]>
The Tcpdump Group git mirrors - tcpdump/blob - tests/TESTrun
4 # Were we told where to find tcpdump?
6 if (!($TCPDUMP = $ENV{TCPDUMP_BIN
})) {
8 # No. Use the appropriate path.
10 if ($^O
eq 'MSWin32') {
12 # XXX - assume, for now, a Visual Studio debug build, so that
13 # tcpdump is in the Debug subdirectory.
15 $TCPDUMP = "Debug\\tcpdump"
17 $TCPDUMP = "./tcpdump"
22 use POSIX
qw( WEXITSTATUS WIFEXITED);
23 use Cwd
qw(abs_path getcwd);
24 use File
::Path
qw(mkpath); # mkpath works with ancient perl, as well as newer perl
26 use Data
::Dumper
; # for debugging.
28 # these are created in the directory where we are run, which might be
30 my $newdir = "tests/NEW";
31 my $diffdir= "tests/DIFF";
34 my $origdir = getcwd
();
35 my $srcdir = $ENV{'srcdir'} || ".";
38 # Force UTC, so time stamps are printed in a standard time zone, and
39 # tests don't have to be run in the time zone in which the output
45 # Get the tests directory from $0.
47 my $testsdir = dirname
($0);
50 # Convert it to an absolute path, so it works even after we do a cd.
52 $testsdir = abs_path
($testsdir);
53 print "Running tests from ${testsdir}\n";
55 unshift(@INC, $testsdir);
60 my $failureoutput=$origdir . "/tests/failure-outputs.txt";
62 # truncate the output file
63 open(FAILUREOUTPUT
, ">" . $failureoutput);
72 # XXX - just do this directly in Perl?
74 if ($^O
eq 'MSWin32') {
75 my $winpath = File
::Spec
->canonpath($path);
76 system "type $winpath";
83 local($name, $input, $output, $options) = @_;
86 $outputbase = basename
($output);
90 my $rawstderrlog = "tests/NEW/${outputbase}.raw.stderr";
91 my $stderrlog = "tests/NEW/${outputbase}.stderr";
95 if ($^O
eq 'MSWin32') {
96 $r = system "$TCPDUMP -# -n -r $input $options 2>NUL | sed 's/\\r//' | tee tests/NEW/$outputbase | diff $output - >tests/DIFF/$outputbase.diff";
97 # need to do same as below for Cygwin.
100 # we used to do this as a nice pipeline, but the problem is that $r fails to
101 # to be set properly if the tcpdump core dumps.
102 $r = system "$TCPDUMP 2>${rawstderrlog} -# -n -r $input $options >tests/NEW/${outputbase}";
104 # failed to start due to error.
110 # this means tcpdump failed.
111 open(OUTPUT
, ">>"."tests/NEW/$outputbase") || die "fail to open $outputbase\n";
113 $coredump = $r & 127;
116 $status = WEXITSTATUS
($r);
119 if($coredump || $status) {
120 printf OUTPUT
"EXIT CODE %08x: dump:%d code: %d\n", $r, $coredump, $status;
122 printf OUTPUT
"EXIT CODE %08x\n", $r;
129 # Compare tcpdump's output with what we think it should be.
130 # If tcpdump failed to produce output, we've produced our own
131 # "output" above, with the exit status.
133 if ($^O
eq 'MSWin32') {
134 my $winoutput = File
::Spec
->canonpath($output);
135 $r = system "fc/lb1000/t/1 $winoutput tests\\NEW\\$outputbase >tests\\DIFF\\$outputbase.diff";
137 $r = system "diff $output tests/NEW/$outputbase >tests/DIFF/$outputbase.diff";
139 $diffstat = WEXITSTATUS
($r);
142 # process the file, sanitize "reading from" line, and count lines
144 open(ERRORRAW
, "<" . $rawstderrlog);
145 open(ERROROUT
, ">" . $stderrlog);
147 next if /^$/; # blank lines are boring
148 if(/^(reading from file )(.*)(,.*)$/) {
149 my $filename = basename
($2);
150 print ERROROUT
"${1}${filename}${3}\n";
159 if ( -f
"$output.stderr" ) {
161 # Compare the standard error with what we think it should be.
163 if ($^O
eq 'MSWin32') {
164 my $canonstderrlog = File
::Spec
->canonpath($stderrlog);
165 $nr = system "fc/lb1000/t/1 $output.stderr $canonstderrlog >tests/DIFF/$outputbase.stderr.diff";
167 $nr = system "diff $output.stderr $stderrlog >tests/DIFF/$outputbase.stderr.diff";
172 $errdiffstat = WEXITSTATUS
($nr);
176 if($linecount == 0 && $status == 0) {
183 #print sprintf("END: %08x\n", $r);
187 if($linecount == 0) {
188 printf " %-40s: passed\n", $name;
190 printf " %-40s: passed with error messages:\n", $name;
191 showfile
($stderrlog);
193 unlink "tests/DIFF/$outputbase.diff";
197 printf " %-40s: TEST FAILED(exit core=%d/diffstat=%d,%d/r=%d)", $name, $coredump, $diffstat, $errdiffstat, $r;
198 open FOUT
, '>>tests/failure-outputs.txt';
199 printf FOUT
"\nFailed test: $name\n\n";
201 if(-f
"tests/DIFF/$outputbase.diff") {
203 # XXX - just do this directly in Perl?
205 if ($^O
eq 'MSWin32') {
206 system "type tests\\DIFF\\$outputbase.diff >> tests\\failure-outputs.txt";
208 system "cat tests/DIFF/$outputbase.diff >> tests/failure-outputs.txt";
213 print " (failed to execute: $!)\n";
217 # this is not working right, $r == 0x8b00 when there is a core dump.
218 # clearly, we need some platform specific perl magic to take this apart, so look for "core"
220 # In particular, on Solaris 10 SPARC an alignment problem results in SIGILL,
221 # a core dump and $r set to 0x00008a00 ($? == 138 in the shell).
222 if($r & 127 || -f
"core") {
223 my $with = ($r & 128) ?
'with' : 'without';
227 printf " (terminated with signal %u, %s coredump)", ($r & 127), $with;
228 if($linecount == 0) {
231 print " with error messages:\n";
232 showfile
($stderrlog);
234 return(($r & 128) ?
10 : 20);
236 if($linecount == 0) {
239 print " with error messages:\n";
240 showfile
($stderrlog);
246 if(defined($confighhash)) {
250 $main::confighhash
= {};
252 # this could be loaded once perhaps.
253 open(CONFIG_H
, "config.h") || die "Can not open config.h: $!\n";
256 if(/^\#define (.*) 1/) {
257 #print "Setting $1\n";
258 $main::confighhash
->{$1} = 1;
262 #print Dumper($main::confighhash);
264 # also run tcpdump --fp-type to get the type of floating-point
265 # arithmetic we're doing, setting a HAVE_{fptype} key based
266 # on the value it prints
267 open(FPTYPE_PIPE
, "$TCPDUMP --fp-type |") or die("piping tcpdump --fp-type failed\n");
268 my $fptype_val = <FPTYPE_PIPE
>;
271 if($fptype_val == "9877.895") {
272 $have_fptype = "HAVE_FPTYPE1";
274 $have_fptype = "HAVE_FPTYPE2";
276 $main::confighhash
->{$have_fptype} = 1;
278 return $main::confighhash
;
282 sub runOneComplexTest
{
283 local($testconfig) = @_;
285 my $output = $testconfig->{output
};
286 my $input = $testconfig->{input
};
287 my $name = $testconfig->{name
};
288 my $options= $testconfig->{args
};
292 my $configset = $testconfig->{config_set
};
293 my $configunset = $testconfig->{config_unset
};
294 my $ch = loadconfighash
();
297 if(defined($configset)) {
298 $foundit = ($ch->{$configset} == 1);
300 if(defined($configunset)) {
301 $unfoundit=($ch->{$configunset} != 1);
305 printf " %-40s: skipped (%s not set)\n", $name, $configset;
310 printf " %-40s: skipped (%s set)\n", $name, $configunset;
315 #print Dumper($testconfig);
317 # EXPAND any occurances of @TESTDIR@ to $testsdir
318 $options =~ s/\@TESTDIR\@/$testsdir/;
320 my $result = runtest
($name,
321 $testsdir . "/" . $input,
322 $testsdir . "/" . $output,
332 # *.tests files are PERL hash definitions. They should create an array of hashes
333 # one per test, and place it into the variable @testlist.
334 sub runComplexTests
{
335 my @files = glob( $testsdir . '/*.tests' );
336 foreach $file (@files) {
337 my @testlist = undef;
339 print "FILE: ${file}\n";
340 open(FILE
, "<".$file) || die "can not open $file: $!";
343 $definitions = <FILE
>;
346 #print "STUFF: ${definitions}\n";
348 if(defined($testlist)) {
350 #print Dumper($testlist);
351 foreach $test (@
$testlist) {
352 runOneComplexTest
($test);
355 warn "File: ${file} could not be loaded as PERL: $!";
364 open(TESTLIST
, "<" . "${testsdir}/TESTLIST") || die "no ${testsdir}/TESTFILE: $!\n";
370 ($name, $input, $output, @options) = split;
371 #print "processing ${only} vs ${name}\n";
372 next if(defined($only) && $only ne $name);
374 my $options = join(" ", @options);
375 #print "@{options} becomes ${options}\n";
377 my $hash = { name
=> $name,
382 runOneComplexTest
($hash);
386 if(scalar(@ARGV) == 0) {
390 runSimpleTests
($ARGV[0]);
393 # exit with number of failing tests.
394 print "------------------------------------------------\n";
395 printf("%4u tests failed\n",$failedcount);
396 printf("%4u tests passed\n",$passedcount);
398 showfile
(${failureoutput
});