xref: /minix/external/bsd/tcpdump/dist/tests/TESTonce (revision b636d99d)
1#!/usr/bin/env perl
2
3system("mkdir -p NEW DIFF");
4
5if(@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
15my $r;
16
17if ($^O eq 'MSWin32') {
18    $r = system "..\\windump -n -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}
21else {
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 -r $input $options >NEW/$output";
25    if($r == 0x100) {
26        # this means tcpdump exited with code 1.
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
38if($r == 0) {
39  printf "    %-30s: passed\n", $name;
40  unlink "DIFF/$output.diff";
41  exit 0;
42}
43printf "    %-30s: TEST FAILED", $name;
44open FOUT, '>>failure-outputs.txt';
45printf FOUT "Failed test: $name\n\n";
46close FOUT;
47if(-f "DIFF/$output.diff") {
48    system "cat DIFF/$output.diff >> failure-outputs.txt";
49}
50
51if($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.
59if($r & 127 || -f "core") {
60    my $with = ($r & 128) ? 'with' : 'without';
61    if(-f "core") {
62        $with = "with";
63    }
64    printf " (terminated with signal %u, %s coredump)\n", ($r & 127), $with;
65    exit ($r & 128) ? 10 : 20;
66}
67print "\n";
68exit $r >> 8;
69