From: Gongjun Song Date: Fri, 7 Mar 2025 15:03:18 +0000 (+0800) Subject: Added the test case of using multiple softdep for a module X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b73b52004ec52f7f4d4786f57336bed2761be06e;p=thirdparty%2Fkmod.git Added the test case of using multiple softdep for a module We defined two modules mod-softdep-a and mod-softdep-b. The softdep statements are split into two separate modprobe configure files. The unit test case is supposed to fail, since the libkmod will take only the first softdep statement based on the current implementation. Co-developed-by: Dan He Signed-off-by: Dan He Co-developed-by: Gongjun Song Signed-off-by: Gongjun Song Signed-off-by: Yuchi Chen Signed-off-by: Wenjie Wang Signed-off-by: Qingqing Li Link: https://github.com/kmod-project/kmod/pull/311 Signed-off-by: Lucas De Marchi --- diff --git a/scripts/setup-rootfs.sh b/scripts/setup-rootfs.sh index cbf94bc9..4bfbcf33 100755 --- a/scripts/setup-rootfs.sh +++ b/scripts/setup-rootfs.sh @@ -115,6 +115,11 @@ map=( ["test-weakdep$MODULE_DIRECTORY/4.4.4/kernel/mod-loop-b.ko"]="mod-loop-b.ko" ["test-weakdep$MODULE_DIRECTORY/4.4.4/kernel/mod-simple.ko"]="mod-simple.ko" ["test-weakdep$MODULE_DIRECTORY/4.4.4/kernel/mod-weakdep.ko"]="mod-weakdep.ko" + ["test-multi-softdep$MODULE_DIRECTORY/4.4.4/kernel/mod-foo-a.ko"]="mod-foo-a.ko" + ["test-multi-softdep$MODULE_DIRECTORY/4.4.4/kernel/mod-foo-b.ko"]="mod-foo-b.ko" + ["test-multi-softdep$MODULE_DIRECTORY/4.4.4/kernel/mod-foo-c.ko"]="mod-foo-c.ko" + ["test-multi-softdep$MODULE_DIRECTORY/4.4.4/kernel/mod-softdep-a.ko"]="mod-softdep-a.ko" + ["test-multi-softdep$MODULE_DIRECTORY/4.4.4/kernel/mod-softdep-b.ko"]="mod-softdep-b.ko" ) gzip_array=( diff --git a/testsuite/meson.build b/testsuite/meson.build index a8b9a438..6bc9186f 100644 --- a/testsuite/meson.build +++ b/testsuite/meson.build @@ -90,6 +90,7 @@ _testsuite = [ 'test-loaded', 'test-modinfo', 'test-modprobe', + 'test-multi-softdep', 'test-new-module', 'test-remove', 'test-strbuf', diff --git a/testsuite/module-playground/Kbuild b/testsuite/module-playground/Kbuild index 5be441b1..b4f0f11e 100644 --- a/testsuite/module-playground/Kbuild +++ b/testsuite/module-playground/Kbuild @@ -36,6 +36,9 @@ obj-m += mod-fake-cciss.o obj-m += mod-weakdep.o +obj-m += mod-softdep-a.o +obj-m += mod-softdep-b.o + else # only build ARCH-specific module ifeq ($(ARCH),) diff --git a/testsuite/module-playground/mod-softdep-a.c b/testsuite/module-playground/mod-softdep-a.c new file mode 100644 index 00000000..90cb90a0 --- /dev/null +++ b/testsuite/module-playground/mod-softdep-a.c @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * Copyright © 2025 Intel Corporation + */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include + +#ifndef MODULE_SOFTDEP +#define MODULE_SOFTDEP(_softdep) MODULE_INFO(softdep, _softdep) +#endif + +static int __init softdep_init(void) +{ + return 0; +} +module_init(softdep_init); + +MODULE_AUTHOR("Dan He "); +MODULE_LICENSE("LGPL"); +MODULE_SOFTDEP("pre: mod-foo-a mod-foo-b post: mod-foo-c"); diff --git a/testsuite/module-playground/mod-softdep-b.c b/testsuite/module-playground/mod-softdep-b.c new file mode 100644 index 00000000..b9fb74df --- /dev/null +++ b/testsuite/module-playground/mod-softdep-b.c @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * Copyright © 2025 Intel Corporation + */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include + +#ifndef MODULE_SOFTDEP +#define MODULE_SOFTDEP(_softdep) MODULE_INFO(softdep, _softdep) +#endif + +static int __init softdep_init(void) +{ + return 0; +} +module_init(softdep_init); + +MODULE_AUTHOR("Dan He "); +MODULE_LICENSE("LGPL"); +MODULE_SOFTDEP("pre: mod-foo-a post: mod-foo-b mod-foo-c"); diff --git a/testsuite/rootfs-pristine/test-multi-softdep/etc/modprobe.d/dumb-softdep.conf b/testsuite/rootfs-pristine/test-multi-softdep/etc/modprobe.d/dumb-softdep.conf new file mode 100644 index 00000000..dc668704 --- /dev/null +++ b/testsuite/rootfs-pristine/test-multi-softdep/etc/modprobe.d/dumb-softdep.conf @@ -0,0 +1,4 @@ +softdep mod-softdep-a pre: mod-foo-a +softdep mod-softdep-a pre: mod-foo-b +softdep mod-softdep-a post: mod-foo-c +softdep mod-softdep-b pre: mod-foo-a diff --git a/testsuite/rootfs-pristine/test-multi-softdep/etc/modprobe.d/dumb-softdep2.conf b/testsuite/rootfs-pristine/test-multi-softdep/etc/modprobe.d/dumb-softdep2.conf new file mode 100644 index 00000000..a3ea7ea4 --- /dev/null +++ b/testsuite/rootfs-pristine/test-multi-softdep/etc/modprobe.d/dumb-softdep2.conf @@ -0,0 +1 @@ +softdep mod-softdep-b post: mod-foo-b mod-foo-c diff --git a/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.alias b/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.alias new file mode 100644 index 00000000..ba76e181 --- /dev/null +++ b/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.alias @@ -0,0 +1 @@ +# Aliases extracted from modules themselves. diff --git a/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.alias.bin b/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.alias.bin new file mode 100644 index 00000000..7075435f Binary files /dev/null and b/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.alias.bin differ diff --git a/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.builtin.alias.bin b/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.builtin.alias.bin new file mode 100644 index 00000000..e69de29b diff --git a/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.builtin.bin b/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.builtin.bin new file mode 100644 index 00000000..e69de29b diff --git a/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.dep b/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.dep new file mode 100644 index 00000000..4c5ea094 --- /dev/null +++ b/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.dep @@ -0,0 +1,5 @@ +kernel/mod-foo-b.ko: +kernel/mod-foo-c.ko: +kernel/mod-foo-a.ko: +kernel/mod-softdep-b.ko: +kernel/mod-softdep-a.ko: diff --git a/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.dep.bin b/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.dep.bin new file mode 100644 index 00000000..6a1c8f4e Binary files /dev/null and b/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.dep.bin differ diff --git a/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.devname b/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.devname new file mode 100644 index 00000000..e69de29b diff --git a/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.softdep b/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.softdep new file mode 100644 index 00000000..5554ccca --- /dev/null +++ b/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.softdep @@ -0,0 +1 @@ +# Soft dependencies extracted from modules themselves. diff --git a/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.symbols b/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.symbols new file mode 100644 index 00000000..ddb6ab6b --- /dev/null +++ b/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.symbols @@ -0,0 +1,4 @@ +# Aliases for symbols, used by symbol_request(). +alias symbol:print_fooA mod_foo_a +alias symbol:print_fooC mod_foo_c +alias symbol:print_fooB mod_foo_b diff --git a/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.symbols.bin b/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.symbols.bin new file mode 100644 index 00000000..1add6e50 Binary files /dev/null and b/testsuite/rootfs-pristine/test-multi-softdep/lib/modules/4.4.4/modules.symbols.bin differ diff --git a/testsuite/test-multi-softdep.c b/testsuite/test-multi-softdep.c new file mode 100644 index 00000000..6ec3b04b --- /dev/null +++ b/testsuite/test-multi-softdep.c @@ -0,0 +1,127 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * Copyright © 2025 Intel Corporation + */ +#include +#include +#include + +#include + +#include +#include "testsuite.h" + +#define MAX_SOFTDEP_N 3 + +static const struct { + const char *modname; + const char *pre[MAX_SOFTDEP_N]; + const char *post[MAX_SOFTDEP_N]; +} test_modules[] = { { .modname = "mod-softdep-a", + .pre = { "mod_foo_a", "mod_foo_b" }, + .post = { "mod_foo_c" } }, + { .modname = "mod-softdep-b", + .pre = { "mod_foo_a" }, + .post = { "mod_foo_b", "mod_foo_c" } } }; + +static int check_dependencies(const char *const *modnames, + const struct kmod_list *mod_list) +{ + const struct kmod_list *itr; + bool visited[MAX_SOFTDEP_N] = {}; + int mod_index; + bool all_loaded = true; + + kmod_list_foreach(itr, mod_list) { + struct kmod_module *softdep_mod = kmod_module_get_module(itr); + const char *softdep_name = kmod_module_get_name(softdep_mod); + printf(" %s", softdep_name); + + for (mod_index = 0; mod_index < MAX_SOFTDEP_N; mod_index++) { + if (!modnames[mod_index]) + break; + if (streq(softdep_name, modnames[mod_index])) + visited[mod_index] = true; + } + kmod_module_unref(softdep_mod); + } + printf("\n"); + + for (mod_index = 0; mod_index < MAX_SOFTDEP_N; mod_index++) { + if (!modnames[mod_index]) + break; + if (!visited[mod_index]) { + ERR("softdep %s not loaded\n", modnames[mod_index]); + all_loaded = false; + } + } + if (all_loaded) + return 0; + else + return -1; +} + +static int multi_softdep(const struct test *t) +{ + struct kmod_ctx *ctx = NULL; + struct kmod_module *mod = NULL; + struct kmod_list *pre = NULL, *post = NULL; + + const char *modname; + size_t mod_index; + int err; + + ctx = kmod_new(NULL, NULL); + if (ctx == NULL) + exit(EXIT_FAILURE); + + for (mod_index = 0; mod_index < ARRAY_SIZE(test_modules); mod_index++) { + modname = test_modules[mod_index].modname; + printf("module %s:\n", modname); + err = kmod_module_new_from_name(ctx, modname, &mod); + if (err < 0) + goto fail; + pre = NULL; + post = NULL; + err = kmod_module_get_softdeps(mod, &pre, &post); + if (err < 0) { + ERR("could not get softdeps of '%s': %s\n", modname, + strerror(-err)); + goto fail; + } + + printf("pre: "); + err = check_dependencies(test_modules[mod_index].pre, pre); + if (err < 0) + goto fail; + printf("post: "); + err = check_dependencies(test_modules[mod_index].post, post); + if (err < 0) + goto fail; + + kmod_module_unref_list(pre); + kmod_module_unref_list(post); + kmod_module_unref(mod); + } + kmod_unref(ctx); + return EXIT_SUCCESS; + +fail: + kmod_module_unref_list(pre); + kmod_module_unref_list(post); + kmod_module_unref(mod); + kmod_unref(ctx); + return EXIT_FAILURE; +} + +/* + * FIXME: This test indicates a bug in kmod. Once fixed, the expected_fail should be removed. + * See https://github.com/kmod-project/kmod/issues/33 for more details. + */ +DEFINE_TEST(multi_softdep, .description = "check if multiple softdep is supported", + .config = { + [TC_UNAME_R] = "4.4.4", + [TC_ROOTFS] = TESTSUITE_ROOTFS "test-multi-softdep/", + }, .expected_fail=true); + +TESTSUITE_MAIN();