PKUOS - Pintos
Pintos source browser for PKU Operating System course
child-syn-read.c
Go to the documentation of this file.
1/** Child process for syn-read test.
2 Reads the contents of a test file a byte at a time, in the
3 hope that this will take long enough that we can get a
4 significant amount of contention in the kernel file system
5 code. */
6
7#include <random.h>
8#include <stdio.h>
9#include <stdlib.h>
10#include <syscall.h>
11#include "tests/lib.h"
13
14const char *test_name = "child-syn-read";
15
16static char buf[BUF_SIZE];
17
18int
19main (int argc, const char *argv[])
20{
21 int child_idx;
22 int fd;
23 size_t i;
24
25 quiet = true;
26
27 CHECK (argc == 2, "argc must be 2, actually %d", argc);
28 child_idx = atoi (argv[1]);
29
30 random_init (0);
31 random_bytes (buf, sizeof buf);
32
33 CHECK ((fd = open (file_name)) > 1, "open \"%s\"", file_name);
34 for (i = 0; i < sizeof buf; i++)
35 {
36 char c;
37 CHECK (read (fd, &c, 1) > 0, "read \"%s\"", file_name);
38 compare_bytes (&c, buf + i, 1, i, file_name);
39 }
40 close (fd);
41
42 return child_idx;
43}
44
static char buf[BUF_SIZE]
const char * test_name
Child process for syn-read test.
int main(int argc, const char *argv[])
int atoi(const char *s)
Converts a string representation of a signed decimal integer in S into an ‘int’, which is returned.
Definition: stdlib.c:10
void close(int fd)
Definition: syscall.c:139
int open(const char *file)
Definition: syscall.c:103
int read(int fd, void *buffer, unsigned size)
Definition: syscall.c:115
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
bool quiet
Definition: lib.c:9
#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
void random_init(unsigned seed)
Initializes or reinitializes the PRNG with the given SEED.
Definition: random.c:34
#define BUF_SIZE
Definition: syn-read.h:4
static const char file_name[]
tests/filesys/base/syn-read.h
Definition: syn-read.h:5