Hi- I had a question a while back about sleeping and selecting on the HP
versus Sun, and got back an answer on how BSD's sleep differs from SYS V's. I
came up with an improved test script that exits on test 3 on the HP platform
perl5.001m that otherwise passes all other tests- runs OK under SunOS. I think
I posted this updated test already, but didn't get a response. This could have
somthing to do with our HP platform, I've only ever logged on to install perl,
one perl program, and this script!
---- cut here ----
#!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";}
versus Sun, and got back an answer on how BSD's sleep differs from SYS V's. I
came up with an improved test script that exits on test 3 on the HP platform
perl5.001m that otherwise passes all other tests- runs OK under SunOS. I think
I posted this updated test already, but didn't get a response. This could have
somthing to do with our HP platform, I've only ever logged on to install perl,
one perl program, and this script!
---- cut here ----
#!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";}