@INC = '../lib';
}
-BEGIN { $| = 1; print "1..17\n"; }
+BEGIN { $| = 1; print "1..19\n"; }
END {print "not ok 1\n" unless $loaded;}
import Time::HiRes 'usleep' if $have_usleep;
import Time::HiRes 'ualarm' if $have_ualarm;
+use Config;
+
sub skip {
map { print "ok $_ (skipped)\n" } @_;
}
{
my $t = time();
my $tf = Time::HiRes::time();
- ok 14, ($tf >= $t) && (($tf - $t) <= 1),
+ ok 14, (abs($tf - $t) <= 1),
"time $t differs from Time::HiRes::time $tf";
}
$SIG{ALRM} = "tick";
while ($i)
{
- alarm(2.5);
+ alarm(0.3);
select (undef, undef, undef, 10);
- print "# Select returned! ", Time::HiRes::tv_interval ($r), "\n";
+ print "# Select returned! $i ", Time::HiRes::tv_interval ($r), "\n";
}
sub tick
{
- print "# Tick! ", Time::HiRes::tv_interval ($r), "\n";
$i--;
+ print "# Tick! $i ", Time::HiRes::tv_interval ($r), "\n";
}
$SIG{ALRM} = 'DEFAULT';
print "ok 17\n";
}
+unless (defined &Time::HiRes::setitimer
+ && defined &Time::HiRes::getitimer
+ && exists &Time::HiRes::ITIMER_VIRTUAL
+ && $Config{d_select}) {
+ for (18..19) {
+ print "ok $_ # Skip: no virtual interval timers\n";
+ }
+} else {
+ use Time::HiRes qw (setitimer getitimer ITIMER_VIRTUAL);
+
+ my $i = 3;
+ my $r = [Time::HiRes::gettimeofday];
+
+ $SIG{VTALRM} = sub {
+ $i ? $i-- : setitimer(ITIMER_VIRTUAL, 0);
+ print "# Tick! $i ", Time::HiRes::tv_interval($r), "\n";
+ };
+
+ print "# setitimer: ", join(" ", setitimer(ITIMER_VIRTUAL, 0.5, 0.4)), "\n";
+
+ # Assume interval timer granularity of 0.05 seconds. Too bold?
+ print "not " unless abs(getitimer(ITIMER_VIRTUAL) / 0.5) - 1 < 0.1;
+ print "ok 18\n";
+
+ print "# getitimer: ", join(" ", getitimer(ITIMER_VIRTUAL)), "\n";
+
+ while (getitimer(ITIMER_VIRTUAL)) {
+ my $j; $j++ for 1..1000; # Can't be unbreakable, must test getitimer().
+ }
+
+ print "# getitimer: ", join(" ", getitimer(ITIMER_VIRTUAL)), "\n";
+
+ print "not " unless getitimer(ITIMER_VIRTUAL) == 0;
+ print "ok 19\n";
+
+ $SIG{VTALRM} = 'DEFAULT';
+}
+