1*0a6a1f1dSLionel Sambuc /* $NetBSD: t_ioctl.c,v 1.2 2015/01/14 22:22:32 christos Exp $ */
211be35a1SLionel Sambuc
311be35a1SLionel Sambuc /*-
411be35a1SLionel Sambuc * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc.
511be35a1SLionel Sambuc * All rights reserved.
611be35a1SLionel Sambuc *
711be35a1SLionel Sambuc * This code is derived from software contributed to The NetBSD Foundation
811be35a1SLionel Sambuc * by Luke Mewburn.
911be35a1SLionel Sambuc *
1011be35a1SLionel Sambuc * Redistribution and use in source and binary forms, with or without
1111be35a1SLionel Sambuc * modification, are permitted provided that the following conditions
1211be35a1SLionel Sambuc * are met:
1311be35a1SLionel Sambuc * 1. Redistributions of source code must retain the above copyright
1411be35a1SLionel Sambuc * notice, this list of conditions and the following disclaimer.
1511be35a1SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
1611be35a1SLionel Sambuc * notice, this list of conditions and the following disclaimer in the
1711be35a1SLionel Sambuc * documentation and/or other materials provided with the distribution.
1811be35a1SLionel Sambuc *
1911be35a1SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2011be35a1SLionel Sambuc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2111be35a1SLionel Sambuc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2211be35a1SLionel Sambuc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2311be35a1SLionel Sambuc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2411be35a1SLionel Sambuc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2511be35a1SLionel Sambuc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2611be35a1SLionel Sambuc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2711be35a1SLionel Sambuc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2811be35a1SLionel Sambuc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2911be35a1SLionel Sambuc * POSSIBILITY OF SUCH DAMAGE.
3011be35a1SLionel Sambuc */
3111be35a1SLionel Sambuc
3211be35a1SLionel Sambuc #include <sys/cdefs.h>
3311be35a1SLionel Sambuc __COPYRIGHT("@(#) Copyright (c) 2008\
3411be35a1SLionel Sambuc The NetBSD Foundation, inc. All rights reserved.");
35*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: t_ioctl.c,v 1.2 2015/01/14 22:22:32 christos Exp $");
3611be35a1SLionel Sambuc
3711be35a1SLionel Sambuc #include <sys/event.h>
3811be35a1SLionel Sambuc #include <sys/ioctl.h>
3911be35a1SLionel Sambuc
4011be35a1SLionel Sambuc #include <stdio.h>
4111be35a1SLionel Sambuc #include <string.h>
4211be35a1SLionel Sambuc
4311be35a1SLionel Sambuc #include <atf-c.h>
4411be35a1SLionel Sambuc
4511be35a1SLionel Sambuc #include "../../h_macros.h"
4611be35a1SLionel Sambuc
4711be35a1SLionel Sambuc ATF_TC(kfilter_byfilter);
ATF_TC_HEAD(kfilter_byfilter,tc)4811be35a1SLionel Sambuc ATF_TC_HEAD(kfilter_byfilter, tc)
4911be35a1SLionel Sambuc {
5011be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Checks KFILTER_BYFILTER ioctl");
5111be35a1SLionel Sambuc }
ATF_TC_BODY(kfilter_byfilter,tc)5211be35a1SLionel Sambuc ATF_TC_BODY(kfilter_byfilter, tc)
5311be35a1SLionel Sambuc {
5411be35a1SLionel Sambuc char buf[32];
5511be35a1SLionel Sambuc struct kfilter_mapping km;
56*0a6a1f1dSLionel Sambuc int kq;
57*0a6a1f1dSLionel Sambuc uint32_t i;
5811be35a1SLionel Sambuc
5911be35a1SLionel Sambuc RL(kq = kqueue());
6011be35a1SLionel Sambuc
6111be35a1SLionel Sambuc km.name = buf;
6211be35a1SLionel Sambuc km.len = sizeof(buf) - 1;
6311be35a1SLionel Sambuc
6411be35a1SLionel Sambuc for (i = 0; i < 7; ++i) {
6511be35a1SLionel Sambuc km.filter = i;
6611be35a1SLionel Sambuc RL(ioctl(kq, KFILTER_BYFILTER, &km));
6711be35a1SLionel Sambuc (void)printf(" map %d -> %s\n", km.filter, km.name);
6811be35a1SLionel Sambuc }
6911be35a1SLionel Sambuc
7011be35a1SLionel Sambuc km.filter = 7;
7111be35a1SLionel Sambuc ATF_REQUIRE_EQ(ioctl(kq, KFILTER_BYFILTER, &km), -1);
7211be35a1SLionel Sambuc }
7311be35a1SLionel Sambuc
7411be35a1SLionel Sambuc ATF_TC(kfilter_byname);
ATF_TC_HEAD(kfilter_byname,tc)7511be35a1SLionel Sambuc ATF_TC_HEAD(kfilter_byname, tc)
7611be35a1SLionel Sambuc {
7711be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "Checks KFILTER_BYNAME ioctl");
7811be35a1SLionel Sambuc }
ATF_TC_BODY(kfilter_byname,tc)7911be35a1SLionel Sambuc ATF_TC_BODY(kfilter_byname, tc)
8011be35a1SLionel Sambuc {
8111be35a1SLionel Sambuc const char *tests[] = {
8211be35a1SLionel Sambuc "EVFILT_READ",
8311be35a1SLionel Sambuc "EVFILT_WRITE",
8411be35a1SLionel Sambuc "EVFILT_AIO",
8511be35a1SLionel Sambuc "EVFILT_VNODE",
8611be35a1SLionel Sambuc "EVFILT_PROC",
8711be35a1SLionel Sambuc "EVFILT_SIGNAL",
8811be35a1SLionel Sambuc "EVFILT_TIMER",
8911be35a1SLionel Sambuc NULL
9011be35a1SLionel Sambuc };
9111be35a1SLionel Sambuc char buf[32];
9211be35a1SLionel Sambuc struct kfilter_mapping km;
9311be35a1SLionel Sambuc const char **test;
9411be35a1SLionel Sambuc int kq;
9511be35a1SLionel Sambuc
9611be35a1SLionel Sambuc RL(kq = kqueue());
9711be35a1SLionel Sambuc
9811be35a1SLionel Sambuc km.name = buf;
9911be35a1SLionel Sambuc
10011be35a1SLionel Sambuc for (test = &tests[0]; *test != NULL; ++test) {
10111be35a1SLionel Sambuc (void)strlcpy(buf, *test, sizeof(buf));
10211be35a1SLionel Sambuc RL(ioctl(kq, KFILTER_BYNAME, &km));
10311be35a1SLionel Sambuc (void)printf(" map %s -> %d\n", km.name, km.filter);
10411be35a1SLionel Sambuc }
10511be35a1SLionel Sambuc
10611be35a1SLionel Sambuc (void)strlcpy(buf, "NOTREG_FILTER", sizeof(buf));
10711be35a1SLionel Sambuc ATF_REQUIRE_EQ(ioctl(kq, KFILTER_BYNAME, &km), -1);
10811be35a1SLionel Sambuc }
10911be35a1SLionel Sambuc
ATF_TP_ADD_TCS(tp)11011be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
11111be35a1SLionel Sambuc {
11211be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, kfilter_byfilter);
11311be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, kfilter_byname);
11411be35a1SLionel Sambuc
11511be35a1SLionel Sambuc return atf_no_error();
11611be35a1SLionel Sambuc }
117