From: Eric Blake Date: Mon, 12 Oct 2009 16:42:35 +0000 (-0600) Subject: utimens-tests: port to NFS file systems X-Git-Tag: v0.1~5322 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=420f3dbbb7343cb76a0c44b7c15b19dbe4aaeaaf;p=gnulib.git utimens-tests: port to NFS file systems 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 --- diff --git a/ChangeLog b/ChangeLog index 3c1077b4d..5e097380a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2009-10-12 Eric Blake + 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 + 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. diff --git a/tests/test-utimens.h b/tests/test-utimens.h index 04131d306..08d3ac0f0 100644 --- a/tests/test-utimens.h +++ b/tests/test-utimens.h @@ -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;