Add more tests.
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 1 Nov 2004 06:28:03 +0000 (06:28 +0000)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 1 Nov 2004 06:28:03 +0000 (06:28 +0000)
19 files changed:
grading/userprog/Makefile
grading/userprog/prep-disk
grading/userprog/read-boundary.c
grading/userprog/read-normal.c
grading/userprog/run-tests
grading/userprog/sample.inc [new file with mode: 0644]
grading/userprog/write-bad-fd.c [new file with mode: 0644]
grading/userprog/write-bad-fd.exp [new file with mode: 0644]
grading/userprog/write-bad-ptr.c [new file with mode: 0644]
grading/userprog/write-bad-ptr.exp [new file with mode: 0644]
grading/userprog/write-boundary.c [new file with mode: 0644]
grading/userprog/write-boundary.exp [new file with mode: 0644]
grading/userprog/write-normal.c [new file with mode: 0644]
grading/userprog/write-normal.exp [new file with mode: 0644]
grading/userprog/write-stdin.c [new file with mode: 0644]
grading/userprog/write-stdin.exp [new file with mode: 0644]
grading/userprog/write-zero.c [new file with mode: 0644]
grading/userprog/write-zero.exp [new file with mode: 0644]
src/Makefile.userprog

index e95e13fdaf032568be18041a61059077f0ed6d03..85ee607f51184d7938a681052e8f7aff7212de00 100644 (file)
@@ -7,7 +7,8 @@ SINGLETONS = \
        $(addprefix create-, normal empty null bad-ptr long exists bound) \
        $(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 read-, normal bad-ptr boundary zero stdout bad-fd) \
+       $(addprefix write-, normal bad-ptr boundary zero stdin bad-fd)
 
 define SINGLETON_PROG
 PROGS += $(1)
index c775a4e7ae14b53901613a8b710ec9f1f7037597..182c561460e9005b41054ba42ff3e3f5d501b641 100755 (executable)
@@ -40,7 +40,7 @@ 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-boundary write-zero));               
+                write-normal write-bad-ptr write-boundary write-zero));
 
 sub put_file {
     my ($fn) = @_;
index 799273093239f6a77ff2074e4b43efb8e547cede..41c798ea7f06302785e85dab5471edcaf10e447d 100644 (file)
@@ -2,15 +2,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <syscall.h>
-
-char expected[] = {
-  "Amazing Electronic Fact: If you scuffed your feet long enough without\n"
-  "touching anything, you would build up so many electrons that your\n"
-  "finger would explode!  But this is nothing to worry about unless you\n"
-  "have carpeting.\n" 
-};
-
-
+#include "sample.inc"
 
 static char *
 mk_boundary_string (const char *src) 
@@ -28,7 +20,7 @@ main (void)
   int byte_cnt;
   char *actual_p;
 
-  actual_p = mk_boundary_string (expected);
+  actual_p = mk_boundary_string (sample);
 
   printf ("(read-boundary) begin\n");
 
@@ -36,11 +28,11 @@ main (void)
   if (handle < 2)
     printf ("(read-boundary) fail: open() returned %d\n", handle);
 
-  byte_cnt = read (handle, actual_p, sizeof expected - 1);
-  if (byte_cnt != sizeof expected - 1)
+  byte_cnt = read (handle, actual_p, sizeof sample - 1);
+  if (byte_cnt != sizeof sample - 1)
     printf ("(read-boundary) fail: read() returned %d instead of %d\n",
-            byte_cnt, sizeof expected - 1);
-  else if (strcmp (expected, actual_p))
+            byte_cnt, sizeof sample - 1);
+  else if (strcmp (sample, actual_p))
     printf ("(read-boundary) fail: expected text differs from actual:\n%s",
             actual_p);
   
index 4bb7679ad39486a305079551a9a957515fde7868..2e6f6817b8814d9ff49e1e46714a558f40d728f2 100644 (file)
@@ -1,15 +1,9 @@
 #include <stdio.h>
 #include <string.h>
 #include <syscall.h>
+#include "sample.inc"
 
-char expected[] = {
-  "Amazing Electronic Fact: If you scuffed your feet long enough without\n"
-  "touching anything, you would build up so many electrons that your\n"
-  "finger would explode!  But this is nothing to worry about unless you\n"
-  "have carpeting.\n" 
-};
-
-char actual[sizeof expected];
+char actual[sizeof sample];
 
 int
 main (void) 
@@ -25,7 +19,7 @@ main (void)
   if (byte_cnt != sizeof actual - 1)
     printf ("(read-normal) fail: read() returned %d instead of %d\n",
             byte_cnt, sizeof actual - 1);
-  else if (strcmp (expected, actual))
+  else if (strcmp (sample, actual))
     printf ("(read-normal) fail: expected text differs from actual:\n%s",
             actual);
   
index 37816499814230bb9aceba85fc9721b1e3d8acc4..9ca9381a99d5e5257ed0f0097cdd597b57f83ccd 100755 (executable)
@@ -48,6 +48,8 @@ sub usage {
             close-normal close-twice close-stdin close-stdout close-bad-fd
             read-normal read-bad-ptr read-boundary read-zero read-stdout
             read-bad-fd
+            write-normal write-bad-ptr write-boundary write-zero write-stdin
+            write-bad-fd
             ) unless @TESTS > 0;
 
 our (%args);
@@ -271,15 +273,15 @@ sub grade_test {
 
     my (@output) = snarf ("output/$test/run.out");
 
-    if (-e "$GRADES_DIR/$test.exp") {
+    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 {
-       my ($grade_func);
-       ($grade_func = $test) =~ s/-/_/g;
-       eval "grade_$grade_func (\@output)";
+       eval "$grade_func (\@output)";
     }
     if ($@) {
        die $@ if $@ =~ /at \S+ line \d+$/;
@@ -288,42 +290,24 @@ sub grade_test {
     return "ok";
 }
 \f
-sub grade_alarm_multiple {
-    verify_alarm (7, @_);
-}
-
-sub verify_alarm {
-    my ($iterations, @output) = @_;
-
+sub grade_write_normal {
+    my (@output) = @_;
     verify_common (@output);
-
-    my (@products);
-    for (my ($i) = 0; $i < $iterations; $i++) {
-       for (my ($t) = 0; $t < 5; $t++) {
-           push (@products, ($i + 1) * ($t + 1) * 10);
-       }
-    }
-    @products = sort {$a <=> $b} @products;
-
-    local ($_);
-    foreach (@output) {
-       die $_ if /Out of order/;
-
-       my ($p) = /product=(\d+)$/;
-       next if !defined $p;
-
-       my ($q) = shift (@products);
-       die "Too many wakeups.\n" if !defined $q;
-       die "Out of order wakeups ($p vs. $q).\n" if $p != $q; # FIXME
-    }
-    die scalar (@products) . " fewer wakeups than expected.\n"
-       if @products != 0;
+    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));
 }
 
-sub grade_alarm_zero {
-    my (@output) = @_;
-    verify_common (@output);
-    die "Crashed in timer_sleep()\n" if !grep (/^Success\.$/, @output);
+sub get_file {
+    my ($guest_fn, $host_fn) = @_;
+    xsystem ("pintos "
+            . "--os-disk=pintos/src/userprog/build/os.dsk "
+            . "--fs-disk=output/$test/fs.dsk "
+            . "-v get $guest_fn $host_fn",
+            LOG => "$test/get-$guest_fn",
+            TIMEOUT => 10)
+       or die "get $guest_fn failed\n";
 }
 
 sub grade_alarm_negative {
diff --git a/grading/userprog/sample.inc b/grading/userprog/sample.inc
new file mode 100644 (file)
index 0000000..dd3d718
--- /dev/null
@@ -0,0 +1,6 @@
+char sample[] = {
+  "Amazing Electronic Fact: If you scuffed your feet long enough without\n"
+  "touching anything, you would build up so many electrons that your\n"
+  "finger would explode!  But this is nothing to worry about unless you\n"
+  "have carpeting.\n" 
+};
diff --git a/grading/userprog/write-bad-fd.c b/grading/userprog/write-bad-fd.c
new file mode 100644 (file)
index 0000000..33df001
--- /dev/null
@@ -0,0 +1,12 @@
+#include <stdio.h>
+#include <syscall.h>
+
+int
+main (void) 
+{
+  char buf = 123;
+  printf ("(write-bad-fd) begin\n");
+  write (0xc0101234, &buf, 1);
+  printf ("(write-bad-fd) end\n");
+  return 0;
+}
diff --git a/grading/userprog/write-bad-fd.exp b/grading/userprog/write-bad-fd.exp
new file mode 100644 (file)
index 0000000..dd05467
--- /dev/null
@@ -0,0 +1,6 @@
+(write-bad-fd) begin
+(write-bad-fd) end
+write-bad-fd: exit(0)
+--OR--
+(write-bad-fd) begin
+write-bad-fd: exit(-1)
diff --git a/grading/userprog/write-bad-ptr.c b/grading/userprog/write-bad-ptr.c
new file mode 100644 (file)
index 0000000..9431c70
--- /dev/null
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include <syscall.h>
+
+int
+main (void) 
+{
+  int handle;
+  printf ("(write-bad-ptr) begin\n");
+
+  handle = open ("sample.txt");
+  if (handle < 2)
+    printf ("(write-bad-ptr) fail: open() returned %d\n", handle);
+
+  write (handle, (char *) 0xc0101234, 123);
+  
+  printf ("(write-bad-ptr) end\n");
+  return 0;
+}
diff --git a/grading/userprog/write-bad-ptr.exp b/grading/userprog/write-bad-ptr.exp
new file mode 100644 (file)
index 0000000..1540400
--- /dev/null
@@ -0,0 +1,6 @@
+(write-bad-ptr) begin
+(write-bad-ptr) end
+write-bad-ptr: exit(0)
+--OR--
+(write-bad-ptr) begin
+write-bad-ptr: exit(-1)
diff --git a/grading/userprog/write-boundary.c b/grading/userprog/write-boundary.c
new file mode 100644 (file)
index 0000000..a31dad0
--- /dev/null
@@ -0,0 +1,38 @@
+#include <inttypes.h>
+#include <stdio.h>
+#include <string.h>
+#include <syscall.h>
+#include "sample.inc"
+
+static char *
+mk_boundary_string (const char *src) 
+{
+  static char dst[8192];
+  char *p = dst + (4096 - (uintptr_t) dst % 4096 - strlen (src) / 2);
+  strlcpy (p, src, 4096);
+  return p;
+}
+
+int
+main (void) 
+{
+  int handle;
+  int byte_cnt;
+  char *sample_p;
+
+  sample_p = mk_boundary_string (sample);
+
+  printf ("(write-boundary) begin\n");
+
+  handle = open ("sample.txt");
+  if (handle < 2)
+    printf ("(write-boundary) fail: open() returned %d\n", handle);
+
+  byte_cnt = write (handle, sample_p, sizeof sample - 1);
+  if (byte_cnt != sizeof sample - 1)
+    printf ("(write-boundary) fail: write() returned %d instead of %d\n",
+            byte_cnt, sizeof sample - 1);
+  
+  printf ("(write-boundary) end\n");
+  return 0;
+}
diff --git a/grading/userprog/write-boundary.exp b/grading/userprog/write-boundary.exp
new file mode 100644 (file)
index 0000000..bf64357
--- /dev/null
@@ -0,0 +1,3 @@
+(write-boundary) begin
+(write-boundary) end
+write-boundary: exit(0)
diff --git a/grading/userprog/write-normal.c b/grading/userprog/write-normal.c
new file mode 100644 (file)
index 0000000..b2e96e8
--- /dev/null
@@ -0,0 +1,26 @@
+#include <stdio.h>
+#include <string.h>
+#include <syscall.h>
+#include "sample.inc"
+
+int
+main (void) 
+{
+  int handle, byte_cnt;
+  printf ("(write-normal) begin\n");
+
+  if (!create ("test.txt", sizeof sample - 1))
+    printf ("(write-normal) create() failed\n");
+
+  handle = open ("test.txt");
+  if (handle < 2)
+    printf ("(write-normal) fail: open() returned %d\n", handle);
+
+  byte_cnt = write (handle, sample, sizeof sample - 1);
+  if (byte_cnt != sizeof sample - 1)
+    printf ("(write-normal) fail: write() returned %d instead of %d\n",
+            byte_cnt, sizeof sample - 1);
+  
+  printf ("(write-normal) end\n");
+  return 0;
+}
diff --git a/grading/userprog/write-normal.exp b/grading/userprog/write-normal.exp
new file mode 100644 (file)
index 0000000..87b05e5
--- /dev/null
@@ -0,0 +1,3 @@
+(write-normal) begin
+(write-normal) end
+write-normal: exit(0)
diff --git a/grading/userprog/write-stdin.c b/grading/userprog/write-stdin.c
new file mode 100644 (file)
index 0000000..1c6862b
--- /dev/null
@@ -0,0 +1,12 @@
+#include <stdio.h>
+#include <syscall.h>
+
+int
+main (void) 
+{
+  char buf = 123;
+  printf ("(write-stdin) begin\n");
+  write (0, &buf, 1);
+  printf ("(write-stdin) end\n");
+  return 0;
+}
diff --git a/grading/userprog/write-stdin.exp b/grading/userprog/write-stdin.exp
new file mode 100644 (file)
index 0000000..bee46e0
--- /dev/null
@@ -0,0 +1,6 @@
+(write-stdin) begin
+(write-stdin) end
+write-stdin: exit(0)
+--OR--
+(write-stdin) begin
+write-stdin: exit(-1)
diff --git a/grading/userprog/write-zero.c b/grading/userprog/write-zero.c
new file mode 100644 (file)
index 0000000..e5b5b95
--- /dev/null
@@ -0,0 +1,22 @@
+#include <stdio.h>
+#include <syscall.h>
+
+int
+main (void) 
+{
+  int handle, byte_cnt;
+  char buf;
+  printf ("(write-zero) begin\n");
+
+  handle = open ("sample.txt");
+  if (handle < 2)
+    printf ("(write-zero) fail: open() returned %d\n", handle);
+
+  buf = 123;
+  byte_cnt = write (handle, &buf, 0);
+  if (byte_cnt != 0)
+    printf ("(write-zero) fail: write() returned %d instead of 0\n", byte_cnt);
+  
+  printf ("(write-zero) end\n");
+  return 0;
+}
diff --git a/grading/userprog/write-zero.exp b/grading/userprog/write-zero.exp
new file mode 100644 (file)
index 0000000..ba76b0c
--- /dev/null
@@ -0,0 +1,3 @@
+(write-zero) begin
+(write-zero) end
+write-zero: exit(0)
index 4cdf078ab9898f36ccbdec5835692b7a8c1c71b4..0d93189d68a87ff0c4fabdf2dba6a88ef13fea11 100644 (file)
@@ -7,7 +7,7 @@ SHELL = /bin/sh
 VPATH = $(SRCDIR)
 
 DEFINES = -DUSER
-CPPFLAGS = -nostdinc -I$(SRCDIR) -I- -I$(SRCDIR)/lib -I$(SRCDIR)/lib/user
+CPPFLAGS = -nostdinc -I$(SRCDIR) -I- -I$(SRCDIR)/lib -I$(SRCDIR)/lib/user -I.
 
 # Linker flags.
 LDFLAGS = -nostdlib -static -s