CS318 - Pintos
Pintos source browser for JHU CS318 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 
14 const char *test_name = "child-syn-read";
15 
16 static char buf[BUF_SIZE];
17 
18 int
19 main (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 
lib.h
buf
static char buf[BUF_SIZE]
Definition: child-syn-read.c:16
syn-read.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
atoi
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
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
random_init
void random_init(unsigned seed)
Initializes or reinitializes the PRNG with the given SEED.
Definition: random.c:34
open
int open(const char *file)
Definition: syscall.c:103
main
int main(int argc, const char *argv[])
Definition: child-syn-read.c:19
file_name
static const char file_name[]
tests/filesys/base/syn-read.h
Definition: syn-read.h:5
close
void close(int fd)
Definition: syscall.c:139
stdlib.h
test_name
const char * test_name
Child process for syn-read test.
Definition: child-syn-read.c:14
BUF_SIZE
#define BUF_SIZE
Definition: syn-read.h:4
read
int read(int fd, void *buffer, unsigned size)
Definition: syscall.c:115
quiet
bool quiet
Definition: lib.c:9