5 unless(&Time::HiRes::d_usleep) {
7 Test::More::plan(skip_all => "no usleep()");
11 use Test::More tests => 6;
12 BEGIN { push @INC, '.' }
15 eval { Time::HiRes::usleep(-2) };
16 like $@, qr/::usleep\(-2\): negative time not invented yet/,
17 "negative time error";
19 my $limit = 0.25; # 25% is acceptable slosh for testing timers
22 Time::HiRes::usleep(10_000);
24 Time::HiRes::usleep(10_000);
25 my $three = CORE::time;
26 ok $one == $two || $two == $three
27 or print("# slept too long, $one $two $three\n");
30 skip "no gettimeofday", 1 unless &Time::HiRes::d_gettimeofday;
31 my $f = Time::HiRes::time();
32 Time::HiRes::usleep(500_000);
33 my $f2 = Time::HiRes::time();
35 ok $d > 0.4 && $d < 0.9 or print("# slept $d secs $f to $f2\n");
39 skip "no gettimeofday", 1 unless &Time::HiRes::d_gettimeofday;
40 my $r = [ Time::HiRes::gettimeofday() ];
41 Time::HiRes::sleep( 0.5 );
42 my $f = Time::HiRes::tv_interval $r;
43 ok $f > 0.4 && $f < 0.9 or print("# slept $f instead of 0.5 secs.\n");
47 skip "no gettimeofday", 2 unless &Time::HiRes::d_gettimeofday;
51 my $sleep = 1.5; # seconds
54 $t0 = Time::HiRes::gettimeofday();
55 $a = abs(Time::HiRes::sleep($sleep) / $sleep - 1.0);
56 $td = Time::HiRes::gettimeofday() - $t0;
59 $msg = "$td went by while sleeping $sleep, ratio $ratio.\n";
62 skip $msg, 1 unless $td < $sleep * (1 + $limit);
63 ok $a < $limit or print("# $msg\n");
66 $t0 = Time::HiRes::gettimeofday();
67 $a = abs(Time::HiRes::usleep($sleep * 1E6) / ($sleep * 1E6) - 1.0);
68 $td = Time::HiRes::gettimeofday() - $t0;
71 $msg = "$td went by while sleeping $sleep, ratio $ratio.\n";
74 skip $msg, 1 unless $td < $sleep * (1 + $limit);
75 ok $a < $limit or print("# $msg\n");