11 if( !$Config{d_alarm} ) {
12 skip_all("alarm() not implemented on this platform");
17 my $Perl = which_perl();
19 my ($start_time, $end_time);
22 local $SIG{ALRM} = sub { $end_time = time; die "ALARM!\n" };
26 # perlfunc recommends against using sleep in combination with alarm.
27 1 while (($end_time = time) - $start_time < 6);
31 my $diff = $end_time - $start_time;
33 # alarm time might be one second less than you said.
34 is( $@, "ALARM!\n", 'alarm w/$SIG{ALRM} vs inf loop' );
35 ok( abs($diff - 3) <= 1, " right time (waited $diff secs for 3-sec alarm)" );
39 local $SIG{ALRM} = sub { $end_time = time; die "ALARM!\n" };
42 system(qq{$Perl -e "sleep 6"});
47 $diff = $end_time - $start_time;
49 # alarm time might be one second less than you said.
50 is( $@, "ALARM!\n", 'alarm w/$SIG{ALRM} vs system()' );
53 local $TODO = "Why does system() block alarm() on $^O?"
54 if $^O eq 'VMS' || $^O eq 'dos';
55 ok( abs($diff - 3) <= 1, " right time (waited $diff secs for 3-sec alarm)" );
60 local $SIG{"ALRM"} = sub { die };
61 eval { alarm(1); my $x = qx($Perl -e "sleep 3"); alarm(0); };
62 chomp (my $foo = "foo\n");
63 ok($foo eq "foo", '[perl #33928] chomp() fails after alarm(), `sleep`');