4 # Copyright (C) 2007-2009 Versabanq Innovations Inc. and contributors.
5 # Copyright (C) 2015 Rob Browning <rlb@defaultvalue.org>
6 # Licensed under the GNU Library General Public License, version 2.
7 # See the included file named LICENSE for license information.
11 use Time::HiRes qw(time);
14 my $istty = -t STDOUT;
20 print $fh "Usage: $0 run <command line...>\n";
34 print "\n" . join("\n", @log) . "\n";
37 print STDERR "\n! Killed by signal FAILED\n";
39 ($pid > 0) || die("pid is '$pid'?!\n");
41 local $SIG{CHLD} = sub { }; # this will wake us from sleep() faster
56 my $pass = ($result eq "ok");
59 my $colour = $pass ? "\e[32;1m" : "\e[31;1m";
60 return "$colour$result\e[0m";
68 my ($floatsec, $warntime, $badtime) = @_;
69 my $ms = int($floatsec * 1000);
70 my $str = sprintf("%d.%03ds", $ms/1000, $ms % 1000);
72 if ($istty && $ms > $badtime) {
73 return "\e[31;1m$str\e[0m";
74 } elsif ($istty && $ms > $warntime) {
75 return "\e[33;1m$str\e[0m";
83 my ($name, $result) = @_;
84 return sprintf("! %-65s %s", $name, colourize($result));
93 printf " %s %s\n", mstime($stop - $start, 500, 1000), colourize("ok");
99 usage_death() if (@ARGV < 1);
104 print STDERR "Testing \"all\" in @ARGV:\n";
106 $pid = open(my $fh, "-|");
110 open STDERR, '>&STDOUT' or die("Can't dup stdout: $!\n");
112 exit 126; # just in case
116 my $allstart = time();
117 local $SIG{INT} = sub { bigkill($pid); };
118 local $SIG{TERM} = sub { bigkill($pid); };
119 local $SIG{ALRM} = sub {
120 print STDERR "Alarm timed out! No test results for too long.\n";
124 my ($gpasses, $gfails) = (0,0);
130 if (/^\s*Testing "(.*)" in (.*):\s*$/)
133 my ($sect, $file) = ($1, $2);
137 printf("! %s %s: ", $file, $sect);
141 elsif (/^!\s*(.*?)\s+(\S+)\s*$/)
145 my ($name, $result) = ($1, $2);
146 my $pass = ($result eq "ok");
149 printf("\n! Startup: ");
153 push @log, resultline($name, $result);
158 print "\n" . join("\n", @log) . "\n";
174 my $newpid = waitpid($pid, 0);
175 if ($newpid != $pid) {
176 die("waitpid returned '$newpid', expected '$pid'\n");
180 my $ret = ($code >> 8);
182 # return death-from-signal exits as >128. This is what bash does if you ran
183 # the program directly.
184 if ($code && !$ret) { $ret = $code | 128; }
187 print "\n" . join("\n", @log) . "\n";
191 print resultline("Program returned non-zero exit code ($ret)", "FAILED");
194 my $gtotal = $gpasses+$gfails;
195 printf("\nWvTest: %d test%s, %d failure%s, total time %s.\n",
196 $gtotal, $gtotal==1 ? "" : "s",
197 $gfails, $gfails==1 ? "" : "s",
198 mstime(time() - $allstart, 2000, 5000));
199 print STDERR "\nWvTest result code: $ret\n";
200 exit( $ret ? $ret : ($gfails ? 125 : 0) );
203 usage_death() unless (@ARGV > 1);
204 my $action = $ARGV[0];
207 if ($action eq 'run') {