summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2009-11-17 09:58:18 -0700
committerEric Blake <ebb9@byu.net>2009-11-17 22:33:56 -0700
commit6038ee4b827caaf05fa37dbb2304fedb9d0cd6c7 (patch)
treef2989aa60b662c9546d1047040bb83f66977f457
parente8eecfd3f7d37692a7b87779b69d6fdc22d88d4d (diff)
downloadgnulib-6038ee4b827caaf05fa37dbb2304fedb9d0cd6c7.tar.gz
usleep: use it to simplify tests
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>
-rw-r--r--ChangeLog18
-rw-r--r--modules/chown-tests4
-rw-r--r--modules/fdutimensat-tests2
-rw-r--r--modules/futimens-tests2
-rw-r--r--modules/lchown-tests4
-rw-r--r--modules/openat-tests4
-rw-r--r--modules/pipe-filter-gi-tests3
-rw-r--r--modules/stat-time-tests3
-rw-r--r--modules/utimens-tests2
-rw-r--r--modules/utimensat-tests2
-rw-r--r--tests/test-chown.h17
-rw-r--r--tests/test-lchown.h17
-rw-r--r--tests/test-pipe-filter-gi2-main.c4
-rw-r--r--tests/test-stat-time.c17
-rw-r--r--tests/test-utimens-common.h6
15 files changed, 46 insertions, 59 deletions
diff --git a/ChangeLog b/ChangeLog
index cf14b4ba15..62b5423ac2 100644
--- 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.
diff --git a/modules/chown-tests b/modules/chown-tests
index 74e4cfbb88..a5d5c3af7c 100644
--- a/modules/chown-tests
+++ b/modules/chown-tests
@@ -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
diff --git a/modules/fdutimensat-tests b/modules/fdutimensat-tests
index abd813d8be..75ff374240 100644
--- a/modules/fdutimensat-tests
+++ b/modules/fdutimensat-tests
@@ -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
diff --git a/modules/futimens-tests b/modules/futimens-tests
index 3a92524f14..2f57c3bbb1 100644
--- a/modules/futimens-tests
+++ b/modules/futimens-tests
@@ -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
diff --git a/modules/lchown-tests b/modules/lchown-tests
index c33103a6b3..8b71e75258 100644
--- a/modules/lchown-tests
+++ b/modules/lchown-tests
@@ -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
diff --git a/modules/openat-tests b/modules/openat-tests
index 62cef88207..e604ca4979 100644
--- a/modules/openat-tests
+++ b/modules/openat-tests
@@ -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
diff --git a/modules/pipe-filter-gi-tests b/modules/pipe-filter-gi-tests
index a02efa8be3..f0b2969f5a 100644
--- a/modules/pipe-filter-gi-tests
+++ b/modules/pipe-filter-gi-tests
@@ -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
diff --git a/modules/stat-time-tests b/modules/stat-time-tests
index 05b2b6237b..0c0b66a792 100644
--- a/modules/stat-time-tests
+++ b/modules/stat-time-tests
@@ -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
diff --git a/modules/utimens-tests b/modules/utimens-tests
index 25e7476a57..6a2d161688 100644
--- a/modules/utimens-tests
+++ b/modules/utimens-tests
@@ -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
diff --git a/modules/utimensat-tests b/modules/utimensat-tests
index 1f161ea35e..ded7f74e62 100644
--- a/modules/utimensat-tests
+++ b/modules/utimensat-tests
@@ -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
diff --git a/tests/test-chown.h b/tests/test-chown.h
index 12082e4ef6..ab98682e2c 100644
--- a/tests/test-chown.h
+++ b/tests/test-chown.h
@@ -22,11 +22,6 @@
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
diff --git a/tests/test-lchown.h b/tests/test-lchown.h
index a1e8b68099..f3ddb7a98b 100644
--- a/tests/test-lchown.h
+++ b/tests/test-lchown.h
@@ -22,11 +22,6 @@
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 */
diff --git a/tests/test-pipe-filter-gi2-main.c b/tests/test-pipe-filter-gi2-main.c
index 7be285e081..b9a0b11a9a 100644
--- a/tests/test-pipe-filter-gi2-main.c
+++ b/tests/test-pipe-filter-gi2-main.c
@@ -45,11 +45,7 @@
static void
small_nap (void)
{
-#if HAVE_USLEEP
usleep (100000);
-#else
- sleep (1);
-#endif
}
static char static_buf[5];
diff --git a/tests/test-stat-time.c b/tests/test-stat-time.c
index b88af3dc51..85ada87737 100644
--- a/tests/test-stat-time.c
+++ b/tests/test-stat-time.c
@@ -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
diff --git a/tests/test-utimens-common.h b/tests/test-utimens-common.h
index 1945f23e30..6c404cc5d2 100644
--- a/tests/test-utimens-common.h
+++ b/tests/test-utimens-common.h
@@ -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