2012-01-26 19:01:41 +00:00
|
|
|
/*
|
2013-01-16 13:27:21 +00:00
|
|
|
* Copyright (C) 2012-2013 ProFUSION embedded systems
|
2012-01-26 19:01:41 +00:00
|
|
|
*
|
2012-07-10 13:42:24 +01:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2012-01-26 19:01:41 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-07-10 13:42:24 +01:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
2012-01-26 19:01:41 +00:00
|
|
|
*
|
2012-07-10 13:42:24 +01:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2014-12-26 01:32:03 +00:00
|
|
|
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
2012-01-26 19:01:41 +00:00
|
|
|
*/
|
|
|
|
|
2014-10-03 05:41:42 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stddef.h>
|
2012-01-24 23:53:27 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2014-10-03 05:41:42 +01:00
|
|
|
|
2015-01-14 16:08:56 +00:00
|
|
|
#include <shared/macro.h>
|
|
|
|
|
2015-01-02 14:38:27 +00:00
|
|
|
#include <libkmod/libkmod.h>
|
2012-01-24 23:53:27 +00:00
|
|
|
|
|
|
|
#include "testsuite.h"
|
|
|
|
|
2020-03-10 05:00:29 +00:00
|
|
|
static noreturn int test_load_resources(const struct test *t)
|
|
|
|
{
|
|
|
|
struct kmod_ctx *ctx;
|
|
|
|
const char *null_config = NULL;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
ctx = kmod_new(NULL, &null_config);
|
|
|
|
if (ctx == NULL)
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
kmod_set_log_priority(ctx, 7);
|
|
|
|
|
|
|
|
err = kmod_load_resources(ctx);
|
|
|
|
if (err != 0) {
|
|
|
|
ERR("could not load libkmod resources: %s\n", strerror(-err));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
kmod_unref(ctx);
|
|
|
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
|
|
|
DEFINE_TEST(test_load_resources,
|
2020-12-18 16:02:09 +00:00
|
|
|
.description = "test if kmod_load_resources works (recent modprobe on kernel without modules.builtin.modinfo)",
|
2020-03-10 05:00:29 +00:00
|
|
|
.config = {
|
|
|
|
[TC_ROOTFS] = TESTSUITE_ROOTFS "test-init-load-resources/",
|
|
|
|
[TC_UNAME_R] = "5.6.0",
|
|
|
|
},
|
|
|
|
.need_spawn = true);
|
|
|
|
|
2020-12-18 16:02:09 +00:00
|
|
|
DEFINE_TEST(test_load_resources,
|
|
|
|
.description = "test if kmod_load_resources works with empty modules.builtin.aliases.bin (recent depmod on kernel without modules.builtin.modinfo)",
|
|
|
|
.config = {
|
|
|
|
[TC_ROOTFS] = TESTSUITE_ROOTFS "test-init-load-resources-empty-builtin-aliases-bin/",
|
|
|
|
[TC_UNAME_R] = "5.6.0",
|
|
|
|
},
|
|
|
|
.need_spawn = true);
|
2020-03-10 05:00:29 +00:00
|
|
|
|
2013-12-17 21:10:16 +00:00
|
|
|
static noreturn int test_initlib(const struct test *t)
|
2012-01-24 23:53:27 +00:00
|
|
|
{
|
|
|
|
struct kmod_ctx *ctx;
|
|
|
|
const char *null_config = NULL;
|
|
|
|
|
|
|
|
ctx = kmod_new(NULL, &null_config);
|
|
|
|
if (ctx == NULL)
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
|
|
|
kmod_unref(ctx);
|
|
|
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
2014-10-09 17:00:30 +01:00
|
|
|
DEFINE_TEST(test_initlib,
|
2012-02-07 12:46:46 +00:00
|
|
|
.description = "test if libkmod's init function work");
|
2012-01-26 04:09:28 +00:00
|
|
|
|
2013-12-17 21:10:16 +00:00
|
|
|
static noreturn int test_insert(const struct test *t)
|
2012-01-26 04:09:28 +00:00
|
|
|
{
|
|
|
|
struct kmod_ctx *ctx;
|
|
|
|
struct kmod_module *mod;
|
|
|
|
const char *null_config = NULL;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
ctx = kmod_new(NULL, &null_config);
|
|
|
|
if (ctx == NULL)
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
2015-02-03 07:17:10 +00:00
|
|
|
err = kmod_module_new_from_path(ctx, "/mod-simple.ko", &mod);
|
2012-01-26 04:09:28 +00:00
|
|
|
if (err != 0) {
|
|
|
|
ERR("could not create module from path: %m\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
err = kmod_module_insert_module(mod, 0, NULL);
|
|
|
|
if (err != 0) {
|
|
|
|
ERR("could not insert module: %m\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
kmod_unref(ctx);
|
|
|
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
2014-10-09 17:00:30 +01:00
|
|
|
DEFINE_TEST(test_insert,
|
2012-01-26 04:09:28 +00:00
|
|
|
.description = "test if libkmod's insert_module returns ok",
|
|
|
|
.config = {
|
2012-05-25 04:24:58 +01:00
|
|
|
[TC_ROOTFS] = TESTSUITE_ROOTFS "test-init/",
|
2012-01-26 04:09:28 +00:00
|
|
|
[TC_INIT_MODULE_RETCODES] = "bla:1:20",
|
|
|
|
},
|
2015-02-03 07:17:10 +00:00
|
|
|
.modules_loaded = "mod_simple",
|
2012-02-07 12:46:46 +00:00
|
|
|
.need_spawn = true);
|
2012-01-24 23:53:27 +00:00
|
|
|
|
2013-12-17 21:10:16 +00:00
|
|
|
static noreturn int test_remove(const struct test *t)
|
2012-01-26 18:10:41 +00:00
|
|
|
{
|
|
|
|
struct kmod_ctx *ctx;
|
2015-02-03 07:17:10 +00:00
|
|
|
struct kmod_module *mod_simple, *mod_bla;
|
2012-01-26 18:10:41 +00:00
|
|
|
const char *null_config = NULL;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
ctx = kmod_new(NULL, &null_config);
|
|
|
|
if (ctx == NULL)
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
|
2015-02-03 07:17:10 +00:00
|
|
|
err = kmod_module_new_from_name(ctx, "mod-simple", &mod_simple);
|
2015-01-14 16:08:56 +00:00
|
|
|
if (err != 0) {
|
|
|
|
ERR("could not create module from name: %s\n", strerror(-err));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
err = kmod_module_new_from_name(ctx, "bla", &mod_bla);
|
2012-01-26 18:10:41 +00:00
|
|
|
if (err != 0) {
|
2015-01-14 16:08:56 +00:00
|
|
|
ERR("could not create module from name: %s\n", strerror(-err));
|
2012-01-26 18:10:41 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2015-02-03 07:17:10 +00:00
|
|
|
err = kmod_module_remove_module(mod_simple, 0);
|
2012-01-26 18:10:41 +00:00
|
|
|
if (err != 0) {
|
2015-01-14 16:08:56 +00:00
|
|
|
ERR("could not remove module: %s\n", strerror(-err));
|
2012-01-26 18:10:41 +00:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2015-01-14 16:08:56 +00:00
|
|
|
|
|
|
|
err = kmod_module_remove_module(mod_bla, 0);
|
|
|
|
if (err != -ENOENT) {
|
|
|
|
ERR("wrong return code for failure test: %d\n", err);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2012-01-26 18:10:41 +00:00
|
|
|
kmod_unref(ctx);
|
|
|
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
2014-10-09 17:00:30 +01:00
|
|
|
DEFINE_TEST(test_remove,
|
2012-01-26 18:10:41 +00:00
|
|
|
.description = "test if libkmod's remove_module returns ok",
|
|
|
|
.config = {
|
2012-05-25 04:24:58 +01:00
|
|
|
[TC_ROOTFS] = TESTSUITE_ROOTFS "test-remove/",
|
2015-01-14 16:08:56 +00:00
|
|
|
[TC_DELETE_MODULE_RETCODES] =
|
2015-02-03 07:17:10 +00:00
|
|
|
"mod-simple:0:0:bla:-1:" STRINGIFY(ENOENT),
|
2012-01-26 18:10:41 +00:00
|
|
|
},
|
2012-02-07 12:46:46 +00:00
|
|
|
.need_spawn = true);
|
2012-01-26 18:10:41 +00:00
|
|
|
|
2014-10-09 18:29:04 +01:00
|
|
|
TESTSUITE_MAIN();
|