-
- @output = fix_exit_codes (get_core_output (@output));
- my ($n) = 0;
- while (my ($m) = $output[0] =~ /^\(multi-oom\) begin (\d+)$/) {
- die "Child process $m started out of order.\n" if $m != $n;
- $n = $m + 1;
- shift @output;
- }
- die "Only $n child process(es) started.\n" if $n < 15;
-
- # There could be a death notice for a process that didn't get
- # fully loaded, and/or notices from the loader.
- while (@output > 0
- && ($output[0] =~ /^multi-oom: exit\(-1\)$/
- || $output[0] =~ /^load: /)) {
- shift @output;
- }
-
- while (--$n >= 0) {
- die "Output ended unexpectedly before process $n finished.\n"
- if @output < 2;
-
- local ($_);
- chomp ($_ = shift @output);
- die "Found '$_' expecting 'end' message.\n" if !/^\(multi-oom\) end/;
- die "Child process $n ended out of order.\n"
- if !/^\(multi-oom\) end $n$/;
-
- chomp ($_ = shift @output);
- die "Kernel didn't print proper exit message for process $n.\n"
- if !/^multi-oom: exit\($n\)$/;
- }
- die "Spurious output at end: '$output[0]'.\n" if @output;
-}
-
-sub get_file {
- my ($guest_fn, $host_fn) = @_;
- xsystem ("pintos "
- . "--os-disk=pintos/src/vm/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";
-}
-
-\f
-sub verify_common {
- my (@output) = @_;
-
- my (@assertion) = grep (/PANIC/, @output);
- if (@assertion != 0) {
- my ($details) = "Kernel panic:\n $assertion[0]\n";
-
- my (@stack_line) = grep (/Call stack:/, @output);
- if (@stack_line != 0) {
- $details .= " $stack_line[0]\n\n";
- $details .= "Translation of backtrace:\n";
- my (@addrs) = $stack_line[0] =~ /Call stack:((?: 0x[0-9a-f]+)+)/;
-
- my ($A2L);
- if (`uname -m`
- =~ /i.86|pentium.*|[pk][56]|nexgen|viac3|6x86|athlon.*/) {
- $A2L = "addr2line";
- } else {
- $A2L = "i386-elf-addr2line";
- }
- open (A2L, "$A2L -fe pintos/src/vm/build/kernel.o @addrs|");
- for (;;) {
- my ($function, $line);
- last unless defined ($function = <A2L>);
- $line = <A2L>;
- chomp $function;
- chomp $line;
- $details .= " $function ($line)\n";
- }
- }
-
- if ($assertion[0] =~ /sec_no < d->capacity/) {
- $details .= <<EOF;
-\nThis assertion commonly fails when accessing a file via
-an inode that has been closed and freed. Freeing an inode
-clears all its sector indexes to 0xcccccccc, which is not
-a valid sector number for disks smaller than about 1.6 TB.
-EOF
- }
-
- $extra{$test} = $details;
- die "Kernel panic. Details at end of file.\n"
- }
-
- if (grep (/Pintos booting/, @output) > 1) {
- my ($details);
-
- $details = "Pintos spontaneously rebooted during this test.\n";
- $details .= "This is most often due to unhandled page faults.\n";
- $details .= "Here's the output from the initial boot through the\n";
- $details .= "first reboot:\n\n";
-
- my ($i) = 0;
- local ($_);
- for (@output) {
- $details .= " $_\n";
- last if /Pintos booting/ && ++$i > 1;
- }
- $details{$test} = $details;
- die "Triple-fault caused spontaneous reboot(s). "
- . "Details at end of file.\n";
- }
-
- die "No output at all\n" if @output == 0;
- die "Didn't start up properly: no \"Pintos booting\" startup message\n"
- if !grep (/Pintos booting with.*kB RAM\.\.\./, @output);
- die "Didn't start up properly: no \"Boot complete\" startup message\n"
- if !grep (/Boot complete/, @output);
- die "Didn't shut down properly: no \"Timer: # ticks\" shutdown message\n"
- if !grep (/Timer: \d+ ticks/, @output);
- die "Didn't shut down properly: no \"Powering off\" shutdown message\n"
- if !grep (/Powering off/, @output);
-}
-
-# Get @output without header or trailer.
-sub get_core_output {
- my (@output) = @_;
-
- our ($test);
- my ($first);
- for ($first = 0; $first <= $#output; $first++) {
- $first++, last if $output[$first] =~ /^Executing '$test.*':$/;
- }
-
- my ($last);
- for ($last = $#output; $last >= 0; $last--) {
- $last--, last if $output[$last] =~ /^Timer: \d+ ticks$/;
- }
-
- if ($last < $first) {
- my ($no_first) = $first > $#output;
- my ($no_last) = $last < $#output;
- die "Couldn't locate output.\n";
- }
-
- return @output[$first ... $last];
-}
-
-sub fix_exit_codes {
- my (@output) = @_;
-
- # Remove lines that look like exit codes.
- # Exit codes are supposed to be printed in the form "process: exit(code)"
- # but people get unfortunately creative with it.
- for (my ($i) = 0; $i <= $#output; $i++) {
- local ($_) = $output[$i];
-
- my ($process, $code);
- if ((($process, $code) = /^([-a-z0-9 ]+):.*[ \(](-?\d+)\b\)?$/)
- || (($process, $code) = /^([-a-z0-9 ]+) exit\((-?\d+)\)$/)
- || (($process, $code)
- = /^([-a-z0-9 ]+) \(.*\): exit\((-?\d+)\)$/)
- || (($process, $code) = /^([-a-z0-9 ]+):\( (-?\d+) \) $/)
- || (($code, $process) = /^shell: exit\((-?\d+)\) \| ([-a-z0-9]+)/)
- ) {
- splice (@output, $i, 1);
- $i--;
- }
- }
-
- return @output;
-}
-
-sub compare_output {
- my ($exp, @actual) = @_;
- @actual = fix_exit_codes (get_core_output (map ("$_\n", @actual)));
- die "Program produced no output.\n" if !@actual;
-
- my ($details) = "";
- $details .= "$test actual output:\n";
- $details .= join ('', map (" $_", @actual));
-
- my (@exp) = map ("$_\n", snarf ($exp));
-
- my ($fuzzy_match) = 0;
- while (@exp != 0) {
- my (@expected);
- while (@exp != 0) {
- my ($s) = shift (@exp);
- last if $s eq "--OR--\n";
- push (@expected, $s);
- }
-
- $details .= "\n$test acceptable output:\n";
- $details .= join ('', map (" $_", @expected));
-
- # Check whether they're the same.
- if ($#actual == $#expected) {
- my ($eq) = 1;
- for (my ($i) = 0; $i <= $#expected; $i++) {
- $eq = 0 if $actual[$i] ne $expected[$i];
- }
- return if $eq;
- }
-
- # They differ. Output a diff.
- my (@diff) = "";
- my ($d) = Algorithm::Diff->new (\@expected, \@actual);
- my ($not_fuzzy_match) = 0;
- while ($d->Next ()) {
- my ($ef, $el, $af, $al) = $d->Get (qw (min1 max1 min2 max2));
- if ($d->Same ()) {
- push (@diff, map (" $_", $d->Items (1)));
- } else {
- push (@diff, map ("- $_", $d->Items (1))) if $d->Items (1);
- push (@diff, map ("+ $_", $d->Items (2))) if $d->Items (2);
- if ($d->Items (1)
- || grep (/\($test\)|exit\(-?\d+\)|dying due to|Page fault/,
- $d->Items (2))) {
- $not_fuzzy_match = 1;
- }
- }
- }
- $fuzzy_match = 1 if !$not_fuzzy_match;
-
- $details .= "Differences in `diff -u' format:\n";
- $details .= join ('', @diff);
- $details .= "(This is considered a `fuzzy match'.)\n"
- if !$not_fuzzy_match;
- }
-
- if ($fuzzy_match) {
- $details =
- "This test passed, but with extra, unexpected output.\n"
- . "Please inspect your code to make sure that it does not\n"
- . "produce output other than as specified in the project\n"
- . "description.\n\n"
- . "$details";
- } else {
- $details =
- "This test failed because its output did not match any\n"
- . "of the acceptable form(s).\n\n"
- . "$details";
- }
-
- $details{$test} = $details;
- die "Output differs from expected. Details at end of file.\n"
- unless $fuzzy_match;
-}
-\f
-sub write_grades {
- my (@summary) = snarf ("$GRADES_DIR/tests.txt");
-
- my ($ploss) = 0;
- my ($tloss) = 0;
- my ($total) = 0;
- my ($warnings) = 0;
- for (my ($i) = 0; $i <= $#summary; $i++) {
- local ($_) = $summary[$i];
- if (my ($loss, $test) = /^ -(\d+) ([-a-zA-Z0-9]+):/) {
- my ($result) = $result{$test} || "Not tested.";
-
- if ($result eq 'ok') {
- if (!defined $details{$test}) {
- # Test successful and no warnings.
- splice (@summary, $i, 1);
- $i--;
- } else {
- # Test successful with warnings.
- s/-(\d+) //;
- $summary[$i] = $_;
- splice (@summary, $i + 1, 0,
- " Test passed with warnings. "
- . "Details at end of file.");
- $warnings++;
- }
- } else {
- $ploss += $loss;
- $tloss += $loss;
- splice (@summary, $i + 1, 0,
- map (" $_", split ("\n", $result)));
- }
- } elsif (my ($ptotal) = /^Score: \/(\d+)$/) {
- $total += $ptotal;
- $summary[$i] = "Score: " . ($ptotal - $ploss) . "/$ptotal";
- splice (@summary, $i, 0, " All tests passed.")
- if $ploss == 0 && !$warnings;
- $ploss = 0;
- $warnings = 0;
- $i++;
- }
- }
- my ($ts) = "(" . ($total - $tloss) . "/" . $total . ")";
- $summary[0] =~ s/\[\[total\]\]/$ts/;
-
- open (SUMMARY, ">tests.out");
- print SUMMARY map ("$_\n", @summary);
- close (SUMMARY);
-}
-
-sub write_details {
- open (DETAILS, ">details.out");
- my ($n) = 0;
- for my $test (@TESTS) {
- next if $result{$test} eq 'ok' && !defined $details{$test};
-
- my ($details) = $details{$test};
- next if !defined ($details) && ! -e "output/$test/run.out";
-
- my ($banner);
- if ($result{$test} ne 'ok') {
- $banner = "$test failure details";
- } else {
- $banner = "$test warnings";
- }
-
- print DETAILS "\n" if $n++;
- print DETAILS "--- $banner ", '-' x (50 - length ($banner));
- print DETAILS "\n\n";
-
- if (!defined $details) {
- my (@output) = snarf ("output/$test/run.out");
-
- # Print only the first in a series of recursing panics.
- my ($panic) = 0;
- for my $i (0...$#output) {
- local ($_) = $output[$i];
- if (/PANIC/ && $panic++ > 0) {
- @output = @output[0...$i];
- push (@output,
- "[...details of recursive panic omitted...]");
- last;
- }
- }
- $details = "Output:\n\n" . join ('', map ("$_\n", @output));
- }
- print DETAILS $details;
-
- print DETAILS "\n", "-" x 10, "\n\n$extra{$test}"
- if defined $extra{$test};
- }
- close (DETAILS);
-
-}
-\f
-sub xsystem {
- my ($command, %options) = @_;
- print "$command\n" if $VERBOSE || $options{VERBOSE};
-
- my ($log) = $options{LOG};
-
- my ($pid, $status);
- eval {
- local $SIG{ALRM} = sub { die "alarm\n" };
- alarm $options{TIMEOUT} if defined $options{TIMEOUT};
- $pid = fork;
- die "fork: $!\n" if !defined $pid;
- if (!$pid) {
- if (defined $log) {
- open (STDOUT, ">output/$log.out");
- open (STDERR, ">output/$log.err");
- }
- exec ($command);
- exit (-1);
- }
- waitpid ($pid, 0);
- $status = $?;
- alarm 0;
- };
-
- my ($ok);
- if ($@) {
- die unless $@ eq "alarm\n"; # propagate unexpected errors
- print "Timed out: ";
- for (my ($i) = 0; $i < 10; $i++) {
- kill ('SIGTERM', $pid);
- sleep (1);
- my ($retval) = waitpid ($pid, WNOHANG);
- last if $retval == $pid || $retval == -1;
- print "Waiting for $pid to die" if $i == 0;
- print ".";
- }
- $ok = 1;
- } else {
- if (WIFSIGNALED ($status)) {
- my ($signal) = WTERMSIG ($status);
- die "Interrupted\n" if $signal == SIGINT;
- print "Child terminated with signal $signal\n";
- }
-
- my ($exp_status) = !defined ($options{EXPECT}) ? 0 : $options{EXPECT};
- $ok = WIFEXITED ($status) && WEXITSTATUS ($status) == $exp_status;
- }
-
- unlink ("output/$log.err") if defined ($log) && $ok;
-
- die $options{DIE} if !$ok && defined $options{DIE};
-
- return $ok;
-}
-
-sub snarf {
- my ($file) = @_;
- open (OUTPUT, $file) or die "$file: open: $!\n";
- my (@lines) = <OUTPUT>;
- chomp (@lines);
- close (OUTPUT);
- return wantarray ? @lines : join ('', map ("$_\n", @lines));