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