1N/A chdir 't' if -d 't'; 1N/A print "# Testing process $$\n"; 1N/A print "# Starting the timer process\n"; 1N/A if ($pid == 0) { # We are the kid, set up the timer. 1N/A print "# Timer process $$\n"; 1N/A warn "\n$0: overall time allowed for tests (${waitfor}s) exceeded\n"; 1N/A print "# Terminating the testing process\n"; 1N/A print "# Timer process exiting\n"; 1N/A print "# No timer process\n"; 1N/A# Ideally, we'd like to test that the timers are rather precise. 1N/A# However, if the system is busy, there are no guarantees on how 1N/A# quickly we will return. This limit used to be 10%, but that 1N/A# was occasionally triggered falsely. 1N/A# Another possibility might be to print "ok" if the test completes fine 1N/A# with (say) 10% slosh, "skip - system may have been busy?" if the test 1N/A# completes fine with (say) 30% slosh, and fail otherwise. If you do that, 1N/A# consider changing over to test.pl at the same time. 1N/Amy $limit =
0.20;
# 20% is acceptable slosh for testing timers 1N/A map { print "ok $_ # skipped\n" } @_; 1N/A print "not ok $n\n"; 1N/A ok 2, @one == 2, 'gettimeofday returned ', 0+@one, ' args'; 1N/A "@two is not greater than @one"; 1N/A ok 8, $d > 0.4 && $d < 0.9, "slept $d secs $f to $f2"; 1N/A# Two-arg tv_interval() is always available. 1N/A ok 11, $f > 0.4 && $f < 0.9, "slept $f instead of 0.5 secs."; 1N/A# new test: did we even get close? 1N/A for my $i (1 .. 100) { 1N/A # $s should be, at worst, equal to $n 1N/A # (time() may be rounding down, up, or closest) 1N/A ok 14, abs($s) / $n <= 1.0, "Time::HiRes::time() not close to time()"; 1N/A print "# s = $s, n = $n, s/n = ", $s/$n, "\n"; 1N/A print "ok $_ # Skip: no gettimeofday or no ualarm or no usleep\n"; 1N/A print "# time...$f\n"; 1N/A # Whether select() gets restarted after signals is 1N/A # implementation dependent. If it is restarted, we 1N/A # will get about 3.3 seconds: 3 from the select, 0.3 1N/A # from the alarm. If this happens, let's just skip 1N/A # this particular test. --jhi 1N/A $ok = "Skip: your select() may get restarted by your SIGALRM (or just retry test)"; 1N/A # This test is more sensitive, so impose a softer limit. 1N/A # This test is more sensitive, so impose a softer limit. 1N/A && eval 'Time::HiRes::ITIMER_VIRTUAL' 1N/A print "ok $_ # Skip: no virtual interval timers\n"; 1N/A # Assume interval timer granularity of $limit * 0.5 seconds. Too bold? 1N/A for (1..1000) { $j++ } # Can't be unbreakable, must test getitimer(). 1N/A print "ok $_ # Skip: no gettimeofday\n"; 1N/A "ok 22\n" : "not ok 22\n"; 1N/A "ok 23\n" : "not ok 23\n"; 1N/A "ok 24\n" : "not ok 24\n"; 1N/A "ok 25\n" : "not ok 25\n"; 1N/A print "# Terminating the timer process $pid\n"; 1N/A kill('TERM', $pid); # We are done, the timer can go.