16 int is
, array
[4], parsigs
, parcum
, sigct
, cumsig
, errct
, subtest
;
17 int iteration
, kk
= 0, errct
= 0;
20 _PROTOTYPE(int main
, (int argc
, char *argv
[]));
21 _PROTOTYPE(void test2a
, (void));
22 _PROTOTYPE(void test2b
, (void));
23 _PROTOTYPE(void test2c
, (void));
24 _PROTOTYPE(void test2d
, (void));
25 _PROTOTYPE(void test2e
, (void));
26 _PROTOTYPE(void test2f
, (void));
27 _PROTOTYPE(void test2g
, (void));
28 _PROTOTYPE(void test2h
, (void));
29 _PROTOTYPE(void sigpip
, (int s
));
30 _PROTOTYPE(void quit
, (void));
31 _PROTOTYPE(void e
, (int n
));
41 if (argc
== 2) m
= atoi(argv
[1]);
44 fflush(stdout
); /* have to flush for child's benefit */
46 system("rm -rf DIR_02; mkdir DIR_02");
49 for (i
= 0; i
< ITERATIONS
; i
++) {
51 if (m
& 0001) test2a();
52 if (m
& 0002) test2b();
53 if (m
& 0004) test2c();
54 if (m
& 0010) test2d();
55 if (m
& 0020) test2e();
56 if (m
& 0040) test2f();
57 if (m
& 0100) test2g();
58 if (m
& 0200) test2h();
61 if (cumsig
!= ITERATIONS
) e(101);
63 return(-1); /* impossible */
75 printf("pipe error. errno= %d\n", errno
);
81 printf("fork failed\n");
88 for (i
= 0; i
< 2048; i
++) buf
[i
] = i
& 0377;
89 for (q
= 0; q
< 8; q
++) {
90 if (write(fd
[1], buf
, 2048) < 0) {
91 printf("write pipe err. errno=%d\n", errno
);
99 printf("wrong exit code %d\n", q
);
106 for (q
= 0; q
< 32; q
++) {
107 n
= read(fd
[0], buf
, 512);
109 printf("read yielded %d bytes, not 512\n", n
);
113 for (j
= 0; j
< n
; j
++)
114 if ((buf
[j
] & 0377) != (kk
& 0377)) {
115 printf("wrong data: %d %d %d \n ",
116 j
, buf
[j
] & 0377, kk
& 0377);
132 signal(SIGPIPE
, sigpip
);
138 write(fd
[1], buf
, 1);
154 signal(SIGINT
, SIG_DFL
);
156 if ((array
[is
++] = fork()) > 0) {
157 if ((array
[is
++] = fork()) > 0) {
158 if ((array
[is
++] = fork()) > 0) {
159 if ((array
[is
++] = fork()) > 0) {
160 signal(SIGINT
, SIG_IGN
);
161 kill(array
[0], SIGINT
);
162 kill(array
[1], SIGINT
);
163 kill(array
[2], SIGINT
);
164 kill(array
[3], SIGINT
);
186 int pid
, stat_loc
, s
;
191 /* Test waitpid(pid, arg2, 0) */
196 s
= waitpid(pid
, &stat_loc
, 0);
198 if (WIFEXITED(stat_loc
) == 0) e(3);
199 if (WIFSIGNALED(stat_loc
) != 0) e(4);
200 if (WEXITSTATUS(stat_loc
) != 22) e(5);
206 /* Test waitpid(-1, arg2, 0) */
211 s
= waitpid(-1, &stat_loc
, 0);
213 if (WIFEXITED(stat_loc
) == 0) e(8);
214 if (WIFSIGNALED(stat_loc
) != 0) e(9);
215 if (WEXITSTATUS(stat_loc
) != 33) e(10);
221 /* Test waitpid(0, arg2, 0) */
226 s
= waitpid(0, &stat_loc
, 0);
228 if (WIFEXITED(stat_loc
) == 0) e(13);
229 if (WIFSIGNALED(stat_loc
) != 0) e(14);
230 if (WEXITSTATUS(stat_loc
) != 44) e(15);
236 /* Test waitpid(0, arg2, WNOHANG) */
237 signal(SIGTERM
, SIG_DFL
);
242 s
= waitpid(0, &stat_loc
, WNOHANG
);
244 if (kill(pid
, SIGTERM
) != 0) e(18);
245 if (waitpid(pid
, &stat_loc
, 0) != pid
) e(19);
246 if (WIFEXITED(stat_loc
) != 0) e(20);
247 if (WIFSIGNALED(stat_loc
) == 0) e(21);
248 if (WTERMSIG(stat_loc
) != SIGTERM
) e(22);
254 /* Test some error conditions. */
256 if (waitpid(0, &stat_loc
, 0) != -1) e(23);
257 if (errno
!= ECHILD
) e(24);
259 if (waitpid(0, &stat_loc
, WNOHANG
) != -1) e(25);
260 if (errno
!= ECHILD
) e(26);
266 int pid1
, pid2
, stat_loc
, s
;
268 /* Test waitpid with two children. */
270 if (iteration
> 1) return; /* slow test, don't do it too much */
271 if ( (pid1
= fork())) {
273 if ( (pid2
= fork()) ) {
274 /* Parent. Collect second child first. */
275 s
= waitpid(pid2
, &stat_loc
, 0);
277 if (WIFEXITED(stat_loc
) == 0) e(2);
278 if (WIFSIGNALED(stat_loc
) != 0) e(3);
279 if (WEXITSTATUS(stat_loc
) != 222) e(4);
281 /* Now collect first child. */
282 s
= waitpid(pid1
, &stat_loc
, 0);
284 if (WIFEXITED(stat_loc
) == 0) e(6);
285 if (WIFSIGNALED(stat_loc
) != 0) e(7);
286 if (WEXITSTATUS(stat_loc
) != 111) e(8);
289 sleep(2); /* child 2 delays before exiting. */
294 exit(111); /* child 1 exits immediately */
301 /* test getpid, getppid, getuid, etc. */
303 pid_t pid
, pid1
, ppid
, cpid
, stat_loc
, err
;
309 if ( (pid1
= fork())) {
310 /* Parent. Do nothing. */
311 if (wait(&stat_loc
) != pid1
) e(1);
312 if (WEXITSTATUS(stat_loc
) != (pid1
& 0377)) e(2);
314 /* Child. Get ppid. */
317 if (ppid
!= pid
) err
= 3;
318 if (cpid
== ppid
) err
= 4;
321 if (err
!= 0) e(err
);
326 /* test time(), times() */
339 if (t1
< 650000000L) e(1); /* 650000000 is Sept. 1990 */
342 t1
= time( (time_t *) NULL
);
343 if (t1
< 650000000L) e(3);
346 t2
= time( (time_t *) NULL
);
348 if (t2
- t1
< 1) e(5);
352 if ( t4
== (clock_t) -1) e(6);
353 if (t4
- t3
< CLOCKS_PER_SEC
) e(7);
354 if (tmsbuf
.tms_utime
< 0) e(8);
355 if (tmsbuf
.tms_stime
< 0) e(9);
356 if (tmsbuf
.tms_cutime
< 0) e(10);
357 if (tmsbuf
.tms_cstime
< 0) e(11);
362 /* Test getgroups(). */
368 if (getgroups(10, g
) != 0) e(1);
369 if (getgroups(1, g
) != 0) e(2);
370 if (getgroups(0, g
) != 0) e(3);
374 int s
; /* for ANSI */
384 system("rm -rf DIR*");
390 printf("%d errors\n", errct
);
398 int err_num
= errno
; /* save errno in case printf clobbers it */
400 printf("Subtest %d, error %d errno=%d ", subtest
, n
, errno
);
401 errno
= err_num
; /* restore errno, just in case */
403 if (errct
++ > MAX_ERROR
) {
404 printf("Too many errors; test aborted\n");
406 system("rm -rf DIR*");