PKUOS - Pintos
Pintos source browser for PKU Operating System course
syn-rw.c
Go to the documentation of this file.
1/** Grows a file in chunks while subprocesses read the growing
2 file. */
3
4#include <random.h>
5#include <syscall.h>
7#include "tests/lib.h"
8#include "tests/main.h"
9
11
12#define CHILD_CNT 4
13
14void
15test_main (void)
16{
17 pid_t children[CHILD_CNT];
18 size_t ofs;
19 int fd;
20
21 CHECK (create (file_name, 0), "create \"%s\"", file_name);
22 CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
23
24 exec_children ("child-syn-rw", children, CHILD_CNT);
25
26 random_bytes (buf, sizeof buf);
27 quiet = true;
28 for (ofs = 0; ofs < BUF_SIZE; ofs += CHUNK_SIZE)
29 CHECK (write (fd, buf + ofs, CHUNK_SIZE) > 0,
30 "write %d bytes at offset %zu in \"%s\"",
31 (int) CHUNK_SIZE, ofs, file_name);
32 quiet = false;
33
34 wait_children (children, CHILD_CNT);
35}
bool create(const char *file, unsigned initial_size)
Definition: syscall.c:91
int open(const char *file)
Definition: syscall.c:103
int write(int fd, const void *buffer, unsigned size)
Definition: syscall.c:121
int pid_t
Process identifier.
Definition: syscall.h:8
void wait_children(pid_t pids[], size_t child_cnt)
Definition: lib.c:94
bool quiet
Definition: lib.c:9
void exec_children(const char *child_name, pid_t pids[], size_t child_cnt)
Definition: lib.c:80
#define CHECK(SUCCESS,...)
Takes an expression to test for SUCCESS and a message, which may include printf-style arguments.
Definition: lib.h:29
void random_bytes(void *buf_, size_t size)
Writes SIZE random bytes into BUF.
Definition: random.c:54
#define BUF_SIZE
Definition: syn-read.h:4
static const char file_name[]
tests/filesys/base/syn-read.h
Definition: syn-read.h:5
void test_main(void)
tests/main.h
Definition: syn-rw.c:15
char buf[BUF_SIZE]
Grows a file in chunks while subprocesses read the growing file.
Definition: syn-rw.c:10
#define CHILD_CNT
Definition: syn-rw.c:12
#define CHUNK_SIZE
Definition: syn-write.h:5