From 5f5e3ca7e9d053549bd4c6f55672ae867857ec54 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 2 Nov 2004 03:18:48 +0000 Subject: [PATCH] Add more tests. --- grading/userprog/Makefile | 20 ++++++++++++++++---- grading/userprog/child-arg.c | 25 +++++++++++++++++++++++++ grading/userprog/child-bad.c | 11 +++++++++++ grading/userprog/child-simple.c | 8 ++++++++ grading/userprog/exec-arg.c | 11 +++++++++++ grading/userprog/exec-arg.exp | 5 +++++ grading/userprog/exec-bad-ptr.c | 11 +++++++++++ grading/userprog/exec-bad-ptr.exp | 6 ++++++ grading/userprog/exec-missing.c | 12 ++++++++++++ grading/userprog/exec-missing.exp | 4 ++++ grading/userprog/exec-multiple.c | 14 ++++++++++++++ grading/userprog/exec-multiple.exp | 11 +++++++++++ grading/userprog/exec-once.c | 11 +++++++++++ grading/userprog/exec-once.exp | 5 +++++ grading/userprog/join-bad-pid.c | 11 +++++++++++ grading/userprog/join-bad-pid.exp | 4 ++++ grading/userprog/join-killed.c | 11 +++++++++++ grading/userprog/join-killed.exp | 6 ++++++ grading/userprog/join-simple.c | 11 +++++++++++ grading/userprog/join-simple.exp | 6 ++++++ grading/userprog/join-twice.c | 14 ++++++++++++++ grading/userprog/join-twice.exp | 6 ++++++ grading/userprog/prep-disk | 2 ++ grading/userprog/run-tests | 25 ++++++++++++++++++++++++- grading/userprog/tests.txt | 3 ++- 25 files changed, 247 insertions(+), 6 deletions(-) create mode 100644 grading/userprog/child-arg.c create mode 100644 grading/userprog/child-bad.c create mode 100644 grading/userprog/child-simple.c create mode 100644 grading/userprog/exec-arg.c create mode 100644 grading/userprog/exec-arg.exp create mode 100644 grading/userprog/exec-bad-ptr.c create mode 100644 grading/userprog/exec-bad-ptr.exp create mode 100644 grading/userprog/exec-missing.c create mode 100644 grading/userprog/exec-missing.exp create mode 100644 grading/userprog/exec-multiple.c create mode 100644 grading/userprog/exec-multiple.exp create mode 100644 grading/userprog/exec-once.c create mode 100644 grading/userprog/exec-once.exp create mode 100644 grading/userprog/join-bad-pid.c create mode 100644 grading/userprog/join-bad-pid.exp create mode 100644 grading/userprog/join-killed.c create mode 100644 grading/userprog/join-killed.exp create mode 100644 grading/userprog/join-simple.c create mode 100644 grading/userprog/join-simple.exp create mode 100644 grading/userprog/join-twice.c create mode 100644 grading/userprog/join-twice.exp diff --git a/grading/userprog/Makefile b/grading/userprog/Makefile index 85ee607..6ce6cba 100644 --- a/grading/userprog/Makefile +++ b/grading/userprog/Makefile @@ -1,6 +1,7 @@ SRCDIR = ../../src -SINGLETONS = \ +# Main test programs. +TESTS = \ $(addprefix args-, argc argv0 argvn single multiple dbl-space) \ $(addprefix sc-, bad-sp bad-arg boundary) \ halt exit \ @@ -8,18 +9,29 @@ SINGLETONS = \ $(addprefix open-, normal missing boundary empty null bad-ptr twice) \ $(addprefix close-, normal twice stdin stdout bad-fd) \ $(addprefix read-, normal bad-ptr boundary zero stdout bad-fd) \ - $(addprefix write-, normal bad-ptr boundary zero stdin bad-fd) + $(addprefix write-, normal bad-ptr boundary zero stdin bad-fd) \ + $(addprefix exec-, once arg multiple missing bad-ptr) \ + $(addprefix join-, simple twice killed bad-pid) -define SINGLETON_PROG +define TEST_PROG PROGS += $(1) $(subst -,_,$(1))_SRC = $(1).c endef -$(foreach prog,$(SINGLETONS),$(eval $(call SINGLETON_PROG,$(prog)))) +$(foreach prog,$(TESTS),$(eval $(call TEST_PROG,$(prog)))) DISKS = $(patsubst %,%.dsk,$(PROGS)) disks: $(DISKS) +# Other programs needed by some of the main test programs. +PROGS += child-simple child-arg child-bad +child_simple_SRC = child-simple.c +child_arg_SRC = child-arg.c +child_bad_SRC = child-bad.c +exec-once.dsk exec-multiple.dsk join-simple.dsk join-twice.dsk: child-simple +exec-arg.dsk: child-arg +join-killed.dsk: child-bad + %.dsk: % ./prep-disk $< diff --git a/grading/userprog/child-arg.c b/grading/userprog/child-arg.c new file mode 100644 index 0000000..748798b --- /dev/null +++ b/grading/userprog/child-arg.c @@ -0,0 +1,25 @@ +#include +#include + +int +main (int argc, char *argv[]) +{ + if (!strcmp (argv[0], "childarg") || !strcmp (argv[1], "childarg")) + { + printf ("(child-arg) success\n"); + return 0; + } + else + { + int i; + + printf ("(child-arg) failure\n"); + printf ("(child-arg) argc=%d\n", argc); + for (i = 0; i <= argc; i++) + if (argv[i] >= (char *) 0xbffff000 && argv[i] < (char *) 0xc0000000) + printf ("(child-arg) argv[%d]='%s'\n", i, argv[i]); + else + printf ("(child-arg) argv[%d]=%p\n", i, argv[i]); + return 1; + } +} diff --git a/grading/userprog/child-bad.c b/grading/userprog/child-bad.c new file mode 100644 index 0000000..a256e63 --- /dev/null +++ b/grading/userprog/child-bad.c @@ -0,0 +1,11 @@ +#include +#include + +int +main (void) +{ + printf ("(child-bad) begin\n"); + asm volatile ("mov $0xc0101234, %esp; int $0x30"); + printf ("(child-bad) end\n"); + return 0; +} diff --git a/grading/userprog/child-simple.c b/grading/userprog/child-simple.c new file mode 100644 index 0000000..8360cc8 --- /dev/null +++ b/grading/userprog/child-simple.c @@ -0,0 +1,8 @@ +#include + +int +main (void) +{ + printf ("(child-simple) run\n"); + return 81; +} diff --git a/grading/userprog/exec-arg.c b/grading/userprog/exec-arg.c new file mode 100644 index 0000000..97f94cf --- /dev/null +++ b/grading/userprog/exec-arg.c @@ -0,0 +1,11 @@ +#include +#include + +int +main (void) +{ + printf ("(exec-arg) begin\n"); + join (exec ("child-arg childarg")); + printf ("(exec-arg) end\n"); + return 0; +} diff --git a/grading/userprog/exec-arg.exp b/grading/userprog/exec-arg.exp new file mode 100644 index 0000000..2b8aee7 --- /dev/null +++ b/grading/userprog/exec-arg.exp @@ -0,0 +1,5 @@ +(exec-arg) begin +(child-arg) success +child-arg: exit(0) +(exec-arg) end +exec-arg: exit(0) diff --git a/grading/userprog/exec-bad-ptr.c b/grading/userprog/exec-bad-ptr.c new file mode 100644 index 0000000..28dcc9b --- /dev/null +++ b/grading/userprog/exec-bad-ptr.c @@ -0,0 +1,11 @@ +#include +#include + +int +main (void) +{ + printf ("(exec-bad-ptr) begin\n"); + exec ((char *) 0xc0101234); + printf ("(exec-bad-ptr) end\n"); + return 0; +} diff --git a/grading/userprog/exec-bad-ptr.exp b/grading/userprog/exec-bad-ptr.exp new file mode 100644 index 0000000..a90700c --- /dev/null +++ b/grading/userprog/exec-bad-ptr.exp @@ -0,0 +1,6 @@ +(exec-bad-ptr) begin +(exec-bad-ptr) end +exec-bad-ptr: exit(0) +--OR-- +(exec-bad-ptr) begin +exec-bad-ptr: exit(-1) diff --git a/grading/userprog/exec-missing.c b/grading/userprog/exec-missing.c new file mode 100644 index 0000000..5fcc3d8 --- /dev/null +++ b/grading/userprog/exec-missing.c @@ -0,0 +1,12 @@ +#include +#include + +int +main (void) +{ + printf ("(exec-missing) begin\n"); + printf ("(exec-missing) exec(\"no-such-file\"): %d\n", + exec ("no-such-file")); + printf ("(exec-missing) end\n"); + return 0; +} diff --git a/grading/userprog/exec-missing.exp b/grading/userprog/exec-missing.exp new file mode 100644 index 0000000..7334b9e --- /dev/null +++ b/grading/userprog/exec-missing.exp @@ -0,0 +1,4 @@ +(exec-missing) begin +(exec-missing) exec("no-such-file"): -1 +(exec-missing) end +exec-missing: exit(0) diff --git a/grading/userprog/exec-multiple.c b/grading/userprog/exec-multiple.c new file mode 100644 index 0000000..e2f8506 --- /dev/null +++ b/grading/userprog/exec-multiple.c @@ -0,0 +1,14 @@ +#include +#include + +int +main (void) +{ + printf ("(exec-multiple) begin\n"); + join (exec ("child-simple")); + join (exec ("child-simple")); + join (exec ("child-simple")); + join (exec ("child-simple")); + printf ("(exec-multiple) end\n"); + return 0; +} diff --git a/grading/userprog/exec-multiple.exp b/grading/userprog/exec-multiple.exp new file mode 100644 index 0000000..0f7752c --- /dev/null +++ b/grading/userprog/exec-multiple.exp @@ -0,0 +1,11 @@ +(exec-multiple) begin +(child-simple) run +child-simple: exit(81) +(child-simple) run +child-simple: exit(81) +(child-simple) run +child-simple: exit(81) +(child-simple) run +child-simple: exit(81) +(exec-multiple) end +exec-multiple: exit(0) diff --git a/grading/userprog/exec-once.c b/grading/userprog/exec-once.c new file mode 100644 index 0000000..ab1de21 --- /dev/null +++ b/grading/userprog/exec-once.c @@ -0,0 +1,11 @@ +#include +#include + +int +main (void) +{ + printf ("(exec-once) begin\n"); + join (exec ("child-simple")); + printf ("(exec-once) end\n"); + return 0; +} diff --git a/grading/userprog/exec-once.exp b/grading/userprog/exec-once.exp new file mode 100644 index 0000000..82132e1 --- /dev/null +++ b/grading/userprog/exec-once.exp @@ -0,0 +1,5 @@ +(exec-once) begin +(child-simple) run +child-simple: exit(81) +(exec-once) end +exec-once: exit(0) diff --git a/grading/userprog/join-bad-pid.c b/grading/userprog/join-bad-pid.c new file mode 100644 index 0000000..9729097 --- /dev/null +++ b/grading/userprog/join-bad-pid.c @@ -0,0 +1,11 @@ +#include +#include + +int +main (void) +{ + printf ("(join-bad-pid) begin\n"); + join ((pid_t) 0xc0101234); + printf ("(join-bad-pid) end\n"); + return 0; +} diff --git a/grading/userprog/join-bad-pid.exp b/grading/userprog/join-bad-pid.exp new file mode 100644 index 0000000..0446482 --- /dev/null +++ b/grading/userprog/join-bad-pid.exp @@ -0,0 +1,4 @@ +(join-simple) begin +(join-simple) join(exec()) = 81 +(join-simple) end +join-simple: exit(0) diff --git a/grading/userprog/join-killed.c b/grading/userprog/join-killed.c new file mode 100644 index 0000000..6a8e6b4 --- /dev/null +++ b/grading/userprog/join-killed.c @@ -0,0 +1,11 @@ +#include +#include + +int +main (void) +{ + printf ("(join-killed) begin\n"); + printf ("(join-killed) join(exec()) = %d\n", join (exec ("child-bad"))); + printf ("(join-killed) end\n"); + return 0; +} diff --git a/grading/userprog/join-killed.exp b/grading/userprog/join-killed.exp new file mode 100644 index 0000000..0e28e2e --- /dev/null +++ b/grading/userprog/join-killed.exp @@ -0,0 +1,6 @@ +(join-killed) begin +(child-bad) begin +child-bad: exit(-1) +(join-killed) join(exec()) = -1 +(join-killed) end +join-killed: exit(0) diff --git a/grading/userprog/join-simple.c b/grading/userprog/join-simple.c new file mode 100644 index 0000000..9d1624a --- /dev/null +++ b/grading/userprog/join-simple.c @@ -0,0 +1,11 @@ +#include +#include + +int +main (void) +{ + printf ("(join-simple) begin\n"); + printf ("(join-simple) join(exec()) = %d\n", join (exec ("child-simple"))); + printf ("(join-simple) end\n"); + return 0; +} diff --git a/grading/userprog/join-simple.exp b/grading/userprog/join-simple.exp new file mode 100644 index 0000000..b3b4051 --- /dev/null +++ b/grading/userprog/join-simple.exp @@ -0,0 +1,6 @@ +(join-simple) begin +(child-simple) run +child-simple: exit(81) +(join-simple) join(exec()) = 81 +(join-simple) end +join-simple: exit(0) diff --git a/grading/userprog/join-twice.c b/grading/userprog/join-twice.c new file mode 100644 index 0000000..10ccb22 --- /dev/null +++ b/grading/userprog/join-twice.c @@ -0,0 +1,14 @@ +#include +#include + +int +main (void) +{ + pid_t child; + printf ("(join-twice) begin\n"); + child = exec ("child-twice"); + printf ("(join-twice) join(exec()) = %d\n", join (child)); + join (child); + printf ("(join-twice) end\n"); + return 0; +} diff --git a/grading/userprog/join-twice.exp b/grading/userprog/join-twice.exp new file mode 100644 index 0000000..71f6223 --- /dev/null +++ b/grading/userprog/join-twice.exp @@ -0,0 +1,6 @@ +(join-twice) begin +(child-twice) run +child-twice: exit(81) +(join-twice) join(exec()) = 81 +(join-twice) end +join-twice: exit(0) diff --git a/grading/userprog/prep-disk b/grading/userprog/prep-disk index 182c561..2a5a9f1 100755 --- a/grading/userprog/prep-disk +++ b/grading/userprog/prep-disk @@ -41,6 +41,8 @@ put_file ("sample.txt") close-normal close-twice read-normal read-bad-ptr read-boundary read-zero write-normal write-bad-ptr write-boundary write-zero)); +put_file ("child-simple") if $test eq 'exec-once' or $test eq 'exec-multiple'; +put_file ("child-arg") if $test eq 'exec-arg'; sub put_file { my ($fn) = @_; diff --git a/grading/userprog/run-tests b/grading/userprog/run-tests index 9ca9381..c51089e 100755 --- a/grading/userprog/run-tests +++ b/grading/userprog/run-tests @@ -50,6 +50,7 @@ sub usage { read-bad-fd write-normal write-bad-ptr write-boundary write-zero write-stdin write-bad-fd + exec-once exec-arg exec-multiple exec-missing exec-bad-ptr ) unless @TESTS > 0; our (%args); @@ -296,7 +297,29 @@ sub grade_write_normal { compare_output ("$GRADES_DIR/write-normal.exp", @output); my ($test_txt) = "output/$test/test.txt"; get_file ("test.txt", $test_txt) if ! -e $test_txt; - compare_output ("$GRADES_DIR/sample.txt", snarf ($test_txt)); + + my (@actual) = snarf ($test_txt); + my (@expected) = snarf ("$GRADES_DIR/sample.txt"); + + my ($eq); + if ($#actual == $#expected) { + $eq = 1; + for my $i (0...$#actual) { + $eq = 0 if $actual[$i] ne $expected[$i]; + } + } else { + $eq = 0; + } + if (!$eq) { + my ($details); + $details = "Expected file content:\n"; + $details .= join ('', map (" $_\n", @expected)); + $details .= "Actual file content:\n"; + $details .= join ('', map (" $_\n", @actual)); + $extra{$test} = $details; + + die "File written didn't have expected content.\n"; + } } sub get_file { diff --git a/grading/userprog/tests.txt b/grading/userprog/tests.txt index ce7c393..afeed07 100644 --- a/grading/userprog/tests.txt +++ b/grading/userprog/tests.txt @@ -69,10 +69,11 @@ Score: /9 System calls: exec -2 exec-once: call exec/join once + -2 exec-arg: check command-line passing on exec -2 exec-multiple: call exec/join multiple times -2 exec-missing: exec of nonexistent file must return -1 -1 exec-bad-ptr: pass invalid pointer to exec system call -Score: /7 +Score: /9 System calls: join -2 join-simple: join must return proper value -- 2.30.2