prototype fix
[minix.git] / test / test1.c
blob918b7e26411e7fbcb335fbdc57a9166a414ad2ae
1 /* test 1 */
3 #include <sys/types.h>
4 #include <sys/wait.h>
5 #include <errno.h>
6 #include <signal.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <stdio.h>
11 #define SIGNUM 10
12 #define MAX_ERROR 4
13 #define ITERATIONS 10
15 _VOLATILE int glov, gct;
16 int errct;
17 int subtest;
19 _PROTOTYPE(int main, (int argc, char *argv []));
20 _PROTOTYPE(void test1a, (void));
21 _PROTOTYPE(void parent, (void));
22 _PROTOTYPE(void child, (int i));
23 _PROTOTYPE(void test1b, (void));
24 _PROTOTYPE(void parent1, (int childpid));
25 _PROTOTYPE(void func, (int s));
26 _PROTOTYPE(void child1, (void));
27 _PROTOTYPE(void e, (int n));
28 _PROTOTYPE(void quit, (void));
30 int main(argc, argv)
31 int argc;
32 char *argv[];
34 int i, m = 0xFFFF;
36 sync();
38 if (argc == 2) m = atoi(argv[1]);
40 printf("Test 1 ");
41 fflush(stdout); /* have to flush for child's benefit */
43 system("rm -rf DIR_01; mkdir DIR_01");
44 chdir("DIR_01");
46 for (i = 0; i < ITERATIONS; i++) {
47 if (m & 00001) test1a();
48 if (m & 00002) test1b();
51 quit();
52 return(-1); /* impossible */
55 void test1a()
57 int i, n, pid;
59 subtest = 1;
60 n = 4;
61 for (i = 0; i < n; i++) {
62 if ((pid = fork())) {
63 if (pid < 0) {
64 printf("\nTest 1 fork failed\n");
65 exit(1);
67 parent();
68 } else
69 child(i);
73 void parent()
76 int n;
78 n = getpid();
79 wait(&n);
82 void child(i)
83 int i;
85 int n;
87 n = getpid();
88 exit(100+i);
91 void test1b()
93 int i, k;
95 subtest = 2;
96 for (i = 0; i < 4; i++) {
97 glov = 0;
98 signal(SIGNUM, func);
99 if ((k = fork())) {
100 if (k < 0) {
101 printf("Test 1 fork failed\n");
102 exit(1);
104 parent1(k);
105 } else
106 child1();
110 void parent1(childpid)
111 int childpid;
114 int n;
116 for (n = 0; n < 5000; n++);
117 while (kill(childpid, SIGNUM) < 0) /* null statement */
119 wait(&n);
122 void func(s)
123 int s; /* for ANSI */
125 glov++;
126 gct++;
129 void child1()
131 while (glov == 0);
132 exit(gct);
135 void quit()
138 chdir("..");
139 system("rm -rf DIR*");
141 if (errct == 0) {
142 printf("ok\n");
143 exit(0);
144 } else {
145 printf("%d errors\n", errct);
146 exit(1);