This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
update Time-HiRes to CPAN version 1.9725
[perl5.git] / cpan / Time-HiRes / t / stat.t
CommitLineData
90e44bf6
Z
1use strict;
2
3BEGIN {
4 require Time::HiRes;
5 unless(&Time::HiRes::d_hires_stat) {
6 require Test::More;
7 Test::More::plan(skip_all => "no hi-res stat");
8 }
9 if($^O =~ /\A(?:cygwin|MSWin)/) {
10 require Test::More;
11 Test::More::plan(skip_all =>
12 "$^O file timestamps not reliable enough for stat test");
13 }
14}
15
858dcda5 16use Test::More 0.82 tests => 16;
90e44bf6
Z
17use t::Watchdog;
18
19my $limit = 0.25; # 25% is acceptable slosh for testing timers
20
90e44bf6
Z
21my @atime;
22my @mtime;
23for (1..5) {
24 Time::HiRes::sleep(rand(0.1) + 0.1);
25 open(X, ">$$");
26 print X $$;
27 close(X);
858dcda5
Z
28 my($a, $stat, $b) = ("a", [Time::HiRes::stat($$)], "b");
29 is $a, "a";
30 is $b, "b";
31 is ref($stat), "ARRAY";
32 push @mtime, $stat->[9];
90e44bf6
Z
33 Time::HiRes::sleep(rand(0.1) + 0.1);
34 open(X, "<$$");
35 <X>;
36 close(X);
858dcda5
Z
37 $stat = [Time::HiRes::stat($$)];
38 push @atime, $stat->[8];
90e44bf6
Z
39}
401 while unlink $$;
41note "mtime = @mtime";
42note "atime = @atime";
43my $ai = 0;
44my $mi = 0;
45my $ss = 0;
46for (my $i = 1; $i < @atime; $i++) {
47 if ($atime[$i] >= $atime[$i-1]) {
48 $ai++;
49 }
50 if ($atime[$i] > int($atime[$i])) {
51 $ss++;
52 }
53}
54for (my $i = 1; $i < @mtime; $i++) {
55 if ($mtime[$i] >= $mtime[$i-1]) {
56 $mi++;
57 }
58 if ($mtime[$i] > int($mtime[$i])) {
59 $ss++;
60 }
61}
62note "ai = $ai, mi = $mi, ss = $ss";
63# Need at least 75% of monotonical increase and
64# 20% of subsecond results. Yes, this is guessing.
65SKIP: {
66 skip "no subsecond timestamps detected", 1 if $ss == 0;
67 ok $mi/(@mtime-1) >= 0.75 && $ai/(@atime-1) >= 0.75 &&
68 $ss/(@mtime+@atime) >= 0.2;
69}
70
711;