From: Eric Blake Date: Mon, 21 Dec 2009 14:00:13 +0000 (-0700) Subject: test-utimens: avoid spurious failure X-Git-Tag: v0.1~5018 X-Git-Url: http://erislabs.net/gitweb/?a=commitdiff_plain;h=c7362ef0beb434d7a3063b5a7ac7b956988dc435;p=gnulib.git test-utimens: avoid spurious failure 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 --- diff --git a/ChangeLog b/ChangeLog index eb560d535..5dd41d1b5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2009-12-21 Eric Blake + + 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 futimens, utimensat: work around Linux bug diff --git a/modules/chown-tests b/modules/chown-tests index a5d5c3af7..d1add611c 100644 --- a/modules/chown-tests +++ b/modules/chown-tests @@ -1,4 +1,5 @@ Files: +tests/nap.h tests/test-chown.h tests/test-chown.c diff --git a/modules/fdutimensat-tests b/modules/fdutimensat-tests index 75ff37424..16cf82c4f 100644 --- a/modules/fdutimensat-tests +++ b/modules/fdutimensat-tests @@ -1,4 +1,5 @@ Files: +tests/nap.h tests/test-futimens.h tests/test-lutimens.h tests/test-utimens.h diff --git a/modules/futimens-tests b/modules/futimens-tests index 2f57c3bbb..c768c330d 100644 --- a/modules/futimens-tests +++ b/modules/futimens-tests @@ -1,4 +1,5 @@ Files: +tests/nap.h tests/test-futimens.h tests/test-utimens-common.h tests/test-futimens.c diff --git a/modules/lchown-tests b/modules/lchown-tests index 8b71e7525..7e4d50272 100644 --- a/modules/lchown-tests +++ b/modules/lchown-tests @@ -1,4 +1,5 @@ Files: +tests/nap.h tests/test-lchown.h tests/test-lchown.c diff --git a/modules/openat-tests b/modules/openat-tests index e604ca497..7265fd982 100644 --- a/modules/openat-tests +++ b/modules/openat-tests @@ -1,4 +1,5 @@ Files: +tests/nap.h tests/test-chown.h tests/test-lchown.h tests/test-lstat.h diff --git a/modules/utimens-tests b/modules/utimens-tests index 6a2d16168..5bf14c22a 100644 --- a/modules/utimens-tests +++ b/modules/utimens-tests @@ -1,4 +1,5 @@ Files: +tests/nap.h tests/test-futimens.h tests/test-lutimens.h tests/test-utimens.h diff --git a/modules/utimensat-tests b/modules/utimensat-tests index ded7f74e6..a56bb3e18 100644 --- a/modules/utimensat-tests +++ b/modules/utimensat-tests @@ -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 index 000000000..e8b4f5a8e --- /dev/null +++ b/tests/nap.h @@ -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 . */ + +/* Written by Eric Blake , 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 */ diff --git a/tests/test-chown.h b/tests/test-chown.h index c4e652af8..62e612e7a 100644 --- a/tests/test-chown.h +++ b/tests/test-chown.h @@ -16,50 +16,7 @@ /* Written by Eric Blake , 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) diff --git a/tests/test-lchown.h b/tests/test-lchown.h index 93a657cf5..26f80f791 100644 --- a/tests/test-lchown.h +++ b/tests/test-lchown.h @@ -16,51 +16,7 @@ /* Written by Eric Blake , 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) diff --git a/tests/test-utimens-common.h b/tests/test-utimens-common.h index 707971abe..30fd88674 100644 --- a/tests/test-utimens-common.h +++ b/tests/test-utimens-common.h @@ -24,10 +24,14 @@ # include # include +/* 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