sub has_symbol {
my $symbol = shift;
- eval "import Time::HiRes qw($symbol)";
+ eval "use Time::HiRes qw($symbol)";
return 0 unless $@ eq '';
- return exists &{"Time::HiRes::$symbol"};
+ eval "my \$a = $symbol";
+ return $@ eq '';
}
printf "# have_gettimeofday = %d\n", $have_gettimeofday;
use Config;
+use Time::HiRes qw(gettimeofday);
+
my $have_alarm = $Config{d_alarm};
my $have_fork = $Config{d_fork};
my $waitfor = 60; # 10-20 seconds is normal (load affects this).
skip 7..8;
}
else {
+ use Time::HiRes qw(usleep);
my $one = time;
usleep(10_000);
my $two = time;
skip 11;
}
else {
- my $r = [gettimeofday()];
+ my $r = [ gettimeofday() ];
Time::HiRes::sleep( 0.5 );
my $f = tv_interval $r;
ok 11, $f > 0.4 && $f < 0.9, "slept $f instead of 0.5 secs.";
$SIG{VTALRM} = 'DEFAULT';
}
-if ($have_gettimeofday) {
+if ($have_gettimeofday &&
+ $have_usleep) {
+ use Time::HiRes qw(usleep);
+
my ($t0, $td);
my $sleep = 1.5; # seconds
# 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 "not ok 30 # dt = $dt, rt = $rt\n";
+ my $ok = 0;
+ TRY: {
+ for my $try (1..3) {
+ print "# CLOCK_REALTIME: try = $try\n";
+ 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);
+ print "# dt = $dt, rt = $rt\n";
+ if ($rt <= 2 * $limit) {
+ $ok = 1;
+ last TRY;
+ }
+ } else {
+ print "# Error: t0 = $t0, t1 = $t1\n";
+ }
+ my $r = rand() + rand();
+ printf "# Sleeping for %.6f seconds...\n";
+ sleep($r);
}
+ }
+ if ($ok) {
+ print "ok 30\n";
} else {
- print "# Error: t0 = $t0, t1 = $t1\n";
- skip 30;
+ print "not ok 30\n";
}
} else {
print "# No clock_gettime\n";