1 # Test to make sure hires feature works.
5 unless ($ENV{PERL_TEST_Net_Ping}) {
6 print "1..0 # Skip: network dependent test\n";
10 unless (eval "require Socket") {
11 print "1..0 \# Skip: no Socket\n";
14 unless (eval "require Time::HiRes") {
15 print "1..0 \# Skip: no Time::HiRes\n";
18 unless (getservbyname('echo', 'tcp')) {
19 print "1..0 \# Skip: no echo port\n";
24 use Test qw(plan ok $TESTERR);
28 # Everything loaded fine
31 my $p = new Net::Ping "tcp";
36 # Default is to not use Time::HiRes
37 ok !$Net::Ping::hires;
43 # Make sure disable works
45 ok !$Net::Ping::hires;
51 # Test on the default port
52 my ($ret, $duration) = $p -> ping("localhost");
54 # localhost should always be reachable, right?
57 # It is extremely likely that the duration contains a decimal
58 # point if Time::HiRes is functioning properly, except when it
59 # is fast enough to be "0", or slow enough to be exactly "1".
60 if (! ok($duration =~ /\.|^[01]$/)) {
61 print($TESTERR "# duration=[$duration]\n");