]>
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);
39 require 'testfuncs.pm';
44 my $failureoutput=$origdir . "/tests/failure-outputs.txt";
46 # truncate the output file
47 open(FAILUREOUTPUT
, ">" . $failureoutput);
53 if(defined($confighhash)) {
57 $main::confighhash
= {};
59 # this could be loaded once perhaps.
60 open(CONFIG_H
, "config.h") || die "Can not open config.h: $!\n";
63 if(/^\#define (.*) 1/) {
64 #print "Setting $1\n";
65 $main::confighhash
->{$1} = 1;
69 #print Dumper($main::confighhash);
71 # also run tcpdump --fp-type to get the type of floating-point
72 # arithmetic we're doing, setting a HAVE_{fptype} key based
73 # on the value it prints
74 open(FPTYPE_PIPE
, "./tcpdump --fp-type |") or die("piping tcpdump --fp-type failed\n");
75 my $fptype_val = <FPTYPE_PIPE
>;
78 if($fptype_val == "9877.895") {
79 $have_fptype = "HAVE_FPTYPE1";
81 $have_fptype = "HAVE_FPTYPE2";
83 $main::confighhash
->{$have_fptype} = 1;
85 return $main::confighhash
;
89 sub runOneComplexTest
{
90 local($testconfig) = @_;
92 my $output = $testconfig->{output
};
93 my $input = $testconfig->{input
};
94 my $name = $testconfig->{name
};
95 my $options= $testconfig->{args
};
99 my $configset = $testconfig->{config_set
};
100 my $configunset = $testconfig->{config_unset
};
101 my $ch = loadconfighash
();
104 if(defined($configset)) {
105 $foundit = ($ch->{$configset} == 1);
107 if(defined($configunset)) {
108 $unfoundit=($ch->{$configunset} != 1);
112 printf " %-40s: skipped (%s not set)\n", $name, $configset;
117 printf " %-40s: skipped (%s set)\n", $name, $configunset;
122 #print Dumper($testconfig);
124 # EXPAND any occurances of @TESTDIR@ to $testsdir
125 $options =~ s/\@TESTDIR\@/$testsdir/;
127 my $result = runtest
($name,
128 $testsdir . "/" . $input,
129 $testsdir . "/" . $output,
139 # *.tests files are PERL hash definitions. They should create an array of hashes
140 # one per test, and place it into the variable @testlist.
141 sub runComplexTests
{
142 my @files = glob( $testsdir . '/*.tests' );
143 foreach $file (@files) {
144 my @testlist = undef;
146 print "FILE: ${file}\n";
147 open(FILE
, "<".$file) || die "can not open $file: $!";
150 $definitions = <FILE
>;
153 #print "STUFF: ${definitions}\n";
155 if(defined($testlist)) {
157 #print Dumper($testlist);
158 foreach $test (@
$testlist) {
159 runOneComplexTest
($test);
162 warn "File: ${file} could not be loaded as PERL: $!";
171 open(TESTLIST
, "<" . "${testsdir}/TESTLIST") || die "no ${testsdir}/TESTFILE: $!\n";
177 ($name, $input, $output, @options) = split;
178 #print "processing ${only} vs ${name}\n";
179 next if(defined($only) && $only ne $name);
181 my $options = join(" ", @options);
182 #print "@{options} becomes ${options}\n";
184 my $hash = { name
=> $name,
189 runOneComplexTest
($hash);
193 if(scalar(@ARGV) == 0) {
197 runSimpleTests
($ARGV[0]);
200 # exit with number of failing tests.
201 print "------------------------------------------------\n";
202 printf("%4u tests failed\n",$failedcount);
203 printf("%4u tests passed\n",$passedcount);
205 system("cat ${failureoutput}");