4 # Copyright (C)2007-2009 Versabanq Innovations Inc. and contributors.
5 # Licensed under the GNU Library General Public License, version 2.
6 # See the included file named LICENSE for license information.
9 use Time::HiRes qw(time);
15 print STDERR "Usage: $0 <command line...>\n";
19 print STDERR "Testing \"all\" in @ARGV:\n";
21 my $pid = open(my $fh, "-|");
25 open STDERR, '>&STDOUT' or die("Can't dup stdout: $!\n");
27 exit 126; # just in case
30 my $istty = -t STDOUT;
32 my ($gpasses, $gfails) = (0,0);
39 print "\n" . join("\n", @log) . "\n";
42 print STDERR "\n! Killed by signal FAILED\n";
44 ($pid > 0) || die("pid is '$pid'?!\n");
46 local $SIG{CHLD} = sub { }; # this will wake us from sleep() faster
59 local $SIG{INT} = sub { bigkill($pid); };
60 local $SIG{TERM} = sub { bigkill($pid); };
61 local $SIG{ALRM} = sub {
62 print STDERR "Alarm timed out! No test results for too long.\n";
69 my $pass = ($result eq "ok");
72 my $colour = $pass ? "\e[32;1m" : "\e[31;1m";
73 return "$colour$result\e[0m";
81 my ($floatsec, $warntime, $badtime) = @_;
82 my $ms = int($floatsec * 1000);
83 my $str = sprintf("%d.%03ds", $ms/1000, $ms % 1000);
85 if ($istty && $ms > $badtime) {
86 return "\e[31;1m$str\e[0m";
87 } elsif ($istty && $ms > $warntime) {
88 return "\e[33;1m$str\e[0m";
96 my ($name, $result) = @_;
97 return sprintf("! %-65s %s", $name, colourize($result));
100 my $allstart = time();
107 printf " %s %s\n", mstime($stop - $start, 500, 1000), colourize("ok");
116 if (/^\s*Testing "(.*)" in (.*):\s*$/)
119 my ($sect, $file) = ($1, $2);
123 printf("! %s %s: ", $file, $sect);
127 elsif (/^!\s*(.*?)\s+(\S+)\s*$/)
131 my ($name, $result) = ($1, $2);
132 my $pass = ($result eq "ok");
135 printf("\n! Startup: ");
139 push @log, resultline($name, $result);
144 print "\n" . join("\n", @log) . "\n";
160 my $newpid = waitpid($pid, 0);
161 if ($newpid != $pid) {
162 die("waitpid returned '$newpid', expected '$pid'\n");
166 my $ret = ($code >> 8);
168 # return death-from-signal exits as >128. This is what bash does if you ran
169 # the program directly.
170 if ($code && !$ret) { $ret = $code | 128; }
173 print "\n" . join("\n", @log) . "\n";
177 print resultline("Program returned non-zero exit code ($ret)", "FAILED");
180 my $gtotal = $gpasses+$gfails;
181 printf("\nWvTest: %d test%s, %d failure%s, total time %s.\n",
182 $gtotal, $gtotal==1 ? "" : "s",
183 $gfails, $gfails==1 ? "" : "s",
184 mstime(time() - $allstart, 2000, 5000));
185 print STDERR "\nWvTest result code: $ret\n";
186 exit( $ret ? $ret : ($gfails ? 125 : 0) );