From 6d26f5fe044da604b04064acd38f31cc8e131e20 Mon Sep 17 00:00:00 2001 From: Artur Grabowski Date: Sun, 17 Feb 2002 05:33:34 +0000 Subject: Add a test for nansleep with a very short time (less than a tick). --- regress/sys/kern/nanosleep/Makefile | 6 ++++- regress/sys/kern/nanosleep/nanosleep.c | 44 ++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 3 deletions(-) (limited to 'regress') 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 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 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); @@ -213,6 +217,42 @@ time_elapsed_with_signal(void) } + if (wait(&status) < 0) + err(1, "wait"); + + 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"); -- cgit v1.2.3