diff options
Diffstat (limited to 'tests/filesys/base/syn-write.c')
| -rw-r--r-- | tests/filesys/base/syn-write.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/filesys/base/syn-write.c b/tests/filesys/base/syn-write.c new file mode 100644 index 0000000..1439862 --- /dev/null +++ b/tests/filesys/base/syn-write.c | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | /* Spawns several child processes to write out different parts of | ||
| 2 | the contents of a file and waits for them to finish. Then | ||
| 3 | reads back the file and verifies its contents. */ | ||
| 4 | |||
| 5 | #include <random.h> | ||
| 6 | #include <stdio.h> | ||
| 7 | #include <string.h> | ||
| 8 | #include <syscall.h> | ||
| 9 | #include "tests/filesys/base/syn-write.h" | ||
| 10 | #include "tests/lib.h" | ||
| 11 | #include "tests/main.h" | ||
| 12 | |||
| 13 | char buf1[BUF_SIZE]; | ||
| 14 | char buf2[BUF_SIZE]; | ||
| 15 | |||
| 16 | void | ||
| 17 | test_main (void) | ||
| 18 | { | ||
| 19 | pid_t children[CHILD_CNT]; | ||
| 20 | int fd; | ||
| 21 | |||
| 22 | CHECK (create (file_name, sizeof buf1), "create \"%s\"", file_name); | ||
| 23 | |||
| 24 | exec_children ("child-syn-wrt", children, CHILD_CNT); | ||
| 25 | wait_children (children, CHILD_CNT); | ||
| 26 | |||
| 27 | CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name); | ||
| 28 | CHECK (read (fd, buf1, sizeof buf1) > 0, "read \"%s\"", file_name); | ||
| 29 | random_bytes (buf2, sizeof buf2); | ||
| 30 | compare_bytes (buf1, buf2, sizeof buf1, 0, file_name); | ||
| 31 | } | ||
