CS318 - Pintos
Pintos source browser for JHU CS318 course
syn-write.c
Go to the documentation of this file.
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>
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 }
lib.h
buf1
char buf1[BUF_SIZE]
Spawns several child processes to write out different parts of the contents of a file and waits for t...
Definition: syn-write.c:13
string.h
CHECK
#define CHECK(SUCCESS,...)
Takes an expression to test for SUCCESS and a message, which may include printf-style arguments.
Definition: lib.h:29
buf2
char buf2[BUF_SIZE]
Definition: syn-write.c:14
CHILD_CNT
#define CHILD_CNT
Definition: syn-read.c:14
random_bytes
void random_bytes(void *buf_, size_t size)
Writes SIZE random bytes into BUF.
Definition: random.c:54
compare_bytes
void compare_bytes(const void *read_data_, const void *expected_data_, size_t size, size_t ofs, const char *file_name)
test/lib.h
Definition: lib.c:163
random.h
syn-write.h
open
int open(const char *file)
Definition: syscall.c:103
wait_children
void wait_children(pid_t pids[], size_t child_cnt)
Definition: lib.c:94
file_name
static const char file_name[]
tests/filesys/base/syn-read.h
Definition: syn-read.h:5
main.h
pid_t
int pid_t
Process identifier.
Definition: syscall.h:8
exec_children
void exec_children(const char *child_name, pid_t pids[], size_t child_cnt)
Definition: lib.c:80
BUF_SIZE
#define BUF_SIZE
Definition: syn-read.h:4
read
int read(int fd, void *buffer, unsigned size)
Definition: syscall.c:115
create
bool create(const char *file, unsigned initial_size)
Definition: syscall.c:91
test_main
void test_main(void)
tests/main.h
Definition: syn-write.c:17