diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 2002-06-19 03:05:08 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 2002-06-19 03:05:08 +0000 |
commit | b36f4bdb32d3f106c06cac2442471177142adc67 (patch) | |
tree | 765f48ae466d7c6b024b6e4ceb49821e8e95199b | |
parent | ac8debd36ead5f4c214c861f9feab242f680e66b (diff) |
regress for the kqueu for random
-rw-r--r-- | regress/sys/kern/kqueue/Makefile | 8 | ||||
-rw-r--r-- | regress/sys/kern/kqueue/kqueue-random.c | 66 | ||||
-rw-r--r-- | regress/sys/kern/kqueue/main.c | 17 |
3 files changed, 82 insertions, 9 deletions
diff --git a/regress/sys/kern/kqueue/Makefile b/regress/sys/kern/kqueue/Makefile index abc15a06839..5ef54b11fcd 100644 --- a/regress/sys/kern/kqueue/Makefile +++ b/regress/sys/kern/kqueue/Makefile @@ -1,7 +1,7 @@ -# $OpenBSD: Makefile,v 1.3 2002/03/02 21:48:05 art Exp $ +# $OpenBSD: Makefile,v 1.4 2002/06/19 03:05:07 mickey Exp $ PROG= kqueue-test -SRCS= kqueue-pipe.c kqueue-fork.c main.c kqueue-process.c +SRCS= kqueue-pipe.c kqueue-fork.c main.c kqueue-process.c kqueue-random.c kq-pipe: ${PROG} ./${PROG} -p @@ -9,8 +9,10 @@ kq-fork: ${PROG} ./${PROG} -f kq-process: ${PROG} ./${PROG} -P +kq-random: ${PROG} + ./${PROG} -r -REGRESSTARGETS=kq-pipe kq-fork kq-process +REGRESSTARGETS=kq-pipe kq-fork kq-process kq-random .PHONY: ${REGRESSTARGETS} .include <bsd.regress.mk> diff --git a/regress/sys/kern/kqueue/kqueue-random.c b/regress/sys/kern/kqueue/kqueue-random.c new file mode 100644 index 00000000000..44f77dee9c6 --- /dev/null +++ b/regress/sys/kern/kqueue/kqueue-random.c @@ -0,0 +1,66 @@ +/* $OpenBSD: kqueue-random.c,v 1.1 2002/06/19 03:05:07 mickey Exp $ */ +/* Copyright (c) 2002 Michael Shalayeff, Public Domain */ + +#include <stdlib.h> +#include <stdio.h> +#include <err.h> +#include <unistd.h> + +#include <sys/param.h> +#include <sys/event.h> +#include <sys/wait.h> +#include <sys/fcntl.h> + +#include <dev/rndvar.h> + +int +do_random(void) +{ + int n, fd, kq, status; + struct timespec ts; + struct kevent ev; + u_int32_t buf[POOLWORDS]; + + if ((fd = open("/dev/srandom", O_RDONLY)) < 0) { + warn("open: /dev/srandom"); + return (1); + } + if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) { + warn("fcntl"); + close(fd); + return (1); + } + + if ((kq = kqueue()) < 0) { + warn("kqueue"); + close(fd); + return (1); + } + + ev.ident = fd; + ev.filter = EVFILT_READ; + ev.flags = EV_ADD | EV_ENABLE; + n = kevent(kq, &ev, 1, NULL, 0, NULL); + if (n == -1) { + warn("kevent"); + close(kq); + close(fd); + return (1); + } + + ts.tv_sec = 0; + ts.tv_nsec = 0; + if (kevent(kq, NULL, 0, &ev, 1, &ts) < 0) { + warn("kevent2"); + return (1); + } + + n = MIN((ev.data + 31) / 32, sizeof(buf)); + if (read(fd, buf, n) < 1) + return (1); + + close(kq); + close(fd); + + return (0); +} diff --git a/regress/sys/kern/kqueue/main.c b/regress/sys/kern/kqueue/main.c index 5b9c389b49e..166b77f73d7 100644 --- a/regress/sys/kern/kqueue/main.c +++ b/regress/sys/kern/kqueue/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.2 2002/03/02 21:48:05 art Exp $ */ +/* $OpenBSD: main.c,v 1.3 2002/06/19 03:05:07 mickey Exp $ */ /* * Written by Artur Grabowski <art@openbsd.org> 2002 Public Domain */ @@ -7,17 +7,19 @@ #include <stdio.h> #include <unistd.h> -extern int do_pipe(void); -extern int check_inheritance(void); -extern int do_process(void); +int do_pipe(void); +int check_inheritance(void); +int do_process(void); +int do_random(void); int main(int argc, char **argv) { + extern char *__progname; int ret, c; ret = 0; - while ((c = getopt(argc, argv, "pfP")) != -1) { + while ((c = getopt(argc, argv, "fPpr")) != -1) { switch (c) { case 'p': ret |= do_pipe(); @@ -28,8 +30,11 @@ main(int argc, char **argv) case 'P': ret |= do_process(); break; + case 'r': + ret |= do_random(); + break; default: - fprintf(stderr, "Usage: kqtest -P|p|f\n"); + fprintf(stderr, "Usage: %s -[fPpr]\n", __progname); exit(1); } } |