"Fossies" - the Fresh Open Source Software Archive

Member "fping-5.1/ci/test-04-options-a-b.pl" (6 Feb 2022, 2535 Bytes) of package /linux/misc/fping-5.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Perl source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "test-04-options-a-b.pl": 5.0_vs_5.1.

    1 #!/usr/bin/perl -w
    2 
    3 use Test::Command tests => 32;
    4 use Test::More;
    5 use Time::HiRes qw(gettimeofday tv_interval);
    6 
    7 #  -4         only use IPv4 addresses
    8 #  -6         only use IPv6 addresses
    9 #  -a         show targets that are alive
   10 #  -A         show targets by address
   11 #  -b n       amount of ping data to send, in bytes (default 56)
   12 #  -B f       set exponential backoff factor to f
   13 
   14 # fping -4 -6
   15 {
   16 my $cmd = Test::Command->new(cmd => "fping -4 -6 127.0.0.1");
   17 $cmd->exit_is_num(1);
   18 $cmd->stdout_is_eq("");
   19 $cmd->stderr_is_eq("fping: can't specify both -4 and -6\n");
   20 }
   21 
   22 # fping -6 -4
   23 {
   24 my $cmd = Test::Command->new(cmd => "fping -6 -4 127.0.0.1");
   25 $cmd->exit_is_num(1);
   26 $cmd->stdout_is_eq("");
   27 $cmd->stderr_is_eq("fping: can't specify both -4 and -6\n");
   28 }
   29 
   30 # fping -4
   31 {
   32 my $cmd = Test::Command->new(cmd => "fping -4 127.0.0.1");
   33 $cmd->exit_is_num(0);
   34 $cmd->stdout_is_eq("127.0.0.1 is alive\n");
   35 $cmd->stderr_is_eq("");
   36 }
   37 
   38 {
   39 my $cmd = Test::Command->new(cmd => "fping -4 ::1");
   40 $cmd->exit_is_num(2);
   41 $cmd->stdout_is_eq("");
   42 $cmd->stderr_like(qr{^::1:.*(not supported|not known)});
   43 }
   44 
   45 # fping -6
   46 SKIP: {
   47     if($ENV{SKIP_IPV6}) {
   48         skip 'Skip IPv6 tests', 3;
   49     }
   50     my $cmd = Test::Command->new(cmd => "fping -6 ::1");
   51     $cmd->exit_is_num(0);
   52     $cmd->stdout_is_eq("::1 is alive\n");
   53     $cmd->stderr_is_eq("");
   54 }
   55 
   56 {
   57 my $cmd = Test::Command->new(cmd => "fping -6 127.0.0.1");
   58 $cmd->exit_is_num(2);
   59 $cmd->stdout_is_eq("");
   60 $cmd->stderr_like(qr{127\.0\.0\.1:.*(not supported|not known)});
   61 }
   62 
   63 # fping -a
   64 {
   65 my $cmd = Test::Command->new(cmd => "fping -a 127.0.0.1 127.0.0.2");
   66 $cmd->exit_is_num(0);
   67 $cmd->stdout_is_eq("127.0.0.1\n127.0.0.2\n");
   68 $cmd->stderr_is_eq("");
   69 }
   70 
   71 # fping -A
   72 {
   73 my $cmd = Test::Command->new(cmd => "fping -4 -A localhost");
   74 $cmd->exit_is_num(0);
   75 $cmd->stdout_is_eq("127.0.0.1 is alive\n");
   76 $cmd->stderr_is_eq("");
   77 }
   78 
   79 # fping -b
   80 {
   81 my $cmd = Test::Command->new(cmd => "fping -b 1000 127.0.0.1");
   82 $cmd->exit_is_num(0);
   83 $cmd->stdout_is_eq("127.0.0.1 is alive\n");
   84 $cmd->stderr_is_eq("");
   85 }
   86 
   87 # fping -B
   88 SKIP: {
   89     if($^O eq 'darwin') {
   90         skip 'timing test not reliable on macOS', 5;
   91     }
   92     my $t0 = [gettimeofday];
   93     my $cmd = Test::Command->new(cmd => "fping  -t 100 -r 3 -B 2  8.8.8.7");
   94     $cmd->exit_is_num(1);
   95     $cmd->stdout_is_eq("8.8.8.7 is unreachable\n");
   96     $cmd->stderr_like(qr{^(|(8.8.8.7: error while sending ping: No route to host\n)+)$});
   97     my $elapsed = tv_interval($t0);
   98     # 0.1 + 0.2 + 0.4 + 0.8 = 1.5
   99     cmp_ok($elapsed, '>=', 1.5);
  100     cmp_ok($elapsed, '<', 1.9);
  101 }