test-stat-time: port to mingw
authorEric Blake <ebb9@byu.net>
Tue, 13 Oct 2009 15:16:16 +0000 (09:16 -0600)
committerEric Blake <ebb9@byu.net>
Wed, 14 Oct 2009 12:25:27 +0000 (06:25 -0600)
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>
ChangeLog
doc/pastposix-functions/usleep.texi
tests/test-stat-time.c

index 1c48c1b..da30191 100644 (file)
--- 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/*
index 507395c..bb38152 100644 (file)
@@ -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
index 97a719a..3a0aafc 100644 (file)
 
 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]);