]> The Tcpdump Group git mirrors - tcpdump/blob - tests/TESTonce
show core dump status clearly
[tcpdump] / tests / TESTonce
1 #!/usr/bin/env perl
2
3 use File::Basename;
4
5 system("mkdir -p NEW DIFF");
6
7 if(@ARGV != 4) {
8 print "Usage: TESTonce name input output options\n";
9 exit 20;
10 }
11
12 $name=$ARGV[0];
13 $input=$ARGV[1];
14 $output=$ARGV[2];
15 $options=$ARGV[3];
16
17 my $r;
18
19 $outputbase = basename($output);
20
21 if ($^O eq 'MSWin32') {
22 $r = system "..\\windump -n -t -r $input $options 2>NUL | sed 's/\\r//' | tee NEW/$outputbase | diff $output - >DIFF/$outputbase.diff";
23 # need to do same as below for Cygwin.
24 }
25 else {
26 # we used to do this as a nice pipeline, but the problem is that $r fails to
27 # to be set properly if the tcpdump core dumps.
28 $r = system "../tcpdump 2>/dev/null -n -t -r $input $options >NEW/$outputbase";
29 if($r != 0) {
30 my $coredump = false;
31 my $status = 0;
32 # this means tcpdump failed.
33 open(OUTPUT, ">>"."NEW/$outputbase") || die "fail to open $outputbase\n";
34 printf OUTPUT "EXIT CODE %08x\n", $r;
35 close(OUTPUT);
36 $r = 0;
37 }
38 if($r == 0) {
39 $r = system "cat NEW/$outputbase | diff $output - >DIFF/$outputbase.diff";
40 }
41 #print sprintf("END: %08x\n", $r);
42 }
43
44 if($r == 0) {
45 printf " %-35s: passed\n", $name;
46 unlink "DIFF/$outputbase.diff";
47 exit 0;
48 }
49 printf " %-35s: TEST FAILED(%s)", $name, $r == -1 ? $! : "exit $?";
50 open FOUT, '>>failure-outputs.txt';
51 printf FOUT "\nFailed test: $name\n\n";
52 close FOUT;
53 if(-f "DIFF/$outputbase.diff") {
54 system "cat DIFF/$outputbase.diff >> failure-outputs.txt";
55 }
56
57 if($r == -1) {
58 print " (failed to execute: $!)\n";
59 exit 30;
60 }
61
62 # this is not working right, $r == 0x8b00 when there is a core dump.
63 # clearly, we need some platform specific perl magic to take this apart, so look for "core"
64 # too.
65 # In particular, on Solaris 10 SPARC an alignment problem results in SIGILL,
66 # a core dump and $r set to 0x00008a00 ($? == 138 in the shell).
67 if($r & 127 || -f "core") {
68 my $with = ($r & 128) ? 'with' : 'without';
69 if(-f "core") {
70 $with = "with";
71 }
72 printf " (terminated with signal %u, %s coredump)\n", ($r & 127), $with;
73 exit ($r & 128) ? 10 : 20;
74 }
75 print "\n";
76 exit $r >> 8;