]>
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
10 # these are created in the directory where we are run, which might be
12 my $newdir = "tests/NEW";
13 my $diffdir= "tests/DIFF";
16 my $origdir = getcwd
();
17 my $srcdir = $ENV{'srcdir'} || ".";
20 # Force UTC, so time stamps are printed in a standard time zone, and
21 # tests don't have to be run in the time zone in which the output
27 # Get the tests directory from $0.
29 my $testsdir = dirname
($0);
32 # Convert it to an absolute path, so it works even after we do a cd.
34 $testsdir = abs_path
($testsdir);
35 print "Running tests from ${testsdir}\n";
37 unshift(@INC, $testsdir);
38 require 'testfuncs.pm';
43 # XXX - create files used by shell scripts; we can remove this once we
44 # no longer use shell scripts in tests.
46 open(PASSEDCOUNT
, ">", "tests/.passed");
47 print PASSEDCOUNT
"${passedcount}\n";
49 open(FAILEDCOUNT
, ">", "tests/.failed");
50 print FAILEDCOUNT
"${failedcount}\n";
52 my $failureoutput=$origdir . "/tests/failure-outputs.txt";
54 # truncate the output file
55 open(FAILUREOUTPUT
, ">" . $failureoutput);
60 my @files = glob( $testsdir . '/*.sh' );
61 foreach $file (@files) {
62 if($file =~ /TEST.*\.sh/) {
63 print "File $file, skipped\n";
67 print "Running $file\n";
68 system("cd tests && sh $file ${srcdir}")
71 # have to update passed/failed here
74 sub runOneComplexTest
{
75 local($testconfig) = @_;
77 my $output = $testconfig->{output
};
78 my $input = $testconfig->{input
};
79 my $name = $testconfig->{name
};
80 my $options= $testconfig->{args
};
83 #print Dumper($testconfig);
85 my $result = runtest
($name,
86 $testsdir . "/" . $input,
87 $testsdir . "/" . $output,
97 # *.tests files are PERL hash definitions. They should create an array of hashes
98 # one per test, and place it into the variable @testlist.
100 my @files = glob( $testsdir . '/*.tests' );
101 foreach $file (@files) {
102 my @testlist = undef;
103 print "FILE: ${file}\n";
104 open(FILE
, "<".$file) || die "can not open $file: $!";
106 $definitions = <FILE
>;
108 #print "STUFF: ${definitions}\n";
110 if(defined($testlist)) {
112 #print Dumper($testlist);
113 foreach $test (@
$testlist) {
114 runOneComplexTest
($test);
117 warn "File: ${file} could not be loaded as PERL: $!";
126 open(TESTLIST
, "<" . "${testsdir}/TESTLIST") || die "no ${testsdir}/TESTFILE: $!\n";
132 ($name, $input, $output, @options) = split;
133 #print "processing ${only} vs ${name}\n";
134 next if(defined($only) && $only ne $name);
136 my $options = join(" ", @options);
137 #print "@{options} becomes ${options}\n";
139 my $hash = { name
=> $name,
144 runOneComplexTest
($hash);
148 if(scalar(@ARGV) == 0) {
153 runSimpleTests
($ARGV[0]);
157 # XXX - read files used by shell scripts, and add the passed and failed
158 # counts reported therein to our own passed and failed counts; we can
159 # remove this once we no longer use shell scripts in tests.
161 open(PASSEDCOUNT
, "<", "tests/.passed");
162 $passedcount += <PASSEDCOUNT
>;
164 open(FAILEDCOUNT
, ">", "tests/.failed");
165 $failedcount += <FAILEDCOUNT
>;
168 # exit with number of failing tests.
169 print "------------------------------------------------\n";
170 printf("%4u tests failed\n",$failedcount);
171 printf("%4u tests passed\n",$passedcount);
173 system("cat ${failureoutput}");