summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2009-11-17 09:24:56 -0700
committerEric Blake <ebb9@byu.net>2009-11-17 22:31:58 -0700
commite8eecfd3f7d37692a7b87779b69d6fdc22d88d4d (patch)
treeba23fa37356a4fb4122ee07e709373fa85c11fda /tests
parent84405cbc35207f178b1b50617254cb85ea803128 (diff)
downloadgnulib-e8eecfd3f7d37692a7b87779b69d6fdc22d88d4d.tar.gz
usleep: new module
mingw usleep(1000000) failed with EINVAL, as allowed by POSIX, but contrary to GNU usage. Rather than implement an accurate usleep based on select or nanosleep, both of which drag in dependencies on external libraries, this version intentionally takes the ceiling in seconds if usleep() is missing. * modules/usleep: New file. * m4/usleep.m4 (gl_FUNC_USLEEP): Likewise. * lib/usleep.c (usleep): Likewise. * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Add defaults. * modules/unistd (Makefile.am): Substitute witnesses. * lib/unistd.in.h (usleep): Add declaration. * doc/pastposix-functions/usleep.texi (usleep): Document this. * MODULES.html.sh (Date and time): Likewise. * modules/usleep-tests (Depends-on): New test. * tests/test-usleep.c: New file. Signed-off-by: Eric Blake <ebb9@byu.net>
Diffstat (limited to 'tests')
-rw-r--r--tests/test-usleep.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/test-usleep.c b/tests/test-usleep.c
new file mode 100644
index 0000000000..d6e62ebe4d
--- /dev/null
+++ b/tests/test-usleep.c
@@ -0,0 +1,49 @@
+/* Test of usleep() function.
+ 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 <http://www.gnu.org/licenses/>. */
+
+/* Written by Eric Blake <ebb9@byu.net>, 2009. */
+
+#include <config.h>
+
+#include <unistd.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+#define ASSERT(expr) \
+ do \
+ { \
+ if (!(expr)) \
+ { \
+ fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
+ fflush (stderr); \
+ abort (); \
+ } \
+ } \
+ while (0)
+
+int
+main(void)
+{
+ time_t start = time (NULL);
+ ASSERT (usleep (1000000) == 0);
+ ASSERT (start < time (NULL));
+
+ ASSERT (usleep (0) == 0);
+
+ return 0;
+}