source: trunk/minix/test/test1.c@ 12

Last change on this file since 12 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 2.0 KB
RevLine 
[9]1/* test 1 */
2
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>
10
11#define SIGNUM 10
12#define MAX_ERROR 4
13#define ITERATIONS 10
14
15_VOLATILE int glov, gct;
16int errct;
17int subtest;
18
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));
29
30int main(argc, argv)
31int argc;
32char *argv[];
33{
34 int i, m = 0xFFFF;
35
36 sync();
37
38 if (argc == 2) m = atoi(argv[1]);
39
40 printf("Test 1 ");
41 fflush(stdout); /* have to flush for child's benefit */
42
43 system("rm -rf DIR_01; mkdir DIR_01");
44 chdir("DIR_01");
45
46 for (i = 0; i < ITERATIONS; i++) {
47 if (m & 00001) test1a();
48 if (m & 00002) test1b();
49 }
50
51 quit();
52 return(-1); /* impossible */
53}
54
55void test1a()
56{
57 int i, n, pid;
58
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);
66 }
67 parent();
68 } else
69 child(i);
70 }
71}
72
73void parent()
74{
75
76 int n;
77
78 n = getpid();
79 wait(&n);
80}
81
82void child(i)
83int i;
84{
85 int n;
86
87 n = getpid();
88 exit(100+i);
89}
90
91void test1b()
92{
93 int i, k;
94
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);
103 }
104 parent1(k);
105 } else
106 child1();
107 }
108}
109
110void parent1(childpid)
111int childpid;
112{
113
114 int n;
115
116 for (n = 0; n < 5000; n++);
117 while (kill(childpid, SIGNUM) < 0) /* null statement */
118 ;
119 wait(&n);
120}
121
122void func(s)
123int s; /* for ANSI */
124{
125 glov++;
126 gct++;
127}
128
129void child1()
130{
131 while (glov == 0);
132 exit(gct);
133}
134
135void quit()
136{
137
138 chdir("..");
139 system("rm -rf DIR*");
140
141 if (errct == 0) {
142 printf("ok\n");
143 exit(0);
144 } else {
145 printf("%d errors\n", errct);
146 exit(1);
147 }
148}
Note: See TracBrowser for help on using the repository browser.