#!/usr/bin/perl
#
# In general we trust %Config, but for nanosleep() this trust
-# may be misplaces (it may be linkable but not really functional).
+# may be misplaced (it may be linkable but not really functional).
# Use $ENV{FORCE_NANOSLEEP_SCAN} to force rescanning whether there
# really is hope.
}
sub has_nanosleep {
- print "Trying out nanosleep... ";
+ print "testing... ";
return 1 if
try_compile_and_link(<<EOM, run => 1);
#include <time.h>
print "Looking for nanosleep()... ";
my $has_nanosleep;
- if (exists $Config{d_nanosleep} && !$ENV{FORCE_NANOSLEEP_SCAN}) {
- # Believe $Config{d_nanosleep}.
+ if ($ENV{FORCE_NANOSLEEP_SCAN}) {
+ print "forced scan... ";
+ if (has_nanosleep()) {
+ $has_nanosleep++;
+ $DEFINE .= ' -DTIME_HIRES_NANOSLEEP';
+ }
+ }
+ elsif (exists $Config{d_nanosleep}) {
+ print "believing \$Config{d_nanosleep}... ";
if ($Config{d_nanosleep}) {
$has_nanosleep++;
$DEFINE .= ' -DTIME_HIRES_NANOSLEEP';
}
- } elsif ($^O ne 'mpeix' && # MPE/iX falsely finds nanosleep.
- has_nanosleep()) {
- $has_nanosleep++;
- $DEFINE .= ' -DTIME_HIRES_NANOSLEEP';
+ } elsif ($^O =~ /^(mpeix)$/) {
+ # MPE/iX falsely finds nanosleep from its libc equivalent.
+ print "skipping because in $^O... ";
+ } else {
+ if (has_nanosleep()) {
+ $has_nanosleep++;
+ $DEFINE .= ' -DTIME_HIRES_NANOSLEEP';
+ }
}
if ($has_nanosleep) {
}
}
-BEGIN { $| = 1; print "1..28\n"; }
+BEGIN { $| = 1; print "1..29\n"; }
END { print "not ok 1\n" unless $loaded }
my $have_ualarm = defined &Time::HiRes::ualarm;
my $have_time = defined &Time::HiRes::time;
+printf "# have_gettimeofday = %d\n", $have_gettimeofday;
+printf "# have_usleep = %d\n", $have_usleep;
+printf "# have_nanosleep = %d\n", $have_nanosleep;
+printf "# have_ualarm = %d\n", $have_ualarm;
+printf "# have_time = %d\n", $have_time;
+
import Time::HiRes 'gettimeofday' if $have_gettimeofday;
import Time::HiRes 'usleep' if $have_usleep;
import Time::HiRes 'nanosleep' if $have_nanosleep;
my $have_alarm = $Config{d_alarm};
my $have_fork = $Config{d_fork};
-my $waitfor = 60; # 10 seconds is normal.
-my $pid;
+my $waitfor = 60; # 10-20 seconds is normal (load affects this).
+my $timer_pid;
if ($have_fork) {
- print "# I am process $$, starting the timer process\n";
- if (defined ($pid = fork())) {
- if ($pid == 0) { # We are the kid, set up the timer.
- print "# I am timer process $$\n";
+ print "# I am the main process $$, starting the timer process...\n";
+ $timer_pid = fork();
+ if (defined $timer_pid) {
+ if ($timer_pid == 0) { # We are the kid, set up the timer.
+ print "# I am the timer process $$, sleeping for $waitfor seconds...\n";
sleep($waitfor);
- warn "\n$0: overall time allowed for tests (${waitfor}s) exceeded\n";
- print "# Terminating the testing process\n";
+ warn "\n$0: overall time allowed for tests (${waitfor}s) exceeded!\n";
+ print "# Terminating the main process...\n";
kill('TERM', getppid());
- print "# Timer process exiting\n";
+ print "# This is the timer process $$, over and out.\n";
exit(0);
+ } else {
+ print "# Timer process $timer_pid launched, continuing testing...\n";
}
} else {
warn "$0: fork failed: $!\n";
}
} else {
- print "# No timer process\n";
+ print "# No timer process (need fork)\n";
}
my $xdefine = '';
}
}
-if (!$have_gettimeofday) {
+unless ($have_gettimeofday) {
skip 2..6;
}
else {
ok 6, $f - $two[0] < 2, "$f - $two[0] >= 2";
}
-if (!$have_usleep) {
+unless ($have_usleep) {
skip 7..8;
}
else {
my $three = time;
ok 7, $one == $two || $two == $three, "slept too long, $one $two $three";
- if (!$have_gettimeofday) {
+ unless ($have_gettimeofday) {
skip 8;
}
else {
ok 9, abs($f - 5.4) < 0.001, $f;
}
-if (!$have_gettimeofday) {
+unless ($have_gettimeofday) {
skip 10;
}
else {
ok 10, $f < 2, $f;
}
-if (!$have_usleep || !$have_gettimeofday) {
+unless ($have_usleep && $have_gettimeofday) {
skip 11;
}
else {
ok 11, $f > 0.4 && $f < 0.9, "slept $f instead of 0.5 secs.";
}
-if (!$have_ualarm || !$have_alarm) {
+unless ($have_ualarm && $have_alarm) {
skip 12..13;
}
else {
# Did we even get close?
-if (!$have_time) {
+unless ($have_time) {
skip 14;
} else {
my ($s, $n, $i) = (0);
}
}
-if (!$have_nanosleep) {
+unless ($have_nanosleep) {
skip 22..23;
}
else {
my $three = CORE::time;
ok 22, $one == $two || $two == $three, "slept too long, $one $two $three";
- if (!$have_gettimeofday) {
+ unless ($have_gettimeofday) {
skip 23;
}
else {
skip 28;
}
-if (defined $pid) {
- print "# I am process $$, terminating the timer process $pid\n";
- kill('TERM', $pid); # We are done, the timer can go.
- unlink("ktrace.out");
+if ($have_ualarm && $] >= 5.008001) {
+ # http://groups.google.com/group/perl.perl5.porters/browse_thread/thread/adaffaaf939b042e/20dafc298df737f0%2320dafc298df737f0?sa=X&oi=groupsr&start=0&num=3
+ # Perl changes [18765] and [18770], perl bug [perl #20920]
+ use Time::HiRes qw(alarm);
+ $SIG{ALRM} = sub { 1 for 1..100000 };
+ alarm(0.01, 0.01);
+ sleep(1);
+ print "ok 29\n"; # Not core dumping by now is considered to be the success.
+} else {
+ skip 29;
+}
+
+END {
+ if (defined $timer_pid) {
+ print "# I am the main process $$, terminating the timer process $timer_pid.\n";
+ kill('TERM', $timer_pid); # We are done, the timer can go.
+ unlink("ktrace.out"); # Used in BSD system call tracing.
+ print "# All done.\n";
+ }
}