summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2001-04-15 12:36:33 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2001-04-15 12:36:33 +0000
commit3c72ec0095d5296c829ece3ce089509b7f8a14ab (patch)
tree979a581701e6430c4c0b930699f6517c3bbcb8bc /t
parent395f5a0c58fdd0dd8fdb730226bfff2dca9e4587 (diff)
downloadperl-3c72ec0095d5296c829ece3ce089509b7f8a14ab.tar.gz
Add interval timer (setitimer, getitimer) support to Time::HiRes.
p4raw-id: //depot/perl@9705
Diffstat (limited to 't')
-rw-r--r--t/lib/time-hires.t39
1 files changed, 36 insertions, 3 deletions
diff --git a/t/lib/time-hires.t b/t/lib/time-hires.t
index 50c20f09ca..1e68acfb4b 100644
--- a/t/lib/time-hires.t
+++ b/t/lib/time-hires.t
@@ -3,7 +3,7 @@ BEGIN {
@INC = '../lib';
}
-BEGIN { $| = 1; print "1..17\n"; }
+BEGIN { $| = 1; print "1..19\n"; }
END {print "not ok 1\n" unless $loaded;}
@@ -23,6 +23,8 @@ import Time::HiRes 'gettimeofday' if $have_gettimeofday;
import Time::HiRes 'usleep' if $have_usleep;
import Time::HiRes 'ualarm' if $have_ualarm;
+use Config;
+
sub skip {
map { print "ok $_ (skipped)\n" } @_;
}
@@ -161,16 +163,47 @@ unless (defined &Time::HiRes::gettimeofday
{
alarm(2.5);
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 $_ # skipped\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, 3, 0.5)), "\n";
+
+ print "# getitimer: ", join(" ", getitimer(ITIMER_VIRTUAL)), "\n";
+
+ while ($i) {
+ my $j; $j++ for 1..1000;
+ }
+
+ print "# getitimer: ", join(" ", getitimer(ITIMER_VIRTUAL)), "\n";
+
+ $SIG{VTALRM} = 'DEFAULT';
+}
+