cdc7f189b56dd3e91390b91c2c9d4ab40cd8b54c
[pintos-anon] / grading / filesys / syn-read.c
1 #include <random.h>
2 #include <stdio.h>
3 #include <syscall.h>
4 #include "fslib.h"
5 #include "syn-read.h"
6
7 const char test_name[] = "syn-read";
8
9 static char buf[BUF_SIZE];
10
11 #define CHILD_CNT 10
12
13 void
14 test_main (void) 
15 {
16   pid_t children[CHILD_CNT];
17   int fd;
18   int i;
19
20   check (create (filename, sizeof buf), "create \"%s\"", filename);
21   check ((fd = open (filename)) > 1, "open \"%s\"", filename);
22   random_bytes (buf, sizeof buf);
23   check (write (fd, buf, sizeof buf) > 0, "write \"%s\"", filename);
24   msg ("close \"%s\"", filename);
25   close (fd);
26
27   for (i = 0; i < CHILD_CNT; i++) 
28     {
29       char cmd_line[128];
30       snprintf (cmd_line, sizeof cmd_line, "child-syn-read %d", i);
31       check ((children[i] = exec (cmd_line)) != PID_ERROR,
32              "exec child %d of %d: \"%s\"", i + 1, (int) CHILD_CNT, cmd_line);
33     }
34
35   for (i = 0; i < CHILD_CNT; i++) 
36     {
37       int status = join (children[i]);
38       check (status == i, "join child %d of %d", i + 1, (int) CHILD_CNT);
39     }
40 }