27db47152f49b62f092ae4952ae51cf0d7a3c47f
[pintos-anon] / src / tests / filesys / base / syn-read.c
1 /* Spawns 10 child processes, all of which read from the same
2    file and make sure that the contents are what they should
3    be. */
4
5 #include <random.h>
6 #include <stdio.h>
7 #include <syscall.h>
8 #include "tests/lib.h"
9 #include "tests/main.h"
10 #include "tests/filesys/base/syn-read.h"
11
12 static char buf[BUF_SIZE];
13
14 #define CHILD_CNT 10
15
16 void
17 test_main (void) 
18 {
19   pid_t children[CHILD_CNT];
20   int fd;
21
22   CHECK (create (filename, sizeof buf), "create \"%s\"", filename);
23   CHECK ((fd = open (filename)) > 1, "open \"%s\"", filename);
24   random_bytes (buf, sizeof buf);
25   CHECK (write (fd, buf, sizeof buf) > 0, "write \"%s\"", filename);
26   msg ("close \"%s\"", filename);
27   close (fd);
28
29   exec_children ("child-syn-read", children, CHILD_CNT);
30   wait_children (children, CHILD_CNT);
31 }