3 * Copyright (c) International Business Machines Corp., 2001
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.
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.
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
25 * wait401 - check that a call to wait4() correctly waits for a child
29 * loop if that option was specified
31 * issue the system call
32 * check the return value
33 * if return value == -1
34 * issue a FAIL message, break remaining tests and cleanup
35 * if we are doing functional testing
36 * issue a PASS message if the wait4 call returned the child's pid
38 * issue a FAIL message
41 * USAGE: <for command-line>
42 * wait401 [-c n] [-f] [-e] [-i n] [-I x] [-P x] [-t]
43 * where, -c n : Run n copies concurrently.
44 * -f : Turn off functionality Testing.
45 * -i n : Execute test n times.
46 * -I x : Execute test for x seconds.
47 * -P x : Pause for x seconds between iterations.
48 * -t : Turn on syscall timing.
63 #include <sys/types.h>
64 #include <sys/resource.h>
70 char *TCID= "wait401()";
74 main(int ac, char **av)
76 int lc; /* loop counter */
77 const char *msg; /* message returned from parse_opts */
80 struct rusage *rusage = NULL;
82 /* parse standard options */
83 if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *) NULL) {
84 tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
87 setup(); /* global setup */
89 /* The following loop checks looping state if -i option given */
91 for (lc = 0; TEST_LOOPING(lc); lc++) {
92 /* reset Tst_count in case we are looping */
96 * Allocate some space for the rusage structure
99 if ((rusage = (struct rusage *)malloc(sizeof(struct rusage)))
101 tst_brkm(TBROK, cleanup, "malloc() failed");
107 tst_brkm(TBROK, cleanup, "fork() failed");
110 if (pid == 0) { /* this is the child */
112 * sleep for a moment to let us do the test
116 } else { /* this is the parent */
118 /* call wait4 with the TEST() macro */
119 TEST(wait4(pid, &status, 0, rusage));
122 if (TEST_RETURN == -1) {
123 tst_brkm(TFAIL, cleanup, "%s call failed - errno = %d "
124 ": %s", TCID, TEST_ERRNO, strerror(TEST_ERRNO));
127 if (STD_FUNCTIONAL_TEST) {
129 * The return from this call should be non-zero.
131 if (WIFEXITED(status) == 0) {
132 tst_brkm(TFAIL, cleanup, "%s call succeeded but "
133 "WIFEXITED() did not return expected value "
134 "- %d", TCID, WIFEXITED(status));
135 } else if (TEST_RETURN != pid) {
136 tst_resm(TFAIL, "%s did not return the "
137 "expected value. %d", TCID,
141 tst_resm(TPASS, "Received child pid as expected.");
144 tst_resm(TPASS, "%s call succeeded", TCID);
147 * Clean up things in case we are looping.
159 * setup() - performs all the ONE TIME setup for this test.
164 /* capture signals */
165 tst_sig(FORK, DEF_HANDLER, cleanup);
167 /* Pause if that option was specified */
172 * cleanup() - performs all the ONE TIME cleanup for this test at completion
179 * print timing stats if that option was specified.
180 * print errno log if that option was specified.
184 /* exit with return code appropriate for results */