PKUOS - Pintos
Pintos source browser for PKU Operating System course
Functions | Variables
lib.c File Reference
#include "tests/lib.h"
#include <random.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <syscall.h>
Include dependency graph for lib.c:

Go to the source code of this file.

Functions

static void vmsg (const char *format, va_list args, const char *suffix)
 
void msg (const char *format,...)
 
void fail (const char *format,...)
 
static void swap (void *a_, void *b_, size_t size)
 
void shuffle (void *buf_, size_t cnt, size_t size)
 
void exec_children (const char *child_name, pid_t pids[], size_t child_cnt)
 
void wait_children (pid_t pids[], size_t child_cnt)
 
void check_file_handle (int fd, const char *file_name, const void *buf_, size_t size)
 
void check_file (const char *file_name, const void *buf, size_t size)
 
void compare_bytes (const void *read_data_, const void *expected_data_, size_t size, size_t ofs, const char *file_name)
 test/lib.h More...
 

Variables

const char * test_name
 Child process for syn-read test. More...
 
bool quiet = false
 

Function Documentation

◆ check_file()

void check_file ( const char *  file_name,
const void *  buf,
size_t  size 
)

Definition at line 151 of file lib.c.

References buf, CHECK, check_file_handle(), close(), file_name, msg(), and open().

Referenced by seq_test(), and test_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_file_handle()

void check_file_handle ( int  fd,
const char *  file_name,
const void *  buf_,
size_t  size 
)

Definition at line 108 of file lib.c.

References block_size(), buf, compare_bytes(), fail(), file_name, filesize(), msg(), and read().

Referenced by check_file(), and test_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ 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 at line 163 of file lib.c.

References fail(), file_name, hex_dump(), memcmp(), msg(), and quiet.

Referenced by check_file_handle(), main(), and test_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exec_children()

void exec_children ( const char *  child_name,
pid_t  pids[],
size_t  child_cnt 
)

Definition at line 80 of file lib.c.

References CHECK, exec(), PID_ERROR, and snprintf().

Referenced by test_main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fail()

void fail ( const char *  format,
  ... 
)

Definition at line 40 of file lib.c.

References exit(), va_end, va_start, and vmsg().

Referenced by check_file_handle(), check_file_size(), check_tell(), compare_bytes(), main(), seq_test(), test_main(), test_sleep(), verify(), wrap_open(), and write_some_bytes().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ msg()

void msg ( const char *  format,
  ... 
)

◆ shuffle()

void shuffle ( void *  buf_,
size_t  cnt,
size_t  size 
)

Definition at line 67 of file lib.c.

References buf, random_ulong(), and swap().

Here is the call graph for this function:

◆ swap()

static void swap ( void *  a_,
void *  b_,
size_t  size 
)
static

Definition at line 52 of file lib.c.

Referenced by shuffle().

Here is the caller graph for this function:

◆ vmsg()

static void vmsg ( const char *  format,
va_list  args,
const char *  suffix 
)
static

Definition at line 12 of file lib.c.

References buf, snprintf(), STDOUT_FILENO, strlcpy(), strlen(), test_name, vsnprintf(), and write().

Referenced by fail(), and msg().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wait_children()

void wait_children ( pid_t  pids[],
size_t  child_cnt 
)

Definition at line 94 of file lib.c.

References CHECK, and wait().

Referenced by test_main().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ quiet

bool quiet = false

Definition at line 9 of file lib.c.

Referenced by compare_bytes(), main(), make_tree(), msg(), remove_tree(), sort_chunks(), test_main(), and try_write().

◆ test_name

const char* test_name

Child process for syn-read test.

Reads the contents of a test file a byte at a time, in the hope that this will take long enough that we can get a significant amount of contention in the kernel file system code.

Child process for syn-read test.

Reads from a file created by our parent process, which is growing it. We loop until we've read the whole file successfully. Many iterations through the loop will return 0 bytes, because the file has not grown in the meantime. That is, we are "busy waiting" for the file to grow. (This test could be improved by adding a "yield" system call and calling yield whenever we receive a 0-byte read.)

Definition at line 8 of file lib.c.

Referenced by vmsg().