test-utimens: avoid spurious failure
authorEric Blake <ebb9@byu.net>
Mon, 21 Dec 2009 14:00:13 +0000 (07:00 -0700)
committerEric Blake <ebb9@byu.net>
Mon, 21 Dec 2009 14:02:45 +0000 (07:02 -0700)
Fixes a spurious failure on ext3, with one-second resolution,
now that ctime effects are being tested for inequality.

* tests/test-chown.h (nap): Factor...
* tests/nap.h: ...into new file.
* tests/test-lchown.h (nap): Avoid duplication.
* tests/test-utimens-common.h (nap): Use shared implementation,
necessary on file systems with 1-second resolution.
* modules/chown-tests (Files): Include new file.
* modules/fdutimensat-tests (Files): Likewise.
* modules/futimens-tests (Files): Likewise.
* modules/lchown-tests (Files): Likewise.
* modules/openat-tests (Files): Likewise.
* modules/utimens-tests (Files): Likewise.
* modules/utimensat-tests (Files): Likewise.

Signed-off-by: Eric Blake <ebb9@byu.net>
12 files changed:
ChangeLog
modules/chown-tests
modules/fdutimensat-tests
modules/futimens-tests
modules/lchown-tests
modules/openat-tests
modules/utimens-tests
modules/utimensat-tests
tests/nap.h [new file with mode: 0644]
tests/test-chown.h
tests/test-lchown.h
tests/test-utimens-common.h

index eb560d5..5dd41d1 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2009-12-21  Eric Blake  <ebb9@byu.net>
+
+       test-utimens: avoid spurious failure
+       * tests/test-chown.h (nap): Factor...
+       * tests/nap.h: ...into new file.
+       * tests/test-lchown.h (nap): Avoid duplication.
+       * tests/test-utimens-common.h (nap): Use shared implementation,
+       necessary on file systems with 1-second resolution.
+       * modules/chown-tests (Files): Include new file.
+       * modules/fdutimensat-tests (Files): Likewise.
+       * modules/futimens-tests (Files): Likewise.
+       * modules/lchown-tests (Files): Likewise.
+       * modules/openat-tests (Files): Likewise.
+       * modules/utimens-tests (Files): Likewise.
+       * modules/utimensat-tests (Files): Likewise.
+
 2009-12-19  Eric Blake  <ebb9@byu.net>
 
        futimens, utimensat: work around Linux bug
index a5d5c3a..d1add61 100644 (file)
@@ -1,4 +1,5 @@
 Files:
+tests/nap.h
 tests/test-chown.h
 tests/test-chown.c
 
index 75ff374..16cf82c 100644 (file)
@@ -1,4 +1,5 @@
 Files:
+tests/nap.h
 tests/test-futimens.h
 tests/test-lutimens.h
 tests/test-utimens.h
index 2f57c3b..c768c33 100644 (file)
@@ -1,4 +1,5 @@
 Files:
+tests/nap.h
 tests/test-futimens.h
 tests/test-utimens-common.h
 tests/test-futimens.c
index 8b71e75..7e4d502 100644 (file)
@@ -1,4 +1,5 @@
 Files:
+tests/nap.h
 tests/test-lchown.h
 tests/test-lchown.c
 
index e604ca4..7265fd9 100644 (file)
@@ -1,4 +1,5 @@
 Files:
+tests/nap.h
 tests/test-chown.h
 tests/test-lchown.h
 tests/test-lstat.h
index 6a2d161..5bf14c2 100644 (file)
@@ -1,4 +1,5 @@
 Files:
+tests/nap.h
 tests/test-futimens.h
 tests/test-lutimens.h
 tests/test-utimens.h
index ded7f74..a56bb3e 100644 (file)
@@ -1,4 +1,5 @@
 Files:
+tests/nap.h
 tests/test-lutimens.h
 tests/test-utimens.h
 tests/test-utimens-common.h
diff --git a/tests/nap.h b/tests/nap.h
new file mode 100644 (file)
index 0000000..e8b4f5a
--- /dev/null
@@ -0,0 +1,67 @@
+/* Assist in file system timestamp tests.
+   Copyright (C) 2009 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+/* Written by Eric Blake <ebb9@byu.net>, 2009.  */
+
+#ifndef GLTEST_NAP_H
+# define GLTEST_NAP_H
+
+/* Sleep long enough to notice a timestamp difference on the file
+   system in the current directory.  Assumes that BASE is defined,
+   and requires that the test module depends on usleep.  */
+static void
+nap (void)
+{
+  static long delay;
+  if (!delay)
+    {
+      /* Initialize only once, by sleeping for 20 milliseconds (needed
+         since xfs has a quantization of about 10 milliseconds, even
+         though it has a granularity of 1 nanosecond, and since NTFS
+         has a default quantization of 15.25 milliseconds, even though
+         it has a granularity of 100 nanoseconds).  If the seconds
+         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 1 second if the time is odd,
+         and 2 seconds (needed for FAT) if time is even.  */
+      struct stat st1;
+      struct stat st2;
+      ASSERT (close (creat (BASE "tmp", 0600)) == 0);
+      ASSERT (stat (BASE "tmp", &st1) == 0);
+      ASSERT (unlink (BASE "tmp") == 0);
+      delay = 20000;
+      usleep (delay);
+      ASSERT (close (creat (BASE "tmp", 0600)) == 0);
+      ASSERT (stat (BASE "tmp", &st2) == 0);
+      ASSERT (unlink (BASE "tmp") == 0);
+      if (st1.st_mtime != st2.st_mtime)
+        {
+          /* Seconds differ, give it one more shot.  */
+          st1 = st2;
+          usleep (delay);
+          ASSERT (close (creat (BASE "tmp", 0600)) == 0);
+          ASSERT (stat (BASE "tmp", &st2) == 0);
+          ASSERT (unlink (BASE "tmp") == 0);
+        }
+      if (! (st1.st_mtime == st2.st_mtime
+             && get_stat_mtime_ns (&st1) < get_stat_mtime_ns (&st2)))
+        delay = (st1.st_mtime & 1) ? 1000000 : 2000000;
+    }
+  usleep (delay);
+}
+
+#endif /* GLTEST_NAP_H */
index c4e652a..62e612e 100644 (file)
 
 /* Written by Eric Blake <ebb9@byu.net>, 2009.  */
 
-#define TEST_CHOWN_NAP
-/* Sleep long enough to notice a timestamp difference on the file
-   system in the current directory.  */
-static void
-nap (void)
-{
-  static long delay;
-  if (!delay)
-    {
-      /* Initialize only once, by sleeping for 20 milliseconds (needed
-         since xfs has a quantization of about 10 milliseconds, even
-         though it has a granularity of 1 nanosecond, and since NTFS
-         has a default quantization of 15.25 milliseconds, even though
-         it has a granularity of 100 nanoseconds).  If the seconds
-         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 1 second if the time is odd,
-         and 2 seconds (needed for FAT) if time is even.  */
-      struct stat st1;
-      struct stat st2;
-      ASSERT (close (creat (BASE "tmp", 0600)) == 0);
-      ASSERT (stat (BASE "tmp", &st1) == 0);
-      ASSERT (unlink (BASE "tmp") == 0);
-      delay = 20000;
-      usleep (delay);
-      ASSERT (close (creat (BASE "tmp", 0600)) == 0);
-      ASSERT (stat (BASE "tmp", &st2) == 0);
-      ASSERT (unlink (BASE "tmp") == 0);
-      if (st1.st_mtime != st2.st_mtime)
-        {
-          /* Seconds differ, give it one more shot.  */
-          st1 = st2;
-          usleep (delay);
-          ASSERT (close (creat (BASE "tmp", 0600)) == 0);
-          ASSERT (stat (BASE "tmp", &st2) == 0);
-          ASSERT (unlink (BASE "tmp") == 0);
-        }
-      if (! (st1.st_mtime == st2.st_mtime
-             && get_stat_mtime_ns (&st1) < get_stat_mtime_ns (&st2)))
-        delay = (st1.st_mtime & 1) ? 1000000 : 2000000;
-    }
-  usleep (delay);
-}
+#include "nap.h"
 
 #if !HAVE_GETEGID
 # define getegid() ((gid_t) -1)
index 93a657c..26f80f7 100644 (file)
 
 /* Written by Eric Blake <ebb9@byu.net>, 2009.  */
 
-#ifndef TEST_CHOWN_NAP
-/* Sleep long enough to notice a timestamp difference on the file
-   system in the current directory.  */
-static void
-nap (void)
-{
-  static long delay;
-  if (!delay)
-    {
-      /* Initialize only once, by sleeping for 20 milliseconds (needed
-         since xfs has a quantization of about 10 milliseconds, even
-         though it has a granularity of 1 nanosecond, and since NTFS
-         has a default quantization of 15.25 milliseconds, even though
-         it has a granularity of 100 nanoseconds).  If the seconds
-         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 1 second if the time is odd,
-         and 2 seconds (needed for FAT) if time is even.  */
-      struct stat st1;
-      struct stat st2;
-      ASSERT (close (creat (BASE "tmp", 0600)) == 0);
-      ASSERT (stat (BASE "tmp", &st1) == 0);
-      ASSERT (unlink (BASE "tmp") == 0);
-      delay = 20000;
-      usleep (delay);
-      ASSERT (close (creat (BASE "tmp", 0600)) == 0);
-      ASSERT (stat (BASE "tmp", &st2) == 0);
-      ASSERT (unlink (BASE "tmp") == 0);
-      if (st1.st_mtime != st2.st_mtime)
-        {
-          /* Seconds differ, give it one more shot.  */
-          st1 = st2;
-          usleep (delay);
-          ASSERT (close (creat (BASE "tmp", 0600)) == 0);
-          ASSERT (stat (BASE "tmp", &st2) == 0);
-          ASSERT (unlink (BASE "tmp") == 0);
-        }
-      if (! (st1.st_mtime == st2.st_mtime
-             && get_stat_mtime_ns (&st1) < get_stat_mtime_ns (&st2)))
-        delay = (st1.st_mtime & 1) ? 1000000 : 2000000;
-    }
-  usleep (delay);
-}
-#endif /* !TEST_CHOWN_NAP */
+#include "nap.h"
 
 #if !HAVE_GETEGID
 # define getegid() ((gid_t) -1)
index 707971a..30fd886 100644 (file)
 # include <string.h>
 # include <unistd.h>
 
+/* Gnulib modules.  */
 # include "stat-time.h"
 # include "timespec.h"
 # include "utimecmp.h"
 
+/* Gnulib test header.  */
+# include "nap.h"
+
 enum {
   BILLION = 1000 * 1000 * 1000,
 
@@ -44,29 +48,6 @@ enum {
                           : 0)
 };
 
-/* Sleep long enough to cross a timestamp quantization boundary on
-   most known systems with subsecond timestamp resolution.  For
-   example, ext4 has a quantization of 10 milliseconds, but a
-   resolution of 1 nanosecond.  Likewise, NTFS has a quantization as
-   slow as 15.25 milliseconds, but a resolution of 100 nanoseconds.
-   This is necessary on systems where creat or utimens with NULL
-   rounds down to the quantization boundary, but where gettime and
-   hence utimensat can inject timestamps between quantization
-   boundaries.  By ensuring we cross a boundary, we are less likely to
-   confuse utimecmp for two times that would round to the same
-   quantization boundary but are distinct based on resolution.  */
-static void
-nap (void)
-{
-  /* Systems that lack usleep also lack subsecond timestamps, and have
-     a quantization boundary equal to the resolution.  Our usage of
-     utimecmp allows equality, so no need to waste 980 milliseconds
-     if the replacement usleep rounds to 1 second.  */
-# if HAVE_USLEEP
-  usleep (20 * 1000); /* 20 milliseconds.  */
-# endif
-}
-
 # if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
 /* Skip ctime tests on native Windows, since it is either a copy of
    mtime or birth time (depending on the file system), rather than a