"Fossies" - the Fresh Open Source Software Archive

Member "fping-5.1/ci/test-14-ping-internet-hosts.pl" (6 Feb 2022, 2924 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.

    1 #!/usr/bin/perl -w
    2 
    3 use Test::Command;
    4 use Test::More;
    5 
    6 # evaluate if we have internet
    7 if(!gethostbyname("www.google.com")) {
    8     plan skip_all => 'Can\'t resolve www.google.com -> no internet?';
    9     exit 0;
   10 }
   11 
   12 plan tests => 30;
   13 
   14 my $re_num = qr{\d+(?:\.\d+)?};
   15 
   16 # fping
   17 {
   18 my $cmd = Test::Command->new(cmd => "fping -q -i 10 -p 20 -c 3 -t200  8.8.8.8 www.france-telecom.fr www.google.com");
   19 $cmd->exit_is_num(0);
   20 $cmd->stdout_is_eq("");
   21 $cmd->stderr_like(qr{8\.8\.8\.8\s*: xmt/rcv/%loss = [123]/[123]/\d+%, min/avg/max = $re_num/$re_num/$re_num
   22 www\.france-telecom\.fr\s*: xmt/rcv/%loss = [123]/[123]/\d+%, min/avg/max = $re_num/$re_num/$re_num
   23 www\.google\.com\s*: xmt/rcv/%loss = [123]/[123]/\d+%, min/avg/max = $re_num/$re_num/$re_num
   24 });
   25 }
   26 
   27 # fping -A -n
   28 {
   29 my $cmd = Test::Command->new(cmd => "fping -A -n 8.8.8.8");
   30 $cmd->exit_is_num(0);
   31 $cmd->stdout_is_eq("dns.google (8.8.8.8) is alive\n");
   32 $cmd->stderr_is_eq("");
   33 }
   34 
   35 # fping -4 -A -n
   36 {
   37 my $cmd = Test::Command->new(cmd => "fping -4 -A -n dns.google");
   38 $cmd->exit_is_num(0);
   39 $cmd->stdout_like(qr{^dns.google \(8\.8\.(4\.4|8\.8)\) is alive\n$});
   40 $cmd->stderr_is_eq("");
   41 }
   42 
   43 # fping -4 --addr --rdns
   44 {
   45 my $cmd = Test::Command->new(cmd => "fping -4 --addr --rdns www.apple.com");
   46 $cmd->exit_is_num(0);
   47 $cmd->stdout_like(qr{^\S+\.akamaitechnologies\.com \(\d+\.\d+\.\d+\.\d+\) is alive\n$});
   48 $cmd->stderr_is_eq("");
   49 }
   50 
   51 # fping -4 --addr --name
   52 {
   53 my $cmd = Test::Command->new(cmd => "fping -4 --addr --name www.google.com");
   54 $cmd->exit_is_num(0);
   55 $cmd->stdout_like(qr{^www\.google\.com \(\d+\.\d+\.\d+\.\d+\) is alive\n$});
   56 $cmd->stderr_is_eq("");
   57 }
   58 
   59 # fping -A -n (IPv6)
   60 SKIP: {
   61     if($ENV{SKIP_IPV6}) {
   62         skip 'Skip IPv6 tests', 3;
   63     }
   64     my $cmd = Test::Command->new(cmd => "fping -6 -n -A dns.google");
   65     $cmd->exit_is_num(0);
   66     $cmd->stdout_like(qr{^dns.google \(2001:4860:4860::88(44|88)\) is alive\n$});
   67     $cmd->stderr_is_eq("");
   68 }
   69 
   70 # fping -m
   71 SKIP: {
   72     if($ENV{SKIP_IPV6}) {
   73         skip 'Skip IPv6 tests', 3;
   74     }
   75     my $cmd = Test::Command->new(cmd => "fping -A -m dns.google");
   76     $cmd->exit_is_num(0);
   77     $cmd->stdout_like(qr{^.* is alive\n.* is alive\n.* is alive\n.* is alive\n});
   78     $cmd->stderr_is_eq("");
   79 }
   80 
   81 # fping -m -A
   82 {
   83 my $cmd = Test::Command->new(cmd => "fping -4 -A -m www.cloudflare.com");
   84 $cmd->exit_is_num(0);
   85 $cmd->stdout_like(qr{\d+\.\d+\.\d+\.\d+ is alive\n\d+\.\d+\.\d+\.\d+ is alive\n});
   86 $cmd->stderr_is_eq("");
   87 }
   88 
   89 # fping -n
   90 {
   91 my $cmd = Test::Command->new(cmd => "fping -n 8.8.8.8");
   92 $cmd->exit_is_num(0);
   93 $cmd->stdout_is_eq("dns.google is alive\n");
   94 $cmd->stderr_is_eq("");
   95 }
   96 
   97 # fping -M
   98 SKIP: {
   99     if($^O eq 'darwin') {
  100         skip '-M option not supported on macOS', 3;
  101     }
  102     my $cmd = Test::Command->new(cmd => "fping -r 0 -b 10000 -M 8.8.8.8");
  103     $cmd->exit_is_num(1);
  104     $cmd->stdout_is_eq("8.8.8.8 is unreachable\n");
  105     $cmd->stderr_is_eq("8.8.8.8: error while sending ping: Message too long\n");
  106 }