]> The Tcpdump Group git mirrors - tcpdump/blob - tests/TESTonce
fill in empty esp4 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.
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;
62 }
63 if($r == 0) {
64 $r = system "cat tests/NEW/$outputbase | diff $output - >tests/DIFF/$outputbase.diff";
65 $diffstat = WEXITSTATUS($r);
66 }
67
68 # process the file, sanitize "reading from" line, and count lines
69 $linecount = 0;
70 open(ERRORRAW, "<" . $rawstderrlog);
71 open(ERROROUT, ">" . $stderrlog);
72 while(<ERRORRAW>) {
73 next if /^$/; # blank lines are boring
74 if(/^(reading from file )(.*)(,.*)$/) {
75 my $filename = basename($2);
76 print ERROROUT "${1}${filename}${3}\n";
77 next;
78 }
79 print ERROROUT;
80 $linecount++;
81 }
82 close(ERROROUT);
83 close(ERRORRAW);
84
85 if ( -f "$output.stderr" ) {
86 $nr = system "cat $stderrlog | diff $output.stderr - >tests/DIFF/$outputbase.stderr.diff";
87 if($r == 0) {
88 $r = $nr;
89 }
90 $errdiffstat = WEXITSTATUS($nr);
91 } else {
92 $errdiffstat = "-"
93 }
94
95 if($r == 0) {
96 if($linecount == 0 && $status == 0) {
97 unlink($stderrlog);
98 } else {
99 $errdiffstat = "+";
100 }
101 }
102
103 #print sprintf("END: %08x\n", $r);
104 }
105
106 if($r == 0) {
107 my $stderrlog="";
108 if($linecount > 0) {
109 $stderrlog=sprintf("-- %d lines extra in stderr", $linecount);
110 }
111 if(!defined($ENV{"SKIPPASSED"})) {
112 printf " %-35s: passed%s\n", $name, $stderrlog;
113 }
114 unlink "tests/DIFF/$outputbase.diff";
115 exit 0;
116 }
117 # must have failed!
118 printf " %-35s: TEST FAILED(exit core=%d/diffstat=%d,%d/r=%d)", $name, $coredump, $diffstat, $errdiffstat, $r;
119 open FOUT, '>>failure-outputs.txt';
120 printf FOUT "\nFailed test: $name\n\n";
121 close FOUT;
122 if(-f "tests/DIFF/$outputbase.diff") {
123 system "cat tests/DIFF/$outputbase.diff >> failure-outputs.txt";
124 }
125
126 if($r == -1) {
127 print " (failed to execute: $!)\n";
128 exit 30;
129 }
130
131 # this is not working right, $r == 0x8b00 when there is a core dump.
132 # clearly, we need some platform specific perl magic to take this apart, so look for "core"
133 # too.
134 # In particular, on Solaris 10 SPARC an alignment problem results in SIGILL,
135 # a core dump and $r set to 0x00008a00 ($? == 138 in the shell).
136 if($r & 127 || -f "core") {
137 my $with = ($r & 128) ? 'with' : 'without';
138 if(-f "core") {
139 $with = "with";
140 }
141 printf " (terminated with signal %u, %s coredump)\n", ($r & 127), $with;
142 exit ($r & 128) ? 10 : 20;
143 }
144 print "\n";
145 exit $r >> 8;