summaryrefslogtreecommitdiffstats
path: root/src/tests/filesys/base/syn-write.c
diff options
context:
space:
mode:
authorFelipe Boeira <felipe.boeira@liu.se>2019-01-08 18:39:03 +0100
committerFelipe Boeira <felipe.boeira@liu.se>2019-01-08 18:39:03 +0100
commitd4522b8e9854178473adcea0fbb84f23f6e744bd (patch)
treefbcf620617c5023154eba3f965b3a982daa64a47 /src/tests/filesys/base/syn-write.c
downloadpintos-d4522b8e9854178473adcea0fbb84f23f6e744bd.tar.gz
Initial commit
Diffstat (limited to 'src/tests/filesys/base/syn-write.c')
-rw-r--r--src/tests/filesys/base/syn-write.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/tests/filesys/base/syn-write.c b/src/tests/filesys/base/syn-write.c
new file mode 100644
index 0000000..1439862
--- /dev/null
+++ b/src/tests/filesys/base/syn-write.c
@@ -0,0 +1,31 @@
+/* Spawns several child processes to write out different parts of
+ the contents of a file and waits for them to finish. Then
+ reads back the file and verifies its contents. */
+
+#include <random.h>
+#include <stdio.h>
+#include <string.h>
+#include <syscall.h>
+#include "tests/filesys/base/syn-write.h"
+#include "tests/lib.h"
+#include "tests/main.h"
+
+char buf1[BUF_SIZE];
+char buf2[BUF_SIZE];
+
+void
+test_main (void)
+{
+ pid_t children[CHILD_CNT];
+ int fd;
+
+ CHECK (create (file_name, sizeof buf1), "create \"%s\"", file_name);
+
+ exec_children ("child-syn-wrt", children, CHILD_CNT);
+ wait_children (children, CHILD_CNT);
+
+ CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
+ CHECK (read (fd, buf1, sizeof buf1) > 0, "read \"%s\"", file_name);
+ random_bytes (buf2, sizeof buf2);
+ compare_bytes (buf1, buf2, sizeof buf1, 0, file_name);
+}