Add more tests, results.
[pintos-anon] / grading / filesys / syn-write.c
1 #include <random.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <syscall.h>
5 #include "fslib.h"
6 #include "syn-write.h"
7
8 const char test_name[] = "syn-write";
9
10 char buf1[BUF_SIZE];
11 char buf2[BUF_SIZE];
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 buf1), "create \"%s\"", filename);
21
22   for (i = 0; i < CHILD_CNT; i++) 
23     {
24       char cmd_line[128];
25       snprintf (cmd_line, sizeof cmd_line, "child-syn-wrt %d", i);
26       check ((children[i] = exec (cmd_line)) != PID_ERROR,
27              "exec child %d of %d: \"%s\"", i + 1, (int) CHILD_CNT, cmd_line);
28     }
29
30   for (i = 0; i < CHILD_CNT; i++) 
31     {
32       int status = join (children[i]);
33       check (status == i, "join child %d of %d", i + 1, (int) CHILD_CNT);
34     }
35
36   check ((fd = open (filename)) > 1, "open \"%s\"", filename);
37   check (read (fd, buf1, sizeof buf1) > 0, "read \"%s\"", filename);
38   random_bytes (buf2, sizeof buf2);
39   compare_bytes (buf1, buf2, sizeof buf1, 0, filename);
40 }