3 use Time::HiRes qw(time);
9 print STDERR "Usage: $0 <command line...>\n";
13 print STDERR "Testing \"all\" in @ARGV:\n";
15 my $pid = open(my $fh, "-|");
19 open STDERR, '>&STDOUT' or die("Can't dup stdout: $!\n");
21 exit 126; # just in case
24 my $istty = -t STDOUT;
26 my ($gpasses, $gfails) = (0,0);
33 print "\n" . join("\n", @log) . "\n";
36 print STDERR "\n! Killed by signal FAILED\n";
38 ($pid > 0) || die("pid is '$pid'?!\n");
40 local $SIG{CHLD} = sub { }; # this will wake us from sleep() faster
53 local $SIG{INT} = sub { bigkill($pid); };
54 local $SIG{TERM} = sub { bigkill($pid); };
55 local $SIG{ALRM} = sub {
56 print STDERR "Alarm timed out! No test results for too long.\n";
63 my $pass = ($result eq "ok");
66 my $colour = $pass ? "\e[32;1m" : "\e[31;1m";
67 return "$colour$result\e[0m";
75 my ($floatsec, $warntime, $badtime) = @_;
76 my $ms = int($floatsec * 1000);
77 my $str = sprintf("%d.%03ds", $ms/1000, $ms % 1000);
79 if ($istty && $ms > $badtime) {
80 return "\e[31;1m$str\e[0m";
81 } elsif ($istty && $ms > $warntime) {
82 return "\e[33;1m$str\e[0m";
90 my ($name, $result) = @_;
91 return sprintf("! %-65s %s", $name, colourize($result));
94 my $allstart = time();
101 printf " %s %s\n", mstime($stop - $start, 500, 1000), colourize("ok");
110 if (/^\s*Testing "(.*)" in (.*):\s*$/)
113 my ($sect, $file) = ($1, $2);
117 printf("! %s %s: ", $file, $sect);
121 elsif (/^!\s*(.*?)\s+(\S+)\s*$/)
125 my ($name, $result) = ($1, $2);
126 my $pass = ($result eq "ok");
129 printf("\n! Startup: ");
133 push @log, resultline($name, $result);
138 print "\n" . join("\n", @log) . "\n";
154 my $newpid = waitpid($pid, 0);
155 if ($newpid != $pid) {
156 die("waitpid returned '$newpid', expected '$pid'\n");
160 my $ret = ($code >> 8);
162 # return death-from-signal exits as >128. This is what bash does if you ran
163 # the program directly.
164 if ($code && !$ret) { $ret = $code | 128; }
167 print "\n" . join("\n", @log) . "\n";
171 print resultline("Program returned non-zero exit code ($ret)", "FAILED");
174 my $gtotal = $gpasses+$gfails;
175 printf("\nWvTest: %d test%s, %d failure%s, total time %s.\n",
176 $gtotal, $gtotal==1 ? "" : "s",
177 $gfails, $gfails==1 ? "" : "s",
178 mstime(time() - $allstart, 2000, 5000));
179 print STDERR "\nWvTest result code: $ret\n";
180 exit( $ret ? $ret : ($gfails ? 125 : 0) );