diff options
author | Chris 'BinGOs' Williams <chris@bingosnet.co.uk> | 2017-09-22 11:15:28 +0100 |
---|---|---|
committer | Chris 'BinGOs' Williams <chris@bingosnet.co.uk> | 2017-09-22 11:45:48 +0100 |
commit | 8da080293c01461bf666873a6d2ee759f47052b0 (patch) | |
tree | 542a5d1bd10aa178d594f080fdfd9adbff52b0ed /dist/Time-HiRes | |
parent | fd481c1750298b9abda12a8359d56200a571a751 (diff) | |
download | perl-8da080293c01461bf666873a6d2ee759f47052b0.tar.gz |
Update Time-HiRes to CPAN version 1.9746
[DELTA]
1.9746 [2017-08-17]
- Unreliable t/usleep.t and t/utime.t tests [rt.cpan.org #122819]
Avoid testing for $dt = $t2 - $t1 and assuming $dt is less than
some value since a heavily loaded machine can delay the $t2.
Testing for greater than is fine.
- Tweak the configuring messages about subsecond stat/utime.
1.9745 [2017-08-14]
- Properly check for futimens/utimensat actually doing something.
This should handle 'gnukfreebsd' (which has only stubs, so far
we have been skipping the test) and as a new thing 'gnu' (Hurd)
(also only stubs). Thanks to Nigel Horne.
- Scan in t/utime.t whether the filesystem (wherever File::Temp
puts it tempfiles) supports subsecond timestamps. This removes
the fragile Linux/ext3 specific hack. As a side effect, the
setting of subsecond timestamps is tested only if reading of
them is supported. Thanks to Carsten Gaebler for the test idea,
and Ryan Voots for testing.
1.9744 [2017-07-27]
- add more potential clock constants, like CLOCK_MONOTONIC_FAST
(available in FreeBSD), and not all potentially found clock
constants were properly exported to be available from Perl,
see your system's clock_gettime() documentation for the available ones
1.9743 [2017-07-20]
- correct declared minimum Perl version (should be 5.6, was declared
as 5.8 since 1.9727_03): blead af94b3ac
- fix the fix for 'do file' to load hints in Makefile.PL: blead 3172fdbc
Diffstat (limited to 'dist/Time-HiRes')
-rw-r--r-- | dist/Time-HiRes/Changes | 31 | ||||
-rw-r--r-- | dist/Time-HiRes/HiRes.pm | 39 | ||||
-rw-r--r-- | dist/Time-HiRes/Makefile.PL | 118 | ||||
-rw-r--r-- | dist/Time-HiRes/t/usleep.t | 4 | ||||
-rw-r--r-- | dist/Time-HiRes/t/utime.t | 74 |
5 files changed, 170 insertions, 96 deletions
diff --git a/dist/Time-HiRes/Changes b/dist/Time-HiRes/Changes index eb85a2c8f9..10af55b79d 100644 --- a/dist/Time-HiRes/Changes +++ b/dist/Time-HiRes/Changes @@ -1,9 +1,34 @@ Revision history for the Perl extension Time::HiRes. -1.9743 +1.9746 [2017-08-17] + - Unreliable t/usleep.t and t/utime.t tests [rt.cpan.org #122819] + Avoid testing for $dt = $t2 - $t1 and assuming $dt is less than + some value since a heavily loaded machine can delay the $t2. + Testing for greater than is fine. + - Tweak the configuring messages about subsecond stat/utime. + +1.9745 [2017-08-14] + - Properly check for futimens/utimensat actually doing something. + This should handle 'gnukfreebsd' (which has only stubs, so far + we have been skipping the test) and as a new thing 'gnu' (Hurd) + (also only stubs). Thanks to Nigel Horne. + - Scan in t/utime.t whether the filesystem (wherever File::Temp + puts it tempfiles) supports subsecond timestamps. This removes + the fragile Linux/ext3 specific hack. As a side effect, the + setting of subsecond timestamps is tested only if reading of + them is supported. Thanks to Carsten Gaebler for the test idea, + and Ryan Voots for testing. + +1.9744 [2017-07-27] + - add more potential clock constants, like CLOCK_MONOTONIC_FAST + (available in FreeBSD), and not all potentially found clock + constants were properly exported to be available from Perl, + see your system's clock_gettime() documentation for the available ones + +1.9743 [2017-07-20] - correct declared minimum Perl version (should be 5.6, was declared - as 5.8 since 1.9727_03) - - fix the fix for 'do file' to load hints in Makefile.PL + as 5.8 since 1.9727_03): blead af94b3ac + - fix the fix for 'do file' to load hints in Makefile.PL: blead 3172fdbc 1.9742 [2017-04-16] - prefer 3-argument open: blead 1ae6ead9 diff --git a/dist/Time-HiRes/HiRes.pm b/dist/Time-HiRes/HiRes.pm index fbdc2b4aca..db6afb6879 100644 --- a/dist/Time-HiRes/HiRes.pm +++ b/dist/Time-HiRes/HiRes.pm @@ -9,18 +9,39 @@ require DynaLoader; our @ISA = qw(Exporter DynaLoader); our @EXPORT = qw( ); +# More or less this same list is in Makefile.PL. Should unify. our @EXPORT_OK = qw (usleep sleep ualarm alarm gettimeofday time tv_interval getitimer setitimer nanosleep clock_gettime clock_getres clock clock_nanosleep - CLOCK_BOOTTIME CLOCK_HIGHRES - CLOCK_MONOTONIC CLOCK_MONOTONIC_COARSE - CLOCK_MONOTONIC_PRECISE CLOCK_MONOTONIC_RAW + CLOCKS_PER_SEC + CLOCK_BOOTTIME + CLOCK_HIGHRES + CLOCK_MONOTONIC + CLOCK_MONOTONIC_COARSE + CLOCK_MONOTONIC_FAST + CLOCK_MONOTONIC_PRECISE + CLOCK_MONOTONIC_RAW CLOCK_PROCESS_CPUTIME_ID - CLOCK_REALTIME CLOCK_REALTIME_COARSE - CLOCK_REALTIME_FAST CLOCK_REALTIME_PRECISE - CLOCK_SECOND CLOCK_SOFTTIME CLOCK_THREAD_CPUTIME_ID - CLOCK_TIMEOFDAY CLOCKS_PER_SEC - ITIMER_REAL ITIMER_VIRTUAL ITIMER_PROF ITIMER_REALPROF + CLOCK_PROF + CLOCK_REALTIME + CLOCK_REALTIME_COARSE + CLOCK_REALTIME_FAST + CLOCK_REALTIME_PRECISE + CLOCK_REALTIME_RAW + CLOCK_SECOND + CLOCK_SOFTTIME + CLOCK_THREAD_CPUTIME_ID + CLOCK_TIMEOFDAY + CLOCK_UPTIME + CLOCK_UPTIME_COARSE + CLOCK_UPTIME_FAST + CLOCK_UPTIME_PRECISE + CLOCK_UPTIME_RAW + CLOCK_VIRTUAL + ITIMER_PROF + ITIMER_REAL + ITIMER_REALPROF + ITIMER_VIRTUAL TIMER_ABSTIME d_usleep d_ualarm d_gettimeofday d_getitimer d_setitimer d_nanosleep d_clock_gettime d_clock_getres d_hires_utime @@ -28,7 +49,7 @@ our @EXPORT_OK = qw (usleep sleep ualarm alarm gettimeofday time tv_interval stat lstat utime ); -our $VERSION = '1.9743'; +our $VERSION = '1.9746'; our $XS_VERSION = $VERSION; $VERSION = eval $VERSION; diff --git a/dist/Time-HiRes/Makefile.PL b/dist/Time-HiRes/Makefile.PL index 54f5cb43dd..e7ce9245ef 100644 --- a/dist/Time-HiRes/Makefile.PL +++ b/dist/Time-HiRes/Makefile.PL @@ -367,10 +367,14 @@ sub has_futimens { #include <sys/stat.h> int main(int argc, char** argv) { - int ret; - struct timespec ts[2]; - ret = futimens(0, ts); - ret == 0 ? exit(0) : exit(errno ? errno : -1); + int ret1, ret2; + struct timespec ts1[2], ts2[2]; + ret1 = futimens(0, ts1); + char buf[1]; + read(0, buf, 0); /* Assuming reading nothing updates atime (the [0]) */ + ret2 = futimens(0, ts2); + ret1 == 0 && ret2 == 0 && (ts1[0].tv_nsec != 0 || ts2[0].tv_nsec != 0) ? + exit(0) : exit(errno ? errno : -1); } EOM } @@ -385,10 +389,16 @@ sub has_utimensat{ #include <fcntl.h> int main(int argc, char** argv) { - int ret; - struct timespec ts[2]; - ret = utimensat(AT_FDCWD, 0, ts, 0); - ret == 0 ? exit(0) : exit(errno ? errno : -1); + int ret1, ret2; + struct timespec ts1[2], ts2[2]; + /* We make the brave but probably foolish assumption that systems + * modern enough to have utimensat also have the /dev/stdin. */ + ret1 = utimensat(AT_FDCWD, "/dev/stdin", ts1, 0); + char buf[1]; + read(0, buf, 0); /* Assuming reading nothing updates atime (the [0]) */ + ret2 = utimensat(AT_FDCWD, "/dev/stdin", ts2, 0); + ret1 == 0 && ret2 == 0 && (ts1[0].tv_nsec != 0 || ts2[0].tv_nsec != 0) ? + exit(0) : exit(errno ? errno : -1); } EOM } @@ -507,7 +517,7 @@ EOD if ($has_setitimer && $has_getitimer) { print "You have interval timers (both setitimer and getitimer).\n"; } else { - print "You do not have interval timers.\n"; + print "You do NOT have interval timers.\n"; } print "Looking for ualarm()... "; @@ -695,7 +705,7 @@ EOD print "NOT found.\n"; } - print "Looking for futimens()... "; + print "Looking for working futimens()... "; my $has_futimens; if (has_futimens()) { $has_futimens++; @@ -708,7 +718,7 @@ EOD print "NOT found.\n"; } - print "Looking for utimensat()... "; + print "Looking for working utimensat()... "; my $has_utimensat; if (has_utimensat()) { $has_utimensat++; @@ -721,8 +731,12 @@ EOD print "NOT found.\n"; } - if ($has_futimens or $has_utimensat) { + my $has_hires_utime = ($has_futimens || $has_utimensat); + if ($has_hires_utime) { $DEFINE .= ' -DTIME_HIRES_UTIME'; + print "You seem to have subsecond timestamp setting.\n"; + } else { + print "You do NOT seem to have subsecond timestamp setting.\n"; } print "Looking for stat() subsecond timestamps...\n"; @@ -838,14 +852,18 @@ EOM DEFINE('TIME_HIRES_STAT', 4); } elsif ($has_stat_st_uxtime) { DEFINE('TIME_HIRES_STAT', 5); - } + } - if ($DEFINE =~ /-DTIME_HIRES_STAT=\d+/) { - print "You seem to have stat() subsecond timestamps.\n"; - print "(Your struct stat has them, but the filesystems must help.)\n"; - } else { - print "You do not seem to have stat subsecond timestamps.\n"; - } + my $has_hires_stat = ($DEFINE =~ /-DTIME_HIRES_STAT=(\d+)/) ? $1 : 0; + if ($has_hires_stat) { + print "You seem to have subsecond timestamp reading.\n"; + print "(Your struct stat has them, but the filesystems must help.)\n"; + unless ($has_hires_utime) { + print "However, you do NOT seem to have subsecond timestamp setting.\n"; + } + } else { + print "You do NOT seem to have subsecond timestamp reading.\n"; + } my $has_w32api_windows_h; @@ -948,31 +966,38 @@ sub doMakefile { sub doConstants { if (eval {require ExtUtils::Constant; 1}) { + # More or less this same list is in HiRes.pm. Should unify. my @names = qw( - CLOCKS_PER_SEC - CLOCK_BOOTTIME - CLOCK_HIGHRES - CLOCK_MONOTONIC - CLOCK_MONOTONIC_COARSE - CLOCK_MONOTONIC_PRECISE - CLOCK_MONOTONIC_RAW - CLOCK_PROCESS_CPUTIME_ID - CLOCK_REALTIME - CLOCK_REALTIME_COARSE - CLOCK_REALTIME_FAST - CLOCK_REALTIME_PRECISE - CLOCK_SECOND - CLOCK_SOFTTIME - CLOCK_THREAD_CPUTIME_ID - CLOCK_TIMEOFDAY - CLOCK_UPTIME - CLOCK_UPTIME_FAST - CLOCK_UPTIME_PRECISE - ITIMER_PROF - ITIMER_REAL - ITIMER_REALPROF - ITIMER_VIRTUAL - TIMER_ABSTIME + CLOCKS_PER_SEC + CLOCK_BOOTTIME + CLOCK_HIGHRES + CLOCK_MONOTONIC + CLOCK_MONOTONIC_COARSE + CLOCK_MONOTONIC_FAST + CLOCK_MONOTONIC_PRECISE + CLOCK_MONOTONIC_RAW + CLOCK_PROF + CLOCK_PROCESS_CPUTIME_ID + CLOCK_REALTIME + CLOCK_REALTIME_COARSE + CLOCK_REALTIME_FAST + CLOCK_REALTIME_PRECISE + CLOCK_REALTIME_RAW + CLOCK_SECOND + CLOCK_SOFTTIME + CLOCK_THREAD_CPUTIME_ID + CLOCK_TIMEOFDAY + CLOCK_UPTIME + CLOCK_UPTIME_COARSE + CLOCK_UPTIME_FAST + CLOCK_UPTIME_PRECISE + CLOCK_UPTIME_RAW + CLOCK_VIRTUAL + ITIMER_PROF + ITIMER_REAL + ITIMER_REALPROF + ITIMER_VIRTUAL + TIMER_ABSTIME ); foreach (qw (d_usleep d_ualarm d_gettimeofday d_getitimer d_setitimer d_nanosleep d_clock_gettime d_clock_getres @@ -982,15 +1007,14 @@ sub doConstants { if ($macro =~ /^(d_nanosleep|d_clock)$/) { $macro =~ s/^d_(.+)/TIME_HIRES_\U$1/; } elsif ($macro =~ /^(d_hires_stat)$/) { - my $d_hires_stat = 0; - $d_hires_stat = $1 if ($DEFINE =~ /-DTIME_HIRES_STAT=(\d+)/); + my $d_hires_stat = $1 if ($DEFINE =~ /-DTIME_HIRES_STAT=(\d+)/); push @names, {name => $_, macro => "TIME_HIRES_STAT", value => $d_hires_stat, default => ["IV", "0"]}; next; } elsif ($macro =~ /^(d_hires_utime)$/) { my $d_hires_utime = - ($DEFINE =~ /-DHAS_FUTIMENS/ || - $DEFINE =~ /-DHAS_UTIMENSAT/) ? 1 : 0; + ($DEFINE =~ /-DHAS_FUTIMENS/ || + $DEFINE =~ /-DHAS_UTIMENSAT/); push @names, {name => $_, macro => "TIME_HIRES_UTIME", value => $d_hires_utime, default => ["IV", "0"]}; next; diff --git a/dist/Time-HiRes/t/usleep.t b/dist/Time-HiRes/t/usleep.t index 9322458b80..bb66cbe62c 100644 --- a/dist/Time-HiRes/t/usleep.t +++ b/dist/Time-HiRes/t/usleep.t @@ -32,7 +32,7 @@ SKIP: { Time::HiRes::usleep(500_000); my $f2 = Time::HiRes::time(); my $d = $f2 - $f; - ok $d > 0.4 && $d < 0.9 or print("# slept $d secs $f to $f2\n"); + ok $d > 0.49 or print("# slept $d secs $f to $f2\n"); } SKIP: { @@ -40,7 +40,7 @@ SKIP: { my $r = [ Time::HiRes::gettimeofday() ]; Time::HiRes::sleep( 0.5 ); my $f = Time::HiRes::tv_interval $r; - ok $f > 0.4 && $f < 0.9 or print("# slept $f instead of 0.5 secs.\n"); + ok $f > 0.49 or print("# slept $f instead of 0.5 secs.\n"); } SKIP: { diff --git a/dist/Time-HiRes/t/utime.t b/dist/Time-HiRes/t/utime.t index 22fd48e703..7821837f8e 100644 --- a/dist/Time-HiRes/t/utime.t +++ b/dist/Time-HiRes/t/utime.t @@ -1,5 +1,32 @@ use strict; +sub has_subsecond_file_times { + require File::Temp; + require Time::HiRes; + my ($fh, $filename) = File::Temp::tempfile( "Time-HiRes-utime-XXXXXXXXX" ); + use File::Basename qw[dirname]; + my $dirname = dirname($filename); + require Cwd; + $dirname = &Cwd::getcwd if $dirname eq '.'; + print(STDERR "\n# Testing for subsecond file timestamps (mtime) in $dirname\n"); + close $fh; + my @mtimes; + for (1..2) { + open $fh, '>', $filename; + print $fh "foo"; + close $fh; + push @mtimes, (Time::HiRes::stat($filename))[9]; + Time::HiRes::sleep(.1) if $_ == 1; + } + my $delta = $mtimes[1] - $mtimes[0]; + # print STDERR "mtimes = @mtimes, delta = $delta\n"; + unlink $filename; + my $ok = $delta > 0 && $delta < 1; + printf(STDERR "# Subsecond file timestamps in $dirname: %s\n", + $ok ? "OK" : "NO"); + return $ok; +} + BEGIN { require Time::HiRes; require Test::More; @@ -7,43 +34,19 @@ BEGIN { unless(&Time::HiRes::d_hires_utime) { Test::More::plan(skip_all => "no hires_utime"); } + unless(&Time::HiRes::d_hires_stat) { + # Being able to read subsecond timestamps is a reasonable + # prerequisite for being able to write them. + Test::More::plan(skip_all => "no hires_stat"); + } unless (&Time::HiRes::d_futimens) { Test::More::plan(skip_all => "no futimens()"); } unless (&Time::HiRes::d_utimensat) { Test::More::plan(skip_all => "no utimensat()"); } - if ($^O eq 'gnukfreebsd') { - Test::More::plan(skip_all => "futimens() and utimensat() not working in $^O"); - } - if ($^O eq 'linux' && -e '/proc/mounts') { - # The linux might be wrong when ext3 - # is available in other operating systems, - # but then we need other methods for detecting - # the filesystem type of the tempfiles. - my ($fh, $fn) = File::Temp::tempfile( "Time-HiRes-utime-XXXXXXXXX", UNLINK => 1); - sub getfstype { - my ($fn) = @_; - my $cmd = "df $fn"; - open(my $df, '-|', $cmd) or die "$cmd: $!"; - my @df = <$df>; # Assume $df[0] is header line. - my $dev = +(split(" ", $df[1]))[0]; - open(my $mounts, '<', '/proc/mounts') or die "/proc/mounts: $!"; - while (<$mounts>) { - my @m = split(" "); - if ($m[0] eq $dev) { return $m[2] } - } - return; - } - my $fstype = getfstype($fn); - unless (defined $fstype) { - warn "Unknown fstype for $fn\n"; - } else { - print "# fstype = $fstype\n"; - if ($fstype eq 'ext3' || $fstype eq 'ext2') { - Test::More::plan(skip_all => "fstype $fstype has no subsecond timestamps in $^O"); - } - } + unless (has_subsecond_file_times()) { + Test::More::plan(skip_all => "No subsecond file timestamps"); } } @@ -106,17 +109,18 @@ print "# utime undef sets time to now\n"; my ($fh2, $filename2) = tempfile( "Time-HiRes-utime-XXXXXXXXX", UNLINK => 1 ); my $now = Time::HiRes::time; + sleep(1); is Time::HiRes::utime(undef, undef, $filename1, $fh2), 2, "Two files changed"; { my ($got_atime, $got_mtime) = ( Time::HiRes::stat($fh1) )[8, 9]; - cmp_ok abs( $got_atime - $now), '<', 0.1, "File 1 atime set correctly"; - cmp_ok abs( $got_mtime - $now), '<', 0.1, "File 1 mtime set correctly"; + cmp_ok $got_atime, '>=', $now, "File 1 atime set correctly"; + cmp_ok $got_mtime, '>=', $now, "File 1 mtime set correctly"; } { my ($got_atime, $got_mtime) = ( Time::HiRes::stat($filename2) )[8, 9]; - cmp_ok abs( $got_atime - $now), '<', 0.1, "File 2 atime set correctly"; - cmp_ok abs( $got_mtime - $now), '<', 0.1, "File 2 mtime set correctly"; + cmp_ok $got_atime, '>=', $now, "File 2 atime set correctly"; + cmp_ok $got_mtime, '>=', $now, "File 2 mtime set correctly"; } }; |