CS318 - Pintos
Pintos source browser for JHU CS318 course
syn-read.c
Go to the documentation of this file.
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"
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 (file_name, sizeof buf), "create \"%s\"", file_name);
23  CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
24  random_bytes (buf, sizeof buf);
25  CHECK (write (fd, buf, sizeof buf) > 0, "write \"%s\"", file_name);
26  msg ("close \"%s\"", file_name);
27  close (fd);
28 
29  exec_children ("child-syn-read", children, CHILD_CNT);
30  wait_children (children, CHILD_CNT);
31 }
lib.h
syn-read.h
write
int write(int fd, const void *buffer, unsigned size)
Definition: syscall.c:121
CHECK
#define CHECK(SUCCESS,...)
Takes an expression to test for SUCCESS and a message, which may include printf-style arguments.
Definition: lib.h:29
CHILD_CNT
#define CHILD_CNT
Definition: syn-read.c:14
test_main
void test_main(void)
tests/main.h
Definition: syn-read.c:17
random_bytes
void random_bytes(void *buf_, size_t size)
Writes SIZE random bytes into BUF.
Definition: random.c:54
random.h
buf
static char buf[BUF_SIZE]
Spawns 10 child processes, all of which read from the same file and make sure that the contents are w...
Definition: syn-read.c:12
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
close
void close(int fd)
Definition: syscall.c:139
exec_children
void exec_children(const char *child_name, pid_t pids[], size_t child_cnt)
Definition: lib.c:80
msg
void msg(const char *format,...)
Definition: lib.c:28
BUF_SIZE
#define BUF_SIZE
Definition: syn-read.h:4
create
bool create(const char *file, unsigned initial_size)
Definition: syscall.c:91