Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/rump Add a test which checks autoloading modules from ...
details: https://anonhg.NetBSD.org/src/rev/759281853157
branches: trunk
changeset: 755556:759281853157
user: pooka <pooka%NetBSD.org@localhost>
date: Wed Jun 09 12:35:45 2010 +0000
description:
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.
diffstat:
tests/rump/Atffile | 5 +-
tests/rump/Makefile | 4 +-
tests/rump/modautoload/Atffile | 6 ++
tests/rump/modautoload/Makefile | 24 ++++++++++
tests/rump/modautoload/t_modautoload.c | 76 ++++++++++++++++++++++++++++++++++
5 files changed, 111 insertions(+), 4 deletions(-)
diffs (148 lines):
diff -r a67fd09d9a42 -r 759281853157 tests/rump/Atffile
--- a/tests/rump/Atffile Wed Jun 09 12:02:37 2010 +0000
+++ b/tests/rump/Atffile Wed Jun 09 12:35:45 2010 +0000
@@ -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
diff -r a67fd09d9a42 -r 759281853157 tests/rump/Makefile
--- a/tests/rump/Makefile Wed Jun 09 12:02:37 2010 +0000
+++ b/tests/rump/Makefile Wed Jun 09 12:35:45 2010 +0000
@@ -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>
diff -r a67fd09d9a42 -r 759281853157 tests/rump/modautoload/Atffile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/rump/modautoload/Atffile Wed Jun 09 12:35:45 2010 +0000
@@ -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_*
diff -r a67fd09d9a42 -r 759281853157 tests/rump/modautoload/Makefile
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/rump/modautoload/Makefile Wed Jun 09 12:35:45 2010 +0000
@@ -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>
diff -r a67fd09d9a42 -r 759281853157 tests/rump/modautoload/t_modautoload.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/rump/modautoload/t_modautoload.c Wed Jun 09 12:35:45 2010 +0000
@@ -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();
+}
Home |
Main Index |
Thread Index |
Old Index