+/* Prints the command-line arguments.
+ This program is used for all of the args-* tests. Grading is
+ done differently for each of the args-* tests based on the
+ output. */
+
#include "tests/lib.h"
int
+/* Utility function for tests that try to break system calls by
+ passing them data that crosses from one virtual page to
+ another. */
+
#include <inttypes.h>
#include <round.h>
#include <string.h>
+/* Child process run by wait-killed test.
+ 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. */
+
#include "tests/lib.h"
#include "tests/main.h"
+/* Child process run by multi-child-fd 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. */
+
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
+/* Child process run by rox-child and rox-multichild tests.
+ 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. */
+
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
+/* Child process run by exec-multiple, exec-one, wait-simple, and
+ wait-twice tests.
+ Just prints a single message and terminates. */
+
#include <stdio.h>
#include "tests/lib.h"
+/* Tries to close an invalid fd, which must either fail silently
+ or terminate with exit code -1. */
+
#include <syscall.h>
#include "tests/main.h"
+/* Opens a file and then closes it. */
+
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
+/* Tries to close the keyboard input stream, which must either
+ fail silently or terminate with exit code -1. */
+
#include <syscall.h>
#include "tests/main.h"
+/* Tries to close the console output stream, which must either
+ fail silently or terminate with exit code -1. */
+
#include <syscall.h>
#include "tests/main.h"
+/* Opens a file and then tries to close it twice. The second
+ close must either fail silently or terminate with exit code
+ -1. */
+
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
+/* Passes a bad pointer to the create system call,
+ which must cause the process to be terminated with exit code
+ -1. */
+
#include "tests/lib.h"
#include "tests/main.h"
+/* Opens a file whose name spans the boundary between two pages.
+ This is valid, so it must succeed. */
+
#include <syscall.h>
#include "tests/userprog/boundary.h"
#include "tests/lib.h"
+/* Tries to create a file with the empty string as its name. */
+
#include "tests/lib.h"
#include "tests/main.h"
+/* Verifies that trying to create a file under a name that
+ already exists will fail. */
+
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
+/* Tries to create a file with a name that is much too long,
+ which must fail. */
+
#include <string.h>
#include <syscall.h>
#include "tests/lib.h"
+/* Creates an ordinary empty file. */
+
#include "tests/lib.h"
#include "tests/main.h"
+/* Tries to create a file with the null pointer as its name.
+ The process must be terminated with exit code -1. */
+
#include "tests/lib.h"
#include "tests/main.h"
+/* Tests argument passing to child processes. */
+
#include <syscall.h>
#include "tests/main.h"
+/* Passes an invalid pointer to the exec system call.
+ The process must be terminated with -1 exit code. */
+
#include <syscall.h>
#include "tests/main.h"
+/* Tries to execute a nonexistent process.
+ The exec system call must return -1. */
+
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
+/* Executes and waits for multiple child processes. */
+
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
+/* Executes and waits for a single child process. */
+
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
+/* Tests the exit system call. */
+
#include "tests/lib.h"
#include "tests/main.h"
+/* Tests the halt system call. */
+
#include "tests/lib.h"
#include "tests/main.h"
+/* Opens a file and then runs a subprocess that tries to close
+ the file. (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. */
+
#include <stdio.h>
#include <syscall.h>
#include "tests/userprog/sample.inc"
+/* Executes itself recursively to the depth indicated by the
+ first command-line argument. */
+
#include <debug.h>
#include <stdlib.h>
#include <stdio.h>
main (int argc UNUSED, char *argv[])
{
int n = atoi (argv[1]);
- if (n == 0)
- n = atoi (argv[0]);
msg ("begin %d", n);
if (n != 0)
+/* Passes an invalid pointer to the open system call.
+ The process must be terminated with -1 exit code. */
+
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
+/* Creates a file whose name spans the boundary between two pages.
+ This is valid, so it must succeed. */
+
#include <syscall.h>
#include "tests/userprog/boundary.h"
#include "tests/lib.h"
+/* Tries to open a file with the empty string as its name. */
+
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
+/* Tries to open a nonexistent file. */
+
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
+/* Open a file. */
+
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
+/* Tries to open a file with the null pointer as its name.
+ The process must be terminated with exit code -1. */
+
#include <stddef.h>
#include <syscall.h>
#include "tests/main.h"
+/* Tries to open the same file twice,
+ which must succeed and must return a different file descriptor
+ in each case. */
+
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
+/* Tries to read from an invalid fd,
+ which must either fail silently or terminate the process with
+ exit code -1. */
+
#include <limits.h>
#include <syscall.h>
#include "tests/lib.h"
+/* Passes an invalid pointer to the read system call.
+ The process must be terminated with -1 exit code. */
+
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
+/* Reads data spanning two pages in virtual address space,
+ which must succeed. */
+
#include <string.h>
#include <syscall.h>
#include "tests/userprog/boundary.h"
+/* Try reading a file in the most normal way. */
+
#include "tests/userprog/sample.inc"
#include "tests/lib.h"
#include "tests/main.h"
+/* Try reading from fd 1 (stdout),
+ which may just fail or terminate the process with -1 exit
+ code. */
+
#include <stdio.h>
#include <syscall.h>
#include "tests/main.h"
+/* Try a 0-byte read, which should return 0 without reading
+ anything. */
+
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
+/* Ensure that the executable of a running process cannot be
+ modified, even by a child process. */
+
#define CHILD_CNT "1"
#include "tests/userprog/rox-child.inc"
+/* Ensure that the executable of a running process cannot be
+ modified, even in the presence of multiple children. */
+
#define CHILD_CNT "5"
#include "tests/userprog/rox-child.inc"
+/* Ensure that the executable of a running process cannot be
+ modified. */
+
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
+/* Sticks a system call number (SYS_exit) at the very top of the
+ stack, then invokes a system call with the stack pointer
+ (%esp) set to its address. 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. */
+
#include <syscall-nr.h>
#include "tests/lib.h"
#include "tests/main.h"
+/* Invokes a system call with the stack pointer (%esp) set to a
+ bad address. The process must be terminated with -1 exit
+ code. */
+
#include "tests/lib.h"
#include "tests/main.h"
+/* Invokes a system call with one byte of the system call's
+ argument on a separate page from the rest of the bytes. This
+ must work. */
+
#include <syscall-nr.h>
#include "tests/userprog/boundary.h"
#include "tests/lib.h"
+/* Invokes a system call with the system call number and its
+ argument on separate pages. This must work. */
+
#include <syscall-nr.h>
#include "tests/userprog/boundary.h"
#include "tests/lib.h"
+/* Waits for an invalid pid. This may fail or terminate the
+ process with -1 exit code. */
+
#include <syscall.h>
#include "tests/main.h"
+/* Wait for a process that will be killed for bad behavior. */
+
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
+/* Wait for a subprocess to finish. */
+
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
+/* Wait for a subprocess to finish, twice.
+ The first call must wait in the usual way and return the exit code.
+ The second wait call must return -1 immediately. */
+
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
+/* Tries to write to an invalid fd,
+ which must either fail silently or terminate the process with
+ exit code -1. */
+
#include <limits.h>
#include <syscall.h>
#include "tests/main.h"
+/* Passes an invalid pointer to the write system call.
+ The process must be terminated with -1 exit code. */
+
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
+/* Writes data spanning two pages in virtual address space,
+ which must succeed. */
+
#include <string.h>
#include <syscall.h>
#include "tests/userprog/boundary.h"
+/* Try writing a file in the most normal way. */
+
#include <syscall.h>
#include "tests/userprog/sample.inc"
#include "tests/lib.h"
+/* Try writing to fd 0 (stdin),
+ which may just fail or terminate the process with -1 exit
+ code. */
+
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
+/* Try a 0-byte write, which should return 0 without writing
+ anything. */
+
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"