From 0f5c19ccf179b35b39ae46dffec60592baeeec00 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 8 Dec 2004 01:47:03 +0000 Subject: [PATCH] More filesys tests. --- grading/filesys/Make.progs | 64 ++++++++++++++++++++--------- grading/filesys/child-syn-read.c | 40 ++++++++++++++++++ grading/filesys/create.inc | 7 +--- grading/filesys/dir-empty-name.c | 10 +++++ grading/filesys/dir-empty-name.exp | 3 ++ grading/filesys/dir-lsdir.c | 10 +++++ grading/filesys/dir-mk-tree.c | 14 +++++++ grading/filesys/dir-mk-tree.exp | 4 ++ grading/filesys/dir-mk-vine.c | 22 ++++++++++ grading/filesys/dir-mk-vine.exp | 25 ++++++++++++ grading/filesys/dir-mkdir.c | 14 +++++++ grading/filesys/dir-mkdir.exp | 6 +++ grading/filesys/dir-open.c | 22 ++++++++++ grading/filesys/dir-open.exp | 11 +++++ grading/filesys/dir-over-file.c | 11 +++++ grading/filesys/dir-over-file.exp | 4 ++ grading/filesys/dir-rm-cwd-cd.c | 16 ++++++++ grading/filesys/dir-rm-cwd.c | 15 +++++++ grading/filesys/dir-rm-cwd.exp | 6 +++ grading/filesys/dir-rm-parent.c | 17 ++++++++ grading/filesys/dir-rm-parent.exp | 8 ++++ grading/filesys/dir-rm-root.c | 11 +++++ grading/filesys/dir-rm-root.exp | 4 ++ grading/filesys/dir-rm-tree.c | 60 +++++++++++++++++++++++++++ grading/filesys/dir-rm-vine.c | 35 ++++++++++++++++ grading/filesys/dir-rmdir.c | 12 ++++++ grading/filesys/dir-rmdir.exp | 5 +++ grading/filesys/dir-under-file.c | 11 +++++ grading/filesys/dir-under-file.exp | 4 ++ grading/filesys/fslib.c | 37 ++++++++--------- grading/filesys/fslib.h | 10 +++-- grading/filesys/fsmain.c | 12 ++++++ grading/filesys/full.inc | 11 +++-- grading/filesys/grow-dir.inc | 10 ++--- grading/filesys/grow-file-size.c | 10 ++--- grading/filesys/grow-file-size.exp | 1 - grading/filesys/grow-seq.inc | 11 +++-- grading/filesys/grow-sparse.c | 7 +--- grading/filesys/grow-tell.c | 11 +++-- grading/filesys/grow-too-big.c | 22 ++++++++++ grading/filesys/grow-two-files.c | 6 +-- grading/filesys/main.c | 10 +++++ grading/filesys/mk-tree.c | 65 ++++++++++++++++++++++++++++++ grading/filesys/mk-tree.h | 6 +++ grading/filesys/random.inc | 9 +---- grading/filesys/run-tests | 22 +++++++++- grading/filesys/seq-block.inc | 10 ++--- grading/filesys/seq-random.inc | 11 +++-- grading/filesys/syn-read.c | 41 +++++++++++++++++++ grading/filesys/syn-remove.c | 28 +++++++++++++ grading/filesys/syn-remove.exp | 10 +++++ grading/filesys/tests.txt | 20 ++++----- 52 files changed, 733 insertions(+), 118 deletions(-) create mode 100644 grading/filesys/child-syn-read.c create mode 100644 grading/filesys/dir-empty-name.c create mode 100644 grading/filesys/dir-empty-name.exp create mode 100644 grading/filesys/dir-lsdir.c create mode 100644 grading/filesys/dir-mk-tree.c create mode 100644 grading/filesys/dir-mk-tree.exp create mode 100644 grading/filesys/dir-mk-vine.c create mode 100644 grading/filesys/dir-mk-vine.exp create mode 100644 grading/filesys/dir-mkdir.c create mode 100644 grading/filesys/dir-mkdir.exp create mode 100644 grading/filesys/dir-open.c create mode 100644 grading/filesys/dir-open.exp create mode 100644 grading/filesys/dir-over-file.c create mode 100644 grading/filesys/dir-over-file.exp create mode 100644 grading/filesys/dir-rm-cwd-cd.c create mode 100644 grading/filesys/dir-rm-cwd.c create mode 100644 grading/filesys/dir-rm-cwd.exp create mode 100644 grading/filesys/dir-rm-parent.c create mode 100644 grading/filesys/dir-rm-parent.exp create mode 100644 grading/filesys/dir-rm-root.c create mode 100644 grading/filesys/dir-rm-root.exp create mode 100644 grading/filesys/dir-rm-tree.c create mode 100644 grading/filesys/dir-rm-vine.c create mode 100644 grading/filesys/dir-rmdir.c create mode 100644 grading/filesys/dir-rmdir.exp create mode 100644 grading/filesys/dir-under-file.c create mode 100644 grading/filesys/dir-under-file.exp create mode 100644 grading/filesys/fsmain.c create mode 100644 grading/filesys/grow-too-big.c create mode 100644 grading/filesys/main.c create mode 100644 grading/filesys/mk-tree.c create mode 100644 grading/filesys/mk-tree.h create mode 100644 grading/filesys/syn-read.c create mode 100644 grading/filesys/syn-remove.c create mode 100644 grading/filesys/syn-remove.exp diff --git a/grading/filesys/Make.progs b/grading/filesys/Make.progs index 08fed39..8ae3a10 100644 --- a/grading/filesys/Make.progs +++ b/grading/filesys/Make.progs @@ -1,20 +1,48 @@ -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 +# -*- makefile -*- -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 +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-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 + +sm_create_SRC = sm-create.c fslib.c fsmain.c +sm_full_SRC = sm-full.c fslib.c fsmain.c +sm_seq_block_SRC = sm-seq-block.c fslib.c fsmain.c +sm_seq_random_SRC = sm-seq-random.c fslib.c fsmain.c +sm_random_SRC = sm-random.c fslib.c fsmain.c + +grow_create_SRC = grow-create.c fslib.c fsmain.c +grow_seq_sm_SRC = grow-seq-sm.c fslib.c fsmain.c +grow_seq_lg_SRC = grow-seq-lg.c fslib.c fsmain.c +grow_file_size_SRC = grow-file-size.c fslib.c fsmain.c +grow_tell_SRC = grow-tell.c fslib.c fsmain.c +grow_sparse_SRC = grow-sparse.c fslib.c fsmain.c +grow_too_big_SRC = grow-too-big.c fslib.c fsmain.c +grow_root_sm_SRC = grow-root-sm.c fslib.c fsmain.c +grow_root_lg_SRC = grow-root-lg.c fslib.c fsmain.c +grow_dir_lg_SRC = grow-dir-lg.c fslib.c fsmain.c +grow_two_files_SRC = grow-two-files.c fslib.c fsmain.c + +dir_mkdir_SRC = dir-mkdir.c fslib.c fsmain.c +dir_rmdir_SRC = dir-rmdir.c fslib.c fsmain.c +dir_mk_vine_SRC = dir-mk-vine.c fslib.c fsmain.c +dir_rm_vine_SRC = dir-rm-vine.c fslib.c fsmain.c +dir_mk_tree_SRC = dir-mk-tree.c mk-tree.c fslib.c fsmain.c +dir_rm_tree_SRC = dir-rm-tree.c mk-tree.c fslib.c fsmain.c +dir_lsdir_SRC = dir-lsdir.c fslib.c fsmain.c +dir_rm_cwd_SRC = dir-rm-cwd.c fslib.c fsmain.c +dir_rm_cwd_cd_SRC = dir-rm-cwd-cd.c fslib.c fsmain.c +dir_rm_parent_SRC = dir-rm-parent.c fslib.c fsmain.c +dir_rm_root_SRC = dir-rm-root.c fslib.c fsmain.c +dir_over_file_SRC = dir-over-file.c fslib.c fsmain.c +dir_under_file_SRC = dir-under-file.c fslib.c fsmain.c +dir_empty_name_SRC = dir-empty-name.c fslib.c fsmain.c +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 -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/child-syn-read.c b/grading/filesys/child-syn-read.c new file mode 100644 index 0000000..90c3ab0 --- /dev/null +++ b/grading/filesys/child-syn-read.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include "fslib.h" + +const char test_name[128] = "child-syn-read"; + +static char buf[1024]; + +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); + 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); + + check ((fd = open (filename)) > 1, "open \"%s\"", filename); + for (i = 0; i < sizeof buf; i++) + { + char c; + check (read (fd, &c, 1) > 0, "read \"%s\"", filename); + check (c != buf[i], "byte %zu differs from expected", i); + } + close (fd); + + return child_idx; +} + diff --git a/grading/filesys/create.inc b/grading/filesys/create.inc index d378fe3..3e8a9b5 100644 --- a/grading/filesys/create.inc +++ b/grading/filesys/create.inc @@ -6,12 +6,9 @@ static char buf[TEST_SIZE]; -int -main (void) +void +test_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/dir-empty-name.c b/grading/filesys/dir-empty-name.c new file mode 100644 index 0000000..427eb2d --- /dev/null +++ b/grading/filesys/dir-empty-name.c @@ -0,0 +1,10 @@ +#include +#include "fslib.h" + +const char test_name[] = "dir-empty-name"; + +void +test_main (void) +{ + check (!create ("", 0), "create \"\" (must return false)"); +} diff --git a/grading/filesys/dir-empty-name.exp b/grading/filesys/dir-empty-name.exp new file mode 100644 index 0000000..c63b116 --- /dev/null +++ b/grading/filesys/dir-empty-name.exp @@ -0,0 +1,3 @@ +(dir-empty-name) begin +(dir-empty-name) create "" (must return false) +(dir-empty-name) end diff --git a/grading/filesys/dir-lsdir.c b/grading/filesys/dir-lsdir.c new file mode 100644 index 0000000..9c54bb1 --- /dev/null +++ b/grading/filesys/dir-lsdir.c @@ -0,0 +1,10 @@ +#include +#include "fslib.h" + +const char test_name[] = "dir-lsdir"; + +void +test_main (void) +{ + lsdir (); +} diff --git a/grading/filesys/dir-mk-tree.c b/grading/filesys/dir-mk-tree.c new file mode 100644 index 0000000..cd4f65a --- /dev/null +++ b/grading/filesys/dir-mk-tree.c @@ -0,0 +1,14 @@ +#include +#include +#include +#include "fslib.h" +#include "mk-tree.h" + +const char test_name[] = "dir-mk-tree"; + +void +test_main (void) +{ + make_tree (4, 3, 3, 4); +} + diff --git a/grading/filesys/dir-mk-tree.exp b/grading/filesys/dir-mk-tree.exp new file mode 100644 index 0000000..141a593 --- /dev/null +++ b/grading/filesys/dir-mk-tree.exp @@ -0,0 +1,4 @@ +(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) end diff --git a/grading/filesys/dir-mk-vine.c b/grading/filesys/dir-mk-vine.c new file mode 100644 index 0000000..c044b3a --- /dev/null +++ b/grading/filesys/dir-mk-vine.c @@ -0,0 +1,22 @@ +#include +#include "fslib.h" + +const char test_name[] = "dir-mk-vine"; + +void +test_main (void) +{ + const char *filename = "/0/1/2/3/4/5/6/7/8/9/test"; + char dir[2]; + + dir[1] = '\0'; + for (dir[0] = '0'; dir[0] <= '9'; dir[0]++) + { + check (mkdir (dir), "mkdir \"%s\"", dir); + check (chdir (dir), "chdir \"%s\"", dir); + } + check (create ("test", 512), "create \"test\""); + check (chdir ("/"), "chdir \"/\""); + check (open (filename) > 1, "open \"%s\"", filename); +} + diff --git a/grading/filesys/dir-mk-vine.exp b/grading/filesys/dir-mk-vine.exp new file mode 100644 index 0000000..b555631 --- /dev/null +++ b/grading/filesys/dir-mk-vine.exp @@ -0,0 +1,25 @@ +(dir-mk-vine) begin +(dir-mk-vine) mkdir "0" +(dir-mk-vine) chdir "0" +(dir-mk-vine) mkdir "1" +(dir-mk-vine) chdir "1" +(dir-mk-vine) mkdir "2" +(dir-mk-vine) chdir "2" +(dir-mk-vine) mkdir "3" +(dir-mk-vine) chdir "3" +(dir-mk-vine) mkdir "4" +(dir-mk-vine) chdir "4" +(dir-mk-vine) mkdir "5" +(dir-mk-vine) chdir "5" +(dir-mk-vine) mkdir "6" +(dir-mk-vine) chdir "6" +(dir-mk-vine) mkdir "7" +(dir-mk-vine) chdir "7" +(dir-mk-vine) mkdir "8" +(dir-mk-vine) chdir "8" +(dir-mk-vine) mkdir "9" +(dir-mk-vine) chdir "9" +(dir-mk-vine) create "test" +(dir-mk-vine) chdir "/" +(dir-mk-vine) open "/0/1/2/3/4/5/6/7/8/9/test" +(dir-mk-vine) end diff --git a/grading/filesys/dir-mkdir.c b/grading/filesys/dir-mkdir.c new file mode 100644 index 0000000..85d243e --- /dev/null +++ b/grading/filesys/dir-mkdir.c @@ -0,0 +1,14 @@ +#include +#include "fslib.h" + +const char test_name[] = "dir-mkdir"; + +void +test_main (void) +{ + check (mkdir ("a"), "mkdir \"a\""); + check (create ("a/b", 512), "create \"a/b\""); + check (chdir ("a"), "chdir \"a\""); + check (open ("b") > 1, "open \"b\""); +} + diff --git a/grading/filesys/dir-mkdir.exp b/grading/filesys/dir-mkdir.exp new file mode 100644 index 0000000..6dcd01c --- /dev/null +++ b/grading/filesys/dir-mkdir.exp @@ -0,0 +1,6 @@ +(dir-mkdir) begin +(dir-mkdir) mkdir "a" +(dir-mkdir) create "a/b" +(dir-mkdir) chdir "a" +(dir-mkdir) open "b" +(dir-mkdir) end diff --git a/grading/filesys/dir-open.c b/grading/filesys/dir-open.c new file mode 100644 index 0000000..40550ee --- /dev/null +++ b/grading/filesys/dir-open.c @@ -0,0 +1,22 @@ +#include +#include "fslib.h" + +const char test_name[] = "dir-open"; + +void +test_main (void) +{ + int fd; + + check (mkdir ("xyzzy"), "mkdir \"xyzzy\""); + msg ("open \"xyzzy\""); + fd = open ("xyzzy"); + if (fd == -1) + msg ("open returned -1 -- ok"); + else + { + int retval = write (fd, "foobar", 6); + check (retval == -1, "write \"xyzzy\" (must return -1, actually %d)", + retval); + } +} diff --git a/grading/filesys/dir-open.exp b/grading/filesys/dir-open.exp new file mode 100644 index 0000000..bdb6b67 --- /dev/null +++ b/grading/filesys/dir-open.exp @@ -0,0 +1,11 @@ +(dir-open) begin +(dir-open) mkdir "xyzzy" +(dir-open) open "xyzzy" +(dir-open) open returned -1 -- ok +(dir-open) end +--OR-- +(dir-open) begin +(dir-open) mkdir "xyzzy" +(dir-open) open "xyzzy" +(dir-open) write "xyzzy" (must return -1, actually -1) +(dir-open) end diff --git a/grading/filesys/dir-over-file.c b/grading/filesys/dir-over-file.c new file mode 100644 index 0000000..01347e1 --- /dev/null +++ b/grading/filesys/dir-over-file.c @@ -0,0 +1,11 @@ +#include +#include "fslib.h" + +const char test_name[] = "dir-over-file"; + +void +test_main (void) +{ + check (mkdir ("abc"), "mkdir \"abc\""); + check (!create ("abc", 0), "create \"abc\" (must return false)"); +} diff --git a/grading/filesys/dir-over-file.exp b/grading/filesys/dir-over-file.exp new file mode 100644 index 0000000..206103b --- /dev/null +++ b/grading/filesys/dir-over-file.exp @@ -0,0 +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 diff --git a/grading/filesys/dir-rm-cwd-cd.c b/grading/filesys/dir-rm-cwd-cd.c new file mode 100644 index 0000000..fe3febd --- /dev/null +++ b/grading/filesys/dir-rm-cwd-cd.c @@ -0,0 +1,16 @@ +#include +#include "fslib.h" + +const char test_name[] = "dir-rm-cwd-cd"; + +void +test_main (void) +{ + check (mkdir ("a"), "mkdir \"a\""); + 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)"); + else + check (chdir ("/a"), "chdir \"/a\" (remove failed so this must succeed)"); +} diff --git a/grading/filesys/dir-rm-cwd.c b/grading/filesys/dir-rm-cwd.c new file mode 100644 index 0000000..2754850 --- /dev/null +++ b/grading/filesys/dir-rm-cwd.c @@ -0,0 +1,15 @@ +#include +#include "fslib.h" + +const char test_name[] = "dir-rm-cwd"; + +void +test_main (void) +{ + check (mkdir ("a"), "mkdir \"a\""); + check (chdir ("a"), "chdir \"a\""); + msg ("remove \"/a\" (must not crash)"); + remove ("/a"); + msg ("create \"b\" (must not crash)"); + create ("b", 123); +} diff --git a/grading/filesys/dir-rm-cwd.exp b/grading/filesys/dir-rm-cwd.exp new file mode 100644 index 0000000..ae91c54 --- /dev/null +++ b/grading/filesys/dir-rm-cwd.exp @@ -0,0 +1,6 @@ +(dir-rm-cwd) begin +(dir-rm-cwd) mkdir "a" +(dir-rm-cwd) chdir "a" +(dir-rm-cwd) remove "/a" (must not crash) +(dir-rm-cwd) create "b" (must not crash) +(dir-rm-cwd) end diff --git a/grading/filesys/dir-rm-parent.c b/grading/filesys/dir-rm-parent.c new file mode 100644 index 0000000..9a2136e --- /dev/null +++ b/grading/filesys/dir-rm-parent.c @@ -0,0 +1,17 @@ +#include +#include "fslib.h" + +const char test_name[] = "dir-rm-parent"; + +void +test_main (void) +{ + check (mkdir ("a"), "mkdir \"a\""); + check (chdir ("a"), "chdir \"a\""); + check (mkdir ("b"), "mkdir \"b\""); + check (chdir ("b"), "chdir \"b\""); + msg ("remove \"/b\" (must not crash)"); + remove ("/b"); + msg ("remove \"/a\" (must not crash)"); + remove ("/a"); +} diff --git a/grading/filesys/dir-rm-parent.exp b/grading/filesys/dir-rm-parent.exp new file mode 100644 index 0000000..863681b --- /dev/null +++ b/grading/filesys/dir-rm-parent.exp @@ -0,0 +1,8 @@ +(dir-rm-parent) begin +(dir-rm-parent) mkdir "a" +(dir-rm-parent) chdir "a" +(dir-rm-parent) mkdir "b" +(dir-rm-parent) chdir "b" +(dir-rm-parent) remove "/b" (must not crash) +(dir-rm-parent) remove "/a" (must not crash) +(dir-rm-parent) end diff --git a/grading/filesys/dir-rm-root.c b/grading/filesys/dir-rm-root.c new file mode 100644 index 0000000..2922824 --- /dev/null +++ b/grading/filesys/dir-rm-root.c @@ -0,0 +1,11 @@ +#include +#include "fslib.h" + +const char test_name[] = "dir-rm-root"; + +void +test_main (void) +{ + check (!remove ("/"), "remove \"/\" (must return false)"); + check (create ("/a", 243), "create \"/a\""); +} diff --git a/grading/filesys/dir-rm-root.exp b/grading/filesys/dir-rm-root.exp new file mode 100644 index 0000000..b6c87cb --- /dev/null +++ b/grading/filesys/dir-rm-root.exp @@ -0,0 +1,4 @@ +(dir-rm-root) begin +(dir-rm-root) remove "/" (must return false) +(dir-rm-root) create "/a" +(dir-rm-root) end diff --git a/grading/filesys/dir-rm-tree.c b/grading/filesys/dir-rm-tree.c new file mode 100644 index 0000000..303f257 --- /dev/null +++ b/grading/filesys/dir-rm-tree.c @@ -0,0 +1,60 @@ +#include +#include +#include +#include "fslib.h" +#include "mk-tree.h" + +const char test_name[] = "dir-rm-tree"; + +static void remove_tree (int at, int bt, int ct, int dt); + +void +test_main (void) +{ + make_tree (4, 3, 3, 4); + remove_tree (4, 3, 3, 4); +} + +static void do_remove (const char *format, ...) PRINTF_FORMAT (1, 2); + +static void +remove_tree (int at, int bt, int ct, int dt) +{ + char try[128]; + int a, b, c, d; + + msg ("removing /0/0/0/0 through /%d/%d/%d/%d...", + at - 1, bt - 1, ct - 1, dt - 1); + quiet = false; + for (a = 0; a < at; a++) + { + for (b = 0; b < bt; b++) + { + for (c = 0; c < ct; c++) + { + for (d = 0; d < dt; d++) + do_remove ("/%d/%d/%d/%d", a, b, c, d); + do_remove ("/%d/%d/%d", a, b, c); + } + do_remove ("/%d/%d", a, b); + } + do_remove ("/%d", a); + } + quiet = false; + + snprintf (try, sizeof (try), "/%d/%d/%d/%d", at - 1, 0, ct - 1, 0); + check (open (try) == -1, "open \"%s\" (must return -1)", try); +} + +static void +do_remove (const char *format, ...) +{ + char name[128]; + va_list args; + + va_start (args, format); + vsnprintf (name, sizeof name, format, args); + va_end (args); + + check (remove (name), "remove \"%s\"", name); +} diff --git a/grading/filesys/dir-rm-vine.c b/grading/filesys/dir-rm-vine.c new file mode 100644 index 0000000..571112a --- /dev/null +++ b/grading/filesys/dir-rm-vine.c @@ -0,0 +1,35 @@ +#include +#include +#include "fslib.h" + +const char test_name[] = "dir-rm-vine"; + +void +test_main (void) +{ + const char *filename = "/0/1/2/3/4/5/6/7/8/9/test"; + int fd; + char tmp[128]; + + tmp[1] = '\0'; + for (tmp[0] = '0'; tmp[0] <= '9'; tmp[0]++) + { + check (mkdir (tmp), "mkdir \"%s\"", tmp); + check (chdir (tmp), "chdir \"%s\"", tmp); + } + check (create ("test", 512), "create \"test\""); + + check (chdir ("/"), "chdir \"/\""); + check ((fd = open (filename)) > 1, "open \"%s\"", filename); + msg ("close \"%s\"", filename); + close (fd); + + strlcpy (tmp, filename, sizeof tmp); + while (strlen (tmp) > 0) + { + check (remove (tmp), "remove \"%s\"", tmp); + *strrchr (tmp, '/') = 0; + } + + check (open (filename) == 1, "open \"%s\" (must return -1)", filename); +} diff --git a/grading/filesys/dir-rmdir.c b/grading/filesys/dir-rmdir.c new file mode 100644 index 0000000..ed9be64 --- /dev/null +++ b/grading/filesys/dir-rmdir.c @@ -0,0 +1,12 @@ +#include +#include "fslib.h" + +const char test_name[] = "dir-rmdir"; + +void +test_main (void) +{ + check (mkdir ("a"), "mkdir \"a\""); + check (remove ("a"), "rmdir \"a\""); + check (!chdir ("a"), "chdir \"a\" (must return false)"); +} diff --git a/grading/filesys/dir-rmdir.exp b/grading/filesys/dir-rmdir.exp new file mode 100644 index 0000000..010c3e0 --- /dev/null +++ b/grading/filesys/dir-rmdir.exp @@ -0,0 +1,5 @@ +(dir-rmdir) begin +(dir-rmdir) mkdir "a" +(dir-rmdir) rmdir "a" +(dir-rmdir) chdir "a" (must return false) +(dir-rmdir) end diff --git a/grading/filesys/dir-under-file.c b/grading/filesys/dir-under-file.c new file mode 100644 index 0000000..2565a27 --- /dev/null +++ b/grading/filesys/dir-under-file.c @@ -0,0 +1,11 @@ +#include +#include "fslib.h" + +const char test_name[] = "dir-under-file"; + +void +test_main (void) +{ + check (create ("abc", 0), "create \"abc\""); + check (!mkdir ("abc"), "mkdir \"abc\" (must return false)"); +} diff --git a/grading/filesys/dir-under-file.exp b/grading/filesys/dir-under-file.exp new file mode 100644 index 0000000..8bbdca7 --- /dev/null +++ b/grading/filesys/dir-under-file.exp @@ -0,0 +1,4 @@ +(dir-under-file) begin +(dir-under-file) create "abc" +(dir-under-file) mkdir "abc" (must return false) +(dir-under-file) end diff --git a/grading/filesys/fslib.c b/grading/filesys/fslib.c index 36f67f8..a94a0d1 100644 --- a/grading/filesys/fslib.c +++ b/grading/filesys/fslib.c @@ -4,21 +4,14 @@ #include #include #include -#include "../lib/arc4.h" bool quiet = false; static void -vmsg (const char *format, va_list args, bool failure) +vmsg (const char *format, va_list args) { - if (quiet && !failure) - return; - printf ("(%s) ", test_name); vprintf (format, args); - if (failure) - printf (": FAILED"); - printf ("\n"); } void @@ -26,8 +19,11 @@ msg (const char *format, ...) { va_list args; + if (quiet) + return; va_start (args, format); - vmsg (format, args, false); + vmsg (format, args); + printf ("\n"); va_end (args); } @@ -36,10 +32,9 @@ fail (const char *format, ...) { va_list args; - quiet = false; - va_start (args, format); - vmsg (format, args, true); + vmsg (format, args); + printf (": FAILED\n"); va_end (args); exit (1); @@ -53,30 +48,30 @@ check (bool success, const char *format, ...) va_start (args, format); if (success) { - if (!quiet) - vmsg (format, args, false); + if (!quiet) + { + vmsg (format, args); + printf ("\n"); + } } else { - vmsg (format, args, true); + 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, int seed, +seq_test (const char *filename, void *buf, size_t size, size_t initial_size, 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); - + random_bytes (buf, size); check (create (filename, initial_size), "create \"%s\"", filename); check ((fd = open (filename)) > 1, "open \"%s\"", filename); diff --git a/grading/filesys/fslib.h b/grading/filesys/fslib.h index b157598..a0e6f32 100644 --- a/grading/filesys/fslib.h +++ b/grading/filesys/fslib.h @@ -13,10 +13,14 @@ 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 *buf, size_t size, size_t initial_size, + size_t (*block_size_func) (void), + void (*check_func) (int fd, long ofs)); + void check_file (const char *filename, const void *buf, size_t filesize); +void test_main (void); + #endif /* fslib.h */ diff --git a/grading/filesys/fsmain.c b/grading/filesys/fsmain.c new file mode 100644 index 0000000..76113a6 --- /dev/null +++ b/grading/filesys/fsmain.c @@ -0,0 +1,12 @@ +#include +#include "fslib.h" + +int +main (void) +{ + msg ("begin"); + random_init (0); + test_main (); + msg ("end"); + return 0; +} diff --git a/grading/filesys/full.inc b/grading/filesys/full.inc index 32b7c8f..25ffe71 100644 --- a/grading/filesys/full.inc +++ b/grading/filesys/full.inc @@ -10,11 +10,10 @@ return_test_size (void) return TEST_SIZE; } -int -main (void) +void +test_main (void) { - msg ("begin"); - seq_test ("quux", buf, sizeof buf, sizeof buf, 2, return_test_size, NULL); - msg ("end"); - return 0; + seq_test ("quux", + buf, sizeof buf, sizeof buf, + return_test_size, NULL); } diff --git a/grading/filesys/grow-dir.inc b/grading/filesys/grow-dir.inc index df3cbdf..86a471f 100644 --- a/grading/filesys/grow-dir.inc +++ b/grading/filesys/grow-dir.inc @@ -12,12 +12,11 @@ return_block_size (void) return sizeof buf; } -int -main (void) +void +test_main (void) { size_t i; - msg ("begin"); #ifdef DIRECTORY check (mkdir (DIRECTORY), "mkdir %s", DIRECTORY); #define DIR_PREFIX DIRECTORY "/" @@ -32,10 +31,9 @@ main (void) msg ("creating and checking \"%s\"", filename); quiet = true; - seq_test (filename, buf, sizeof buf, sizeof buf, 0, + seq_test (filename, + buf, sizeof buf, sizeof buf, 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 index b92ec5b..cf36c17 100644 --- a/grading/filesys/grow-file-size.c +++ b/grading/filesys/grow-file-size.c @@ -21,12 +21,10 @@ check_file_size (int fd, long ofs) ofs, size); } -int -main (void) +void +test_main (void) { - msg ("begin"); - seq_test ("testfile", buf, sizeof buf, 0, 0, + seq_test ("testfile", + buf, sizeof buf, 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 index fcb5ce4..6c8f2ea 100644 --- a/grading/filesys/grow-file-size.exp +++ b/grading/filesys/grow-file-size.exp @@ -6,4 +6,3 @@ (grow-file-size) open "testfile" for verification (grow-file-size) close "testfile" (grow-file-size) end - diff --git a/grading/filesys/grow-seq.inc b/grading/filesys/grow-seq.inc index 2c0e3ba..8a32cd0 100644 --- a/grading/filesys/grow-seq.inc +++ b/grading/filesys/grow-seq.inc @@ -10,11 +10,10 @@ return_block_size (void) return 1234; } -int -main (void) +void +test_main (void) { - msg ("begin"); - seq_test ("testme", buf, sizeof buf, 0, 3, return_block_size, NULL); - msg ("end"); - return 0; + seq_test ("testme", + buf, sizeof buf, 0, + return_block_size, NULL); } diff --git a/grading/filesys/grow-sparse.c b/grading/filesys/grow-sparse.c index 6180828..896b2fa 100644 --- a/grading/filesys/grow-sparse.c +++ b/grading/filesys/grow-sparse.c @@ -6,13 +6,12 @@ const char test_name[] = "grow-sparse"; static char buf[76543]; -int -main (void) +void +test_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\""); @@ -21,6 +20,4 @@ main (void) msg ("close \"testfile\""); close (fd); check_file ("testfile", buf, sizeof buf); - msg ("end"); - return 0; } diff --git a/grading/filesys/grow-tell.c b/grading/filesys/grow-tell.c index 4f9d517..672786a 100644 --- a/grading/filesys/grow-tell.c +++ b/grading/filesys/grow-tell.c @@ -21,11 +21,10 @@ check_tell (int fd, long ofs) ofs, pos); } -int -main (void) +void +test_main (void) { - msg ("begin"); - seq_test ("foobar", buf, sizeof buf, 0, 1, return_block_size, check_tell); - msg ("end"); - return 0; + seq_test ("foobar", + buf, sizeof buf, 0, + return_block_size, check_tell); } diff --git a/grading/filesys/grow-too-big.c b/grading/filesys/grow-too-big.c new file mode 100644 index 0000000..5711693 --- /dev/null +++ b/grading/filesys/grow-too-big.c @@ -0,0 +1,22 @@ +/* -*- c -*- */ + +#include +#include +#include "fslib.h" + +const char test_name[] = "grow-sparse"; + +void +test_main (void) +{ + char zero = 0; + int fd; + + check (create ("testfile", 0), "create \"testfile\""); + check ((fd = open ("testfile")) > 1, "open \"testfile\""); + msg ("seek \"testfile\""); + seek (fd, UINT_MAX); + check (write (fd, &zero, 1) > 0, "write \"testfile\""); + msg ("close \"testfile\""); + close (fd); +} diff --git a/grading/filesys/grow-two-files.c b/grading/filesys/grow-two-files.c index 8809c60..aa6820a 100644 --- a/grading/filesys/grow-two-files.c +++ b/grading/filesys/grow-two-files.c @@ -24,8 +24,8 @@ write_some_bytes (const char *filename, int fd, const char *buf, size_t *ofs) } } -int -main (void) +void +test_main (void) { int fd_a, fd_b; size_t ofs_a, ofs_b; @@ -55,6 +55,4 @@ main (void) check_file ("a", buf_a, FILE_SIZE); check_file ("b", buf_b, FILE_SIZE); - - return 0; } diff --git a/grading/filesys/main.c b/grading/filesys/main.c new file mode 100644 index 0000000..52561bc --- /dev/null +++ b/grading/filesys/main.c @@ -0,0 +1,10 @@ +#include "fslib.h" + +int +main (void) +{ + msg ("begin"); + test_main (); + msg ("end"); + return 0; +} diff --git a/grading/filesys/mk-tree.c b/grading/filesys/mk-tree.c new file mode 100644 index 0000000..ed0e5c3 --- /dev/null +++ b/grading/filesys/mk-tree.c @@ -0,0 +1,65 @@ +#include +#include +#include "fslib.h" +#include "mk-tree.h" + +static void do_mkdir (const char *format, ...) PRINTF_FORMAT (1, 2); +static void do_touch (const char *format, ...) PRINTF_FORMAT (1, 2); + +void +make_tree (int at, int bt, int ct, int dt) +{ + char try[128]; + int a, b, c, d; + int fd; + + msg ("creating /0/0/0/0 through /%d/%d/%d/%d...", + at - 1, bt - 1, ct - 1, dt - 1); + quiet = true; + for (a = 0; a < at; a++) + { + do_mkdir ("/%d", a); + for (b = 0; b < bt; b++) + { + do_mkdir ("/%d/%d", a, b); + for (c = 0; c < ct; c++) + { + do_mkdir ("/%d/%d/%d", a, b, c); + for (d = 0; d < dt; d++) + do_touch ("/%d/%d/%d/%d", a, b, c, d); + } + } + } + quiet = false; + + snprintf (try, sizeof try, "/%d/%d/%d/%d", 0, bt - 1, 0, dt - 1); + check ((fd = open (try)) > 1, "open \"%s\"", try); + msg ("close \"%s\"", try); + close (fd); +} + +static void +do_mkdir (const char *format, ...) +{ + char dir[128]; + va_list args; + + va_start (args, format); + vsnprintf (dir, sizeof dir, format, args); + va_end (args); + + check (mkdir (dir), "mkdir \"%s\"", dir); +} + +static void +do_touch (const char *format, ...) +{ + char file[128]; + va_list args; + + va_start (args, format); + vsnprintf (file, sizeof file, format, args); + va_end (args); + + check (create (file, 0), "create \"%s\"", file); +} diff --git a/grading/filesys/mk-tree.h b/grading/filesys/mk-tree.h new file mode 100644 index 0000000..e10334c --- /dev/null +++ b/grading/filesys/mk-tree.h @@ -0,0 +1,6 @@ +#ifndef MK_TREE_H +#define MK_TREE_H 1 + +void make_tree (int at, int bt, int ct, int dt); + +#endif /* mk-tree.h */ diff --git a/grading/filesys/random.inc b/grading/filesys/random.inc index e821a59..e720574 100644 --- a/grading/filesys/random.inc +++ b/grading/filesys/random.inc @@ -15,14 +15,12 @@ char buf[TEST_SIZE]; int order[BLOCK_CNT]; -int -main (void) +void +test_main (void) { int fd; size_t i; - msg ("begin"); - random_init (57); random_bytes (buf, sizeof buf); @@ -64,7 +62,4 @@ main (void) fail ("close \"bazzle\""); close (fd); - - msg ("end"); - return 0; } diff --git a/grading/filesys/run-tests b/grading/filesys/run-tests index 7b73487..09c334c 100755 --- a/grading/filesys/run-tests +++ b/grading/filesys/run-tests @@ -48,8 +48,17 @@ sub usage { # 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 + 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 ) unless @TESTS > 0; our (%args); @@ -251,7 +260,8 @@ sub really_run_test { # Make output directory. mkdir "output/$test"; - xsystem ("pintos make-disk output/$test/fs.dsk 2 >/dev/null 2>&1", + my ($fs_size) = $test ne 'grow-too-big' ? 2 : .25; + xsystem ("pintos make-disk output/$test/fs.dsk $fs_size >/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"); @@ -268,6 +278,14 @@ sub really_run_test { if !xsystem ("$pintos_base_cmd put -f $GRADES_DIR/$test $test", LOG => "$test/put", TIMEOUT => 60, EXPECT => 1); + my (@extra_files); + push (@extra_files, "child-syn-read") if $test eq 'syn-read'; + for my $fn (@extra_files) { + return "format/put error" + if !xsystem ("$pintos_base_cmd put $GRADES_DIR/$fn $fn", + LOG => "$test/put-$fn", TIMEOUT => 60, EXPECT => 1); + } + # Run. my ($timeout) = 60; my ($testargs) = defined ($args{$test}) ? " $args{$test}" : ""; diff --git a/grading/filesys/seq-block.inc b/grading/filesys/seq-block.inc index e5424cd..9dc5d31 100644 --- a/grading/filesys/seq-block.inc +++ b/grading/filesys/seq-block.inc @@ -10,12 +10,10 @@ return_block_size (void) return BLOCK_SIZE; } -int -main (void) +void +test_main (void) { - msg ("begin"); - seq_test ("noodle", buf, sizeof buf, sizeof buf, 4, + seq_test ("noodle", + buf, sizeof buf, sizeof buf, return_block_size, NULL); - msg ("end"); - return 0; } diff --git a/grading/filesys/seq-random.inc b/grading/filesys/seq-random.inc index a0e6106..e22ba89 100644 --- a/grading/filesys/seq-random.inc +++ b/grading/filesys/seq-random.inc @@ -11,12 +11,11 @@ return_random (void) return random_ulong () % 1031 + 1; } -int -main (void) +void +test_main (void) { - msg ("begin"); random_init (-1); - seq_test ("nibble", buf, sizeof buf, sizeof buf, 5, return_random, NULL); - msg ("end"); - return 0; + seq_test ("nibble", + buf, sizeof buf, sizeof buf, + return_random, NULL); } diff --git a/grading/filesys/syn-read.c b/grading/filesys/syn-read.c new file mode 100644 index 0000000..d050db7 --- /dev/null +++ b/grading/filesys/syn-read.c @@ -0,0 +1,41 @@ +#include +#include +#include +#include "fslib.h" + +const char test_name[] = "syn-read"; + +static char buf[1024]; + +#define CHILD_CNT 10 + +void +test_main (void) +{ + const char *filename = "data"; + pid_t children[CHILD_CNT]; + int fd; + int i; + + check (create (filename, sizeof buf), "create \"%s\"", filename); + check ((fd = open (filename)) > 1, "open \"%s\"", filename); + random_bytes (buf, sizeof buf); + check (write (fd, buf, sizeof buf) > 0, "write \"%s\"", filename); + msg ("close \"%s\"", filename); + close (fd); + + 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); + check ((children[i] = exec (cmd_line)) != PID_ERROR, + "exec \"%s\"", 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); + } +} diff --git a/grading/filesys/syn-remove.c b/grading/filesys/syn-remove.c new file mode 100644 index 0000000..e47456a --- /dev/null +++ b/grading/filesys/syn-remove.c @@ -0,0 +1,28 @@ +#include +#include +#include +#include "fslib.h" + +const char test_name[] = "syn-remove"; + +char buf1[1234]; +char buf2[1234]; + +void +test_main (void) +{ + const char *filename = "deleteme"; + int fd; + + check (create (filename, 0), "create \"%s\"", filename); + check ((fd = open (filename)) > 1, "open \"%s\"", filename); + check (remove (filename), "remove \"%s\"", filename); + random_bytes (buf1, sizeof buf1); + check (write (fd, buf1, sizeof buf1) > 0, "write \"%s\"", filename); + 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"); + msg ("close \"%s\"", filename); + close (fd); +} diff --git a/grading/filesys/syn-remove.exp b/grading/filesys/syn-remove.exp new file mode 100644 index 0000000..f4ad702 --- /dev/null +++ b/grading/filesys/syn-remove.exp @@ -0,0 +1,10 @@ +(syn-remove) begin +(syn-remove) create "deleteme" +(syn-remove) open "deleteme" +(syn-remove) remove "deleteme" +(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/tests.txt b/grading/filesys/tests.txt index 901f5a1..837ca2b 100644 --- a/grading/filesys/tests.txt +++ b/grading/filesys/tests.txt @@ -24,6 +24,7 @@ File growth 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 past 64 kB, write byte, verify zeroing + grow-too-big: create empty file, seek past 2 GB, write byte, must not crash 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 @@ -31,22 +32,21 @@ File growth Score: / Subdirectories and file management - dir-mkdir: create directory and chdir into it + dir-mkdir: mkdir a, create a/b, chdir a, open b dir-rmdir: create directory, remove directory, chdir into it must now fail - dir-mk-vine: create deep chain of directories + dir-mk-vine: create deep chain of directories, create & check files in them dir-rm-vine: create and remove deep chain of directories - dir-mk-tree: create wide, deep directory tree + dir-mk-tree: create wide, deep directory tree, create & check files in it dir-rm-tree: create and remove wide, deep directory tree - dir-rel-mkdir: mkdir /a, chdir /a, mkdir b, chdir b, create /a/b/c, open c - dir-rel-open: mkdir /a, mkdir /a/b, create /a/b/c, chdir /a, open b/c - dir-rel-rmdir: mkdir a, mkdir /a/b, chdir a, rmdir b - dir-rel-remove: mkdir a, create /a/b, chdir a, remove b - dir-abs-mkdir: mkdir /a, chdir /a, mkdir /b, create /b/c, chdir /b, open c dir-lsdir: lsdir must work dir-rm-cwd: removing current directory must not crash - dir-rm-cwd-cd: if current directory removed then cd'ing to it must fail + dir-rm-cwd-cd: if current directory removable, then cd'ing to it must fail dir-rm-parent: removing current directory and then its parent must not crash - dir-open: if directories can be opened as file, then writing them must fail + dir-rm-root: must not be able to remove root directory + dir-over-file: creating a directory named after an existing file must fail + dir-under-file: creating a file named after an existing directory must fail + dir-empty-name: creating a file named after the empty string must fail + dir-open: if directories can be opened as files, then writing them must fail Score: / Synchronization -- 2.30.2