@@ -36,7 +36,6 @@ $testsdir = abs_path($testsdir);
3636print " Running tests from ${testsdir} \n " ;
3737
3838unshift (@INC , $testsdir );
39- require ' testfuncs.pm' ;
4039
4140$passedcount = 0;
4241$failedcount = 0;
@@ -49,6 +48,143 @@ close(FAILUREOUTPUT);
4948
5049$confighhash = undef ;
5150
51+ sub runtest {
52+ local ($name , $input , $output , $options ) = @_ ;
53+ my $r ;
54+
55+ $outputbase = basename($output );
56+ my $coredump = false;
57+ my $status = 0;
58+ my $linecount = 0;
59+ my $rawstderrlog = " tests/NEW/${outputbase} .raw.stderr" ;
60+ my $stderrlog = " tests/NEW/${outputbase} .stderr" ;
61+ my $diffstat = 0;
62+ my $errdiffstat = 0;
63+
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.
67+ }
68+ else {
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} " ;
72+ if ($r == -1) {
73+ # failed to start due to error.
74+ $status = $! ;
75+ }
76+ if ($r != 0) {
77+ $coredump = false;
78+ $status = 0;
79+ # this means tcpdump failed.
80+ open (OUTPUT, " >>" ." tests/NEW/$outputbase " ) || die " fail to open $outputbase \n " ;
81+ if ( $r & 128 ) {
82+ $coredump = $r & 127;
83+ }
84+ if ( WIFEXITED($r )) {
85+ $status = WEXITSTATUS($r );
86+ }
87+
88+ if ($coredump || $status ) {
89+ printf OUTPUT " EXIT CODE %08x: dump:%d code: %d \n " , $r , $coredump , $status ;
90+ } else {
91+ printf OUTPUT " EXIT CODE %08x\n " , $r ;
92+ }
93+ close (OUTPUT);
94+ $r = 0;
95+ }
96+ if ($r == 0) {
97+ $r = system " cat tests/NEW/$outputbase | diff $output - >tests/DIFF/$outputbase .diff" ;
98+ $diffstat = WEXITSTATUS($r );
99+ }
100+
101+ # process the file, sanitize "reading from" line, and count lines
102+ $linecount = 0;
103+ open (ERRORRAW, " <" . $rawstderrlog );
104+ open (ERROROUT, " >" . $stderrlog );
105+ while (<ERRORRAW>) {
106+ next if / ^$ / ; # blank lines are boring
107+ if (/ ^(reading from file )(.*)(,.*)$ / ) {
108+ my $filename = basename($2 );
109+ print ERROROUT " ${1}${filename} ${3}\n " ;
110+ next ;
111+ }
112+ print ERROROUT;
113+ $linecount ++;
114+ }
115+ close (ERROROUT);
116+ close (ERRORRAW);
117+
118+ if ( -f " $output .stderr" ) {
119+ $nr = system " cat $stderrlog | diff $output .stderr - >tests/DIFF/$outputbase .stderr.diff" ;
120+ if ($r == 0) {
121+ $r = $nr ;
122+ }
123+ $errdiffstat = WEXITSTATUS($nr );
124+ }
125+
126+ if ($r == 0) {
127+ if ($linecount == 0 && $status == 0) {
128+ unlink ($stderrlog );
129+ } else {
130+ $errdiffstat = 1;
131+ }
132+ }
133+
134+ # print sprintf("END: %08x\n", $r);
135+ }
136+
137+ if ($r == 0) {
138+ if ($linecount == 0) {
139+ printf " %-40s: passed\n " , $name ;
140+ } else {
141+ printf " %-40s: passed with error messages:\n " , $name ;
142+ system " cat $stderrlog " ;
143+ }
144+ unlink " tests/DIFF/$outputbase .diff" ;
145+ return 0;
146+ }
147+ # must have failed!
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 " \n Failed test: $name \n\n " ;
151+ close FOUT;
152+ if (-f " tests/DIFF/$outputbase .diff" ) {
153+ system " cat tests/DIFF/$outputbase .diff >> tests/failure-outputs.txt" ;
154+ }
155+
156+ if ($r == -1) {
157+ print " (failed to execute: $! )\n " ;
158+ return (30);
159+ }
160+
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"
163+ # too.
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' ;
168+ if (-f " core" ) {
169+ $with = " with" ;
170+ }
171+ printf " (terminated with signal %u , %s coredump)" , ($r & 127), $with ;
172+ if ($linecount == 0) {
173+ print " \n " ;
174+ } else {
175+ print " with error messages:\n " ;
176+ system " cat $stderrlog " ;
177+ }
178+ return (($r & 128) ? 10 : 20);
179+ }
180+ if ($linecount == 0) {
181+ print " \n " ;
182+ } else {
183+ print " with error messages:\n " ;
184+ system " cat $stderrlog " ;
185+ }
186+ }
187+
52188sub loadconfighash {
53189 if (defined ($confighhash )) {
54190 return $confighhash ;
0 commit comments