t_modautoload.c revision 1.1
11.1Spooka/*	$NetBSD: t_modautoload.c,v 1.1 2010/06/09 12:35:45 pooka Exp $	*/
21.1Spooka
31.1Spooka#include <sys/types.h>
41.1Spooka#include <sys/mount.h>
51.1Spooka#include <sys/module.h>
61.1Spooka#include <sys/dirent.h>
71.1Spooka#include <sys/sysctl.h>
81.1Spooka
91.1Spooka#include <atf-c.h>
101.1Spooka#include <err.h>
111.1Spooka#include <errno.h>
121.1Spooka#include <fcntl.h>
131.1Spooka#include <stdio.h>
141.1Spooka#include <unistd.h>
151.1Spooka#include <string.h>
161.1Spooka#include <stdlib.h>
171.1Spooka
181.1Spooka#include <rump/rump.h>
191.1Spooka#include <rump/rump_syscalls.h>
201.1Spooka
211.1Spooka#include <miscfs/kernfs/kernfs.h>
221.1Spooka
231.1Spooka#include "../../h_macros.h"
241.1Spooka
251.1SpookaATF_TC(modautoload);
261.1SpookaATF_TC_HEAD(modautoload, tc)
271.1Spooka{
281.1Spooka
291.1Spooka	atf_tc_set_md_var(tc, "descr", "tests that kernel module "
301.1Spooka	    "autoload works in rump");
311.1Spooka}
321.1Spooka
331.1Spookastatic void
341.1Spookamountkernfs(void)
351.1Spooka{
361.1Spooka
371.1Spooka#ifndef HAVE_HOST_MODULES
381.1Spooka	atf_tc_skip("host kernel modules not supported on this architecture");
391.1Spooka#endif
401.1Spooka
411.1Spooka	rump_init();
421.1Spooka
431.1Spooka	if (rump_sys_mkdir("/kern", 0777) == -1)
441.1Spooka		atf_tc_fail_errno("mkdir /kern");
451.1Spooka	if (rump_sys_mount(MOUNT_KERNFS, "/kern", 0, NULL, 0) == -1)
461.1Spooka		atf_tc_fail_errno("could not mount kernfs");
471.1Spooka}
481.1Spooka
491.1Spooka/*
501.1Spooka * Why use kernfs here?  It talks to plenty of other parts with the
511.1Spooka * kernel (e.g. vfs_attach() in modcmd), but is still easy to verify
521.1Spooka * it's working correctly.
531.1Spooka */
541.1Spooka
551.1Spooka#define MAGICNUM 1323
561.1SpookaATF_TC_BODY(modautoload, tc)
571.1Spooka{
581.1Spooka	extern int rumpns_hz;
591.1Spooka	char buf[64];
601.1Spooka	int fd;
611.1Spooka
621.1Spooka	mountkernfs();
631.1Spooka	rumpns_hz = MAGICNUM;
641.1Spooka	if ((fd = rump_sys_open("/kern/hz", O_RDONLY)) == -1)
651.1Spooka		atf_tc_fail_errno("open /kern/hz");
661.1Spooka	if (rump_sys_read(fd, buf, sizeof(buf)) <= 0)
671.1Spooka		atf_tc_fail_errno("read");
681.1Spooka	ATF_REQUIRE(atoi(buf) == MAGICNUM);
691.1Spooka}
701.1Spooka
711.1SpookaATF_TP_ADD_TCS(tp)
721.1Spooka{
731.1Spooka	ATF_TP_ADD_TC(tp, modautoload);
741.1Spooka
751.1Spooka	return atf_no_error();
761.1Spooka}
77