CS318 - Pintos
Pintos source browser for JHU CS318 course
Macros | Functions | Variables
lib.h File Reference
#include <debug.h>
#include <stdbool.h>
#include <stddef.h>
#include <syscall.h>
Include dependency graph for lib.h:

Go to the source code of this file.

Macros

#define CHECK(SUCCESS, ...)
 Takes an expression to test for SUCCESS and a message, which may include printf-style arguments. More...
 

Functions

void msg (const char *,...) PRINTF_FORMAT(1
 
void void fail (const char *,...) PRINTF_FORMAT(1
 
void shuffle (void *, 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 filesize)
 
void check_file (const char *file_name, const void *buf, size_t filesize)
 
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
 
void void NO_RETURN
 

Macro Definition Documentation

◆ CHECK

#define CHECK (   SUCCESS,
  ... 
)
Value:
do \
{ \
msg (__VA_ARGS__); \
if (!(SUCCESS)) \
fail (__VA_ARGS__); \
} \
while (0)

Takes an expression to test for SUCCESS and a message, which may include printf-style arguments.

Logs the message, then tests the expression. If it is zero, indicating failure, emits the message as a failure.

Somewhat tricky to use:

  • SUCCESS must not have side effects that affect the message, because that will cause the original message and the failure message to differ.
  • The message must not have side effects of its own, because it will be printed twice on failure, or zero times on success if quiet is set.

Definition at line 29 of file lib.h.

Function Documentation

◆ check_file()

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

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  filesize 
)

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 void fail ( const char *  ,
  ... 
)

Definition at line 40 of file lib.c.

◆ msg()

void msg ( const char *  ,
  ... 
)

Definition at line 28 of file lib.c.

◆ shuffle()

void shuffle ( void *  ,
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:

◆ 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

◆ NO_RETURN

void void NO_RETURN

Definition at line 13 of file lib.h.

◆ quiet

bool quiet

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.)

Child process for syn-read test.

Attempts to close the file descriptor passed as the first command-line argument. This is invalid, because file descriptors are not inherited in Pintos. Two results are allowed: either the system call should return without taking any action, or the kernel should terminate the process with a -1 exit code.

Child process for syn-read test.

Opens and tries to write to its own executable, verifying that that is disallowed. Then recursively executes itself to the depth indicated by the first command-line argument.

Child process for syn-read test.

Just prints a single message and terminates.

Child process for syn-read test.

Child process for syn-read test.

Encrypts 1 MB of zeros, then decrypts it, and ensures that the zeros are back.

Child process for syn-read test.


Child process for syn-read test.

The sorted data is written back to the same file in-place.

Definition at line 14 of file child-syn-read.c.

Referenced by consume_some_resources(), main(), spawn_child(), and vmsg().