CVS commit: src/tests/kernel/kqueue

2020-10-31 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Oct 31 14:57:02 UTC 2020

Modified Files:
src/tests/kernel/kqueue: t_ioctl.c

Log Message:
Avoid hard-coding names and limits so this will not break again.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/kernel/kqueue/t_ioctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/kqueue/t_ioctl.c
diff -u src/tests/kernel/kqueue/t_ioctl.c:1.4 src/tests/kernel/kqueue/t_ioctl.c:1.5
--- src/tests/kernel/kqueue/t_ioctl.c:1.4	Tue Jan  9 12:35:29 2018
+++ src/tests/kernel/kqueue/t_ioctl.c	Sat Oct 31 10:57:02 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: t_ioctl.c,v 1.4 2018/01/09 17:35:29 martin Exp $ */
+/* $NetBSD: t_ioctl.c,v 1.5 2020/10/31 14:57:02 christos Exp $ */
 
 /*-
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -32,8 +32,9 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_ioctl.c,v 1.4 2018/01/09 17:35:29 martin Exp $");
+__RCSID("$NetBSD: t_ioctl.c,v 1.5 2020/10/31 14:57:02 christos Exp $");
 
+#define EVFILT_NAMES
 #include 
 #include 
 
@@ -61,13 +62,13 @@ ATF_TC_BODY(kfilter_byfilter, tc)
 	km.name = buf;
 	km.len = sizeof(buf) - 1;
 
-	for (i = 0; i < 8; ++i) {
+	for (i = 0; i < EVFILT_SYSCOUNT; ++i) {
 		km.filter = i;
 		RL(ioctl(kq, KFILTER_BYFILTER, ));
 		(void)printf("  map %d -> %s\n", km.filter, km.name);
 	}
 
-	km.filter = 8;
+	km.filter = EVFILT_SYSCOUNT;
 	ATF_REQUIRE_EQ(ioctl(kq, KFILTER_BYFILTER, ), -1);
 }
 
@@ -78,28 +79,16 @@ ATF_TC_HEAD(kfilter_byname, tc)
 }
 ATF_TC_BODY(kfilter_byname, tc)
 {
-	const char *tests[] = {
-		"EVFILT_READ",
-		"EVFILT_WRITE",
-		"EVFILT_AIO",
-		"EVFILT_VNODE",
-		"EVFILT_PROC",
-		"EVFILT_SIGNAL",
-		"EVFILT_TIMER",
-		"EVFILT_FS",
-		NULL
-	};
 	char buf[32];
 	struct kfilter_mapping km;
-	const char **test;
 	int kq;
 
 	RL(kq = kqueue());
 
 	km.name = buf;
 
-	for (test = [0]; *test != NULL; ++test) {
-		(void)strlcpy(buf, *test, sizeof(buf));
+	for (size_t i = 0; i < EVFILT_SYSCOUNT; i++) {
+		(void)strlcpy(buf, evfiltnames[i], sizeof(buf));
 		RL(ioctl(kq, KFILTER_BYNAME, ));
 		(void)printf("  map %s -> %d\n", km.name, km.filter);
 	}



CVS commit: src/tests/kernel/kqueue

2018-01-09 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Tue Jan  9 17:35:29 UTC 2018

Modified Files:
src/tests/kernel/kqueue: t_ioctl.c

Log Message:
Add EVFILT_FS


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/kqueue/t_ioctl.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/kqueue/t_ioctl.c
diff -u src/tests/kernel/kqueue/t_ioctl.c:1.3 src/tests/kernel/kqueue/t_ioctl.c:1.4
--- src/tests/kernel/kqueue/t_ioctl.c:1.3	Fri Jan 13 21:30:41 2017
+++ src/tests/kernel/kqueue/t_ioctl.c	Tue Jan  9 17:35:29 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: t_ioctl.c,v 1.3 2017/01/13 21:30:41 christos Exp $ */
+/* $NetBSD: t_ioctl.c,v 1.4 2018/01/09 17:35:29 martin Exp $ */
 
 /*-
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include 
 __COPYRIGHT("@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.");
-__RCSID("$NetBSD: t_ioctl.c,v 1.3 2017/01/13 21:30:41 christos Exp $");
+__RCSID("$NetBSD: t_ioctl.c,v 1.4 2018/01/09 17:35:29 martin Exp $");
 
 #include 
 #include 
@@ -61,13 +61,13 @@ ATF_TC_BODY(kfilter_byfilter, tc)
 	km.name = buf;
 	km.len = sizeof(buf) - 1;
 
-	for (i = 0; i < 7; ++i) {
+	for (i = 0; i < 8; ++i) {
 		km.filter = i;
 		RL(ioctl(kq, KFILTER_BYFILTER, ));
 		(void)printf("  map %d -> %s\n", km.filter, km.name);
 	}
 
-	km.filter = 7;
+	km.filter = 8;
 	ATF_REQUIRE_EQ(ioctl(kq, KFILTER_BYFILTER, ), -1);
 }
 
@@ -86,6 +86,7 @@ ATF_TC_BODY(kfilter_byname, tc)
 		"EVFILT_PROC",
 		"EVFILT_SIGNAL",
 		"EVFILT_TIMER",
+		"EVFILT_FS",
 		NULL
 	};
 	char buf[32];



CVS commit: src/tests/kernel/kqueue

2016-04-29 Thread Ryo ONODERA
Module Name:src
Committed By:   ryoon
Date:   Fri Apr 29 07:12:34 UTC 2016

Modified Files:
src/tests/kernel/kqueue: Makefile

Log Message:
Tab alignment


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/tests/kernel/kqueue/Makefile

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/kqueue/Makefile
diff -u src/tests/kernel/kqueue/Makefile:1.4 src/tests/kernel/kqueue/Makefile:1.5
--- src/tests/kernel/kqueue/Makefile:1.4	Wed Jan 14 22:22:32 2015
+++ src/tests/kernel/kqueue/Makefile	Fri Apr 29 07:12:34 2016
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.4 2015/01/14 22:22:32 christos Exp $
+# $NetBSD: Makefile,v 1.5 2016/04/29 07:12:34 ryoon Exp $
 
 WARNS?=6
 NOMAN=		# defined
@@ -7,7 +7,7 @@ NOMAN=		# defined
 
 TESTSDIR=	${TESTSBASE}/kernel/kqueue
 
-TESTS_SUBDIRS=		read
+TESTS_SUBDIRS=	read
 TESTS_SUBDIRS+=	write
 
 TESTS_C=	t_ioctl



CVS commit: src/tests/kernel/kqueue

2015-01-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jan 14 22:22:14 UTC 2015

Added Files:
src/tests/kernel/kqueue: t_vnode.c

Log Message:
PR/48958: rudolf: EVFILT_VNODE filter miscounting hardlinks (add test)


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/tests/kernel/kqueue/t_vnode.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/tests/kernel/kqueue/t_vnode.c
diff -u /dev/null src/tests/kernel/kqueue/t_vnode.c:1.1
--- /dev/null	Wed Jan 14 17:22:14 2015
+++ src/tests/kernel/kqueue/t_vnode.c	Wed Jan 14 17:22:14 2015
@@ -0,0 +1,533 @@
+#include sys/event.h
+#include sys/stat.h
+#include sys/time.h
+#include fcntl.h
+#include stdio.h
+#include unistd.h
+
+#include atf-c.h
+
+/*
+ * Test cases for events triggered by manipulating a target directory
+ * content.  Using EVFILT_VNODE filter on the target directory descriptor.
+ *
+ */
+
+static const char *dir_target = foo;
+static const char *dir_inside1 = foo/bar1;
+static const char *dir_inside2 = foo/bar2;
+static const char *dir_outside = bar;
+static const char *file_inside1 = foo/baz1;
+static const char *file_inside2 = foo/baz2;
+static const char *file_outside = qux;
+static const struct timespec ts = {0, 0};
+static int kq = -1;
+static int target = -1;
+
+int init_target(void);
+int init_kqueue(void);
+int create_file(const char *);
+void cleanup(void);
+
+int
+init_target(void)
+{
+	if (mkdir(dir_target, S_IRWXU)  0) {
+		return -1;
+	}
+	target = open(dir_target, O_RDONLY, 0);
+	return target;
+}
+
+int
+init_kqueue(void)
+{
+	struct kevent eventlist[1];
+
+	kq = kqueue();
+	if (kq  0) {
+		return -1;
+	}
+	EV_SET(eventlist[0], (uintptr_t)target, EVFILT_VNODE,
+		EV_ADD | EV_ONESHOT, NOTE_DELETE |
+		NOTE_WRITE | NOTE_EXTEND | NOTE_ATTRIB |
+		NOTE_LINK | NOTE_RENAME | NOTE_REVOKE, 0, 0);
+	return kevent(kq, eventlist, 1, NULL, 0, NULL);
+}
+
+int
+create_file(const char *file)
+{
+	int fd;
+
+	fd = open(file, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
+	if (fd  0) {
+		return -1;
+	}
+	return close(fd);
+}
+
+void
+cleanup(void)
+{
+	(void)unlink(file_inside1);
+	(void)unlink(file_inside2);
+	(void)unlink(file_outside);
+	(void)rmdir(dir_inside1);
+	(void)rmdir(dir_inside2);
+	(void)rmdir(dir_outside);
+	(void)rmdir(dir_target);
+	(void)close(kq);
+	(void)close(target);
+}
+
+ATF_TC_WITH_CLEANUP(dir_no_note_link_create_file_in);
+ATF_TC_HEAD(dir_no_note_link_create_file_in, tc)
+{
+	atf_tc_set_md_var(tc, descr, This test case ensures 
+		that kevent(2) does not return NOTE_LINK for the directory 
+		'foo' if a file 'foo/baz' is created.);
+}
+ATF_TC_BODY(dir_no_note_link_create_file_in, tc)
+{
+	struct kevent changelist[1];
+
+	ATF_REQUIRE(init_target() != -1);
+	ATF_REQUIRE(init_kqueue() != -1);
+
+	ATF_REQUIRE(create_file(file_inside1) != -1);
+	ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, ts) != -1);
+	ATF_CHECK_EQ(changelist[0].fflags  NOTE_LINK, 0);
+}
+ATF_TC_CLEANUP(dir_no_note_link_create_file_in, tc)
+{
+	cleanup();
+}
+
+ATF_TC_WITH_CLEANUP(dir_no_note_link_delete_file_in);
+ATF_TC_HEAD(dir_no_note_link_delete_file_in, tc)
+{
+	atf_tc_set_md_var(tc, descr, This test case ensures 
+		that kevent(2) does not return NOTE_LINK for the directory 
+		'foo' if a file 'foo/baz' is deleted.);
+}
+ATF_TC_BODY(dir_no_note_link_delete_file_in, tc)
+{
+	struct kevent changelist[1];
+
+	ATF_REQUIRE(init_target() != -1);
+	ATF_REQUIRE(create_file(file_inside1) != -1);
+	ATF_REQUIRE(init_kqueue() != -1);
+
+	ATF_REQUIRE(unlink(file_inside1) != -1);
+	ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, ts) != -1);
+	ATF_CHECK_EQ(changelist[0].fflags  NOTE_LINK, 0);
+}
+ATF_TC_CLEANUP(dir_no_note_link_delete_file_in, tc)
+{
+	cleanup();
+}
+
+ATF_TC_WITH_CLEANUP(dir_no_note_link_mv_dir_within);
+ATF_TC_HEAD(dir_no_note_link_mv_dir_within, tc)
+{
+	atf_tc_set_md_var(tc, descr, This test case ensures 
+		that kevent(2) does not return NOTE_LINK for the directory 
+		'foo' if a directory 'foo/bar' is renamed to 'foo/baz'.);
+}
+ATF_TC_BODY(dir_no_note_link_mv_dir_within, tc)
+{
+	struct kevent changelist[1];
+
+	ATF_REQUIRE(init_target() != -1);
+	ATF_REQUIRE(mkdir(dir_inside1, S_IRWXU) != -1);
+	ATF_REQUIRE(init_kqueue() != -1);
+
+	ATF_REQUIRE(rename(dir_inside1, dir_inside2) != -1);
+	ATF_REQUIRE(kevent(kq, NULL, 0, changelist, 1, ts) != -1);
+	ATF_CHECK_EQ(changelist[0].fflags  NOTE_LINK, 0);
+}
+ATF_TC_CLEANUP(dir_no_note_link_mv_dir_within, tc)
+{
+	cleanup();
+}
+
+ATF_TC_WITH_CLEANUP(dir_no_note_link_mv_file_within);
+ATF_TC_HEAD(dir_no_note_link_mv_file_within, tc)
+{
+	atf_tc_set_md_var(tc, descr, This test case ensures 
+		that kevent(2) does not return NOTE_LINK for the directory 
+		'foo' if a file 'foo/baz' is renamed to 'foo/qux'.);
+}
+ATF_TC_BODY(dir_no_note_link_mv_file_within, tc)
+{
+	struct kevent changelist[1];
+
+	ATF_REQUIRE(init_target() != -1);
+	ATF_REQUIRE(create_file(file_inside1) != -1);
+	

CVS commit: src/tests/kernel/kqueue

2015-01-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Jan 14 22:22:32 UTC 2015

Modified Files:
src/tests/kernel/kqueue: Makefile t_ioctl.c t_proc1.c t_proc2.c
t_proc3.c

Log Message:
bump warns.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/tests/kernel/kqueue/Makefile
cvs rdiff -u -r1.1 -r1.2 src/tests/kernel/kqueue/t_ioctl.c \
src/tests/kernel/kqueue/t_proc1.c src/tests/kernel/kqueue/t_proc2.c \
src/tests/kernel/kqueue/t_proc3.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/kernel/kqueue/Makefile
diff -u src/tests/kernel/kqueue/Makefile:1.3 src/tests/kernel/kqueue/Makefile:1.4
--- src/tests/kernel/kqueue/Makefile:1.3	Sat Nov 17 16:55:24 2012
+++ src/tests/kernel/kqueue/Makefile	Wed Jan 14 17:22:32 2015
@@ -1,5 +1,6 @@
-# $NetBSD: Makefile,v 1.3 2012/11/17 21:55:24 joerg Exp $
+# $NetBSD: Makefile,v 1.4 2015/01/14 22:22:32 christos Exp $
 
+WARNS?=6
 NOMAN=		# defined
 
 .include bsd.own.mk
@@ -14,5 +15,6 @@ TESTS_C+=	t_proc1
 TESTS_C+=	t_proc2
 TESTS_C+=	t_proc3
 TESTS_C+=	t_sig
+TESTS_C+=	t_vnode
 
 .include bsd.test.mk

Index: src/tests/kernel/kqueue/t_ioctl.c
diff -u src/tests/kernel/kqueue/t_ioctl.c:1.1 src/tests/kernel/kqueue/t_ioctl.c:1.2
--- src/tests/kernel/kqueue/t_ioctl.c:1.1	Fri Feb 20 16:39:57 2009
+++ src/tests/kernel/kqueue/t_ioctl.c	Wed Jan 14 17:22:32 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: t_ioctl.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $ */
+/* $NetBSD: t_ioctl.c,v 1.2 2015/01/14 22:22:32 christos Exp $ */
 
 /*-
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include sys/cdefs.h
 __COPYRIGHT(@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.);
-__RCSID($NetBSD: t_ioctl.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $);
+__RCSID($NetBSD: t_ioctl.c,v 1.2 2015/01/14 22:22:32 christos Exp $);
 
 #include sys/event.h
 #include sys/ioctl.h
@@ -53,7 +53,8 @@ ATF_TC_BODY(kfilter_byfilter, tc)
 {
 	char buf[32];
 	struct kfilter_mapping km;
-	int i, kq;
+	int kq;
+	uint32_t i;
 
 	RL(kq = kqueue());
 
Index: src/tests/kernel/kqueue/t_proc1.c
diff -u src/tests/kernel/kqueue/t_proc1.c:1.1 src/tests/kernel/kqueue/t_proc1.c:1.2
--- src/tests/kernel/kqueue/t_proc1.c:1.1	Fri Feb 20 16:39:57 2009
+++ src/tests/kernel/kqueue/t_proc1.c	Wed Jan 14 17:22:32 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: t_proc1.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $ */
+/* $NetBSD: t_proc1.c,v 1.2 2015/01/14 22:22:32 christos Exp $ */
 
 /*-
  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include sys/cdefs.h
 __COPYRIGHT(@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.);
-__RCSID($NetBSD: t_proc1.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $);
+__RCSID($NetBSD: t_proc1.c,v 1.2 2015/01/14 22:22:32 christos Exp $);
 
 /*
  * this also used to trigger problem fixed in
@@ -99,7 +99,8 @@ ATF_TC_BODY(proc1, tc)
 {
 	struct kevent event[1];
 	pid_t pid;
-	int kq, want, status;
+	int kq, status;
+	u_int want;
 
 	RL(kq = kqueue());
 
@@ -112,7 +113,7 @@ ATF_TC_BODY(proc1, tc)
 
 	(void)sleep(1); /* give child some time to come up */
 
-	event[0].ident = pid;
+	event[0].ident = (uintptr_t)pid;
 	event[0].filter = EVFILT_PROC;
 	event[0].flags = EV_ADD | EV_ENABLE;
 	event[0].fflags = NOTE_EXIT | NOTE_FORK | NOTE_EXEC; /* | NOTE_TRACK;*/
Index: src/tests/kernel/kqueue/t_proc2.c
diff -u src/tests/kernel/kqueue/t_proc2.c:1.1 src/tests/kernel/kqueue/t_proc2.c:1.2
--- src/tests/kernel/kqueue/t_proc2.c:1.1	Fri Feb 20 16:39:57 2009
+++ src/tests/kernel/kqueue/t_proc2.c	Wed Jan 14 17:22:32 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: t_proc2.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $ */
+/* $NetBSD: t_proc2.c,v 1.2 2015/01/14 22:22:32 christos Exp $ */
 
 /*-
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
 #include sys/cdefs.h
 __COPYRIGHT(@(#) Copyright (c) 2008\
  The NetBSD Foundation, inc. All rights reserved.);
-__RCSID($NetBSD: t_proc2.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $);
+__RCSID($NetBSD: t_proc2.c,v 1.2 2015/01/14 22:22:32 christos Exp $);
 
 #include sys/event.h
 #include sys/time.h
@@ -106,7 +106,8 @@ ATF_TC_BODY(proc2, tc)
 		/* NOTREACHED */
 	}
 
-	EV_SET(ke, pid, EVFILT_PROC, EV_ADD, NOTE_FORK|NOTE_TRACK, 0, 0);
+	EV_SET(ke, (uintptr_t)pid, EVFILT_PROC, EV_ADD, NOTE_FORK|NOTE_TRACK,
+	0, 0);
 
 	RL(kevent(kq, ke, 1, NULL, 0, timeout));
 
Index: src/tests/kernel/kqueue/t_proc3.c
diff -u src/tests/kernel/kqueue/t_proc3.c:1.1 src/tests/kernel/kqueue/t_proc3.c:1.2
--- src/tests/kernel/kqueue/t_proc3.c:1.1	Sat Nov 17 16:55:24 2012
+++ src/tests/kernel/kqueue/t_proc3.c	Wed Jan 14 17:22:32 2015
@@ -1,4 +1,4 @@
-/* $NetBSD: t_proc3.c,v 1.1 2012/11/17 21:55:24 joerg Exp $ */
+/* $NetBSD: t_proc3.c,v 1.2 2015/01/14 22:22:32 christos Exp $ */
 
 /*-
  * Copyright (c) 2012 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__RCSID($NetBSD: t_proc3.c,v 1.1 2012/11/17