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 static char buf1[BUF_SIZE];
17 static char buf2[BUF_SIZE];
20 main (int argc, const char *argv[])
26 test_name = "child-syn-rw";
29 CHECK (argc == 2, "argc must be 2, actually %d", argc);
30 child_idx = atoi (argv[1]);
33 random_bytes (buf1, sizeof buf1);
35 CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
37 while (ofs < sizeof buf2)
39 int bytes_read = read (fd, buf2 + ofs, sizeof buf2 - ofs);
40 CHECK (bytes_read >= -1 && bytes_read <= (int) (sizeof buf2 - ofs),
41 "%zu-byte read on \"%s\" returned invalid value of %d",
42 sizeof buf2 - ofs, file_name, bytes_read);
45 compare_bytes (buf2 + ofs, buf1 + ofs, bytes_read, ofs, file_name);