TESTonce 1.9 KB

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