[BACK]Return to t_modautoload.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / tests / rump / modautoload

File: [cvs.NetBSD.org] / src / tests / rump / modautoload / t_modautoload.c (download)

Revision 1.1, Wed Jun 9 12:35:45 2010 UTC (12 years, 5 months ago) by pooka
Branch: MAIN
CVS Tags: yamt-pagecache-tag8, yamt-pagecache-base8, yamt-pagecache-base7, yamt-pagecache-base6, yamt-pagecache-base5, yamt-pagecache-base4, yamt-pagecache-base3, yamt-pagecache-base2, yamt-pagecache-base, riastradh-drm2-base2, riastradh-drm2-base1, riastradh-drm2-base, riastradh-drm2, netbsd-6-base, netbsd-6-1-RELEASE, netbsd-6-1-RC4, netbsd-6-1-RC3, netbsd-6-1-RC2, netbsd-6-1-RC1, netbsd-6-1-5-RELEASE, netbsd-6-1-4-RELEASE, netbsd-6-1-3-RELEASE, netbsd-6-1-2-RELEASE, netbsd-6-1-1-RELEASE, netbsd-6-1, netbsd-6-0-RELEASE, netbsd-6-0-RC2, netbsd-6-0-RC1, netbsd-6-0-6-RELEASE, netbsd-6-0-5-RELEASE, netbsd-6-0-4-RELEASE, netbsd-6-0-3-RELEASE, netbsd-6-0-2-RELEASE, netbsd-6-0-1-RELEASE, netbsd-6-0, netbsd-6, matt-nb6-plus-nbase, matt-nb6-plus-base, matt-nb6-plus, matt-mips64-premerge-20101231, cherry-xenmp-base, cherry-xenmp, bouyer-quota2-nbase, bouyer-quota2-base, bouyer-quota2, agc-symver-base, agc-symver
Branch point for: yamt-pagecache, tls-maxphys

Add a test which checks autoloading modules from the host's
/stand/arch/vers/kmods works in rump (and that the result is usable ;).

On i386 this "just works".  For amd64, due to -mcmodel=kernel,
things are a little more complicated.  We must have the entire rump
kernel loaded in the lower 2GB.  Currently, this can be done either
by using the non-PIC version for the rump kernel compiled with
-mcmodel=small, or, as njoly pointed out, using netbsd32, which
causes vm_default_addr() to give something in the lower 2GB and
therefore shared libs "magically" getting loaded there.  I guess
it would be possible to put a suggested vaddr into the rump kernel
libs and make ld.elf_so map memory from the suggested address if
present ... but that's another show.

Also thanks to tron for access to an amd64 so that I could verify
the test works.

/*	$NetBSD: t_modautoload.c,v 1.1 2010/06/09 12:35:45 pooka Exp $	*/

#include <sys/types.h>
#include <sys/mount.h>
#include <sys/module.h>
#include <sys/dirent.h>
#include <sys/sysctl.h>

#include <atf-c.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>

#include <rump/rump.h>
#include <rump/rump_syscalls.h>

#include <miscfs/kernfs/kernfs.h>

#include "../../h_macros.h"

ATF_TC_HEAD(modautoload, tc)

	atf_tc_set_md_var(tc, "descr", "tests that kernel module "
	    "autoload works in rump");

static void

	atf_tc_skip("host kernel modules not supported on this architecture");


	if (rump_sys_mkdir("/kern", 0777) == -1)
		atf_tc_fail_errno("mkdir /kern");
	if (rump_sys_mount(MOUNT_KERNFS, "/kern", 0, NULL, 0) == -1)
		atf_tc_fail_errno("could not mount kernfs");

 * Why use kernfs here?  It talks to plenty of other parts with the
 * kernel (e.g. vfs_attach() in modcmd), but is still easy to verify
 * it's working correctly.

#define MAGICNUM 1323
ATF_TC_BODY(modautoload, tc)
	extern int rumpns_hz;
	char buf[64];
	int fd;

	rumpns_hz = MAGICNUM;
	if ((fd = rump_sys_open("/kern/hz", O_RDONLY)) == -1)
		atf_tc_fail_errno("open /kern/hz");
	if (rump_sys_read(fd, buf, sizeof(buf)) <= 0)
	ATF_REQUIRE(atoi(buf) == MAGICNUM);

	ATF_TP_ADD_TC(tp, modautoload);

	return atf_no_error();