aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/filesys/base/syn-write.c
blob: 1439862dd2ddf1aba0816deaad0e13014aaa4a91 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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);
}