blob: 0dfc6611fdb2dc651cb58047b8b370edf1a50174 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
#!./perl
BEGIN {
chdir 't';
@INC = '../lib';
require './test.pl';
}
BEGIN {
use Config;
if( !$Config{d_alarm} ) {
skip_all("alarm() not implemented on this platform");
}
}
plan tests => 4;
my $Perl = which_perl();
my $start_time = time;
eval {
local $SIG{ALRM} = sub { die "ALARM!\n" };
alarm 3;
# perlfunc recommends against using sleep in combination with alarm.
1 while (time - $start_time < 6);
};
alarm 0;
my $diff = time - $start_time;
# alarm time might be one second less than you said.
is( $@, "ALARM!\n", 'alarm w/$SIG{ALRM} vs inf loop' );
ok( $diff == 3 || $diff == 2, ' right time' );
my $start_time = time;
eval {
local $SIG{ALRM} = sub { die "ALARM!\n" };
alarm 3;
system(qq{$Perl -e "sleep 6"});
};
alarm 0;
$diff = time - $start_time;
# alarm time might be one second less than you said.
is( $@, "ALARM!\n", 'alarm w/$SIG{ALRM} vs system()' );
TODO: {
local $TODO = "alarm() can't stop a system call with \$SIG{ALRM} set";
ok( $diff == 3 || $diff == 2, ' right time' );
}
|