2019-01-27 05:08:33 +03:00
|
|
|
/* $NetBSD: t_modctl.c,v 1.13 2019/01/27 02:08:50 pgoyette Exp $ */
|
2008-05-01 19:38:17 +04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008 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.
|
|
|
|
*/
|
|
|
|
|
2008-02-10 15:40:10 +03:00
|
|
|
#include <sys/cdefs.h>
|
2019-01-27 05:08:33 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: t_modctl.c,v 1.13 2019/01/27 02:08:50 pgoyette Exp $");
|
2008-02-10 15:40:10 +03:00
|
|
|
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/sysctl.h>
|
2008-03-02 14:22:10 +03:00
|
|
|
|
2008-05-01 19:38:17 +04:00
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2008-02-10 15:40:10 +03:00
|
|
|
|
2008-05-01 19:38:17 +04:00
|
|
|
#include <prop/proplib.h>
|
2008-02-10 15:40:10 +03:00
|
|
|
|
2008-05-01 19:38:17 +04:00
|
|
|
#include <atf-c.h>
|
2008-02-10 15:40:10 +03:00
|
|
|
|
2008-02-10 19:02:24 +03:00
|
|
|
enum presence_check { both_checks, stat_check, sysctl_check };
|
|
|
|
|
2012-08-13 12:07:03 +04:00
|
|
|
static void check_permission(void);
|
2012-03-13 09:56:46 +04:00
|
|
|
static bool get_modstat_info(const char *, modstat_t *);
|
|
|
|
static bool get_sysctl(const char *, void *buf, const size_t);
|
|
|
|
static bool k_helper_is_present_stat(void);
|
|
|
|
static bool k_helper_is_present_sysctl(void);
|
|
|
|
static bool k_helper_is_present(enum presence_check);
|
|
|
|
static int load(prop_dictionary_t, bool, const char *, ...);
|
|
|
|
static int unload(const char *, bool);
|
|
|
|
static void unload_cleanup(const char *);
|
|
|
|
|
2008-02-10 15:40:10 +03:00
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
/* Auxiliary functions */
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
2012-08-13 12:07:03 +04:00
|
|
|
* A function checking wether we are allowed to load modules currently
|
|
|
|
* (either the kernel is not modular, or securelevel may prevent it)
|
2008-02-10 15:40:10 +03:00
|
|
|
*/
|
2012-08-13 12:07:03 +04:00
|
|
|
static void
|
|
|
|
check_permission(void)
|
2008-02-10 15:40:10 +03:00
|
|
|
{
|
2012-08-13 12:07:03 +04:00
|
|
|
int err;
|
|
|
|
|
|
|
|
err = modctl(MODCTL_EXISTS, 0);
|
2012-08-20 12:07:52 +04:00
|
|
|
if (err == 0) return;
|
|
|
|
if (errno == ENOSYS)
|
2012-08-13 12:07:03 +04:00
|
|
|
atf_tc_skip("Kernel does not have 'options MODULAR'.");
|
2012-08-20 12:07:52 +04:00
|
|
|
else if (errno == EPERM)
|
2012-08-13 12:07:03 +04:00
|
|
|
atf_tc_skip("Module loading administratively forbidden");
|
2012-08-20 12:07:52 +04:00
|
|
|
ATF_REQUIRE_EQ_MSG(errno, 0, "unexpected error %d from "
|
|
|
|
"modctl(MODCTL_EXISTS, 0)", errno);
|
2008-02-10 15:40:10 +03:00
|
|
|
}
|
|
|
|
|
2012-03-13 09:56:46 +04:00
|
|
|
static bool
|
2008-02-10 19:02:24 +03:00
|
|
|
get_modstat_info(const char *name, modstat_t *msdest)
|
|
|
|
{
|
|
|
|
bool found;
|
|
|
|
size_t len;
|
2019-01-27 05:08:33 +03:00
|
|
|
int count;
|
2008-02-10 19:02:24 +03:00
|
|
|
struct iovec iov;
|
|
|
|
modstat_t *ms;
|
|
|
|
|
2012-08-13 12:07:03 +04:00
|
|
|
check_permission();
|
2019-01-27 05:08:33 +03:00
|
|
|
for (len = 8192; ;) {
|
2008-05-01 19:38:17 +04:00
|
|
|
iov.iov_base = malloc(len);
|
2008-02-10 19:02:24 +03:00
|
|
|
iov.iov_len = len;
|
2012-03-13 09:56:46 +04:00
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
|
2008-05-01 19:38:17 +04:00
|
|
|
if (modctl(MODCTL_STAT, &iov) != 0) {
|
2008-02-10 19:02:24 +03:00
|
|
|
int err = errno;
|
2008-05-01 19:38:17 +04:00
|
|
|
fprintf(stderr, "modctl(MODCTL_STAT) failed: %s\n",
|
|
|
|
strerror(err));
|
|
|
|
atf_tc_fail("Failed to query module status");
|
2008-02-10 19:02:24 +03:00
|
|
|
}
|
|
|
|
if (len >= iov.iov_len)
|
|
|
|
break;
|
2008-05-01 19:38:17 +04:00
|
|
|
free(iov.iov_base);
|
2008-02-10 19:02:24 +03:00
|
|
|
len = iov.iov_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
found = false;
|
2019-01-27 05:08:33 +03:00
|
|
|
count = *(int *)iov.iov_base;
|
|
|
|
ms = (modstat_t *)((char *)iov.iov_base + sizeof(int));
|
|
|
|
while ( count ) {
|
2008-05-01 19:38:17 +04:00
|
|
|
if (strcmp(ms->ms_name, name) == 0) {
|
2008-02-10 19:02:24 +03:00
|
|
|
if (msdest != NULL)
|
|
|
|
*msdest = *ms;
|
|
|
|
found = true;
|
2019-01-27 05:08:33 +03:00
|
|
|
break;
|
2008-02-10 19:02:24 +03:00
|
|
|
}
|
2019-01-27 05:08:33 +03:00
|
|
|
ms++;
|
|
|
|
count--;
|
2008-02-10 19:02:24 +03:00
|
|
|
}
|
|
|
|
|
2008-05-01 19:38:17 +04:00
|
|
|
free(iov.iov_base);
|
2008-02-10 19:02:24 +03:00
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2008-03-02 14:22:10 +03:00
|
|
|
/*
|
|
|
|
* Queries a sysctl property.
|
|
|
|
*/
|
2012-03-13 09:56:46 +04:00
|
|
|
static bool
|
2008-05-01 19:38:17 +04:00
|
|
|
get_sysctl(const char *name, void *buf, const size_t len)
|
2008-03-02 14:22:10 +03:00
|
|
|
{
|
|
|
|
size_t len2 = len;
|
2008-05-01 19:38:17 +04:00
|
|
|
printf("Querying sysctl variable: %s\n", name);
|
|
|
|
int ret = sysctlbyname(name, buf, &len2, NULL, 0);
|
2008-03-02 14:22:10 +03:00
|
|
|
if (ret == -1 && errno != ENOENT) {
|
2008-05-01 19:38:17 +04:00
|
|
|
fprintf(stderr, "sysctlbyname(2) failed: %s\n",
|
|
|
|
strerror(errno));
|
|
|
|
atf_tc_fail("Failed to query %s", name);
|
2008-03-02 14:22:10 +03:00
|
|
|
}
|
|
|
|
return ret != -1;
|
|
|
|
}
|
|
|
|
|
2008-02-10 15:40:10 +03:00
|
|
|
/*
|
|
|
|
* Returns a boolean indicating if the k_helper module was loaded
|
2008-02-10 19:02:24 +03:00
|
|
|
* successfully. This implementation uses modctl(2)'s MODCTL_STAT
|
|
|
|
* subcommand to do the check.
|
2008-02-10 15:40:10 +03:00
|
|
|
*/
|
2012-03-13 09:56:46 +04:00
|
|
|
static bool
|
2008-02-10 19:02:24 +03:00
|
|
|
k_helper_is_present_stat(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
return get_modstat_info("k_helper", NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns a boolean indicating if the k_helper module was loaded
|
|
|
|
* successfully. This implementation uses the module's sysctl
|
|
|
|
* installed node to do the check.
|
|
|
|
*/
|
2012-03-13 09:56:46 +04:00
|
|
|
static bool
|
2008-02-10 19:02:24 +03:00
|
|
|
k_helper_is_present_sysctl(void)
|
2008-02-10 15:40:10 +03:00
|
|
|
{
|
2008-03-02 14:22:10 +03:00
|
|
|
size_t present;
|
2008-02-10 15:40:10 +03:00
|
|
|
|
2008-03-02 14:22:10 +03:00
|
|
|
return get_sysctl("vendor.k_helper.present", &present,
|
2008-05-01 19:38:17 +04:00
|
|
|
sizeof(present));
|
2008-02-10 15:40:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2008-02-10 19:02:24 +03:00
|
|
|
* Returns a boolean indicating if the k_helper module was loaded
|
|
|
|
* successfully. The 'how' parameter specifies the implementation to
|
|
|
|
* use to do the check.
|
2008-02-10 15:40:10 +03:00
|
|
|
*/
|
2012-03-13 09:56:46 +04:00
|
|
|
static bool
|
2008-05-01 19:38:17 +04:00
|
|
|
k_helper_is_present(enum presence_check how)
|
2008-02-10 15:40:10 +03:00
|
|
|
{
|
2008-02-10 19:02:24 +03:00
|
|
|
bool found;
|
|
|
|
|
|
|
|
switch (how) {
|
|
|
|
case both_checks:
|
|
|
|
found = k_helper_is_present_stat();
|
|
|
|
ATF_CHECK(k_helper_is_present_sysctl() == found);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case stat_check:
|
|
|
|
found = k_helper_is_present_stat();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sysctl_check:
|
|
|
|
found = k_helper_is_present_sysctl();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2010-11-03 19:10:19 +03:00
|
|
|
found = false;
|
|
|
|
assert(found);
|
2008-02-10 19:02:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Loads the specified module from a file. If fatal is set and an error
|
|
|
|
* occurs when loading the module, an error message is printed and the
|
|
|
|
* test case is aborted.
|
|
|
|
*/
|
2012-03-15 06:02:20 +04:00
|
|
|
static __printflike(3, 4) int
|
2008-05-01 19:38:17 +04:00
|
|
|
load(prop_dictionary_t props, bool fatal, const char *fmt, ...)
|
2008-02-10 19:02:24 +03:00
|
|
|
{
|
|
|
|
int err;
|
2008-05-01 19:38:17 +04:00
|
|
|
va_list ap;
|
|
|
|
char filename[MAXPATHLEN], *propsstr;
|
2008-03-02 14:22:10 +03:00
|
|
|
modctl_load_t ml;
|
|
|
|
|
2012-08-13 12:07:03 +04:00
|
|
|
check_permission();
|
2008-03-02 14:22:10 +03:00
|
|
|
if (props == NULL) {
|
|
|
|
props = prop_dictionary_create();
|
|
|
|
propsstr = prop_dictionary_externalize(props);
|
|
|
|
ATF_CHECK(propsstr != NULL);
|
|
|
|
prop_object_release(props);
|
|
|
|
} else {
|
|
|
|
propsstr = prop_dictionary_externalize(props);
|
|
|
|
ATF_CHECK(propsstr != NULL);
|
|
|
|
}
|
|
|
|
|
2008-05-01 19:38:17 +04:00
|
|
|
va_start(ap, fmt);
|
|
|
|
vsnprintf(filename, sizeof(filename), fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
ml.ml_filename = filename;
|
2008-03-02 14:22:10 +03:00
|
|
|
ml.ml_flags = 0;
|
|
|
|
ml.ml_props = propsstr;
|
|
|
|
ml.ml_propslen = strlen(propsstr);
|
2008-02-10 15:40:10 +03:00
|
|
|
|
2008-05-01 19:38:17 +04:00
|
|
|
printf("Loading module %s\n", filename);
|
2012-03-13 09:56:46 +04:00
|
|
|
errno = err = 0;
|
|
|
|
|
2008-05-01 19:38:17 +04:00
|
|
|
if (modctl(MODCTL_LOAD, &ml) == -1) {
|
2008-02-10 19:02:24 +03:00
|
|
|
err = errno;
|
2008-05-01 19:38:17 +04:00
|
|
|
fprintf(stderr, "modctl(MODCTL_LOAD, %s), failed: %s\n",
|
|
|
|
filename, strerror(err));
|
2008-02-10 19:02:24 +03:00
|
|
|
if (fatal)
|
2008-05-01 19:38:17 +04:00
|
|
|
atf_tc_fail("Module load failed");
|
2008-02-10 15:40:10 +03:00
|
|
|
}
|
2008-03-02 14:22:10 +03:00
|
|
|
|
2008-05-01 19:38:17 +04:00
|
|
|
free(propsstr);
|
2008-03-02 14:22:10 +03:00
|
|
|
|
2008-02-10 19:02:24 +03:00
|
|
|
return err;
|
2008-02-10 15:40:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unloads the specified module. If silent is true, nothing will be
|
|
|
|
* printed and no errors will be raised if the unload was unsuccessful.
|
|
|
|
*/
|
2012-03-13 09:56:46 +04:00
|
|
|
static int
|
2008-05-01 19:38:17 +04:00
|
|
|
unload(const char *name, bool fatal)
|
2008-02-10 15:40:10 +03:00
|
|
|
{
|
2008-02-10 19:02:24 +03:00
|
|
|
int err;
|
2008-02-10 15:40:10 +03:00
|
|
|
|
2012-08-13 12:07:03 +04:00
|
|
|
check_permission();
|
2008-05-01 19:38:17 +04:00
|
|
|
printf("Unloading module %s\n", name);
|
2012-03-13 09:56:46 +04:00
|
|
|
errno = err = 0;
|
|
|
|
|
2008-05-01 19:38:17 +04:00
|
|
|
if (modctl(MODCTL_UNLOAD, __UNCONST(name)) == -1) {
|
2008-02-10 19:02:24 +03:00
|
|
|
err = errno;
|
2008-05-01 19:38:17 +04:00
|
|
|
fprintf(stderr, "modctl(MODCTL_UNLOAD, %s) failed: %s\n",
|
|
|
|
name, strerror(err));
|
2008-02-10 19:02:24 +03:00
|
|
|
if (fatal)
|
2008-05-01 19:38:17 +04:00
|
|
|
atf_tc_fail("Module unload failed");
|
2008-02-10 15:40:10 +03:00
|
|
|
}
|
2008-02-10 19:02:24 +03:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* A silent version of unload, to be called as part of the cleanup
|
|
|
|
* process only.
|
|
|
|
*/
|
2012-03-13 09:56:46 +04:00
|
|
|
static void
|
2008-02-10 19:02:24 +03:00
|
|
|
unload_cleanup(const char *name)
|
|
|
|
{
|
|
|
|
|
2008-05-01 19:38:17 +04:00
|
|
|
(void)modctl(MODCTL_UNLOAD, __UNCONST(name));
|
2008-02-10 15:40:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
/* Test cases */
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
2008-05-01 19:38:17 +04:00
|
|
|
ATF_TC_WITH_CLEANUP(cmd_load);
|
|
|
|
ATF_TC_HEAD(cmd_load, tc)
|
2008-02-10 15:40:10 +03:00
|
|
|
{
|
2008-05-01 19:38:17 +04:00
|
|
|
atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_LOAD command");
|
|
|
|
atf_tc_set_md_var(tc, "require.user", "root");
|
2008-02-10 15:40:10 +03:00
|
|
|
}
|
2008-05-01 19:38:17 +04:00
|
|
|
ATF_TC_BODY(cmd_load, tc)
|
2008-02-10 15:40:10 +03:00
|
|
|
{
|
2008-05-01 19:38:17 +04:00
|
|
|
char longname[MAXPATHLEN];
|
|
|
|
size_t i;
|
|
|
|
|
2012-04-17 10:23:52 +04:00
|
|
|
ATF_CHECK(load(NULL, false, " ") == ENOENT);
|
2008-05-01 19:38:17 +04:00
|
|
|
ATF_CHECK(load(NULL, false, "non-existent.o") == ENOENT);
|
2008-02-10 19:02:24 +03:00
|
|
|
|
2008-05-01 19:38:17 +04:00
|
|
|
for (i = 0; i < MAXPATHLEN - 1; i++)
|
|
|
|
longname[i] = 'a';
|
|
|
|
longname[MAXPATHLEN - 1] = '\0';
|
2012-03-15 06:02:20 +04:00
|
|
|
ATF_CHECK(load(NULL, false, "%s", longname) == ENAMETOOLONG);
|
2008-02-10 15:40:10 +03:00
|
|
|
|
2008-02-10 19:02:24 +03:00
|
|
|
ATF_CHECK(!k_helper_is_present(stat_check));
|
2009-01-04 20:56:57 +03:00
|
|
|
load(NULL, true, "%s/k_helper/k_helper.kmod",
|
|
|
|
atf_tc_get_config_var(tc, "srcdir"));
|
2008-05-01 19:38:17 +04:00
|
|
|
printf("Checking if load was successful\n");
|
2008-02-10 19:02:24 +03:00
|
|
|
ATF_CHECK(k_helper_is_present(stat_check));
|
|
|
|
}
|
2008-05-01 19:38:17 +04:00
|
|
|
ATF_TC_CLEANUP(cmd_load, tc)
|
2008-02-10 19:02:24 +03:00
|
|
|
{
|
|
|
|
unload_cleanup("k_helper");
|
|
|
|
}
|
|
|
|
|
2008-05-01 19:38:17 +04:00
|
|
|
ATF_TC_WITH_CLEANUP(cmd_load_props);
|
|
|
|
ATF_TC_HEAD(cmd_load_props, tc)
|
2008-03-02 14:22:10 +03:00
|
|
|
{
|
2008-05-01 19:38:17 +04:00
|
|
|
atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_LOAD command, "
|
|
|
|
"providing extra load-time properties");
|
|
|
|
atf_tc_set_md_var(tc, "require.user", "root");
|
2008-03-02 14:22:10 +03:00
|
|
|
}
|
2008-05-01 19:38:17 +04:00
|
|
|
ATF_TC_BODY(cmd_load_props, tc)
|
2008-03-02 14:22:10 +03:00
|
|
|
{
|
|
|
|
prop_dictionary_t props;
|
|
|
|
|
2008-05-01 19:38:17 +04:00
|
|
|
printf("Loading module without properties\n");
|
2008-03-02 14:22:10 +03:00
|
|
|
props = prop_dictionary_create();
|
2009-01-04 20:56:57 +03:00
|
|
|
load(props, true, "%s/k_helper/k_helper.kmod",
|
|
|
|
atf_tc_get_config_var(tc, "srcdir"));
|
2008-03-02 14:22:10 +03:00
|
|
|
prop_object_release(props);
|
|
|
|
{
|
|
|
|
int ok;
|
|
|
|
ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_ok",
|
2008-05-01 19:38:17 +04:00
|
|
|
&ok, sizeof(ok)));
|
2008-03-02 14:22:10 +03:00
|
|
|
ATF_CHECK(!ok);
|
|
|
|
}
|
2008-05-01 19:38:17 +04:00
|
|
|
unload("k_helper", true);
|
2008-03-02 14:22:10 +03:00
|
|
|
|
2008-05-01 19:38:17 +04:00
|
|
|
printf("Loading module with a string property\n");
|
2008-03-02 14:22:10 +03:00
|
|
|
props = prop_dictionary_create();
|
|
|
|
prop_dictionary_set(props, "prop_str",
|
2008-05-01 19:38:17 +04:00
|
|
|
prop_string_create_cstring("1st string"));
|
2009-01-04 20:56:57 +03:00
|
|
|
load(props, true, "%s/k_helper/k_helper.kmod",
|
|
|
|
atf_tc_get_config_var(tc, "srcdir"));
|
2008-03-02 14:22:10 +03:00
|
|
|
prop_object_release(props);
|
|
|
|
{
|
|
|
|
int ok;
|
|
|
|
ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_ok",
|
2008-05-01 19:38:17 +04:00
|
|
|
&ok, sizeof(ok)));
|
2008-03-02 14:22:10 +03:00
|
|
|
ATF_CHECK(ok);
|
|
|
|
|
|
|
|
char val[128];
|
|
|
|
ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_val",
|
2008-05-01 19:38:17 +04:00
|
|
|
&val, sizeof(val)));
|
|
|
|
ATF_CHECK(strcmp(val, "1st string") == 0);
|
2008-03-02 14:22:10 +03:00
|
|
|
}
|
2008-05-01 19:38:17 +04:00
|
|
|
unload("k_helper", true);
|
2008-03-02 14:22:10 +03:00
|
|
|
|
2008-05-01 19:38:17 +04:00
|
|
|
printf("Loading module with a different string property\n");
|
2008-03-02 14:22:10 +03:00
|
|
|
props = prop_dictionary_create();
|
|
|
|
prop_dictionary_set(props, "prop_str",
|
2008-05-01 19:38:17 +04:00
|
|
|
prop_string_create_cstring("2nd string"));
|
2009-01-04 20:56:57 +03:00
|
|
|
load(props, true, "%s/k_helper/k_helper.kmod",
|
|
|
|
atf_tc_get_config_var(tc, "srcdir"));
|
2008-03-02 14:22:10 +03:00
|
|
|
prop_object_release(props);
|
|
|
|
{
|
|
|
|
int ok;
|
|
|
|
ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_ok",
|
2008-05-01 19:38:17 +04:00
|
|
|
&ok, sizeof(ok)));
|
2008-03-02 14:22:10 +03:00
|
|
|
ATF_CHECK(ok);
|
|
|
|
|
|
|
|
char val[128];
|
|
|
|
ATF_CHECK(get_sysctl("vendor.k_helper.prop_str_val",
|
2008-05-01 19:38:17 +04:00
|
|
|
&val, sizeof(val)));
|
|
|
|
ATF_CHECK(strcmp(val, "2nd string") == 0);
|
2008-03-02 14:22:10 +03:00
|
|
|
}
|
2008-05-01 19:38:17 +04:00
|
|
|
unload("k_helper", true);
|
2008-03-02 14:22:10 +03:00
|
|
|
}
|
2008-05-01 19:38:17 +04:00
|
|
|
ATF_TC_CLEANUP(cmd_load_props, tc)
|
2008-03-02 14:22:10 +03:00
|
|
|
{
|
|
|
|
unload_cleanup("k_helper");
|
|
|
|
}
|
|
|
|
|
2010-08-21 17:21:48 +04:00
|
|
|
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];
|
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2008-05-01 19:38:17 +04:00
|
|
|
ATF_TC_WITH_CLEANUP(cmd_stat);
|
|
|
|
ATF_TC_HEAD(cmd_stat, tc)
|
2008-02-10 19:02:24 +03:00
|
|
|
{
|
2008-05-01 19:38:17 +04:00
|
|
|
atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_STAT command");
|
|
|
|
atf_tc_set_md_var(tc, "require.user", "root");
|
2008-02-10 19:02:24 +03:00
|
|
|
}
|
2008-05-01 19:38:17 +04:00
|
|
|
ATF_TC_BODY(cmd_stat, tc)
|
2008-02-10 19:02:24 +03:00
|
|
|
{
|
|
|
|
ATF_CHECK(!k_helper_is_present(both_checks));
|
|
|
|
|
2009-01-04 20:56:57 +03:00
|
|
|
load(NULL, true, "%s/k_helper/k_helper.kmod",
|
|
|
|
atf_tc_get_config_var(tc, "srcdir"));
|
2008-02-10 19:02:24 +03:00
|
|
|
ATF_CHECK(k_helper_is_present(both_checks));
|
|
|
|
{
|
|
|
|
modstat_t ms;
|
|
|
|
ATF_CHECK(get_modstat_info("k_helper", &ms));
|
2008-02-10 15:40:10 +03:00
|
|
|
|
2008-02-10 19:02:24 +03:00
|
|
|
ATF_CHECK(ms.ms_class == MODULE_CLASS_MISC);
|
|
|
|
ATF_CHECK(ms.ms_source == MODULE_SOURCE_FILESYS);
|
|
|
|
ATF_CHECK(ms.ms_refcnt == 0);
|
|
|
|
}
|
2008-05-01 19:38:17 +04:00
|
|
|
unload("k_helper", true);
|
2008-02-10 15:40:10 +03:00
|
|
|
|
2008-02-10 19:02:24 +03:00
|
|
|
ATF_CHECK(!k_helper_is_present(both_checks));
|
|
|
|
}
|
2008-05-01 19:38:17 +04:00
|
|
|
ATF_TC_CLEANUP(cmd_stat, tc)
|
2008-02-10 19:02:24 +03:00
|
|
|
{
|
|
|
|
unload_cleanup("k_helper");
|
|
|
|
}
|
|
|
|
|
2008-05-01 19:38:17 +04:00
|
|
|
ATF_TC_WITH_CLEANUP(cmd_unload);
|
|
|
|
ATF_TC_HEAD(cmd_unload, tc)
|
2008-02-10 19:02:24 +03:00
|
|
|
{
|
2008-05-01 19:38:17 +04:00
|
|
|
atf_tc_set_md_var(tc, "descr", "Tests for the MODCTL_UNLOAD command");
|
|
|
|
atf_tc_set_md_var(tc, "require.user", "root");
|
2008-02-10 19:02:24 +03:00
|
|
|
}
|
2008-05-01 19:38:17 +04:00
|
|
|
ATF_TC_BODY(cmd_unload, tc)
|
2008-02-10 19:02:24 +03:00
|
|
|
{
|
2009-01-04 20:56:57 +03:00
|
|
|
load(NULL, true, "%s/k_helper/k_helper.kmod",
|
|
|
|
atf_tc_get_config_var(tc, "srcdir"));
|
2008-02-10 19:02:24 +03:00
|
|
|
|
|
|
|
ATF_CHECK(unload("", false) == ENOENT);
|
2008-05-02 18:20:50 +04:00
|
|
|
ATF_CHECK(unload("non-existent.kmod", false) == ENOENT);
|
|
|
|
ATF_CHECK(unload("k_helper.kmod", false) == ENOENT);
|
2008-02-10 19:02:24 +03:00
|
|
|
|
|
|
|
ATF_CHECK(k_helper_is_present(stat_check));
|
2008-05-01 19:38:17 +04:00
|
|
|
unload("k_helper", true);
|
|
|
|
printf("Checking if unload was successful\n");
|
2008-02-10 19:02:24 +03:00
|
|
|
ATF_CHECK(!k_helper_is_present(stat_check));
|
2008-02-10 15:40:10 +03:00
|
|
|
}
|
2008-05-01 19:38:17 +04:00
|
|
|
ATF_TC_CLEANUP(cmd_unload, tc)
|
2008-02-10 15:40:10 +03:00
|
|
|
{
|
2008-02-10 19:02:24 +03:00
|
|
|
unload_cleanup("k_helper");
|
2008-02-10 15:40:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
/* Main */
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
2008-05-01 19:38:17 +04:00
|
|
|
ATF_TP_ADD_TCS(tp)
|
2008-02-10 15:40:10 +03:00
|
|
|
{
|
|
|
|
|
2008-05-01 19:38:17 +04:00
|
|
|
ATF_TP_ADD_TC(tp, cmd_load);
|
|
|
|
ATF_TP_ADD_TC(tp, cmd_load_props);
|
|
|
|
ATF_TP_ADD_TC(tp, cmd_stat);
|
2010-08-21 17:21:48 +04:00
|
|
|
ATF_TP_ADD_TC(tp, cmd_load_recurse);
|
2008-05-01 19:38:17 +04:00
|
|
|
ATF_TP_ADD_TC(tp, cmd_unload);
|
|
|
|
|
|
|
|
return atf_no_error();
|
2008-02-10 15:40:10 +03:00
|
|
|
}
|