From: Steve Peters Date: Sat, 5 Nov 2005 12:55:47 +0000 (+0000) Subject: Upgrade to Time-HiRes-1.81 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b311af6269bf99f73d9dd17d28dfefaec9fc7ec4;p=p5sagit%2Fp5-mst-13.2.git Upgrade to Time-HiRes-1.81 p4raw-id: //depot/perl@26014 --- diff --git a/ext/Time/HiRes/Changes b/ext/Time/HiRes/Changes index 91abfe4..391753a 100644 --- a/ext/Time/HiRes/Changes +++ b/ext/Time/HiRes/Changes @@ -1,5 +1,35 @@ Revision history for Perl extension Time::HiRes. +1.81 [2005-10-05] + - try to be more robust and consistent in the detection of + CLOCK_REALTIME and ITIMER_VIRTUAL in HiRes.t: the proper + way is + + sub has_symbol { + my $symbol = shift; + eval 'import Time::HiRes qw($symbol)'; + return 0 unless $@ eq ''; + return exists ${"Time::HiRes::$symbol"}; + } + + and then use + + &FOO_BAR + + in the test. All these moves are needed because + + 1) one cannot directly do eval 'Time::HiRes::FOO_BAR' + because FOO_BAR might have a true value of zero + (or in the general case an empty string or even undef) + + 2) In case FOO_BAR is not available in this platform, + &FOO_BAR avoids the bareword warning + + - wait more (1.5 seconds instead of 0.1) for the CLOCK_REALTIME test + but expect the 'customary' slop of 0.20 instead of 0.25 + - fixed inside a comment HAS_POLL -> TIME_HIRES_NANOSLEEP + - at the end of HiRest.t tell how close we were to termination + 1.80 [2005-10-04] - Gisle noticed a mistake (using HAS_NANOSLEEP) in 1.79 diff --git a/ext/Time/HiRes/HiRes.pm b/ext/Time/HiRes/HiRes.pm index 6dac141..2f781d3 100644 --- a/ext/Time/HiRes/HiRes.pm +++ b/ext/Time/HiRes/HiRes.pm @@ -17,7 +17,7 @@ require DynaLoader; d_usleep d_ualarm d_gettimeofday d_getitimer d_setitimer d_nanosleep d_clock_gettime d_clock_getres); -$VERSION = '1.80'; +$VERSION = '1.81'; $XS_VERSION = $VERSION; $VERSION = eval $VERSION; diff --git a/ext/Time/HiRes/HiRes.xs b/ext/Time/HiRes/HiRes.xs index 2463531..201e99f 100644 --- a/ext/Time/HiRes/HiRes.xs +++ b/ext/Time/HiRes/HiRes.xs @@ -423,7 +423,7 @@ hrt_usleep(unsigned long usec) nanosleep(&tsa, NULL); } -#endif /* #if !defined(HAS_USLEEP) && defined(HAS_POLL) */ +#endif /* #if !defined(HAS_USLEEP) && defined(TIME_HIRES_NANOSLEEP) */ #if !defined(HAS_USLEEP) && defined(HAS_POLL) #define HAS_USLEEP diff --git a/ext/Time/HiRes/t/HiRes.t b/ext/Time/HiRes/t/HiRes.t index 25a97b5..efa8ba6 100644 --- a/ext/Time/HiRes/t/HiRes.t +++ b/ext/Time/HiRes/t/HiRes.t @@ -31,6 +31,13 @@ my $have_ualarm = &Time::HiRes::d_ualarm; my $have_clock_gettime = &Time::HiRes::d_clock_gettime; my $have_clock_getres = &Time::HiRes::d_clock_getres; +sub has_symbol { + my $symbol = shift; + eval "import Time::HiRes qw($symbol)"; + return 0 unless $@ eq ''; + return exists &{"Time::HiRes::$symbol"}; +} + printf "# have_gettimeofday = %d\n", $have_gettimeofday; printf "# have_usleep = %d\n", $have_usleep; printf "# have_nanosleep = %d\n", $have_nanosleep; @@ -51,6 +58,7 @@ my $have_alarm = $Config{d_alarm}; my $have_fork = $Config{d_fork}; my $waitfor = 60; # 10-20 seconds is normal (load affects this). my $timer_pid; +my $TheEnd; if ($have_fork) { print "# I am the main process $$, starting the timer process...\n"; @@ -65,7 +73,8 @@ if ($have_fork) { print "# This is the timer process $$, over and out.\n"; exit(0); } else { - print "# Timer process $timer_pid launched, continuing testing...\n"; + print "# The timer process $timer_pid launched, continuing testing...\n"; + $TheEnd = time() + $waitfor; } } else { warn "$0: fork failed: $!\n"; @@ -285,41 +294,39 @@ unless ( defined &Time::HiRes::gettimeofday unless ( defined &Time::HiRes::setitimer && defined &Time::HiRes::getitimer - && eval 'use Time::HiRes qw(ITIMER_VIRTUAL); print ITIMER_VIRTUAL' - && $Config{d_select} - && $Config{d_select} + && has_symbol('ITIMER_VIRTUAL') && $Config{sig_name} =~ m/\bVTALRM\b/) { for (18..19) { print "ok $_ # Skip: no virtual interval timers\n"; } } else { - use Time::HiRes qw (setitimer getitimer ITIMER_VIRTUAL); + 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); + $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 $limit * 0.5 seconds. Too bold? - my $virt = getitimer(ITIMER_VIRTUAL); + my $virt = getitimer(&ITIMER_VIRTUAL); print "not " unless defined $virt && abs($virt / 0.5) - 1 < $limit; print "ok 18\n"; print "# getitimer: ", join(" ", getitimer(ITIMER_VIRTUAL)), "\n"; - while (getitimer(ITIMER_VIRTUAL)) { + while (getitimer(&ITIMER_VIRTUAL)) { my $j; for (1..1000) { $j++ } # Can't be unbreakable, must test getitimer(). } print "# getitimer: ", join(" ", getitimer(ITIMER_VIRTUAL)), "\n"; - $virt = getitimer(ITIMER_VIRTUAL); + $virt = getitimer(&ITIMER_VIRTUAL); print "not " unless defined $virt && $virt == 0; print "ok 19\n"; @@ -456,6 +463,8 @@ if ($have_ualarm && $] >= 5.008001) { # one bug that caused a core dump on reentering the handler. This bug # was fixed by the time of Perl 5.8.1. + # Do not try mixing sleep() and alarm() for testing this. + my $a = 0; # Number of alarms we receive. my $A = 2; # Number of alarms we will handle before disarming. # (We may well get $A + 1 alarms.) @@ -477,30 +486,26 @@ if ($have_ualarm && $] >= 5.008001) { skip 29; } -if ($have_clock_gettime) { - # All implementations are SUPPOSED TO support CLOCK_REALTIME... - eval 'use Time::HiRes qw(CLOCK_REALTIME)'; - unless ($@) { - my $t0 = clock_gettime(&CLOCK_REALTIME); - use Time::HiRes qw(sleep); - my $T = 0.1; - sleep($T); - my $t1 = clock_gettime(&CLOCK_REALTIME); - if ($t0 > 0 && $t1) { - print "# t1 = $t1, t0 = $t0\n"; - my $dt = $t1 - $t0; - my $rt = abs(1 - $dt / $T); - if ($rt <= 0.25) { # Allow 25% jitter. - print "ok 30 # dt = $dt, r = $rt\n"; - } else { - print "not ok 30 # dt = $dt, rt = $rt\n"; - } +if ($have_clock_gettime && + # All implementations of clock_gettime() + # are SUPPOSED TO support CLOCK_REALTIME. + has_symbol('CLOCK_REALTIME')) { + my $t0 = clock_gettime(&CLOCK_REALTIME); + use Time::HiRes qw(sleep); + my $T = 1.5; + sleep($T); + my $t1 = clock_gettime(&CLOCK_REALTIME); + if ($t0 > 0 && $t1 > $t0) { + print "# t1 = $t1, t0 = $t0\n"; + my $dt = $t1 - $t0; + my $rt = abs(1 - $dt / $T); + if ($rt <= $limit) { + print "ok 30 # dt = $dt, r = $rt\n"; } else { - print "# Error '$!'\n"; - skip 30; + print "not ok 30 # dt = $dt, rt = $rt\n"; } } else { - print "# No CLOCK_REALTIME ($@)\n"; + print "# Error: t0 = $t0, t1 = $t1\n"; skip 30; } } else { @@ -522,7 +527,8 @@ if ($have_clock_getres) { END { if (defined $timer_pid) { - print "# I am the main process $$, terminating the timer process $timer_pid.\n"; + my $left = $TheEnd - time(); + printf "# I am the main process $$, terminating the timer process $timer_pid\n# before it terminates me in %d seconds (testing took %d seconds).\n", $left, $waitfor - $left; kill('TERM', $timer_pid); # We are done, the timer can go. unlink("ktrace.out"); # Used in BSD system call tracing. print "# All done.\n";