Remove building with NOCRYPTO option
[minix.git] / tests / modules / t_builtin.c
blob0d9a3f0dc129a78015d95bd3dfd60d7b3036c33f
1 /* $NetBSD: t_builtin.c,v 1.2 2010/11/03 16:10:23 christos Exp $ */
3 /*-
4 * Copyright (c) 2010 The NetBSD Foundation, Inc. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
16 * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/types.h>
30 #include <sys/module.h>
31 #include <sys/mount.h>
33 #include <atf-c.h>
34 #include <fcntl.h>
35 #include <stdbool.h>
37 #include <miscfs/kernfs/kernfs.h>
39 #include <rump/rump.h>
40 #include <rump/rump_syscalls.h>
42 #include "../h_macros.h"
44 #define MYMP "/mnt"
45 #define HZFILE MYMP "/hz"
47 static char kernfs[] = "kernfs";
49 static bool
50 check_kernfs(void)
52 char buf[16];
53 bool rv = true;
54 int fd;
56 fd = rump_sys_open(HZFILE, O_RDONLY);
57 if (fd == -1)
58 return false;
59 if (rump_sys_read(fd, buf, sizeof(buf)) < 1)
60 rv = false;
61 RL(rump_sys_close(fd));
63 return rv;
66 ATF_TC(disable);
67 ATF_TC_HEAD(disable, tc)
70 atf_tc_set_md_var(tc, "descr", "Tests that builtin modules can "
71 "be disabled");
74 ATF_TC_BODY(disable, tc)
77 rump_init();
78 RL(rump_sys_mkdir(MYMP, 0777));
79 RL(rump_sys_mount(MOUNT_KERNFS, MYMP, 0, NULL, 0));
80 ATF_REQUIRE(check_kernfs());
81 RL(rump_sys_unmount(MYMP, 0));
82 RL(rump_sys_modctl(MODCTL_UNLOAD, kernfs));
85 ATF_TC(noauto);
86 ATF_TC_HEAD(noauto, tc)
88 atf_tc_set_md_var(tc, "descr", "Tests that disabled builtin modules "
89 "will not autoload");
92 ATF_TC_BODY(noauto, tc)
95 rump_init();
96 RL(rump_sys_mkdir(MYMP, 0777));
98 RL(rump_sys_modctl(MODCTL_UNLOAD, kernfs));
100 ATF_REQUIRE_ERRNO(ENODEV,
101 rump_sys_mount(MOUNT_KERNFS, MYMP, 0, NULL, 0) == -1);
104 ATF_TC(forcereload);
105 ATF_TC_HEAD(forcereload, tc)
107 atf_tc_set_md_var(tc, "descr", "Tests that disabled builtin modules "
108 "can be force-reloaded");
111 ATF_TC_BODY(forcereload, tc)
113 struct modctl_load mod;
115 rump_init();
116 RL(rump_sys_mkdir(MYMP, 0777));
118 RL(rump_sys_modctl(MODCTL_UNLOAD, kernfs));
119 ATF_REQUIRE_ERRNO(ENODEV,
120 rump_sys_mount(MOUNT_KERNFS, MYMP, 0, NULL, 0) == -1);
122 memset(&mod, 0, sizeof(mod));
123 mod.ml_filename = kernfs;
124 mod.ml_flags = MODCTL_LOAD_FORCE;
126 RL(rump_sys_modctl(MODCTL_LOAD, &mod));
128 RL(rump_sys_mount(MOUNT_KERNFS, MYMP, 0, NULL, 0));
129 ATF_REQUIRE(check_kernfs());
130 RL(rump_sys_unmount(MYMP, 0));
133 ATF_TC(disabledstat);
134 ATF_TC_HEAD(disabledstat, tc)
136 atf_tc_set_md_var(tc, "descr", "Tests that disabled builtin modules "
137 "show up in modstat with refcount -1");
140 ATF_TC_BODY(disabledstat, tc)
142 struct modstat ms[128];
143 struct iovec iov;
144 size_t i;
145 bool found = false;
147 rump_init();
148 RL(rump_sys_mkdir(MYMP, 0777));
150 RL(rump_sys_modctl(MODCTL_UNLOAD, kernfs));
152 iov.iov_base = ms;
153 iov.iov_len = sizeof(ms);
154 RL(rump_sys_modctl(MODCTL_STAT, &iov));
156 for (i = 0; i < __arraycount(ms); i++) {
157 if (strcmp(ms[i].ms_name, kernfs) == 0) {
158 ATF_REQUIRE_EQ(ms[i].ms_refcnt, (u_int)-1);
159 found = 1;
160 break;
163 ATF_REQUIRE(found);
166 ATF_TC(busydisable);
167 ATF_TC_HEAD(busydisable, tc)
169 atf_tc_set_md_var(tc, "descr", "Tests that busy builtin modules "
170 "cannot be disabled");
173 ATF_TC_BODY(busydisable, tc)
176 rump_init();
177 RL(rump_sys_mkdir(MYMP, 0777));
178 RL(rump_sys_mount(MOUNT_KERNFS, MYMP, 0, NULL, 0));
179 ATF_REQUIRE(check_kernfs());
180 ATF_REQUIRE_ERRNO(EBUSY,
181 rump_sys_modctl(MODCTL_UNLOAD, kernfs) == -1);
184 ATF_TP_ADD_TCS(tp)
187 ATF_TP_ADD_TC(tp, disable);
188 ATF_TP_ADD_TC(tp, noauto);
189 ATF_TP_ADD_TC(tp, forcereload);
190 ATF_TP_ADD_TC(tp, disabledstat);
191 ATF_TP_ADD_TC(tp, busydisable);
193 return atf_no_error();