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 cf14b4b..62b5423 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 74e4cfb..a5d5c3a 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 abd813d..75ff374 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 3a92524..2f57c3b 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 c33103a..8b71e75 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 62cef88..e604ca4 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 a02efa8..f0b2969 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 05b2b62..0c0b66a 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 25e7476..6a2d161 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 1f161ea..ded7f74 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 12082e4..ab98682 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 a1e8b68..f3ddb7a 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 7be285e..b9a0b11 100644 (file)
 static void
 small_nap (void)
 {
-#if HAVE_USLEEP
   usleep (100000);
-#else
-  sleep (1);
-#endif
 }
 
 static char static_buf[5];
index b88af3d..85ada87 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 1945f23..6c404cc 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