use oxpcie only if enabled to avoid baud bottleneck of uart.
[minix.git] / test / test4.c
blobbb553e1440974f9d2c11524c55359bb303a0aa90
1 /* test 4 */
3 #include <sys/types.h>
4 #include <sys/wait.h>
5 #include <fcntl.h>
6 #include <signal.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <stdio.h>
10 #include <string.h>
12 pid_t pid0, pid1, pid2, pid3;
13 int s, i, fd, nextb, errct = 0;
14 char *tempfile = "test4.temp";
15 char buf[1024];
16 extern int errno;
18 _PROTOTYPE(int main, (void));
19 _PROTOTYPE(void subr, (void));
20 _PROTOTYPE(void nofork, (void));
21 _PROTOTYPE(void quit, (void));
23 int main()
25 int k;
27 printf("Test 4 ");
28 fflush(stdout); /* have to flush for child's benefit */
30 system("rm -rf DIR_04; mkdir DIR_04");
31 chdir("DIR_04");
33 creat(tempfile, 0777);
34 for (k = 0; k < 20; k++) {
35 subr();
37 unlink(tempfile);
38 quit();
39 return(-1); /* impossible */
42 void subr()
44 if ( (pid0 = fork()) != 0) {
45 /* Parent 0 */
46 if (pid0 < 0) nofork();
47 if ( (pid1 = fork()) != 0) {
48 /* Parent 1 */
49 if (pid1 < 0) nofork();
50 if ( (pid2 = fork()) != 0) {
51 /* Parent 2 */
52 if (pid2 < 0) nofork();
53 if ( (pid3 = fork()) != 0) {
54 /* Parent 3 */
55 if (pid3 < 0) nofork();
56 for (i = 0; i < 10000; i++);
57 kill(pid2, 9);
58 kill(pid1, 9);
59 kill(pid0, 9);
60 wait(&s);
61 wait(&s);
62 wait(&s);
63 wait(&s);
64 } else {
65 fd = open(tempfile, O_RDONLY);
66 lseek(fd, 20480L * nextb, 0);
67 for (i = 0; i < 10; i++) read(fd, buf, 1024);
68 nextb++;
69 close(fd);
70 exit(0);
72 } else {
73 while (1) getpid();
75 } else {
76 while (1) getpid();
78 } else {
79 while (1) getpid();
83 void nofork()
85 int e = errno;
86 printf("Fork failed: %s (%d)\n",strerror(e),e);
87 exit(1);
90 void quit()
93 chdir("..");
94 system("rm -rf DIR*");
96 if (errct == 0) {
97 printf("ok\n");
98 exit(0);
99 } else {
100 printf("%d errors\n", errct);
101 exit(1);