]>
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 grovel Makefile for some things and pretend they are config options.
72 open(MAKEFILE
, "Makefile") || die "can not open Makefile: $!\n";
75 #print "Processing $_\n";
76 if(/^CC\s*=.*gcc.*/) {
78 $main::confighhash
->{'USING_GCC'} = 1;
83 return $main::confighhash
;
87 sub runOneComplexTest
{
88 local($testconfig) = @_;
90 my $output = $testconfig->{output
};
91 my $input = $testconfig->{input
};
92 my $name = $testconfig->{name
};
93 my $options= $testconfig->{args
};
97 my $configset = $testconfig->{config_set
};
98 my $configunset = $testconfig->{config_unset
};
99 my $ch = loadconfighash
();
102 if(defined($configset)) {
103 $foundit = ($ch->{$configset} == 1);
105 if(defined($configunset)) {
106 $unfoundit=($ch->{$configunset} != 1);
110 print "${name} ... skipped, no ${configset}\n";
115 print "${name} ... skipped, ${configunset} is set\n";
120 #print Dumper($testconfig);
122 # EXPAND any occurances of @TESTDIR@ to $testsdir
123 $options =~ s/\@TESTDIR\@/$testsdir/;
125 my $result = runtest
($name,
126 $testsdir . "/" . $input,
127 $testsdir . "/" . $output,
137 # *.tests files are PERL hash definitions. They should create an array of hashes
138 # one per test, and place it into the variable @testlist.
139 sub runComplexTests
{
140 my @files = glob( $testsdir . '/*.tests' );
141 foreach $file (@files) {
142 my @testlist = undef;
144 print "FILE: ${file}\n";
145 open(FILE
, "<".$file) || die "can not open $file: $!";
148 $definitions = <FILE
>;
151 #print "STUFF: ${definitions}\n";
153 if(defined($testlist)) {
155 #print Dumper($testlist);
156 foreach $test (@
$testlist) {
157 runOneComplexTest
($test);
160 warn "File: ${file} could not be loaded as PERL: $!";
169 open(TESTLIST
, "<" . "${testsdir}/TESTLIST") || die "no ${testsdir}/TESTFILE: $!\n";
175 ($name, $input, $output, @options) = split;
176 #print "processing ${only} vs ${name}\n";
177 next if(defined($only) && $only ne $name);
179 my $options = join(" ", @options);
180 #print "@{options} becomes ${options}\n";
182 my $hash = { name
=> $name,
187 runOneComplexTest
($hash);
191 if(scalar(@ARGV) == 0) {
195 runSimpleTests
($ARGV[0]);
198 # exit with number of failing tests.
199 print "------------------------------------------------\n";
200 printf("%4u tests failed\n",$failedcount);
201 printf("%4u tests passed\n",$passedcount);
203 system("cat ${failureoutput}");