diff options
| author | manuel <manuel@mausz.at> | 2012-03-26 12:54:45 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2012-03-26 12:54:45 +0200 |
| commit | b5f0874cd96ee2a62aabc645b9626c2749cb6a01 (patch) | |
| tree | 1262e4bbe0634de6650be130c36e0538240f4cbf /pintos-progos/tests/filesys/extended/child-syn-rw.c | |
| download | progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.tar.gz progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.tar.bz2 progos-b5f0874cd96ee2a62aabc645b9626c2749cb6a01.zip | |
initial pintos checkin
Diffstat (limited to 'pintos-progos/tests/filesys/extended/child-syn-rw.c')
| -rw-r--r-- | pintos-progos/tests/filesys/extended/child-syn-rw.c | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/pintos-progos/tests/filesys/extended/child-syn-rw.c b/pintos-progos/tests/filesys/extended/child-syn-rw.c new file mode 100644 index 0000000..0e2217d --- /dev/null +++ b/pintos-progos/tests/filesys/extended/child-syn-rw.c | |||
| @@ -0,0 +1,53 @@ | |||
| 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.) */ | ||
| 9 | |||
| 10 | #include <random.h> | ||
| 11 | #include <stdlib.h> | ||
| 12 | #include <syscall.h> | ||
| 13 | #include "tests/filesys/extended/syn-rw.h" | ||
| 14 | #include "tests/lib.h" | ||
| 15 | |||
| 16 | const char *test_name = "child-syn-rw"; | ||
| 17 | |||
| 18 | static char buf1[BUF_SIZE]; | ||
| 19 | static char buf2[BUF_SIZE]; | ||
| 20 | |||
| 21 | int | ||
| 22 | main (int argc, const char *argv[]) | ||
| 23 | { | ||
| 24 | int child_idx; | ||
| 25 | int fd; | ||
| 26 | size_t ofs; | ||
| 27 | |||
| 28 | quiet = true; | ||
| 29 | |||
| 30 | CHECK (argc == 2, "argc must be 2, actually %d", argc); | ||
| 31 | child_idx = atoi (argv[1]); | ||
| 32 | |||
| 33 | random_init (0); | ||
| 34 | random_bytes (buf1, sizeof buf1); | ||
| 35 | |||
| 36 | CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name); | ||
| 37 | ofs = 0; | ||
| 38 | while (ofs < sizeof buf2) | ||
| 39 | { | ||
| 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); | ||
| 44 | if (bytes_read > 0) | ||
| 45 | { | ||
| 46 | compare_bytes (buf2 + ofs, buf1 + ofs, bytes_read, ofs, file_name); | ||
| 47 | ofs += bytes_read; | ||
| 48 | } | ||
| 49 | } | ||
| 50 | close (fd); | ||
| 51 | |||
| 52 | return child_idx; | ||
| 53 | } | ||
