Module Name:    src
Committed By:   pooka
Date:           Wed Jun  9 12:35:46 UTC 2010

Modified Files:
        src/tests/rump: Atffile Makefile
Added Files:
        src/tests/rump/modautoload: Atffile Makefile t_modautoload.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/rump/Atffile src/tests/rump/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/rump/modautoload/Atffile \
    src/tests/rump/modautoload/Makefile \
    src/tests/rump/modautoload/t_modautoload.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/rump/Atffile
diff -u src/tests/rump/Atffile:1.2 src/tests/rump/Atffile:1.3
--- src/tests/rump/Atffile:1.2	Mon May 31 23:32:50 2010
+++ src/tests/rump/Atffile	Wed Jun  9 12:35:45 2010
@@ -1,6 +1,7 @@
 Content-Type: application/X-atf-atffile; version="1"
-X-NetBSD-Id: "$NetBSD: Atffile,v 1.2 2010/05/31 23:32:50 pooka Exp $"
+X-NetBSD-Id: "$NetBSD: Atffile,v 1.3 2010/06/09 12:35:45 pooka Exp $"
 
 prop: test-suite = "NetBSD"
 
-tp-glob: rumpkern
+tp: modautoload
+tp: rumpkern
Index: src/tests/rump/Makefile
diff -u src/tests/rump/Makefile:1.2 src/tests/rump/Makefile:1.3
--- src/tests/rump/Makefile:1.2	Mon May 31 23:32:50 2010
+++ src/tests/rump/Makefile	Wed Jun  9 12:35:45 2010
@@ -1,11 +1,11 @@
-#	$NetBSD: Makefile,v 1.2 2010/05/31 23:32:50 pooka Exp $
+#	$NetBSD: Makefile,v 1.3 2010/06/09 12:35:45 pooka Exp $
 #
 
 .include <bsd.own.mk>
 
 TESTSDIR=	${TESTSBASE}/rump
 
-SUBDIR=	kernspace .WAIT rumpkern
+SUBDIR=	kernspace .WAIT rumpkern modautoload
 
 .include <bsd.test.mk>
 .include <bsd.subdir.mk>

Added files:

Index: src/tests/rump/modautoload/Atffile
diff -u /dev/null src/tests/rump/modautoload/Atffile:1.1
--- /dev/null	Wed Jun  9 12:35:46 2010
+++ src/tests/rump/modautoload/Atffile	Wed Jun  9 12:35:45 2010
@@ -0,0 +1,6 @@
+Content-Type: application/X-atf-atffile; version="1"
+X-NetBSD-Id: "$NetBSD: Atffile,v 1.1 2010/06/09 12:35:45 pooka Exp $"
+
+prop: test-suite = "NetBSD"
+
+tp-glob: t_*
Index: src/tests/rump/modautoload/Makefile
diff -u /dev/null src/tests/rump/modautoload/Makefile:1.1
--- /dev/null	Wed Jun  9 12:35:46 2010
+++ src/tests/rump/modautoload/Makefile	Wed Jun  9 12:35:45 2010
@@ -0,0 +1,24 @@
+#	$NetBSD: Makefile,v 1.1 2010/06/09 12:35:45 pooka Exp $
+#
+
+TESTSDIR=	${TESTSBASE}/rump/modautoload
+
+TESTS_C=	t_modautoload
+
+.include <bsd.own.mk>
+.ifdef RUMPKMOD
+CPPFLAGS+=	-DHAVE_HOST_MODULES
+.endif
+
+# Note: we link the rump kernel into the application to make this work
+# on amd64.  This is the reason we keep this test in its own
+# subdirectory -- otherwise the LDADD lines would get a little hairy.
+LDFLAGS+=	-Wl,-E
+LDADD+=		-Wl,--whole-archive	${DESTDIR}/usr/lib/librumpvfs.a	\
+					${DESTDIR}/usr/lib/librump.a	\
+		-Wl,--no-whole-archive
+LDADD+=		-lrumpuser -lpthread
+
+WARNS=	4
+
+.include <bsd.test.mk>
Index: src/tests/rump/modautoload/t_modautoload.c
diff -u /dev/null src/tests/rump/modautoload/t_modautoload.c:1.1
--- /dev/null	Wed Jun  9 12:35:46 2010
+++ src/tests/rump/modautoload/t_modautoload.c	Wed Jun  9 12:35:45 2010
@@ -0,0 +1,76 @@
+/*	$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(modautoload);
+ATF_TC_HEAD(modautoload, tc)
+{
+
+	atf_tc_set_md_var(tc, "descr", "tests that kernel module "
+	    "autoload works in rump");
+}
+
+static void
+mountkernfs(void)
+{
+
+#ifndef HAVE_HOST_MODULES
+	atf_tc_skip("host kernel modules not supported on this architecture");
+#endif
+
+	rump_init();
+
+	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;
+
+	mountkernfs();
+	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_tc_fail_errno("read");
+	ATF_REQUIRE(atoi(buf) == MAGICNUM);
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+	ATF_TP_ADD_TC(tp, modautoload);
+
+	return atf_no_error();
+}

Reply via email to