]>
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 # we used to do this as a nice pipeline, but the problem is that $r fails to
96 # to be set properly if the tcpdump core dumps.
98 # Furthermore, on Windows, fc can't read the standard input, so we
99 # can't do it as a pipeline in any case.
100 $r = system "$TCPDUMP -# -n -r $input $options >tests/NEW/${outputbase} 2>${rawstderrlog}";
102 # failed to start due to error.
109 # Something other than "tcpdump opened the file, read it, and
110 # dissected all the packets". What happened?
112 # We write out an exit status after whatever the subprocess
113 # wrote out, so it shows up when we diff the expected output
116 open(OUTPUT
, ">>"."tests/NEW/$outputbase") || die "fail to open $outputbase\n";
118 $coredump = $r & 127;
121 $status = WEXITSTATUS
($r);
124 if($coredump || $status) {
125 printf OUTPUT
"EXIT CODE %08x: dump:%d code: %d\n", $r, $coredump, $status;
127 printf OUTPUT
"EXIT CODE %08x\n", $r;
134 # Compare tcpdump's output with what we think it should be.
135 # If tcpdump failed to produce output, we've produced our own
136 # "output" above, with the exit status.
138 if ($^O
eq 'MSWin32') {
139 my $winoutput = File
::Spec
->canonpath($output);
140 $r = system "fc /lb1000 /t /1 $winoutput tests\\NEW\\$outputbase >tests\\DIFF\\$outputbase.diff";
142 $r = system "diff $output tests/NEW/$outputbase >tests/DIFF/$outputbase.diff";
144 $diffstat = WEXITSTATUS
($r);
147 # process the standard error file, sanitize "reading from" line,
150 open(ERRORRAW
, "<" . $rawstderrlog);
151 open(ERROROUT
, ">" . $stderrlog);
153 next if /^$/; # blank lines are boring
154 if(/^(reading from file )(.*)(,.*)$/) {
155 my $filename = basename
($2);
156 print ERROROUT
"${1}${filename}${3}\n";
165 if ( -f
"$output.stderr" ) {
167 # Compare the standard error with what we think it should be.
169 if ($^O
eq 'MSWin32') {
170 my $winoutput = File
::Spec
->canonpath($output);
171 my $canonstderrlog = File
::Spec
->canonpath($stderrlog);
172 $nr = system "fc /lb1000 /t /1 $winoutput.stderr $canonstderrlog >tests\DIFF\$outputbase.stderr.diff";
174 $nr = system "diff $output.stderr $stderrlog >tests/DIFF/$outputbase.stderr.diff";
179 $errdiffstat = WEXITSTATUS
($nr);
183 if($linecount == 0 && $status == 0) {
190 #print sprintf("END: %08x\n", $r);
193 if($linecount == 0) {
194 printf " %-40s: passed\n", $name;
196 printf " %-40s: passed with error messages:\n", $name;
197 showfile
($stderrlog);
199 unlink "tests/DIFF/$outputbase.diff";
203 printf " %-40s: TEST FAILED(exit core=%d/diffstat=%d,%d/r=%d)", $name, $coredump, $diffstat, $errdiffstat, $r;
204 open FOUT
, '>>tests/failure-outputs.txt';
205 printf FOUT
"\nFailed test: $name\n\n";
207 if(-f
"tests/DIFF/$outputbase.diff") {
209 # XXX - just do this directly in Perl?
211 if ($^O
eq 'MSWin32') {
212 system "type tests\\DIFF\\$outputbase.diff >> tests\\failure-outputs.txt";
214 system "cat tests/DIFF/$outputbase.diff >> tests/failure-outputs.txt";
219 print " (failed to execute: $!)\n";
223 # this is not working right, $r == 0x8b00 when there is a core dump.
224 # clearly, we need some platform specific perl magic to take this apart, so look for "core"
226 # In particular, on Solaris 10 SPARC an alignment problem results in SIGILL,
227 # a core dump and $r set to 0x00008a00 ($? == 138 in the shell).
228 if($r & 127 || -f
"core") {
229 my $with = ($r & 128) ?
'with' : 'without';
233 printf " (terminated with signal %u, %s coredump)", ($r & 127), $with;
234 if($linecount == 0) {
237 print " with error messages:\n";
238 showfile
($stderrlog);
240 return(($r & 128) ?
10 : 20);
242 if($linecount == 0) {
245 print " with error messages:\n";
246 showfile
($stderrlog);
252 if(defined($confighhash)) {
256 $main::confighhash
= {};
258 # this could be loaded once perhaps.
259 open(CONFIG_H
, "config.h") || die "Can not open config.h: $!\n";
262 if(/^\#define (.*) 1/) {
263 #print "Setting $1\n";
264 $main::confighhash
->{$1} = 1;
268 #print Dumper($main::confighhash);
270 # also run tcpdump --fp-type to get the type of floating-point
271 # arithmetic we're doing, setting a HAVE_{fptype} key based
272 # on the value it prints
273 open(FPTYPE_PIPE
, "$TCPDUMP --fp-type |") or die("piping tcpdump --fp-type failed\n");
274 my $fptype_val = <FPTYPE_PIPE
>;
277 if($fptype_val == "9877.895") {
278 $have_fptype = "HAVE_FPTYPE1";
280 $have_fptype = "HAVE_FPTYPE2";
282 $main::confighhash
->{$have_fptype} = 1;
284 return $main::confighhash
;
288 sub runOneComplexTest
{
289 local($testconfig) = @_;
291 my $output = $testconfig->{output
};
292 my $input = $testconfig->{input
};
293 my $name = $testconfig->{name
};
294 my $options= $testconfig->{args
};
298 my $configset = $testconfig->{config_set
};
299 my $configunset = $testconfig->{config_unset
};
300 my $ch = loadconfighash
();
303 if(defined($configset)) {
304 $foundit = ($ch->{$configset} == 1);
306 if(defined($configunset)) {
307 $unfoundit=($ch->{$configunset} != 1);
311 printf " %-40s: skipped (%s not set)\n", $name, $configset;
316 printf " %-40s: skipped (%s set)\n", $name, $configunset;
321 #print Dumper($testconfig);
323 # EXPAND any occurances of @TESTDIR@ to $testsdir
324 $options =~ s/\@TESTDIR\@/$testsdir/;
326 my $result = runtest
($name,
327 $testsdir . "/" . $input,
328 $testsdir . "/" . $output,
338 # *.tests files are PERL hash definitions. They should create an array of hashes
339 # one per test, and place it into the variable @testlist.
340 sub runComplexTests
{
341 my @files = glob( $testsdir . '/*.tests' );
342 foreach $file (@files) {
343 my @testlist = undef;
345 print "FILE: ${file}\n";
346 open(FILE
, "<".$file) || die "can not open $file: $!";
349 $definitions = <FILE
>;
352 #print "STUFF: ${definitions}\n";
354 if(defined($testlist)) {
356 #print Dumper($testlist);
357 foreach $test (@
$testlist) {
358 runOneComplexTest
($test);
361 warn "File: ${file} could not be loaded as PERL: $!";
370 open(TESTLIST
, "<" . "${testsdir}/TESTLIST") || die "no ${testsdir}/TESTFILE: $!\n";
376 ($name, $input, $output, @options) = split;
377 #print "processing ${only} vs ${name}\n";
378 next if(defined($only) && $only ne $name);
380 my $options = join(" ", @options);
381 #print "@{options} becomes ${options}\n";
383 my $hash = { name
=> $name,
388 runOneComplexTest
($hash);
392 if(scalar(@ARGV) == 0) {
396 runSimpleTests
($ARGV[0]);
399 # exit with number of failing tests.
400 print "------------------------------------------------\n";
401 printf("%4u tests failed\n",$failedcount);
402 printf("%4u tests passed\n",$passedcount);
404 showfile
(${failureoutput
});