Mercurial > hg > octave-lojdl > gnulib-hg
changeset 12167:c314d472dca7
test-stat-time: port to mingw
Newer mingw has usleep, but it rejects arguments over 1000000
without sleeping. And since stat has no visibility into
sub-second resolutions, it meant all the timestamps ended up
identical. Fixed by restoring the 8 seconds of sleep, as
well as working around the documented unlink issue.
* tests/test-stat-time.c (force_unlink): Return a value.
(test_ctime) [W32]: Fix compilation error.
(nap): Don't call usleep with too large an argument. Use
force_unlink.
* doc/pastposix-functions/usleep.texi (usleep): Document the
portability issue.
Signed-off-by: Eric Blake <ebb9@byu.net>
author | Eric Blake <ebb9@byu.net> |
---|---|
date | Tue, 13 Oct 2009 09:16:16 -0600 |
parents | d943ffe46edc |
children | 7ea363404f65 |
files | ChangeLog doc/pastposix-functions/usleep.texi tests/test-stat-time.c |
diffstat | 3 files changed, 27 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-10-14 Eric Blake <ebb9@byu.net> + + test-stat-time: port to mingw + * tests/test-stat-time.c (force_unlink): Return a value. + (test_ctime) [W32]: Fix compilation error. + (nap): Don't call usleep with too large an argument. Use + force_unlink. + * doc/pastposix-functions/usleep.texi (usleep): Document the + portability issue. + 2009-10-13 Jim Meyering <meyering@redhat.com> use AC_CHECK_FUNCS_ONCE, not AC_CHECK_FUNCS in modules/*
--- a/doc/pastposix-functions/usleep.texi +++ b/doc/pastposix-functions/usleep.texi @@ -14,9 +14,13 @@ @itemize @item This function is missing on some platforms: -IRIX 5.3, Solaris 2.4, mingw, BeOS. +IRIX 5.3, Solaris 2.4, older mingw, BeOS. @item According to POSIX, the @code{usleep} function may interfere with the program's use of the @code{SIGALRM} signal. On Linux, it doesn't; on other platforms, it may. +@item +On some systems, @code{usleep} rejects attempts to sleep longer than 1 +second, as allowed by POSIX: +mingw. @end itemize
--- a/tests/test-stat-time.c +++ b/tests/test-stat-time.c @@ -41,13 +41,13 @@ enum { NFILES = 4 }; -static void +static int force_unlink (const char *filename) { /* This chmod is necessary on mingw, where unlink() of a read-only file fails with EPERM. */ chmod (filename, 0600); - unlink (filename); + return unlink (filename); } static void @@ -110,11 +110,12 @@ differ, repeat the test one more time (in case we crossed a quantization boundary on a file system with 1 second resolution). If we can't observe a difference in only the - nanoseconds, then fall back to 2 seconds. */ + nanoseconds, then fall back to 2 seconds. However, note that + usleep (2000000) is allowed to fail with EINVAL. */ struct stat st1; struct stat st2; ASSERT (stat ("t-stt-stamp1", &st1) == 0); - ASSERT (unlink ("t-stt-stamp1") == 0); + ASSERT (force_unlink ("t-stt-stamp1") == 0); delay = 15000; usleep (delay); create_file ("t-stt-stamp1"); @@ -123,7 +124,7 @@ { /* Seconds differ, give it one more shot. */ st1 = st2; - ASSERT (unlink ("t-stt-stamp1") == 0); + ASSERT (force_unlink ("t-stt-stamp1") == 0); usleep (delay); create_file ("t-stt-stamp1"); ASSERT (stat ("t-stt-stamp1", &st2) == 0); @@ -132,7 +133,10 @@ && get_stat_mtime_ns (&st1) < get_stat_mtime_ns (&st2))) delay = 2000000; } - usleep (delay); + if (delay == 2000000) + sleep (2); + else + usleep (delay); #endif /* HAVE_USLEEP */ } @@ -204,7 +208,7 @@ st_ctime is either the same as st_mtime (plus or minus an offset) or set to the file _creation_ time, and is not influenced by rename or chmod. */ -# define test_ctime ((void) 0) +# define test_ctime(ignored) ((void) 0) #else static void test_ctime (const struct stat *statinfo) @@ -229,7 +233,7 @@ { int i; - /* Collect the birth times.. */ + /* Collect the birth times. */ for (i = 0; i < NFILES; ++i) { birthtimes[i] = get_stat_birthtime (&statinfo[i]);