]> The Tcpdump Group git mirrors - tcpdump/commitdiff
do better recording of when stderr has content in it
authorMichael Richardson <[email protected]>
Sun, 18 Aug 2019 21:09:57 +0000 (17:09 -0400)
committerMichael Richardson <[email protected]>
Sun, 18 Aug 2019 22:04:09 +0000 (18:04 -0400)
tests/TESTonce

index a52b7f7b75a160115bd00206cae41fefea60a12d..7bd09b9e2b66ee6037435271e1f16264bfebac2a 100755 (executable)
@@ -22,6 +22,9 @@ my $r;
 $outputbase = basename($output);
 my $coredump = false;
 my $status = 0;
+my $linecount = 0;
+my $stderrlog = "NEW/${outputbase}.stderr";
+my $diffstat = 0;
 
 if ($^O eq 'MSWin32') {
     $r = system "..\\windump -# -n -r $input $options 2>NUL | sed 's/\\r//' | tee NEW/$outputbase | diff $output - >DIFF/$outputbase.diff";
@@ -30,10 +33,14 @@ if ($^O eq 'MSWin32') {
 else {
     # we used to do this as a nice pipeline, but the problem is that $r fails to
     # to be set properly if the tcpdump core dumps.
-    $r = system "$TCPDUMP 2>NEW/$outputbase.stderr -# -n -r $input $options >NEW/$outputbase";
+    $r = system "$TCPDUMP 2>${stderrlog} -# -n -r $input $options >NEW/${outputbase}";
+    if($r == -1) {
+        # failed to start due to error.
+        $status = $!;
+    }
     if($r != 0) {
-        my $coredump = false;
-        my $status = 0;
+        $coredump = false;
+        $status = 0;
         # this means tcpdump failed.
         open(OUTPUT, ">>"."NEW/$outputbase") || die "fail to open $outputbase\n";
         if( $r & 128 ) {
@@ -49,16 +56,35 @@ else {
     }
     if($r == 0) {
         $r = system "cat NEW/$outputbase | diff $output - >DIFF/$outputbase.diff";
+        $diffstat = WEXITSTATUS($r);
     }
+    if($r == 0) {
+        $linecount = 0;
+        open(ERROROUT, "<" . $stderrlog);
+        while(<ERROROUT>) {
+            next if /^$/;  # blank lines are boring
+            next if /^reading from file/;  # stock output boring too
+            $linecount++;
+        }
+        if($linecount == 0) {
+            unlink($stderrlog);
+        }
+    }
+
     #print sprintf("END: %08x\n", $r);
 }
 
 if($r == 0) {
-  printf "    %-35s: passed\n", $name;
-  unlink "DIFF/$outputbase.diff";
-  exit 0;
+    my $stderrlog="";
+    if($linecount > 0) {
+        $stderrlog=sprintf("%d lines in stderr", $linecount);
+    }
+    printf "    %-35s: passed%s\n", $name, $stderrlog;
+    unlink "DIFF/$outputbase.diff";
+    exit 0;
 }
-printf "    %-35s: TEST FAILED(%s)", $name, $r == -1 ? $! : "exit core=$coredump/stat=$status";
+# must have failed!
+printf "    %-35s: TEST FAILED(exit core=%d/diffstat=%d/r=%d)", $name, $coredump, $diffstat, $r;
 open FOUT, '>>failure-outputs.txt';
 printf FOUT "\nFailed test: $name\n\n";
 close FOUT;