diff options
Diffstat (limited to 'regress')
-rw-r--r-- | regress/sys/kern/kqueue/Makefile | 8 | ||||
-rw-r--r-- | regress/sys/kern/kqueue/kqueue-timer.c | 67 | ||||
-rw-r--r-- | regress/sys/kern/kqueue/main.c | 8 |
3 files changed, 78 insertions, 5 deletions
diff --git a/regress/sys/kern/kqueue/Makefile b/regress/sys/kern/kqueue/Makefile index 11387b2175a..efc23d64bb6 100644 --- a/regress/sys/kern/kqueue/Makefile +++ b/regress/sys/kern/kqueue/Makefile @@ -1,10 +1,10 @@ -# $OpenBSD: Makefile,v 1.17 2015/04/25 20:47:49 guenther Exp $ +# $OpenBSD: Makefile,v 1.18 2015/12/05 10:51:49 blambert Exp $ PROG= kqueue-test CFLAGS+=-Wall SRCS= kqueue-pipe.c kqueue-fork.c main.c kqueue-process.c kqueue-random.c \ kqueue-pty.c kqueue-tun.c kqueue-signal.c kqueue-fdpass.c \ - kqueue-flock.c + kqueue-flock.c kqueue-timer.c LDADD= -levent -lutil DPADD= ${LIBEVENT} ${LIBUTIL} @@ -30,9 +30,11 @@ kq-fdpass: ${PROG} ./${PROG} -F kq-flock: ${PROG} ./${PROG} -l +kq-timer: ${PROG} + ./${PROG} -i REGRESS_TARGETS=kq-pipe kq-fork kq-process kq-random kq-pty kq-signal \ - kq-fdpass kq-flock + kq-fdpass kq-flock kq-timer # kq-tun broke at some point, apparently from a change in tun routing REGRESS_ROOT_TARGETS=${REGRESS_TARGETS} .PHONY: ${REGRESS_TARGETS} diff --git a/regress/sys/kern/kqueue/kqueue-timer.c b/regress/sys/kern/kqueue/kqueue-timer.c new file mode 100644 index 00000000000..9c162018d0a --- /dev/null +++ b/regress/sys/kern/kqueue/kqueue-timer.c @@ -0,0 +1,67 @@ +/* $OpenBSD: kqueue-timer.c,v 1.1 2015/12/05 10:51:49 blambert Exp $ */ +/* + * Copyright (c) 2015 Bret Stephen Lambert <blambert@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#include <sys/types.h> +#include <sys/time.h> +#include <sys/event.h> +#include <stdio.h> +#include <unistd.h> +#include <string.h> + +int do_timer(void); + +int +do_timer(void) +{ + int kq, n; + struct kevent ev; + struct timespec ts; + + if ((kq = kqueue()) == -1) + return (1); + + memset(&ev, 0, sizeof(ev)); + ev.filter = EVFILT_TIMER; + ev.flags = EV_ADD | EV_ENABLE | EV_ONESHOT; + ev.data = 500; /* 1/2 second in ms */ + + if (kevent(kq, &ev, 1, NULL, 0, NULL) == -1) + return (1); + + ts.tv_sec = 2; /* wait 2s for kqueue timeout */ + ts.tv_nsec = 0; + + if ((n = kevent(kq, NULL, 0, &ev, 1, &ts)) != 1) + return (1); + + /* Now retry w/o EV_ONESHOT, as EV_CLEAR is implicit */ + + memset(&ev, 0, sizeof(ev)); + ev.filter = EVFILT_TIMER; + ev.flags = EV_ADD | EV_ENABLE; + ev.data = 500; /* 1/2 second in ms */ + + if (kevent(kq, &ev, 1, NULL, 0, NULL) == -1) + return (1); + + ts.tv_sec = 2; /* wait 2s for kqueue timeout */ + ts.tv_nsec = 0; + + if ((n = kevent(kq, NULL, 0, &ev, 1, &ts)) != 1) + return (1); + + return (0); +} diff --git a/regress/sys/kern/kqueue/main.c b/regress/sys/kern/kqueue/main.c index d99507932ef..b4dca744e48 100644 --- a/regress/sys/kern/kqueue/main.c +++ b/regress/sys/kern/kqueue/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.7 2012/07/08 12:31:03 guenther Exp $ */ +/* $OpenBSD: main.c,v 1.8 2015/12/05 10:51:49 blambert Exp $ */ /* * Written by Artur Grabowski <art@openbsd.org> 2002 Public Domain */ @@ -16,6 +16,7 @@ int do_pty(void); int do_tun(void); int do_fdpass(void); int do_flock(void); +int do_timer(void); int main(int argc, char **argv) @@ -24,7 +25,7 @@ main(int argc, char **argv) int ret, c; ret = 0; - while ((c = getopt(argc, argv, "fFlpPrstT")) != -1) { + while ((c = getopt(argc, argv, "fFilpPrstT")) != -1) { switch (c) { case 'f': ret |= check_inheritance(); @@ -32,6 +33,9 @@ main(int argc, char **argv) case 'F': ret |= do_fdpass(); break; + case 'i': + ret |= do_timer(); + break; case 'l': ret |= do_flock(); break; |