source: trunk/essentials/dev-lang/perl/t/op/alarm.t

Last change on this file was 3181, checked in by bird, 18 years ago

perl 5.8.8

File size: 1.3 KB
Line 
1#!./perl
2
3BEGIN {
4 chdir 't';
5 @INC = '../lib';
6 require './test.pl';
7}
8
9BEGIN {
10 use Config;
11 if( !$Config{d_alarm} ) {
12 skip_all("alarm() not implemented on this platform");
13 }
14}
15
16plan tests => 5;
17my $Perl = which_perl();
18
19my $start_time = time;
20eval {
21 local $SIG{ALRM} = sub { die "ALARM!\n" };
22 alarm 3;
23
24 # perlfunc recommends against using sleep in combination with alarm.
25 1 while (time - $start_time < 6);
26};
27alarm 0;
28my $diff = time - $start_time;
29
30# alarm time might be one second less than you said.
31is( $@, "ALARM!\n", 'alarm w/$SIG{ALRM} vs inf loop' );
32ok( abs($diff - 3) <= 1, " right time" );
33
34
35my $start_time = time;
36eval {
37 local $SIG{ALRM} = sub { die "ALARM!\n" };
38 alarm 3;
39 system(qq{$Perl -e "sleep 6"});
40};
41alarm 0;
42$diff = time - $start_time;
43
44# alarm time might be one second less than you said.
45is( $@, "ALARM!\n", 'alarm w/$SIG{ALRM} vs system()' );
46
47{
48 local $TODO = "Why does system() block alarm() on $^O?"
49 if $^O eq 'VMS' || $^O eq'MacOS' || $^O eq 'dos';
50 ok( abs($diff - 3) <= 1, " right time (waited $diff secs for 3-sec alarm)" );
51}
52
53
54{
55 local $SIG{"ALRM"} = sub { die };
56 eval { alarm(1); my $x = qx($Perl -e "sleep 3") };
57 chomp (my $foo = "foo\n");
58 ok($foo eq "foo", '[perl #33928] chomp() fails after alarm(), `sleep`');
59}
Note: See TracBrowser for help on using the repository browser.