From 6ebce2100b371612b554bf17a3ce613a4093df37 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 7 Dec 2004 02:31:22 +0000 Subject: [PATCH] Initial file system tests. --- grading/filesys/.cvsignore | 20 + grading/filesys/Make.progs | 20 + grading/filesys/Makefile | 9 + grading/filesys/create.inc | 17 + grading/filesys/fslib.c | 171 +++++++ grading/filesys/fslib.h | 22 + grading/filesys/full.inc | 20 + grading/filesys/grow-create.c | 3 + grading/filesys/grow-create.exp | 5 + grading/filesys/grow-dir-lg.c | 4 + grading/filesys/grow-dir-lg.exp | 53 ++ grading/filesys/grow-dir.inc | 41 ++ grading/filesys/grow-file-size.c | 32 ++ grading/filesys/grow-file-size.exp | 9 + grading/filesys/grow-root-lg.c | 3 + grading/filesys/grow-root-lg.exp | 52 ++ grading/filesys/grow-root-sm.c | 3 + grading/filesys/grow-root-sm.exp | 22 + grading/filesys/grow-seq-lg.c | 3 + grading/filesys/grow-seq-lg.exp | 8 + grading/filesys/grow-seq-sm.c | 3 + grading/filesys/grow-seq-sm.exp | 8 + grading/filesys/grow-seq.inc | 20 + grading/filesys/grow-sparse.c | 26 + grading/filesys/grow-sparse.exp | 9 + grading/filesys/grow-tell.c | 31 ++ grading/filesys/grow-tell.exp | 8 + grading/filesys/grow-two-files.c | 60 +++ grading/filesys/grow-two-files.exp | 11 + grading/filesys/lib/.cvsignore | 1 + grading/filesys/lib/user/.cvsignore | 1 + grading/filesys/panic.diff | 20 + grading/filesys/random.inc | 70 +++ grading/filesys/run-tests | 736 ++++++++++++++++++++++++++++ grading/filesys/seq-block.inc | 21 + grading/filesys/seq-random.inc | 22 + grading/filesys/sm-create.c | 3 + grading/filesys/sm-create.exp | 5 + grading/filesys/sm-full.c | 3 + grading/filesys/sm-full.exp | 8 + grading/filesys/sm-random.c | 4 + grading/filesys/sm-random.exp | 6 + grading/filesys/sm-seq-block.c | 4 + grading/filesys/sm-seq-block.exp | 8 + grading/filesys/sm-seq-random.c | 3 + grading/filesys/sm-seq-random.exp | 8 + grading/filesys/tests.txt | 2 +- grading/vm/Make.progs | 16 +- grading/vm/arc4.c | 53 -- grading/vm/arc4.h | 18 - grading/vm/child-linear.c | 2 +- grading/vm/cksum.c | 86 ---- grading/vm/cksum.h | 8 - grading/vm/mmap-close.c | 2 +- grading/vm/mmap-shuffle.c | 4 +- grading/vm/page-linear.c | 2 +- grading/vm/page-merge-par.c | 2 +- grading/vm/page-merge-seq.c | 2 +- grading/vm/page-shuffle.c | 4 +- grading/vm/pt-big-stk-obj.c | 4 +- grading/vm/pt-grow-stack.c | 4 +- 61 files changed, 1638 insertions(+), 187 deletions(-) create mode 100644 grading/filesys/.cvsignore create mode 100644 grading/filesys/Make.progs create mode 100644 grading/filesys/Makefile create mode 100644 grading/filesys/create.inc create mode 100644 grading/filesys/fslib.c create mode 100644 grading/filesys/fslib.h create mode 100644 grading/filesys/full.inc create mode 100644 grading/filesys/grow-create.c create mode 100644 grading/filesys/grow-create.exp create mode 100644 grading/filesys/grow-dir-lg.c create mode 100644 grading/filesys/grow-dir-lg.exp create mode 100644 grading/filesys/grow-dir.inc create mode 100644 grading/filesys/grow-file-size.c create mode 100644 grading/filesys/grow-file-size.exp create mode 100644 grading/filesys/grow-root-lg.c create mode 100644 grading/filesys/grow-root-lg.exp create mode 100644 grading/filesys/grow-root-sm.c create mode 100644 grading/filesys/grow-root-sm.exp create mode 100644 grading/filesys/grow-seq-lg.c create mode 100644 grading/filesys/grow-seq-lg.exp create mode 100644 grading/filesys/grow-seq-sm.c create mode 100644 grading/filesys/grow-seq-sm.exp create mode 100644 grading/filesys/grow-seq.inc create mode 100644 grading/filesys/grow-sparse.c create mode 100644 grading/filesys/grow-sparse.exp create mode 100644 grading/filesys/grow-tell.c create mode 100644 grading/filesys/grow-tell.exp create mode 100644 grading/filesys/grow-two-files.c create mode 100644 grading/filesys/grow-two-files.exp create mode 100644 grading/filesys/lib/.cvsignore create mode 100644 grading/filesys/lib/user/.cvsignore create mode 100644 grading/filesys/panic.diff create mode 100644 grading/filesys/random.inc create mode 100755 grading/filesys/run-tests create mode 100644 grading/filesys/seq-block.inc create mode 100644 grading/filesys/seq-random.inc create mode 100644 grading/filesys/sm-create.c create mode 100644 grading/filesys/sm-create.exp create mode 100644 grading/filesys/sm-full.c create mode 100644 grading/filesys/sm-full.exp create mode 100644 grading/filesys/sm-random.c create mode 100644 grading/filesys/sm-random.exp create mode 100644 grading/filesys/sm-seq-block.c create mode 100644 grading/filesys/sm-seq-block.exp create mode 100644 grading/filesys/sm-seq-random.c create mode 100644 grading/filesys/sm-seq-random.exp delete mode 100644 grading/vm/arc4.c delete mode 100644 grading/vm/arc4.h delete mode 100644 grading/vm/cksum.c delete mode 100644 grading/vm/cksum.h diff --git a/grading/filesys/.cvsignore b/grading/filesys/.cvsignore new file mode 100644 index 0000000..936cf61 --- /dev/null +++ b/grading/filesys/.cvsignore @@ -0,0 +1,20 @@ +*.d +*.dsk +*.o +bochsout.txt +bochsrc.txt +sm-create +sm-full +sm-seq-block +sm-seq-random +sm-random +grow-create +grow-seq-sm +grow-seq-lg +grow-file-size +grow-tell +grow-sparse +grow-root-sm +grow-root-lg +grow-dir-lg +grow-two-files diff --git a/grading/filesys/Make.progs b/grading/filesys/Make.progs new file mode 100644 index 0000000..08fed39 --- /dev/null +++ b/grading/filesys/Make.progs @@ -0,0 +1,20 @@ +PROGS = sm-create sm-full sm-seq-block sm-seq-random sm-random \ + grow-create grow-seq-sm grow-seq-lg grow-file-size grow-tell \ + grow-sparse grow-root-sm grow-root-lg grow-dir-lg grow-two-files + +sm_create_SRC = sm-create.c fslib.c ../lib/arc4.c +sm_full_SRC = sm-full.c fslib.c ../lib/arc4.c +sm_seq_block_SRC = sm-seq-block.c fslib.c ../lib/arc4.c +sm_seq_random_SRC = sm-seq-random.c fslib.c ../lib/arc4.c +sm_random_SRC = sm-random.c fslib.c ../lib/arc4.c + +grow_create_SRC = grow-create.c fslib.c ../lib/arc4.c +grow_seq_sm_SRC = grow-seq-sm.c fslib.c ../lib/arc4.c +grow_seq_lg_SRC = grow-seq-lg.c fslib.c ../lib/arc4.c +grow_file_size_SRC = grow-file-size.c fslib.c ../lib/arc4.c +grow_tell_SRC = grow-tell.c fslib.c ../lib/arc4.c +grow_sparse_SRC = grow-sparse.c fslib.c ../lib/arc4.c +grow_root_sm_SRC = grow-root-sm.c fslib.c ../lib/arc4.c +grow_root_lg_SRC = grow-root-lg.c fslib.c ../lib/arc4.c +grow_dir_lg_SRC = grow-dir-lg.c fslib.c ../lib/arc4.c +grow_two_files_SRC = grow-two-files.c fslib.c ../lib/arc4.c diff --git a/grading/filesys/Makefile b/grading/filesys/Makefile new file mode 100644 index 0000000..05e4d90 --- /dev/null +++ b/grading/filesys/Makefile @@ -0,0 +1,9 @@ +include Make.progs + +SRCDIR = ../../src + +all: $(PROGS) + +include $(SRCDIR)/Makefile.userprog + +CFLAGS += -Werror diff --git a/grading/filesys/create.inc b/grading/filesys/create.inc new file mode 100644 index 0000000..d378fe3 --- /dev/null +++ b/grading/filesys/create.inc @@ -0,0 +1,17 @@ +/* -*- c -*- */ + +#include +#include +#include "fslib.h" + +static char buf[TEST_SIZE]; + +int +main (void) +{ + msg ("begin"); + check (create ("testfile", TEST_SIZE), "create testfile"); + check_file ("testfile", buf, TEST_SIZE); + msg ("end"); + return 0; +} diff --git a/grading/filesys/fslib.c b/grading/filesys/fslib.c new file mode 100644 index 0000000..36f67f8 --- /dev/null +++ b/grading/filesys/fslib.c @@ -0,0 +1,171 @@ +#include "fslib.h" +#include +#include +#include +#include +#include +#include "../lib/arc4.h" + +bool quiet = false; + +static void +vmsg (const char *format, va_list args, bool failure) +{ + if (quiet && !failure) + return; + + printf ("(%s) ", test_name); + vprintf (format, args); + if (failure) + printf (": FAILED"); + printf ("\n"); +} + +void +msg (const char *format, ...) +{ + va_list args; + + va_start (args, format); + vmsg (format, args, false); + va_end (args); +} + +void +fail (const char *format, ...) +{ + va_list args; + + quiet = false; + + va_start (args, format); + vmsg (format, args, true); + va_end (args); + + exit (1); +} + +void +check (bool success, const char *format, ...) +{ + va_list args; + + va_start (args, format); + if (success) + { + if (!quiet) + vmsg (format, args, false); + } + else + { + vmsg (format, args, true); + exit (1); + } + va_end (args); +} + +void +seq_test (const char *filename, void *buf, size_t size, + size_t initial_size, int seed, + size_t (*block_size_func) (void), + void (*check_func) (int fd, long ofs)) +{ + static struct arc4 arc4; + size_t ofs; + int fd; + + arc4_init (&arc4, &seed, sizeof seed); + arc4_crypt (&arc4, buf, size); + + check (create (filename, initial_size), "create \"%s\"", filename); + check ((fd = open (filename)) > 1, "open \"%s\"", filename); + + ofs = 0; + msg ("writing \"%s\"", filename); + while (ofs < size) + { + size_t block_size = block_size_func (); + if (block_size > size - ofs) + block_size = size - ofs; + + if (write (fd, buf + ofs, block_size) <= 0) + fail ("write %zu bytes at offset %zu in \"%s\" failed", + block_size, ofs, filename); + + ofs += block_size; + if (check_func != NULL) + check_func (fd, ofs); + } + msg ("close \"%s\"", filename); + close (fd); + check_file (filename, buf, size); +} + +static void +swap (void *a_, void *b_, size_t size) +{ + uint8_t *a = a_; + uint8_t *b = b_; + size_t i; + + for (i = 0; i < size; i++) + { + uint8_t t = a[i]; + a[i] = b[i]; + b[i] = t; + } +} + +void +shuffle (void *buf_, size_t cnt, size_t size) +{ + char *buf = buf_; + size_t i; + + for (i = 0; i < cnt; i++) + { + size_t j = i + random_ulong () % (cnt - i); + swap (buf + i * size, buf + j * size, size); + } +} + +void +check_file (const char *filename, const void *buf_, size_t size) +{ + const char *buf = buf_; + size_t ofs; + char block[512]; + int fd; + + check ((fd = open (filename)) > 1, "open \"%s\" for verification", filename); + + ofs = 0; + while (ofs < size) + { + size_t block_size = size - ofs; + if (block_size > sizeof block) + block_size = sizeof block; + + if (read (fd, block, block_size) <= 0) + fail ("read %zu bytes at offset %zu in \"%s\" failed", + block_size, ofs, filename); + + if (memcmp (buf + ofs, block, block_size)) + { + if (block_size <= 512) + { + printf ("Expected data:\n"); + hex_dump (ofs, buf + ofs, block_size, false); + printf ("Actually read data:\n"); + hex_dump (ofs, block, block_size, false); + } + fail ("%zu bytes at offset %zu differed from expected", + block_size, ofs); + } + + ofs += block_size; + } + + msg ("close \"%s\"", filename); + close (fd); +} diff --git a/grading/filesys/fslib.h b/grading/filesys/fslib.h new file mode 100644 index 0000000..b157598 --- /dev/null +++ b/grading/filesys/fslib.h @@ -0,0 +1,22 @@ +#ifndef FSLIB_H +#define FSLIB_H + +#include +#include +#include + +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; +void check (bool, const char *, ...) PRINTF_FORMAT (2, 3); + +void shuffle (void *, size_t cnt, size_t size); +void seq_test (const char *filename, + void *buffer, size_t size, + size_t initial_size, int seed, + size_t (*block_size) (void), void (*check) (int fd, long ofs)); +void check_file (const char *filename, const void *buf, size_t filesize); + +#endif /* fslib.h */ diff --git a/grading/filesys/full.inc b/grading/filesys/full.inc new file mode 100644 index 0000000..32b7c8f --- /dev/null +++ b/grading/filesys/full.inc @@ -0,0 +1,20 @@ +/* -*- c -*- */ + +#include "fslib.h" + +static char buf[TEST_SIZE]; + +static size_t +return_test_size (void) +{ + return TEST_SIZE; +} + +int +main (void) +{ + msg ("begin"); + seq_test ("quux", buf, sizeof buf, sizeof buf, 2, return_test_size, NULL); + msg ("end"); + return 0; +} diff --git a/grading/filesys/grow-create.c b/grading/filesys/grow-create.c new file mode 100644 index 0000000..ba6a40d --- /dev/null +++ b/grading/filesys/grow-create.c @@ -0,0 +1,3 @@ +const char test_name[] = "grow-create"; +#define TEST_SIZE 0 +#include "create.inc" diff --git a/grading/filesys/grow-create.exp b/grading/filesys/grow-create.exp new file mode 100644 index 0000000..0bfb05f --- /dev/null +++ b/grading/filesys/grow-create.exp @@ -0,0 +1,5 @@ +(grow-create) begin +(grow-create) create testfile +(grow-create) open "testfile" for verification +(grow-create) close "testfile" +(grow-create) end diff --git a/grading/filesys/grow-dir-lg.c b/grading/filesys/grow-dir-lg.c new file mode 100644 index 0000000..b68ccee --- /dev/null +++ b/grading/filesys/grow-dir-lg.c @@ -0,0 +1,4 @@ +const char test_name[] = "grow-dir-lg"; +#define FILE_CNT 50 +#define DIRECTORY "/x" +#include "grow-dir.inc" diff --git a/grading/filesys/grow-dir-lg.exp b/grading/filesys/grow-dir-lg.exp new file mode 100644 index 0000000..f83f326 --- /dev/null +++ b/grading/filesys/grow-dir-lg.exp @@ -0,0 +1,53 @@ +(grow-dir-lg) begin +(grow-dir-lg) mkdir /x +(grow-dir-lg) creating and checking "/x/file0" +(grow-dir-lg) creating and checking "/x/file1" +(grow-dir-lg) creating and checking "/x/file2" +(grow-dir-lg) creating and checking "/x/file3" +(grow-dir-lg) creating and checking "/x/file4" +(grow-dir-lg) creating and checking "/x/file5" +(grow-dir-lg) creating and checking "/x/file6" +(grow-dir-lg) creating and checking "/x/file7" +(grow-dir-lg) creating and checking "/x/file8" +(grow-dir-lg) creating and checking "/x/file9" +(grow-dir-lg) creating and checking "/x/file10" +(grow-dir-lg) creating and checking "/x/file11" +(grow-dir-lg) creating and checking "/x/file12" +(grow-dir-lg) creating and checking "/x/file13" +(grow-dir-lg) creating and checking "/x/file14" +(grow-dir-lg) creating and checking "/x/file15" +(grow-dir-lg) creating and checking "/x/file16" +(grow-dir-lg) creating and checking "/x/file17" +(grow-dir-lg) creating and checking "/x/file18" +(grow-dir-lg) creating and checking "/x/file19" +(grow-dir-lg) creating and checking "/x/file20" +(grow-dir-lg) creating and checking "/x/file21" +(grow-dir-lg) creating and checking "/x/file22" +(grow-dir-lg) creating and checking "/x/file23" +(grow-dir-lg) creating and checking "/x/file24" +(grow-dir-lg) creating and checking "/x/file25" +(grow-dir-lg) creating and checking "/x/file26" +(grow-dir-lg) creating and checking "/x/file27" +(grow-dir-lg) creating and checking "/x/file28" +(grow-dir-lg) creating and checking "/x/file29" +(grow-dir-lg) creating and checking "/x/file30" +(grow-dir-lg) creating and checking "/x/file31" +(grow-dir-lg) creating and checking "/x/file32" +(grow-dir-lg) creating and checking "/x/file33" +(grow-dir-lg) creating and checking "/x/file34" +(grow-dir-lg) creating and checking "/x/file35" +(grow-dir-lg) creating and checking "/x/file36" +(grow-dir-lg) creating and checking "/x/file37" +(grow-dir-lg) creating and checking "/x/file38" +(grow-dir-lg) creating and checking "/x/file39" +(grow-dir-lg) creating and checking "/x/file40" +(grow-dir-lg) creating and checking "/x/file41" +(grow-dir-lg) creating and checking "/x/file42" +(grow-dir-lg) creating and checking "/x/file43" +(grow-dir-lg) creating and checking "/x/file44" +(grow-dir-lg) creating and checking "/x/file45" +(grow-dir-lg) creating and checking "/x/file46" +(grow-dir-lg) creating and checking "/x/file47" +(grow-dir-lg) creating and checking "/x/file48" +(grow-dir-lg) creating and checking "/x/file49" +(grow-dir-lg) end diff --git a/grading/filesys/grow-dir.inc b/grading/filesys/grow-dir.inc new file mode 100644 index 0000000..df3cbdf --- /dev/null +++ b/grading/filesys/grow-dir.inc @@ -0,0 +1,41 @@ +/* -*- c -*- */ + +#include +#include +#include "fslib.h" + +static char buf[512]; + +static size_t +return_block_size (void) +{ + return sizeof buf; +} + +int +main (void) +{ + size_t i; + + msg ("begin"); +#ifdef DIRECTORY + check (mkdir (DIRECTORY), "mkdir %s", DIRECTORY); +#define DIR_PREFIX DIRECTORY "/" +#else +#define DIR_PREFIX "" +#endif + for (i = 0; i < FILE_CNT; i++) + { + char filename[128]; + snprintf (filename, sizeof filename, "%sfile%zu", DIR_PREFIX, i); + + msg ("creating and checking \"%s\"", filename); + + quiet = true; + seq_test (filename, buf, sizeof buf, sizeof buf, 0, + return_block_size, NULL); + quiet = false; + } + msg ("end"); + return 0; +} diff --git a/grading/filesys/grow-file-size.c b/grading/filesys/grow-file-size.c new file mode 100644 index 0000000..b92ec5b --- /dev/null +++ b/grading/filesys/grow-file-size.c @@ -0,0 +1,32 @@ +/* -*- c -*- */ + +#include +#include "fslib.h" + +const char test_name[] = "grow-file-size"; +static char buf[2134]; + +static size_t +return_block_size (void) +{ + return 37; +} + +static void +check_file_size (int fd, long ofs) +{ + long size = filesize (fd); + if (size != ofs) + fail ("filesize not updated properly: should be %ld, actually %ld", + ofs, size); +} + +int +main (void) +{ + msg ("begin"); + seq_test ("testfile", buf, sizeof buf, 0, 0, + return_block_size, check_file_size); + msg ("end"); + return 0; +} diff --git a/grading/filesys/grow-file-size.exp b/grading/filesys/grow-file-size.exp new file mode 100644 index 0000000..fcb5ce4 --- /dev/null +++ b/grading/filesys/grow-file-size.exp @@ -0,0 +1,9 @@ +(grow-file-size) begin +(grow-file-size) create "testfile" +(grow-file-size) open "testfile" +(grow-file-size) writing "testfile" +(grow-file-size) close "testfile" +(grow-file-size) open "testfile" for verification +(grow-file-size) close "testfile" +(grow-file-size) end + diff --git a/grading/filesys/grow-root-lg.c b/grading/filesys/grow-root-lg.c new file mode 100644 index 0000000..537a7e3 --- /dev/null +++ b/grading/filesys/grow-root-lg.c @@ -0,0 +1,3 @@ +const char test_name[] = "grow-root-lg"; +#define FILE_CNT 50 +#include "grow-dir.inc" diff --git a/grading/filesys/grow-root-lg.exp b/grading/filesys/grow-root-lg.exp new file mode 100644 index 0000000..9736808 --- /dev/null +++ b/grading/filesys/grow-root-lg.exp @@ -0,0 +1,52 @@ +(grow-root-lg) begin +(grow-root-lg) creating and checking "file0" +(grow-root-lg) creating and checking "file1" +(grow-root-lg) creating and checking "file2" +(grow-root-lg) creating and checking "file3" +(grow-root-lg) creating and checking "file4" +(grow-root-lg) creating and checking "file5" +(grow-root-lg) creating and checking "file6" +(grow-root-lg) creating and checking "file7" +(grow-root-lg) creating and checking "file8" +(grow-root-lg) creating and checking "file9" +(grow-root-lg) creating and checking "file10" +(grow-root-lg) creating and checking "file11" +(grow-root-lg) creating and checking "file12" +(grow-root-lg) creating and checking "file13" +(grow-root-lg) creating and checking "file14" +(grow-root-lg) creating and checking "file15" +(grow-root-lg) creating and checking "file16" +(grow-root-lg) creating and checking "file17" +(grow-root-lg) creating and checking "file18" +(grow-root-lg) creating and checking "file19" +(grow-root-lg) creating and checking "file20" +(grow-root-lg) creating and checking "file21" +(grow-root-lg) creating and checking "file22" +(grow-root-lg) creating and checking "file23" +(grow-root-lg) creating and checking "file24" +(grow-root-lg) creating and checking "file25" +(grow-root-lg) creating and checking "file26" +(grow-root-lg) creating and checking "file27" +(grow-root-lg) creating and checking "file28" +(grow-root-lg) creating and checking "file29" +(grow-root-lg) creating and checking "file30" +(grow-root-lg) creating and checking "file31" +(grow-root-lg) creating and checking "file32" +(grow-root-lg) creating and checking "file33" +(grow-root-lg) creating and checking "file34" +(grow-root-lg) creating and checking "file35" +(grow-root-lg) creating and checking "file36" +(grow-root-lg) creating and checking "file37" +(grow-root-lg) creating and checking "file38" +(grow-root-lg) creating and checking "file39" +(grow-root-lg) creating and checking "file40" +(grow-root-lg) creating and checking "file41" +(grow-root-lg) creating and checking "file42" +(grow-root-lg) creating and checking "file43" +(grow-root-lg) creating and checking "file44" +(grow-root-lg) creating and checking "file45" +(grow-root-lg) creating and checking "file46" +(grow-root-lg) creating and checking "file47" +(grow-root-lg) creating and checking "file48" +(grow-root-lg) creating and checking "file49" +(grow-root-lg) end diff --git a/grading/filesys/grow-root-sm.c b/grading/filesys/grow-root-sm.c new file mode 100644 index 0000000..30685eb --- /dev/null +++ b/grading/filesys/grow-root-sm.c @@ -0,0 +1,3 @@ +const char test_name[] = "grow-root-sm"; +#define FILE_CNT 20 +#include "grow-dir.inc" diff --git a/grading/filesys/grow-root-sm.exp b/grading/filesys/grow-root-sm.exp new file mode 100644 index 0000000..c9f4bd5 --- /dev/null +++ b/grading/filesys/grow-root-sm.exp @@ -0,0 +1,22 @@ +(grow-root-sm) begin +(grow-root-sm) creating and checking "file0" +(grow-root-sm) creating and checking "file1" +(grow-root-sm) creating and checking "file2" +(grow-root-sm) creating and checking "file3" +(grow-root-sm) creating and checking "file4" +(grow-root-sm) creating and checking "file5" +(grow-root-sm) creating and checking "file6" +(grow-root-sm) creating and checking "file7" +(grow-root-sm) creating and checking "file8" +(grow-root-sm) creating and checking "file9" +(grow-root-sm) creating and checking "file10" +(grow-root-sm) creating and checking "file11" +(grow-root-sm) creating and checking "file12" +(grow-root-sm) creating and checking "file13" +(grow-root-sm) creating and checking "file14" +(grow-root-sm) creating and checking "file15" +(grow-root-sm) creating and checking "file16" +(grow-root-sm) creating and checking "file17" +(grow-root-sm) creating and checking "file18" +(grow-root-sm) creating and checking "file19" +(grow-root-sm) end diff --git a/grading/filesys/grow-seq-lg.c b/grading/filesys/grow-seq-lg.c new file mode 100644 index 0000000..9cd7c74 --- /dev/null +++ b/grading/filesys/grow-seq-lg.c @@ -0,0 +1,3 @@ +const char test_name[] = "grow-seq-lg"; +#define TEST_SIZE 72943 +#include "grow-seq.inc" diff --git a/grading/filesys/grow-seq-lg.exp b/grading/filesys/grow-seq-lg.exp new file mode 100644 index 0000000..36953cb --- /dev/null +++ b/grading/filesys/grow-seq-lg.exp @@ -0,0 +1,8 @@ +(grow-seq-lg) begin +(grow-seq-lg) create "testme" +(grow-seq-lg) open "testme" +(grow-seq-lg) writing "testme" +(grow-seq-lg) close "testme" +(grow-seq-lg) open "testme" for verification +(grow-seq-lg) close "testme" +(grow-seq-lg) end diff --git a/grading/filesys/grow-seq-sm.c b/grading/filesys/grow-seq-sm.c new file mode 100644 index 0000000..a99fa0c --- /dev/null +++ b/grading/filesys/grow-seq-sm.c @@ -0,0 +1,3 @@ +const char test_name[] = "grow-seq-sm"; +#define TEST_SIZE 5678 +#include "grow-seq.inc" diff --git a/grading/filesys/grow-seq-sm.exp b/grading/filesys/grow-seq-sm.exp new file mode 100644 index 0000000..8fb12e5 --- /dev/null +++ b/grading/filesys/grow-seq-sm.exp @@ -0,0 +1,8 @@ +(grow-seq-sm) begin +(grow-seq-sm) create "testme" +(grow-seq-sm) open "testme" +(grow-seq-sm) writing "testme" +(grow-seq-sm) close "testme" +(grow-seq-sm) open "testme" for verification +(grow-seq-sm) close "testme" +(grow-seq-sm) end diff --git a/grading/filesys/grow-seq.inc b/grading/filesys/grow-seq.inc new file mode 100644 index 0000000..2c0e3ba --- /dev/null +++ b/grading/filesys/grow-seq.inc @@ -0,0 +1,20 @@ +/* -*- c -*- */ + +#include "fslib.h" + +static char buf[TEST_SIZE]; + +static size_t +return_block_size (void) +{ + return 1234; +} + +int +main (void) +{ + msg ("begin"); + seq_test ("testme", buf, sizeof buf, 0, 3, return_block_size, NULL); + msg ("end"); + return 0; +} diff --git a/grading/filesys/grow-sparse.c b/grading/filesys/grow-sparse.c new file mode 100644 index 0000000..6180828 --- /dev/null +++ b/grading/filesys/grow-sparse.c @@ -0,0 +1,26 @@ +/* -*- c -*- */ + +#include +#include "fslib.h" + +const char test_name[] = "grow-sparse"; +static char buf[76543]; + +int +main (void) +{ + char zero = 0; + int fd; + + msg ("begin"); + check (create ("testfile", 0), "create \"testfile\""); + check ((fd = open ("testfile")) > 1, "open \"testfile\""); + msg ("seek \"testfile\""); + seek (fd, sizeof buf - 1); + check (write (fd, &zero, 1) > 0, "write \"testfile\""); + msg ("close \"testfile\""); + close (fd); + check_file ("testfile", buf, sizeof buf); + msg ("end"); + return 0; +} diff --git a/grading/filesys/grow-sparse.exp b/grading/filesys/grow-sparse.exp new file mode 100644 index 0000000..c7cd00c --- /dev/null +++ b/grading/filesys/grow-sparse.exp @@ -0,0 +1,9 @@ +(grow-sparse) begin +(grow-sparse) create "testfile" +(grow-sparse) open "testfile" +(grow-sparse) seek "testfile" +(grow-sparse) write "testfile" +(grow-sparse) close "testfile" +(grow-sparse) open "testfile" for verification +(grow-sparse) close "testfile" +(grow-sparse) end diff --git a/grading/filesys/grow-tell.c b/grading/filesys/grow-tell.c new file mode 100644 index 0000000..4f9d517 --- /dev/null +++ b/grading/filesys/grow-tell.c @@ -0,0 +1,31 @@ +/* -*- c -*- */ + +#include +#include "fslib.h" + +const char test_name[] = "grow-tell"; +static char buf[2134]; + +static size_t +return_block_size (void) +{ + return 37; +} + +static void +check_tell (int fd, long ofs) +{ + long pos = tell (fd); + if (pos != ofs) + fail ("file position not updated properly: should be %ld, actually %ld", + ofs, pos); +} + +int +main (void) +{ + msg ("begin"); + seq_test ("foobar", buf, sizeof buf, 0, 1, return_block_size, check_tell); + msg ("end"); + return 0; +} diff --git a/grading/filesys/grow-tell.exp b/grading/filesys/grow-tell.exp new file mode 100644 index 0000000..e7788f9 --- /dev/null +++ b/grading/filesys/grow-tell.exp @@ -0,0 +1,8 @@ +(grow-tell) begin +(grow-tell) create "foobar" +(grow-tell) open "foobar" +(grow-tell) writing "foobar" +(grow-tell) close "foobar" +(grow-tell) open "foobar" for verification +(grow-tell) close "foobar" +(grow-tell) end diff --git a/grading/filesys/grow-two-files.c b/grading/filesys/grow-two-files.c new file mode 100644 index 0000000..8809c60 --- /dev/null +++ b/grading/filesys/grow-two-files.c @@ -0,0 +1,60 @@ +#include +#include +#include "fslib.h" + +const char test_name[] = "grow-two-files"; + +#define FILE_SIZE 8143 +static char buf_a[FILE_SIZE]; +static char buf_b[FILE_SIZE]; + +static void +write_some_bytes (const char *filename, int fd, const char *buf, size_t *ofs) +{ + if (*ofs < FILE_SIZE) + { + size_t block_size = random_ulong () % (FILE_SIZE / 8) + 1; + if (block_size > FILE_SIZE - *ofs) + block_size = FILE_SIZE - *ofs; + + if (write (fd, buf + *ofs, block_size) <= 0) + fail ("write %zu bytes at offset %zu in \"%s\"", + block_size, *ofs, filename); + *ofs += block_size; + } +} + +int +main (void) +{ + int fd_a, fd_b; + size_t ofs_a, ofs_b; + + random_init (0); + random_bytes (buf_a, sizeof buf_a); + random_bytes (buf_b, sizeof buf_b); + + check (create ("a", 0), "create \"a\""); + check (create ("b", 0), "create \"b\""); + + check ((fd_a = open ("a")) > 1, "open \"a\""); + check ((fd_b = open ("b")) > 1, "open \"b\""); + + msg ("write \"a\" and \"b\" alternately"); + while (ofs_a < FILE_SIZE || ofs_b < FILE_SIZE) + { + write_some_bytes ("a", fd_a, buf_a, &ofs_a); + write_some_bytes ("b", fd_b, buf_b, &ofs_b); + } + + msg ("close \"a\""); + close (fd_a); + + msg ("close \"b\""); + close (fd_b); + + check_file ("a", buf_a, FILE_SIZE); + check_file ("b", buf_b, FILE_SIZE); + + return 0; +} diff --git a/grading/filesys/grow-two-files.exp b/grading/filesys/grow-two-files.exp new file mode 100644 index 0000000..affa63a --- /dev/null +++ b/grading/filesys/grow-two-files.exp @@ -0,0 +1,11 @@ +(grow-two-files) create "a" +(grow-two-files) create "b" +(grow-two-files) open "a" +(grow-two-files) open "b" +(grow-two-files) write "a" and "b" alternately +(grow-two-files) close "a" +(grow-two-files) close "b" +(grow-two-files) open "a" for verification +(grow-two-files) close "a" +(grow-two-files) open "b" for verification +(grow-two-files) close "b" diff --git a/grading/filesys/lib/.cvsignore b/grading/filesys/lib/.cvsignore new file mode 100644 index 0000000..a438335 --- /dev/null +++ b/grading/filesys/lib/.cvsignore @@ -0,0 +1 @@ +*.d diff --git a/grading/filesys/lib/user/.cvsignore b/grading/filesys/lib/user/.cvsignore new file mode 100644 index 0000000..a438335 --- /dev/null +++ b/grading/filesys/lib/user/.cvsignore @@ -0,0 +1 @@ +*.d diff --git a/grading/filesys/panic.diff b/grading/filesys/panic.diff new file mode 100644 index 0000000..6134d47 --- /dev/null +++ b/grading/filesys/panic.diff @@ -0,0 +1,20 @@ +diff -up /home/blp/cs140/pintos/src/lib/debug.c.\~1.8.\~ /home/blp/cs140/pintos/src/lib/debug.c +--- /home/blp/cs140/pintos/src/lib/debug.c.~1.8.~ 2004-09-12 13:14:11.000000000 -0700 ++++ /home/blp/cs140/pintos/src/lib/debug.c 2004-10-17 00:02:32.000000000 -0700 +@@ -5,6 +5,7 @@ + #include + #include + #ifdef KERNEL ++#include "threads/init.h" + #include "threads/interrupt.h" + #include "devices/serial.h" + #else +@@ -83,7 +84,7 @@ debug_panic (const char *file, int line, + + #ifdef KERNEL + serial_flush (); +- for (;;); ++ power_off (); + #else + exit (1); + #endif diff --git a/grading/filesys/random.inc b/grading/filesys/random.inc new file mode 100644 index 0000000..e821a59 --- /dev/null +++ b/grading/filesys/random.inc @@ -0,0 +1,70 @@ +/* -*- c -*- */ + +#include +#include +#include +#include +#include "fslib.h" + +#if TEST_SIZE % BLOCK_SIZE != 0 +#error TEST_SIZE must be a multiple of BLOCK_SIZE +#endif + +#define BLOCK_CNT (TEST_SIZE / BLOCK_SIZE) + +char buf[TEST_SIZE]; +int order[BLOCK_CNT]; + +int +main (void) +{ + int fd; + size_t i; + + msg ("begin"); + + random_init (57); + random_bytes (buf, sizeof buf); + + for (i = 0; i < BLOCK_CNT; i++) + order[i] = i; + + check (create ("bazzle", TEST_SIZE), "create \"bazzle\""); + check ((fd = open ("bazzle")) > 1, "open \"bazzle\""); + + msg ("write \"bazzle\" in random order"); + shuffle (order, BLOCK_CNT, sizeof *order); + for (i = 0; i < BLOCK_CNT; i++) + { + size_t ofs = BLOCK_SIZE * order[i]; + seek (fd, ofs); + if (write (fd, buf + ofs, BLOCK_SIZE) <= 0) + fail ("write %d bytes at offset %zu failed", (int) BLOCK_SIZE, ofs); + } + + msg ("read \"bazzle\" in random order"); + shuffle (order, BLOCK_CNT, sizeof *order); + for (i = 0; i < BLOCK_CNT; i++) + { + char block[BLOCK_SIZE]; + size_t ofs = BLOCK_SIZE * order[i]; + seek (fd, ofs); + if (read (fd, block, BLOCK_SIZE) <= 0) + fail ("read %d bytes at offset %zu failed", (int) BLOCK_SIZE, ofs); + if (memcmp (block, buf + ofs, BLOCK_SIZE)) + { + printf ("Expected data:\n"); + hex_dump (ofs, buf + ofs, BLOCK_SIZE, false); + printf ("Actually read data:\n"); + hex_dump (ofs, block, BLOCK_SIZE, false); + fail ("%d bytes at offset %zu differed from expected", + (int) BLOCK_SIZE, ofs); + } + } + + fail ("close \"bazzle\""); + close (fd); + + msg ("end"); + return 0; +} diff --git a/grading/filesys/run-tests b/grading/filesys/run-tests new file mode 100755 index 0000000..7b73487 --- /dev/null +++ b/grading/filesys/run-tests @@ -0,0 +1,736 @@ +#! /usr/bin/perl + +# Find the directory that contains the grading files. +our ($GRADES_DIR); + +# Add our Perl library directory to the include path. +BEGIN { + ($GRADES_DIR = $0) =~ s#/[^/]+$##; + -d $GRADES_DIR or die "$GRADES_DIR: stat: $!\n"; + unshift @INC, "$GRADES_DIR/../lib"; +} + +use warnings; +use strict; +use POSIX; +use Algorithm::Diff; +use Getopt::Long; + +our ($verbose) = 0; # Verbosity of output +our (@TESTS); # Tests to run. +my ($clean) = 0; +my ($grade) = 0; + +GetOptions ("v|verbose+" => \$verbose, + "h|help" => sub { usage (0) }, + "t|test=s" => \@TESTS, + "c|clean" => \$clean, + "g|grade" => \$grade) + or die "Malformed command line; use --help for help.\n"; +die "Non-option argument not supported; use --help for help.\n" + if @ARGV > 0; + +sub usage { + my ($exitcode) = @_; + print "run-tests, for grading Pintos multiprogramming projects.\n\n"; + print "Invoke from a directory containing a student tarball named by\n"; + print "the submit script, e.g. username.Oct.12.04.20.04.09.tar.gz.\n"; + print "In normal usage, no options are needed.\n\n"; + print "Output is produced in tests.out and details.out.\n\n"; + print "Options:\n"; + print " -c, --clean Remove old output files before starting\n"; + print " -t, --test=TEST Execute TEST only (allowed multiple times)\n"; + print " -g, --grade Instead of running tests, compose grade.out\n"; + print " -v, --verbose Print commands before executing them\n"; + print " -h, --help Print this help message\n"; + exit $exitcode; +} + +# Default set of tests. +@TESTS = qw (sm-create sm-full sm-seq-block sm-seq-random sm-random + grow-create grow-seq-sm grow-seq-lg grow-file-size grow-tell + grow-sparse grow-root-sm grow-root-lg grow-dir-lg grow-two-files + ) unless @TESTS > 0; + +our (%args); + +# Handle final grade mode. +if ($grade) { + open (OUT, ">grade.out") or die "grade.out: create: $!\n"; + + open (GRADE, ") { + last if /^\s*$/; + print OUT; + } + close (GRADE); + + my (@tests) = snarf ("tests.out"); + my ($p_got, $p_pos) = $tests[0] =~ m%\((\d+)/(\d+)\)% or die; + + my (@review) = snarf ("review.txt"); + my ($part_lost) = (0, 0); + for (my ($i) = $#review; $i >= 0; $i--) { + local ($_) = $review[$i]; + if (my ($loss) = /^\s*([-+]\d+)/) { + $part_lost += $loss; + } elsif (my ($out_of) = m%\[\[/(\d+)\]\]%) { + my ($got) = $out_of + $part_lost; + $got = 0 if $got < 0; + $review[$i] =~ s%\[\[/\d+\]\]%($got/$out_of)% or die; + $part_lost = 0; + + $p_got += $got; + $p_pos += $out_of; + } + } + die "Lost points outside a section\n" if $part_lost; + + for (my ($i) = 1; $i <= $#review; $i++) { + if ($review[$i] =~ /^-{3,}\s*$/ && $review[$i - 1] !~ /^\s*$/) { + $review[$i] = '-' x (length ($review[$i - 1])); + } + } + + print OUT "\nOVERALL SCORE\n"; + print OUT "-------------\n"; + print OUT "$p_got points out of $p_pos total\n\n"; + + print OUT map ("$_\n", @tests), "\n"; + print OUT map ("$_\n", @review), "\n"; + + print OUT "DETAILS\n"; + print OUT "-------\n\n"; + print OUT map ("$_\n", snarf ("details.out")); + + exit 0; +} + +if ($clean) { + # Verify that we're roughly in the correct directory + # before we go blasting away files. + choose_tarball (); + + xsystem ("rm -rf output pintos", VERBOSE => 1); + xsystem ("rm -f details.out tests.out", VERBOSE => 1); +} + +# Create output directory, if it doesn't already exist. +-d ("output") || mkdir ("output") or die "output: mkdir: $!\n"; + +# Extract submission. +extract_tarball () if ! -d "pintos"; + +# Compile submission. +compile (); + +# Verify that the proper directory was submitted. +-d "pintos/src/threads" or die "pintos/src/threads: stat: $!\n"; + +# Run and grade the tests. +our $test; +our %result; +our %details; +our %extra; +for $test (@TESTS) { + print "$test: "; + my ($result) = run_test ($test); + if ($result eq 'ok') { + $result = grade_test ($test); + $result =~ s/\n$//; + } + print "$result"; + print " - with warnings" if $result eq 'ok' && defined $details{$test}; + print "\n"; + + $result{$test} = $result; +} + +# Write output. +write_grades (); +write_details (); + +sub choose_tarball { + my (@tarballs) + = grep (/^[a-z0-9]+\.[A-Za-z]+\.\d+\.\d+\.\d+\.\d+.\d+\.tar\.gz$/, + glob ("*.tar.gz")); + die "no pintos dir and no source tarball\n" if scalar (@tarballs) == 0; + + # Sort tarballs in reverse order by time. + @tarballs = sort { ext_mdyHMS ($b) cmp ext_mdyHMS ($a) } @tarballs; + + print "Multiple tarballs: choosing $tarballs[0]\n" + if scalar (@tarballs) > 1; + return $tarballs[0]; +} + +sub extract_tarball { + my ($tarball) = choose_tarball (); + + mkdir "pintos" or die "pintos: mkdir: $!\n"; + mkdir "pintos/src" or die "pintos: mkdir: $!\n"; + + print "Extracting $tarball...\n"; + xsystem ("cd pintos/src && tar xzf ../../$tarball", + DIE => "extraction failed\n"); + + if (-e "fixme.sh") { + print "Running fixme.sh...\n"; + xsystem ("sh -e fixme.sh", DIE => "fix script failed\n"); + } + + print "Patching...\n"; + xsystem ("patch -fs pintos/src/lib/debug.c < $GRADES_DIR/panic.diff", + LOG => "patch", + DIE => "patch failed\n"); + + open (CONSTANTS, ">pintos/src/constants.h") + or die "constants.h: create: $!\n"; + print CONSTANTS "#define THREAD_JOIN_IMPLEMENTED 1\n"; + close CONSTANTS; +} + +sub ext_mdyHMS { + my ($s) = @_; + my ($ms, $d, $y, $H, $M, $S) = + $s =~ /.([A-Za-z]+)\.(\d+)\.(\d+)\.(\d+)\.(\d+).(\d+)\.tar\.gz$/ + or die; + my ($m) = index ("janfebmaraprmayjunjulaugsepoctnovdec", lc $ms) / 3 + or die; + return sprintf "%02d-%02d-%02d %02d:%02d:%02d", $y, $m, $d, $H, $M, $S; +} + +sub test_source { + my ($test) = @_; + my ($src) = "$GRADES_DIR/$test.c"; + -e $src or die "$src: stat: $!\n"; + return $src; +} + +sub test_constants { + my ($defines) = ""; + return $defines; + } + +sub run_test { + my ($test) = @_; + + # Reuse older results if any + if (open (DONE, "; + chomp $status; + close (DONE); + return $status; + } + + # Really run the test. + my ($status) = really_run_test ($test); + + # Save the results for later. + open (DONE, ">output/$test/done") or die "output/$test/done: create: $!\n"; + print DONE "$status\n"; + close (DONE); + + return $status; +} + +sub compile { + print "Compiling...\n"; + xsystem ("cd pintos/src/vm && make", LOG => "make") + or return "compile error"; +} + +sub really_run_test { + # Need to run it. + # If there's residue from an earlier test, move it to .old. + # If there's already a .old, delete it. + xsystem ("rm -rf output/$test.old", VERBOSE => 1) if -d "output/$test.old"; + rename "output/$test", "output/$test.old" or die "rename: $!\n" + if -d "output/$test"; + + # Make output directory. + mkdir "output/$test"; + xsystem ("pintos make-disk output/$test/fs.dsk 2 >/dev/null 2>&1", + DIE => "failed to create file system disk"); + xsystem ("pintos make-disk output/$test/swap.dsk 2 >/dev/null 2>&1", + DIE => "failed to create swap disk"); + + # Format disk, install test. + my ($pintos_base_cmd) = + "pintos " + . "--os-disk=pintos/src/vm/build/os.dsk " + . "--fs-disk=output/$test/fs.dsk " + . "--swap-disk=output/$test/swap.dsk " + . "-v"; + unlink ("output/$test/fs.dsk", "output/$test/swap.dsk"), + return "format/put error" + if !xsystem ("$pintos_base_cmd put -f $GRADES_DIR/$test $test", + LOG => "$test/put", TIMEOUT => 60, EXPECT => 1); + + # Run. + my ($timeout) = 60; + my ($testargs) = defined ($args{$test}) ? " $args{$test}" : ""; + my ($result) = + xsystem ("$pintos_base_cmd run -q -ex \"$test$testargs\"", + LOG => "$test/run", TIMEOUT => $timeout, EXPECT => 1) + ? "ok" : "Bochs error"; + unlink ("output/$test/fs.dsk", "output/$test/swap.dsk"); + return $result; +} + +sub grade_test { + my ($test) = @_; + + my (@output) = snarf ("output/$test/run.out"); + + my ($grade_func) = "grade_$test"; + $grade_func =~ s/-/_/g; + if (-e "$GRADES_DIR/$test.exp" && !defined (&$grade_func)) { + eval { + verify_common (@output); + compare_output ("$GRADES_DIR/$test.exp", @output); + } + } else { + eval "$grade_func (\@output)"; + } + if ($@) { + die $@ if $@ =~ /at \S+ line \d+$/; + return $@; + } + return "ok"; +} + +sub grade_process_death { + my ($proc_name, @output) = @_; + + verify_common (@output); + @output = get_core_output (@output); + die "First line of output is not `($proc_name) begin' message.\n" + if $output[0] ne "($proc_name) begin"; + die "Output contains `FAIL' message.\n" + if grep (/FAIL/, @output); + die "Output contains spurious ($proc_name) message.\n" + if grep (/\($proc_name\)/, @output) > 1; +} + +sub grade_pt_bad_addr { + grade_process_death ('pt-bad-addr', @_); +} + +sub grade_pt_write_code { + grade_process_death ('pt-write-code', @_); +} + +sub grade_mmap_unmap { + grade_process_death ('mmap-unmap', @_); +} + +sub verify_common { + my (@output) = @_; + + my (@assertion) = grep (/PANIC/, @output); + if (@assertion != 0) { + my ($details) = "Kernel panic:\n $assertion[0]\n"; + + my (@stack_line) = grep (/Call stack:/, @output); + if (@stack_line != 0) { + $details .= " $stack_line[0]\n\n"; + $details .= "Translation of backtrace:\n"; + my (@addrs) = $stack_line[0] =~ /Call stack:((?: 0x[0-9a-f]+)+)/; + + my ($A2L); + if (`uname -m` + =~ /i.86|pentium.*|[pk][56]|nexgen|viac3|6x86|athlon.*/) { + $A2L = "addr2line"; + } else { + $A2L = "i386-elf-addr2line"; + } + open (A2L, "$A2L -fe pintos/src/vm/build/kernel.o @addrs|"); + for (;;) { + my ($function, $line); + last unless defined ($function = ); + $line = ; + chomp $function; + chomp $line; + $details .= " $function ($line)\n"; + } + } + + if ($assertion[0] =~ /sec_no < d->capacity/) { + $details .= < 1) { + my ($details); + + $details = "Pintos spontaneously rebooted during this test.\n"; + $details .= "This is most often due to unhandled page faults.\n"; + $details .= "Here's the output from the initial boot through the\n"; + $details .= "first reboot:\n\n"; + + my ($i) = 0; + local ($_); + for (@output) { + $details .= " $_\n"; + last if /Pintos booting/ && ++$i > 1; + } + $details{$test} = $details; + die "Triple-fault caused spontaneous reboot(s). " + . "Details at end of file.\n"; + } + + die "No output at all\n" if @output == 0; + die "Didn't start up properly: no \"Pintos booting\" startup message\n" + if !grep (/Pintos booting with.*kB RAM\.\.\./, @output); + die "Didn't start up properly: no \"Boot complete\" startup message\n" + if !grep (/Boot complete/, @output); + die "Didn't shut down properly: no \"Timer: # ticks\" shutdown message\n" + if !grep (/Timer: \d+ ticks/, @output); + die "Didn't shut down properly: no \"Powering off\" shutdown message\n" + if !grep (/Powering off/, @output); +} + +# Get @output without header or trailer. +sub get_core_output { + my (@output) = @_; + + our ($test); + my ($first); + for ($first = 0; $first <= $#output; $first++) { + $first++, last if $output[$first] =~ /^Executing '$test.*':$/; + } + + my ($last); + for ($last = $#output; $last >= 0; $last--) { + $last--, last if $output[$last] =~ /^Timer: \d+ ticks$/; + } + + if ($last < $first) { + my ($no_first) = $first > $#output; + my ($no_last) = $last < $#output; + die "Couldn't locate output.\n"; + } + + return @output[$first ... $last]; +} + +sub fix_exit_codes { + my (@output) = @_; + + # Remove lines that look like exit codes. + # Exit codes are supposed to be printed in the form "process: exit(code)" + # but people get unfortunately creative with it. + for (my ($i) = 0; $i <= $#output; $i++) { + local ($_) = $output[$i]; + + my ($process, $code); + if ((($process, $code) = /^([-a-z0-9 ]+):.*[ \(](-?\d+)\b\)?$/) + || (($process, $code) = /^([-a-z0-9 ]+) exit\((-?\d+)\)$/) + || (($process, $code) + = /^([-a-z0-9 ]+) \(.*\): exit\((-?\d+)\)$/) + || (($process, $code) = /^([-a-z0-9 ]+):\( (-?\d+) \) $/) + || (($code, $process) = /^shell: exit\((-?\d+)\) \| ([-a-z0-9]+)/) + ) { + splice (@output, $i, 1); + $i--; + } + } + + return @output; +} + +sub compare_output { + my ($exp, @actual) = @_; + @actual = fix_exit_codes (get_core_output (map ("$_\n", @actual))); + die "Program produced no output.\n" if !@actual; + + my ($details) = ""; + $details .= "$test actual output:\n"; + $details .= join ('', map (" $_", @actual)); + + my (@exp) = map ("$_\n", snarf ($exp)); + + my ($fuzzy_match) = 0; + while (@exp != 0) { + my (@expected); + while (@exp != 0) { + my ($s) = shift (@exp); + last if $s eq "--OR--\n"; + push (@expected, $s); + } + + $details .= "\n$test acceptable output:\n"; + $details .= join ('', map (" $_", @expected)); + + # Check whether they're the same. + if ($#actual == $#expected) { + my ($eq) = 1; + for (my ($i) = 0; $i <= $#expected; $i++) { + $eq = 0 if $actual[$i] ne $expected[$i]; + } + return if $eq; + } + + # They differ. Output a diff. + my (@diff) = ""; + my ($d) = Algorithm::Diff->new (\@expected, \@actual); + my ($not_fuzzy_match) = 0; + while ($d->Next ()) { + my ($ef, $el, $af, $al) = $d->Get (qw (min1 max1 min2 max2)); + if ($d->Same ()) { + push (@diff, map (" $_", $d->Items (1))); + } else { + push (@diff, map ("- $_", $d->Items (1))) if $d->Items (1); + push (@diff, map ("+ $_", $d->Items (2))) if $d->Items (2); + if ($d->Items (1) + || grep (/\($test\)|exit\(-?\d+\)|dying due to|Page fault/, + $d->Items (2))) { + $not_fuzzy_match = 1; + } + } + } + $fuzzy_match = 1 if !$not_fuzzy_match; + + $details .= "Differences in `diff -u' format:\n"; + $details .= join ('', @diff); + $details .= "(This is considered a `fuzzy match'.)\n" + if !$not_fuzzy_match; + } + + if ($fuzzy_match) { + $details = + "This test passed, but with extra, unexpected output.\n" + . "Please inspect your code to make sure that it does not\n" + . "produce output other than as specified in the project\n" + . "description.\n\n" + . "$details"; + } else { + $details = + "This test failed because its output did not match any\n" + . "of the acceptable form(s).\n\n" + . "$details"; + } + + $details{$test} = $details; + die "Output differs from expected. Details at end of file.\n" + unless $fuzzy_match; +} + +sub write_grades { + my (@summary) = snarf ("$GRADES_DIR/tests.txt"); + + my ($ploss) = 0; + my ($tloss) = 0; + my ($total) = 0; + my ($warnings) = 0; + for (my ($i) = 0; $i <= $#summary; $i++) { + local ($_) = $summary[$i]; + if (my ($loss, $test) = /^ -(\d+) ([-a-zA-Z0-9]+):/) { + my ($result) = $result{$test} || "Not tested."; + + if ($result eq 'ok') { + if (!defined $details{$test}) { + # Test successful and no warnings. + splice (@summary, $i, 1); + $i--; + } else { + # Test successful with warnings. + s/-(\d+) //; + $summary[$i] = $_; + splice (@summary, $i + 1, 0, + " Test passed with warnings. " + . "Details at end of file."); + $warnings++; + } + } else { + $ploss += $loss; + $tloss += $loss; + splice (@summary, $i + 1, 0, + map (" $_", split ("\n", $result))); + } + } elsif (my ($ptotal) = /^Score: \/(\d+)$/) { + $total += $ptotal; + $summary[$i] = "Score: " . ($ptotal - $ploss) . "/$ptotal"; + splice (@summary, $i, 0, " All tests passed.") + if $ploss == 0 && !$warnings; + $ploss = 0; + $warnings = 0; + $i++; + } + } + my ($ts) = "(" . ($total - $tloss) . "/" . $total . ")"; + $summary[0] =~ s/\[\[total\]\]/$ts/; + + open (SUMMARY, ">tests.out"); + print SUMMARY map ("$_\n", @summary); + close (SUMMARY); +} + +sub write_details { + open (DETAILS, ">details.out"); + my ($n) = 0; + for my $test (@TESTS) { + next if $result{$test} eq 'ok' && !defined $details{$test}; + + my ($details) = $details{$test}; + next if !defined ($details) && ! -e "output/$test/run.out"; + + my ($banner); + if ($result{$test} ne 'ok') { + $banner = "$test failure details"; + } else { + $banner = "$test warnings"; + } + + print DETAILS "\n" if $n++; + print DETAILS "--- $banner ", '-' x (50 - length ($banner)); + print DETAILS "\n\n"; + + if (!defined $details) { + my (@output) = snarf ("output/$test/run.out"); + + # Print only the first in a series of recursing panics. + my ($panic) = 0; + for my $i (0...$#output) { + local ($_) = $output[$i]; + if (/PANIC/ && $panic++ > 0) { + @output = @output[0...$i]; + push (@output, + "[...details of recursive panic omitted...]"); + last; + } + } + $details = "Output:\n\n" . join ('', map ("$_\n", @output)); + } + print DETAILS $details; + + print DETAILS "\n", "-" x 10, "\n\n$extra{$test}" + if defined $extra{$test}; + } + close (DETAILS); + +} + +sub xsystem { + my ($command, %options) = @_; + print "$command\n" if $verbose || $options{VERBOSE}; + + my ($log) = $options{LOG}; + + my ($pid, $status); + eval { + local $SIG{ALRM} = sub { die "alarm\n" }; + alarm $options{TIMEOUT} if defined $options{TIMEOUT}; + $pid = fork; + die "fork: $!\n" if !defined $pid; + if (!$pid) { + if (defined $log) { + open (STDOUT, ">output/$log.out"); + open (STDERR, ">output/$log.err"); + } + exec ($command); + exit (-1); + } + waitpid ($pid, 0); + $status = $?; + alarm 0; + }; + + my ($ok); + if ($@) { + die unless $@ eq "alarm\n"; # propagate unexpected errors + print "Timed out: "; + for (my ($i) = 0; $i < 10; $i++) { + kill ('SIGTERM', $pid); + sleep (1); + my ($retval) = waitpid ($pid, WNOHANG); + last if $retval == $pid || $retval == -1; + print "Waiting for $pid to die" if $i == 0; + print "."; + } + $ok = 1; + } else { + if (WIFSIGNALED ($status)) { + my ($signal) = WTERMSIG ($status); + die "Interrupted\n" if $signal == SIGINT; + print "Child terminated with signal $signal\n"; + } + + my ($exp_status) = !defined ($options{EXPECT}) ? 0 : $options{EXPECT}; + $ok = WIFEXITED ($status) && WEXITSTATUS ($status) == $exp_status; + } + + + if (!$ok && defined $options{DIE}) { + my ($msg) = $options{DIE}; + if (defined ($log)) { + chomp ($msg); + $msg .= "; see output/$log.err and output/$log.out for details\n"; + } + die $msg; + } elsif (defined ($log) && $ok) { + unlink ("output/$log.err"); + } + + return $ok; +} + +sub snarf { + my ($file) = @_; + open (OUTPUT, $file) or die "$file: open: $!\n"; + my (@lines) = ; + chomp (@lines); + close (OUTPUT); + return wantarray ? @lines : join ('', map ("$_\n", @lines)); +} + +sub files_equal { + my ($a, $b) = @_; + my ($equal); + open (A, "<$a") or die "$a: open: $!\n"; + open (B, "<$b") or die "$b: open: $!\n"; + if (-s A != -s B) { + $equal = 0; + } else { + my ($sa, $sb); + for (;;) { + sysread (A, $sa, 1024); + sysread (B, $sb, 1024); + $equal = 0, last if $sa ne $sb; + $equal = 1, last if $sa eq ''; + } + } + close (A); + close (B); + return $equal; +} + +sub file_contains { + my ($file, $expected) = @_; + open (FILE, "<$file") or die "$file: open: $!\n"; + my ($actual); + sysread (FILE, $actual, -s FILE); + my ($equal) = $actual eq $expected; + close (FILE); + return $equal; +} + +sub number_lines { + my ($ln, $lines) = @_; + my ($out); + for my $line (@$lines) { + chomp $line; + $out .= sprintf "%4d %s\n", $ln++, $line; + } + return $out; +} diff --git a/grading/filesys/seq-block.inc b/grading/filesys/seq-block.inc new file mode 100644 index 0000000..e5424cd --- /dev/null +++ b/grading/filesys/seq-block.inc @@ -0,0 +1,21 @@ +/* -*- c -*- */ + +#include "fslib.h" + +static char buf[TEST_SIZE]; + +static size_t +return_block_size (void) +{ + return BLOCK_SIZE; +} + +int +main (void) +{ + msg ("begin"); + seq_test ("noodle", buf, sizeof buf, sizeof buf, 4, + return_block_size, NULL); + msg ("end"); + return 0; +} diff --git a/grading/filesys/seq-random.inc b/grading/filesys/seq-random.inc new file mode 100644 index 0000000..a0e6106 --- /dev/null +++ b/grading/filesys/seq-random.inc @@ -0,0 +1,22 @@ +/* -*- c -*- */ + +#include +#include "fslib.h" + +static char buf[TEST_SIZE]; + +static size_t +return_random (void) +{ + return random_ulong () % 1031 + 1; +} + +int +main (void) +{ + msg ("begin"); + random_init (-1); + seq_test ("nibble", buf, sizeof buf, sizeof buf, 5, return_random, NULL); + msg ("end"); + return 0; +} diff --git a/grading/filesys/sm-create.c b/grading/filesys/sm-create.c new file mode 100644 index 0000000..47f4f99 --- /dev/null +++ b/grading/filesys/sm-create.c @@ -0,0 +1,3 @@ +const char test_name[] = "sm-create"; +#define TEST_SIZE 5678 +#include "create.inc" diff --git a/grading/filesys/sm-create.exp b/grading/filesys/sm-create.exp new file mode 100644 index 0000000..b2c53ba --- /dev/null +++ b/grading/filesys/sm-create.exp @@ -0,0 +1,5 @@ +(sm-create) begin +(sm-create) create testfile +(sm-create) open "testfile" for verification +(sm-create) close "testfile" +(sm-create) end diff --git a/grading/filesys/sm-full.c b/grading/filesys/sm-full.c new file mode 100644 index 0000000..7fabd50 --- /dev/null +++ b/grading/filesys/sm-full.c @@ -0,0 +1,3 @@ +const char test_name[] = "sm-full"; +#define TEST_SIZE 5678 +#include "full.inc" diff --git a/grading/filesys/sm-full.exp b/grading/filesys/sm-full.exp new file mode 100644 index 0000000..44c99ee --- /dev/null +++ b/grading/filesys/sm-full.exp @@ -0,0 +1,8 @@ +(sm-full) begin +(sm-full) create "quux" +(sm-full) open "quux" +(sm-full) writing "quux" +(sm-full) close "quux" +(sm-full) open "quux" for verification +(sm-full) close "quux" +(sm-full) end diff --git a/grading/filesys/sm-random.c b/grading/filesys/sm-random.c new file mode 100644 index 0000000..56f4a73 --- /dev/null +++ b/grading/filesys/sm-random.c @@ -0,0 +1,4 @@ +const char test_name[] = "sm-random"; +#define BLOCK_SIZE 13 +#define TEST_SIZE (13 * 123) +#include "random.inc" diff --git a/grading/filesys/sm-random.exp b/grading/filesys/sm-random.exp new file mode 100644 index 0000000..aba5461 --- /dev/null +++ b/grading/filesys/sm-random.exp @@ -0,0 +1,6 @@ +(sm-random) begin +(sm-random) create "bazzle" +(sm-random) open "bazzle" +(sm-random) write "bazzle" in random order +(sm-random) read "bazzle" in random order +(sm-random) close "bazzle" diff --git a/grading/filesys/sm-seq-block.c b/grading/filesys/sm-seq-block.c new file mode 100644 index 0000000..a6a1a4b --- /dev/null +++ b/grading/filesys/sm-seq-block.c @@ -0,0 +1,4 @@ +const char test_name[] = "sm-seq-block"; +#define TEST_SIZE 5678 +#define BLOCK_SIZE 513 +#include "seq-block.inc" diff --git a/grading/filesys/sm-seq-block.exp b/grading/filesys/sm-seq-block.exp new file mode 100644 index 0000000..f7b4ccc --- /dev/null +++ b/grading/filesys/sm-seq-block.exp @@ -0,0 +1,8 @@ +(sm-seq-block) begin +(sm-seq-block) create "noodle" +(sm-seq-block) open "noodle" +(sm-seq-block) writing "noodle" +(sm-seq-block) close "noodle" +(sm-seq-block) open "noodle" for verification +(sm-seq-block) close "noodle" +(sm-seq-block) end diff --git a/grading/filesys/sm-seq-random.c b/grading/filesys/sm-seq-random.c new file mode 100644 index 0000000..0ec496e --- /dev/null +++ b/grading/filesys/sm-seq-random.c @@ -0,0 +1,3 @@ +const char test_name[] = "sm-seq-random"; +#define TEST_SIZE 5678 +#include "seq-random.inc" diff --git a/grading/filesys/sm-seq-random.exp b/grading/filesys/sm-seq-random.exp new file mode 100644 index 0000000..9432552 --- /dev/null +++ b/grading/filesys/sm-seq-random.exp @@ -0,0 +1,8 @@ +(sm-seq-random) begin +(sm-seq-random) create "nibble" +(sm-seq-random) open "nibble" +(sm-seq-random) writing "nibble" +(sm-seq-random) close "nibble" +(sm-seq-random) open "nibble" for verification +(sm-seq-random) close "nibble" +(sm-seq-random) end diff --git a/grading/filesys/tests.txt b/grading/filesys/tests.txt index 9f5ad13..901f5a1 100644 --- a/grading/filesys/tests.txt +++ b/grading/filesys/tests.txt @@ -23,7 +23,7 @@ File growth grow-seq-lg: extend empty file sequentially to large size, verify grow-file-size: filesize must return proper value as file grows grow-tell: tell must return proper value as file grows - grow-sparse: create empty file, seek to 128 kB, write byte, verify zeroing + grow-sparse: create empty file, seek past 64 kB, write byte, verify zeroing grow-root-sm: create 20 small files in root directory grow-root-lg: create 50 small files in root directory grow-dir-lg: create subdirectory, create 50 small files in it diff --git a/grading/vm/Make.progs b/grading/vm/Make.progs index d191fa1..aa545b2 100644 --- a/grading/vm/Make.progs +++ b/grading/vm/Make.progs @@ -3,15 +3,15 @@ TESTS = \ page-linear page-parallel page-merge-seq page-merge-par \ page-shuffle mmap-read mmap-close mmap-unmap mmap-overlap \ mmap-twice mmap-write mmap-exit mmap-shuffle -pt_grow_stack_SRC = pt-grow-stack.c arc4.c cksum.c -pt_big_stk_obj_SRC = pt-big-stk-obj.c arc4.c cksum.c +pt_grow_stack_SRC = pt-grow-stack.c ../lib/arc4.c ../lib/cksum.c +pt_big_stk_obj_SRC = pt-big-stk-obj.c ../lib/arc4.c ../lib/cksum.c pt_bad_addr_SRC = pt-bad-addr.c pt_write_code_SRC = pt-write-code.c -page_linear_SRC = page-linear.c arc4.c +page_linear_SRC = page-linear.c ../lib/arc4.c page_parallel_SRC = page-parallel.c -page_merge_seq_SRC = page-merge-seq.c arc4.c -page_merge_par_SRC = page-merge-par.c arc4.c -page_shuffle_SRC = page-shuffle.c arc4.c cksum.c +page_merge_seq_SRC = page-merge-seq.c ../lib/arc4.c +page_merge_par_SRC = page-merge-par.c ../lib/arc4.c +page_shuffle_SRC = page-shuffle.c ../lib/arc4.c ../lib/cksum.c mmap_read_SRC = mmap-read.c mmap_close_SRC = mmap-close.c mmap_unmap_SRC = mmap-unmap.c @@ -19,9 +19,9 @@ mmap_overlap_SRC = mmap-overlap.c mmap_twice_SRC = mmap-twice.c mmap_write_SRC = mmap-write.c mmap_exit_SRC = mmap-exit.c -mmap_shuffle_SRC = mmap-shuffle.c arc4.c cksum.c +mmap_shuffle_SRC = mmap-shuffle.c ../lib/arc4.c ../lib/cksum.c PROGS = $(TESTS) child-linear child-sort child-mm-wrt -child_linear_SRC = child-linear.c arc4.c +child_linear_SRC = child-linear.c ../lib/arc4.c child_sort_SRC = child-sort.c child_mm_wrt_SRC = child-mm-wrt.c diff --git a/grading/vm/arc4.c b/grading/vm/arc4.c deleted file mode 100644 index cd7fd6f..0000000 --- a/grading/vm/arc4.c +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include "arc4.h" - -/* Swap bytes. */ -static inline void -swap_byte (uint8_t *a, uint8_t *b) -{ - uint8_t t = *a; - *a = *b; - *b = t; -} - -void -arc4_init (struct arc4 *arc4, const void *key_, size_t size) -{ - const uint8_t *key = key_; - size_t key_idx; - uint8_t *s; - int i, j; - - s = arc4->s; - arc4->i = arc4->j = 0; - for (i = 0; i < 256; i++) - s[i] = i; - for (key_idx = 0, i = j = 0; i < 256; i++) - { - j = (j + s[i] + key[key_idx]) & 255; - swap_byte (s + i, s + j); - if (++key_idx >= size) - key_idx = 0; - } -} - -void -arc4_crypt (struct arc4 *arc4, void *buf_, size_t size) -{ - uint8_t *buf = buf_; - uint8_t *s; - uint8_t i, j; - - s = arc4->s; - i = arc4->i; - j = arc4->j; - while (size-- > 0) - { - i += 1; - j += s[i]; - swap_byte (s + i, s + j); - *buf++ ^= s[(s[i] + s[j]) & 255]; - } - arc4->i = i; - arc4->j = j; -} diff --git a/grading/vm/arc4.h b/grading/vm/arc4.h deleted file mode 100644 index ccb260c..0000000 --- a/grading/vm/arc4.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef ARC4_H -#define ARC4_H - -#include -#include - -/* Alleged RC4 algorithm encryption state. */ -struct arc4 - { - uint8_t s[256]; - uint8_t i, j; - }; - -void arc4_init (struct arc4 *, const void *, size_t); -void arc4_crypt (struct arc4 *, void *, size_t); - - -#endif /* arc4.h */ diff --git a/grading/vm/child-linear.c b/grading/vm/child-linear.c index e0cf2f1..4fa58b4 100644 --- a/grading/vm/child-linear.c +++ b/grading/vm/child-linear.c @@ -1,6 +1,6 @@ #include #include -#include "arc4.h" +#include "../lib/arc4.h" #define SIZE (128 * 1024) diff --git a/grading/vm/cksum.c b/grading/vm/cksum.c deleted file mode 100644 index 1a4219c..0000000 --- a/grading/vm/cksum.c +++ /dev/null @@ -1,86 +0,0 @@ -/* crctab[] and cksum() are from the `cksum' entry in SUSv3. */ - -#include "cksum.h" - -static unsigned long crctab[] = { - 0x00000000, - 0x04c11db7, 0x09823b6e, 0x0d4326d9, 0x130476dc, 0x17c56b6b, - 0x1a864db2, 0x1e475005, 0x2608edb8, 0x22c9f00f, 0x2f8ad6d6, - 0x2b4bcb61, 0x350c9b64, 0x31cd86d3, 0x3c8ea00a, 0x384fbdbd, - 0x4c11db70, 0x48d0c6c7, 0x4593e01e, 0x4152fda9, 0x5f15adac, - 0x5bd4b01b, 0x569796c2, 0x52568b75, 0x6a1936c8, 0x6ed82b7f, - 0x639b0da6, 0x675a1011, 0x791d4014, 0x7ddc5da3, 0x709f7b7a, - 0x745e66cd, 0x9823b6e0, 0x9ce2ab57, 0x91a18d8e, 0x95609039, - 0x8b27c03c, 0x8fe6dd8b, 0x82a5fb52, 0x8664e6e5, 0xbe2b5b58, - 0xbaea46ef, 0xb7a96036, 0xb3687d81, 0xad2f2d84, 0xa9ee3033, - 0xa4ad16ea, 0xa06c0b5d, 0xd4326d90, 0xd0f37027, 0xddb056fe, - 0xd9714b49, 0xc7361b4c, 0xc3f706fb, 0xceb42022, 0xca753d95, - 0xf23a8028, 0xf6fb9d9f, 0xfbb8bb46, 0xff79a6f1, 0xe13ef6f4, - 0xe5ffeb43, 0xe8bccd9a, 0xec7dd02d, 0x34867077, 0x30476dc0, - 0x3d044b19, 0x39c556ae, 0x278206ab, 0x23431b1c, 0x2e003dc5, - 0x2ac12072, 0x128e9dcf, 0x164f8078, 0x1b0ca6a1, 0x1fcdbb16, - 0x018aeb13, 0x054bf6a4, 0x0808d07d, 0x0cc9cdca, 0x7897ab07, - 0x7c56b6b0, 0x71159069, 0x75d48dde, 0x6b93dddb, 0x6f52c06c, - 0x6211e6b5, 0x66d0fb02, 0x5e9f46bf, 0x5a5e5b08, 0x571d7dd1, - 0x53dc6066, 0x4d9b3063, 0x495a2dd4, 0x44190b0d, 0x40d816ba, - 0xaca5c697, 0xa864db20, 0xa527fdf9, 0xa1e6e04e, 0xbfa1b04b, - 0xbb60adfc, 0xb6238b25, 0xb2e29692, 0x8aad2b2f, 0x8e6c3698, - 0x832f1041, 0x87ee0df6, 0x99a95df3, 0x9d684044, 0x902b669d, - 0x94ea7b2a, 0xe0b41de7, 0xe4750050, 0xe9362689, 0xedf73b3e, - 0xf3b06b3b, 0xf771768c, 0xfa325055, 0xfef34de2, 0xc6bcf05f, - 0xc27dede8, 0xcf3ecb31, 0xcbffd686, 0xd5b88683, 0xd1799b34, - 0xdc3abded, 0xd8fba05a, 0x690ce0ee, 0x6dcdfd59, 0x608edb80, - 0x644fc637, 0x7a089632, 0x7ec98b85, 0x738aad5c, 0x774bb0eb, - 0x4f040d56, 0x4bc510e1, 0x46863638, 0x42472b8f, 0x5c007b8a, - 0x58c1663d, 0x558240e4, 0x51435d53, 0x251d3b9e, 0x21dc2629, - 0x2c9f00f0, 0x285e1d47, 0x36194d42, 0x32d850f5, 0x3f9b762c, - 0x3b5a6b9b, 0x0315d626, 0x07d4cb91, 0x0a97ed48, 0x0e56f0ff, - 0x1011a0fa, 0x14d0bd4d, 0x19939b94, 0x1d528623, 0xf12f560e, - 0xf5ee4bb9, 0xf8ad6d60, 0xfc6c70d7, 0xe22b20d2, 0xe6ea3d65, - 0xeba91bbc, 0xef68060b, 0xd727bbb6, 0xd3e6a601, 0xdea580d8, - 0xda649d6f, 0xc423cd6a, 0xc0e2d0dd, 0xcda1f604, 0xc960ebb3, - 0xbd3e8d7e, 0xb9ff90c9, 0xb4bcb610, 0xb07daba7, 0xae3afba2, - 0xaafbe615, 0xa7b8c0cc, 0xa379dd7b, 0x9b3660c6, 0x9ff77d71, - 0x92b45ba8, 0x9675461f, 0x8832161a, 0x8cf30bad, 0x81b02d74, - 0x857130c3, 0x5d8a9099, 0x594b8d2e, 0x5408abf7, 0x50c9b640, - 0x4e8ee645, 0x4a4ffbf2, 0x470cdd2b, 0x43cdc09c, 0x7b827d21, - 0x7f436096, 0x7200464f, 0x76c15bf8, 0x68860bfd, 0x6c47164a, - 0x61043093, 0x65c52d24, 0x119b4be9, 0x155a565e, 0x18197087, - 0x1cd86d30, 0x029f3d35, 0x065e2082, 0x0b1d065b, 0x0fdc1bec, - 0x3793a651, 0x3352bbe6, 0x3e119d3f, 0x3ad08088, 0x2497d08d, - 0x2056cd3a, 0x2d15ebe3, 0x29d4f654, 0xc5a92679, 0xc1683bce, - 0xcc2b1d17, 0xc8ea00a0, 0xd6ad50a5, 0xd26c4d12, 0xdf2f6bcb, - 0xdbee767c, 0xe3a1cbc1, 0xe760d676, 0xea23f0af, 0xeee2ed18, - 0xf0a5bd1d, 0xf464a0aa, 0xf9278673, 0xfde69bc4, 0x89b8fd09, - 0x8d79e0be, 0x803ac667, 0x84fbdbd0, 0x9abc8bd5, 0x9e7d9662, - 0x933eb0bb, 0x97ffad0c, 0xafb010b1, 0xab710d06, 0xa6322bdf, - 0xa2f33668, 0xbcb4666d, 0xb8757bda, 0xb5365d03, 0xb1f740b4 -}; - -/* This is the algorithm used by the Posix `cksum' utility. */ -unsigned long cksum(const unsigned char *b, size_t n) -{ - register unsigned i, c, s = 0; - for (i = n; i > 0; --i) { - c = (unsigned)(*b++); - s = (s << 8) ^ crctab[(s >> 24) ^ c]; - } - while (n != 0) { - c = n & 0377; - n >>= 8; - s = (s << 8) ^ crctab[(s >> 24) ^ c]; - } - return ~s; -} - -#ifdef STANDALONE_TEST -#include -int -main (void) -{ - char buf[65536]; - int n = fread (buf, 1, sizeof buf, stdin); - printf ("%lu\n", cksum (buf, n)); - return 0; -} -#endif diff --git a/grading/vm/cksum.h b/grading/vm/cksum.h deleted file mode 100644 index 79b7c42..0000000 --- a/grading/vm/cksum.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef CKSUM_H -#define CKSUM_H - -#include - -unsigned long cksum(const unsigned char *b, size_t n); - -#endif /* cksum.h */ diff --git a/grading/vm/mmap-close.c b/grading/vm/mmap-close.c index 54668b8..901b34d 100644 --- a/grading/vm/mmap-close.c +++ b/grading/vm/mmap-close.c @@ -1,6 +1,6 @@ #include #include -#include "arc4.h" +#include "../lib/arc4.h" #include "sample.inc" #ifdef PINTOS #include diff --git a/grading/vm/mmap-shuffle.c b/grading/vm/mmap-shuffle.c index d576e9a..1eccc03 100644 --- a/grading/vm/mmap-shuffle.c +++ b/grading/vm/mmap-shuffle.c @@ -5,8 +5,8 @@ #else #include "posix-compat.h" #endif -#include "arc4.h" -#include "cksum.h" +#include "../lib/arc4.h" +#include "../lib/cksum.h" #define SIZE (63 * 1024) /* Max file size. */ static char *buf = (char *) 0x10000000; diff --git a/grading/vm/page-linear.c b/grading/vm/page-linear.c index 00ffb17..18ba30c 100644 --- a/grading/vm/page-linear.c +++ b/grading/vm/page-linear.c @@ -1,5 +1,5 @@ #include -#include "arc4.h" +#include "../lib/arc4.h" #define SIZE (128 * 1024) diff --git a/grading/vm/page-merge-par.c b/grading/vm/page-merge-par.c index c602d16..5c5d62b 100644 --- a/grading/vm/page-merge-par.c +++ b/grading/vm/page-merge-par.c @@ -5,7 +5,7 @@ #else #include "posix-compat.h" #endif -#include "arc4.h" +#include "../lib/arc4.h" #define CHUNK_SIZE (63 * 1024) /* Max file size. */ #define CHUNK_CNT 8 /* Number of chunks. */ diff --git a/grading/vm/page-merge-seq.c b/grading/vm/page-merge-seq.c index 306910d..f7ac14c 100644 --- a/grading/vm/page-merge-seq.c +++ b/grading/vm/page-merge-seq.c @@ -5,7 +5,7 @@ #else #include "posix-compat.h" #endif -#include "arc4.h" +#include "../lib/arc4.h" #define CHUNK_SIZE (63 * 1024) /* Max file size. */ #define CHUNK_CNT 16 /* Number of chunks. */ diff --git a/grading/vm/page-shuffle.c b/grading/vm/page-shuffle.c index 9f65099..ae2559e 100644 --- a/grading/vm/page-shuffle.c +++ b/grading/vm/page-shuffle.c @@ -1,7 +1,7 @@ #include #include -#include "arc4.h" -#include "cksum.h" +#include "../lib/arc4.h" +#include "../lib/cksum.h" #define SIZE (128 * 1024) diff --git a/grading/vm/pt-big-stk-obj.c b/grading/vm/pt-big-stk-obj.c index 70f5d79..3198c7c 100644 --- a/grading/vm/pt-big-stk-obj.c +++ b/grading/vm/pt-big-stk-obj.c @@ -1,7 +1,7 @@ #include #include -#include "arc4.h" -#include "cksum.h" +#include "../lib/arc4.h" +#include "../lib/cksum.h" int main (void) diff --git a/grading/vm/pt-grow-stack.c b/grading/vm/pt-grow-stack.c index 805db98..596285a 100644 --- a/grading/vm/pt-grow-stack.c +++ b/grading/vm/pt-grow-stack.c @@ -1,7 +1,7 @@ #include #include -#include "arc4.h" -#include "cksum.h" +#include "../lib/arc4.h" +#include "../lib/cksum.h" int main (void) -- 2.30.2