#!/usr/bin/perl -w
use strict;
+use Time::HiRes qw(time);
# always flush
$| = 1;
}
}
+sub mstime($$$)
+{
+ my ($floatsec, $warntime, $badtime) = @_;
+ my $ms = int($floatsec * 1000);
+ my $str = sprintf("%d.%03ds", $ms/1000, $ms % 1000);
+
+ if ($istty && $ms > $badtime) {
+ return "\e[31;1m$str\e[0m";
+ } elsif ($istty && $ms > $warntime) {
+ return "\e[33;1m$str\e[0m";
+ } else {
+ return "$str";
+ }
+}
+
sub resultline($$)
{
my ($name, $result) = @_;
return sprintf("! %-65s %s", $name, colourize($result));
}
-my $insection = 0;
+my $allstart = time();
+my ($start, $stop);
+
+sub endsect()
+{
+ $stop = time();
+ if ($start) {
+ printf " %s %s\n", mstime($stop - $start, 500, 1000), colourize("ok");
+ }
+}
while (<$fh>)
{
if (/^\s*Testing "(.*)" in (.*):\s*$/)
{
alarm(120);
-
my ($sect, $file) = ($1, $2);
- if ($insection) {
- printf " %s\n", colourize("ok");
- }
+ endsect();
printf("! %s %s: ", $file, $sect);
@log = ();
- $insection = 1;
+ $start = $stop;
}
elsif (/^!\s*(.*?)\s+(\S+)\s*$/)
{
my ($name, $result) = ($1, $2);
my $pass = ($result eq "ok");
- if (!$insection) {
+ if (!$start) {
printf("\n! Startup: ");
+ $start = time();
}
- $insection++;
push @log, resultline($name, $result);
}
}
-if ($insection) {
- printf " %s\n", colourize("ok");
-}
+endsect();
my $newpid = waitpid($pid, 0);
if ($newpid != $pid) {
my $code = $?;
my $ret = ($code >> 8);
+# return death-from-signal exits as >128. This is what bash does if you ran
+# the program directly.
+if ($code && !$ret) { $ret = $code | 128; }
+
if ($ret && @log) {
print "\n" . join("\n", @log) . "\n";
}
+if ($code != 0) {
+ print resultline("Program returned non-zero exit code ($ret)", "FAILED");
+}
my $gtotal = $gpasses+$gfails;
-printf("\nWvTest: %d test%s, %d failure%s.\n",
+printf("\nWvTest: %d test%s, %d failure%s, total time %s.\n",
$gtotal, $gtotal==1 ? "" : "s",
- $gfails, $gfails==1 ? "" : "s");
+ $gfails, $gfails==1 ? "" : "s",
+ mstime(time() - $allstart, 2000, 5000));
print STDERR "\nWvTest result code: $ret\n";
exit( $ret ? $ret : ($gfails ? 125 : 0) );