diff options
Diffstat (limited to 'pintos-progos/tests/filesys/base/child-syn-read.c')
| -rw-r--r-- | pintos-progos/tests/filesys/base/child-syn-read.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/pintos-progos/tests/filesys/base/child-syn-read.c b/pintos-progos/tests/filesys/base/child-syn-read.c new file mode 100644 index 0000000..77a5e26 --- /dev/null +++ b/pintos-progos/tests/filesys/base/child-syn-read.c | |||
| @@ -0,0 +1,44 @@ | |||
| 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 | const char *test_name = "child-syn-read"; | ||
| 15 | |||
| 16 | static char buf[BUF_SIZE]; | ||
| 17 | |||
| 18 | int | ||
| 19 | main (int argc, const char *argv[]) | ||
| 20 | { | ||
| 21 | int child_idx; | ||
| 22 | int fd; | ||
| 23 | size_t i; | ||
| 24 | |||
| 25 | quiet = true; | ||
| 26 | |||
| 27 | CHECK (argc == 2, "argc must be 2, actually %d", argc); | ||
| 28 | child_idx = atoi (argv[1]); | ||
| 29 | |||
| 30 | random_init (0); | ||
| 31 | random_bytes (buf, sizeof buf); | ||
| 32 | |||
| 33 | CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name); | ||
| 34 | for (i = 0; i < sizeof buf; i++) | ||
| 35 | { | ||
| 36 | char c; | ||
| 37 | CHECK (read (fd, &c, 1) > 0, "read \"%s\"", file_name); | ||
| 38 | compare_bytes (&c, buf + i, 1, i, file_name); | ||
| 39 | } | ||
| 40 | close (fd); | ||
| 41 | |||
| 42 | return child_idx; | ||
| 43 | } | ||
| 44 | |||
