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