Home | History | Annotate | Line # | Download | only in modules
t_modctl.c revision 1.5.6.3
      1  1.5.6.3      yamt /*	$NetBSD: t_modctl.c,v 1.5.6.3 2012/10/30 19:00:05 yamt Exp $	*/
      2      1.1      jmmv /*
      3      1.1      jmmv  * Copyright (c) 2008 The NetBSD Foundation, Inc.
      4      1.1      jmmv  * All rights reserved.
      5      1.1      jmmv  *
      6      1.1      jmmv  * Redistribution and use in source and binary forms, with or without
      7      1.1      jmmv  * modification, are permitted provided that the following conditions
      8      1.1      jmmv  * are met:
      9      1.1      jmmv  * 1. Redistributions of source code must retain the above copyright
     10      1.1      jmmv  *    notice, this list of conditions and the following disclaimer.
     11      1.1      jmmv  * 2. Redistributions in binary form must reproduce the above copyright
     12      1.1      jmmv  *    notice, this list of conditions and the following disclaimer in the
     13      1.1      jmmv  *    documentation and/or other materials provided with the distribution.
     14      1.1      jmmv  *
     15      1.1      jmmv  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
     16      1.1      jmmv  * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
     17      1.1      jmmv  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     18      1.1      jmmv  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19      1.1      jmmv  * IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
     20      1.1      jmmv  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21      1.1      jmmv  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
     22      1.1      jmmv  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23      1.1      jmmv  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
     24      1.1      jmmv  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     25      1.1      jmmv  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
     26      1.1      jmmv  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27      1.1      jmmv  */
     28      1.1      jmmv 
     29      1.1      jmmv #include <sys/cdefs.h>
     30  1.5.6.3      yamt __KERNEL_RCSID(0, "$NetBSD: t_modctl.c,v 1.5.6.3 2012/10/30 19:00:05 yamt Exp $");
     31      1.1      jmmv 
     32      1.1      jmmv #include <sys/module.h>
     33      1.1      jmmv #include <sys/sysctl.h>
     34      1.1      jmmv 
     35      1.1      jmmv #include <assert.h>
     36      1.1      jmmv #include <errno.h>
     37      1.1      jmmv #include <stdarg.h>
     38      1.1      jmmv #include <stdbool.h>
     39      1.1      jmmv #include <stdio.h>
     40      1.1      jmmv #include <stdlib.h>
     41      1.1      jmmv #include <string.h>
     42      1.1      jmmv 
     43      1.1      jmmv #include <prop/proplib.h>
     44      1.1      jmmv 
     45      1.1      jmmv #include <atf-c.h>
     46      1.1      jmmv 
     47      1.1      jmmv enum presence_check { both_checks, stat_check, sysctl_check };
     48      1.1      jmmv 
     49  1.5.6.3      yamt static void	check_permission(void);
     50  1.5.6.1      yamt static bool	get_modstat_info(const char *, modstat_t *);
     51  1.5.6.1      yamt static bool	get_sysctl(const char *, void *buf, const size_t);
     52  1.5.6.1      yamt static bool	k_helper_is_present_stat(void);
     53  1.5.6.1      yamt static bool	k_helper_is_present_sysctl(void);
     54  1.5.6.1      yamt static bool	k_helper_is_present(enum presence_check);
     55  1.5.6.1      yamt static int	load(prop_dictionary_t, bool, const char *, ...);
     56  1.5.6.1      yamt static int	unload(const char *, bool);
     57  1.5.6.1      yamt static void	unload_cleanup(const char *);
     58  1.5.6.1      yamt 
     59      1.1      jmmv /* --------------------------------------------------------------------- */
     60      1.1      jmmv /* Auxiliary functions                                                   */
     61      1.1      jmmv /* --------------------------------------------------------------------- */
     62      1.1      jmmv 
     63      1.1      jmmv /*
     64  1.5.6.3      yamt  * A function checking wether we are allowed to load modules currently
     65  1.5.6.3      yamt  * (either the kernel is not modular, or securelevel may prevent it)
     66      1.1      jmmv  */
     67  1.5.6.3      yamt static void
     68  1.5.6.3      yamt check_permission(void)
     69      1.1      jmmv {
     70  1.5.6.3      yamt 	int err;
     71  1.5.6.3      yamt 
     72  1.5.6.3      yamt 	err = modctl(MODCTL_EXISTS, 0);
     73  1.5.6.3      yamt 	if (err == 0) return;
     74  1.5.6.3      yamt 	if (errno == ENOSYS)
     75  1.5.6.3      yamt 		atf_tc_skip("Kernel does not have 'options MODULAR'.");
     76  1.5.6.3      yamt 	else if (errno == EPERM)
     77  1.5.6.3      yamt 		atf_tc_skip("Module loading administratively forbidden");
     78  1.5.6.3      yamt 	ATF_REQUIRE_EQ_MSG(errno, 0, "unexpected error %d from "
     79  1.5.6.3      yamt 	    "modctl(MODCTL_EXISTS, 0)", errno);
     80      1.1      jmmv }
     81      1.1      jmmv 
     82  1.5.6.1      yamt static bool
     83      1.1      jmmv get_modstat_info(const char *name, modstat_t *msdest)
     84      1.1      jmmv {
     85      1.1      jmmv 	bool found;
     86      1.1      jmmv 	size_t len;
     87      1.1      jmmv 	struct iovec iov;
     88      1.1      jmmv 	modstat_t *ms;
     89      1.1      jmmv 
     90  1.5.6.3      yamt 	check_permission();
     91      1.1      jmmv 	for (len = 4096; ;) {
     92      1.1      jmmv 		iov.iov_base = malloc(len);
     93      1.1      jmmv 		iov.iov_len = len;
     94  1.5.6.1      yamt 
     95  1.5.6.1      yamt 		errno = 0;
     96  1.5.6.1      yamt 
     97      1.1      jmmv 		if (modctl(MODCTL_STAT, &iov) != 0) {
     98      1.1      jmmv 			int err = errno;
     99      1.1      jmmv 			fprintf(stderr, "modctl(MODCTL_STAT) failed: %s\n",
    100      1.1      jmmv 			    strerror(err));
    101      1.1      jmmv 			atf_tc_fail("Failed to query module status");
    102      1.1      jmmv 		}
    103      1.1      jmmv 		if (len >= iov.iov_len)
    104      1.1      jmmv 			break;
    105      1.1      jmmv 		free(iov.iov_base);
    106      1.1      jmmv 		len = iov.iov_len;
    107      1.1      jmmv 	}
    108      1.1      jmmv 
    109      1.1      jmmv 	found = false;
    110      1.1      jmmv 	len = iov.iov_len / sizeof(modstat_t);
    111      1.1      jmmv 	for (ms = (modstat_t *)iov.iov_base; len != 0 && !found;
    112      1.1      jmmv 	    ms++, len--) {
    113      1.1      jmmv 		if (strcmp(ms->ms_name, name) == 0) {
    114      1.1      jmmv 			if (msdest != NULL)
    115      1.1      jmmv 				*msdest = *ms;
    116      1.1      jmmv 			found = true;
    117      1.1      jmmv 		}
    118      1.1      jmmv 	}
    119      1.1      jmmv 
    120      1.1      jmmv 	free(iov.iov_base);
    121      1.1      jmmv 
    122      1.1      jmmv 	return found;
    123      1.1      jmmv }
    124      1.1      jmmv 
    125      1.1      jmmv /*
    126      1.1      jmmv  * Queries a sysctl property.
    127      1.1      jmmv  */
    128  1.5.6.1      yamt static bool
    129      1.1      jmmv get_sysctl(const char *name, void *buf, const size_t len)
    130      1.1      jmmv {
    131      1.1      jmmv 	size_t len2 = len;
    132      1.1      jmmv 	printf("Querying sysctl variable: %s\n", name);
    133      1.1      jmmv 	int ret = sysctlbyname(name, buf, &len2, NULL, 0);
    134      1.1      jmmv 	if (ret == -1 && errno != ENOENT) {
    135      1.1      jmmv 		fprintf(stderr, "sysctlbyname(2) failed: %s\n",
    136      1.1      jmmv 		    strerror(errno));
    137      1.1      jmmv 		atf_tc_fail("Failed to query %s", name);
    138      1.1      jmmv 	}
    139      1.1      jmmv 	return ret != -1;
    140      1.1      jmmv }
    141      1.1      jmmv 
    142      1.1      jmmv /*
    143      1.1      jmmv  * Returns a boolean indicating if the k_helper module was loaded
    144      1.1      jmmv  * successfully.  This implementation uses modctl(2)'s MODCTL_STAT
    145      1.1      jmmv  * subcommand to do the check.
    146      1.1      jmmv  */
    147  1.5.6.1      yamt static bool
    148      1.1      jmmv k_helper_is_present_stat(void)
    149      1.1      jmmv {
    150      1.1      jmmv 
    151      1.1      jmmv 	return get_modstat_info("k_helper", NULL);
    152      1.1      jmmv }
    153      1.1      jmmv 
    154      1.1      jmmv /*
    155      1.1      jmmv  * Returns a boolean indicating if the k_helper module was loaded
    156      1.1      jmmv  * successfully.  This implementation uses the module's sysctl
    157      1.1      jmmv  * installed node to do the check.
    158      1.1      jmmv  */
    159  1.5.6.1      yamt static bool
    160      1.1      jmmv k_helper_is_present_sysctl(void)
    161      1.1      jmmv {
    162      1.1      jmmv 	size_t present;
    163      1.1      jmmv 
    164      1.1      jmmv 	return get_sysctl("vendor.k_helper.present", &present,
    165      1.1      jmmv 	    sizeof(present));
    166      1.1      jmmv }
    167      1.1      jmmv 
    168      1.1      jmmv /*
    169      1.1      jmmv  * Returns a boolean indicating if the k_helper module was loaded
    170      1.1      jmmv  * successfully.  The 'how' parameter specifies the implementation to
    171      1.1      jmmv  * use to do the check.
    172      1.1      jmmv  */
    173  1.5.6.1      yamt static bool
    174      1.1      jmmv k_helper_is_present(enum presence_check how)
    175      1.1      jmmv {
    176      1.1      jmmv 	bool found;
    177      1.1      jmmv 
    178      1.1      jmmv 	switch (how) {
    179      1.1      jmmv 	case both_checks:
    180      1.1      jmmv 		found = k_helper_is_present_stat();
    181      1.1      jmmv 		ATF_CHECK(k_helper_is_present_sysctl() == found);
    182      1.1      jmmv 		break;
    183      1.1      jmmv 
    184      1.1      jmmv 	case stat_check:
    185      1.1      jmmv 		found = k_helper_is_present_stat();
    186      1.1      jmmv 		break;
    187      1.1      jmmv 
    188      1.1      jmmv 	case sysctl_check:
    189      1.1      jmmv 		found = k_helper_is_present_sysctl();
    190      1.1      jmmv 		break;
    191      1.1      jmmv 
    192      1.1      jmmv 	default:
    193      1.5  christos 		found = false;
    194      1.5  christos 		assert(found);
    195      1.1      jmmv 	}
    196      1.1      jmmv 
    197      1.1      jmmv 	return found;
    198      1.1      jmmv }
    199      1.1      jmmv 
    200      1.1      jmmv /*
    201      1.1      jmmv  * Loads the specified module from a file.  If fatal is set and an error
    202      1.1      jmmv  * occurs when loading the module, an error message is printed and the
    203      1.1      jmmv  * test case is aborted.
    204      1.1      jmmv  */
    205  1.5.6.1      yamt static __printflike(3, 4) int
    206      1.1      jmmv load(prop_dictionary_t props, bool fatal, const char *fmt, ...)
    207      1.1      jmmv {
    208      1.1      jmmv 	int err;
    209      1.1      jmmv 	va_list ap;
    210      1.1      jmmv 	char filename[MAXPATHLEN], *propsstr;
    211      1.1      jmmv 	modctl_load_t ml;
    212      1.1      jmmv 
    213  1.5.6.3      yamt 	check_permission();
    214      1.1      jmmv 	if (props == NULL) {
    215      1.1      jmmv 		props = prop_dictionary_create();
    216      1.1      jmmv 		propsstr = prop_dictionary_externalize(props);
    217      1.1      jmmv 		ATF_CHECK(propsstr != NULL);
    218      1.1      jmmv 		prop_object_release(props);
    219      1.1      jmmv 	} else {
    220      1.1      jmmv 		propsstr = prop_dictionary_externalize(props);
    221      1.1      jmmv 		ATF_CHECK(propsstr != NULL);
    222      1.1      jmmv 	}
    223      1.1      jmmv 
    224      1.1      jmmv 	va_start(ap, fmt);
    225      1.1      jmmv 	vsnprintf(filename, sizeof(filename), fmt, ap);
    226      1.1      jmmv 	va_end(ap);
    227      1.1      jmmv 
    228      1.1      jmmv 	ml.ml_filename = filename;
    229      1.1      jmmv 	ml.ml_flags = 0;
    230      1.1      jmmv 	ml.ml_props = propsstr;
    231      1.1      jmmv 	ml.ml_propslen = strlen(propsstr);
    232      1.1      jmmv 
    233      1.1      jmmv 	printf("Loading module %s\n", filename);
    234  1.5.6.1      yamt 	errno = err = 0;
    235  1.5.6.1      yamt 
    236      1.1      jmmv 	if (modctl(MODCTL_LOAD, &ml) == -1) {
    237      1.1      jmmv 		err = errno;
    238      1.1      jmmv 		fprintf(stderr, "modctl(MODCTL_LOAD, %s), failed: %s\n",
    239      1.1      jmmv 		    filename, strerror(err));
    240      1.1      jmmv 		if (fatal)
    241      1.1      jmmv 			atf_tc_fail("Module load failed");
    242      1.1      jmmv 	}
    243      1.1      jmmv 
    244      1.1      jmmv 	free(propsstr);
    245      1.1      jmmv 
    246      1.1      jmmv 	return err;
    247      1.1      jmmv }
    248      1.1      jmmv 
    249      1.1      jmmv /*
    250      1.1      jmmv  * Unloads the specified module.  If silent is true, nothing will be
    251      1.1      jmmv  * printed and no errors will be raised if the unload was unsuccessful.
    252      1.1      jmmv  */
    253  1.5.6.1      yamt static int
    254      1.1      jmmv unload(const char *name, bool fatal)
    255      1.1      jmmv {
    256      1.1      jmmv 	int err;
    257      1.1      jmmv 
    258  1.5.6.3      yamt 	check_permission();
    259      1.1      jmmv 	printf("Unloading module %s\n", name);
    260  1.5.6.1      yamt 	errno = err = 0;
    261  1.5.6.1      yamt 
    262      1.1      jmmv 	if (modctl(MODCTL_UNLOAD, __UNCONST(name)) == -1) {
    263      1.1      jmmv 		err = errno;
    264      1.1      jmmv 		fprintf(stderr, "modctl(MODCTL_UNLOAD, %s) failed: %s\n",
    265      1.1      jmmv 		    name, strerror(err));
    266      1.1      jmmv 		if (fatal)
    267      1.1      jmmv 			atf_tc_fail("Module unload failed");
    268      1.1      jmmv 	}
    269      1.1      jmmv 	return err;
    270      1.1      jmmv }
    271      1.1      jmmv 
    272      1.1      jmmv /*
    273      1.1      jmmv  * A silent version of unload, to be called as part of the cleanup
    274      1.1      jmmv  * process only.
    275      1.1      jmmv  */
    276  1.5.6.1      yamt static void
    277      1.1      jmmv unload_cleanup(const char *name)
    278      1.1      jmmv {
    279      1.1      jmmv 
    280      1.1      jmmv 	(void)modctl(MODCTL_UNLOAD, __UNCONST(name));
    281      1.1      jmmv }
    282      1.1      jmmv 
    283      1.1      jmmv /* --------------------------------------------------------------------- */
    284      1.1      jmmv /* Test cases                                                            */
    285      1.1      jmmv /* --------------------------------------------------------------------- */
    286      1.1      jmmv 
    287      1.1      jmmv ATF_TC_WITH_CLEANUP(cmd_load);
    288      1.1      jmmv ATF_TC_HEAD(cmd_load, tc)
    289      1.1      jmmv {
    290      1.1      jmmv 	atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_LOAD command");
    291      1.1      jmmv 	atf_tc_set_md_var(tc, "require.user", "root");
    292      1.1      jmmv }
    293      1.1      jmmv ATF_TC_BODY(cmd_load, tc)
    294      1.1      jmmv {
    295      1.1      jmmv 	char longname[MAXPATHLEN];
    296      1.1      jmmv 	size_t i;
    297      1.1      jmmv 
    298  1.5.6.2      yamt 	ATF_CHECK(load(NULL, false, " ") == ENOENT);
    299      1.1      jmmv 	ATF_CHECK(load(NULL, false, "non-existent.o") == ENOENT);
    300      1.1      jmmv 
    301      1.1      jmmv 	for (i = 0; i < MAXPATHLEN - 1; i++)
    302      1.1      jmmv 		longname[i] = 'a';
    303      1.1      jmmv 	longname[MAXPATHLEN - 1] = '\0';
    304  1.5.6.1      yamt 	ATF_CHECK(load(NULL, false, "%s", longname) == ENAMETOOLONG);
    305      1.1      jmmv 
    306      1.1      jmmv 	ATF_CHECK(!k_helper_is_present(stat_check));
    307      1.3      jmmv 	load(NULL, true, "%s/k_helper/k_helper.kmod",
    308      1.3      jmmv 	    atf_tc_get_config_var(tc, "srcdir"));
    309      1.1      jmmv 	printf("Checking if load was successful\n");
    310      1.1      jmmv 	ATF_CHECK(k_helper_is_present(stat_check));
    311      1.1      jmmv }
    312      1.1      jmmv ATF_TC_CLEANUP(cmd_load, tc)
    313      1.1      jmmv {
    314      1.1      jmmv 	unload_cleanup("k_helper");
    315      1.1      jmmv }
    316      1.1      jmmv 
    317      1.1      jmmv ATF_TC_WITH_CLEANUP(cmd_load_props);
    318      1.1      jmmv ATF_TC_HEAD(cmd_load_props, tc)
    319      1.1      jmmv {
    320      1.1      jmmv 	atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_LOAD command, "
    321      1.1      jmmv 	    "providing extra load-time properties");
    322      1.1      jmmv 	atf_tc_set_md_var(tc, "require.user", "root");
    323      1.1      jmmv }
    324      1.1      jmmv ATF_TC_BODY(cmd_load_props, tc)
    325      1.1      jmmv {
    326      1.1      jmmv 	prop_dictionary_t props;
    327      1.1      jmmv 
    328      1.1      jmmv 	printf("Loading module without properties\n");
    329      1.1      jmmv 	props = prop_dictionary_create();
    330      1.3      jmmv 	load(props, true, "%s/k_helper/k_helper.kmod",
    331      1.3      jmmv 	    atf_tc_get_config_var(tc, "srcdir"));
    332      1.1      jmmv 	prop_object_release(props);
    333      1.1      jmmv 	{
    334      1.1      jmmv 		int ok;
    335      1.1      jmmv 		ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_ok",
    336      1.1      jmmv 		    &ok, sizeof(ok)));
    337      1.1      jmmv 		ATF_CHECK(!ok);
    338      1.1      jmmv 	}
    339      1.1      jmmv 	unload("k_helper", true);
    340      1.1      jmmv 
    341      1.1      jmmv 	printf("Loading module with a string property\n");
    342      1.1      jmmv 	props = prop_dictionary_create();
    343      1.1      jmmv 	prop_dictionary_set(props, "prop_str",
    344      1.1      jmmv 	    prop_string_create_cstring("1st string"));
    345      1.3      jmmv 	load(props, true, "%s/k_helper/k_helper.kmod",
    346      1.3      jmmv 	    atf_tc_get_config_var(tc, "srcdir"));
    347      1.1      jmmv 	prop_object_release(props);
    348      1.1      jmmv 	{
    349      1.1      jmmv 		int ok;
    350      1.1      jmmv 		ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_ok",
    351      1.1      jmmv 		    &ok, sizeof(ok)));
    352      1.1      jmmv 		ATF_CHECK(ok);
    353      1.1      jmmv 
    354      1.1      jmmv 		char val[128];
    355      1.1      jmmv 		ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_val",
    356      1.1      jmmv 		    &val, sizeof(val)));
    357      1.1      jmmv 		ATF_CHECK(strcmp(val, "1st string") == 0);
    358      1.1      jmmv 	}
    359      1.1      jmmv 	unload("k_helper", true);
    360      1.1      jmmv 
    361      1.1      jmmv 	printf("Loading module with a different string property\n");
    362      1.1      jmmv 	props = prop_dictionary_create();
    363      1.1      jmmv 	prop_dictionary_set(props, "prop_str",
    364      1.1      jmmv 	    prop_string_create_cstring("2nd string"));
    365      1.3      jmmv 	load(props, true, "%s/k_helper/k_helper.kmod",
    366      1.3      jmmv 	    atf_tc_get_config_var(tc, "srcdir"));
    367      1.1      jmmv 	prop_object_release(props);
    368      1.1      jmmv 	{
    369      1.1      jmmv 		int ok;
    370      1.1      jmmv 		ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_ok",
    371      1.1      jmmv 		    &ok, sizeof(ok)));
    372      1.1      jmmv 		ATF_CHECK(ok);
    373      1.1      jmmv 
    374      1.1      jmmv 		char val[128];
    375      1.1      jmmv 		ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_val",
    376      1.1      jmmv 		    &val, sizeof(val)));
    377      1.1      jmmv 		ATF_CHECK(strcmp(val, "2nd string") == 0);
    378      1.1      jmmv 	}
    379      1.1      jmmv 	unload("k_helper", true);
    380      1.1      jmmv }
    381      1.1      jmmv ATF_TC_CLEANUP(cmd_load_props, tc)
    382      1.1      jmmv {
    383      1.1      jmmv 	unload_cleanup("k_helper");
    384      1.1      jmmv }
    385      1.1      jmmv 
    386      1.4  pgoyette ATF_TC_WITH_CLEANUP(cmd_load_recurse);
    387      1.4  pgoyette ATF_TC_HEAD(cmd_load_recurse, tc)
    388      1.4  pgoyette {
    389      1.4  pgoyette 	atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_LOAD command, "
    390      1.4  pgoyette 	    "with recursive module_load()");
    391      1.4  pgoyette 	atf_tc_set_md_var(tc, "require.user", "root");
    392      1.4  pgoyette }
    393      1.4  pgoyette ATF_TC_BODY(cmd_load_recurse, tc)
    394      1.4  pgoyette {
    395      1.4  pgoyette 	prop_dictionary_t props;
    396      1.4  pgoyette 	char filename[MAXPATHLEN];
    397      1.4  pgoyette 
    398      1.4  pgoyette 	printf("Loading module with request to load another module\n");
    399      1.4  pgoyette 	props = prop_dictionary_create();
    400      1.4  pgoyette 	snprintf(filename, sizeof(filename), "%s/k_helper2/k_helper2.kmod",
    401      1.4  pgoyette 	    atf_tc_get_config_var(tc, "srcdir"));
    402      1.4  pgoyette 	prop_dictionary_set(props, "prop_recurse",
    403      1.4  pgoyette 	    prop_string_create_cstring(filename));
    404      1.4  pgoyette 	load(props, true, "%s/k_helper/k_helper.kmod",
    405      1.4  pgoyette 	    atf_tc_get_config_var(tc, "srcdir"));
    406      1.4  pgoyette 	{
    407      1.4  pgoyette 		int ok;
    408      1.4  pgoyette 		ATF_CHECK(get_sysctl("vendor.k_helper.prop_int_load",
    409      1.4  pgoyette 		    &ok, sizeof(ok)));
    410      1.4  pgoyette 		ATF_CHECK(ok == 0);
    411      1.4  pgoyette 		ATF_CHECK(get_sysctl("vendor.k_helper2.present",
    412      1.4  pgoyette 		    &ok, sizeof(ok)));
    413      1.4  pgoyette 		ATF_CHECK(ok);
    414      1.4  pgoyette 	}
    415      1.4  pgoyette 	unload("k_helper", true);
    416      1.4  pgoyette 	unload("k_helper2", true);
    417      1.4  pgoyette }
    418      1.4  pgoyette ATF_TC_CLEANUP(cmd_load_recurse, tc)
    419      1.4  pgoyette {
    420      1.4  pgoyette 	unload_cleanup("k_helper");
    421      1.4  pgoyette 	unload_cleanup("k_helper2");
    422      1.4  pgoyette }
    423      1.4  pgoyette 
    424      1.1      jmmv ATF_TC_WITH_CLEANUP(cmd_stat);
    425      1.1      jmmv ATF_TC_HEAD(cmd_stat, tc)
    426      1.1      jmmv {
    427      1.1      jmmv 	atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_STAT command");
    428      1.1      jmmv 	atf_tc_set_md_var(tc, "require.user", "root");
    429      1.1      jmmv }
    430      1.1      jmmv ATF_TC_BODY(cmd_stat, tc)
    431      1.1      jmmv {
    432      1.1      jmmv 	ATF_CHECK(!k_helper_is_present(both_checks));
    433      1.1      jmmv 
    434      1.3      jmmv 	load(NULL, true, "%s/k_helper/k_helper.kmod",
    435      1.3      jmmv 	    atf_tc_get_config_var(tc, "srcdir"));
    436      1.1      jmmv 	ATF_CHECK(k_helper_is_present(both_checks));
    437      1.1      jmmv 	{
    438      1.1      jmmv 		modstat_t ms;
    439      1.1      jmmv 		ATF_CHECK(get_modstat_info("k_helper", &ms));
    440      1.1      jmmv 
    441      1.1      jmmv 		ATF_CHECK(ms.ms_class == MODULE_CLASS_MISC);
    442      1.1      jmmv 		ATF_CHECK(ms.ms_source == MODULE_SOURCE_FILESYS);
    443      1.1      jmmv 		ATF_CHECK(ms.ms_refcnt == 0);
    444      1.1      jmmv 	}
    445      1.1      jmmv 	unload("k_helper", true);
    446      1.1      jmmv 
    447      1.1      jmmv 	ATF_CHECK(!k_helper_is_present(both_checks));
    448      1.1      jmmv }
    449      1.1      jmmv ATF_TC_CLEANUP(cmd_stat, tc)
    450      1.1      jmmv {
    451      1.1      jmmv 	unload_cleanup("k_helper");
    452      1.1      jmmv }
    453      1.1      jmmv 
    454      1.1      jmmv ATF_TC_WITH_CLEANUP(cmd_unload);
    455      1.1      jmmv ATF_TC_HEAD(cmd_unload, tc)
    456      1.1      jmmv {
    457      1.1      jmmv 	atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_UNLOAD command");
    458      1.1      jmmv 	atf_tc_set_md_var(tc, "require.user", "root");
    459      1.1      jmmv }
    460      1.1      jmmv ATF_TC_BODY(cmd_unload, tc)
    461      1.1      jmmv {
    462      1.3      jmmv 	load(NULL, true, "%s/k_helper/k_helper.kmod",
    463      1.3      jmmv 	    atf_tc_get_config_var(tc, "srcdir"));
    464      1.1      jmmv 
    465      1.1      jmmv 	ATF_CHECK(unload("", false) == ENOENT);
    466      1.2        ad 	ATF_CHECK(unload("non-existent.kmod", false) == ENOENT);
    467      1.2        ad 	ATF_CHECK(unload("k_helper.kmod", false) == ENOENT);
    468      1.1      jmmv 
    469      1.1      jmmv 	ATF_CHECK(k_helper_is_present(stat_check));
    470      1.1      jmmv 	unload("k_helper", true);
    471      1.1      jmmv 	printf("Checking if unload was successful\n");
    472      1.1      jmmv 	ATF_CHECK(!k_helper_is_present(stat_check));
    473      1.1      jmmv }
    474      1.1      jmmv ATF_TC_CLEANUP(cmd_unload, tc)
    475      1.1      jmmv {
    476      1.1      jmmv 	unload_cleanup("k_helper");
    477      1.1      jmmv }
    478      1.1      jmmv 
    479      1.1      jmmv /* --------------------------------------------------------------------- */
    480      1.1      jmmv /* Main                                                                  */
    481      1.1      jmmv /* --------------------------------------------------------------------- */
    482      1.1      jmmv 
    483      1.1      jmmv ATF_TP_ADD_TCS(tp)
    484      1.1      jmmv {
    485      1.1      jmmv 
    486      1.1      jmmv 	ATF_TP_ADD_TC(tp, cmd_load);
    487      1.1      jmmv 	ATF_TP_ADD_TC(tp, cmd_load_props);
    488      1.1      jmmv 	ATF_TP_ADD_TC(tp, cmd_stat);
    489      1.4  pgoyette 	ATF_TP_ADD_TC(tp, cmd_load_recurse);
    490      1.1      jmmv 	ATF_TP_ADD_TC(tp, cmd_unload);
    491      1.1      jmmv 
    492      1.1      jmmv 	return atf_no_error();
    493      1.1      jmmv }
    494