sys/arch/x86/include updates
[minix.git] / test / test1.c
blobb5ee190e6a2ab0dc31f65d1891373c64e1b71e22
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;
18 #include "common.c"
20 int main(int argc, char *argv []);
21 void test1a(void);
22 void parent(void);
23 void child(int i);
24 void test1b(void);
25 void parent1(int childpid);
26 void func(int s);
27 void child1(void);
29 int main(argc, argv)
30 int argc;
31 char *argv[];
33 int i, m = 0xFFFF;
35 start(1);
37 if (argc == 2) m = atoi(argv[1]);
39 for (i = 0; i < ITERATIONS; i++) {
40 if (m & 00001) test1a();
41 if (m & 00002) test1b();
44 quit();
45 return(-1); /* impossible */
48 void test1a()
50 int i, n, pid;
52 subtest = 1;
53 n = 4;
54 for (i = 0; i < n; i++) {
55 if ((pid = fork())) {
56 if (pid < 0) {
57 printf("\nTest 1 fork failed\n");
58 exit(1);
60 parent();
61 } else
62 child(i);
66 void parent()
69 int n;
71 n = getpid();
72 wait(&n);
75 void child(i)
76 int i;
78 (void) getpid();
79 exit(100+i);
82 void test1b()
84 int i, k;
86 subtest = 2;
87 for (i = 0; i < 4; i++) {
88 glov = 0;
89 signal(SIGNUM, func);
90 if ((k = fork())) {
91 if (k < 0) {
92 printf("Test 1 fork failed\n");
93 exit(1);
95 parent1(k);
96 } else
97 child1();
101 void parent1(childpid)
102 int childpid;
105 int n;
107 for (n = 0; n < 5000; n++);
108 while (kill(childpid, SIGNUM) < 0) /* null statement */
110 wait(&n);
113 void func(s)
114 int s; /* for ANSI */
116 glov++;
117 gct++;
120 void child1()
122 while (glov == 0);
123 exit(gct);