When running a "test" or "assemble" target, run-tests now returns zero
[pintos-anon] / grading / lib / Pintos / Grading.pm
index d48b2751c92219f4a1b55f3771d0e2a9cc657cd0..7e5ec67fb008f7fc5ad06353b1f2c9ae574eb98f 100644 (file)
@@ -16,6 +16,11 @@ use POSIX;
 use Getopt::Long qw(:config no_ignore_case);
 use Algorithm::Diff;
 \f
+# We execute lots of subprocesses.
+# Without this, our stdout output can get flushed multiple times,
+# which is harmless but looks bizarre.
+$| = 1;
+
 sub parse_cmd_line {
     my ($do_regex, $no_regex);
     GetOptions ("v|verbose+" => \$verbose,
@@ -408,7 +413,9 @@ sub run_pintos {
 # Grade the test.
 sub grade_test {
     # Read test output.
-    my (@output) = snarf ("output/$test/run.out");
+    my ($outfile) = "output/$test/run.out";
+    die "$outfile: missing test output file (make failed?)" if ! -e $outfile;
+    my (@output) = snarf ($outfile);
 
     # If there's a function "grade_$test", use it to evaluate the output.
     # If there's a file "$GRADES_DIR/$test.exp", compare its contents
@@ -825,5 +832,12 @@ sub file_contains {
     close (FILE);
     return $equal;
 }
+\f
+sub success {
+    for my $test (@TESTS) {
+       return 1 if !defined ($result{$test}) || $result{$test} ne 'ok';
+    }
+    return 0;
+}
 
 1;