]>
The Tcpdump Group git mirrors - tcpdump/blob - tests/TESTonce
3 $TCPDUMP = "./tcpdump";
4 if ($^O
eq 'MSWin32') {
7 if($ENV{TCPDUMP_BIN
}) {
8 $TCPDUMP = $ENV{TCPDUMP_BIN
};
12 use POSIX
qw( WEXITSTATUS WIFEXITED);
14 system("mkdir -p tests/NEW tests/DIFF");
17 print "Usage: TESTonce name input output options\n";
27 my $debug = 0; # change to suit.
29 $outputbase = basename
($output);
33 my $rawstderrlog = "tests/NEW/${outputbase}.raw.stderr";
34 my $stderrlog = "tests/NEW/${outputbase}.stderr";
39 if ($^O
eq 'MSWin32') {
40 $r = system ".\\${TCPDUMP} -t -n -r $input $options 2>NUL | sed 's/\\r//' | tee tests/NEW/${outputbase} | diff $output - >tests/DIFF/${outputbase}.diff";
41 # need to do same as below for Cygwin.
44 # we used to do this as a nice pipeline, but the problem is that $r fails to
45 # to be set properly if the tcpdump core dumps.
46 $cmd = "$TCPDUMP 2>${rawstderrlog} -t -n -r $input $options >tests/NEW/${outputbase}";
47 print "CMD: $cmd\n" if $debug;
50 # failed to start due to error.
56 # this means tcpdump failed, which however, might be expected.
57 open(OUTPUT
, ">>"."tests/NEW/${outputbase}") || die "fail to open ${outputbase}\n";
62 $status = WEXITSTATUS
($r);
65 if($coredump || $status) {
66 printf OUTPUT
"\nEXIT CODE %08x: dump:%d code: %d\n", $r, $coredump, $status;
68 printf OUTPUT
"\nEXIT CODE %08x\n", $r;
71 $r = 0; # clear the error so that the diff will occur.
73 print "RUNNING DIFF after ${r}\n" if $debug;
76 $cmd = "cat tests/NEW/${outputbase} | diff $output - >tests/DIFF/${outputbase}.diff";
77 print "RUNNING: $cmd\n" if $debug;
80 $diffstat = WEXITSTATUS
($r);
85 # process the file, sanitize "reading from" line, and count lines
87 open(ERRORRAW
, "<" . $rawstderrlog);
88 open(ERROROUT
, ">" . $stderrlog);
90 next if /^\s*$/; # blank lines are boring
91 if(/^(reading from file )(.*)(,.*)$/) {
92 my $filename = basename
($2);
93 print ERROROUT
"${1}${filename}${3}\n";
102 if ( -f
"$output.stderr" ) {
103 $nr = system "cat $stderrlog | diff $output.stderr - >tests/DIFF/$outputbase.stderr.diff";
107 $errdiffstat = WEXITSTATUS
($nr);
113 if($linecount == 0 && $status == 0) {
114 print "UNLINK: ${stderrlog}\n" if $debug;
115 unlink($stderrlog) unless $debug;
121 print sprintf("END: %08x\n", $r) if $debug;
126 if($linecount > 0 && $errdiffstat != "-") {
127 $stderrlog=sprintf("-- %d lines extra in stderr", $linecount);
129 if(!defined($ENV{"SKIPPASSED"})) {
130 printf " %-35s: passed%s\n", $name, $stderrlog;
132 unlink "tests/DIFF/$outputbase.diff" unless $debug;
136 printf " %-35s: TEST FAILED(exit core=%d/diffstat=%d,%d/r=%d)", $name, $coredump, $diffstat, $errdiffstat, $r;
137 open FOUT
, '>>tests/failure-outputs.txt';
138 printf FOUT
"\nFailed test: $name\n\n";
140 if(-f
"tests/DIFF/$outputbase.diff") {
141 system "cat tests/DIFF/$outputbase.diff >> tests/failure-outputs.txt";
145 print " (failed to execute: $!)\n";
149 # this is not working right, $r == 0x8b00 when there is a core dump.
150 # clearly, we need some platform specific perl magic to take this apart, so look for "core"
152 # In particular, on Solaris 10 SPARC an alignment problem results in SIGILL,
153 # a core dump and $r set to 0x00008a00 ($? == 138 in the shell).
154 if($r & 127 || -f
"core") {
155 my $with = ($r & 128) ?
'with' : 'without';
159 printf " (terminated with signal %u, %s coredump)\n", ($r & 127), $with;
160 exit ($r & 128) ?
10 : 20;