e426fadc570ba4804e667e61e49a05e6c92d66af
[pintos-anon] / src / tests / filesys / base / child-syn-read.c
1 /* Child process for syn-read test.
2    Reads the contents of a test file a byte at a time, in the
3    hope that this will take long enough that we can get a
4    significant amount of contention in the kernel file system
5    code. */
6
7 #include <random.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <syscall.h>
11 #include "tests/lib.h"
12 #include "tests/filesys/base/syn-read.h"
13
14 static char buf[BUF_SIZE];
15
16 int
17 main (int argc, const char *argv[]) 
18 {
19   int child_idx;
20   int fd;
21   size_t i;
22
23   quiet = true;
24   
25   CHECK (argc == 2, "argc must be 2, actually %d", argc);
26   child_idx = atoi (argv[1]);
27
28   random_init (0);
29   random_bytes (buf, sizeof buf);
30
31   CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
32   for (i = 0; i < sizeof buf; i++) 
33     {
34       char c;
35       CHECK (read (fd, &c, 1) > 0, "read \"%s\"", file_name);
36       compare_bytes (&c, buf + i, 1, i, file_name);
37     }
38   close (fd);
39
40   return child_idx;
41 }
42