1 /* $NetBSD: t_modautoload.c,v 1.4 2015/12/27 08:21:44 pgoyette Exp $ */
5 #include <sys/module.h>
6 #include <sys/dirent.h>
7 #include <sys/sysctl.h>
18 #include <rump/rump.h>
19 #include <rump/rump_syscalls.h>
21 #include <miscfs/kernfs/kernfs.h>
23 #include "../../h_macros.h"
26 ATF_TC_HEAD(modautoload, tc)
29 atf_tc_set_md_var(tc, "descr", "tests that kernel module "
30 "autoload works in rump");
36 bool old_autoload, new_autoload;
37 size_t old_len, new_len;
40 if (!rump_nativeabi_p())
41 atf_tc_skip("host kernel modules not supported");
45 if (rump_sys_mkdir("/kern", 0777) == -1)
46 atf_tc_fail_errno("mkdir /kern");
49 new_len = sizeof(new_autoload);
50 error = sysctlbyname("kern.module.autoload",
51 &old_autoload, &old_len,
52 &new_autoload, new_len);
54 atf_tc_fail_errno("could not enable module autoload");
56 if (rump_sys_mount(MOUNT_KERNFS, "/kern", 0, NULL, 0) == -1)
57 atf_tc_fail_errno("could not mount kernfs");
61 * Why use kernfs here? It talks to plenty of other parts with the
62 * kernel (e.g. vfs_attach() in modcmd), but is still easy to verify
63 * it's working correctly.
67 ATF_TC_BODY(modautoload, tc)
75 if ((fd = rump_sys_open("/kern/hz", O_RDONLY)) == -1)
76 atf_tc_fail_errno("open /kern/hz");
77 if (rump_sys_read(fd, buf, sizeof(buf)) <= 0)
78 atf_tc_fail_errno("read");
79 ATF_REQUIRE(atoi(buf) == MAGICNUM);
84 ATF_TP_ADD_TC(tp, modautoload);
86 return atf_no_error();