]>
The Tcpdump Group git mirrors - tcpdump/blob - tests/testfuncs.pm
3 # expects to be run from the top directory, with "tests" subdirectory.
6 local($name, $input, $output, $options) = @_;
9 $outputbase = basename
($output);
13 my $rawstderrlog = "tests/NEW/${outputbase}.raw.stderr";
14 my $stderrlog = "tests/NEW/${outputbase}.stderr";
18 if ($^O
eq 'MSWin32') {
19 $r = system "..\\windump -# -n -r $input $options 2>NUL | sed 's/\\r//' | tee tests/NEW/$outputbase | diff $output - >tests/DIFF/$outputbase.diff";
20 # need to do same as below for Cygwin.
23 # we used to do this as a nice pipeline, but the problem is that $r fails to
24 # to be set properly if the tcpdump core dumps.
25 $r = system "$TCPDUMP 2>${rawstderrlog} -# -n -r $input $options >tests/NEW/${outputbase}";
27 # failed to start due to error.
33 # this means tcpdump failed.
34 open(OUTPUT
, ">>"."tests/NEW/$outputbase") || die "fail to open $outputbase\n";
39 $status = WEXITSTATUS
($r);
42 if($coredump || $status) {
43 printf OUTPUT
"EXIT CODE %08x: dump:%d code: %d\n", $r, $coredump, $status;
45 printf OUTPUT
"EXIT CODE %08x\n", $r;
51 $r = system "cat tests/NEW/$outputbase | diff $output - >tests/DIFF/$outputbase.diff";
52 $diffstat = WEXITSTATUS
($r);
55 # process the file, sanitize "reading from" line, and count lines
57 open(ERRORRAW
, "<" . $rawstderrlog);
58 open(ERROROUT
, ">" . $stderrlog);
60 next if /^$/; # blank lines are boring
61 if(/^(reading from file )(.*)(,.*)$/) {
62 my $filename = basename
($2);
63 print ERROROUT
"${1}${filename}${3}\n";
72 if ( -f
"$output.stderr" ) {
73 $nr = system "cat $stderrlog | diff $output.stderr - >tests/DIFF/$outputbase.stderr.diff";
77 $errdiffstat = WEXITSTATUS
($nr);
81 if($linecount == 0 && $status == 0) {
88 #print sprintf("END: %08x\n", $r);
93 printf " %-40s: passed\n", $name;
95 printf " %-40s: passed with error messages:\n", $name;
96 system "cat $stderrlog";
98 unlink "tests/DIFF/$outputbase.diff";
102 printf " %-40s: TEST FAILED(exit core=%d/diffstat=%d,%d/r=%d)", $name, $coredump, $diffstat, $errdiffstat, $r;
103 open FOUT
, '>>tests/failure-outputs.txt';
104 printf FOUT
"\nFailed test: $name\n\n";
106 if(-f
"tests/DIFF/$outputbase.diff") {
107 system "cat tests/DIFF/$outputbase.diff >> tests/failure-outputs.txt";
111 print " (failed to execute: $!)\n";
115 # this is not working right, $r == 0x8b00 when there is a core dump.
116 # clearly, we need some platform specific perl magic to take this apart, so look for "core"
118 # In particular, on Solaris 10 SPARC an alignment problem results in SIGILL,
119 # a core dump and $r set to 0x00008a00 ($? == 138 in the shell).
120 if($r & 127 || -f
"core") {
121 my $with = ($r & 128) ?
'with' : 'without';
125 printf " (terminated with signal %u, %s coredump)", ($r & 127), $with;
126 if($linecount == 0) {
129 print " with error messages:\n";
130 system "cat $stderrlog";
132 return(($r & 128) ?
10 : 20);
134 if($linecount == 0) {
137 print " with error messages:\n";
138 system "cat $stderrlog";