Mailing List Archive

User mollified, modifies test script...
Thanks to Nick for showing me how BSD-ish sleep vs SYSV-ish sleep made the
previous test script run incorrectly (a SYSV sleep interrupted by an alarm
doesn't send the SIGALRM until a second after it's interrupted). Enclosed is
yet another modification of the original test script, with a new test #3
inserted in the middle, that (ta-daah!) fails on the HP perl5.0001m, that
otherwise passes all the packaged 'make test' suite! Output looks like-

[18] % ./perl ~yhluchan/yhtest/perltest
1..5
ok 1
ok 2
Alarm clock
[19] %




#!perl

print "1..5\n";

# Test the alarm mechanism

sub alarm_handler {++$wentoff;}
$SIG{'ALRM'}='alarm_handler';
alarm 2;
$interval = sleep 5;

if ($interval >= 2 && $interval <= 3) {print "ok 1\n";}
else {print "not ok 1 '$interval' should be 2 or 3 seconds\n";}

select(undef, undef, undef, 1.1); # For BSD-ish sleeps

if ($wentoff) {print "ok 2\n";}
else {print "not ok 2 The alarm signal handler was not called.\n";}

# Can alarm and select live together in harmony?
alarm 1;
select(undef, undef, undef, 1.1);
if ($wentoff == 2) {print "ok 3\n";}
else {print "not ok 3 The alarm handler wasn't called twice, even though the
alarm was called twice.\n"}

# Do some testing of select (and time)

$start = time;
($num, $timeleft) = select (undef, undef, undef, 1.5);
$interval = time - $start;

if ($timeleft == 1.5 || $timeleft == 0) {print "ok 4\n";}
else {print "not ok 3 '$timeleft' should be 0 or 1.5 seconds\n";}

if ($interval >= 1 && $interval <= 2) {print "ok 5\n";}
else {print "not ok 4 select should have waited between 1 and 2 seconds, not
$interval seconds\n";}