1*11be35a1SLionel Sambuc /* $NetBSD: t_modautoload.c,v 1.1 2010/06/09 12:35:45 pooka Exp $ */ 2*11be35a1SLionel Sambuc 3*11be35a1SLionel Sambuc #include <sys/types.h> 4*11be35a1SLionel Sambuc #include <sys/mount.h> 5*11be35a1SLionel Sambuc #include <sys/module.h> 6*11be35a1SLionel Sambuc #include <sys/dirent.h> 7*11be35a1SLionel Sambuc #include <sys/sysctl.h> 8*11be35a1SLionel Sambuc 9*11be35a1SLionel Sambuc #include <atf-c.h> 10*11be35a1SLionel Sambuc #include <err.h> 11*11be35a1SLionel Sambuc #include <errno.h> 12*11be35a1SLionel Sambuc #include <fcntl.h> 13*11be35a1SLionel Sambuc #include <stdio.h> 14*11be35a1SLionel Sambuc #include <unistd.h> 15*11be35a1SLionel Sambuc #include <string.h> 16*11be35a1SLionel Sambuc #include <stdlib.h> 17*11be35a1SLionel Sambuc 18*11be35a1SLionel Sambuc #include <rump/rump.h> 19*11be35a1SLionel Sambuc #include <rump/rump_syscalls.h> 20*11be35a1SLionel Sambuc 21*11be35a1SLionel Sambuc #include <miscfs/kernfs/kernfs.h> 22*11be35a1SLionel Sambuc 23*11be35a1SLionel Sambuc #include "../../h_macros.h" 24*11be35a1SLionel Sambuc 25*11be35a1SLionel Sambuc ATF_TC(modautoload); 26*11be35a1SLionel Sambuc ATF_TC_HEAD(modautoload, tc) 27*11be35a1SLionel Sambuc { 28*11be35a1SLionel Sambuc 29*11be35a1SLionel Sambuc atf_tc_set_md_var(tc, "descr", "tests that kernel module " 30*11be35a1SLionel Sambuc "autoload works in rump"); 31*11be35a1SLionel Sambuc } 32*11be35a1SLionel Sambuc 33*11be35a1SLionel Sambuc static void 34*11be35a1SLionel Sambuc mountkernfs(void) 35*11be35a1SLionel Sambuc { 36*11be35a1SLionel Sambuc 37*11be35a1SLionel Sambuc #ifndef HAVE_HOST_MODULES 38*11be35a1SLionel Sambuc atf_tc_skip("host kernel modules not supported on this architecture"); 39*11be35a1SLionel Sambuc #endif 40*11be35a1SLionel Sambuc 41*11be35a1SLionel Sambuc rump_init(); 42*11be35a1SLionel Sambuc 43*11be35a1SLionel Sambuc if (rump_sys_mkdir("/kern", 0777) == -1) 44*11be35a1SLionel Sambuc atf_tc_fail_errno("mkdir /kern"); 45*11be35a1SLionel Sambuc if (rump_sys_mount(MOUNT_KERNFS, "/kern", 0, NULL, 0) == -1) 46*11be35a1SLionel Sambuc atf_tc_fail_errno("could not mount kernfs"); 47*11be35a1SLionel Sambuc } 48*11be35a1SLionel Sambuc 49*11be35a1SLionel Sambuc /* 50*11be35a1SLionel Sambuc * Why use kernfs here? It talks to plenty of other parts with the 51*11be35a1SLionel Sambuc * kernel (e.g. vfs_attach() in modcmd), but is still easy to verify 52*11be35a1SLionel Sambuc * it's working correctly. 53*11be35a1SLionel Sambuc */ 54*11be35a1SLionel Sambuc 55*11be35a1SLionel Sambuc #define MAGICNUM 1323 56*11be35a1SLionel Sambuc ATF_TC_BODY(modautoload, tc) 57*11be35a1SLionel Sambuc { 58*11be35a1SLionel Sambuc extern int rumpns_hz; 59*11be35a1SLionel Sambuc char buf[64]; 60*11be35a1SLionel Sambuc int fd; 61*11be35a1SLionel Sambuc 62*11be35a1SLionel Sambuc mountkernfs(); 63*11be35a1SLionel Sambuc rumpns_hz = MAGICNUM; 64*11be35a1SLionel Sambuc if ((fd = rump_sys_open("/kern/hz", O_RDONLY)) == -1) 65*11be35a1SLionel Sambuc atf_tc_fail_errno("open /kern/hz"); 66*11be35a1SLionel Sambuc if (rump_sys_read(fd, buf, sizeof(buf)) <= 0) 67*11be35a1SLionel Sambuc atf_tc_fail_errno("read"); 68*11be35a1SLionel Sambuc ATF_REQUIRE(atoi(buf) == MAGICNUM); 69*11be35a1SLionel Sambuc } 70*11be35a1SLionel Sambuc 71*11be35a1SLionel Sambuc ATF_TP_ADD_TCS(tp) 72*11be35a1SLionel Sambuc { 73*11be35a1SLionel Sambuc ATF_TP_ADD_TC(tp, modautoload); 74*11be35a1SLionel Sambuc 75*11be35a1SLionel Sambuc return atf_no_error(); 76*11be35a1SLionel Sambuc } 77