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 sigpip
, (int s
));
29 _PROTOTYPE(void quit
, (void));
30 _PROTOTYPE(void e
, (int n
));
40 if (argc
== 2) m
= atoi(argv
[1]);
43 fflush(stdout
); /* have to flush for child's benefit */
45 system("rm -rf DIR_02; mkdir DIR_02");
48 for (i
= 0; i
< ITERATIONS
; i
++) {
50 if (m
& 0001) test2a();
51 if (m
& 0002) test2b();
52 if (m
& 0004) test2c();
53 if (m
& 0010) test2d();
54 if (m
& 0020) test2e();
55 if (m
& 0040) test2f();
56 if (m
& 0100) test2g();
59 if (cumsig
!= ITERATIONS
) e(101);
61 return(-1); /* impossible */
73 printf("pipe error. errno= %d\n", errno
);
79 printf("fork failed\n");
86 for (i
= 0; i
< 2048; i
++) buf
[i
] = i
& 0377;
87 for (q
= 0; q
< 8; q
++) {
88 if (write(fd
[1], buf
, 2048) < 0) {
89 printf("write pipe err. errno=%d\n", errno
);
97 printf("wrong exit code %d\n", q
);
104 for (q
= 0; q
< 32; q
++) {
105 n
= read(fd
[0], buf
, 512);
107 printf("read yielded %d bytes, not 512\n", n
);
111 for (j
= 0; j
< n
; j
++)
112 if ((buf
[j
] & 0377) != (kk
& 0377)) {
113 printf("wrong data: %d %d %d \n ",
114 j
, buf
[j
] & 0377, kk
& 0377);
130 signal(SIGPIPE
, sigpip
);
136 write(fd
[1], buf
, 1);
152 signal(SIGINT
, SIG_DFL
);
154 if ((array
[is
++] = fork()) > 0) {
155 if ((array
[is
++] = fork()) > 0) {
156 if ((array
[is
++] = fork()) > 0) {
157 if ((array
[is
++] = fork()) > 0) {
158 signal(SIGINT
, SIG_IGN
);
159 kill(array
[0], SIGINT
);
160 kill(array
[1], SIGINT
);
161 kill(array
[2], SIGINT
);
162 kill(array
[3], SIGINT
);
184 int pid
, stat_loc
, s
;
189 /* Test waitpid(pid, arg2, 0) */
194 s
= waitpid(pid
, &stat_loc
, 0);
196 if (WIFEXITED(stat_loc
) == 0) e(3);
197 if (WIFSIGNALED(stat_loc
) != 0) e(4);
198 if (WEXITSTATUS(stat_loc
) != 22) e(5);
204 /* Test waitpid(-1, arg2, 0) */
209 s
= waitpid(-1, &stat_loc
, 0);
211 if (WIFEXITED(stat_loc
) == 0) e(8);
212 if (WIFSIGNALED(stat_loc
) != 0) e(9);
213 if (WEXITSTATUS(stat_loc
) != 33) e(10);
219 /* Test waitpid(0, arg2, 0) */
224 s
= waitpid(0, &stat_loc
, 0);
226 if (WIFEXITED(stat_loc
) == 0) e(13);
227 if (WIFSIGNALED(stat_loc
) != 0) e(14);
228 if (WEXITSTATUS(stat_loc
) != 44) e(15);
234 /* Test waitpid(0, arg2, WNOHANG) */
235 signal(SIGTERM
, SIG_DFL
);
240 s
= waitpid(0, &stat_loc
, WNOHANG
);
242 if (kill(pid
, SIGTERM
) != 0) e(18);
243 if (waitpid(pid
, &stat_loc
, 0) != pid
) e(19);
244 if (WIFEXITED(stat_loc
) != 0) e(20);
245 if (WIFSIGNALED(stat_loc
) == 0) e(21);
246 if (WTERMSIG(stat_loc
) != SIGTERM
) e(22);
252 /* Test some error conditions. */
254 if (waitpid(0, &stat_loc
, 0) != -1) e(23);
255 if (errno
!= ECHILD
) e(24);
257 if (waitpid(0, &stat_loc
, WNOHANG
) != -1) e(25);
258 if (errno
!= ECHILD
) e(26);
264 int pid1
, pid2
, stat_loc
, s
;
266 /* Test waitpid with two children. */
268 if (iteration
> 1) return; /* slow test, don't do it too much */
269 if ( (pid1
= fork())) {
271 if ( (pid2
= fork()) ) {
272 /* Parent. Collect second child first. */
273 s
= waitpid(pid2
, &stat_loc
, 0);
275 if (WIFEXITED(stat_loc
) == 0) e(2);
276 if (WIFSIGNALED(stat_loc
) != 0) e(3);
277 if (WEXITSTATUS(stat_loc
) != 222) e(4);
279 /* Now collect first child. */
280 s
= waitpid(pid1
, &stat_loc
, 0);
282 if (WIFEXITED(stat_loc
) == 0) e(6);
283 if (WIFSIGNALED(stat_loc
) != 0) e(7);
284 if (WEXITSTATUS(stat_loc
) != 111) e(8);
287 sleep(2); /* child 2 delays before exiting. */
292 exit(111); /* child 1 exits immediately */
299 /* test getpid, getppid, getuid, etc. */
301 pid_t pid
, pid1
, ppid
, cpid
, stat_loc
, err
;
307 if ( (pid1
= fork())) {
308 /* Parent. Do nothing. */
309 if (wait(&stat_loc
) != pid1
) e(1);
310 if (WEXITSTATUS(stat_loc
) != (pid1
& 0377)) e(2);
312 /* Child. Get ppid. */
315 if (ppid
!= pid
) err
= 3;
316 if (cpid
== ppid
) err
= 4;
319 if (err
!= 0) e(err
);
324 /* test time(), times() */
337 if (t1
< 650000000L) e(1); /* 650000000 is Sept. 1990 */
340 t1
= time( (time_t *) NULL
);
341 if (t1
< 650000000L) e(3);
344 t2
= time( (time_t *) NULL
);
346 if (t2
- t1
< 1) e(5);
350 if ( t4
== (clock_t) -1) e(6);
351 if (t4
- t3
< CLOCKS_PER_SEC
) e(7);
352 if (tmsbuf
.tms_utime
< 0) e(8);
353 if (tmsbuf
.tms_stime
< 0) e(9);
354 if (tmsbuf
.tms_cutime
< 0) e(10);
355 if (tmsbuf
.tms_cstime
< 0) e(11);
359 int s
; /* for ANSI */
369 system("rm -rf DIR*");
375 printf("%d errors\n", errct
);
383 int err_num
= errno
; /* save errno in case printf clobbers it */
385 printf("Subtest %d, error %d errno=%d ", subtest
, n
, errno
);
386 errno
= err_num
; /* restore errno, just in case */
388 if (errct
++ > MAX_ERROR
) {
389 printf("Too many errors; test aborted\n");
391 system("rm -rf DIR*");