summaryrefslogtreecommitdiff
path: root/regress
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2002-02-17 05:33:34 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2002-02-17 05:33:34 +0000
commit6d26f5fe044da604b04064acd38f31cc8e131e20 (patch)
treea3edcb3d31006fbe8a0918cccae4932bb41a5d17 /regress
parente86418196377f389bd849546b2798a8e72f3f747 (diff)
Add a test for nansleep with a very short time (less than a tick).
Diffstat (limited to 'regress')
-rw-r--r--regress/sys/kern/nanosleep/Makefile6
-rw-r--r--regress/sys/kern/nanosleep/nanosleep.c44
2 files changed, 47 insertions, 3 deletions
diff --git a/regress/sys/kern/nanosleep/Makefile b/regress/sys/kern/nanosleep/Makefile
index b81a0876cb1..dc2a24ec25d 100644
--- a/regress/sys/kern/nanosleep/Makefile
+++ b/regress/sys/kern/nanosleep/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.1 2002/02/16 00:47:55 art Exp $
+# $OpenBSD: Makefile,v 1.2 2002/02/17 05:33:33 art Exp $
PROG= nanosleep
SRCS= nanosleep.c
@@ -15,6 +15,10 @@ time_elapsed: nanosleep
time_elapsed_with_signal: nanosleep
./nanosleep -E
+short_time: nanosleep
+ ./nanosleep -S
+
REGRESSTARGETS=trivial with_signal time_elapsed time_elapsed_with_signal
+REGRESSTARGETS+=short_time
.include <bsd.regress.mk>
diff --git a/regress/sys/kern/nanosleep/nanosleep.c b/regress/sys/kern/nanosleep/nanosleep.c
index 08ddba13390..41a9a20349d 100644
--- a/regress/sys/kern/nanosleep/nanosleep.c
+++ b/regress/sys/kern/nanosleep/nanosleep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nanosleep.c,v 1.1 2002/02/16 00:47:55 art Exp $ */
+/* $OpenBSD: nanosleep.c,v 1.2 2002/02/17 05:33:33 art Exp $ */
/*
* Written by Artur Grabowski <art@openbsd.org> 2002 Public Domain.
*/
@@ -17,6 +17,8 @@ int with_signal(void);
int time_elapsed(void);
int time_elapsed_with_signal(void);
+int short_time(void);
+
void sighandler(int);
int
@@ -26,7 +28,7 @@ main(int argc, char **argv)
ret = 0;
- while ((ch = getopt(argc, argv, "tseE")) != -1) {
+ while ((ch = getopt(argc, argv, "tseES")) != -1) {
switch (ch) {
case 't':
ret |= trivial();
@@ -40,6 +42,8 @@ main(int argc, char **argv)
case 'E':
ret |= time_elapsed_with_signal();
break;
+ case 'S':
+ ret |= short_time();
default:
fprintf(stderr, "Usage: nanosleep [-tse]\n");
exit(1);
@@ -218,3 +222,39 @@ time_elapsed_with_signal(void)
return 0;
}
+
+int
+short_time(void)
+{
+ struct timespec ts, rts;
+ pid_t pid;
+ int status;
+
+ signal(SIGUSR1, sighandler);
+
+ pid = getpid();
+
+ switch(fork()) {
+ case -1:
+ err(1, "fork");
+ default:
+ /* Sleep two seconds, then shoot parent. */
+ ts.tv_sec = 2;
+ ts.tv_nsec = 0;
+ nanosleep(&ts, NULL);
+ kill(pid, SIGUSR1);
+ exit(0);
+ }
+
+ ts.tv_sec = 0;
+ ts.tv_nsec = 1;
+ if (nanosleep(&ts, NULL) <= 0) {
+ warn("short_time: nanosleep");
+ return 1;
+ }
+
+ if (wait(&status) < 0)
+ err(1, "wait");
+
+ return 0;
+}