From bf4c5c753234a3d014ecfc2a2b647551ccbad0e0 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 3 Nov 2004 22:52:40 +0000 Subject: [PATCH] More tests. --- grading/userprog/Makefile | 6 +++-- grading/userprog/child-close.c | 20 +++++++++++++++++ grading/userprog/multi-child-fd.c | 35 +++++++++++++++++++++++++++++ grading/userprog/multi-child-fd.exp | 12 ++++++++++ grading/userprog/multi-parent-fd.c | 35 +++++++++++++++++++++++++++++ grading/userprog/prep-disk | 4 +++- grading/userprog/run-tests | 13 +++++++++-- 7 files changed, 120 insertions(+), 5 deletions(-) create mode 100644 grading/userprog/child-close.c create mode 100644 grading/userprog/multi-child-fd.c create mode 100644 grading/userprog/multi-child-fd.exp create mode 100644 grading/userprog/multi-parent-fd.c diff --git a/grading/userprog/Makefile b/grading/userprog/Makefile index c1e5f24..e49f6d6 100644 --- a/grading/userprog/Makefile +++ b/grading/userprog/Makefile @@ -12,7 +12,7 @@ TESTS = \ $(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) \ - $(addprefix multi-, recurse oom) + $(addprefix multi-, recurse oom child-fd) define TEST_PROG PROGS += $(1) @@ -25,13 +25,15 @@ DISKS = $(patsubst %,%.dsk,$(PROGS)) disks: $(DISKS) # Other programs needed by some of the main test programs. -PROGS += child-simple child-arg child-bad +PROGS += child-simple child-arg child-bad child-close child_simple_SRC = child-simple.c child_arg_SRC = child-arg.c child_bad_SRC = child-bad.c +child_close_SRC = child-close.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 +multi-child-fd.dsk: child-close %.dsk: % ./prep-disk $< diff --git a/grading/userprog/child-close.c b/grading/userprog/child-close.c new file mode 100644 index 0000000..1134341 --- /dev/null +++ b/grading/userprog/child-close.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include + +int +main (int argc UNUSED, char *argv[]) +{ + if (isdigit (*argv[0])) + close (atoi (argv[0])); + else if (isdigit (*argv[1])) + close (atoi (argv[1])); + else + { + printf ("(child-close) fail: bad command-line arguments\n"); + return 1; + } + printf ("(child-close) success\n"); + return 0; +} diff --git a/grading/userprog/multi-child-fd.c b/grading/userprog/multi-child-fd.c new file mode 100644 index 0000000..4a8c89f --- /dev/null +++ b/grading/userprog/multi-child-fd.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include "sample.inc" + +char actual[sizeof sample]; + +int +main (void) +{ + char child_cmd[128]; + int byte_cnt; + int handle; + + printf ("(multi-child-fd) begin\n"); + + handle = open("sample.txt"); + if (handle < 2) + printf ("(multi-child-fd) fail: open() returned %d\n", handle); + + snprintf (child_cmd, sizeof child_cmd, "child-close %d", handle); + + printf ("(multi-child-fd) join(exec()) = %d\n", join (exec (child_cmd))); + + byte_cnt = read (handle, actual, sizeof actual - 1); + if (byte_cnt != sizeof actual - 1) + printf ("(multi-child-fd) fail: read() returned %d instead of %d\n", + byte_cnt, sizeof actual - 1); + else if (strcmp (sample, actual)) + printf ("(multi-child-fd) fail: expected text differs from actual:\n%s", + actual); + + printf ("(multi-child-fd) end\n"); + return 0; +} diff --git a/grading/userprog/multi-child-fd.exp b/grading/userprog/multi-child-fd.exp new file mode 100644 index 0000000..57b2e12 --- /dev/null +++ b/grading/userprog/multi-child-fd.exp @@ -0,0 +1,12 @@ +(multi-child-fd) begin +(child-close) success +child-close: exit(0) +(multi-child-fd) join(exec()) = 0 +(multi-child-fd) end +multi-child-fd: exit(0) +--OR-- +(multi-child-fd) begin +child-close: exit(-1) +(multi-child-fd) join(exec()) = -1 +(multi-child-fd) end +multi-child-fd: exit(0) diff --git a/grading/userprog/multi-parent-fd.c b/grading/userprog/multi-parent-fd.c new file mode 100644 index 0000000..4a8c89f --- /dev/null +++ b/grading/userprog/multi-parent-fd.c @@ -0,0 +1,35 @@ +#include +#include +#include +#include "sample.inc" + +char actual[sizeof sample]; + +int +main (void) +{ + char child_cmd[128]; + int byte_cnt; + int handle; + + printf ("(multi-child-fd) begin\n"); + + handle = open("sample.txt"); + if (handle < 2) + printf ("(multi-child-fd) fail: open() returned %d\n", handle); + + snprintf (child_cmd, sizeof child_cmd, "child-close %d", handle); + + printf ("(multi-child-fd) join(exec()) = %d\n", join (exec (child_cmd))); + + byte_cnt = read (handle, actual, sizeof actual - 1); + if (byte_cnt != sizeof actual - 1) + printf ("(multi-child-fd) fail: read() returned %d instead of %d\n", + byte_cnt, sizeof actual - 1); + else if (strcmp (sample, actual)) + printf ("(multi-child-fd) fail: expected text differs from actual:\n%s", + actual); + + printf ("(multi-child-fd) end\n"); + return 0; +} diff --git a/grading/userprog/prep-disk b/grading/userprog/prep-disk index 2a5a9f1..611fdcc 100755 --- a/grading/userprog/prep-disk +++ b/grading/userprog/prep-disk @@ -40,9 +40,11 @@ put_file ("sample.txt") qw (open-normal open-boundary open-twice close-normal close-twice read-normal read-bad-ptr read-boundary read-zero - write-normal write-bad-ptr write-boundary write-zero)); + write-normal write-bad-ptr write-boundary write-zero + multi-child-fd)); put_file ("child-simple") if $test eq 'exec-once' or $test eq 'exec-multiple'; put_file ("child-arg") if $test eq 'exec-arg'; +put_file ("child-close") if $test eq 'multi-child-fd'; sub put_file { my ($fn) = @_; diff --git a/grading/userprog/run-tests b/grading/userprog/run-tests index 1cd9bf4..e2587c2 100755 --- a/grading/userprog/run-tests +++ b/grading/userprog/run-tests @@ -51,7 +51,7 @@ sub usage { 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 - multi-recurse multi-oom + multi-recurse multi-oom multi-child-fd ) unless @TESTS > 0; our (%args); @@ -192,6 +192,15 @@ sub extract_tarball { xsystem ("patch -fs pintos/src/lib/debug.c < $GRADES_DIR/panic.diff", LOG => "patch", DIE => "patch failed\n"); + xsystem ("patch -fs pintos/src/lib/kernel/bitmap.c " + . "< $GRADES_DIR/random.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 { @@ -384,7 +393,7 @@ sub verify_common { } else { $A2L = "i386-elf-addr2line"; } - open (A2L, "$A2L -fe output/$test/kernel.o @addrs|"); + open (A2L, "$A2L -fe pintos/src/userprog/build/kernel.o @addrs|"); for (;;) { my ($function, $line); last unless defined ($function = ); -- 2.30.2