summaryrefslogtreecommitdiff
path: root/tests/TESTonce
diff options
context:
space:
mode:
authorSeonah Moon <seonah1.moon@samsung.com>2019-10-07 11:05:26 +0900
committerSeonah Moon <seonah1.moon@samsung.com>2019-10-07 11:06:12 +0900
commitb0706e54b48af6c11783f55455842a292c4d9b17 (patch)
treee18f8e347693bf9a1297f5553716e84c9109246f /tests/TESTonce
parentd722eee76c51a65c5449806c6fdacf2ac4f95055 (diff)
parent9ceaf0d786e9465506271e8450248a57719e4eb1 (diff)
downloadtcpdump-b0706e54b48af6c11783f55455842a292c4d9b17.tar.gz
tcpdump-b0706e54b48af6c11783f55455842a292c4d9b17.tar.bz2
tcpdump-b0706e54b48af6c11783f55455842a292c4d9b17.zip
Change-Id: Ib2ce6fe0c63523943f1fe7d772010824fe2c0d41
Diffstat (limited to 'tests/TESTonce')
-rwxr-xr-xtests/TESTonce127
1 files changed, 110 insertions, 17 deletions
diff --git a/tests/TESTonce b/tests/TESTonce
index 7026624..425abaa 100755
--- a/tests/TESTonce
+++ b/tests/TESTonce
@@ -1,6 +1,17 @@
#!/usr/bin/env perl
-system("mkdir -p NEW DIFF");
+$TCPDUMP = "./tcpdump";
+if ($^O eq 'MSWin32') {
+ $TCPDUMP = "windump";
+}
+if($ENV{TCPDUMP_BIN}) {
+ $TCPDUMP = $ENV{TCPDUMP_BIN};
+}
+
+use File::Basename;
+use POSIX qw( WEXITSTATUS WIFEXITED);
+
+system("mkdir -p tests/NEW tests/DIFF");
if(@ARGV != 4) {
print "Usage: TESTonce name input output options\n";
@@ -13,39 +24,121 @@ $output=$ARGV[2];
$options=$ARGV[3];
my $r;
+my $debug = 0; # change to suit.
+
+$outputbase = basename($output);
+my $coredump = false;
+my $status = 0;
+my $linecount = 0;
+my $rawstderrlog = "tests/NEW/${outputbase}.raw.stderr";
+my $stderrlog = "tests/NEW/${outputbase}.stderr";
+my $diffstat = 0;
+my $errdiffstat = 0;
+my $cmd;
if ($^O eq 'MSWin32') {
- $r = system "..\\windump -n -t -r $input $options 2>NUL | sed 's/\\r//' | tee NEW/$output | diff $output - >DIFF/$output.diff";
+ $r = system ".\\${TCPDUMP} -t -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.
}
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>/dev/null -n -t -r $input $options >NEW/$output";
+ $cmd = "$TCPDUMP 2>${rawstderrlog} -t -n -r $input $options >tests/NEW/${outputbase}";
+ print "CMD: $cmd\n" if $debug;
+ $r = system $cmd;
+ if($r == -1) {
+ # failed to start due to error.
+ $status = $!;
+ }
if($r != 0) {
- # this means tcpdump failed.
- open(OUTPUT, ">>"."NEW/$output") || die "fail to open $output\n";
- printf OUTPUT "EXIT CODE %08x\n", $r;
+ $coredump = false;
+ $status = 0;
+ # this means tcpdump failed, which however, might be expected.
+ 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 "\nEXIT CODE %08x: dump:%d code: %d\n", $r, $coredump, $status;
+ } else {
+ printf OUTPUT "\nEXIT CODE %08x\n", $r;
+ }
close(OUTPUT);
- $r = 0;
+ $r = 0; # clear the error so that the diff will occur.
+ }
+ print "RUNNING DIFF after ${r}\n" if $debug;
+
+ # always run diff.
+ $cmd = "cat tests/NEW/${outputbase} | diff $output - >tests/DIFF/${outputbase}.diff";
+ print "RUNNING: $cmd\n" if $debug;
+ $r = system $cmd;
+ if(WIFEXITED($r)) {
+ $diffstat = WEXITSTATUS($r);
}
+
+ #system("/bin/sh");
+
+ # process the file, sanitize "reading from" line, and count lines
+ $linecount = 0;
+ open(ERRORRAW, "<" . $rawstderrlog);
+ open(ERROROUT, ">" . $stderrlog);
+ while(<ERRORRAW>) {
+ next if /^\s*$/; # 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" ) {
+ $nr = system "cat $stderrlog | diff $output.stderr - >tests/DIFF/$outputbase.stderr.diff";
+ if($r == 0) {
+ $r = $nr;
+ }
+ $errdiffstat = WEXITSTATUS($nr);
+ } else {
+ $errdiffstat = "-"
+ }
+
if($r == 0) {
- $r = system "cat NEW/$output | diff $output - >DIFF/$output.diff";
+ if($linecount == 0 && $status == 0) {
+ print "UNLINK: ${stderrlog}\n" if $debug;
+ unlink($stderrlog) unless $debug;
+ } else {
+ $errdiffstat = "+";
+ }
}
- #print sprintf("END: %08x\n", $r);
+
+ print sprintf("END: %08x\n", $r) if $debug;
}
if($r == 0) {
- printf " %-35s: passed\n", $name;
- unlink "DIFF/$output.diff";
- exit 0;
+ my $stderrlog="";
+ if($linecount > 0 && $errdiffstat != "-") {
+ $stderrlog=sprintf("-- %d lines extra in stderr", $linecount);
+ }
+ if(!defined($ENV{"SKIPPASSED"})) {
+ printf " %-35s: passed%s\n", $name, $stderrlog;
+ }
+ unlink "tests/DIFF/$outputbase.diff" unless $debug;
+ exit 0;
}
-printf " %-35s: TEST FAILED", $name;
-open FOUT, '>>failure-outputs.txt';
-printf FOUT "Failed test: $name\n\n";
+# must have failed!
+printf " %-35s: TEST FAILED(exit core=%d/diffstat=%d,%d/r=%d)", $name, $coredump, $diffstat, $errdiffstat, $r;
+open FOUT, '>>tests/failure-outputs.txt';
+printf FOUT "\nFailed test: $name\n\n";
close FOUT;
-if(-f "DIFF/$output.diff") {
- system "cat DIFF/$output.diff >> failure-outputs.txt";
+if(-f "tests/DIFF/$outputbase.diff") {
+ system "cat tests/DIFF/$outputbase.diff >> tests/failure-outputs.txt";
}
if($r == -1) {