blob: 8fd4094bcc897656adb8c238eb7cef5ca977551b [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20/*
21 * NAME
22 * waitpid04.c
23 *
24 * DESCRIPTION
25 * test to check the error conditions in waitpid sys call
26 *
27 * USAGE: <for command-line>
28 * waitpid04 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
29 * where, -c n : Run n copies concurrently.
30 * -e : Turn on errno logging.
31 * -i n : Execute test n times.
32 * -I x : Execute test for x seconds.
33 * -P x : Pause for x seconds between iterations.
34 * -t : Turn on syscall timing.
35 *
36 * History
37 * 07/2001 John George
38 * -Ported
39 *
40 * Restrictions
41 * NONE
42 */
43
44#include <sys/signal.h>
45#include <sys/types.h>
46#include <sys/wait.h>
47#include <errno.h>
48#include <test.h>
49#include <usctest.h>
50
51void setup(void);
52void cleanup(void);
53
54/* 0 terminated list of expected errnos */
55int exp_enos[] = {10,22,0};
56
57char *TCID = "waitpid04";
58int TST_TOTAL = 1;
59extern int Tst_count;
60
61#define INVAL_FLAG -1
62#define FAILED 1
63
64int flag, condition_number;
65
66main(int ac, char **av)
67{
68 int pid, status, ret;
69
70 int lc; /* loop counter */
71 char *msg; /* message returned from parse_opts */
72
73 /* parse standard options */
74 if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) !=
75 (char *) NULL) {
76 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
77 tst_exit();
78 /*NOTREACHED*/
79 }
80
81 setup();
82
83 /* check for looping state if -i option is given */
84 for (lc = 0; TEST_LOOPING(lc); lc++) {
85 /* reset Tst_count in case we are looping */
86 Tst_count = 0;
87
88 ret = waitpid(pid, &status, WNOHANG);
89 flag = 0;
90 if( ret != -1) {
91 tst_resm(TFAIL, "condition %d test failed",
92 condition_number++);
93 } else {
94 TEST_ERROR_LOG(errno);
95 if (errno != ECHILD) {
96 tst_resm(TFAIL, "waitpid() set invalid "
97 "errno, expected ECHILD, got: %d",
98 errno);
99 } else {
100 tst_resm(TPASS, "condition %d test passed",
101 condition_number++);
102 }
103 }
104
105 if (fork() == 0) {
106 exit(0);
107 }
108 ret = waitpid(pid, &status, WUNTRACED);
109 flag = 0;
110 if( ret != -1) {
111 tst_resm(TFAIL, "condition %d test failed",
112 condition_number++);
113 } else {
114 TEST_ERROR_LOG(errno);
115 if (errno != ECHILD) {
116 tst_resm(TFAIL, "waitpid() set invalid "
117 "errno, expected ECHILD, got: %d",
118 errno);
119 } else {
120 tst_resm(TPASS, "condition %d test passed",
121 condition_number++);
122 }
123 }
124
125 /* Option is Inval = INVAL_FLAG */
126 ret = waitpid(pid, &status, INVAL_FLAG);
127 flag = 0;
128 if( ret != -1) {
129 tst_resm(TFAIL, "condition %d test failed",
130 condition_number++);
131 } else {
132 TEST_ERROR_LOG(errno);
133 if (errno != EINVAL) {
134 tst_resm(TFAIL, "waitpid() set invalid "
135 "errno, expected EINVAL, got: %d",
136 errno);
137 } else {
138 tst_resm(TPASS, "condition %d test passed",
139 condition_number++);
140 }
141 }
142 }
143 cleanup();
144 /*NOTREACHED*/
145}
146
147/*
148 * setup()
149 * performs all ONE TIME setup for this test
150 */
151void
152setup(void)
153{
154 /* Set up the expected error numbers for -e option */
155 TEST_EXP_ENOS(exp_enos)
156
157 /* Pause if that option was specified
158 * TEST_PAUSE contains the code to fork the test with the -c option.
159 */
160 TEST_PAUSE;
161}
162
163/*
164 * cleanup()
165 * performs all ONE TIME cleanup for this test at
166 * completion or premature exit
167 */
168void
169cleanup(void)
170{
171 /*
172 * print timing stats if that option was specified.
173 * print errno log if that option was specified.
174 */
175 TEST_CLEANUP;
176
177 /* exit with return code appropriate for results */
178 tst_exit();
179 /*NOTREACHED*/
180}