]> The Tcpdump Group git mirrors - tcpdump/commitdiff
TESTrun: use the same code paths on Windows and UN*X.
authorGuy Harris <[email protected]>
Sat, 13 Jun 2020 22:49:04 +0000 (15:49 -0700)
committerGuy Harris <[email protected]>
Sat, 13 Jun 2020 22:49:04 +0000 (15:49 -0700)
There's no need to treat Windows specially in that code path.

tests/TESTrun

index 5348797102b2dd433381c63711af683608ff2403..52443a772c5016aac3dca64dd1c6916abcc69e15 100755 (executable)
@@ -92,97 +92,91 @@ sub runtest {
     my $diffstat = 0;
     my $errdiffstat = 0;
 
-    if ($^O eq 'MSWin32') {
-        $r = system "$TCPDUMP -# -n -r $input $options 2>NUL | sed 's/\\r//' | tee tests/NEW/$outputbase | diff $output - >tests/DIFF/$outputbase.diff";
-        # need to do same as below for Cygwin.
+    # 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>${rawstderrlog} -# -n -r $input $options >tests/NEW/${outputbase}";
+    if($r == -1) {
+        # failed to start due to error.
+        $status = $!;
     }
-    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>${rawstderrlog} -# -n -r $input $options >tests/NEW/${outputbase}";
-        if($r == -1) {
-            # failed to start due to error.
-            $status = $!;
+    if($r != 0) {
+        $coredump = false;
+        $status = 0;
+        # this means tcpdump failed.
+        open(OUTPUT, ">>"."tests/NEW/$outputbase") || die "fail to open $outputbase\n";
+        if( $r & 128 ) {
+            $coredump = $r & 127;
+        }
+        if( WIFEXITED($r)) {
+            $status = WEXITSTATUS($r);
         }
-        if($r != 0) {
-            $coredump = false;
-            $status = 0;
-            # this means tcpdump failed.
-            open(OUTPUT, ">>"."tests/NEW/$outputbase") || die "fail to open $outputbase\n";
-            if( $r & 128 ) {
-                $coredump = $r & 127;
-            }
-            if( WIFEXITED($r)) {
-                $status = WEXITSTATUS($r);
-            }
 
-            if($coredump || $status) {
-                printf OUTPUT "EXIT CODE %08x: dump:%d code: %d\n", $r, $coredump, $status;
-            } else {
-                printf OUTPUT "EXIT CODE %08x\n", $r;
-            }
-            close(OUTPUT);
-            $r = 0;
+        if($coredump || $status) {
+            printf OUTPUT "EXIT CODE %08x: dump:%d code: %d\n", $r, $coredump, $status;
+        } else {
+            printf OUTPUT "EXIT CODE %08x\n", $r;
         }
-        if($r == 0) {
-            #
-            # Compare tcpdump's output with what we think it should be.
-            # If tcpdump failed to produce output, we've produced our own
-            # "output" above, with the exit status.
-            #
-            if ($^O eq 'MSWin32') {
-                my $winoutput = File::Spec->canonpath($output);
-                $r = system "fc/lb1000/t/1 $winoutput tests\\NEW\\$outputbase >tests\\DIFF\\$outputbase.diff";
-            } else {
-                $r = system "diff $output tests/NEW/$outputbase >tests/DIFF/$outputbase.diff";
-            }
-            $diffstat = WEXITSTATUS($r);
+        close(OUTPUT);
+        $r = 0;
+    }
+    if($r == 0) {
+        #
+        # Compare tcpdump's output with what we think it should be.
+        # If tcpdump failed to produce output, we've produced our own
+        # "output" above, with the exit status.
+        #
+        if ($^O eq 'MSWin32') {
+            my $winoutput = File::Spec->canonpath($output);
+            $r = system "fc/lb1000/t/1 $winoutput tests\\NEW\\$outputbase >tests\\DIFF\\$outputbase.diff";
+        } else {
+            $r = system "diff $output tests/NEW/$outputbase >tests/DIFF/$outputbase.diff";
         }
+        $diffstat = WEXITSTATUS($r);
+    }
 
-        # process the file, sanitize "reading from" line, and count lines
-        $linecount = 0;
-        open(ERRORRAW, "<" . $rawstderrlog);
-        open(ERROROUT, ">" . $stderrlog);
-        while(<ERRORRAW>) {
-            next if /^$/;  # blank lines are boring
-            if(/^(reading from file )(.*)(,.*)$/) {
-                my $filename = basename($2);
-                print ERROROUT "${1}${filename}${3}\n";
-                next;
-            }
-            print ERROROUT;
-            $linecount++;
-        }
-        close(ERROROUT);
-        close(ERRORRAW);
-
-        if ( -f "$output.stderr" ) {
-            #
-            # Compare the standard error with what we think it should be.
-            #
-            if ($^O eq 'MSWin32') {
-                my $canonstderrlog = File::Spec->canonpath($stderrlog);
-                $nr = system "fc/lb1000/t/1 $output.stderr $canonstderrlog >tests/DIFF/$outputbase.stderr.diff";
-            } else {
-                $nr = system "diff $output.stderr $stderrlog >tests/DIFF/$outputbase.stderr.diff";
-            }
-            if($r == 0) {
-                $r = $nr;
-            }
-            $errdiffstat = WEXITSTATUS($nr);
+    # process the file, sanitize "reading from" line, and count lines
+    $linecount = 0;
+    open(ERRORRAW, "<" . $rawstderrlog);
+    open(ERROROUT, ">" . $stderrlog);
+    while(<ERRORRAW>) {
+        next if /^$/;  # blank lines are boring
+        if(/^(reading from file )(.*)(,.*)$/) {
+            my $filename = basename($2);
+            print ERROROUT "${1}${filename}${3}\n";
+            next;
         }
+        print ERROROUT;
+        $linecount++;
+    }
+    close(ERROROUT);
+    close(ERRORRAW);
 
+    if ( -f "$output.stderr" ) {
+        #
+        # Compare the standard error with what we think it should be.
+        #
+        if ($^O eq 'MSWin32') {
+            my $canonstderrlog = File::Spec->canonpath($stderrlog);
+            $nr = system "fc/lb1000/t/1 $output.stderr $canonstderrlog >tests/DIFF/$outputbase.stderr.diff";
+        } else {
+            $nr = system "diff $output.stderr $stderrlog >tests/DIFF/$outputbase.stderr.diff";
+        }
         if($r == 0) {
-            if($linecount == 0 && $status == 0) {
-                unlink($stderrlog);
-            } else {
-                $errdiffstat = 1;
-            }
+            $r = $nr;
         }
+        $errdiffstat = WEXITSTATUS($nr);
+    }
 
-        #print sprintf("END: %08x\n", $r);
+    if($r == 0) {
+        if($linecount == 0 && $status == 0) {
+            unlink($stderrlog);
+        } else {
+            $errdiffstat = 1;
+        }
     }
 
+    #print sprintf("END: %08x\n", $r);
+
     if($r == 0) {
         if($linecount == 0) {
             printf "    %-40s: passed\n", $name;