]>
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 # XXX - create files used by shell scripts; we can remove this once we
45 # no longer use shell scripts in tests.
47 open(PASSEDCOUNT
, ">", "tests/.passed");
48 print PASSEDCOUNT
"${passedcount}\n";
50 open(FAILEDCOUNT
, ">", "tests/.failed");
51 print FAILEDCOUNT
"${failedcount}\n";
53 my $failureoutput=$origdir . "/tests/failure-outputs.txt";
55 # truncate the output file
56 open(FAILUREOUTPUT
, ">" . $failureoutput);
61 my @files = glob( $testsdir . '/*.sh' );
62 foreach $file (@files) {
63 if($file =~ /TEST.*\.sh/) {
64 print "File $file, skipped\n";
68 print "Running $file\n";
69 system("cd tests && sh $file ${srcdir}")
72 # have to update passed/failed here
78 if(defined($confighhash)) {
82 $main::confighhash
= {};
84 # this could be loaded once perhaps.
85 open(CONFIG_H
, "config.h") || die "Can not open config.h: $!\n";
88 if(/^\#define (.*) 1/) {
89 #print "Setting $1\n";
90 $main::confighhash
->{$1} = 1;
94 #print Dumper($main::confighhash);
96 # also grovel Makefile for some things and pretend they are config options.
97 open(MAKEFILE
, "Makefile") || die "can not open Makefile: $!\n";
100 #print "Processing $_\n";
101 if(/^CC\s*=.*gcc.*/) {
102 #print "GCC FOUND\n";
103 $main::confighhash
->{'USING_GCC'} = 1;
108 return $main::confighhash
;
112 sub runOneComplexTest
{
113 local($testconfig) = @_;
115 my $output = $testconfig->{output
};
116 my $input = $testconfig->{input
};
117 my $name = $testconfig->{name
};
118 my $options= $testconfig->{args
};
122 my $configset = $testconfig->{config_set
};
123 my $configunset = $testconfig->{config_unset
};
124 my $ch = loadconfighash
();
127 if(defined($configset)) {
128 $foundit = ($ch->{$configset} == 1);
130 if(defined($configunset)) {
131 $unfoundit=($ch->{$configunset} != 1);
135 print "${name} ... skipped, no ${configset}\n";
140 print "${name} ... skipped, ${configunset} is set\n";
145 #print Dumper($testconfig);
147 # EXPAND any occurances of @TESTDIR@ to $testsdir
148 $options =~ s/\@TESTDIR\@/$testsdir/;
150 my $result = runtest
($name,
151 $testsdir . "/" . $input,
152 $testsdir . "/" . $output,
162 # *.tests files are PERL hash definitions. They should create an array of hashes
163 # one per test, and place it into the variable @testlist.
164 sub runComplexTests
{
165 my @files = glob( $testsdir . '/*.tests' );
166 foreach $file (@files) {
167 my @testlist = undef;
169 print "FILE: ${file}\n";
170 open(FILE
, "<".$file) || die "can not open $file: $!";
173 $definitions = <FILE
>;
176 #print "STUFF: ${definitions}\n";
178 if(defined($testlist)) {
180 #print Dumper($testlist);
181 foreach $test (@
$testlist) {
182 runOneComplexTest
($test);
185 warn "File: ${file} could not be loaded as PERL: $!";
194 open(TESTLIST
, "<" . "${testsdir}/TESTLIST") || die "no ${testsdir}/TESTFILE: $!\n";
200 ($name, $input, $output, @options) = split;
201 #print "processing ${only} vs ${name}\n";
202 next if(defined($only) && $only ne $name);
204 my $options = join(" ", @options);
205 #print "@{options} becomes ${options}\n";
207 my $hash = { name
=> $name,
212 runOneComplexTest
($hash);
216 if(scalar(@ARGV) == 0) {
221 runSimpleTests
($ARGV[0]);
225 # XXX - read files used by shell scripts, and add the passed and failed
226 # counts reported therein to our own passed and failed counts; we can
227 # remove this once we no longer use shell scripts in tests.
229 open(PASSEDCOUNT
, "<", "tests/.passed");
230 $passedcount += <PASSEDCOUNT
>;
232 open(FAILEDCOUNT
, ">", "tests/.failed");
233 $failedcount += <FAILEDCOUNT
>;
236 # exit with number of failing tests.
237 print "------------------------------------------------\n";
238 printf("%4u tests failed\n",$failedcount);
239 printf("%4u tests passed\n",$passedcount);
241 system("cat ${failureoutput}");