Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/lib/libc/sys Add a test for adding an event to an unsu...



details:   https://anonhg.NetBSD.org/src/rev/d483f49e9950
branches:  trunk
changeset: 782869:d483f49e9950
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Nov 24 15:05:45 2012 +0000

description:
Add a test for adding an event to an unsupported fd.

diffstat:

 tests/lib/libc/sys/t_kevent.c |  34 ++++++++++++++++++++++++++++++++--
 1 files changed, 32 insertions(+), 2 deletions(-)

diffs (67 lines):

diff -r 4da250c3a1d7 -r d483f49e9950 tests/lib/libc/sys/t_kevent.c
--- a/tests/lib/libc/sys/t_kevent.c     Sat Nov 24 14:01:28 2012 +0000
+++ b/tests/lib/libc/sys/t_kevent.c     Sat Nov 24 15:05:45 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: t_kevent.c,v 1.4 2012/06/02 16:52:18 martin Exp $ */
+/*     $NetBSD: t_kevent.c,v 1.5 2012/11/24 15:05:45 christos Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_kevent.c,v 1.4 2012/06/02 16:52:18 martin Exp $");
+__RCSID("$NetBSD: t_kevent.c,v 1.5 2012/11/24 15:05:45 christos Exp $");
 
 #include <sys/types.h>
 #include <sys/event.h>
@@ -41,6 +41,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <fcntl.h>
 #include <err.h>
 #include <sys/event.h>
 #include <sys/time.h>
@@ -137,11 +138,40 @@
        ATF_CHECK(WIFEXITED(status) && WEXITSTATUS(status)==0);
 }
 
+ATF_TC(kqueue_unsupported_fd);
+ATF_TC_HEAD(kqueue_unsupported_fd, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Checks that watching an fd whose"
+           " type is not supported does not crash the kernel");
+}
+
+ATF_TC_BODY(kqueue_unsupported_fd, tc)
+{
+       /* mqueue and semaphore use fnullop_kqueue also */
+       static const char drvctl[] = "/dev/drvctl";
+       int fd, kq;
+       struct kevent ev;
+
+       ATF_REQUIRE((fd = open(drvctl, O_RDONLY)) != -1);
+       ATF_REQUIRE((kq = kqueue()) != -1);
+
+       EV_SET(&ev, fd, EVFILT_VNODE, EV_ADD | EV_ENABLE | EV_CLEAR,
+          NOTE_DELETE|NOTE_WRITE|NOTE_EXTEND|NOTE_ATTRIB|NOTE_LINK|
+          NOTE_RENAME|NOTE_REVOKE, 0, 0);
+
+       ATF_REQUIRE(kevent(kq, &ev, 1, NULL, 0, NULL) == -1);
+       ATF_REQUIRE_ERRNO(EOPNOTSUPP, true);
+
+       (void)close(fd);
+}
+
+
 ATF_TP_ADD_TCS(tp)
 {
 
        ATF_TP_ADD_TC(tp, kevent_zerotimer);
        ATF_TP_ADD_TC(tp, kqueue_desc_passing);
+       ATF_TP_ADD_TC(tp, kqueue_unsupported_fd);
 
        return atf_no_error();
 }



Home | Main Index | Thread Index | Old Index