From: Ben Pfaff Date: Wed, 8 Dec 2004 07:54:45 +0000 (+0000) Subject: Add more tests, results. X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5db27be45b12cc35feb6f1de19861d180e5620fe;p=pintos-anon Add more tests, results. --- diff --git a/grading/filesys/Make.progs b/grading/filesys/Make.progs index 8ae3a10..1aa2a8f 100644 --- a/grading/filesys/Make.progs +++ b/grading/filesys/Make.progs @@ -5,8 +5,9 @@ grow-create grow-seq-sm grow-seq-lg grow-file-size grow-tell \ grow-sparse grow-too-big grow-root-sm grow-root-lg grow-dir-lg \ grow-two-files dir-mkdir dir-rmdir dir-mk-vine dir-rm-vine dir-mk-tree \ dir-rm-tree dir-lsdir dir-rm-cwd dir-rm-cwd-cd dir-rm-parent \ -dir-rm-root dir-over-file dir-under-file dir-empty-name dir-open \ -syn-remove syn-read child-syn-read +dir-rm-root dir-over-file dir-under-file dir-empty-name dir-open \ +syn-remove syn-read child-syn-read syn-write child-syn-wrt syn-rw \ +child-syn-rw sm_create_SRC = sm-create.c fslib.c fsmain.c sm_full_SRC = sm-full.c fslib.c fsmain.c @@ -45,4 +46,7 @@ dir_open_SRC = dir-open.c fslib.c fsmain.c syn_remove_SRC = syn-remove.c fslib.c fsmain.c syn_read_SRC = syn-read.c fslib.c fsmain.c child_syn_read_SRC = child-syn-read.c fslib.c - +syn_write_SRC = syn-write.c fslib.c fsmain.c +child_syn_wrt_SRC = child-syn-wrt.c fslib.c +syn_rw_SRC = syn-rw.c fslib.c fsmain.c +child_syn_rw_SRC = child-syn-rw.c fslib.c diff --git a/grading/filesys/child-syn-read.c b/grading/filesys/child-syn-read.c index 90c3ab0..f4e4917 100644 --- a/grading/filesys/child-syn-read.c +++ b/grading/filesys/child-syn-read.c @@ -3,25 +3,23 @@ #include #include #include "fslib.h" +#include "syn-read.h" const char test_name[128] = "child-syn-read"; -static char buf[1024]; +static char buf[BUF_SIZE]; int main (int argc, const char *argv[]) { - const char *filename = "data"; int child_idx; int fd; size_t i; quiet = true; - check (argc == 3, "argc must be 3, actually %d", argc); + check (argc == 2, "argc must be 2, actually %d", argc); child_idx = atoi (argv[1]); - check (atoi (argv[2]) == (int) sizeof buf, - "argv[2] must be %zu, actually %s", sizeof buf, argv[2]); random_init (0); random_bytes (buf, sizeof buf); @@ -31,7 +29,7 @@ main (int argc, const char *argv[]) { char c; check (read (fd, &c, 1) > 0, "read \"%s\"", filename); - check (c != buf[i], "byte %zu differs from expected", i); + compare_bytes (&c, buf + i, 1, i, filename); } close (fd); diff --git a/grading/filesys/child-syn-rw.c b/grading/filesys/child-syn-rw.c new file mode 100644 index 0000000..64e93c7 --- /dev/null +++ b/grading/filesys/child-syn-rw.c @@ -0,0 +1,46 @@ +#include +#include +#include +#include +#include +#include "fslib.h" +#include "syn-rw.h" + +const char test_name[128] = "child-syn-rw"; + +static char buf1[BUF_SIZE]; +static char buf2[BUF_SIZE]; + +int +main (int argc, const char *argv[]) +{ + int child_idx; + int fd; + size_t ofs; + + quiet = true; + + check (argc == 2, "argc must be 2, actually %d", argc); + child_idx = atoi (argv[1]); + + random_init (0); + random_bytes (buf1, sizeof buf1); + + check ((fd = open (filename)) > 1, "open \"%s\"", filename); + ofs = 0; + while (ofs < sizeof buf2) + { + int bytes_read = read (fd, buf2 + ofs, sizeof buf2 - ofs); + check (bytes_read >= -1 && bytes_read <= (int) (sizeof buf2 - ofs), + "%zu-byte read on \"%s\" returned invalid value of %d", + sizeof buf2 - ofs, filename, bytes_read); + if (bytes_read > 0) + { + compare_bytes (buf2 + ofs, buf1 + ofs, bytes_read, ofs, filename); + ofs += bytes_read; + } + } + close (fd); + + return child_idx; +} diff --git a/grading/filesys/child-syn-wrt.c b/grading/filesys/child-syn-wrt.c new file mode 100644 index 0000000..2a57281 --- /dev/null +++ b/grading/filesys/child-syn-wrt.c @@ -0,0 +1,33 @@ +#include +#include +#include +#include "fslib.h" +#include "syn-write.h" + +const char test_name[] = "child-syn-wrt"; + +char buf[BUF_SIZE]; + +int +main (int argc, char *argv[]) +{ + int child_idx; + int fd; + + quiet = true; + + check (argc == 2, "argc must be 2, actually %d", argc); + child_idx = atoi (argv[1]); + + random_init (0); + random_bytes (buf, sizeof buf); + + check ((fd = open (filename)) > 1, "open \"%s\"", filename); + seek (fd, CHUNK_SIZE * child_idx); + check (write (fd, buf + CHUNK_SIZE * child_idx, CHUNK_SIZE) > 0, + "write \"%s\"", filename); + msg ("close \"%s\"", filename); + close (fd); + + return child_idx; +} diff --git a/grading/filesys/dir-mk-tree.exp b/grading/filesys/dir-mk-tree.exp index 141a593..5558a16 100644 --- a/grading/filesys/dir-mk-tree.exp +++ b/grading/filesys/dir-mk-tree.exp @@ -1,4 +1,5 @@ (dir-mk-tree) begin -(dir-mk-tree) creating /0/0/0/0 through /4/4/4/1... -(dir-mk-tree) open "/0/1/2/1" +(dir-mk-tree) creating /0/0/0/0 through /3/2/2/3... +(dir-mk-tree) open "/0/2/0/3" +(dir-mk-tree) close "/0/2/0/3" (dir-mk-tree) end diff --git a/grading/filesys/dir-over-file.exp b/grading/filesys/dir-over-file.exp index 206103b..2bc552b 100644 --- a/grading/filesys/dir-over-file.exp +++ b/grading/filesys/dir-over-file.exp @@ -1,4 +1,4 @@ -(dir-dir-as-file) begin -(dir-dir-as-file) mkdir "abc" -(dir-dir-as-file) create "abc" (must return false) -(dir-dir-as-file) end +(dir-over-file) begin +(dir-over-file) mkdir "abc" +(dir-over-file) create "abc" (must return false) +(dir-over-file) end diff --git a/grading/filesys/dir-rm-cwd-cd.c b/grading/filesys/dir-rm-cwd-cd.c index fe3febd..f1916fb 100644 --- a/grading/filesys/dir-rm-cwd-cd.c +++ b/grading/filesys/dir-rm-cwd-cd.c @@ -10,7 +10,8 @@ test_main (void) check (chdir ("a"), "chdir \"a\""); msg ("remove \"/a\" (must not crash)"); if (remove ("/a")) - check (!chdir ("/a"), "chdir \"/a\" (remove succeeded so this must fail)"); + check (!chdir ("/a"), + "chdir \"/a\" (remove succeeded so this must return false)"); else check (chdir ("/a"), "chdir \"/a\" (remove failed so this must succeed)"); } diff --git a/grading/filesys/dir-rm-cwd-cd.exp b/grading/filesys/dir-rm-cwd-cd.exp new file mode 100644 index 0000000..fb8a9e7 --- /dev/null +++ b/grading/filesys/dir-rm-cwd-cd.exp @@ -0,0 +1,13 @@ +(dir-rm-cwd-cd) begin +(dir-rm-cwd-cd) mkdir "a" +(dir-rm-cwd-cd) chdir "a" +(dir-rm-cwd-cd) remove "/a" (must not crash) +(dir-rm-cwd-cd) chdir "/a" (remove succeeded so this must return false) +(dir-rm-cwd-cd) end +--OR-- +(dir-rm-cwd-cd) begin +(dir-rm-cwd-cd) mkdir "a" +(dir-rm-cwd-cd) chdir "a" +(dir-rm-cwd-cd) remove "/a" (must not crash) +(dir-rm-cwd-cd) chdir "/a" (remove failed so this must succeed) +(dir-rm-cwd-cd) end diff --git a/grading/filesys/dir-rm-tree.c b/grading/filesys/dir-rm-tree.c index 303f257..24cc21f 100644 --- a/grading/filesys/dir-rm-tree.c +++ b/grading/filesys/dir-rm-tree.c @@ -25,7 +25,7 @@ remove_tree (int at, int bt, int ct, int dt) msg ("removing /0/0/0/0 through /%d/%d/%d/%d...", at - 1, bt - 1, ct - 1, dt - 1); - quiet = false; + quiet = true; for (a = 0; a < at; a++) { for (b = 0; b < bt; b++) diff --git a/grading/filesys/dir-rm-tree.exp b/grading/filesys/dir-rm-tree.exp new file mode 100644 index 0000000..97bcd21 --- /dev/null +++ b/grading/filesys/dir-rm-tree.exp @@ -0,0 +1,7 @@ +(dir-rm-tree) begin +(dir-rm-tree) creating /0/0/0/0 through /3/2/2/3... +(dir-rm-tree) open "/0/2/0/3" +(dir-rm-tree) close "/0/2/0/3" +(dir-rm-tree) removing /0/0/0/0 through /3/2/2/3... +(dir-rm-tree) open "/3/0/2/0" (must return -1) +(dir-rm-tree) end diff --git a/grading/filesys/dir-rm-vine.c b/grading/filesys/dir-rm-vine.c index 571112a..20b52a2 100644 --- a/grading/filesys/dir-rm-vine.c +++ b/grading/filesys/dir-rm-vine.c @@ -31,5 +31,5 @@ test_main (void) *strrchr (tmp, '/') = 0; } - check (open (filename) == 1, "open \"%s\" (must return -1)", filename); + check (open (filename) == -1, "open \"%s\" (must return -1)", filename); } diff --git a/grading/filesys/dir-rm-vine.exp b/grading/filesys/dir-rm-vine.exp new file mode 100644 index 0000000..ecc1329 --- /dev/null +++ b/grading/filesys/dir-rm-vine.exp @@ -0,0 +1,38 @@ +(dir-rm-vine) begin +(dir-rm-vine) mkdir "0" +(dir-rm-vine) chdir "0" +(dir-rm-vine) mkdir "1" +(dir-rm-vine) chdir "1" +(dir-rm-vine) mkdir "2" +(dir-rm-vine) chdir "2" +(dir-rm-vine) mkdir "3" +(dir-rm-vine) chdir "3" +(dir-rm-vine) mkdir "4" +(dir-rm-vine) chdir "4" +(dir-rm-vine) mkdir "5" +(dir-rm-vine) chdir "5" +(dir-rm-vine) mkdir "6" +(dir-rm-vine) chdir "6" +(dir-rm-vine) mkdir "7" +(dir-rm-vine) chdir "7" +(dir-rm-vine) mkdir "8" +(dir-rm-vine) chdir "8" +(dir-rm-vine) mkdir "9" +(dir-rm-vine) chdir "9" +(dir-rm-vine) create "test" +(dir-rm-vine) chdir "/" +(dir-rm-vine) open "/0/1/2/3/4/5/6/7/8/9/test" +(dir-rm-vine) close "/0/1/2/3/4/5/6/7/8/9/test" +(dir-rm-vine) remove "/0/1/2/3/4/5/6/7/8/9/test" +(dir-rm-vine) remove "/0/1/2/3/4/5/6/7/8/9" +(dir-rm-vine) remove "/0/1/2/3/4/5/6/7/8" +(dir-rm-vine) remove "/0/1/2/3/4/5/6/7" +(dir-rm-vine) remove "/0/1/2/3/4/5/6" +(dir-rm-vine) remove "/0/1/2/3/4/5" +(dir-rm-vine) remove "/0/1/2/3/4" +(dir-rm-vine) remove "/0/1/2/3" +(dir-rm-vine) remove "/0/1/2" +(dir-rm-vine) remove "/0/1" +(dir-rm-vine) remove "/0" +(dir-rm-vine) open "/0/1/2/3/4/5/6/7/8/9/test" (must return -1) +(dir-rm-vine) end diff --git a/grading/filesys/fslib.c b/grading/filesys/fslib.c index a94a0d1..d5eeda8 100644 --- a/grading/filesys/fslib.c +++ b/grading/filesys/fslib.c @@ -8,10 +8,19 @@ bool quiet = false; static void -vmsg (const char *format, va_list args) +vmsg (const char *format, va_list args, const char *suffix) { - printf ("(%s) ", test_name); - vprintf (format, args); + /* We go to some trouble to stuff the entire message into a + single buffer and output it in a single system call, because + that'll (typically) ensure that it gets sent to the console + atomically. Otherwise kernel messages like "foo: exit(0)" + can end up being interleaved if we're unlucky. */ + static char buf[1024]; + + snprintf (buf, sizeof buf, "(%s) ", test_name); + vsnprintf (buf + strlen (buf), sizeof buf - strlen (buf), format, args); + strlcpy (buf + strlen (buf), suffix, sizeof buf - strlen (buf)); + write (STDOUT_FILENO, buf, strlen (buf)); } void @@ -22,8 +31,7 @@ msg (const char *format, ...) if (quiet) return; va_start (args, format); - vmsg (format, args); - printf ("\n"); + vmsg (format, args, "\n"); va_end (args); } @@ -33,36 +41,12 @@ fail (const char *format, ...) va_list args; va_start (args, format); - vmsg (format, args); - printf (": FAILED\n"); + vmsg (format, args, ": FAILED\n"); 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); - printf ("\n"); - } - } - else - { - vmsg (format, args); - printf (": FAILED\n"); - exit (1); - } - va_end (args); -} - void seq_test (const char *filename, void *buf, size_t size, size_t initial_size, size_t (*block_size_func) (void), @@ -145,22 +129,46 @@ check_file (const char *filename, const void *buf_, size_t size) 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); - } - + compare_bytes (block, buf + ofs, block_size, ofs, filename); ofs += block_size; } msg ("close \"%s\"", filename); close (fd); } + +void +compare_bytes (const void *read_data_, const void *expected_data_, size_t size, + size_t ofs, const char *filename) +{ + const uint8_t *read_data = read_data_; + const uint8_t *expected_data = expected_data_; + size_t i, j; + size_t show_cnt; + + if (!memcmp (read_data, expected_data, size)) + return; + + for (i = 0; i < size; i++) + if (read_data[i] != expected_data[i]) + break; + for (j = i + 1; j < size; j++) + if (read_data[j] == expected_data[j]) + break; + + quiet = false; + msg ("%zu bytes read starting at offset %zu in \"%s\" differ " + "from expected.", j - i, ofs + i, filename); + show_cnt = j - i; + if (j - i > 64) + { + show_cnt = 64; + msg ("Showing first differing %zu bytes.", show_cnt); + } + msg ("Data actually read:"); + hex_dump (ofs + i, read_data + i, show_cnt, true); + msg ("Expected data:"); + hex_dump (ofs + i, expected_data + i, show_cnt, true); + fail ("%zu bytes read starting at offset %zu in \"%s\" differ " + "from expected", j - i, ofs, filename); +} diff --git a/grading/filesys/fslib.h b/grading/filesys/fslib.h index a0e6f32..b1d654f 100644 --- a/grading/filesys/fslib.h +++ b/grading/filesys/fslib.h @@ -10,7 +10,15 @@ 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); + +#define check(SUCCESS, ...) \ + do \ + { \ + msg (__VA_ARGS__); \ + if (!(SUCCESS)) \ + fail (__VA_ARGS__); \ + } \ + while (0) void shuffle (void *, size_t cnt, size_t size); @@ -21,6 +29,9 @@ void seq_test (const char *filename, void check_file (const char *filename, 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 *filename); + void test_main (void); #endif /* fslib.h */ diff --git a/grading/filesys/grow-root-sm.c b/grading/filesys/grow-root-sm.c index 30685eb..92eead5 100644 --- a/grading/filesys/grow-root-sm.c +++ b/grading/filesys/grow-root-sm.c @@ -1,3 +1,3 @@ const char test_name[] = "grow-root-sm"; -#define FILE_CNT 20 +#define FILE_CNT 10 #include "grow-dir.inc" diff --git a/grading/filesys/grow-root-sm.exp b/grading/filesys/grow-root-sm.exp index c9f4bd5..a4df5cd 100644 --- a/grading/filesys/grow-root-sm.exp +++ b/grading/filesys/grow-root-sm.exp @@ -9,14 +9,4 @@ (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-too-big.exp b/grading/filesys/grow-too-big.exp new file mode 100644 index 0000000..683630f --- /dev/null +++ b/grading/filesys/grow-too-big.exp @@ -0,0 +1,7 @@ +(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) end diff --git a/grading/filesys/grow-two-files.exp b/grading/filesys/grow-two-files.exp index affa63a..5d3403a 100644 --- a/grading/filesys/grow-two-files.exp +++ b/grading/filesys/grow-two-files.exp @@ -1,3 +1,4 @@ +(grow-two-files) begin (grow-two-files) create "a" (grow-two-files) create "b" (grow-two-files) open "a" @@ -9,3 +10,4 @@ (grow-two-files) close "a" (grow-two-files) open "b" for verification (grow-two-files) close "b" +(grow-two-files) end diff --git a/grading/filesys/random.inc b/grading/filesys/random.inc index e720574..59f52f2 100644 --- a/grading/filesys/random.inc +++ b/grading/filesys/random.inc @@ -18,6 +18,7 @@ int order[BLOCK_CNT]; void test_main (void) { + const char *filename = "bazzle"; int fd; size_t i; @@ -27,10 +28,10 @@ test_main (void) for (i = 0; i < BLOCK_CNT; i++) order[i] = i; - check (create ("bazzle", TEST_SIZE), "create \"bazzle\""); - check ((fd = open ("bazzle")) > 1, "open \"bazzle\""); + check (create (filename, TEST_SIZE), "create \"%s\"", filename); + check ((fd = open (filename)) > 1, "open \"%s\"", filename); - msg ("write \"bazzle\" in random order"); + msg ("write \"%s\" in random order", filename); shuffle (order, BLOCK_CNT, sizeof *order); for (i = 0; i < BLOCK_CNT; i++) { @@ -40,7 +41,7 @@ test_main (void) fail ("write %d bytes at offset %zu failed", (int) BLOCK_SIZE, ofs); } - msg ("read \"bazzle\" in random order"); + msg ("read \"%s\" in random order", filename); shuffle (order, BLOCK_CNT, sizeof *order); for (i = 0; i < BLOCK_CNT; i++) { @@ -49,17 +50,9 @@ test_main (void) 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); - } + compare_bytes (block, buf + ofs, BLOCK_SIZE, ofs, filename); } - fail ("close \"bazzle\""); + msg ("close \"%s\"", filename); close (fd); } diff --git a/grading/filesys/run-tests b/grading/filesys/run-tests index 09c334c..0f86dbf 100755 --- a/grading/filesys/run-tests +++ b/grading/filesys/run-tests @@ -58,7 +58,7 @@ sub usage { dir-rm-parent dir-rm-root dir-over-file dir-under-file dir-empty-name dir-open - syn-remove syn-read + syn-remove syn-read syn-write syn-rw ) unless @TESTS > 0; our (%args); @@ -246,7 +246,7 @@ sub run_test { sub compile { print "Compiling...\n"; - xsystem ("cd pintos/src/vm && make", LOG => "make") + xsystem ("cd pintos/src/filesys && make", LOG => "make") or return "compile error"; } @@ -269,7 +269,7 @@ sub really_run_test { # Format disk, install test. my ($pintos_base_cmd) = "pintos " - . "--os-disk=pintos/src/vm/build/os.dsk " + . "--os-disk=pintos/src/filesys/build/os.dsk " . "--fs-disk=output/$test/fs.dsk " . "--swap-disk=output/$test/swap.dsk " . "-v"; @@ -280,6 +280,8 @@ sub really_run_test { my (@extra_files); push (@extra_files, "child-syn-read") if $test eq 'syn-read'; + push (@extra_files, "child-syn-wrt") if $test eq 'syn-write'; + push (@extra_files, "child-syn-rw") if $test eq 'syn-rw'; for my $fn (@extra_files) { return "format/put error" if !xsystem ("$pintos_base_cmd put $GRADES_DIR/$fn $fn", @@ -364,7 +366,7 @@ sub verify_common { } else { $A2L = "i386-elf-addr2line"; } - open (A2L, "$A2L -fe pintos/src/vm/build/kernel.o @addrs|"); + open (A2L, "$A2L -fe pintos/src/filesys/build/kernel.o @addrs|"); for (;;) { my ($function, $line); last unless defined ($function = ); @@ -388,6 +390,11 @@ EOF die "Kernel panic. Details at end of file.\n" } + my (@failure) = grep (/FAIL/, @output); + if (@failure != 0) { + die "Test failed: \"$failure[0]\"\n"; + } + if (grep (/Pintos booting/, @output) > 1) { my ($details); diff --git a/grading/filesys/syn-read.c b/grading/filesys/syn-read.c index d050db7..cdc7f18 100644 --- a/grading/filesys/syn-read.c +++ b/grading/filesys/syn-read.c @@ -2,17 +2,17 @@ #include #include #include "fslib.h" +#include "syn-read.h" const char test_name[] = "syn-read"; -static char buf[1024]; +static char buf[BUF_SIZE]; #define CHILD_CNT 10 void test_main (void) { - const char *filename = "data"; pid_t children[CHILD_CNT]; int fd; int i; @@ -27,10 +27,9 @@ test_main (void) for (i = 0; i < CHILD_CNT; i++) { char cmd_line[128]; - snprintf (cmd_line, sizeof cmd_line, - "child-syn-read %d %zu", i, sizeof buf); + snprintf (cmd_line, sizeof cmd_line, "child-syn-read %d", i); check ((children[i] = exec (cmd_line)) != PID_ERROR, - "exec \"%s\"", cmd_line); + "exec child %d of %d: \"%s\"", i + 1, (int) CHILD_CNT, cmd_line); } for (i = 0; i < CHILD_CNT; i++) diff --git a/grading/filesys/syn-read.h b/grading/filesys/syn-read.h new file mode 100644 index 0000000..6b1d8ed --- /dev/null +++ b/grading/filesys/syn-read.h @@ -0,0 +1,2 @@ +#define BUF_SIZE 1024 +static const char filename[] = "data"; diff --git a/grading/filesys/syn-remove.c b/grading/filesys/syn-remove.c index e47456a..c89c0bc 100644 --- a/grading/filesys/syn-remove.c +++ b/grading/filesys/syn-remove.c @@ -22,7 +22,7 @@ test_main (void) msg ("seek \"%s\" to 0", filename); seek (fd, 0); check (read (fd, buf2, sizeof buf2) > 0, "read \"%s\"", filename); - check (!memcmp (buf1, buf2, sizeof buf1), "compare data read and written"); + compare_bytes (buf2, buf1, sizeof buf1, 0, filename); msg ("close \"%s\"", filename); close (fd); } diff --git a/grading/filesys/syn-remove.exp b/grading/filesys/syn-remove.exp index f4ad702..a7c56ca 100644 --- a/grading/filesys/syn-remove.exp +++ b/grading/filesys/syn-remove.exp @@ -5,6 +5,5 @@ (syn-remove) write "deleteme" (syn-remove) seek "deleteme" to 0 (syn-remove) read "deleteme" -(syn-remove) compare data read and written (syn-remove) close "deleteme" (syn-remove) end diff --git a/grading/filesys/syn-rw.c b/grading/filesys/syn-rw.c new file mode 100644 index 0000000..6c02b94 --- /dev/null +++ b/grading/filesys/syn-rw.c @@ -0,0 +1,45 @@ +#include +#include +#include +#include "fslib.h" +#include "syn-rw.h" + +const char test_name[] = "syn-rw"; + +char buf[BUF_SIZE]; + +#define CHILD_CNT 4 + +void +test_main (void) +{ + pid_t children[CHILD_CNT]; + size_t ofs; + int fd; + int i; + + check (create (filename, 0), "create \"%s\"", filename); + check ((fd = open (filename)) > 1, "open \"%s\"", filename); + + for (i = 0; i < CHILD_CNT; i++) + { + char cmd_line[128]; + snprintf (cmd_line, sizeof cmd_line, "child-syn-rw %d", i); + check ((children[i] = exec (cmd_line)) != PID_ERROR, + "exec child %d of %d: \"%s\"", i + 1, (int) CHILD_CNT, cmd_line); + } + + random_bytes (buf, sizeof buf); + quiet = true; + for (ofs = 0; ofs < BUF_SIZE; ofs += CHUNK_SIZE) + check (write (fd, buf + ofs, CHUNK_SIZE) > 0, + "write %d bytes at offset %zu in \"%s\"", + (int) CHUNK_SIZE, ofs, filename); + quiet = false; + + for (i = 0; i < CHILD_CNT; i++) + { + int status = join (children[i]); + check (status == i, "join child %d of %d", i + 1, (int) CHILD_CNT); + } +} diff --git a/grading/filesys/syn-rw.h b/grading/filesys/syn-rw.h new file mode 100644 index 0000000..679a69e --- /dev/null +++ b/grading/filesys/syn-rw.h @@ -0,0 +1,4 @@ +#define CHUNK_SIZE 8 +#define CHUNK_CNT 512 +#define BUF_SIZE (CHUNK_SIZE * CHUNK_CNT) +static const char filename[] = "logfile"; diff --git a/grading/filesys/syn-write.c b/grading/filesys/syn-write.c new file mode 100644 index 0000000..ee88c8b --- /dev/null +++ b/grading/filesys/syn-write.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include "fslib.h" +#include "syn-write.h" + +const char test_name[] = "syn-write"; + +char buf1[BUF_SIZE]; +char buf2[BUF_SIZE]; + +void +test_main (void) +{ + pid_t children[CHILD_CNT]; + int fd; + int i; + + check (create (filename, sizeof buf1), "create \"%s\"", filename); + + for (i = 0; i < CHILD_CNT; i++) + { + char cmd_line[128]; + snprintf (cmd_line, sizeof cmd_line, "child-syn-wrt %d", i); + check ((children[i] = exec (cmd_line)) != PID_ERROR, + "exec child %d of %d: \"%s\"", i + 1, (int) CHILD_CNT, cmd_line); + } + + for (i = 0; i < CHILD_CNT; i++) + { + int status = join (children[i]); + check (status == i, "join child %d of %d", i + 1, (int) CHILD_CNT); + } + + check ((fd = open (filename)) > 1, "open \"%s\"", filename); + check (read (fd, buf1, sizeof buf1) > 0, "read \"%s\"", filename); + random_bytes (buf2, sizeof buf2); + compare_bytes (buf1, buf2, sizeof buf1, 0, filename); +} diff --git a/grading/filesys/syn-write.exp b/grading/filesys/syn-write.exp new file mode 100644 index 0000000..78ed950 --- /dev/null +++ b/grading/filesys/syn-write.exp @@ -0,0 +1,25 @@ +(syn-write) begin +(syn-write) create "stuff" +(syn-write) exec child 1 of 10: "child-syn-wrt 0" +(syn-write) exec child 2 of 10: "child-syn-wrt 1" +(syn-write) exec child 3 of 10: "child-syn-wrt 2" +(syn-write) exec child 4 of 10: "child-syn-wrt 3" +(syn-write) exec child 5 of 10: "child-syn-wrt 4" +(syn-write) exec child 6 of 10: "child-syn-wrt 5" +(syn-write) exec child 7 of 10: "child-syn-wrt 6" +(syn-write) exec child 8 of 10: "child-syn-wrt 7" +(syn-write) exec child 9 of 10: "child-syn-wrt 8" +(syn-write) exec child 10 of 10: "child-syn-wrt 9" +(syn-write) join child 1 of 10 +(syn-write) join child 2 of 10 +(syn-write) join child 3 of 10 +(syn-write) join child 4 of 10 +(syn-write) join child 5 of 10 +(syn-write) join child 6 of 10 +(syn-write) join child 7 of 10 +(syn-write) join child 8 of 10 +(syn-write) join child 9 of 10 +(syn-write) join child 10 of 10 +(syn-write) open "stuff" +(syn-write) read "stuff" +(syn-write) end diff --git a/grading/filesys/syn-write.h b/grading/filesys/syn-write.h new file mode 100644 index 0000000..17776ff --- /dev/null +++ b/grading/filesys/syn-write.h @@ -0,0 +1,4 @@ +#define CHILD_CNT 10 +#define CHUNK_SIZE 512 +#define BUF_SIZE (CHILD_CNT * CHUNK_SIZE) +static const char filename[] = "stuff";