mkfs: symlink support
[minix.git] / test / test10.c
blob41d574a1ba9a085927e3052b62e862546535a4a3
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, k;
77 if ((pid = fork()) != 0) {
78 wait(&n); /* wait for some child (any one) */
79 } else {
80 k = execl(name[n], name[n], (char *) 0);
81 errct++;
82 printf("Child execl didn't take. file=%s errno=%d\n", name[n], errno);
83 rmfiles();
84 exit(1);
85 printf("Worse yet, EXIT didn't exit\n");
89 void mkfiles()
91 int fd;
92 fd = open("t10a", 0);
93 if (fd < 0) {
94 printf("Can't open t10a\n");
95 exit(1);
97 psize = read(fd, (char *) prog, PROGBUF_LONGS * 4);
98 cr_file("t10b", 1600);
99 cr_file("t10c", 1400);
100 cr_file("t10d", 2300);
101 cr_file("t10e", 3100);
102 cr_file("t10f", 2400);
103 cr_file("t10g", 1700);
104 cr_file("t10h", 1500);
105 cr_file("t10i", 4000);
106 cr_file("t10j", 2250);
107 close(fd);
110 void cr_file(name, size)
111 char *name;
112 int size;
115 int fd;
117 size += 3000;
118 fd = creat(name, 0755);
119 write(fd, (char *) prog, psize);
120 close(fd);
123 void rmfiles()
125 unlink("t10b");
126 unlink("t10c");
127 unlink("t10d");
128 unlink("t10e");
129 unlink("t10f");
130 unlink("t10g");
131 unlink("t10h");
132 unlink("t10i");
133 unlink("t10j");