Home | History | Annotate | Line # | Download | only in modules
t_modctl.c revision 1.1
      1  1.1  jmmv /*	$NetBSD: t_modctl.c,v 1.1 2008/05/01 15:38:17 jmmv 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.1  jmmv __KERNEL_RCSID(0, "$NetBSD: t_modctl.c,v 1.1 2008/05/01 15:38:17 jmmv 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 static bool have_modular = false;
     48  1.1  jmmv 
     49  1.1  jmmv enum presence_check { both_checks, stat_check, sysctl_check };
     50  1.1  jmmv 
     51  1.1  jmmv /* --------------------------------------------------------------------- */
     52  1.1  jmmv /* Auxiliary functions                                                   */
     53  1.1  jmmv /* --------------------------------------------------------------------- */
     54  1.1  jmmv 
     55  1.1  jmmv /*
     56  1.1  jmmv  * Checks if the kernel has 'options MODULAR' built into it and returns
     57  1.1  jmmv  * a boolean indicating this condition.  This function must be called
     58  1.1  jmmv  * during the test program's initialization and the result be stored
     59  1.1  jmmv  * globally for further (efficient) usage of require_modular().
     60  1.1  jmmv  */
     61  1.1  jmmv static
     62  1.1  jmmv bool
     63  1.1  jmmv check_modular(void)
     64  1.1  jmmv {
     65  1.1  jmmv 	bool res;
     66  1.1  jmmv 	struct iovec iov;
     67  1.1  jmmv 
     68  1.1  jmmv 	iov.iov_base = NULL;
     69  1.1  jmmv 	iov.iov_len = 0;
     70  1.1  jmmv 
     71  1.1  jmmv 	if (modctl(MODCTL_STAT, &iov) == 0)
     72  1.1  jmmv 		res = true;
     73  1.1  jmmv 	else
     74  1.1  jmmv 		res = (errno != ENOSYS);
     75  1.1  jmmv 
     76  1.1  jmmv 	return res;
     77  1.1  jmmv }
     78  1.1  jmmv 
     79  1.1  jmmv /*
     80  1.1  jmmv  * Makes sure that the kernel has 'options MODULAR' built into it and
     81  1.1  jmmv  * skips the test otherwise.  Cannot be called unless check_modular()
     82  1.1  jmmv  * has been executed before.
     83  1.1  jmmv  */
     84  1.1  jmmv static
     85  1.1  jmmv void
     86  1.1  jmmv require_modular(void)
     87  1.1  jmmv {
     88  1.1  jmmv 
     89  1.1  jmmv 	if (!have_modular)
     90  1.1  jmmv 		atf_tc_skip("Kernel does not have 'options MODULAR'.");
     91  1.1  jmmv }
     92  1.1  jmmv 
     93  1.1  jmmv static
     94  1.1  jmmv bool
     95  1.1  jmmv get_modstat_info(const char *name, modstat_t *msdest)
     96  1.1  jmmv {
     97  1.1  jmmv 	bool found;
     98  1.1  jmmv 	size_t len;
     99  1.1  jmmv 	struct iovec iov;
    100  1.1  jmmv 	modstat_t *ms;
    101  1.1  jmmv 
    102  1.1  jmmv 	for (len = 4096; ;) {
    103  1.1  jmmv 		iov.iov_base = malloc(len);
    104  1.1  jmmv 		iov.iov_len = len;
    105  1.1  jmmv 		if (modctl(MODCTL_STAT, &iov) != 0) {
    106  1.1  jmmv 			int err = errno;
    107  1.1  jmmv 			fprintf(stderr, "modctl(MODCTL_STAT) failed: %s\n",
    108  1.1  jmmv 			    strerror(err));
    109  1.1  jmmv 			atf_tc_fail("Failed to query module status");
    110  1.1  jmmv 		}
    111  1.1  jmmv 		if (len >= iov.iov_len)
    112  1.1  jmmv 			break;
    113  1.1  jmmv 		free(iov.iov_base);
    114  1.1  jmmv 		len = iov.iov_len;
    115  1.1  jmmv 	}
    116  1.1  jmmv 
    117  1.1  jmmv 	found = false;
    118  1.1  jmmv 	len = iov.iov_len / sizeof(modstat_t);
    119  1.1  jmmv 	for (ms = (modstat_t *)iov.iov_base; len != 0 && !found;
    120  1.1  jmmv 	    ms++, len--) {
    121  1.1  jmmv 		if (strcmp(ms->ms_name, name) == 0) {
    122  1.1  jmmv 			if (msdest != NULL)
    123  1.1  jmmv 				*msdest = *ms;
    124  1.1  jmmv 			found = true;
    125  1.1  jmmv 		}
    126  1.1  jmmv 	}
    127  1.1  jmmv 
    128  1.1  jmmv 	free(iov.iov_base);
    129  1.1  jmmv 
    130  1.1  jmmv 	return found;
    131  1.1  jmmv }
    132  1.1  jmmv 
    133  1.1  jmmv /*
    134  1.1  jmmv  * Queries a sysctl property.
    135  1.1  jmmv  */
    136  1.1  jmmv static
    137  1.1  jmmv bool
    138  1.1  jmmv get_sysctl(const char *name, void *buf, const size_t len)
    139  1.1  jmmv {
    140  1.1  jmmv 	size_t len2 = len;
    141  1.1  jmmv 	printf("Querying sysctl variable: %s\n", name);
    142  1.1  jmmv 	int ret = sysctlbyname(name, buf, &len2, NULL, 0);
    143  1.1  jmmv 	if (ret == -1 && errno != ENOENT) {
    144  1.1  jmmv 		fprintf(stderr, "sysctlbyname(2) failed: %s\n",
    145  1.1  jmmv 		    strerror(errno));
    146  1.1  jmmv 		atf_tc_fail("Failed to query %s", name);
    147  1.1  jmmv 	}
    148  1.1  jmmv 	return ret != -1;
    149  1.1  jmmv }
    150  1.1  jmmv 
    151  1.1  jmmv /*
    152  1.1  jmmv  * Returns a boolean indicating if the k_helper module was loaded
    153  1.1  jmmv  * successfully.  This implementation uses modctl(2)'s MODCTL_STAT
    154  1.1  jmmv  * subcommand to do the check.
    155  1.1  jmmv  */
    156  1.1  jmmv static
    157  1.1  jmmv bool
    158  1.1  jmmv k_helper_is_present_stat(void)
    159  1.1  jmmv {
    160  1.1  jmmv 
    161  1.1  jmmv 	return get_modstat_info("k_helper", NULL);
    162  1.1  jmmv }
    163  1.1  jmmv 
    164  1.1  jmmv /*
    165  1.1  jmmv  * Returns a boolean indicating if the k_helper module was loaded
    166  1.1  jmmv  * successfully.  This implementation uses the module's sysctl
    167  1.1  jmmv  * installed node to do the check.
    168  1.1  jmmv  */
    169  1.1  jmmv static
    170  1.1  jmmv bool
    171  1.1  jmmv k_helper_is_present_sysctl(void)
    172  1.1  jmmv {
    173  1.1  jmmv 	size_t present;
    174  1.1  jmmv 
    175  1.1  jmmv 	return get_sysctl("vendor.k_helper.present", &present,
    176  1.1  jmmv 	    sizeof(present));
    177  1.1  jmmv }
    178  1.1  jmmv 
    179  1.1  jmmv /*
    180  1.1  jmmv  * Returns a boolean indicating if the k_helper module was loaded
    181  1.1  jmmv  * successfully.  The 'how' parameter specifies the implementation to
    182  1.1  jmmv  * use to do the check.
    183  1.1  jmmv  */
    184  1.1  jmmv static
    185  1.1  jmmv bool
    186  1.1  jmmv k_helper_is_present(enum presence_check how)
    187  1.1  jmmv {
    188  1.1  jmmv 	bool found;
    189  1.1  jmmv 
    190  1.1  jmmv 	switch (how) {
    191  1.1  jmmv 	case both_checks:
    192  1.1  jmmv 		found = k_helper_is_present_stat();
    193  1.1  jmmv 		ATF_CHECK(k_helper_is_present_sysctl() == found);
    194  1.1  jmmv 		break;
    195  1.1  jmmv 
    196  1.1  jmmv 	case stat_check:
    197  1.1  jmmv 		found = k_helper_is_present_stat();
    198  1.1  jmmv 		break;
    199  1.1  jmmv 
    200  1.1  jmmv 	case sysctl_check:
    201  1.1  jmmv 		found = k_helper_is_present_sysctl();
    202  1.1  jmmv 		break;
    203  1.1  jmmv 
    204  1.1  jmmv 	default:
    205  1.1  jmmv 		assert(false);
    206  1.1  jmmv 	}
    207  1.1  jmmv 
    208  1.1  jmmv 	return found;
    209  1.1  jmmv }
    210  1.1  jmmv 
    211  1.1  jmmv /*
    212  1.1  jmmv  * Loads the specified module from a file.  If fatal is set and an error
    213  1.1  jmmv  * occurs when loading the module, an error message is printed and the
    214  1.1  jmmv  * test case is aborted.
    215  1.1  jmmv  */
    216  1.1  jmmv static
    217  1.1  jmmv int
    218  1.1  jmmv load(prop_dictionary_t props, bool fatal, const char *fmt, ...)
    219  1.1  jmmv {
    220  1.1  jmmv 	int err;
    221  1.1  jmmv 	va_list ap;
    222  1.1  jmmv 	char filename[MAXPATHLEN], *propsstr;
    223  1.1  jmmv 	modctl_load_t ml;
    224  1.1  jmmv 
    225  1.1  jmmv 	if (props == NULL) {
    226  1.1  jmmv 		props = prop_dictionary_create();
    227  1.1  jmmv 		propsstr = prop_dictionary_externalize(props);
    228  1.1  jmmv 		ATF_CHECK(propsstr != NULL);
    229  1.1  jmmv 		prop_object_release(props);
    230  1.1  jmmv 	} else {
    231  1.1  jmmv 		propsstr = prop_dictionary_externalize(props);
    232  1.1  jmmv 		ATF_CHECK(propsstr != NULL);
    233  1.1  jmmv 	}
    234  1.1  jmmv 
    235  1.1  jmmv 	va_start(ap, fmt);
    236  1.1  jmmv 	vsnprintf(filename, sizeof(filename), fmt, ap);
    237  1.1  jmmv 	va_end(ap);
    238  1.1  jmmv 
    239  1.1  jmmv 	ml.ml_filename = filename;
    240  1.1  jmmv 	ml.ml_flags = 0;
    241  1.1  jmmv 	ml.ml_props = propsstr;
    242  1.1  jmmv 	ml.ml_propslen = strlen(propsstr);
    243  1.1  jmmv 
    244  1.1  jmmv 	printf("Loading module %s\n", filename);
    245  1.1  jmmv 	err = 0;
    246  1.1  jmmv 	if (modctl(MODCTL_LOAD, &ml) == -1) {
    247  1.1  jmmv 		err = errno;
    248  1.1  jmmv 		fprintf(stderr, "modctl(MODCTL_LOAD, %s), failed: %s\n",
    249  1.1  jmmv 		    filename, strerror(err));
    250  1.1  jmmv 		if (fatal)
    251  1.1  jmmv 			atf_tc_fail("Module load failed");
    252  1.1  jmmv 	}
    253  1.1  jmmv 
    254  1.1  jmmv 	free(propsstr);
    255  1.1  jmmv 
    256  1.1  jmmv 	return err;
    257  1.1  jmmv }
    258  1.1  jmmv 
    259  1.1  jmmv /*
    260  1.1  jmmv  * Unloads the specified module.  If silent is true, nothing will be
    261  1.1  jmmv  * printed and no errors will be raised if the unload was unsuccessful.
    262  1.1  jmmv  */
    263  1.1  jmmv static
    264  1.1  jmmv int
    265  1.1  jmmv unload(const char *name, bool fatal)
    266  1.1  jmmv {
    267  1.1  jmmv 	int err;
    268  1.1  jmmv 
    269  1.1  jmmv 	printf("Unloading module %s\n", name);
    270  1.1  jmmv 	err = 0;
    271  1.1  jmmv 	if (modctl(MODCTL_UNLOAD, __UNCONST(name)) == -1) {
    272  1.1  jmmv 		err = errno;
    273  1.1  jmmv 		fprintf(stderr, "modctl(MODCTL_UNLOAD, %s) failed: %s\n",
    274  1.1  jmmv 		    name, strerror(err));
    275  1.1  jmmv 		if (fatal)
    276  1.1  jmmv 			atf_tc_fail("Module unload failed");
    277  1.1  jmmv 	}
    278  1.1  jmmv 	return err;
    279  1.1  jmmv }
    280  1.1  jmmv 
    281  1.1  jmmv /*
    282  1.1  jmmv  * A silent version of unload, to be called as part of the cleanup
    283  1.1  jmmv  * process only.
    284  1.1  jmmv  */
    285  1.1  jmmv static
    286  1.1  jmmv int
    287  1.1  jmmv unload_cleanup(const char *name)
    288  1.1  jmmv {
    289  1.1  jmmv 
    290  1.1  jmmv 	(void)modctl(MODCTL_UNLOAD, __UNCONST(name));
    291  1.1  jmmv }
    292  1.1  jmmv 
    293  1.1  jmmv /* --------------------------------------------------------------------- */
    294  1.1  jmmv /* Test cases                                                            */
    295  1.1  jmmv /* --------------------------------------------------------------------- */
    296  1.1  jmmv 
    297  1.1  jmmv ATF_TC_WITH_CLEANUP(cmd_load);
    298  1.1  jmmv ATF_TC_HEAD(cmd_load, tc)
    299  1.1  jmmv {
    300  1.1  jmmv 	atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_LOAD command");
    301  1.1  jmmv 	atf_tc_set_md_var(tc, "require.user", "root");
    302  1.1  jmmv }
    303  1.1  jmmv ATF_TC_BODY(cmd_load, tc)
    304  1.1  jmmv {
    305  1.1  jmmv 	char longname[MAXPATHLEN];
    306  1.1  jmmv 	size_t i;
    307  1.1  jmmv 
    308  1.1  jmmv 	require_modular();
    309  1.1  jmmv 
    310  1.1  jmmv 	ATF_CHECK(load(NULL, false, "") == ENOENT);
    311  1.1  jmmv 	ATF_CHECK(load(NULL, false, "non-existent.o") == ENOENT);
    312  1.1  jmmv 
    313  1.1  jmmv 	for (i = 0; i < MAXPATHLEN - 1; i++)
    314  1.1  jmmv 		longname[i] = 'a';
    315  1.1  jmmv 	longname[MAXPATHLEN - 1] = '\0';
    316  1.1  jmmv 	ATF_CHECK(load(NULL, false, longname) == ENAMETOOLONG);
    317  1.1  jmmv 
    318  1.1  jmmv 	ATF_CHECK(!k_helper_is_present(stat_check));
    319  1.1  jmmv 	load(NULL, true, "%s/k_helper.o", atf_tc_get_config_var(tc, "srcdir"));
    320  1.1  jmmv 	printf("Checking if load was successful\n");
    321  1.1  jmmv 	ATF_CHECK(k_helper_is_present(stat_check));
    322  1.1  jmmv }
    323  1.1  jmmv ATF_TC_CLEANUP(cmd_load, tc)
    324  1.1  jmmv {
    325  1.1  jmmv 	unload_cleanup("k_helper");
    326  1.1  jmmv }
    327  1.1  jmmv 
    328  1.1  jmmv ATF_TC_WITH_CLEANUP(cmd_load_props);
    329  1.1  jmmv ATF_TC_HEAD(cmd_load_props, tc)
    330  1.1  jmmv {
    331  1.1  jmmv 	atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_LOAD command, "
    332  1.1  jmmv 	    "providing extra load-time properties");
    333  1.1  jmmv 	atf_tc_set_md_var(tc, "require.user", "root");
    334  1.1  jmmv }
    335  1.1  jmmv ATF_TC_BODY(cmd_load_props, tc)
    336  1.1  jmmv {
    337  1.1  jmmv 	prop_dictionary_t props;
    338  1.1  jmmv 
    339  1.1  jmmv 	require_modular();
    340  1.1  jmmv 
    341  1.1  jmmv 	printf("Loading module without properties\n");
    342  1.1  jmmv 	props = prop_dictionary_create();
    343  1.1  jmmv 	load(props, true, "%s/k_helper.o", atf_tc_get_config_var(tc, "srcdir"));
    344  1.1  jmmv 	prop_object_release(props);
    345  1.1  jmmv 	{
    346  1.1  jmmv 		int ok;
    347  1.1  jmmv 		ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_ok",
    348  1.1  jmmv 		    &ok, sizeof(ok)));
    349  1.1  jmmv 		ATF_CHECK(!ok);
    350  1.1  jmmv 	}
    351  1.1  jmmv 	unload("k_helper", true);
    352  1.1  jmmv 
    353  1.1  jmmv 	printf("Loading module with a string property\n");
    354  1.1  jmmv 	props = prop_dictionary_create();
    355  1.1  jmmv 	prop_dictionary_set(props, "prop_str",
    356  1.1  jmmv 	    prop_string_create_cstring("1st string"));
    357  1.1  jmmv 	load(props, true, "%s/k_helper.o", atf_tc_get_config_var(tc, "srcdir"));
    358  1.1  jmmv 	prop_object_release(props);
    359  1.1  jmmv 	{
    360  1.1  jmmv 		int ok;
    361  1.1  jmmv 		ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_ok",
    362  1.1  jmmv 		    &ok, sizeof(ok)));
    363  1.1  jmmv 		ATF_CHECK(ok);
    364  1.1  jmmv 
    365  1.1  jmmv 		char val[128];
    366  1.1  jmmv 		ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_val",
    367  1.1  jmmv 		    &val, sizeof(val)));
    368  1.1  jmmv 		ATF_CHECK(strcmp(val, "1st string") == 0);
    369  1.1  jmmv 	}
    370  1.1  jmmv 	unload("k_helper", true);
    371  1.1  jmmv 
    372  1.1  jmmv 	printf("Loading module with a different string property\n");
    373  1.1  jmmv 	props = prop_dictionary_create();
    374  1.1  jmmv 	prop_dictionary_set(props, "prop_str",
    375  1.1  jmmv 	    prop_string_create_cstring("2nd string"));
    376  1.1  jmmv 	load(props, true, "%s/k_helper.o", atf_tc_get_config_var(tc, "srcdir"));
    377  1.1  jmmv 	prop_object_release(props);
    378  1.1  jmmv 	{
    379  1.1  jmmv 		int ok;
    380  1.1  jmmv 		ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_ok",
    381  1.1  jmmv 		    &ok, sizeof(ok)));
    382  1.1  jmmv 		ATF_CHECK(ok);
    383  1.1  jmmv 
    384  1.1  jmmv 		char val[128];
    385  1.1  jmmv 		ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_val",
    386  1.1  jmmv 		    &val, sizeof(val)));
    387  1.1  jmmv 		ATF_CHECK(strcmp(val, "2nd string") == 0);
    388  1.1  jmmv 	}
    389  1.1  jmmv 	unload("k_helper", true);
    390  1.1  jmmv }
    391  1.1  jmmv ATF_TC_CLEANUP(cmd_load_props, tc)
    392  1.1  jmmv {
    393  1.1  jmmv 	unload_cleanup("k_helper");
    394  1.1  jmmv }
    395  1.1  jmmv 
    396  1.1  jmmv ATF_TC_WITH_CLEANUP(cmd_stat);
    397  1.1  jmmv ATF_TC_HEAD(cmd_stat, tc)
    398  1.1  jmmv {
    399  1.1  jmmv 	atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_STAT command");
    400  1.1  jmmv 	atf_tc_set_md_var(tc, "require.user", "root");
    401  1.1  jmmv }
    402  1.1  jmmv ATF_TC_BODY(cmd_stat, tc)
    403  1.1  jmmv {
    404  1.1  jmmv 	require_modular();
    405  1.1  jmmv 
    406  1.1  jmmv 	ATF_CHECK(!k_helper_is_present(both_checks));
    407  1.1  jmmv 
    408  1.1  jmmv 	load(NULL, true, "%s/k_helper.o", atf_tc_get_config_var(tc, "srcdir"));
    409  1.1  jmmv 	ATF_CHECK(k_helper_is_present(both_checks));
    410  1.1  jmmv 	{
    411  1.1  jmmv 		modstat_t ms;
    412  1.1  jmmv 		ATF_CHECK(get_modstat_info("k_helper", &ms));
    413  1.1  jmmv 
    414  1.1  jmmv 		ATF_CHECK(ms.ms_class == MODULE_CLASS_MISC);
    415  1.1  jmmv 		ATF_CHECK(ms.ms_source == MODULE_SOURCE_FILESYS);
    416  1.1  jmmv 		ATF_CHECK(ms.ms_refcnt == 0);
    417  1.1  jmmv 	}
    418  1.1  jmmv 	unload("k_helper", true);
    419  1.1  jmmv 
    420  1.1  jmmv 	ATF_CHECK(!k_helper_is_present(both_checks));
    421  1.1  jmmv }
    422  1.1  jmmv ATF_TC_CLEANUP(cmd_stat, tc)
    423  1.1  jmmv {
    424  1.1  jmmv 	unload_cleanup("k_helper");
    425  1.1  jmmv }
    426  1.1  jmmv 
    427  1.1  jmmv ATF_TC_WITH_CLEANUP(cmd_unload);
    428  1.1  jmmv ATF_TC_HEAD(cmd_unload, tc)
    429  1.1  jmmv {
    430  1.1  jmmv 	atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_UNLOAD command");
    431  1.1  jmmv 	atf_tc_set_md_var(tc, "require.user", "root");
    432  1.1  jmmv }
    433  1.1  jmmv ATF_TC_BODY(cmd_unload, tc)
    434  1.1  jmmv {
    435  1.1  jmmv 	require_modular();
    436  1.1  jmmv 
    437  1.1  jmmv 	load(NULL, true, "%s/k_helper.o", atf_tc_get_config_var(tc, "srcdir"));
    438  1.1  jmmv 
    439  1.1  jmmv 	ATF_CHECK(unload("", false) == ENOENT);
    440  1.1  jmmv 	ATF_CHECK(unload("non-existent.o", false) == ENOENT);
    441  1.1  jmmv 	ATF_CHECK(unload("k_helper.o", false) == ENOENT);
    442  1.1  jmmv 
    443  1.1  jmmv 	ATF_CHECK(k_helper_is_present(stat_check));
    444  1.1  jmmv 	unload("k_helper", true);
    445  1.1  jmmv 	printf("Checking if unload was successful\n");
    446  1.1  jmmv 	ATF_CHECK(!k_helper_is_present(stat_check));
    447  1.1  jmmv }
    448  1.1  jmmv ATF_TC_CLEANUP(cmd_unload, tc)
    449  1.1  jmmv {
    450  1.1  jmmv 	unload_cleanup("k_helper");
    451  1.1  jmmv }
    452  1.1  jmmv 
    453  1.1  jmmv /* --------------------------------------------------------------------- */
    454  1.1  jmmv /* Main                                                                  */
    455  1.1  jmmv /* --------------------------------------------------------------------- */
    456  1.1  jmmv 
    457  1.1  jmmv ATF_TP_ADD_TCS(tp)
    458  1.1  jmmv {
    459  1.1  jmmv 	have_modular = check_modular();
    460  1.1  jmmv 
    461  1.1  jmmv 	ATF_TP_ADD_TC(tp, cmd_load);
    462  1.1  jmmv 	ATF_TP_ADD_TC(tp, cmd_load_props);
    463  1.1  jmmv 	ATF_TP_ADD_TC(tp, cmd_stat);
    464  1.1  jmmv 	ATF_TP_ADD_TC(tp, cmd_unload);
    465  1.1  jmmv 
    466  1.1  jmmv 	return atf_no_error();
    467  1.1  jmmv }
    468