Add more tests.
[pintos-anon] / grading / userprog / prep-disk
diff --git a/grading/userprog/prep-disk b/grading/userprog/prep-disk
new file mode 100755 (executable)
index 0000000..c775a4e
--- /dev/null
@@ -0,0 +1,57 @@
+#! /usr/bin/perl -w
+
+use strict;
+use Getopt::Long;
+
+my ($pintos) = "pintos";
+my ($os_disk) = "../../src/userprog/build/os.dsk";
+my ($fs_disk);
+my ($test);
+
+GetOptions ("os-disk=s" => \$os_disk,
+           "fs-disk=s" => \$fs_disk,
+           "test=s" => \$test,
+           "help" => sub { usage (0) })
+    or die "option parsing failed; use --help for help\n";
+
+if (!defined ($test)) {
+    die "test name expected; use --help for help\n"
+       if @ARGV != 1;
+    $test = shift @ARGV;
+} elsif (@ARGV != 0) {
+    die "can't have non-option arg with --test\n";
+}
+
+$fs_disk = "$test.dsk" if !defined $fs_disk;
+
+if (! -e $os_disk) {
+    print STDERR "$os_disk: stat: $!\n";
+    print STDERR "perhaps you should `make' in ../../src/userprog?\n";
+    exit 1;
+}
+
+our ($formatted) = 0;
+
+unlink $fs_disk;
+xsystem ("$pintos make-disk '$fs_disk' 2");
+put_file ("$test");
+put_file ("sample.txt")
+    if grep ($_ eq $test,
+            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));               
+
+sub put_file {
+    my ($fn) = @_;
+    my ($cmd) = "$pintos -v --os-disk='$os_disk' --fs-disk='$fs_disk' put";
+    $cmd .= " -f", $formatted = 1 if !$formatted;
+    $cmd .= " '$fn'";
+    xsystem ($cmd);
+}
+
+sub xsystem {
+    my ($cmd) = @_;
+    print "$cmd\n";
+    system ($cmd) == 0 || die "command failed\n";
+}