]>
The Tcpdump Group git mirrors - tcpdump/blob - tests/TESTonce
3 $TCPDUMP = "../tcpdump" if (!($TCPDUMP = $ENV{TCPDUMP_BIN
}));
6 use POSIX
qw( WEXITSTATUS WIFEXITED);
8 system("mkdir -p NEW DIFF");
11 print "Usage: TESTonce name input output options\n";
22 $outputbase = basename
($output);
26 my $rawstderrlog = "NEW/${outputbase}.raw.stderr";
27 my $stderrlog = "NEW/${outputbase}.stderr";
31 if ($^O
eq 'MSWin32') {
32 $r = system "..\\windump -# -n -r $input $options 2>NUL | sed 's/\\r//' | tee NEW/$outputbase | diff $output - >DIFF/$outputbase.diff";
33 # need to do same as below for Cygwin.
36 # we used to do this as a nice pipeline, but the problem is that $r fails to
37 # to be set properly if the tcpdump core dumps.
38 $r = system "$TCPDUMP 2>${rawstderrlog} -# -n -r $input $options >NEW/${outputbase}";
40 # failed to start due to error.
46 # this means tcpdump failed.
47 open(OUTPUT
, ">>"."NEW/$outputbase") || die "fail to open $outputbase\n";
52 $status = WEXITSTATUS
($r);
55 if($coredump || $status) {
56 printf OUTPUT
"EXIT CODE %08x: dump:%d code: %d\n", $r, $coredump, $status;
58 printf OUTPUT
"EXIT CODE %08x\n", $r;
64 $r = system "cat NEW/$outputbase | diff $output - >DIFF/$outputbase.diff";
65 $diffstat = WEXITSTATUS
($r);
68 # process the file, sanitize "reading from" line, and count lines
70 open(ERRORRAW
, "<" . $rawstderrlog);
71 open(ERROROUT
, ">" . $stderrlog);
73 next if /^$/; # blank lines are boring
74 if(/^(reading from file )(.*)(,.*)$/) {
75 my $filename = basename
($2);
76 print ERROROUT
"${1}${filename}${3}\n";
85 if ( -f
"$output.stderr" ) {
86 $nr = system "cat $stderrlog | diff $output.stderr - >DIFF/$outputbase.stderr.diff";
90 $errdiffstat = WEXITSTATUS
($nr);
94 if($linecount == 0 && $status == 0) {
101 #print sprintf("END: %08x\n", $r);
107 $stderrlog=sprintf("-- %d lines extra in stderr", $linecount);
109 printf " %-35s: passed%s\n", $name, $stderrlog;
110 unlink "DIFF/$outputbase.diff";
114 printf " %-35s: TEST FAILED(exit core=%d/diffstat=%d,%d/r=%d)", $name, $coredump, $diffstat, $errdiffstat, $r;
115 open FOUT
, '>>failure-outputs.txt';
116 printf FOUT
"\nFailed test: $name\n\n";
118 if(-f
"DIFF/$outputbase.diff") {
119 system "cat DIFF/$outputbase.diff >> failure-outputs.txt";
123 print " (failed to execute: $!)\n";
127 # this is not working right, $r == 0x8b00 when there is a core dump.
128 # clearly, we need some platform specific perl magic to take this apart, so look for "core"
130 # In particular, on Solaris 10 SPARC an alignment problem results in SIGILL,
131 # a core dump and $r set to 0x00008a00 ($? == 138 in the shell).
132 if($r & 127 || -f
"core") {
133 my $with = ($r & 128) ?
'with' : 'without';
137 printf " (terminated with signal %u, %s coredump)\n", ($r & 127), $with;
138 exit ($r & 128) ?
10 : 20;