]> rtime.felk.cvut.cz Git - wvtest.git/blobdiff - wvtestrunner.pl
Added a Makefile to dotnet as an example of how to run tests.
[wvtest.git] / wvtestrunner.pl
index 9eace827ed74209d15a6caee7446c6554cb48e9d..cc5cdd9c1a6d87a2d1b75c684f6a04eeee606fbf 100755 (executable)
@@ -1,5 +1,6 @@
 #!/usr/bin/perl -w
 use strict;
+use Time::HiRes qw(time);
 
 # always flush
 $| = 1;
@@ -32,7 +33,7 @@ sub bigkill($)
        print "\n" . join("\n", @log) . "\n";
     }
     
-    print STDERR "Killed by signal.\n";
+    print STDERR "\n! Killed by signal    FAILED\n";
 
     ($pid > 0) || die("pid is '$pid'?!\n");
 
@@ -50,7 +51,11 @@ sub bigkill($)
 
 # parent
 local $SIG{INT} = sub { bigkill($pid); };
-local $SIG{TERM} = sub { bikill($pid); };
+local $SIG{TERM} = sub { bigkill($pid); };
+local $SIG{ALRM} = sub { 
+    print STDERR "Alarm timed out!  No test results for too long.\n";
+    bigkill($pid);
+};
 
 sub colourize($)
 {
@@ -65,39 +70,65 @@ sub colourize($)
     }
 }
 
+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>)
 {
     chomp;
+    s/\r//g;
     
     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*$/)
     {
+        alarm(120);
+    
        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);
        
@@ -118,9 +149,7 @@ while (<$fh>)
     }
 }
 
-if ($insection) {
-    printf " %s\n", colourize("ok");
-}
+endsect();
 
 my $newpid = waitpid($pid, 0);
 if ($newpid != $pid) {
@@ -130,14 +159,22 @@ 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) );