]> The Tcpdump Group git mirrors - tcpdump/blob - tests/TESTonce
make check needs to work in build directories
[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 # this means tcpdump failed.
31 open(OUTPUT, ">>"."NEW/$outputbase") || die "fail to open $outputbase\n";
32 printf OUTPUT "EXIT CODE %08x\n", $r;
33 close(OUTPUT);
34 $r = 0;
35 }
36 if($r == 0) {
37 $r = system "cat NEW/$outputbase | diff $output - >DIFF/$outputbase.diff";
38 }
39 #print sprintf("END: %08x\n", $r);
40 }
41
42 if($r == 0) {
43 printf " %-35s: passed\n", $name;
44 unlink "DIFF/$outputbase.diff";
45 exit 0;
46 }
47 printf " %-35s: TEST FAILED(%s)", $name, $r == -1 ? $! : "exit $?";
48 open FOUT, '>>failure-outputs.txt';
49 printf FOUT "\nFailed test: $name\n\n";
50 close FOUT;
51 if(-f "DIFF/$outputbase.diff") {
52 system "cat DIFF/$outputbase.diff >> failure-outputs.txt";
53 }
54
55 if($r == -1) {
56 print " (failed to execute: $!)\n";
57 exit 30;
58 }
59
60 # this is not working right, $r == 0x8b00 when there is a core dump.
61 # clearly, we need some platform specific perl magic to take this apart, so look for "core"
62 # too.
63 # In particular, on Solaris 10 SPARC an alignment problem results in SIGILL,
64 # a core dump and $r set to 0x00008a00 ($? == 138 in the shell).
65 if($r & 127 || -f "core") {
66 my $with = ($r & 128) ? 'with' : 'without';
67 if(-f "core") {
68 $with = "with";
69 }
70 printf " (terminated with signal %u, %s coredump)\n", ($r & 127), $with;
71 exit ($r & 128) ? 10 : 20;
72 }
73 print "\n";
74 exit $r >> 8;