]> The Tcpdump Group git mirrors - tcpdump/blob - tests/TESTonce
the failed/passed count was not kept in the right place
[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 NEW 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 $stderrlog = "NEW/${outputbase}.stderr";
27 my $diffstat = 0;
28
29 if ($^O eq 'MSWin32') {
30 $r = system "..\\windump -# -n -r $input $options 2>NUL | sed 's/\\r//' | tee NEW/$outputbase | diff $output - >DIFF/$outputbase.diff";
31 # need to do same as below for Cygwin.
32 }
33 else {
34 # we used to do this as a nice pipeline, but the problem is that $r fails to
35 # to be set properly if the tcpdump core dumps.
36 $r = system "$TCPDUMP 2>${stderrlog} -# -n -r $input $options >NEW/${outputbase}";
37 if($r == -1) {
38 # failed to start due to error.
39 $status = $!;
40 }
41 if($r != 0) {
42 $coredump = false;
43 $status = 0;
44 # this means tcpdump failed.
45 open(OUTPUT, ">>"."NEW/$outputbase") || die "fail to open $outputbase\n";
46 if( $r & 128 ) {
47 $coredump = $r & 127;
48 }
49 if( WIFEXITED($r)) {
50 $status = WEXITSTATUS($r);
51 }
52
53 printf OUTPUT "EXIT CODE %08x: dump:%d code: %d\n", $r, $coredump, $status;
54 close(OUTPUT);
55 $r = 0;
56 }
57 if($r == 0) {
58 $r = system "cat NEW/$outputbase | diff $output - >DIFF/$outputbase.diff";
59 $diffstat = WEXITSTATUS($r);
60 }
61 if($r == 0) {
62 $linecount = 0;
63 open(ERROROUT, "<" . $stderrlog);
64 while(<ERROROUT>) {
65 next if /^$/; # blank lines are boring
66 next if /^reading from file/; # stock output boring too
67 $linecount++;
68 }
69 if($linecount == 0) {
70 unlink($stderrlog);
71 }
72 }
73
74 #print sprintf("END: %08x\n", $r);
75 }
76
77 if($r == 0) {
78 my $stderrlog="";
79 if($linecount > 0) {
80 $stderrlog=sprintf("%d lines in stderr", $linecount);
81 }
82 printf " %-35s: passed%s\n", $name, $stderrlog;
83 unlink "DIFF/$outputbase.diff";
84 exit 0;
85 }
86 # must have failed!
87 printf " %-35s: TEST FAILED(exit core=%d/diffstat=%d/r=%d)", $name, $coredump, $diffstat, $r;
88 open FOUT, '>>failure-outputs.txt';
89 printf FOUT "\nFailed test: $name\n\n";
90 close FOUT;
91 if(-f "DIFF/$outputbase.diff") {
92 system "cat DIFF/$outputbase.diff >> failure-outputs.txt";
93 }
94
95 if($r == -1) {
96 print " (failed to execute: $!)\n";
97 exit 30;
98 }
99
100 # this is not working right, $r == 0x8b00 when there is a core dump.
101 # clearly, we need some platform specific perl magic to take this apart, so look for "core"
102 # too.
103 # In particular, on Solaris 10 SPARC an alignment problem results in SIGILL,
104 # a core dump and $r set to 0x00008a00 ($? == 138 in the shell).
105 if($r & 127 || -f "core") {
106 my $with = ($r & 128) ? 'with' : 'without';
107 if(-f "core") {
108 $with = "with";
109 }
110 printf " (terminated with signal %u, %s coredump)\n", ($r & 127), $with;
111 exit ($r & 128) ? 10 : 20;
112 }
113 print "\n";
114 exit $r >> 8;