1 # Test to make sure hires feature works.
5 unless ($ENV{PERL_TEST_Net_Ping}) {
6 print "1..0 # Skip: network dependent test\n";
12 unless (eval "require Socket") {
13 print "1..0 \# Skip: no Socket\n";
16 unless (eval "require Time::HiRes") {
17 print "1..0 \# Skip: no Time::HiRes\n";
20 unless (getservbyname('echo', 'tcp')) {
21 print "1..0 \# Skip: no echo port\n";
26 use Test qw(plan ok $TESTERR);
30 # Everything loaded fine
33 my $p = new Net::Ping "tcp";
38 # Default is to not use Time::HiRes
39 ok !$Net::Ping::hires;
45 # Make sure disable works
47 ok !$Net::Ping::hires;
53 # Test on the default port
54 my ($ret, $duration) = $p -> ping("localhost");
56 # localhost should always be reachable, right?
59 # It is extremely likely that the duration contains a decimal
60 # point if Time::HiRes is functioning properly, except when it
61 # is fast enough to be "0", or slow enough to be exactly "1".
62 if (! ok($duration =~ /\.|^[01]$/)) {
63 print($TESTERR "# duration=[$duration]\n");