usleep: use it to simplify tests
authorEric Blake <ebb9@byu.net>
Tue, 17 Nov 2009 16:58:18 +0000 (09:58 -0700)
committerEric Blake <ebb9@byu.net>
Wed, 18 Nov 2009 05:33:56 +0000 (22:33 -0700)
Blindly using usleep makes it easier to write tests.

* modules/stat-time-tests (Depends-on): Add usleep.
(configure.ac): Drop usleep check.
* modules/chown-tests (Depends-on, configure.ac): Likewise.
* modules/lchown-tests (Depends-on, configure.ac): Likewise.
* modules/fdutimensat-tests (Depends-on, configure.ac): Likewise.
* modules/futimens-tests (Depends-on, configure.ac): Likewise.
* modules/openat-tests (Depends-on, configure.ac): Likewise.
* modules/utimens-tests (Depends-on, configure.ac): Likewise.
* modules/utimensat-tests (Depends-on, configure.ac): Likewise.
* modules/pipe-filter-gi-tests (Depends-on, configure.ac):
Likewise.
* tests/test-chown.h (nap): Rely on nicer usleep semantics.
* tests/test-lchown.h (nap): Likewise.
* tests/test-pipe-filter-gi2-main.c (small_nap): Likewise.
* tests/test-stat-time.c (nap): Likewise.
* tests/test-utimens-common.h (nap): Update comments.

Signed-off-by: Eric Blake <ebb9@byu.net>
15 files changed:
ChangeLog
modules/chown-tests
modules/fdutimensat-tests
modules/futimens-tests
modules/lchown-tests
modules/openat-tests
modules/pipe-filter-gi-tests
modules/stat-time-tests
modules/utimens-tests
modules/utimensat-tests
tests/test-chown.h
tests/test-lchown.h
tests/test-pipe-filter-gi2-main.c
tests/test-stat-time.c
tests/test-utimens-common.h

index cf14b4ba159e63f2de5bf754c10974f94349b399..62b5423ac242b8f95a7c1ba0ae5de3b0979eaa4b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,23 @@
 2009-11-17  Eric Blake  <ebb9@byu.net>
 
+       usleep: use it to simplify tests
+       * modules/stat-time-tests (Depends-on): Add usleep.
+       (configure.ac): Drop usleep check.
+       * modules/chown-tests (Depends-on, configure.ac): Likewise.
+       * modules/lchown-tests (Depends-on, configure.ac): Likewise.
+       * modules/fdutimensat-tests (Depends-on, configure.ac): Likewise.
+       * modules/futimens-tests (Depends-on, configure.ac): Likewise.
+       * modules/openat-tests (Depends-on, configure.ac): Likewise.
+       * modules/utimens-tests (Depends-on, configure.ac): Likewise.
+       * modules/utimensat-tests (Depends-on, configure.ac): Likewise.
+       * modules/pipe-filter-gi-tests (Depends-on, configure.ac):
+       Likewise.
+       * tests/test-chown.h (nap): Rely on nicer usleep semantics.
+       * tests/test-lchown.h (nap): Likewise.
+       * tests/test-pipe-filter-gi2-main.c (small_nap): Likewise.
+       * tests/test-stat-time.c (nap): Likewise.
+       * tests/test-utimens-common.h (nap): Update comments.
+
        usleep: new module
        * modules/usleep: New file.
        * m4/usleep.m4 (gl_FUNC_USLEEP): Likewise.
index 74e4cfbb88155cbebd8d3352e81db433f49544fd..a5d5c3af7cd542967823681280e23174c8db8e1c 100644 (file)
@@ -6,13 +6,13 @@ Depends-on:
 lstat
 mgetgroups
 progname
-sleep
+usleep
 stat-time
 stdbool
 symlink
 
 configure.ac:
-AC_CHECK_FUNCS_ONCE([getegid usleep])
+AC_CHECK_FUNCS_ONCE([getegid])
 
 Makefile.am:
 TESTS += test-chown
index abd813d8be78e5684cde4260a7c5be018f54de59..75ff374240d9c674f45607a20e8896b1b7db7d4c 100644 (file)
@@ -8,10 +8,10 @@ tests/test-fdutimensat.c
 Depends-on:
 progname
 timespec
+usleep
 utimecmp
 
 configure.ac:
-AC_CHECK_FUNCS_ONCE([usleep])
 
 Makefile.am:
 TESTS += test-fdutimensat
index 3a92524f14f1c0de21b4222aad5c3739c8d46470..2f57c3bbb151cb74229699a01e4a606767650af2 100644 (file)
@@ -5,10 +5,10 @@ tests/test-futimens.c
 
 Depends-on:
 timespec
+usleep
 utimecmp
 
 configure.ac:
-AC_CHECK_FUNCS_ONCE([usleep])
 
 Makefile.am:
 TESTS += test-futimens
index c33103a6b36338cc3d386139fbb7674a7f0b3f4f..8b71e752588324a4b82f1f0dfb588239a5292897 100644 (file)
@@ -5,13 +5,13 @@ tests/test-lchown.c
 Depends-on:
 mgetgroups
 progname
-sleep
+usleep
 stat-time
 stdbool
 symlink
 
 configure.ac:
-AC_CHECK_FUNCS_ONCE([getegid usleep])
+AC_CHECK_FUNCS_ONCE([getegid])
 
 Makefile.am:
 TESTS += test-lchown
index 62cef88207fc97401c54b12508d2314ac3e04db2..e604ca4979b357368a95108fc04ed216eb40ad45 100644 (file)
@@ -15,13 +15,13 @@ tests/test-unlinkat.c
 Depends-on:
 mgetgroups
 pathmax
-sleep
+usleep
 stat-time
 symlink
 unlinkdir
 
 configure.ac:
-AC_CHECK_FUNCS_ONCE([getegid usleep])
+AC_CHECK_FUNCS_ONCE([getegid])
 
 Makefile.am:
 TESTS += test-fchownat test-fstatat test-mkdirat test-openat test-unlinkat
index a02efa8be392cdcd5cddc457fd81543e590f2940..f0b2969f5a75f046e55483bcb90dbd36c4eef769 100644 (file)
@@ -11,11 +11,10 @@ binary-io
 c-ctype
 read-file
 full-write
-sleep
+usleep
 progname
 
 configure.ac:
-AC_CHECK_FUNCS_ONCE([usleep])
 
 Makefile.am:
 TESTS += test-pipe-filter-gi1.sh test-pipe-filter-gi2.sh
index 05b2b6237b6b7db536f35c94db9d8964b43cd225..0c0b66a792a0eef4c62cb505ca20b37ecc2f458c 100644 (file)
@@ -3,10 +3,9 @@ tests/test-stat-time.c
 
 Depends-on:
 time
-sleep
+usleep
 
 configure.ac:
-AC_CHECK_FUNCS_ONCE([usleep])
 
 Makefile.am:
 TESTS += test-stat-time
index 25e7476a5716cdafc8b511963bddd37d9f7caebc..6a2d161688ad7e12776a6a465804deb050981b3d 100644 (file)
@@ -8,10 +8,10 @@ tests/test-utimens.c
 Depends-on:
 symlink
 timespec
+usleep
 utimecmp
 
 configure.ac:
-AC_CHECK_FUNCS_ONCE([usleep])
 
 Makefile.am:
 TESTS += test-utimens
index 1f161ea35e0a145ccb1bfde6fc6cbbefe045af68..ded7f74e62bc24024d3829740230a3b1a43eb8e6 100644 (file)
@@ -7,10 +7,10 @@ tests/test-utimensat.c
 Depends-on:
 progname
 timespec
+usleep
 utimecmp
 
 configure.ac:
-AC_CHECK_FUNCS_ONCE([usleep])
 
 Makefile.am:
 TESTS += test-utimensat
index 12082e4ef60e2d123848b45a393a41cd02c0e926..ab98682e2c198c700db93020f53389c4483bbfda 100644 (file)
 static void
 nap (void)
 {
-#if !HAVE_USLEEP
-  /* Assume the worst case file system of FAT, which has a granularity
-     of 2 seconds.  */
-  sleep (2);
-#else /* HAVE_USLEEP */
   static long delay;
   if (!delay)
     {
@@ -38,8 +33,8 @@ 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.  However, note that
-         usleep (2000000) is allowed to fail with EINVAL.  */
+         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);
@@ -61,13 +56,9 @@ nap (void)
         }
       if (! (st1.st_mtime == st2.st_mtime
              && get_stat_mtime_ns (&st1) < get_stat_mtime_ns (&st2)))
-        delay = 2000000;
+        delay = (st1.st_mtime & 1) ? 1000000 : 2000000;
     }
-  if (delay == 2000000)
-    sleep (2);
-  else
-    usleep (delay);
-#endif /* HAVE_USLEEP */
+  usleep (delay);
 }
 
 #if !HAVE_GETEGID
index a1e8b680995b5e4baae9c5adef40187e0590e056..f3ddb7a98b20b482f1af03dc78373bd3aec0169a 100644 (file)
 static void
 nap (void)
 {
-# if !HAVE_USLEEP
-  /* Assume the worst case file system of FAT, which has a granularity
-     of 2 seconds.  */
-  sleep (2);
-# else /* HAVE_USLEEP */
   static long delay;
   if (!delay)
     {
@@ -38,8 +33,8 @@ 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.  However, note that
-         usleep (2000000) is allowed to fail with EINVAL.  */
+         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);
@@ -61,13 +56,9 @@ nap (void)
         }
       if (! (st1.st_mtime == st2.st_mtime
              && get_stat_mtime_ns (&st1) < get_stat_mtime_ns (&st2)))
-        delay = 2000000;
+        delay = (st1.st_mtime & 1) ? 1000000 : 2000000;
     }
-  if (delay == 2000000)
-    sleep (2);
-  else
-    usleep (delay);
-# endif /* HAVE_USLEEP */
+  usleep (delay);
 }
 #endif /* !TEST_CHOWN_NAP */
 
index 7be285e08198991d540658cbc1ca4395d9c04e91..b9a0b11a9ab209bae42e76e648779d03623e1d91 100644 (file)
 static void
 small_nap (void)
 {
-#if HAVE_USLEEP
   usleep (100000);
-#else
-  sleep (1);
-#endif
 }
 
 static char static_buf[5];
index b88af3dc51af6ca5258c6f7f237b2f80fb2886b0..85ada87737a022b6ba7d3d4a57e8293f9dd1528d 100644 (file)
@@ -96,11 +96,6 @@ do_stat (const char *filename, struct stat *p)
 static void
 nap (void)
 {
-#if !HAVE_USLEEP
-  /* Assume the worst case file system of FAT, which has a granularity
-     of 2 seconds.  */
-  sleep (2);
-#else /* HAVE_USLEEP */
   static long delay;
   if (!delay)
     {
@@ -112,8 +107,8 @@ 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.  However, note that
-         usleep (2000000) is allowed to fail with EINVAL.  */
+         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 (stat ("t-stt-stamp1", &st1) == 0);
@@ -133,13 +128,9 @@ nap (void)
         }
       if (! (st1.st_mtime == st2.st_mtime
              && get_stat_mtime_ns (&st1) < get_stat_mtime_ns (&st2)))
-        delay = 2000000;
+        delay = (st1.st_mtime & 1) ? 1000000 : 2000000;
     }
-  if (delay == 2000000)
-    sleep (2);
-  else
-    usleep (delay);
-#endif /* HAVE_USLEEP */
+  usleep (delay);
 }
 
 static void
index 1945f23e30aa850cea1d91ad492042007be2fce1..6c404cc5d251be5bf4c22ee85effda150f4d5bac 100644 (file)
@@ -58,8 +58,10 @@ enum {
 static void
 nap (void)
 {
-  /* Systems that lack usleep also lack subsecond timestamps.  Our
-     usage of utimecmp allows equality, so we don't need to sleep.  */
+  /* 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