Module Name:    src
Committed By:   pgoyette
Date:           Sat Aug 21 13:21:49 UTC 2010

Modified Files:
        src/distrib/sets/lists/tests: module.mi
        src/tests/modules: Makefile t_modctl.c
        src/tests/modules/k_helper: k_helper.c
Added Files:
        src/tests/modules/k_helper2: Makefile k_helper2.c

Log Message:
Add a new atf test-case to check that recursive module calls actually work.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/distrib/sets/lists/tests/module.mi
cvs rdiff -u -r1.5 -r1.6 src/tests/modules/Makefile
cvs rdiff -u -r1.3 -r1.4 src/tests/modules/t_modctl.c
cvs rdiff -u -r1.3 -r1.4 src/tests/modules/k_helper/k_helper.c
cvs rdiff -u -r0 -r1.1 src/tests/modules/k_helper2/Makefile \
    src/tests/modules/k_helper2/k_helper2.c

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

Modified files:

Index: src/distrib/sets/lists/tests/module.mi
diff -u src/distrib/sets/lists/tests/module.mi:1.3 src/distrib/sets/lists/tests/module.mi:1.4
--- src/distrib/sets/lists/tests/module.mi:1.3	Tue Dec 15 03:01:16 2009
+++ src/distrib/sets/lists/tests/module.mi	Sat Aug 21 13:21:48 2010
@@ -1,9 +1,11 @@
-# $NetBSD: module.mi,v 1.3 2009/12/15 03:01:16 mrg Exp $
+# $NetBSD: module.mi,v 1.4 2010/08/21 13:21:48 pgoyette Exp $
 #
 # These are only made for ports doing modules.
 #
 ./usr/tests/modules/Atffile			tests-sys-tests		atf
 ./usr/tests/modules/k_helper			tests-sys-tests		atf
 ./usr/tests/modules/k_helper/k_helper.kmod	tests-sys-tests		atf
+./usr/tests/modules/k_helper2			tests-sys-tests		atf
+./usr/tests/modules/k_helper2/k_helper2.kmod	tests-sys-tests		atf
 ./usr/tests/modules/t_modctl			tests-sys-tests		atf
 ./usr/tests/modules/t_modload			tests-sys-tests		atf

Index: src/tests/modules/Makefile
diff -u src/tests/modules/Makefile:1.5 src/tests/modules/Makefile:1.6
--- src/tests/modules/Makefile:1.5	Tue Jul 13 21:13:28 2010
+++ src/tests/modules/Makefile	Sat Aug 21 13:21:48 2010
@@ -1,19 +1,14 @@
-# $NetBSD: Makefile,v 1.5 2010/07/13 21:13:28 jmmv Exp $
+#	$NetBSD: Makefile,v 1.6 2010/08/21 13:21:48 pgoyette Exp $
 
 .include <bsd.own.mk>
 
-TESTSDIR=	${TESTSBASE}/modules
+KMOD=   	k_helper2
+KMODULEDIR=	${DESTDIR}/${TESTSBASE}/modules/${KMOD}
 
-# Ideally this test could be in the parent Makefile, which could not descend
-# into this directory at all.  Unfortunately, the etc/mtree/NetBSD.dist file
-# creates the 'modules' subdirectory unconditionally, which if left empty
-# will confuse atf-run.  Therefore we must install, at the very least, the
-# Atffile into it.
-TESTS_C=	t_modctl
-LDADD=		-lprop
+SRCS=   	k_helper2.c
 
-TESTS_SH=	t_modload
-
-SUBDIR=		k_helper
+ATFFILE=	no
+NOMAN=		# defined
 
 .include <bsd.test.mk>
+.include <bsd.kmodule.mk>

Index: src/tests/modules/t_modctl.c
diff -u src/tests/modules/t_modctl.c:1.3 src/tests/modules/t_modctl.c:1.4
--- src/tests/modules/t_modctl.c:1.3	Sun Jan  4 17:56:57 2009
+++ src/tests/modules/t_modctl.c	Sat Aug 21 13:21:48 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_modctl.c,v 1.3 2009/01/04 17:56:57 jmmv Exp $	*/
+/*	$NetBSD: t_modctl.c,v 1.4 2010/08/21 13:21:48 pgoyette Exp $	*/
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: t_modctl.c,v 1.3 2009/01/04 17:56:57 jmmv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: t_modctl.c,v 1.4 2010/08/21 13:21:48 pgoyette Exp $");
 
 #include <sys/module.h>
 #include <sys/sysctl.h>
@@ -397,6 +397,46 @@
 	unload_cleanup("k_helper");
 }
 
+ATF_TC_WITH_CLEANUP(cmd_load_recurse);
+ATF_TC_HEAD(cmd_load_recurse, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_LOAD command, "
+	    "with recursive module_load()");
+	atf_tc_set_md_var(tc, "require.user", "root");
+}
+ATF_TC_BODY(cmd_load_recurse, tc)
+{
+	prop_dictionary_t props;
+	char filename[MAXPATHLEN];
+
+	require_modular();
+
+	printf("Loading module with request to load another module\n");
+	props = prop_dictionary_create();
+	snprintf(filename, sizeof(filename), "%s/k_helper2/k_helper2.kmod",
+	    atf_tc_get_config_var(tc, "srcdir"));
+	prop_dictionary_set(props, "prop_recurse",
+	    prop_string_create_cstring(filename));
+	load(props, true, "%s/k_helper/k_helper.kmod",
+	    atf_tc_get_config_var(tc, "srcdir"));
+	{
+		int ok;
+		ATF_CHECK(get_sysctl("vendor.k_helper.prop_int_load",
+		    &ok, sizeof(ok)));
+		ATF_CHECK(ok == 0);
+		ATF_CHECK(get_sysctl("vendor.k_helper2.present",
+		    &ok, sizeof(ok)));
+		ATF_CHECK(ok);
+	}
+	unload("k_helper", true);
+	unload("k_helper2", true);
+}
+ATF_TC_CLEANUP(cmd_load_recurse, tc)
+{
+	unload_cleanup("k_helper");
+	unload_cleanup("k_helper2");
+}
+
 ATF_TC_WITH_CLEANUP(cmd_stat);
 ATF_TC_HEAD(cmd_stat, tc)
 {
@@ -467,6 +507,7 @@
 	ATF_TP_ADD_TC(tp, cmd_load);
 	ATF_TP_ADD_TC(tp, cmd_load_props);
 	ATF_TP_ADD_TC(tp, cmd_stat);
+	ATF_TP_ADD_TC(tp, cmd_load_recurse);
 	ATF_TP_ADD_TC(tp, cmd_unload);
 
 	return atf_no_error();

Index: src/tests/modules/k_helper/k_helper.c
diff -u src/tests/modules/k_helper/k_helper.c:1.3 src/tests/modules/k_helper/k_helper.c:1.4
--- src/tests/modules/k_helper/k_helper.c:1.3	Mon Apr 28 20:24:12 2008
+++ src/tests/modules/k_helper/k_helper.c	Sat Aug 21 13:21:48 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: k_helper.c,v 1.3 2008/04/28 20:24:12 martin Exp $	*/
+/*	$NetBSD: k_helper.c,v 1.4 2010/08/21 13:21:48 pgoyette Exp $	*/
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: k_helper.c,v 1.3 2008/04/28 20:24:12 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: k_helper.c,v 1.4 2010/08/21 13:21:48 pgoyette Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -50,7 +50,8 @@
 static int prop_str_ok;
 static char prop_str_val[128];
 static int prop_int_ok;
-static int prop_int_val;
+static int64_t prop_int_val;
+static int prop_int_load;
 
 #define K_HELPER 0x12345678
 #define K_HELPER_PRESENT 0
@@ -58,6 +59,7 @@
 #define K_HELPER_PROP_STR_VAL 2
 #define K_HELPER_PROP_INT_OK 3
 #define K_HELPER_PROP_INT_VAL 4
+#define K_HELPER_PROP_INT_LOAD 5
 
 SYSCTL_SETUP(sysctl_k_helper_setup, "sysctl k_helper subtree setup")
 {
@@ -98,10 +100,17 @@
 
 	sysctl_createv(clog, 0, NULL, NULL,
 	               CTLFLAG_PERMANENT,
-	               CTLTYPE_INT, "prop_int_val",
+	               CTLTYPE_QUAD, "prop_int_val",
 		       SYSCTL_DESCR("String property's value"),
 		       NULL, 0, &prop_int_val, 0,
 	               CTL_VENDOR, K_HELPER, K_HELPER_PROP_INT_VAL, CTL_EOL);
+
+	sysctl_createv(clog, 0, NULL, NULL,
+	               CTLFLAG_PERMANENT,
+	               CTLTYPE_INT, "prop_int_load",
+		       SYSCTL_DESCR("Status of recursive modload"),
+		       NULL, 0, &prop_int_load, 0,
+	               CTL_VENDOR, K_HELPER, K_HELPER_PROP_INT_LOAD, CTL_EOL);
 }
 
 /* --------------------------------------------------------------------- */
@@ -143,6 +152,17 @@
 	if (!prop_int_ok)
 		prop_int_val = -1;
 
+	p = prop_dictionary_get(props, "prop_recurse");
+	if (p != NULL && prop_object_type(p) == PROP_TYPE_STRING) {
+		const char *recurse_name = prop_string_cstring_nocopy(p);
+		if (recurse_name != NULL)
+			prop_int_load = module_load(recurse_name,
+			    MODCTL_NO_PROP, NULL, MODULE_CLASS_ANY);
+		else
+			prop_int_load = -1;
+	} else
+		prop_int_load = -2;
+
 	sysctl_k_helper_setup(&clog);
 
 	return 0;

Added files:

Index: src/tests/modules/k_helper2/Makefile
diff -u /dev/null src/tests/modules/k_helper2/Makefile:1.1
--- /dev/null	Sat Aug 21 13:21:49 2010
+++ src/tests/modules/k_helper2/Makefile	Sat Aug 21 13:21:48 2010
@@ -0,0 +1,14 @@
+#	$NetBSD: Makefile,v 1.1 2010/08/21 13:21:48 pgoyette Exp $
+
+.include <bsd.own.mk>
+
+KMOD=   	k_helper2
+KMODULEDIR=	${DESTDIR}/${TESTSBASE}/modules/${KMOD}
+
+SRCS=   	k_helper2.c
+
+ATFFILE=	no
+NOMAN=		# defined
+
+.include <bsd.test.mk>
+.include <bsd.kmodule.mk>
Index: src/tests/modules/k_helper2/k_helper2.c
diff -u /dev/null src/tests/modules/k_helper2/k_helper2.c:1.1
--- /dev/null	Sat Aug 21 13:21:49 2010
+++ src/tests/modules/k_helper2/k_helper2.c	Sat Aug 21 13:21:48 2010
@@ -0,0 +1,115 @@
+/*	$NetBSD: k_helper2.c,v 1.1 2010/08/21 13:21:48 pgoyette Exp $ */
+/*
+ * Copyright (c) 2010 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
+ * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+ * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+ * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: k_helper2.c,v 1.1 2010/08/21 13:21:48 pgoyette Exp $");
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/module.h>
+#include <sys/sysctl.h>
+
+#include <prop/proplib.h>
+
+MODULE(MODULE_CLASS_MISC, k_helper2, NULL);
+
+/* --------------------------------------------------------------------- */
+/* Sysctl interface to query information about the module.               */
+/* --------------------------------------------------------------------- */
+
+/* TODO: Change the integer variables below that represent booleans to
+ * bools, once sysctl(8) supports CTLTYPE_BOOL nodes. */
+
+static struct sysctllog *clog;
+static int present = 1;
+
+#define K_HELPER2 0x23456781
+#define K_HELPER_PRESENT 0
+
+SYSCTL_SETUP(sysctl_k_helper2_setup, "sysctl k_helper subtree setup")
+{
+
+	sysctl_createv(clog, 0, NULL, NULL,
+	               CTLFLAG_PERMANENT,
+	               CTLTYPE_NODE, "k_helper2", NULL,
+	               NULL, 0, NULL, 0,
+	               CTL_VENDOR, K_HELPER2, CTL_EOL);
+
+	sysctl_createv(clog, 0, NULL, NULL,
+	               CTLFLAG_PERMANENT,
+	               CTLTYPE_INT, "present",
+		       SYSCTL_DESCR("Whether the module was loaded or not"),
+		       NULL, 0, &present, 0,
+	               CTL_VENDOR, K_HELPER2, K_HELPER_PRESENT, CTL_EOL);
+}
+
+/* --------------------------------------------------------------------- */
+/* Module management.                                                    */
+/* --------------------------------------------------------------------- */
+
+static
+int
+k_helper2_init(prop_dictionary_t props)
+{
+	sysctl_k_helper2_setup(&clog);
+
+	return 0;
+}
+
+static
+int
+k_helper2_fini(void *arg)
+{
+
+	sysctl_teardown(&clog);
+
+	return 0;
+}
+
+static
+int
+k_helper2_modcmd(modcmd_t cmd, void *arg)
+{
+	int ret;
+
+	switch (cmd) {
+	case MODULE_CMD_INIT:
+		ret = k_helper2_init(arg);
+		break;
+
+	case MODULE_CMD_FINI:
+		ret = k_helper2_fini(arg);
+		break;
+
+	case MODULE_CMD_STAT:
+	default:
+		ret = ENOTTY;
+	}
+
+	return ret;
+}

Reply via email to