Drop main() prototype. Syncs with NetBSD-8
[minix.git] / minix / tests / test10.c
blob400f2e6d2215c36393451b8f25c722b46995f8a2
1 /* test 10 */
3 #include <sys/types.h>
4 #include <sys/wait.h>
5 #include <errno.h>
6 #include <fcntl.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <stdio.h>
11 char *name[] = {"t10a", "t10b", "t10c", "t10d", "t10e", "t10f", "t10g",
12 "t10h", "t10i", "t10j"};
14 #define PROGBUF_LONGS 3000
15 long prog[PROGBUF_LONGS];
16 int psize;
18 int max_error = 2;
19 #include "common.h"
22 int main(void);
23 void spawn(int n);
24 void mkfiles(void);
25 void cr_file(char *name, int size);
26 void rmfiles(void);
27 void quit(void);
29 int main()
31 int i, n, pid, r;
33 start(10);
34 system("cp ../t10a .");
35 pid = getpid();
37 /* Create files t10b ... t10h */
38 mkfiles();
40 if (getpid() == pid)
41 if (fork() == 0) {
42 execl("t10a", "t10a", (char *) 0);
43 exit(0);
45 if (getpid() == pid)
46 if (fork() == 0) {
47 execl("t10b", "t10b", (char *) 0);
48 exit(0);
50 if (getpid() == pid)
51 if (fork() == 0) {
52 execl("t10c", "t10c", (char *) 0);
53 exit(0);
55 if (getpid() == pid)
56 if (fork() == 0) {
57 execl("t10d", "t10d", (char *) 0);
58 exit(0);
61 srand(100);
62 for (i = 0; i < 60; i++) {
63 r = rand() & 07;
64 spawn(r);
67 for (i = 0; i < 4; i++) wait(&n);
68 rmfiles();
69 quit();
70 return(-1); /* impossible */
73 void spawn(n)
74 int n;
76 int pid;
78 if ((pid = fork()) != 0) {
79 wait(&n); /* wait for some child (any one) */
80 } else {
81 /* a successful exec or a successful detection of a broken executable
82 * is ok
84 if(execl(name[n], name[n], (char *) 0) < 0 && errno == ENOEXEC)
85 exit(0);
86 errct++;
87 printf("Child execl didn't take. file=%s errno=%d\n", name[n], errno);
88 rmfiles();
89 exit(1);
90 printf("Worse yet, EXIT didn't exit\n");
94 void mkfiles()
96 int fd;
97 fd = open("t10a", 0);
98 if (fd < 0) {
99 printf("Can't open t10a\n");
100 exit(1);
102 psize = read(fd, (char *) prog, PROGBUF_LONGS * 4);
103 cr_file("t10b", 1600);
104 cr_file("t10c", 1400);
105 cr_file("t10d", 2300);
106 cr_file("t10e", 3100);
107 cr_file("t10f", 2400);
108 cr_file("t10g", 1700);
109 cr_file("t10h", 1500);
110 cr_file("t10i", 4000);
111 cr_file("t10j", 2250);
112 close(fd);
115 void cr_file(name, size)
116 char *name;
117 int size;
120 int fd;
122 size += 3000;
123 fd = creat(name, 0755);
124 write(fd, (char *) prog, psize);
125 close(fd);
128 void rmfiles()
130 unlink("t10b");
131 unlink("t10c");
132 unlink("t10d");
133 unlink("t10e");
134 unlink("t10f");
135 unlink("t10g");
136 unlink("t10h");
137 unlink("t10i");
138 unlink("t10j");