Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add a new atf test-case to check that recursive module calls...



details:   https://anonhg.NetBSD.org/src/rev/d696b29aed48
branches:  trunk
changeset: 757254:d696b29aed48
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Sat Aug 21 13:21:48 2010 +0000

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

diffstat:

 distrib/sets/lists/tests/module.mi  |    4 +-
 tests/modules/Makefile              |   19 ++---
 tests/modules/k_helper/k_helper.c   |   28 +++++++-
 tests/modules/k_helper2/Makefile    |   14 ++++
 tests/modules/k_helper2/k_helper2.c |  115 ++++++++++++++++++++++++++++++++++++
 tests/modules/t_modctl.c            |   45 +++++++++++++-
 6 files changed, 206 insertions(+), 19 deletions(-)

diffs (truncated from 329 to 300 lines):

diff -r 56a69edf543c -r d696b29aed48 distrib/sets/lists/tests/module.mi
--- a/distrib/sets/lists/tests/module.mi        Sat Aug 21 13:20:43 2010 +0000
+++ b/distrib/sets/lists/tests/module.mi        Sat Aug 21 13:21:48 2010 +0000
@@ -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
diff -r 56a69edf543c -r d696b29aed48 tests/modules/Makefile
--- a/tests/modules/Makefile    Sat Aug 21 13:20:43 2010 +0000
+++ b/tests/modules/Makefile    Sat Aug 21 13:21:48 2010 +0000
@@ -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>
diff -r 56a69edf543c -r d696b29aed48 tests/modules/k_helper/k_helper.c
--- a/tests/modules/k_helper/k_helper.c Sat Aug 21 13:20:43 2010 +0000
+++ b/tests/modules/k_helper/k_helper.c Sat Aug 21 13:21:48 2010 +0000
@@ -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;
diff -r 56a69edf543c -r d696b29aed48 tests/modules/k_helper2/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/modules/k_helper2/Makefile  Sat Aug 21 13:21:48 2010 +0000
@@ -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>
diff -r 56a69edf543c -r d696b29aed48 tests/modules/k_helper2/k_helper2.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/modules/k_helper2/k_helper2.c       Sat Aug 21 13:21:48 2010 +0000
@@ -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;
+}
diff -r 56a69edf543c -r d696b29aed48 tests/modules/t_modctl.c
--- a/tests/modules/t_modctl.c  Sat Aug 21 13:20:43 2010 +0000
+++ b/tests/modules/t_modctl.c  Sat Aug 21 13:21:48 2010 +0000
@@ -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"));



Home | Main Index | Thread Index | Old Index