]> The Tcpdump Group git mirrors - tcpdump/blob - tests/TESTonce
added some debugging, found wrong failure-outputs file
[tcpdump] / tests / TESTonce
1 #!/usr/bin/env perl
2
3 $TCPDUMP = "tcpdump" if (!($TCPDUMP = $ENV{TCPDUMP_BIN}));
4
5 use File::Basename;
6 use POSIX qw( WEXITSTATUS WIFEXITED);
7
8 system("mkdir -p tests/NEW tests/DIFF");
9
10 if(@ARGV != 4) {
11 print "Usage: TESTonce name input output options\n";
12 exit 20;
13 }
14
15 $name=$ARGV[0];
16 $input=$ARGV[1];
17 $output=$ARGV[2];
18 $options=$ARGV[3];
19
20 my $r;
21
22 $outputbase = basename($output);
23 my $coredump = false;
24 my $status = 0;
25 my $linecount = 0;
26 my $rawstderrlog = "tests/NEW/${outputbase}.raw.stderr";
27 my $stderrlog = "tests/NEW/${outputbase}.stderr";
28 my $diffstat = 0;
29 my $errdiffstat = 0;
30
31 if ($^O eq 'MSWin32') {
32 $r = system "..\\windump -t -n -r $input $options 2>NUL | sed 's/\\r//' | tee tests/NEW/$outputbase | diff $output - >tests/DIFF/$outputbase.diff";
33 # need to do same as below for Cygwin.
34 }
35 else {
36 # we used to do this as a nice pipeline, but the problem is that $r fails to
37 # to be set properly if the tcpdump core dumps.
38 $r = system "$TCPDUMP 2>${rawstderrlog} -t -n -r $input $options >tests/NEW/${outputbase}";
39 if($r == -1) {
40 # failed to start due to error.
41 $status = $!;
42 }
43 if($r != 0) {
44 $coredump = false;
45 $status = 0;
46 # this means tcpdump failed, which however, might be expected.
47 open(OUTPUT, ">>"."tests/NEW/${outputbase}") || die "fail to open ${outputbase}\n";
48 if( $r & 128 ) {
49 $coredump = $r & 127;
50 }
51 if( WIFEXITED($r)) {
52 $status = WEXITSTATUS($r);
53 }
54
55 if($coredump || $status) {
56 printf OUTPUT "\nEXIT CODE %08x: dump:%d code: %d\n", $r, $coredump, $status;
57 } else {
58 printf OUTPUT "\nEXIT CODE %08x\n", $r;
59 }
60 close(OUTPUT);
61 $r = 0; # clear the error so that the diff will occur.
62 }
63 #print "RUNNING DIFF after ${r}\n";
64
65 # always run diff.
66 #print "RUNNING: cat tests/NEW/${outputbase} | diff $output - >tests/DIFF/${outputbase}.diff\n";
67 $r = system "cat tests/NEW/${outputbase} | diff $output - >tests/DIFF/${outputbase}.diff";
68 $diffstat = WEXITSTATUS($r);
69
70 # process the file, sanitize "reading from" line, and count lines
71 $linecount = 0;
72 open(ERRORRAW, "<" . $rawstderrlog);
73 open(ERROROUT, ">" . $stderrlog);
74 while(<ERRORRAW>) {
75 next if /^$/; # blank lines are boring
76 if(/^(reading from file )(.*)(,.*)$/) {
77 my $filename = basename($2);
78 print ERROROUT "${1}${filename}${3}\n";
79 next;
80 }
81 print ERROROUT;
82 $linecount++;
83 }
84 close(ERROROUT);
85 close(ERRORRAW);
86
87 if ( -f "$output.stderr" ) {
88 $nr = system "cat $stderrlog | diff $output.stderr - >tests/DIFF/$outputbase.stderr.diff";
89 if($r == 0) {
90 $r = $nr;
91 }
92 $errdiffstat = WEXITSTATUS($nr);
93 } else {
94 $errdiffstat = "-"
95 }
96
97 if($r == 0) {
98 if($linecount == 0 && $status == 0) {
99 #print "UNLINK: ${stderrlog}\n";
100 unlink($stderrlog);
101 } else {
102 $errdiffstat = "+";
103 }
104 }
105
106 #print sprintf("END: %08x\n", $r);
107 }
108
109 if($r == 0) {
110 my $stderrlog="";
111 if($linecount > 0) {
112 $stderrlog=sprintf("-- %d lines extra in stderr", $linecount);
113 }
114 if(!defined($ENV{"SKIPPASSED"})) {
115 printf " %-35s: passed%s\n", $name, $stderrlog;
116 }
117 unlink "tests/DIFF/$outputbase.diff";
118 exit 0;
119 }
120 # must have failed!
121 printf " %-35s: TEST FAILED(exit core=%d/diffstat=%d,%d/r=%d)", $name, $coredump, $diffstat, $errdiffstat, $r;
122 open FOUT, '>>tests/failure-outputs.txt';
123 printf FOUT "\nFailed test: $name\n\n";
124 close FOUT;
125 if(-f "tests/DIFF/$outputbase.diff") {
126 system "cat tests/DIFF/$outputbase.diff >> tests/failure-outputs.txt";
127 }
128
129 if($r == -1) {
130 print " (failed to execute: $!)\n";
131 exit 30;
132 }
133
134 # this is not working right, $r == 0x8b00 when there is a core dump.
135 # clearly, we need some platform specific perl magic to take this apart, so look for "core"
136 # too.
137 # In particular, on Solaris 10 SPARC an alignment problem results in SIGILL,
138 # a core dump and $r set to 0x00008a00 ($? == 138 in the shell).
139 if($r & 127 || -f "core") {
140 my $with = ($r & 128) ? 'with' : 'without';
141 if(-f "core") {
142 $with = "with";
143 }
144 printf " (terminated with signal %u, %s coredump)\n", ($r & 127), $with;
145 exit ($r & 128) ? 10 : 20;
146 }
147 print "\n";
148 exit $r >> 8;