1 /* Child process for syn-rw.
2 Reads from a file created by our parent process, which is
3 growing it. We loop until we've read the whole file
4 successfully. Many iterations through the loop will return 0
5 bytes, because the file has not grown in the meantime. That
6 is, we are "busy waiting" for the file to grow.
7 (This test could be improved by adding a "yield" system call
8 and calling yield whenever we receive a 0-byte read.) */
13 #include "tests/filesys/extended/syn-rw.h"
14 #include "tests/lib.h"
16 const char *test_name = "child-syn-rw";
18 static char buf1[BUF_SIZE];
19 static char buf2[BUF_SIZE];
22 main (int argc, const char *argv[])
30 CHECK (argc == 2, "argc must be 2, actually %d", argc);
31 child_idx = atoi (argv[1]);
34 random_bytes (buf1, sizeof buf1);
36 CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
38 while (ofs < sizeof buf2)
40 int bytes_read = read (fd, buf2 + ofs, sizeof buf2 - ofs);
41 CHECK (bytes_read >= -1 && bytes_read <= (int) (sizeof buf2 - ofs),
42 "%zu-byte read on \"%s\" returned invalid value of %d",
43 sizeof buf2 - ofs, file_name, bytes_read);
46 compare_bytes (buf2 + ofs, buf1 + ofs, bytes_read, ofs, file_name);