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