19e9d592207cfa464758742cc3f2d319fc260eee
[pintos-anon] / src / tests / filesys / base / syn-write.c
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 (filename, sizeof buf1), "create \"%s\"", filename);
23
24   exec_children ("child-syn-wrt", children, CHILD_CNT);
25   wait_children (children, CHILD_CNT);
26
27   CHECK ((fd = open (filename)) > 1, "open \"%s\"", filename);
28   CHECK (read (fd, buf1, sizeof buf1) > 0, "read \"%s\"", filename);
29   random_bytes (buf2, sizeof buf2);
30   compare_bytes (buf1, buf2, sizeof buf1, 0, filename);
31 }