1 /* $NetBSD: t_builtin.c,v 1.2 2010/11/03 16:10:23 christos Exp $ */
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
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>
37 #include <miscfs/kernfs/kernfs.h>
39 #include <rump/rump.h>
40 #include <rump/rump_syscalls.h>
42 #include "../h_macros.h"
45 #define HZFILE MYMP "/hz"
47 static char kernfs
[] = "kernfs";
56 fd
= rump_sys_open(HZFILE
, O_RDONLY
);
59 if (rump_sys_read(fd
, buf
, sizeof(buf
)) < 1)
61 RL(rump_sys_close(fd
));
67 ATF_TC_HEAD(disable
, tc
)
70 atf_tc_set_md_var(tc
, "descr", "Tests that builtin modules can "
74 ATF_TC_BODY(disable
, tc
)
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
));
86 ATF_TC_HEAD(noauto
, tc
)
88 atf_tc_set_md_var(tc
, "descr", "Tests that disabled builtin modules "
92 ATF_TC_BODY(noauto
, tc
)
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);
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
;
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];
148 RL(rump_sys_mkdir(MYMP
, 0777));
150 RL(rump_sys_modctl(MODCTL_UNLOAD
, kernfs
));
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);
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
)
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);
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();