utimens-tests: port to NFS file systems
authorEric Blake <ebb9@byu.net>
Mon, 12 Oct 2009 16:42:35 +0000 (10:42 -0600)
committerEric Blake <ebb9@byu.net>
Tue, 13 Oct 2009 02:57:50 +0000 (20:57 -0600)
Testing on Solaris 8 with NFS: creat() and utimens(,NULL) seem to
set timestamps according to the current time on the server, while
utimens(,{,UTIME_NOW}) sets timestamps according to the current
time on the client.  If two machines are not perfectly
synchronized in time, then this makes time appear to move
backwards.  Avoid spurious test failures caused by a mtime
comparison across machines, by instead doing 2 mtime comparisons,
each known to be from timestamps tied to a single machine.

* tests/test-utimens.h (test_utimens): Add a utimens call prior to
grabbing stat buffer.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
tests/test-utimens.h

index 3c1077b..5e09738 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2009-10-12  Eric Blake  <ebb9@byu.net>
 
+       utimens-tests: port to NFS file systems
+       * tests/test-utimens.h (test_utimens): Refactor utimecmp
+       comparisons to avoid spurious failures from timestamp drift
+       between NFS machines.
+
+2009-10-12  Eric Blake  <ebb9@byu.net>
+
        stat-time-tests: minor cleanups
        * modules/stat-time-tests (configure.ac): Use AC_CHECK_FUNCS_ONCE.
        * tests/test-stat-time.c (nap): Separate assignment from call.
index 04131d3..08d3ac0 100644 (file)
@@ -56,10 +56,28 @@ test_utimens (int (*func) (char const *, struct timespec const *))
 
   ASSERT (close (creat (BASE "file", 0600)) == 0);
   /* If utimens truncates to less resolution than the file system
-     supports, then time can appear to go backwards between now and
-     the follow-up utimens(file,NULL).  Use UTIMECMP_TRUNCATE_SOURCE
-     to compensate, with st1 as the source.  */
+     supports, then time can appear to go backwards between now and a
+     follow-up utimens with UTIME_NOW or a NULL timespec.  Use
+     UTIMECMP_TRUNCATE_SOURCE to compensate, with st1 as the
+     source.  */
   ASSERT (stat (BASE "file", &st1) == 0);
+  ASSERT (func (BASE "file", NULL) == 0);
+  ASSERT (stat (BASE "file", &st2) == 0);
+  ASSERT (0 <= utimecmp (BASE "file", &st2, &st1, UTIMECMP_TRUNCATE_SOURCE));
+  {
+    /* On some NFS systems, the 'now' timestamp of creat or a NULL
+       timespec is determined by the server, but the 'now' timestamp
+       determined by gettime() (as is done when using UTIME_OMIT) is
+       determined by the client; since the two machines are not
+       necessarily on the same clock, this is another case where time
+       can appear to go backwards.  The rest of this test cares about
+       client time, so manually use gettime() to set both times.  */
+    struct timespec ts[2];
+    gettime (&ts[0]);
+    ts[1] = ts[0];
+    ASSERT (func (BASE "file", ts) == 0);
+    ASSERT (stat (BASE "file", &st1) == 0);
+  }
 
   /* Invalid arguments.  */
   errno = 0;