1 # Test to make sure alarm / SIGALM does not interfere
2 # with Net::Ping. (This test was derived to ensure
3 # compatibility with the "spamassassin" utility.)
4 # Based on code written by radu@netsoft.ro (Radu Greab).
8 unless ($ENV{PERL_TEST_Net_Ping}) {
9 print "1..0 \# Skip: network dependent test\n";
13 unless (eval "require Socket") {
14 print "1..0 \# Skip: no Socket\n";
17 unless (eval {alarm 0; 1;}) {
18 print "1..0 \# Skip: alarm borks on $^O $^X $] ?\n";
21 unless (getservbyname('echo', 'tcp')) {
22 print "1..0 \# Skip: no echo port\n";
40 local $SIG{ALRM} = sub { die "alarm works" };
41 ok 1; # SIGALRM can be set on this platform
43 ok 1; # alarm() can be set on this platform
47 my $ping = Net::Ping->new("tcp", 2);
48 # It does not matter if alive or not
49 $ping->ping("127.0.0.1");
50 $ping->ping("172.29.249.249");
51 die "alarm failed" if time > $start + $timeout + 1;
54 # Got out of "infinite loop" okay
57 # Make sure it died for a good excuse
58 ok $@ =~ /alarm works/ or die $@;
60 alarm 0; # Reset alarm