xref: /minix3/tests/rump/modautoload/t_modautoload.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: t_modautoload.c,v 1.2 2014/03/10 22:38:53 pooka Exp $	*/
211be35a1SLionel Sambuc 
311be35a1SLionel Sambuc #include <sys/types.h>
411be35a1SLionel Sambuc #include <sys/mount.h>
511be35a1SLionel Sambuc #include <sys/module.h>
611be35a1SLionel Sambuc #include <sys/dirent.h>
711be35a1SLionel Sambuc #include <sys/sysctl.h>
811be35a1SLionel Sambuc 
911be35a1SLionel Sambuc #include <atf-c.h>
1011be35a1SLionel Sambuc #include <err.h>
1111be35a1SLionel Sambuc #include <errno.h>
1211be35a1SLionel Sambuc #include <fcntl.h>
1311be35a1SLionel Sambuc #include <stdio.h>
1411be35a1SLionel Sambuc #include <unistd.h>
1511be35a1SLionel Sambuc #include <string.h>
1611be35a1SLionel Sambuc #include <stdlib.h>
1711be35a1SLionel Sambuc 
1811be35a1SLionel Sambuc #include <rump/rump.h>
1911be35a1SLionel Sambuc #include <rump/rump_syscalls.h>
2011be35a1SLionel Sambuc 
2111be35a1SLionel Sambuc #include <miscfs/kernfs/kernfs.h>
2211be35a1SLionel Sambuc 
2311be35a1SLionel Sambuc #include "../../h_macros.h"
2411be35a1SLionel Sambuc 
2511be35a1SLionel Sambuc ATF_TC(modautoload);
ATF_TC_HEAD(modautoload,tc)2611be35a1SLionel Sambuc ATF_TC_HEAD(modautoload, tc)
2711be35a1SLionel Sambuc {
2811be35a1SLionel Sambuc 
2911be35a1SLionel Sambuc 	atf_tc_set_md_var(tc, "descr", "tests that kernel module "
3011be35a1SLionel Sambuc 	    "autoload works in rump");
3111be35a1SLionel Sambuc }
3211be35a1SLionel Sambuc 
3311be35a1SLionel Sambuc static void
mountkernfs(void)3411be35a1SLionel Sambuc mountkernfs(void)
3511be35a1SLionel Sambuc {
3611be35a1SLionel Sambuc 
37*0a6a1f1dSLionel Sambuc 	if (!rump_nativeabi_p())
38*0a6a1f1dSLionel Sambuc 		atf_tc_skip("host kernel modules not supported");
3911be35a1SLionel Sambuc 
4011be35a1SLionel Sambuc 	rump_init();
4111be35a1SLionel Sambuc 
4211be35a1SLionel Sambuc 	if (rump_sys_mkdir("/kern", 0777) == -1)
4311be35a1SLionel Sambuc 		atf_tc_fail_errno("mkdir /kern");
4411be35a1SLionel Sambuc 	if (rump_sys_mount(MOUNT_KERNFS, "/kern", 0, NULL, 0) == -1)
4511be35a1SLionel Sambuc 		atf_tc_fail_errno("could not mount kernfs");
4611be35a1SLionel Sambuc }
4711be35a1SLionel Sambuc 
4811be35a1SLionel Sambuc /*
4911be35a1SLionel Sambuc  * Why use kernfs here?  It talks to plenty of other parts with the
5011be35a1SLionel Sambuc  * kernel (e.g. vfs_attach() in modcmd), but is still easy to verify
5111be35a1SLionel Sambuc  * it's working correctly.
5211be35a1SLionel Sambuc  */
5311be35a1SLionel Sambuc 
5411be35a1SLionel Sambuc #define MAGICNUM 1323
ATF_TC_BODY(modautoload,tc)5511be35a1SLionel Sambuc ATF_TC_BODY(modautoload, tc)
5611be35a1SLionel Sambuc {
5711be35a1SLionel Sambuc 	extern int rumpns_hz;
5811be35a1SLionel Sambuc 	char buf[64];
5911be35a1SLionel Sambuc 	int fd;
6011be35a1SLionel Sambuc 
6111be35a1SLionel Sambuc 	mountkernfs();
6211be35a1SLionel Sambuc 	rumpns_hz = MAGICNUM;
6311be35a1SLionel Sambuc 	if ((fd = rump_sys_open("/kern/hz", O_RDONLY)) == -1)
6411be35a1SLionel Sambuc 		atf_tc_fail_errno("open /kern/hz");
6511be35a1SLionel Sambuc 	if (rump_sys_read(fd, buf, sizeof(buf)) <= 0)
6611be35a1SLionel Sambuc 		atf_tc_fail_errno("read");
6711be35a1SLionel Sambuc 	ATF_REQUIRE(atoi(buf) == MAGICNUM);
6811be35a1SLionel Sambuc }
6911be35a1SLionel Sambuc 
ATF_TP_ADD_TCS(tp)7011be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp)
7111be35a1SLionel Sambuc {
7211be35a1SLionel Sambuc 	ATF_TP_ADD_TC(tp, modautoload);
7311be35a1SLionel Sambuc 
7411be35a1SLionel Sambuc 	return atf_no_error();
7511be35a1SLionel Sambuc }
76