- 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;
- }
-
-
- if (!$ok && defined $options{DIE}) {
- my ($msg) = $options{DIE};
- if (defined ($log)) {
- chomp ($msg);
- $msg .= "; see output/$log.err and output/$log.out for details\n";
- }
- die $msg;
- } elsif (defined ($log) && $ok) {
- unlink ("output/$log.err");
- }
-
- 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));
-}
-
-sub files_equal {
- my ($a, $b) = @_;
- my ($equal);
- open (A, "<$a") or die "$a: open: $!\n";
- open (B, "<$b") or die "$b: open: $!\n";
- if (-s A != -s B) {
- $equal = 0;
- } else {
- my ($sa, $sb);
- for (;;) {
- sysread (A, $sa, 1024);
- sysread (B, $sb, 1024);
- $equal = 0, last if $sa ne $sb;
- $equal = 1, last if $sa eq '';
- }
- }
- close (A);
- close (B);
- return $equal;
-}
-
-sub file_contains {
- my ($file, $expected) = @_;
- open (FILE, "<$file") or die "$file: open: $!\n";
- my ($actual);
- sysread (FILE, $actual, -s FILE);
- my ($equal) = $actual eq $expected;
- close (FILE);
- return $equal;
-}
-
-sub number_lines {
- my ($ln, $lines) = @_;
- my ($out);
- for my $line (@$lines) {
- chomp $line;
- $out .= sprintf "%4d %s\n", $ln++, $line;
- }
- return $out;