5bd739ec79f72a77b9f63a408d5ac206ea8a20e6
[pintos-anon] / grading / filesys / child-syn-read.c
1 #include <random.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <syscall.h>
5 #include "fslib.h"
6 #include "syn-read.h"
7
8 const char test_name[128] = "child-syn-read";
9
10 static char buf[BUF_SIZE];
11
12 int
13 main (int argc, const char *argv[]) 
14 {
15   int child_idx;
16   int fd;
17   size_t i;
18
19   quiet = true;
20   
21   CHECK (argc == 2, "argc must be 2, actually %d", argc);
22   child_idx = atoi (argv[1]);
23
24   random_init (0);
25   random_bytes (buf, sizeof buf);
26
27   CHECK ((fd = open (filename)) > 1, "open \"%s\"", filename);
28   for (i = 0; i < sizeof buf; i++) 
29     {
30       char c;
31       CHECK (read (fd, &c, 1) > 0, "read \"%s\"", filename);
32       compare_bytes (&c, buf + i, 1, i, filename);
33     }
34   close (fd);
35
36   return child_idx;
37 }
38