Make tests public. Rewrite most tests. Add tests.
[pintos-anon] / src / tests / filesys / extended / child-syn-rw.c
1 #include <random.h>
2 #include <stdlib.h>
3 #include <syscall.h>
4 #include "tests/filesys/extended/syn-rw.h"
5 #include "tests/lib.h"
6
7 const char *test_name = "child-syn-rw";
8
9 static char buf1[BUF_SIZE];
10 static char buf2[BUF_SIZE];
11
12 int
13 main (int argc, const char *argv[]) 
14 {
15   int child_idx;
16   int fd;
17   size_t ofs;
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 (buf1, sizeof buf1);
26
27   CHECK ((fd = open (filename)) > 1, "open \"%s\"", filename);
28   ofs = 0;
29   while (ofs < sizeof buf2)
30     {
31       int bytes_read = read (fd, buf2 + ofs, sizeof buf2 - ofs);
32       CHECK (bytes_read >= -1 && bytes_read <= (int) (sizeof buf2 - ofs),
33              "%zu-byte read on \"%s\" returned invalid value of %d",
34              sizeof buf2 - ofs, filename, bytes_read);
35       if (bytes_read > 0) 
36         {
37           compare_bytes (buf2 + ofs, buf1 + ofs, bytes_read, ofs, filename);
38           ofs += bytes_read;
39         }
40     }
41   close (fd);
42
43   return child_idx;
44 }