CS318 - Pintos
Pintos source browser for JHU CS318 course
Macros | Functions | Variables
page-merge-seq.c File Reference
#include <syscall.h>
#include "tests/arc4.h"
#include "tests/lib.h"
#include "tests/main.h"
Include dependency graph for page-merge-seq.c:

Go to the source code of this file.

Macros

#define CHUNK_SIZE   (126 * 512)
 Generates about 1 MB of random data that is then divided into 16 chunks. More...
 
#define CHUNK_CNT   16
 Number of chunks. More...
 
#define DATA_SIZE   (CHUNK_CNT * CHUNK_SIZE)
 Buffer size. More...
 

Functions

static void init (void)
 Initialize buf1 with random data, then count the number of instances of each value within it. More...
 
static void sort_chunks (void)
 Sort each chunk of buf1 using a subprocess. More...
 
static void merge (void)
 Merge the sorted chunks in buf1 into a fully sorted buf2. More...
 
static void verify (void)
 
void test_main (void)
 tests/main.h More...
 

Variables

unsigned char buf1 [DATA_SIZE]
 
unsigned char buf2 [DATA_SIZE]
 
size_t histogram [256]
 

Macro Definition Documentation

◆ CHUNK_CNT

#define CHUNK_CNT   16

Number of chunks.

Definition at line 15 of file page-merge-seq.c.

◆ CHUNK_SIZE

#define CHUNK_SIZE   (126 * 512)

Generates about 1 MB of random data that is then divided into 16 chunks.

A separate subprocess sorts each chunk in sequence. Then we merge the chunks and verify that the result is what it should be. This is the max file size for an older version of the Pintos file system that had 126 direct blocks each pointing to a single disk sector. We could raise it now.

Definition at line 14 of file page-merge-seq.c.

◆ DATA_SIZE

#define DATA_SIZE   (CHUNK_CNT * CHUNK_SIZE)

Buffer size.

Definition at line 16 of file page-merge-seq.c.

Function Documentation

◆ init()

static void init ( void  )
static

Initialize buf1 with random data, then count the number of instances of each value within it.

Definition at line 24 of file page-merge-seq.c.

References arc4_crypt(), arc4_init(), buf1, histogram, arc4::i, and msg().

Referenced by test_main().

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

◆ merge()

static void merge ( void  )
static

Merge the sorted chunks in buf1 into a fully sorted buf2.

Definition at line 73 of file page-merge-seq.c.

References buf1, buf2, CHUNK_CNT, CHUNK_SIZE, arc4::i, and msg().

Referenced by test_main().

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

◆ sort_chunks()

static void sort_chunks ( void  )
static

Sort each chunk of buf1 using a subprocess.

Definition at line 39 of file page-merge-seq.c.

References buf1, CHECK, CHUNK_CNT, CHUNK_SIZE, close(), create(), exec(), arc4::i, msg(), open(), quiet, read(), wait(), and write().

Referenced by test_main().

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

◆ test_main()

void test_main ( void  )

tests/main.h

tests/main.h

tests/main.h

This must fail, because that directory is non-empty.

tests/main.h

This must fail.

tests/main.h

and an ordinary file in each of them, until we fill up the disk.

Then delete most of them, for two reasons. First, "tar" limits file names to 100 characters (which could be extended to 256 without much trouble). Second, a full disk has no room for the tar archive.

tests/main.h

This should terminate the process with a -1 exit code.

tests/main.h

Sets the stack pointer (esp) to an invalid value and invokes a system call, which should then terminate the process with a -1 exit code.

tests/main.h

The second close must either fail silently or terminate with exit code -1.

tests/main.h

This is valid, so it must succeed.

tests/main.h

The process must be terminated with exit code -1.

tests/main.h

The process must be terminated with -1 exit code.

tests/main.h

Must kill process.

tests/main.h

The exec system call must return -1.

tests/main.h

(Pintos does not have inheritance of file handles, so this must fail.) The parent process then attempts to use the file handle, which must succeed.

tests/main.h

The process must be terminated with -1 exit code because the argument to the system call would be above the top of the user address space.

tests/main.h

The process must be terminated with -1 exit code.

For Project 3: The bad address lies approximately 64MB below the code segment, so there is no ambiguity that this attempt must be rejected even after stack growth is implemented. Moreover, a good stack growth heuristics should probably not grow the stack for the purpose of reading the system call number and arguments.

tests/main.h

This must work.

tests/main.h

This may fail or terminate the process with -1 exit code.

tests/main.h

The first call must wait in the usual way and return the exit code. The second wait call must return -1 immediately.

tests/main.h

Tries to write to a mapping present in the parent. The process must be terminated with -1 exit code.

tests/main.h

Then dereferences the address that we tried to map, and the process must be terminated with -1 exit code.

Definition at line 131 of file page-merge-seq.c.

References init(), merge(), sort_chunks(), and verify().

Here is the call graph for this function:

◆ verify()

static void verify ( void  )
static

Definition at line 108 of file page-merge-seq.c.

References buf2, fail(), histogram, and msg().

Referenced by test_main().

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

Variable Documentation

◆ buf1

unsigned char buf1[DATA_SIZE]

Definition at line 18 of file page-merge-seq.c.

Referenced by init(), merge(), and sort_chunks().

◆ buf2

unsigned char buf2[DATA_SIZE]

Definition at line 18 of file page-merge-seq.c.

Referenced by merge(), and verify().

◆ histogram

size_t histogram[256]

Definition at line 19 of file page-merge-seq.c.

Referenced by init(), and verify().