From 20bdd2f41cb9d43df6dd0cfe361ac73a0e8148f9 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Tue, 13 Oct 2009 09:16:16 -0600 Subject: [PATCH] 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 --- ChangeLog | 10 ++++++++++ doc/pastposix-functions/usleep.texi | 6 +++++- tests/test-stat-time.c | 20 ++++++++++++-------- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1c48c1b78..da301919b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-10-14 Eric Blake + + 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 use AC_CHECK_FUNCS_ONCE, not AC_CHECK_FUNCS in modules/* diff --git a/doc/pastposix-functions/usleep.texi b/doc/pastposix-functions/usleep.texi index 507395c65..bb381520a 100644 --- a/doc/pastposix-functions/usleep.texi +++ b/doc/pastposix-functions/usleep.texi @@ -14,9 +14,13 @@ Portability problems not fixed by Gnulib: @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 diff --git a/tests/test-stat-time.c b/tests/test-stat-time.c index 97a719ac8..3a0aafccc 100644 --- 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 @@ nap (void) 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 @@ nap (void) { /* 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 @@ nap (void) && 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 @@ test_mtime (const struct stat *statinfo, struct timespec *modtimes) 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 @@ test_birthtime (const struct stat *statinfo, { int i; - /* Collect the birth times.. */ + /* Collect the birth times. */ for (i = 0; i < NFILES; ++i) { birthtimes[i] = get_stat_birthtime (&statinfo[i]); -- 2.11.0