plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. |
Zeng Linggang | f55ca22 | 2014-06-23 10:37:45 +0800 | [diff] [blame] | 3 | * AUTHOR : William Roske |
| 4 | * CO-PILOT : Dave Fenner |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of version 2 of the GNU General Public License as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it would be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 13 | * |
| 14 | * Further, this software is distributed without any warranty that it is |
| 15 | * free of the rightful claim of any third person regarding infringement |
| 16 | * or the like. Any license provided herein, whether implied or |
| 17 | * otherwise, applies only to this software file. Patent licenses, if |
| 18 | * any, provided herein do not apply to combinations of this program with |
| 19 | * other software, or any other product whatsoever. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License along |
Wanlong Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 22 | * with this program; if not, write the Free Software Foundation, Inc., |
| 23 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 24 | * |
| 25 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 26 | * Mountain View, CA 94043, or: |
| 27 | * |
| 28 | * http://www.sgi.com |
| 29 | * |
| 30 | * For further information regarding this notice, see: |
| 31 | * |
| 32 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 33 | * |
| 34 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 35 | |
| 36 | #include <errno.h> |
| 37 | #include <string.h> |
| 38 | #include <signal.h> |
| 39 | #include <stdlib.h> |
| 40 | #include <sys/types.h> |
| 41 | #include <sys/wait.h> |
| 42 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 43 | |
Zeng Linggang | f55ca22 | 2014-06-23 10:37:45 +0800 | [diff] [blame] | 44 | static void setup(void); |
| 45 | static void cleanup(void); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 46 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 47 | char *TCID = "wait02"; |
| 48 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 49 | |
Zeng Linggang | f55ca22 | 2014-06-23 10:37:45 +0800 | [diff] [blame] | 50 | static void wait_verify(void); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 51 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 52 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 53 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 54 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 55 | const char *msg; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 56 | |
Zeng Linggang | f55ca22 | 2014-06-23 10:37:45 +0800 | [diff] [blame] | 57 | msg = parse_opts(ac, av, NULL, NULL); |
| 58 | if (msg != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 59 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 60 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 61 | setup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 62 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 63 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 64 | tst_count = 0; |
Zeng Linggang | f55ca22 | 2014-06-23 10:37:45 +0800 | [diff] [blame] | 65 | wait_verify(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 66 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 67 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 68 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 69 | tst_exit(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 70 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 71 | |
Zeng Linggang | f55ca22 | 2014-06-23 10:37:45 +0800 | [diff] [blame] | 72 | static void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 73 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 74 | tst_sig(FORK, DEF_HANDLER, cleanup); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 75 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 76 | TEST_PAUSE; |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 77 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 78 | |
Zeng Linggang | f55ca22 | 2014-06-23 10:37:45 +0800 | [diff] [blame] | 79 | static void wait_verify(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 80 | { |
Zeng Linggang | f55ca22 | 2014-06-23 10:37:45 +0800 | [diff] [blame] | 81 | int fork_pid, status, exit_child = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 82 | |
Zeng Linggang | f55ca22 | 2014-06-23 10:37:45 +0800 | [diff] [blame] | 83 | fork_pid = FORK_OR_VFORK(); |
| 84 | if (fork_pid == -1) { |
| 85 | tst_brkm(TBROK | TERRNO, cleanup, "fork() Failure"); |
| 86 | } else if (fork_pid == 0) { |
| 87 | sleep(1); |
| 88 | exit(exit_child); |
| 89 | } |
| 90 | |
| 91 | TEST(wait(&status)); |
| 92 | |
| 93 | if (TEST_RETURN == -1) { |
| 94 | tst_resm(TFAIL | TTERRNO, "wait(1) Failed"); |
| 95 | } else if (WIFEXITED(status) && WEXITSTATUS(status) == exit_child) { |
| 96 | tst_resm(TPASS, "wait(&status) returned %ld", TEST_RETURN); |
| 97 | } else { |
| 98 | tst_resm(TFAIL, |
| 99 | "wait(1) Failed, exit_child - 0x%x, status - 0x%x", |
| 100 | exit_child, status); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | static void cleanup(void) |
| 105 | { |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 106 | } |