]>
The Tcpdump Group git mirrors - tcpdump/blob - tests/TESTrun
3 $TCPDUMP = "./tcpdump" if (!($TCPDUMP = $ENV{TCPDUMP_BIN
}));
6 use POSIX
qw( WEXITSTATUS WIFEXITED);
7 use Cwd
qw(abs_path getcwd);
8 use File
::Path
qw(mkpath); # mkpath works with ancient perl, as well as newer perl
9 use Data
::Dumper
; # for debugging.
11 # these are created in the directory where we are run, which might be
13 my $newdir = "tests/NEW";
14 my $diffdir= "tests/DIFF";
17 my $origdir = getcwd
();
18 my $srcdir = $ENV{'srcdir'} || ".";
21 # Force UTC, so time stamps are printed in a standard time zone, and
22 # tests don't have to be run in the time zone in which the output
28 # Get the tests directory from $0.
30 my $testsdir = dirname
($0);
33 # Convert it to an absolute path, so it works even after we do a cd.
35 $testsdir = abs_path
($testsdir);
36 print "Running tests from ${testsdir}\n";
38 unshift(@INC, $testsdir);
43 my $failureoutput=$origdir . "/tests/failure-outputs.txt";
45 # truncate the output file
46 open(FAILUREOUTPUT
, ">" . $failureoutput);
52 local($name, $input, $output, $options) = @_;
55 $outputbase = basename
($output);
59 my $rawstderrlog = "tests/NEW/${outputbase}.raw.stderr";
60 my $stderrlog = "tests/NEW/${outputbase}.stderr";
64 if ($^O
eq 'MSWin32') {
65 $r = system "..\\windump -# -n -r $input $options 2>NUL | sed 's/\\r//' | tee tests/NEW/$outputbase | diff $output - >tests/DIFF/$outputbase.diff";
66 # need to do same as below for Cygwin.
69 # we used to do this as a nice pipeline, but the problem is that $r fails to
70 # to be set properly if the tcpdump core dumps.
71 $r = system "$TCPDUMP 2>${rawstderrlog} -# -n -r $input $options >tests/NEW/${outputbase}";
73 # failed to start due to error.
79 # this means tcpdump failed.
80 open(OUTPUT
, ">>"."tests/NEW/$outputbase") || die "fail to open $outputbase\n";
85 $status = WEXITSTATUS
($r);
88 if($coredump || $status) {
89 printf OUTPUT
"EXIT CODE %08x: dump:%d code: %d\n", $r, $coredump, $status;
91 printf OUTPUT
"EXIT CODE %08x\n", $r;
97 $r = system "cat tests/NEW/$outputbase | diff $output - >tests/DIFF/$outputbase.diff";
98 $diffstat = WEXITSTATUS
($r);
101 # process the file, sanitize "reading from" line, and count lines
103 open(ERRORRAW
, "<" . $rawstderrlog);
104 open(ERROROUT
, ">" . $stderrlog);
106 next if /^$/; # blank lines are boring
107 if(/^(reading from file )(.*)(,.*)$/) {
108 my $filename = basename
($2);
109 print ERROROUT
"${1}${filename}${3}\n";
118 if ( -f
"$output.stderr" ) {
119 $nr = system "cat $stderrlog | diff $output.stderr - >tests/DIFF/$outputbase.stderr.diff";
123 $errdiffstat = WEXITSTATUS
($nr);
127 if($linecount == 0 && $status == 0) {
134 #print sprintf("END: %08x\n", $r);
138 if($linecount == 0) {
139 printf " %-40s: passed\n", $name;
141 printf " %-40s: passed with error messages:\n", $name;
142 system "cat $stderrlog";
144 unlink "tests/DIFF/$outputbase.diff";
148 printf " %-40s: TEST FAILED(exit core=%d/diffstat=%d,%d/r=%d)", $name, $coredump, $diffstat, $errdiffstat, $r;
149 open FOUT
, '>>tests/failure-outputs.txt';
150 printf FOUT
"\nFailed test: $name\n\n";
152 if(-f
"tests/DIFF/$outputbase.diff") {
153 system "cat tests/DIFF/$outputbase.diff >> tests/failure-outputs.txt";
157 print " (failed to execute: $!)\n";
161 # this is not working right, $r == 0x8b00 when there is a core dump.
162 # clearly, we need some platform specific perl magic to take this apart, so look for "core"
164 # In particular, on Solaris 10 SPARC an alignment problem results in SIGILL,
165 # a core dump and $r set to 0x00008a00 ($? == 138 in the shell).
166 if($r & 127 || -f
"core") {
167 my $with = ($r & 128) ?
'with' : 'without';
171 printf " (terminated with signal %u, %s coredump)", ($r & 127), $with;
172 if($linecount == 0) {
175 print " with error messages:\n";
176 system "cat $stderrlog";
178 return(($r & 128) ?
10 : 20);
180 if($linecount == 0) {
183 print " with error messages:\n";
184 system "cat $stderrlog";
189 if(defined($confighhash)) {
193 $main::confighhash
= {};
195 # this could be loaded once perhaps.
196 open(CONFIG_H
, "config.h") || die "Can not open config.h: $!\n";
199 if(/^\#define (.*) 1/) {
200 #print "Setting $1\n";
201 $main::confighhash
->{$1} = 1;
205 #print Dumper($main::confighhash);
207 # also run tcpdump --fp-type to get the type of floating-point
208 # arithmetic we're doing, setting a HAVE_{fptype} key based
209 # on the value it prints
210 open(FPTYPE_PIPE
, "./tcpdump --fp-type |") or die("piping tcpdump --fp-type failed\n");
211 my $fptype_val = <FPTYPE_PIPE
>;
214 if($fptype_val == "9877.895") {
215 $have_fptype = "HAVE_FPTYPE1";
217 $have_fptype = "HAVE_FPTYPE2";
219 $main::confighhash
->{$have_fptype} = 1;
221 return $main::confighhash
;
225 sub runOneComplexTest
{
226 local($testconfig) = @_;
228 my $output = $testconfig->{output
};
229 my $input = $testconfig->{input
};
230 my $name = $testconfig->{name
};
231 my $options= $testconfig->{args
};
235 my $configset = $testconfig->{config_set
};
236 my $configunset = $testconfig->{config_unset
};
237 my $ch = loadconfighash
();
240 if(defined($configset)) {
241 $foundit = ($ch->{$configset} == 1);
243 if(defined($configunset)) {
244 $unfoundit=($ch->{$configunset} != 1);
248 printf " %-40s: skipped (%s not set)\n", $name, $configset;
253 printf " %-40s: skipped (%s set)\n", $name, $configunset;
258 #print Dumper($testconfig);
260 # EXPAND any occurances of @TESTDIR@ to $testsdir
261 $options =~ s/\@TESTDIR\@/$testsdir/;
263 my $result = runtest
($name,
264 $testsdir . "/" . $input,
265 $testsdir . "/" . $output,
275 # *.tests files are PERL hash definitions. They should create an array of hashes
276 # one per test, and place it into the variable @testlist.
277 sub runComplexTests
{
278 my @files = glob( $testsdir . '/*.tests' );
279 foreach $file (@files) {
280 my @testlist = undef;
282 print "FILE: ${file}\n";
283 open(FILE
, "<".$file) || die "can not open $file: $!";
286 $definitions = <FILE
>;
289 #print "STUFF: ${definitions}\n";
291 if(defined($testlist)) {
293 #print Dumper($testlist);
294 foreach $test (@
$testlist) {
295 runOneComplexTest
($test);
298 warn "File: ${file} could not be loaded as PERL: $!";
307 open(TESTLIST
, "<" . "${testsdir}/TESTLIST") || die "no ${testsdir}/TESTFILE: $!\n";
313 ($name, $input, $output, @options) = split;
314 #print "processing ${only} vs ${name}\n";
315 next if(defined($only) && $only ne $name);
317 my $options = join(" ", @options);
318 #print "@{options} becomes ${options}\n";
320 my $hash = { name
=> $name,
325 runOneComplexTest
($hash);
329 if(scalar(@ARGV) == 0) {
333 runSimpleTests
($ARGV[0]);
336 # exit with number of failing tests.
337 print "------------------------------------------------\n";
338 printf("%4u tests failed\n",$failedcount);
339 printf("%4u tests passed\n",$passedcount);
341 system("cat ${failureoutput}");