xref: /freebsd/contrib/netbsd-tests/kernel/kqueue/t_ioctl.c (revision 1a36faad54665288ed4eb839d2a4699ae2ead45e)
1*63d1fd59SEnji Cooper /* $NetBSD: t_ioctl.c,v 1.3 2017/01/13 21:30:41 christos Exp $ */
257718be8SEnji Cooper 
357718be8SEnji Cooper /*-
457718be8SEnji Cooper  * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
557718be8SEnji Cooper  * All rights reserved.
657718be8SEnji Cooper  *
757718be8SEnji Cooper  * This code is derived from software contributed to The NetBSD Foundation
857718be8SEnji Cooper  * by Luke Mewburn.
957718be8SEnji Cooper  *
1057718be8SEnji Cooper  * Redistribution and use in source and binary forms, with or without
1157718be8SEnji Cooper  * modification, are permitted provided that the following conditions
1257718be8SEnji Cooper  * are met:
1357718be8SEnji Cooper  * 1. Redistributions of source code must retain the above copyright
1457718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer.
1557718be8SEnji Cooper  * 2. Redistributions in binary form must reproduce the above copyright
1657718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer in the
1757718be8SEnji Cooper  *    documentation and/or other materials provided with the distribution.
1857718be8SEnji Cooper  *
1957718be8SEnji Cooper  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2057718be8SEnji Cooper  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2157718be8SEnji Cooper  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2257718be8SEnji Cooper  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2357718be8SEnji Cooper  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2457718be8SEnji Cooper  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2557718be8SEnji Cooper  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2657718be8SEnji Cooper  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2757718be8SEnji Cooper  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2857718be8SEnji Cooper  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2957718be8SEnji Cooper  * POSSIBILITY OF SUCH DAMAGE.
3057718be8SEnji Cooper  */
3157718be8SEnji Cooper 
3257718be8SEnji Cooper #include <sys/cdefs.h>
3357718be8SEnji Cooper __COPYRIGHT("@(#) Copyright (c) 2008\
3457718be8SEnji Cooper  The NetBSD Foundation, inc. All rights reserved.");
35*63d1fd59SEnji Cooper __RCSID("$NetBSD: t_ioctl.c,v 1.3 2017/01/13 21:30:41 christos Exp $");
3657718be8SEnji Cooper 
3757718be8SEnji Cooper #include <sys/event.h>
3857718be8SEnji Cooper #include <sys/ioctl.h>
3957718be8SEnji Cooper 
4057718be8SEnji Cooper #include <stdio.h>
4157718be8SEnji Cooper #include <string.h>
4257718be8SEnji Cooper 
4357718be8SEnji Cooper #include <atf-c.h>
4457718be8SEnji Cooper 
45*63d1fd59SEnji Cooper #include "h_macros.h"
4657718be8SEnji Cooper 
4757718be8SEnji Cooper ATF_TC(kfilter_byfilter);
ATF_TC_HEAD(kfilter_byfilter,tc)4857718be8SEnji Cooper ATF_TC_HEAD(kfilter_byfilter, tc)
4957718be8SEnji Cooper {
5057718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Checks KFILTER_BYFILTER ioctl");
5157718be8SEnji Cooper }
ATF_TC_BODY(kfilter_byfilter,tc)5257718be8SEnji Cooper ATF_TC_BODY(kfilter_byfilter, tc)
5357718be8SEnji Cooper {
5457718be8SEnji Cooper 	char buf[32];
5557718be8SEnji Cooper 	struct kfilter_mapping km;
56640235e2SEnji Cooper 	int kq;
57640235e2SEnji Cooper 	uint32_t i;
5857718be8SEnji Cooper 
5957718be8SEnji Cooper 	RL(kq = kqueue());
6057718be8SEnji Cooper 
6157718be8SEnji Cooper 	km.name = buf;
6257718be8SEnji Cooper 	km.len = sizeof(buf) - 1;
6357718be8SEnji Cooper 
6457718be8SEnji Cooper 	for (i = 0; i < 7; ++i) {
6557718be8SEnji Cooper 		km.filter = i;
6657718be8SEnji Cooper 		RL(ioctl(kq, KFILTER_BYFILTER, &km));
6757718be8SEnji Cooper 		(void)printf("  map %d -> %s\n", km.filter, km.name);
6857718be8SEnji Cooper 	}
6957718be8SEnji Cooper 
7057718be8SEnji Cooper 	km.filter = 7;
7157718be8SEnji Cooper 	ATF_REQUIRE_EQ(ioctl(kq, KFILTER_BYFILTER, &km), -1);
7257718be8SEnji Cooper }
7357718be8SEnji Cooper 
7457718be8SEnji Cooper ATF_TC(kfilter_byname);
ATF_TC_HEAD(kfilter_byname,tc)7557718be8SEnji Cooper ATF_TC_HEAD(kfilter_byname, tc)
7657718be8SEnji Cooper {
7757718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "Checks KFILTER_BYNAME ioctl");
7857718be8SEnji Cooper }
ATF_TC_BODY(kfilter_byname,tc)7957718be8SEnji Cooper ATF_TC_BODY(kfilter_byname, tc)
8057718be8SEnji Cooper {
8157718be8SEnji Cooper 	const char *tests[] = {
8257718be8SEnji Cooper 		"EVFILT_READ",
8357718be8SEnji Cooper 		"EVFILT_WRITE",
8457718be8SEnji Cooper 		"EVFILT_AIO",
8557718be8SEnji Cooper 		"EVFILT_VNODE",
8657718be8SEnji Cooper 		"EVFILT_PROC",
8757718be8SEnji Cooper 		"EVFILT_SIGNAL",
8857718be8SEnji Cooper 		"EVFILT_TIMER",
8957718be8SEnji Cooper 		NULL
9057718be8SEnji Cooper 	};
9157718be8SEnji Cooper 	char buf[32];
9257718be8SEnji Cooper 	struct kfilter_mapping km;
9357718be8SEnji Cooper 	const char **test;
9457718be8SEnji Cooper 	int kq;
9557718be8SEnji Cooper 
9657718be8SEnji Cooper 	RL(kq = kqueue());
9757718be8SEnji Cooper 
9857718be8SEnji Cooper 	km.name = buf;
9957718be8SEnji Cooper 
10057718be8SEnji Cooper 	for (test = &tests[0]; *test != NULL; ++test) {
10157718be8SEnji Cooper 		(void)strlcpy(buf, *test, sizeof(buf));
10257718be8SEnji Cooper 		RL(ioctl(kq, KFILTER_BYNAME, &km));
10357718be8SEnji Cooper 		(void)printf("  map %s -> %d\n", km.name, km.filter);
10457718be8SEnji Cooper 	}
10557718be8SEnji Cooper 
10657718be8SEnji Cooper 	(void)strlcpy(buf, "NOTREG_FILTER", sizeof(buf));
10757718be8SEnji Cooper 	ATF_REQUIRE_EQ(ioctl(kq, KFILTER_BYNAME, &km), -1);
10857718be8SEnji Cooper }
10957718be8SEnji Cooper 
ATF_TP_ADD_TCS(tp)11057718be8SEnji Cooper ATF_TP_ADD_TCS(tp)
11157718be8SEnji Cooper {
11257718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, kfilter_byfilter);
11357718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, kfilter_byname);
11457718be8SEnji Cooper 
11557718be8SEnji Cooper 	return atf_no_error();
11657718be8SEnji Cooper }
117