diff options
| author | mgorny <mgorny@NetBSD.org> | 2019-02-15 18:57:15 +0000 |
|---|---|---|
| committer | mgorny <mgorny@NetBSD.org> | 2019-02-15 18:57:15 +0000 |
| commit | fa4a0befc70b42761da93e4665288a387d3a1d1f (patch) | |
| tree | 32754b8f2f30702c2cb889d42215add9f0e7cbfd /tests/kernel/kqueue | |
| parent | a95837ea9342493a7a7b103802b8afb431ccf847 (diff) | |
Fix reporting EOF via kevent and add a test case
Fix the kernel pty driver to report closed slave via master's kevent
EVFILT_READ. This behavior matches the behavior for pipes, is
consistent with how FreeBSD implements it and is relied upon by LLDB's
main loop implementation.
Includes feedback by kre and kamil (from tech-kern), commit approved
by kamil.
Diffstat (limited to 'tests/kernel/kqueue')
| -rw-r--r-- | tests/kernel/kqueue/read/t_ttypty.c | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/tests/kernel/kqueue/read/t_ttypty.c b/tests/kernel/kqueue/read/t_ttypty.c index 89b1dc2ec4c..e0c2e77bf22 100644 --- a/tests/kernel/kqueue/read/t_ttypty.c +++ b/tests/kernel/kqueue/read/t_ttypty.c @@ -1,7 +1,7 @@ -/* $NetBSD: t_ttypty.c,v 1.2 2017/01/13 21:30:41 christos Exp $ */ +/* $NetBSD: t_ttypty.c,v 1.3 2019/02/15 18:57:15 mgorny Exp $ */ /*- - * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. + * Copyright (c) 2002, 2008, 2019 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -30,11 +30,12 @@ */ #include <sys/cdefs.h> -__COPYRIGHT("@(#) Copyright (c) 2008\ +__COPYRIGHT("@(#) Copyright (c) 2008, 2019\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_ttypty.c,v 1.2 2017/01/13 21:30:41 christos Exp $"); +__RCSID("$NetBSD: t_ttypty.c,v 1.3 2019/02/15 18:57:15 mgorny Exp $"); #include <sys/event.h> +#include <sys/time.h> #include <sys/wait.h> #include <poll.h> @@ -135,10 +136,48 @@ ATF_TC_BODY(slave, tc) h_check(false); } +ATF_TC(closed_slave); +ATF_TC_HEAD(closed_slave, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Checks EVFILT_READ reporting for slave tty being closed"); +} +ATF_TC_BODY(closed_slave, tc) +{ + char slavetty[1024]; + struct kevent event[1]; + int amaster, aslave; + int kq, n; + struct timespec timeout = {5, 0}; + + RL(openpty(&amaster, &aslave, slavetty, NULL, NULL)); + + (void)printf("tty: openpty master %d slave %d tty '%s'\n", + amaster, aslave, slavetty); + + RL(kq = kqueue()); + + EV_SET(&event[0], amaster, EVFILT_READ, EV_ADD|EV_ENABLE, 0, 0, 0); + RL(kevent(kq, event, 1, NULL, 0, NULL)); + + RL(close(aslave)); + + RL(n = kevent(kq, NULL, 0, event, 1, &timeout)); + + (void)printf("kevent num %d filt %d flags: %#x, fflags: %#x, " + "data: %" PRId64 "\n", n, event[0].filter, event[0].flags, + event[0].fflags, event[0].data); + + ATF_REQUIRE_EQ(n, 1); + ATF_REQUIRE_EQ(event[0].filter, EVFILT_READ); + ATF_REQUIRE_EQ(event[0].flags & EV_EOF, EV_EOF); +} + ATF_TP_ADD_TCS(tp) { ATF_TP_ADD_TC(tp, master); ATF_TP_ADD_TC(tp, slave); + ATF_TP_ADD_TC(tp, closed_slave); return atf_no_error(); } |
