Mercurial > hg > octave-lojdl > gnulib-hg
changeset 12316:d47887220b68
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>
author | Eric Blake <ebb9@byu.net> |
---|---|
date | Tue, 17 Nov 2009 09:58:18 -0700 |
parents | 8cb02ee162a1 |
children | 407921985bc0 |
files | 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 |
diffstat | 15 files changed, 46 insertions(+), 59 deletions(-) [+] |
line wrap: on
line diff
--- 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.
--- a/modules/chown-tests +++ b/modules/chown-tests @@ -6,13 +6,13 @@ 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
--- a/modules/fdutimensat-tests +++ b/modules/fdutimensat-tests @@ -8,10 +8,10 @@ Depends-on: progname timespec +usleep utimecmp configure.ac: -AC_CHECK_FUNCS_ONCE([usleep]) Makefile.am: TESTS += test-fdutimensat
--- a/modules/futimens-tests +++ b/modules/futimens-tests @@ -5,10 +5,10 @@ Depends-on: timespec +usleep utimecmp configure.ac: -AC_CHECK_FUNCS_ONCE([usleep]) Makefile.am: TESTS += test-futimens
--- a/modules/lchown-tests +++ b/modules/lchown-tests @@ -5,13 +5,13 @@ 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
--- a/modules/openat-tests +++ b/modules/openat-tests @@ -15,13 +15,13 @@ 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
--- a/modules/pipe-filter-gi-tests +++ b/modules/pipe-filter-gi-tests @@ -11,11 +11,10 @@ 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
--- a/modules/stat-time-tests +++ b/modules/stat-time-tests @@ -3,10 +3,9 @@ Depends-on: time -sleep +usleep configure.ac: -AC_CHECK_FUNCS_ONCE([usleep]) Makefile.am: TESTS += test-stat-time
--- a/modules/utimens-tests +++ b/modules/utimens-tests @@ -8,10 +8,10 @@ Depends-on: symlink timespec +usleep utimecmp configure.ac: -AC_CHECK_FUNCS_ONCE([usleep]) Makefile.am: TESTS += test-utimens
--- a/modules/utimensat-tests +++ b/modules/utimensat-tests @@ -7,10 +7,10 @@ Depends-on: progname timespec +usleep utimecmp configure.ac: -AC_CHECK_FUNCS_ONCE([usleep]) Makefile.am: TESTS += test-utimensat
--- 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 @@ 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 @@ } 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
--- 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 @@ 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 @@ } 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 */
--- 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];
--- a/tests/test-stat-time.c +++ b/tests/test-stat-time.c @@ -96,11 +96,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) { @@ -112,8 +107,8 @@ 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 @@ } 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
--- a/tests/test-utimens-common.h +++ b/tests/test-utimens-common.h @@ -58,8 +58,10 @@ 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