check_ping.t 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #! /usr/bin/perl -w -I ..
  2. #
  3. # Ping Response Tests via check_ping
  4. #
  5. # $Id$
  6. #
  7. use strict;
  8. use Test;
  9. use NPTest;
  10. use vars qw($tests);
  11. BEGIN {$tests = 6; plan tests => $tests}
  12. my $successOutput = '/PING (ok|OK) - Packet loss = +[0-9]{1,2}\%, +RTA = [\.0-9]+ ms/';
  13. my $failureOutput = '/Packet loss = +[0-9]{1,2}\%, +RTA = [\.0-9]+ ms/';
  14. my $host_responsive = getTestParameter( "host_responsive", "NP_HOST_RESPONSIVE", "localhost",
  15. "The hostname of system responsive to network requests" );
  16. my $host_nonresponsive = getTestParameter( "host_nonresponsive", "NP_HOST_NONRESPONSIVE", "10.0.0.1",
  17. "The hostname of system not responsive to network requests" );
  18. my $hostname_invalid = getTestParameter( "hostname_invalid", "NP_HOSTNAME_INVALID", "nosuchhost",
  19. "An invalid (not known to DNS) hostname" );
  20. my $t;
  21. $t += checkCmd( "./check_ping $host_responsive 100 100 1000 1000 -p 1", 0, $successOutput );
  22. $t += checkCmd( "./check_ping $host_responsive 0 0 0 0 -p 1", 2, $failureOutput );
  23. $t += checkCmd( "./check_ping $host_nonresponsive 0 0 0 0 -p 1 -to 1", 2 );
  24. $t += checkCmd( "./check_ping $hostname_invalid 0 0 0 0 -p 1 -to 1", 3 );
  25. exit(0) if defined($Test::Harness::VERSION);
  26. exit($tests - $t);