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