summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Shalayeff <mickey@cvs.openbsd.org>2003-06-12 05:06:48 +0000
committerMichael Shalayeff <mickey@cvs.openbsd.org>2003-06-12 05:06:48 +0000
commitd929e09929bff6f39b9be75d18497b3110a25951 (patch)
tree7ca0a58efbecb6d89a37dc5c14f8375f17a05279
parented00071561fdffa8e0a37a9244a8890e9684b206 (diff)
test for kqueue on ptys (to verify pr3209)
-rw-r--r--regress/sys/kern/kqueue/Makefile13
-rw-r--r--regress/sys/kern/kqueue/kqueue-pty.c110
-rw-r--r--regress/sys/kern/kqueue/main.c10
3 files changed, 127 insertions, 6 deletions
diff --git a/regress/sys/kern/kqueue/Makefile b/regress/sys/kern/kqueue/Makefile
index 7d7994bd6e6..5b002bbb11e 100644
--- a/regress/sys/kern/kqueue/Makefile
+++ b/regress/sys/kern/kqueue/Makefile
@@ -1,7 +1,12 @@
-# $OpenBSD: Makefile,v 1.5 2002/09/02 20:01:44 avsm Exp $
+# $OpenBSD: Makefile,v 1.6 2003/06/12 05:06:47 mickey Exp $
PROG= kqueue-test
-SRCS= kqueue-pipe.c kqueue-fork.c main.c kqueue-process.c kqueue-random.c
+CFLAGS+=-Wall
+SRCS= kqueue-pipe.c kqueue-fork.c main.c kqueue-process.c kqueue-random.c \
+ kqueue-pty.c
+LDADD= ${LIBUTIL}
+DPADD= ${DPUTIL}
+SUDO=sudo
kq-pipe: ${PROG}
./${PROG} -p
@@ -11,8 +16,10 @@ kq-process: ${PROG}
./${PROG} -P
kq-random: ${PROG}
./${PROG} -r
+kq-pty: ${PROG}
+ ${SUDO} ./${PROG} -T
-REGRESS_TARGETS=kq-pipe kq-fork kq-process kq-random
+REGRESS_TARGETS=kq-pipe kq-fork kq-process kq-random kq-pty
.PHONY: ${REGRESS_TARGETS}
.include <bsd.regress.mk>
diff --git a/regress/sys/kern/kqueue/kqueue-pty.c b/regress/sys/kern/kqueue/kqueue-pty.c
new file mode 100644
index 00000000000..4683bb67a3f
--- /dev/null
+++ b/regress/sys/kern/kqueue/kqueue-pty.c
@@ -0,0 +1,110 @@
+/* $OpenBSD: kqueue-pty.c,v 1.1 2003/06/12 05:06:47 mickey Exp $ */
+
+#include <sys/types.h>
+#include <sys/time.h>
+#include <sys/event.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <util.h>
+#include <termios.h>
+#include <fcntl.h>
+#include <err.h>
+
+#define EVDUMP(ev) printf("%d %d %d %d %d", ev->ident, ev->filter, ev->flags, ev->fflags, ev->data)
+
+int
+pty_check(int kq, struct kevent *ev, int n, int rm, int rs, int wm, int ws)
+{
+ struct timespec ts;
+ int i;
+
+ ts.tv_sec = 0;
+ ts.tv_nsec = 0;
+ if ((n = kevent(kq, NULL, 0, ev, n, &ts)) < 0)
+ err(1, "slave: kevent");
+
+ if (n == 0)
+ return (1);
+
+ printf("%d:\n", n);
+ for (i = 0; i < n; i++, ev++) {
+ EVDUMP(ev);
+ if (ev->filter == EVFILT_READ) {
+ if (rm < 0 && ev->ident == -rm) {
+ printf(" bad");
+ }
+ if (rs < 0 && ev->ident == -rs) {
+ printf(" bad");
+ }
+ } else if (ev->filter == EVFILT_WRITE) {
+ if (wm < 0 && ev->ident == -wm) {
+ printf(" bad");
+ }
+ if (ws < 0 && ev->ident == -ws) {
+ printf(" bad");
+ }
+ } else
+ errx(1, "unknown event");
+ printf("\n");
+ }
+ printf("\n");
+
+ return (0);
+}
+
+int
+do_pty(void)
+{
+ struct kevent ev[4];
+ struct termios tt;
+ int kq, massa, slave;
+ char buf[1024];
+
+ tcgetattr(STDIN_FILENO, &tt);
+ cfmakeraw(&tt);
+ tt.c_lflag &= ~ECHO;
+ if (openpty(&massa, &slave, NULL, &tt, NULL) < 0)
+ err(1, "openpty");
+ if (fcntl(massa, F_SETFL, O_NONBLOCK) < 0)
+ err(1, "massa: fcntl");
+ if (fcntl(slave, F_SETFL, O_NONBLOCK) < 0)
+ err(1, "massa: fcntl");
+ if ((kq = kqueue()) == -1)
+ err(1, "kqueue");
+
+ /* test the read from the slave works */
+ EV_SET(&ev[0], massa, EVFILT_READ, EV_ADD|EV_ENABLE, 0, 0, NULL);
+ EV_SET(&ev[1], massa, EVFILT_WRITE, EV_ADD|EV_ENABLE, 0, 0, NULL);
+ EV_SET(&ev[2], slave, EVFILT_READ, EV_ADD|EV_ENABLE, 0, 0, NULL);
+ EV_SET(&ev[3], slave, EVFILT_WRITE, EV_ADD|EV_ENABLE, 0, 0, NULL);
+ if (kevent(kq, ev, 4, NULL, 0, NULL) < 0)
+ err(1, "slave: kevent add");
+
+ if (write(massa, " ", 1) != 1)
+ err(1, "massa: write");
+
+ if (pty_check(kq, ev, 4, -massa, slave, massa, slave))
+ return (1);
+
+ read(slave, buf, sizeof(buf));
+
+ if (pty_check(kq, ev, 4, -massa, -slave, massa, slave))
+ return (1);
+
+ while (write(massa, buf, sizeof(buf)) > 0);
+
+ if (pty_check(kq, ev, 4, -massa, slave, -massa, slave))
+ return (1);
+
+ read(slave, buf, 1);
+
+ if (pty_check(kq, ev, 4, -massa, slave, massa, slave))
+ return (1);
+
+ while (read(slave, buf, sizeof(buf)) > 0);
+
+ if (pty_check(kq, ev, 4, -massa, -slave, massa, slave))
+ return (1);
+
+ return (0);
+}
diff --git a/regress/sys/kern/kqueue/main.c b/regress/sys/kern/kqueue/main.c
index 166b77f73d7..3e19f26a685 100644
--- a/regress/sys/kern/kqueue/main.c
+++ b/regress/sys/kern/kqueue/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.3 2002/06/19 03:05:07 mickey Exp $ */
+/* $OpenBSD: main.c,v 1.4 2003/06/12 05:06:47 mickey Exp $ */
/*
* Written by Artur Grabowski <art@openbsd.org> 2002 Public Domain
*/
@@ -11,6 +11,7 @@ int do_pipe(void);
int check_inheritance(void);
int do_process(void);
int do_random(void);
+int do_pty(void);
int
main(int argc, char **argv)
@@ -19,7 +20,7 @@ main(int argc, char **argv)
int ret, c;
ret = 0;
- while ((c = getopt(argc, argv, "fPpr")) != -1) {
+ while ((c = getopt(argc, argv, "fPprT")) != -1) {
switch (c) {
case 'p':
ret |= do_pipe();
@@ -33,8 +34,11 @@ main(int argc, char **argv)
case 'r':
ret |= do_random();
break;
+ case 'T':
+ ret |= do_pty();
+ break;
default:
- fprintf(stderr, "Usage: %s -[fPpr]\n", __progname);
+ fprintf(stderr, "Usage: %s -[fPprt]\n", __progname);
exit(1);
}
}