t40c term[] count fix
[minix.git] / test / test10.c
blob040b0f33a9177221367724038b9bc235dbf25b62
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 #define MAX_ERROR 2
19 #include "common.c"
21 int main(void);
22 void spawn(int n);
23 void mkfiles(void);
24 void cr_file(char *name, int size);
25 void rmfiles(void);
26 void quit(void);
28 int main()
30 int i, n, pid, r;
32 start(10);
33 system("cp ../t10a .");
34 pid = getpid();
36 /* Create files t10b ... t10h */
37 mkfiles();
39 if (getpid() == pid)
40 if (fork() == 0) {
41 execl("t10a", "t10a", (char *) 0);
42 exit(0);
44 if (getpid() == pid)
45 if (fork() == 0) {
46 execl("t10b", "t10b", (char *) 0);
47 exit(0);
49 if (getpid() == pid)
50 if (fork() == 0) {
51 execl("t10c", "t10c", (char *) 0);
52 exit(0);
54 if (getpid() == pid)
55 if (fork() == 0) {
56 execl("t10d", "t10d", (char *) 0);
57 exit(0);
60 srand(100);
61 for (i = 0; i < 60; i++) {
62 r = rand() & 07;
63 spawn(r);
66 for (i = 0; i < 4; i++) wait(&n);
67 rmfiles();
68 quit();
69 return(-1); /* impossible */
72 void spawn(n)
73 int n;
75 int pid;
77 if ((pid = fork()) != 0) {
78 wait(&n); /* wait for some child (any one) */
79 } else {
80 /* a successful exec or a successful detection of a broken executable
81 * is ok
83 if(execl(name[n], name[n], (char *) 0) < 0 && errno == ENOEXEC)
84 exit(0);
85 errct++;
86 printf("Child execl didn't take. file=%s errno=%d\n", name[n], errno);
87 rmfiles();
88 exit(1);
89 printf("Worse yet, EXIT didn't exit\n");
93 void mkfiles()
95 int fd;
96 fd = open("t10a", 0);
97 if (fd < 0) {
98 printf("Can't open t10a\n");
99 exit(1);
101 psize = read(fd, (char *) prog, PROGBUF_LONGS * 4);
102 cr_file("t10b", 1600);
103 cr_file("t10c", 1400);
104 cr_file("t10d", 2300);
105 cr_file("t10e", 3100);
106 cr_file("t10f", 2400);
107 cr_file("t10g", 1700);
108 cr_file("t10h", 1500);
109 cr_file("t10i", 4000);
110 cr_file("t10j", 2250);
111 close(fd);
114 void cr_file(name, size)
115 char *name;
116 int size;
119 int fd;
121 size += 3000;
122 fd = creat(name, 0755);
123 write(fd, (char *) prog, psize);
124 close(fd);
127 void rmfiles()
129 unlink("t10b");
130 unlink("t10c");
131 unlink("t10d");
132 unlink("t10e");
133 unlink("t10f");
134 unlink("t10g");
135 unlink("t10h");
136 unlink("t10i");
137 unlink("t10j");