From 0114c307ee36853ec713851fd327bbe0a665dc7a Mon Sep 17 00:00:00 2001 From: David Schweikert Date: Thu, 9 Oct 2014 20:16:11 +1100 Subject: [PATCH] improve tests for macos x and for when offline --- ci/prepare-macos.sh | 13 ++++++++ ci/test-11-nopriv.pl | 9 +++++- ci/test-13-unknown-host.pl | 4 +-- ci/test-14-ping-internet-hosts.pl | 51 ++++++++++++++++++++++++++++++- ci/test-4-options-a-b.pl | 28 ++--------------- ci/test-7-options-i-m.pl | 10 ++---- ci/test-8-options-n-q.pl | 10 ++---- 7 files changed, 79 insertions(+), 46 deletions(-) create mode 100755 ci/prepare-macos.sh diff --git a/ci/prepare-macos.sh b/ci/prepare-macos.sh new file mode 100755 index 0000000..09125eb --- /dev/null +++ b/ci/prepare-macos.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# only do this on Mac OS X +if [ `uname -s` != "Darwin" ]; then + exit 0; +fi + +if [[ ! `ifconfig lo0` =~ 127\.0\.0\.2 ]]; then + sudo ifconfig lo0 127.0.0.2/8 alias + sudo ifconfig lo0 127.0.0.3/8 alias + sudo ifconfig lo0 127.0.0.4/8 alias + sudo ifconfig lo0 127.0.0.5/8 alias +fi diff --git a/ci/test-11-nopriv.pl b/ci/test-11-nopriv.pl index 5b24a32..87802fe 100755 --- a/ci/test-11-nopriv.pl +++ b/ci/test-11-nopriv.pl @@ -1,6 +1,13 @@ #!/usr/bin/perl -w -use Test::Command tests => 6; +use Test::Command; +use Test::More; + +if( $^O eq 'darwin' ) { + plan skip_all => 'Test irrelevant on MacOS'; + exit 0; +} +plan tests => 6; # run without privileges my $fping_bin = `which fping`; chomp $fping_bin; diff --git a/ci/test-13-unknown-host.pl b/ci/test-13-unknown-host.pl index d4abb2a..ee0c850 100755 --- a/ci/test-13-unknown-host.pl +++ b/ci/test-13-unknown-host.pl @@ -7,7 +7,7 @@ use Test::Command tests => 6; my $cmd = Test::Command->new(cmd => "fping nosuchname.example.com"); $cmd->exit_is_num(1); $cmd->stdout_is_eq(""); -$cmd->stderr_is_eq("nosuchname.example.com: Name or service not known\n"); +$cmd->stderr_like(qr{^nosuchname\.example\.com: (Name or service not known|nodename nor servname provided, or not known)\n}); } # fping6 @@ -15,5 +15,5 @@ $cmd->stderr_is_eq("nosuchname.example.com: Name or service not known\n"); my $cmd = Test::Command->new(cmd => "fping6 nosuchname.example.com"); $cmd->exit_is_num(1); $cmd->stdout_is_eq(""); -$cmd->stderr_is_eq("nosuchname.example.com: Name or service not known\n"); +$cmd->stderr_like(qr{^nosuchname\.example\.com: (Name or service not known|nodename nor servname provided, or not known)\n}); } diff --git a/ci/test-14-ping-internet-hosts.pl b/ci/test-14-ping-internet-hosts.pl index ec7f098..c7f8dd3 100755 --- a/ci/test-14-ping-internet-hosts.pl +++ b/ci/test-14-ping-internet-hosts.pl @@ -1,6 +1,15 @@ #!/usr/bin/perl -w -use Test::Command tests => 3; +use Test::Command; +use Test::More; + +# evaluate if we have internet +if(!gethostbyname("www.google.com")) { + plan skip_all => 'Can\'t resolve www.google.com -> no internet?'; + exit 0; +} + +plan tests => 18; my $re_num = qr{\d+(?:\.\d+)?}; @@ -15,3 +24,43 @@ www\.france-telecom\.fr\s*: xmt/rcv/%loss = [123]/3/\d+%, min/avg/max = $re_num/ www\.google\.com\s*: xmt/rcv/%loss = [123]/3/\d+%, min/avg/max = $re_num/$re_num/$re_num }); } + +# fping -A -n +{ +my $cmd = Test::Command->new(cmd => "fping -A -n 8.8.8.8"); +$cmd->exit_is_num(0); +$cmd->stdout_is_eq("google-public-dns-a.google.com (8.8.8.8) is alive\n"); +$cmd->stderr_is_eq(""); +} + +# fping -A -n +{ +my $cmd = Test::Command->new(cmd => "fping -A -n google-public-dns-a.google.com"); +$cmd->exit_is_num(0); +$cmd->stdout_is_eq("google-public-dns-a.google.com (8.8.8.8) is alive\n"); +$cmd->stderr_is_eq(""); +} + +# fping6 -A -n +{ +my $cmd = Test::Command->new(cmd => "fping6 -n -A 2001:4860:4860::8888"); +$cmd->exit_is_num(0); +$cmd->stdout_is_eq("google-public-dns-a.google.com (2001:4860:4860::8888) is alive\n"); +$cmd->stderr_is_eq(""); +} + +# fping -m +{ +my $cmd = Test::Command->new(cmd => "fping -m google-public-dns-a.google.com"); +$cmd->exit_is_num(0); +$cmd->stdout_is_eq("google-public-dns-a.google.com is alive\n"); +$cmd->stderr_is_eq(""); +} + +# fping -n +{ +my $cmd = Test::Command->new(cmd => "fping -n 8.8.8.8"); +$cmd->exit_is_num(0); +$cmd->stdout_is_eq("google-public-dns-a.google.com is alive\n"); +$cmd->stderr_is_eq(""); +} diff --git a/ci/test-4-options-a-b.pl b/ci/test-4-options-a-b.pl index 023f6f1..2288931 100755 --- a/ci/test-4-options-a-b.pl +++ b/ci/test-4-options-a-b.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -use Test::Command tests => 23; +use Test::Command tests => 14; use Test::More; use Time::HiRes qw(gettimeofday tv_interval); @@ -25,30 +25,6 @@ $cmd->stdout_is_eq("127.0.0.1 is alive\n"); $cmd->stderr_is_eq(""); } -# fping -A -n -{ -my $cmd = Test::Command->new(cmd => "fping -A -n 8.8.8.8"); -$cmd->exit_is_num(0); -$cmd->stdout_is_eq("google-public-dns-a.google.com (8.8.8.8) is alive\n"); -$cmd->stderr_is_eq(""); -} - -# fping -A -n -{ -my $cmd = Test::Command->new(cmd => "fping -A -n google-public-dns-a.google.com"); -$cmd->exit_is_num(0); -$cmd->stdout_is_eq("google-public-dns-a.google.com (8.8.8.8) is alive\n"); -$cmd->stderr_is_eq(""); -} - -# fping6 -A -n -{ -my $cmd = Test::Command->new(cmd => "fping6 -n -A 2001:4860:4860::8888"); -$cmd->exit_is_num(0); -$cmd->stdout_is_eq("google-public-dns-a.google.com (2001:4860:4860::8888) is alive\n"); -$cmd->stderr_is_eq(""); -} - # fping -b { my $cmd = Test::Command->new(cmd => "fping -b 1000 127.0.0.1"); @@ -63,7 +39,7 @@ my $t0 = [gettimeofday]; my $cmd = Test::Command->new(cmd => "fping -t 100 -r 3 -B 2 8.8.8.7"); $cmd->exit_is_num(1); $cmd->stdout_is_eq("8.8.8.7 is unreachable\n"); -$cmd->stderr_is_eq(""); +$cmd->stderr_like(qr{^(|(8.8.8.7: error while sending ping: No route to host\n)+)$}); my $elapsed = tv_interval($t0); # 0.1 + 0.2 + 0.4 + 0.8 = 1.5 cmp_ok($elapsed, '>=', 1.5); diff --git a/ci/test-7-options-i-m.pl b/ci/test-7-options-i-m.pl index 74ab9f2..e4529d9 100755 --- a/ci/test-7-options-i-m.pl +++ b/ci/test-7-options-i-m.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -use Test::Command tests => 7; +use Test::Command tests => 4; # -i n interval between sending ping packets (in millisec) (default 25) # -l loop sending pings forever @@ -22,10 +22,4 @@ $cmd->stdout_like(qr{127\.0\.0\.1 : \[0\], 84 bytes, 0\.\d+ ms \(0.\d+ avg, 0% l }); } -# fping -m -{ -my $cmd = Test::Command->new(cmd => "fping -m google-public-dns-a.google.com"); -$cmd->exit_is_num(0); -$cmd->stdout_is_eq("google-public-dns-a.google.com is alive\n"); -$cmd->stderr_is_eq(""); -} +# fping -m -> test-14-internet-hosts diff --git a/ci/test-8-options-n-q.pl b/ci/test-8-options-n-q.pl index 2737dd3..66630b8 100755 --- a/ci/test-8-options-n-q.pl +++ b/ci/test-8-options-n-q.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -use Test::Command tests => 12; +use Test::Command tests => 9; # -n show targets by name (-d is equivalent) # -O n set the type of service (tos) flag on the ICMP packets @@ -9,13 +9,7 @@ use Test::Command tests => 12; # -q quiet (don't show per-target/per-ping results) # -Q n same as -q, but show summary every n seconds -# fping -n -{ -my $cmd = Test::Command->new(cmd => "fping -n 8.8.8.8"); -$cmd->exit_is_num(0); -$cmd->stdout_is_eq("google-public-dns-a.google.com is alive\n"); -$cmd->stderr_is_eq(""); -} +# fping -n -> test-14-internet-hosts # fping -O {