code stringlengths 1 2.01M | repo_name stringlengths 3 62 | path stringlengths 1 267 | language stringclasses 231
values | license stringclasses 13
values | size int64 1 2.01M |
|---|---|---|---|---|---|
#ifndef FILESYS_FSUTIL_H
#define FILESYS_FSUTIL_H
void fsutil_ls (char **argv);
void fsutil_cat (char **argv);
void fsutil_rm (char **argv);
void fsutil_extract (char **argv);
void fsutil_append (char **argv);
#endif /* filesys/fsutil.h */
| 10cm | trunk/10cm/pintos/src/filesys/fsutil.h | C | oos | 243 |
#include "filesys/directory.h"
#include <stdio.h>
#include <string.h>
#include <list.h>
#include "filesys/filesys.h"
#include "filesys/inode.h"
#include "threads/malloc.h"
/* A directory. */
struct dir
{
struct inode *inode; /* Backing store. */
off_t pos; /* Current position. */
};
/* A single directory entry. */
struct dir_entry
{
disk_sector_t inode_sector; /* Sector number of header. */
char name[NAME_MAX + 1]; /* Null terminated file name. */
bool in_use; /* In use or free? */
};
/* Create a directory with space for ENTRY_CNT entries in the
given SECTOR. Returns true if successful, false on failure. */
bool
dir_create (disk_sector_t sector, size_t entry_cnt)
{
return inode_create (sector, entry_cnt * sizeof (struct dir_entry));
}
/* Opens and returns the directory for the given INODE, of which
it takes ownership. Returns a null pointer on failure. */
struct dir *
dir_open (struct inode *inode)
{
struct dir *dir = calloc (1, sizeof *dir);
if (inode != NULL && dir != NULL)
{
dir->inode = inode;
dir->pos = 0;
return dir;
}
else
{
inode_close (inode);
free (dir);
return NULL;
}
}
/* Opens the root directory and returns a directory for it.
Return true if successful, false on failure. */
struct dir *
dir_open_root (void)
{
return dir_open (inode_open (ROOT_DIR_SECTOR));
}
/* Opens and returns a new directory for the same inode as DIR.
Returns a null pointer when failure occurs. */
struct dir *
dir_reopen (struct dir *dir)
{
return dir_open (inode_reopen (dir->inode));
}
/* Destroys DIR and frees associated resources. */
void
dir_close (struct dir *dir)
{
if (dir != NULL)
{
inode_close (dir->inode);
free (dir);
}
}
/* Returns the inode encapsulated by DIR. */
struct inode *
dir_get_inode (struct dir *dir)
{
return dir->inode;
}
/* Searches DIR for a file with the given NAME.
If successful, returns true, sets *EP to the directory entry
if EP is non-null, and sets *OFSP to the byte offset of the
directory entry if OFSP is not null.
otherwise, returns false and ignores EP and OFSP. */
static bool
lookup (const struct dir *dir, const char *name,
struct dir_entry *ep, off_t *ofsp)
{
struct dir_entry e;
size_t ofs;
ASSERT (dir != NULL);
ASSERT (name != NULL);
for (ofs = 0; inode_read_at (dir->inode, &e, sizeof e, ofs) == sizeof e;
ofs += sizeof e)
if (e.in_use && !strcmp (name, e.name))
{
if (ep != NULL)
*ep = e;
if (ofsp != NULL)
*ofsp = ofs;
return true;
}
return false;
}
/* Searches DIR for a file with the given NAME
and returns true if one exists, false otherwise.
On success, sets *INODE to an inode for the file, otherwise to
a null pointer. The caller must close *INODE. */
bool
dir_lookup (const struct dir *dir, const char *name,
struct inode **inode)
{
struct dir_entry e;
ASSERT (dir != NULL);
ASSERT (name != NULL);
if (lookup (dir, name, &e, NULL))
*inode = inode_open (e.inode_sector);
else
*inode = NULL;
return *inode != NULL;
}
/* Adds a file named NAME to DIR, which must not already contain a
file by that name. The file's inode is in sector
INODE_SECTOR.
Returns true on success, false on failure.
Fails if NAME is invalid (i.e. too long) or a disk or memory
error occurs. */
bool
dir_add (struct dir *dir, const char *name, disk_sector_t inode_sector)
{
struct dir_entry e;
off_t ofs;
bool success = false;
ASSERT (dir != NULL);
ASSERT (name != NULL);
/* Check NAME for validity. */
if (*name == '\0' || strlen (name) > NAME_MAX)
return false;
/* Check NAME is not in use. */
if (lookup (dir, name, NULL, NULL))
goto done;
/* Set OFS to offset of free slot.
If there are no free slots, then it will be set to the
current end-of-file.
inode_read_at() will only return a short read at end of file.
Otherwise, we'd need to verify that we didn't get a short
read due to something intermittent such as low memory. */
for (ofs = 0; inode_read_at (dir->inode, &e, sizeof e, ofs) == sizeof e;
ofs += sizeof e)
if (!e.in_use)
break;
/* Write slot. */
e.in_use = true;
strlcpy (e.name, name, sizeof e.name);
e.inode_sector = inode_sector;
success = inode_write_at (dir->inode, &e, sizeof e, ofs) == sizeof e;
done:
return success;
}
/* Removes any entry for NAME in DIR.
Returns true if successful, false on failure,
which occurs only if there is no file with the given NAME. */
bool
dir_remove (struct dir *dir, const char *name)
{
struct dir_entry e;
struct inode *inode = NULL;
bool success = false;
off_t ofs;
ASSERT (dir != NULL);
ASSERT (name != NULL);
/* find directory entry. */
if (!lookup (dir, name, &e, &ofs))
goto done;
/* open inode. */
inode = inode_open (e.inode_sector);
if (inode == NULL)
goto done;
/* erase directory entry. */
e.in_use = false;
if (inode_write_at (dir->inode, &e, sizeof e, ofs) != sizeof e)
goto done;
/* remove inode. */
inode_remove (inode);
success = true;
done:
inode_close (inode);
return success;
}
/* Reads the next directory entry in DIR and stores the name in
NAME. Returns true if successful, false if the directory
contains no more entries. */
bool
dir_readdir (struct dir *dir, char name[NAME_MAX + 1])
{
struct dir_entry e;
while (inode_read_at (dir->inode, &e, sizeof e, dir->pos) == sizeof e)
{
dir->pos += sizeof e;
if (e.in_use)
{
strlcpy (name, e.name, NAME_MAX + 1);
return true;
}
}
return false;
}
| 10cm | trunk/10cm/pintos/src/filesys/directory.c | C | oos | 5,843 |
include ../Makefile.kernel
| 10cm | trunk/10cm/pintos/src/filesys/Makefile | Makefile | oos | 27 |
#include "filesys/filesys.h"
#include <debug.h>
#include <stdio.h>
#include <string.h>
#include "filesys/file.h"
#include "filesys/free-map.h"
#include "filesys/inode.h"
#include "filesys/cache.h"
#include "filesys/directory.h"
#include "devices/disk.h"
/* The disk that contains the file system. */
struct disk *filesys_disk;
static void do_format (void);
/* Initialize the file system module.
If FORMAT is true, reformats the file system. */
void
filesys_init (bool format)
{
filesys_disk = disk_get (0, 1);
if (filesys_disk == NULL)
PANIC ("hd0:1 (hdb) not present, file system initialization failed");
inode_init ();
free_map_init ();
if (format)
do_format ();
free_map_open ();
}
/* Shuts down the file system module, writing any unwritten data
to disk. */
void
filesys_done (void)
{
free_map_close ();
#ifdef __BUFFER_CACHE_
cache_release();
#endif
}
/* Creates a file named NAME with the given INITIAL_SIZE
Returns true if successful, false otherwise.
Fails if a file named NAME already exists,
or if internal memory allocation fails. */
bool
filesys_create (const char *name, off_t initial_size)
{
disk_sector_t inode_sector = 0;
struct dir *dir = dir_open_root ();
bool success = (dir != NULL
&& free_map_allocate (1, &inode_sector)
&& inode_create (inode_sector, initial_size)
&& dir_add (dir, name, inode_sector));
if (!success && inode_sector != 0)
free_map_release (inode_sector, 1);
dir_close (dir);
return success;
}
/* Opens the file with the given NAME.
Returns the new file if successful or a null pointer
otherwise.
Fails if no file named NAME exists,
or if an internal memory allocation fails. */
struct file *
filesys_open (const char *name)
{
struct dir *dir = dir_open_root ();
struct inode *inode = NULL;
if (dir != NULL)
dir_lookup (dir, name, &inode);
dir_close (dir);
return file_open (inode);
}
/* Deletes the file named NAME.
Returns true if successful, false on failure.
Fails if the file named NAME dose not exist,
or if an internal memory allocation fails. */
bool
filesys_remove (const char *name)
{
struct dir *dir = dir_open_root ();
bool success = dir != NULL && dir_remove (dir, name);
dir_close (dir);
return success;
}
/* Formats the file system. */
static void
do_format (void)
{
printf ("Formatting file system...");
free_map_create ();
if (!dir_create (ROOT_DIR_SECTOR, 16))
PANIC ("root directory creation failed");
free_map_close ();
printf ("done.\n");
}
| 10cm | trunk/10cm/pintos/src/filesys/filesys.c | C | oos | 2,590 |
#include "filesys/free-map.h"
#include <bitmap.h>
#include <debug.h>
#include "filesys/file.h"
#include "filesys/filesys.h"
#include "filesys/inode.h"
static struct file *free_map_file; /* Free map file. */
static struct bitmap *free_map; /* Free map, one bit per disk sector. */
/* Initialize the free map. */
void
free_map_init (void)
{
free_map = bitmap_create (disk_size (filesys_disk));
if (free_map == NULL)
PANIC ("bitmap creation failed--disk is too large");
bitmap_mark (free_map, FREE_MAP_SECTOR);
bitmap_mark (free_map, ROOT_DIR_SECTOR);
}
/* Allocates CNT consecutive sectors from the free map and stores
the first into *SECTORP.
Returns true if successful, false if all sectors were
available. */
bool
free_map_allocate (size_t cnt, disk_sector_t *sectorp)
{
disk_sector_t sector = bitmap_scan_and_flip (free_map, 0, cnt, false);
if (sector != BITMAP_ERROR
&& free_map_file != NULL
&& !bitmap_write (free_map, free_map_file))
{
bitmap_set_multiple (free_map, sector, cnt, false);
sector = BITMAP_ERROR;
}
if (sector != BITMAP_ERROR)
*sectorp = sector;
return sector != BITMAP_ERROR;
}
/* Makes CNT sectors starting at SECTOR usable. */
void
free_map_release (disk_sector_t sector, size_t cnt)
{
ASSERT (bitmap_all (free_map, sector, cnt));
bitmap_set_multiple (free_map, sector, cnt, false);
bitmap_write (free_map, free_map_file);
}
/* Opens the free map file and reads it from disk. */
void
free_map_open (void)
{
free_map_file = file_open (inode_open (FREE_MAP_SECTOR));
if (free_map_file == NULL)
PANIC ("can't open free map");
if (!bitmap_read (free_map, free_map_file))
PANIC ("can't read free map");
}
/* Writes the free map to disk and closes the free map file. */
void
free_map_close (void)
{
file_close (free_map_file);
}
/* Creates a new free map file on disk and writes the free map to
it. */
void
free_map_create (void)
{
/* Create inode. */
if (!inode_create (FREE_MAP_SECTOR, bitmap_file_size (free_map)))
PANIC ("free map creation failed");
/* Write bitmap to file. */
free_map_file = file_open (inode_open (FREE_MAP_SECTOR));
if (free_map_file == NULL)
PANIC ("can't open free map");
if (!bitmap_write (free_map, free_map_file))
PANIC ("can't write free map");
}
| 10cm | trunk/10cm/pintos/src/filesys/free-map.c | C | oos | 2,328 |
#include <random.h>
#include "tests/lib.h"
#include "tests/main.h"
/* tests/main.c */
int
main (int argc UNUSED, char *argv[])
{
test_name = argv[0];
msg ("begin");
random_init (0);
test_main ();
msg ("end");
return 0;
}
| 10cm | trunk/10cm/pintos/src/tests/main.c | C | oos | 236 |
#ifndef TESTS_LIB_H
#define TESTS_LIB_H
#include <debug.h>
#include <stdbool.h>
#include <stddef.h>
#include <syscall.h>
extern const char *test_name;
extern bool quiet;
void msg (const char *, ...) PRINTF_FORMAT (1, 2);
void fail (const char *, ...) PRINTF_FORMAT (1, 2) NO_RETURN;
/* 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. */
#define CHECK(SUCCESS, ...) \
do \
{ \
msg (__VA_ARGS__); \
if (!(SUCCESS)) \
fail (__VA_ARGS__); \
} \
while (0)
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);
#endif /* test/lib.h */
| 10cm | trunk/10cm/pintos/src/tests/lib.h | C | oos | 1,767 |
/* Test program for sorting and searching in lib/stdlib.c.
Attempts to test the sorting and searching functionality that
is not sufficiently tested elsewhere in Pintos.
This is not a test we will run on your submitted projects.
It is here for completeness.
*/
#undef NDEBUG
#include <debug.h>
#include <limits.h>
#include <random.h>
#include <stdlib.h>
#include <stdio.h>
#include "threads/test.h"
/* Maximum number of elements in an array that we will test. */
#define MAX_CNT 4096
static void shuffle (int[], size_t);
static int compare_ints (const void *, const void *);
static void verify_order (const int[], size_t);
static void verify_bsearch (const int[], size_t);
/* Test sorting and searching implementations. */
void
test (void)
{
int cnt;
printf ("testing various size arrays:");
for (cnt = 0; cnt < MAX_CNT; cnt = cnt * 4 / 3 + 1)
{
int repeat;
printf (" %zu", cnt);
for (repeat = 0; repeat < 10; repeat++)
{
static int values[MAX_CNT];
int i;
/* Put values 0...CNT in random order in VALUES. */
for (i = 0; i < cnt; i++)
values[i] = i;
shuffle (values, cnt);
/* Sort VALUES, then verify ordering. */
qsort (values, cnt, sizeof *values, compare_ints);
verify_order (values, cnt);
verify_bsearch (values, cnt);
}
}
printf (" done\n");
printf ("stdlib: PASS\n");
}
/* Shuffles the CNT elements in ARRAY into random order. */
static void
shuffle (int *array, size_t cnt)
{
size_t i;
for (i = 0; i < cnt; i++)
{
size_t j = i + random_ulong () % (cnt - i);
int t = array[j];
array[j] = array[i];
array[i] = t;
}
}
/* Returns 1 if *A is greater than *B,
0 if *A equals *B,
-1 if *A is less than *B. */
static int
compare_ints (const void *a_, const void *b_)
{
const int *a = a_;
const int *b = b_;
return *a < *b ? -1 : *a > *b;
}
/* Verifies that ARRAY contains the CNT ints 0...CNT-1. */
static void
verify_order (const int *array, size_t cnt)
{
int i;
for (i = 0; (size_t) i < cnt; i++)
ASSERT (array[i] == i);
}
/* Checks that bsearch() works properly in ARRAY. ARRAY must
contain the values 0...CNT-1. */
static void
verify_bsearch (const int *array, size_t cnt)
{
int not_in_array[] = {0, -1, INT_MAX, MAX_CNT, MAX_CNT + 1, MAX_CNT * 2};
int i;
/* Check that all the values in the array are found properly. */
for (i = 0; (size_t) i < cnt; i++)
ASSERT (bsearch (&i, array, cnt, sizeof *array, compare_ints)
== array + i);
/* Check that some values not in the array are not found. */
not_in_array[0] = cnt;
for (i = 0; (size_t) i < sizeof not_in_array / sizeof *not_in_array; i++)
ASSERT (bsearch (¬_in_array[i], array, cnt, sizeof *array, compare_ints)
== NULL);
}
| 10cm | trunk/10cm/pintos/src/tests/internal/stdlib.c | C | oos | 2,886 |
/* Test program for printf() in lib/stdio.c.
Attempts to test printf() functionality that is not
sufficiently tested elsewhere in Pintos.
This is not a test we will run on your submitted projects.
It is here for completeness.
*/
#undef NDEBUG
#include <limits.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "threads/test.h"
/* Number of failures so far. */
static int failure_cnt;
static void
checkf (const char *expect, const char *format, ...)
{
char output[128];
va_list args;
printf ("\"%s\" -> \"%s\": ", format, expect);
va_start (args, format);
vsnprintf (output, sizeof output, format, args);
va_end (args);
if (strcmp (expect, output))
{
printf ("\nFAIL: actual output \"%s\"\n", output);
failure_cnt++;
}
else
printf ("okay\n");
}
/* Test printf() implementation. */
void
test (void)
{
printf ("Testing formats:");
/* Check that commas show up in the right places, for positive
numbers. */
checkf ("1", "%'d", 1);
checkf ("12", "%'d", 12);
checkf ("123", "%'d", 123);
checkf ("1,234", "%'d", 1234);
checkf ("12,345", "%'d", 12345);
checkf ("123,456", "%'ld", 123456L);
checkf ("1,234,567", "%'ld", 1234567L);
checkf ("12,345,678", "%'ld", 12345678L);
checkf ("123,456,789", "%'ld", 123456789L);
checkf ("1,234,567,890", "%'ld", 1234567890L);
checkf ("12,345,678,901", "%'lld", 12345678901LL);
checkf ("123,456,789,012", "%'lld", 123456789012LL);
checkf ("1,234,567,890,123", "%'lld", 1234567890123LL);
checkf ("12,345,678,901,234", "%'lld", 12345678901234LL);
checkf ("123,456,789,012,345", "%'lld", 123456789012345LL);
checkf ("1,234,567,890,123,456", "%'lld", 1234567890123456LL);
checkf ("12,345,678,901,234,567", "%'lld", 12345678901234567LL);
checkf ("123,456,789,012,345,678", "%'lld", 123456789012345678LL);
checkf ("1,234,567,890,123,456,789", "%'lld", 1234567890123456789LL);
/* Check that commas show up in the right places, for positive
numbers. */
checkf ("-1", "%'d", -1);
checkf ("-12", "%'d", -12);
checkf ("-123", "%'d", -123);
checkf ("-1,234", "%'d", -1234);
checkf ("-12,345", "%'d", -12345);
checkf ("-123,456", "%'ld", -123456L);
checkf ("-1,234,567", "%'ld", -1234567L);
checkf ("-12,345,678", "%'ld", -12345678L);
checkf ("-123,456,789", "%'ld", -123456789L);
checkf ("-1,234,567,890", "%'ld", -1234567890L);
checkf ("-12,345,678,901", "%'lld", -12345678901LL);
checkf ("-123,456,789,012", "%'lld", -123456789012LL);
checkf ("-1,234,567,890,123", "%'lld", -1234567890123LL);
checkf ("-12,345,678,901,234", "%'lld", -12345678901234LL);
checkf ("-123,456,789,012,345", "%'lld", -123456789012345LL);
checkf ("-1,234,567,890,123,456", "%'lld", -1234567890123456LL);
checkf ("-12,345,678,901,234,567", "%'lld", -12345678901234567LL);
checkf ("-123,456,789,012,345,678", "%'lld", -123456789012345678LL);
checkf ("-1,234,567,890,123,456,789", "%'lld", -1234567890123456789LL);
/* Check signed integer conversions. */
checkf (" 0", "%5d", 0);
checkf ("0 ", "%-5d", 0);
checkf (" +0", "%+5d", 0);
checkf ("+0 ", "%+-5d", 0);
checkf (" 0", "% 5d", 0);
checkf ("00000", "%05d", 0);
checkf (" ", "%5.0d", 0);
checkf (" 00", "%5.2d", 0);
checkf ("0", "%d", 0);
checkf (" 1", "%5d", 1);
checkf ("1 ", "%-5d", 1);
checkf (" +1", "%+5d", 1);
checkf ("+1 ", "%+-5d", 1);
checkf (" 1", "% 5d", 1);
checkf ("00001", "%05d", 1);
checkf (" 1", "%5.0d", 1);
checkf (" 01", "%5.2d", 1);
checkf ("1", "%d", 1);
checkf (" -1", "%5d", -1);
checkf ("-1 ", "%-5d", -1);
checkf (" -1", "%+5d", -1);
checkf ("-1 ", "%+-5d", -1);
checkf (" -1", "% 5d", -1);
checkf ("-0001", "%05d", -1);
checkf (" -1", "%5.0d", -1);
checkf (" -01", "%5.2d", -1);
checkf ("-1", "%d", -1);
checkf ("12345", "%5d", 12345);
checkf ("12345", "%-5d", 12345);
checkf ("+12345", "%+5d", 12345);
checkf ("+12345", "%+-5d", 12345);
checkf (" 12345", "% 5d", 12345);
checkf ("12345", "%05d", 12345);
checkf ("12345", "%5.0d", 12345);
checkf ("12345", "%5.2d", 12345);
checkf ("12345", "%d", 12345);
checkf ("123456", "%5d", 123456);
checkf ("123456", "%-5d", 123456);
checkf ("+123456", "%+5d", 123456);
checkf ("+123456", "%+-5d", 123456);
checkf (" 123456", "% 5d", 123456);
checkf ("123456", "%05d", 123456);
checkf ("123456", "%5.0d", 123456);
checkf ("123456", "%5.2d", 123456);
checkf ("123456", "%d", 123456);
/* Check unsigned integer conversions. */
checkf (" 0", "%5u", 0);
checkf (" 0", "%5o", 0);
checkf (" 0", "%5x", 0);
checkf (" 0", "%5X", 0);
checkf (" 0", "%#5o", 0);
checkf (" 0", "%#5x", 0);
checkf (" 0", "%#5X", 0);
checkf (" 00000000", "%#10.8x", 0);
checkf (" 1", "%5u", 1);
checkf (" 1", "%5o", 1);
checkf (" 1", "%5x", 1);
checkf (" 1", "%5X", 1);
checkf (" 01", "%#5o", 1);
checkf (" 0x1", "%#5x", 1);
checkf (" 0X1", "%#5X", 1);
checkf ("0x00000001", "%#10.8x", 1);
checkf ("123456", "%5u", 123456);
checkf ("361100", "%5o", 123456);
checkf ("1e240", "%5x", 123456);
checkf ("1E240", "%5X", 123456);
checkf ("0361100", "%#5o", 123456);
checkf ("0x1e240", "%#5x", 123456);
checkf ("0X1E240", "%#5X", 123456);
checkf ("0x0001e240", "%#10.8x", 123456);
/* Character and string conversions. */
checkf ("foobar", "%c%c%c%c%c%c", 'f', 'o', 'o', 'b', 'a', 'r');
checkf (" left-right ", "%6s%s%-7s", "left", "-", "right");
checkf ("trim", "%.4s", "trimoff");
checkf ("%%", "%%%%");
/* From Cristian Cadar's automatic test case generator. */
checkf (" abcdefgh", "%9s", "abcdefgh");
checkf ("36657730000", "%- o", (unsigned) 036657730000);
checkf ("4139757568", "%- u", (unsigned) 4139757568UL);
checkf ("f6bfb000", "%- x", (unsigned) 0xf6bfb000);
checkf ("36657730000", "%-to", (ptrdiff_t) 036657730000);
checkf ("4139757568", "%-tu", (ptrdiff_t) 4139757568UL);
checkf ("-155209728", "%-zi", (size_t) -155209728);
checkf ("-155209728", "%-zd", (size_t) -155209728);
checkf ("036657730000", "%+#o", (unsigned) 036657730000);
checkf ("0xf6bfb000", "%+#x", (unsigned) 0xf6bfb000);
checkf ("-155209728", "% zi", (size_t) -155209728);
checkf ("-155209728", "% zd", (size_t) -155209728);
checkf ("4139757568", "% tu", (ptrdiff_t) 4139757568UL);
checkf ("036657730000", "% #o", (unsigned) 036657730000);
checkf ("0xf6bfb000", "% #x", (unsigned) 0xf6bfb000);
checkf ("0xf6bfb000", "%# x", (unsigned) 0xf6bfb000);
checkf ("-155209728", "%#zd", (size_t) -155209728);
checkf ("-155209728", "%0zi", (size_t) -155209728);
checkf ("4,139,757,568", "%'tu", (ptrdiff_t) 4139757568UL);
checkf ("-155,209,728", "%-'d", -155209728);
checkf ("-155209728", "%.zi", (size_t) -155209728);
checkf ("-155209728", "%zi", (size_t) -155209728);
checkf ("-155209728", "%zd", (size_t) -155209728);
checkf ("-155209728", "%+zi", (size_t) -155209728);
if (failure_cnt == 0)
printf ("\nstdio: PASS\n");
else
printf ("\nstdio: FAIL: %d tests failed\n", failure_cnt);
}
| 10cm | trunk/10cm/pintos/src/tests/internal/stdio.c | C | oos | 7,238 |
/* Test program for lib/kernel/list.c.
Attempts to test the list functionality that is not
sufficiently tested elsewhere in Pintos.
This is not a test we will run on your submitted projects.
It is here for completeness.
*/
#undef NDEBUG
#include <debug.h>
#include <list.h>
#include <random.h>
#include <stdio.h>
#include "threads/test.h"
/* Maximum number of elements in a linked list that we will
test. */
#define MAX_SIZE 64
/* A linked list element. */
struct value
{
struct list_elem elem; /* List element. */
int value; /* Item value. */
};
static void shuffle (struct value[], size_t);
static bool value_less (const struct list_elem *, const struct list_elem *,
void *);
static void verify_list_fwd (struct list *, int size);
static void verify_list_bkwd (struct list *, int size);
/* Test the linked list implementation. */
void
test (void)
{
int size;
printf ("testing various size lists:");
for (size = 0; size < MAX_SIZE; size++)
{
int repeat;
printf (" %d", size);
for (repeat = 0; repeat < 10; repeat++)
{
static struct value values[MAX_SIZE * 4];
struct list list;
struct list_elem *e;
int i, ofs;
/* Put values 0...SIZE in random order in VALUES. */
for (i = 0; i < size; i++)
values[i].value = i;
shuffle (values, size);
/* Assemble list. */
list_init (&list);
for (i = 0; i < size; i++)
list_push_back (&list, &values[i].elem);
/* Verify correct minimum and maximum elements. */
e = list_min (&list, value_less, NULL);
ASSERT (size ? list_entry (e, struct value, elem)->value == 0
: e == list_begin (&list));
e = list_max (&list, value_less, NULL);
ASSERT (size ? list_entry (e, struct value, elem)->value == size - 1
: e == list_begin (&list));
/* Sort and verify list. */
list_sort (&list, value_less, NULL);
verify_list_fwd (&list, size);
/* Reverse and verify list. */
list_reverse (&list);
verify_list_bkwd (&list, size);
/* Shuffle, insert using list_insert_ordered(),
and verify ordering. */
shuffle (values, size);
list_init (&list);
for (i = 0; i < size; i++)
list_insert_ordered (&list, &values[i].elem,
value_less, NULL);
verify_list_fwd (&list, size);
/* Duplicate some items, uniquify, and verify. */
ofs = size;
for (e = list_begin (&list); e != list_end (&list);
e = list_next (e))
{
struct value *v = list_entry (e, struct value, elem);
int copies = random_ulong () % 4;
while (copies-- > 0)
{
values[ofs].value = v->value;
list_insert (e, &values[ofs++].elem);
}
}
ASSERT ((size_t) ofs < sizeof values / sizeof *values);
list_unique (&list, NULL, value_less, NULL);
verify_list_fwd (&list, size);
}
}
printf (" done\n");
printf ("list: PASS\n");
}
/* Shuffles the CNT elements in ARRAY into random order. */
static void
shuffle (struct value *array, size_t cnt)
{
size_t i;
for (i = 0; i < cnt; i++)
{
size_t j = i + random_ulong () % (cnt - i);
struct value t = array[j];
array[j] = array[i];
array[i] = t;
}
}
/* Returns true if value A is less than value B, false
otherwise. */
static bool
value_less (const struct list_elem *a_, const struct list_elem *b_,
void *aux UNUSED)
{
const struct value *a = list_entry (a_, struct value, elem);
const struct value *b = list_entry (b_, struct value, elem);
return a->value < b->value;
}
/* Verifies that LIST contains the values 0...SIZE when traversed
in forward order. */
static void
verify_list_fwd (struct list *list, int size)
{
struct list_elem *e;
int i;
for (i = 0, e = list_begin (list);
i < size && e != list_end (list);
i++, e = list_next (e))
{
struct value *v = list_entry (e, struct value, elem);
ASSERT (i == v->value);
}
ASSERT (i == size);
ASSERT (e == list_end (list));
}
/* Verifies that LIST contains the values 0...SIZE when traversed
in reverse order. */
static void
verify_list_bkwd (struct list *list, int size)
{
struct list_elem *e;
int i;
for (i = 0, e = list_rbegin (list);
i < size && e != list_rend (list);
i++, e = list_prev (e))
{
struct value *v = list_entry (e, struct value, elem);
ASSERT (i == v->value);
}
ASSERT (i == size);
ASSERT (e == list_rend (list));
}
| 10cm | trunk/10cm/pintos/src/tests/internal/list.c | C | oos | 4,884 |
use strict;
use warnings;
use tests::arc4;
my (@arc4);
sub random_init {
if (@arc4 == 0) {
my ($seed) = @_;
$seed = 0 if !defined $seed;
@arc4 = arc4_init (pack ("V", $seed));
}
}
sub random_bytes {
random_init ();
my ($n) = @_;
return arc4_crypt (\@arc4, "\0" x $n);
}
sub random_ulong {
random_init ();
return unpack ("V", random_bytes (4));
}
1;
| 10cm | trunk/10cm/pintos/src/tests/random.pm | Perl | oos | 386 |
#ifndef TESTS_MAIN_H
#define TESTS_MAIN_H
void test_main (void);
#endif /* tests/main.h */
| 10cm | trunk/10cm/pintos/src/tests/main.h | C | oos | 93 |
/* -*- c -*- */
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
const char *child_cmd = "child-rox " CHILD_CNT;
int handle;
pid_t child;
char buffer[16];
/* Open child-rox, read from it, write back same data. */
CHECK ((handle = open ("child-rox")) > 1, "open \"child-rox\"");
CHECK (read (handle, buffer, sizeof buffer) == (int) sizeof buffer,
"read \"child-rox\"");
seek (handle, 0);
CHECK (write (handle, buffer, sizeof buffer) == (int) sizeof buffer,
"write \"child-rox\"");
/* Execute child-rox and wait for it. */
CHECK ((child = exec (child_cmd)) != -1, "exec \"%s\"", child_cmd);
quiet = true;
CHECK (wait (child) == 12, "wait for child");
quiet = false;
/* Write to child-rox again. */
seek (handle, 0);
CHECK (write (handle, buffer, sizeof buffer) == (int) sizeof buffer,
"write \"child-rox\"");
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/rox-child.inc | C | oos | 919 |
/* Writes data spanning two pages in virtual address space,
which must succeed. */
#include <string.h>
#include <syscall.h>
#include "tests/userprog/boundary.h"
#include "tests/userprog/sample.inc"
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
int handle;
int byte_cnt;
char *sample_p;
sample_p = copy_string_across_boundary (sample);
CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
byte_cnt = write (handle, sample_p, sizeof sample - 1);
if (byte_cnt != sizeof sample - 1)
fail ("write() returned %d instead of %zu", byte_cnt, sizeof sample - 1);
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/write-boundary.c | C | oos | 621 |
/* 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"
void
test_main (void)
{
int handle;
CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
msg ("close \"sample.txt\"");
close (handle);
msg ("close \"sample.txt\" again");
close (handle);
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/close-twice.c | C | oos | 421 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF', <<'EOF']);
(create-empty) begin
(create-empty) create(""): 0
(create-empty) end
create-empty: exit(0)
EOF
(create-empty) begin
create-empty: exit(-1)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/create-empty.ck | Perl | oos | 245 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(create-long) begin
(create-long) create("x..."): 0
(create-long) end
create-long: exit(0)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/create-long.ck | Perl | oos | 188 |
/* 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"
void
test_main (void)
{
msg ("create(NULL): %d", create (NULL, 0));
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/create-null.c | C | oos | 239 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF', <<'EOF']);
(open-bad-ptr) begin
(open-bad-ptr) end
open-bad-ptr: exit(0)
EOF
(open-bad-ptr) begin
open-bad-ptr: exit(-1)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/open-bad-ptr.ck | Perl | oos | 216 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(wait-twice) begin
(child-simple) run
child-simple: exit(81)
(wait-twice) wait(exec()) = 81
(wait-twice) wait(exec()) = -1
(wait-twice) end
wait-twice: exit(0)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/wait-twice.ck | Perl | oos | 257 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF', <<'EOF']);
(wait-bad-pid) begin
(wait-bad-pid) end
wait-bad-pid: exit(0)
EOF
(wait-bad-pid) begin
wait-bad-pid: exit(-1)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/wait-bad-pid.ck | Perl | oos | 216 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(write-boundary) begin
(write-boundary) open "sample.txt"
(write-boundary) end
write-boundary: exit(0)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/write-boundary.ck | Perl | oos | 200 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected (IGNORE_USER_FAULTS => 1, [<<'EOF']);
(bad-jump) begin
bad-jump: exit(-1)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/bad-jump.ck | Perl | oos | 158 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(args) begin
(args) argc = 3
(args) argv[0] = 'args-dbl-space'
(args) argv[1] = 'two'
(args) argv[2] = 'spaces!'
(args) argv[3] = null
(args) end
args-dbl-space: exit(0)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/args-dbl-space.ck | Perl | oos | 267 |
/* 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"
void
test_main (void)
{
CHECK (create ("quux.dat", 0), "create quux.dat");
CHECK (create ("warble.dat", 0), "create warble.dat");
CHECK (!create ("quux.dat", 0), "try to re-create quux.dat");
CHECK (create ("baffle.dat", 0), "create baffle.dat");
CHECK (!create ("warble.dat", 0), "try to re-create quux.dat");
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/create-exists.c | C | oos | 485 |
/* Ensure that the executable of a running process cannot be
modified. */
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
int handle;
char buffer[16];
CHECK ((handle = open ("rox-simple")) > 1, "open \"rox-simple\"");
CHECK (read (handle, buffer, sizeof buffer) == (int) sizeof buffer,
"read \"rox-simple\"");
CHECK (write (handle, buffer, sizeof buffer) == 0,
"try to write \"rox-simple\"");
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/rox-simple.c | C | oos | 476 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(wait-simple) begin
(child-simple) run
child-simple: exit(81)
(wait-simple) wait(exec()) = 81
(wait-simple) end
wait-simple: exit(0)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/wait-simple.ck | Perl | oos | 230 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF', <<'EOF']);
(read-stdout) begin
(read-stdout) end
read-stdout: exit(0)
EOF
(read-stdout) begin
read-stdout: exit(-1)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/read-stdout.ck | Perl | oos | 211 |
/* 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"
void
test_main (void)
{
msg ("create(0x20101234): %d", create ((char *) 0x20101234, 0));
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/create-bad-ptr.c | C | oos | 268 |
/* 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"
void
test_main (void)
{
asm volatile ("movl $0x20101234, %esp; int $0x30");
fail ("should have exited with -1");
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/child-bad.c | C | oos | 361 |
/* Tries to create a file with the empty string as its name. */
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
msg ("create(\"\"): %d", create ("", 0));
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/create-empty.c | C | oos | 184 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(multi-recurse) begin 15
(multi-recurse) exec("multi-recurse 14")
(multi-recurse) begin 14
(multi-recurse) exec("multi-recurse 13")
(multi-recurse) begin 13
(multi-recurse) exec("multi-recurse 12")
(multi-recurse) begin 12
(multi-recurse) exec("multi-recurse 11")
(multi-recurse) begin 11
(multi-recurse) exec("multi-recurse 10")
(multi-recurse) begin 10
(multi-recurse) exec("multi-recurse 9")
(multi-recurse) begin 9
(multi-recurse) exec("multi-recurse 8")
(multi-recurse) begin 8
(multi-recurse) exec("multi-recurse 7")
(multi-recurse) begin 7
(multi-recurse) exec("multi-recurse 6")
(multi-recurse) begin 6
(multi-recurse) exec("multi-recurse 5")
(multi-recurse) begin 5
(multi-recurse) exec("multi-recurse 4")
(multi-recurse) begin 4
(multi-recurse) exec("multi-recurse 3")
(multi-recurse) begin 3
(multi-recurse) exec("multi-recurse 2")
(multi-recurse) begin 2
(multi-recurse) exec("multi-recurse 1")
(multi-recurse) begin 1
(multi-recurse) exec("multi-recurse 0")
(multi-recurse) begin 0
(multi-recurse) end 0
multi-recurse: exit(0)
(multi-recurse) end 1
multi-recurse: exit(1)
(multi-recurse) end 2
multi-recurse: exit(2)
(multi-recurse) end 3
multi-recurse: exit(3)
(multi-recurse) end 4
multi-recurse: exit(4)
(multi-recurse) end 5
multi-recurse: exit(5)
(multi-recurse) end 6
multi-recurse: exit(6)
(multi-recurse) end 7
multi-recurse: exit(7)
(multi-recurse) end 8
multi-recurse: exit(8)
(multi-recurse) end 9
multi-recurse: exit(9)
(multi-recurse) end 10
multi-recurse: exit(10)
(multi-recurse) end 11
multi-recurse: exit(11)
(multi-recurse) end 12
multi-recurse: exit(12)
(multi-recurse) end 13
multi-recurse: exit(13)
(multi-recurse) end 14
multi-recurse: exit(14)
(multi-recurse) end 15
multi-recurse: exit(15)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/multi-recurse.ck | Perl | oos | 1,824 |
/* This program attempts to write to memory at an address that is not mapped.
This should terminate the process with a -1 exit code. */
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
*(int *)NULL = 42;
fail ("should have exited with -1");
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/bad-write.c | C | oos | 275 |
/* 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"
void
test_main (void)
{
close (1);
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/close-stdout.c | C | oos | 202 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(sc-bad-arg) begin
sc-bad-arg: exit(-1)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/sc-bad-arg.ck | Perl | oos | 137 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(sc-bad-sp) begin
sc-bad-sp: exit(-1)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/sc-bad-sp.ck | Perl | oos | 135 |
/* This program attempts to read memory at an address that is not mapped.
This should terminate the process with a -1 exit code. */
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
msg ("Congratulations - you have successfully dereferenced NULL: %d",
*(int *)NULL);
fail ("should have exited with -1");
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/bad-read.c | C | oos | 346 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(exec-once) begin
(child-simple) run
child-simple: exit(81)
(exec-once) end
exec-once: exit(0)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/exec-once.ck | Perl | oos | 192 |
/* 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"
void
test_main (void)
{
msg ("open(0x20101234): %d", open ((char *) 0x20101234));
fail ("should have called exit(-1)");
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/open-bad-ptr.c | C | oos | 307 |
/* 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"
#include "tests/main.h"
void
test_main (void)
{
char buf;
read (0x20101234, &buf, 1);
read (5, &buf, 1);
read (1234, &buf, 1);
read (-1, &buf, 1);
read (-1024, &buf, 1);
read (INT_MIN, &buf, 1);
read (INT_MAX, &buf, 1);
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/read-bad-fd.c | C | oos | 427 |
/* Opens a file and then closes it. */
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
int handle;
CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
msg ("close \"sample.txt\"");
close (handle);
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/close-normal.c | C | oos | 269 |
/* 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"
void
test_main (void)
{
exec ((char *) 0x20101234);
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/exec-bad-ptr.c | C | oos | 214 |
/* 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>
#include <syscall.h>
#include "tests/lib.h"
const char *test_name = "child-rox";
static void
try_write (void)
{
int handle;
char buffer[19];
quiet = true;
CHECK ((handle = open ("child-rox")) > 1, "open \"child-rox\"");
quiet = false;
CHECK (write (handle, buffer, sizeof buffer) == 0,
"try to write \"child-rox\"");
close (handle);
}
int
main (int argc UNUSED, char *argv[])
{
msg ("begin");
try_write ();
if (!isdigit (*argv[1]))
fail ("bad command-line arguments");
if (atoi (argv[1]) > 1)
{
char cmd[128];
int child;
snprintf (cmd, sizeof cmd, "child-rox %d", atoi (argv[1]) - 1);
CHECK ((child = exec (cmd)) != -1, "exec \"%s\"", cmd);
quiet = true;
CHECK (wait (child) == 12, "wait for \"child-rox\"");
quiet = false;
}
try_write ();
msg ("end");
return 12;
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/child-rox.c | C | oos | 1,187 |
/* 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"
void
test_main (void)
{
asm volatile ("movl $0xbffffffc, %%esp; movl %0, (%%esp); int $0x30"
: : "i" (SYS_EXIT));
fail ("should have called exit(-1)");
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/sc-bad-arg.c | C | oos | 552 |
/* 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"
void
test_main (void)
{
close (0);
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/close-stdin.c | C | oos | 202 |
/* Tries to execute a nonexistent process.
The exec system call must return -1. */
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
msg ("exec(\"no-such-file\"): %d", exec ("no-such-file"));
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/exec-missing.c | C | oos | 244 |
/* 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"
#include "tests/main.h"
void
test_main (void)
{
CHECK (open (copy_string_across_boundary ("sample.txt")) > 1,
"open \"sample.txt\"");
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/open-boundary.c | C | oos | 339 |
/* Tests the exit system call. */
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
exit (57);
fail ("should have called exit(57)");
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/exit.c | C | oos | 163 |
/* Tries to open a nonexistent file. */
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
int handle = open ("no-such-file");
if (handle != -1)
fail ("open() returned %d", handle);
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/open-missing.c | C | oos | 236 |
/* 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"
void
test_main (void)
{
open (NULL);
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/open-null.c | C | oos | 224 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
system call!
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/null.ck | Perl | oos | 110 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(open-boundary) begin
(open-boundary) open "sample.txt"
(open-boundary) end
open-boundary: exit(0)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/open-boundary.ck | Perl | oos | 196 |
/* 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"
void
test_main (void)
{
char buf;
read (STDOUT_FILENO, &buf, 1);
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/read-stdout.c | C | oos | 247 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF', <<'EOF']);
(close-stdout) begin
(close-stdout) end
close-stdout: exit(0)
EOF
(close-stdout) begin
close-stdout: exit(-1)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/close-stdout.ck | Perl | oos | 216 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF', <<'EOF']);
(write-stdin) begin
(write-stdin) end
write-stdin: exit(0)
EOF
(write-stdin) begin
write-stdin: exit(-1)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/write-stdin.ck | Perl | oos | 211 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(open-missing) begin
(open-missing) end
open-missing: exit(0)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/open-missing.ck | Perl | oos | 159 |
/* 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"
void
test_main (void)
{
int h1 = open ("sample.txt");
int h2 = open ("sample.txt");
CHECK ((h1 = open ("sample.txt")) > 1, "open \"sample.txt\" once");
CHECK ((h2 = open ("sample.txt")) > 1, "open \"sample.txt\" again");
if (h1 == h2)
fail ("open() returned %d both times", h1);
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/open-twice.c | C | oos | 493 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF', <<'EOF']);
(open-null) begin
(open-null) end
open-null: exit(0)
EOF
(open-null) begin
open-null: exit(-1)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/open-null.ck | Perl | oos | 201 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(args) begin
(args) argc = 5
(args) argv[0] = 'args-multiple'
(args) argv[1] = 'some'
(args) argv[2] = 'arguments'
(args) argv[3] = 'for'
(args) argv[4] = 'you!'
(args) argv[5] = null
(args) end
args-multiple: exit(0)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/args-multiple.ck | Perl | oos | 315 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF', <<'EOF', <<'EOF', <<'EOF']);
(exec-missing) begin
load: no-such-file: open failed
(exec-missing) exec("no-such-file"): -1
(exec-missing) end
exec-missing: exit(0)
EOF
(exec-missing) begin
(exec-missing) exec("no-such-file"): -1
(exec-missing) end
exec-missing: exit(0)
EOF
(exec-missing) begin
load: no-such-file: open failed
no-such-file: exit(-1)
(exec-missing) exec("no-such-file"): -1
(exec-missing) end
exec-missing: exit(0)
EOF
(exec-missing) begin
load: no-such-file: open failed
(exec-missing) exec("no-such-file"): -1
no-such-file: exit(-1)
(exec-missing) end
exec-missing: exit(0)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/exec-missing.ck | Perl | oos | 686 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(create-exists) begin
(create-exists) create quux.dat
(create-exists) create warble.dat
(create-exists) try to re-create quux.dat
(create-exists) create baffle.dat
(create-exists) try to re-create quux.dat
(create-exists) end
create-exists: exit(0)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/create-exists.ck | Perl | oos | 346 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected (IGNORE_USER_FAULTS => 1, [<<'EOF']);
(bad-read) begin
bad-read: exit(-1)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/bad-read.ck | Perl | oos | 158 |
/* 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"
#include "tests/main.h"
void
test_main (void)
{
static char name[512];
memset (name, 'x', sizeof name);
name[sizeof name - 1] = '\0';
msg ("create(\"x...\"): %d", create (name, 0));
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/create-long.c | C | oos | 346 |
/* Try reading a file in the most normal way. */
#include "tests/userprog/sample.inc"
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
check_file ("sample.txt", sample, sizeof sample - 1);
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/read-normal.c | C | oos | 218 |
/* Try writing a file in the most normal way. */
#include <syscall.h>
#include "tests/userprog/sample.inc"
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
int handle, byte_cnt;
CHECK (create ("sample.txt", sizeof sample - 1), "create \"sample.txt\"");
CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
byte_cnt = write (handle, sample, sizeof sample - 1);
if (byte_cnt != sizeof sample - 1)
fail ("write() returned %d instead of %zu", byte_cnt, sizeof sample - 1);
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/write-normal.c | C | oos | 527 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(read-boundary) begin
(read-boundary) open "sample.txt"
(read-boundary) end
read-boundary: exit(0)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/read-boundary.ck | Perl | oos | 196 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected (IGNORE_USER_FAULTS => 1, [<<'EOF']);
(bad-write2) begin
bad-write2: exit(-1)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/bad-write2.ck | Perl | oos | 162 |
/* This program attempts to execute code at a kernel virtual address.
This should terminate the process with a -1 exit code. */
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
msg ("Congratulations - you have successfully called kernel code: %d",
((int (*)(void))0xC0000000)());
fail ("should have exited with -1");
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/bad-jump2.c | C | oos | 361 |
/* 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"
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
char child_cmd[128];
int handle;
CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
snprintf (child_cmd, sizeof child_cmd, "child-close %d", handle);
msg ("wait(exec()) = %d", wait (exec (child_cmd)));
check_file_handle (handle, "sample.txt", sample, sizeof sample - 1);
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/multi-child-fd.c | C | oos | 693 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(args) begin
(args) argc = 2
(args) argv[0] = 'args-single'
(args) argv[1] = 'onearg'
(args) argv[2] = null
(args) end
args-single: exit(0)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/args-single.ck | Perl | oos | 237 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF', <<'EOF']);
(close-bad-fd) begin
(close-bad-fd) end
close-bad-fd: exit(0)
EOF
(close-bad-fd) begin
close-bad-fd: exit(-1)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/close-bad-fd.ck | Perl | oos | 216 |
/* This program attempts to read kernel memory.
This should terminate the process with a -1 exit code. */
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
msg ("Congratulations - you have successfully read kernel memory: %d",
*(int *)0xC0000000);
fail ("should have exited with -1");
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/bad-read2.c | C | oos | 328 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF', <<'EOF']);
(read-bad-ptr) begin
(read-bad-ptr) open "sample.txt"
(read-bad-ptr) end
read-bad-ptr: exit(0)
EOF
(read-bad-ptr) begin
(read-bad-ptr) open "sample.txt"
read-bad-ptr: exit(-1)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/read-bad-ptr.ck | Perl | oos | 282 |
/* Try a 0-byte write, which should return 0 without writing
anything. */
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
int handle, byte_cnt;
char buf;
CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
buf = 123;
byte_cnt = write (handle, &buf, 0);
if (byte_cnt != 0)
fail("write() returned %d instead of 0", byte_cnt);
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/write-zero.c | C | oos | 409 |
/* Invokes a system call with the stack pointer (%esp) set to a
bad address. 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. */
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
asm volatile ("movl $.-(64*1024*1024), %esp; int $0x30");
fail ("should have called exit(-1)");
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/sc-bad-sp.c | C | oos | 653 |
/* 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"
#include "tests/main.h"
void
test_main (void)
{
msg ("create(\"quux.dat\"): %d",
create (copy_string_across_boundary ("quux.dat"), 0));
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/create-bound.c | C | oos | 337 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF', <<'EOF']);
(write-bad-fd) begin
(write-bad-fd) end
write-bad-fd: exit(0)
EOF
(write-bad-fd) begin
write-bad-fd: exit(-1)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/write-bad-fd.ck | Perl | oos | 216 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(args) begin
(args) argc = 1
(args) argv[0] = 'args-none'
(args) argv[1] = null
(args) end
args-none: exit(0)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/args-none.ck | Perl | oos | 207 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(sc-boundary-2) begin
sc-boundary-2: exit(67)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/sc-boundary-2.ck | Perl | oos | 143 |
/* Wait for a subprocess to finish. */
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
msg ("wait(exec()) = %d", wait (exec ("child-simple")));
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/wait-simple.c | C | oos | 195 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(rox-multichild) begin
(rox-multichild) open "child-rox"
(rox-multichild) read "child-rox"
(rox-multichild) write "child-rox"
(rox-multichild) exec "child-rox 5"
(child-rox) begin
(child-rox) try to write "child-rox"
(child-rox) exec "child-rox 4"
(child-rox) begin
(child-rox) try to write "child-rox"
(child-rox) exec "child-rox 3"
(child-rox) begin
(child-rox) try to write "child-rox"
(child-rox) exec "child-rox 2"
(child-rox) begin
(child-rox) try to write "child-rox"
(child-rox) exec "child-rox 1"
(child-rox) begin
(child-rox) try to write "child-rox"
(child-rox) try to write "child-rox"
(child-rox) end
child-rox: exit(12)
(child-rox) try to write "child-rox"
(child-rox) end
child-rox: exit(12)
(child-rox) try to write "child-rox"
(child-rox) end
child-rox: exit(12)
(child-rox) try to write "child-rox"
(child-rox) end
child-rox: exit(12)
(child-rox) try to write "child-rox"
(child-rox) end
child-rox: exit(12)
(rox-multichild) write "child-rox"
(rox-multichild) end
rox-multichild: exit(0)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/rox-multichild.ck | Perl | oos | 1,103 |
/* 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"
void
test_main (void)
{
char buf = 123;
write (0x01012342, &buf, 1);
write (7, &buf, 1);
write (2546, &buf, 1);
write (-5, &buf, 1);
write (-8192, &buf, 1);
write (INT_MIN + 1, &buf, 1);
write (INT_MAX - 1, &buf, 1);
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/write-bad-fd.c | C | oos | 424 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(rox-child) begin
(rox-child) open "child-rox"
(rox-child) read "child-rox"
(rox-child) write "child-rox"
(rox-child) exec "child-rox 1"
(child-rox) begin
(child-rox) try to write "child-rox"
(child-rox) try to write "child-rox"
(child-rox) end
child-rox: exit(12)
(rox-child) write "child-rox"
(rox-child) end
rox-child: exit(0)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/rox-child.ck | Perl | oos | 427 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(sc-boundary) begin
sc-boundary: exit(42)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/sc-boundary.ck | Perl | oos | 139 |
/* 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"
void
test_main (void)
{
int handle;
CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
read (handle, (char *) 0xc0100000, 123);
fail ("should not have survived read()");
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/read-bad-ptr.c | C | oos | 378 |
/* Tests the halt system call. */
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
halt ();
fail ("should have halted");
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/halt.c | C | oos | 152 |
#ifndef TESTS_USERPROG_BOUNDARY_H
#define TESTS_USERPROG_BOUNDARY_H
void *get_boundary_area (void);
char *copy_string_across_boundary (const char *);
#endif /* tests/userprog/boundary.h */
| 10cm | trunk/10cm/pintos/src/tests/userprog/boundary.h | C | oos | 191 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(create-normal) begin
(create-normal) create quux.dat
(create-normal) end
create-normal: exit(0)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/create-normal.ck | Perl | oos | 194 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
our ($test);
my (@output) = read_text_file ("$test.output");
common_checks ("run", @output);
fail "missing 'begin' message\n"
if !grep ($_ eq '(halt) begin', @output);
fail "found 'fail' message--halt didn't really halt\n"
if grep ($_ eq '(halt) fail', @output);
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/halt.ck | Perl | oos | 335 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected (IGNORE_USER_FAULTS => 1, IGNORE_EXIT_CODES => 1, [<<'EOF']);
(multi-oom) begin
(multi-oom) success. program forked 10 times.
(multi-oom) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/no-vm/multi-oom.ck | Perl | oos | 226 |
# -*- makefile -*-
tests/userprog/no-vm_TESTS = tests/userprog/no-vm/multi-oom
tests/userprog/no-vm_PROGS = $(tests/userprog/no-vm_TESTS)
tests/userprog/no-vm/multi-oom_SRC = tests/userprog/no-vm/multi-oom.c \
tests/lib.c
tests/userprog/no-vm/multi-oom.output: TIMEOUT = 360
| 10cm | trunk/10cm/pintos/src/tests/userprog/no-vm/.svn/text-base/Make.tests.svn-base | Makefile | oos | 277 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected (IGNORE_USER_FAULTS => 1, IGNORE_EXIT_CODES => 1, [<<'EOF']);
(multi-oom) begin
(multi-oom) success. program forked 10 times.
(multi-oom) end
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/no-vm/.svn/text-base/multi-oom.ck.svn-base | Perl | oos | 226 |
# -*- makefile -*-
tests/userprog/no-vm_TESTS = tests/userprog/no-vm/multi-oom
tests/userprog/no-vm_PROGS = $(tests/userprog/no-vm_TESTS)
tests/userprog/no-vm/multi-oom_SRC = tests/userprog/no-vm/multi-oom.c \
tests/lib.c
tests/userprog/no-vm/multi-oom.output: TIMEOUT = 360
| 10cm | trunk/10cm/pintos/src/tests/userprog/no-vm/Make.tests | Makefile | oos | 277 |
/* Recursively executes itself until the child fails to execute.
We expect that at least 30 copies can run.
We count how many children your kernel was able to execute
before it fails to start a new process. We require that,
if a process doesn't actually get to start, exec() must
return -1, not a valid PID.
We repeat this process 10 times, checking that your kernel
allows for the same level of depth every time.
In addition, some processes will spawn children that terminate
abnormally after allocating some resources.
Written by Godmar Back <godmar@gmail.com>
*/
#include <debug.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <syscall.h>
#include <random.h>
#include "tests/lib.h"
static const int EXPECTED_DEPTH_TO_PASS = 30;
static const int EXPECTED_REPETITIONS = 10;
const char *test_name = "multi-oom";
enum child_termination_mode { RECURSE, CRASH };
/* Spawn a recursive copy of ourselves, passing along instructions
for the child. */
static pid_t
spawn_child (int c, enum child_termination_mode mode)
{
char child_cmd[128];
snprintf (child_cmd, sizeof child_cmd,
"%s %d %s", test_name, c, mode == CRASH ? "-k" : "");
return exec (child_cmd);
}
/* Open a number of files (and fail to close them).
The kernel must free any kernel resources associated
with these file descriptors. */
static void
consume_some_resources (void)
{
int fd, fdmax = 126;
/* Open as many files as we can, up to fdmax.
Depending on how file descriptors are allocated inside
the kernel, open() may fail if the kernel is low on memory.
A low-memory condition in open() should not lead to the
termination of the process. */
for (fd = 0; fd < fdmax; fd++)
if (open (test_name) == -1)
break;
}
/* Consume some resources, then terminate this process
in some abnormal way. */
static int NO_INLINE
consume_some_resources_and_die (int seed)
{
consume_some_resources ();
random_init (seed);
int *PHYS_BASE = (int *)0xC0000000;
switch (random_ulong () % 5)
{
case 0:
*(int *) NULL = 42;
case 1:
return *(int *) NULL;
case 2:
return *PHYS_BASE;
case 3:
*PHYS_BASE = 42;
case 4:
open ((char *)PHYS_BASE);
exit (-1);
default:
NOT_REACHED ();
}
return 0;
}
/* The first copy is invoked without command line arguments.
Subsequent copies are invoked with a parameter 'depth'
that describes how many parent processes preceded them.
Each process spawns one or multiple recursive copies of
itself, passing 'depth+1' as depth.
Some children are started with the '-k' flag, which will
result in abnormal termination.
*/
int
main (int argc, char *argv[])
{
int n;
n = argc > 1 ? atoi (argv[1]) : 0;
bool is_at_root = (n == 0);
if (is_at_root)
msg ("begin");
/* If -k is passed, crash this process. */
if (argc > 2 && !strcmp(argv[2], "-k"))
{
consume_some_resources_and_die (n);
NOT_REACHED ();
}
int howmany = is_at_root ? EXPECTED_REPETITIONS : 1;
int i, expected_depth = -1;
for (i = 0; i < howmany; i++)
{
pid_t child_pid;
/* Spawn a child that will be abnormally terminated.
To speed the test up, do this only for processes
spawned at a certain depth. */
if (n > EXPECTED_DEPTH_TO_PASS/2)
{
child_pid = spawn_child (n + 1, CRASH);
if (child_pid != -1)
{
if (wait (child_pid) != -1)
fail ("crashed child should return -1.");
}
/* If spawning this child failed, so should
the next spawn_child below. */
}
/* Now spawn the child that will recurse. */
child_pid = spawn_child (n + 1, RECURSE);
/* If maximum depth is reached, return result. */
if (child_pid == -1)
return n;
/* Else wait for child to report how deeply it was able to recurse. */
int reached_depth = wait (child_pid);
if (reached_depth == -1)
fail ("wait returned -1.");
/* Record the depth reached during the first run; on subsequent
runs, fail if those runs do not match the depth achieved on the
first run. */
if (i == 0)
expected_depth = reached_depth;
else if (expected_depth != reached_depth)
fail ("after run %d/%d, expected depth %d, actual depth %d.",
i, howmany, expected_depth, reached_depth);
ASSERT (expected_depth == reached_depth);
}
consume_some_resources ();
if (n == 0)
{
if (expected_depth < EXPECTED_DEPTH_TO_PASS)
fail ("should have forked at least %d times.", EXPECTED_DEPTH_TO_PASS);
msg ("success. program forked %d times.", howmany);
msg ("end");
}
return expected_depth;
}
// vim: sw=2
| 10cm | trunk/10cm/pintos/src/tests/userprog/no-vm/multi-oom.c | C | oos | 4,914 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(open-empty) begin
(open-empty) end
open-empty: exit(0)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/open-empty.ck | Perl | oos | 153 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(create-bound) begin
(create-bound) create("quux.dat"): 1
(create-bound) end
create-bound: exit(0)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/create-bound.ck | Perl | oos | 196 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF', <<'EOF']);
(close-stdin) begin
(close-stdin) end
close-stdin: exit(0)
EOF
(close-stdin) begin
close-stdin: exit(-1)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/close-stdin.ck | Perl | oos | 211 |
/* Try a 0-byte read, which should return 0 without reading
anything. */
#include <syscall.h>
#include "tests/lib.h"
#include "tests/main.h"
void
test_main (void)
{
int handle, byte_cnt;
char buf;
CHECK ((handle = open ("sample.txt")) > 1, "open \"sample.txt\"");
buf = 123;
byte_cnt = read (handle, &buf, 0);
if (byte_cnt != 0)
fail ("read() returned %d instead of 0", byte_cnt);
else if (buf != 123)
fail ("0-byte read() modified buffer");
}
| 10cm | trunk/10cm/pintos/src/tests/userprog/read-zero.c | C | oos | 474 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(close-normal) begin
(close-normal) open "sample.txt"
(close-normal) close "sample.txt"
(close-normal) end
close-normal: exit(0)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/close-normal.ck | Perl | oos | 226 |
# -*- perl -*-
use strict;
use warnings;
use tests::tests;
check_expected ([<<'EOF']);
(read-normal) begin
(read-normal) open "sample.txt" for verification
(read-normal) verified contents of "sample.txt"
(read-normal) close "sample.txt"
(read-normal) end
read-normal: exit(0)
EOF
pass;
| 10cm | trunk/10cm/pintos/src/tests/userprog/.svn/text-base/read-normal.ck.svn-base | Perl | oos | 286 |