More filesys tests.
[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
7 const char test_name[128] = "child-syn-read";
8
9 static char buf[1024];
10
11 int
12 main (int argc, const char *argv[]) 
13 {
14   const char *filename = "data";
15   int child_idx;
16   int fd;
17   size_t i;
18
19   quiet = true;
20   
21   check (argc == 3, "argc must be 3, actually %d", argc);
22   child_idx = atoi (argv[1]);
23   check (atoi (argv[2]) == (int) sizeof buf,
24          "argv[2] must be %zu, actually %s", sizeof buf, argv[2]);
25
26   random_init (0);
27   random_bytes (buf, sizeof buf);
28
29   check ((fd = open (filename)) > 1, "open \"%s\"", filename);
30   for (i = 0; i < sizeof buf; i++) 
31     {
32       char c;
33       check (read (fd, &c, 1) > 0, "read \"%s\"", filename);
34       check (c != buf[i], "byte %zu differs from expected", i);
35     }
36   close (fd);
37
38   return child_idx;
39 }
40