-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
testsuite: add tests for weak dependencies
The following tests to verify weak dependencies have been implemented: 1) modprobe test to check that related weakdep modules are not loaded due to being a weakdep. 2) depmod test to check weakdep output. 3) user test to check that configuration files with weakdep are parsed correctly and related weakdep modules can be read correctly from user applications. Signed-off-by: Jose Ignacio Tornos Martinez <jtornosm@redhat.com> Link: https://lore.kernel.org/r/20240530070836.9438-1-jtornosm@redhat.com [ Minor whitespace issues and define MODULE_WEAKDEP if it's not defined already ] Signed-off-by: Lucas De Marchi <lucas.de.marchi@gmail.com>
- Loading branch information
1 parent
a0ed4f8
commit d06712b
Showing
36 changed files
with
309 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
|
||
#include <linux/init.h> | ||
#include <linux/module.h> | ||
|
||
#ifndef MODULE_WEAKDEP | ||
#define MODULE_WEAKDEP(_weakdep) MODULE_INFO(weakdep, _weakdep) | ||
#endif | ||
|
||
static int __init weakdep_init(void) | ||
{ | ||
return 0; | ||
} | ||
|
||
module_init(weakdep_init); | ||
|
||
MODULE_AUTHOR("Jose Ignacio Tornos Martinez <jtornosm@redhat.com>"); | ||
MODULE_LICENSE("LGPL"); | ||
MODULE_WEAKDEP("mod-simple"); |
2 changes: 2 additions & 0 deletions
2
...suite/rootfs-pristine/test-depmod/check-weakdep/lib/modules/4.4.4/correct-modules.weakdep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Weak dependencies extracted from modules themselves. | ||
weakdep mod_weakdep mod-simple |
1 change: 1 addition & 0 deletions
1
testsuite/rootfs-pristine/test-modprobe/weakdep-loop/etc/modprobe.d/dumb-weakdep.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
weakdep mod-loop-b mod-loop-a mod-simple |
1 change: 1 addition & 0 deletions
1
testsuite/rootfs-pristine/test-modprobe/weakdep-loop/lib/modules/4.4.4/modules.alias
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Aliases extracted from modules themselves. |
Binary file added
BIN
+12 Bytes
testsuite/rootfs-pristine/test-modprobe/weakdep-loop/lib/modules/4.4.4/modules.alias.bin
Binary file not shown.
Empty file.
Empty file.
3 changes: 3 additions & 0 deletions
3
testsuite/rootfs-pristine/test-modprobe/weakdep-loop/lib/modules/4.4.4/modules.dep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
kernel/mod-loop-b.ko: | ||
kernel/mod-loop-a.ko: | ||
kernel/mod-simple.ko: |
Binary file added
BIN
+188 Bytes
testsuite/rootfs-pristine/test-modprobe/weakdep-loop/lib/modules/4.4.4/modules.dep.bin
Binary file not shown.
1 change: 1 addition & 0 deletions
1
testsuite/rootfs-pristine/test-modprobe/weakdep-loop/lib/modules/4.4.4/modules.devname
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Device nodes to trigger on-demand module loading. |
1 change: 1 addition & 0 deletions
1
testsuite/rootfs-pristine/test-modprobe/weakdep-loop/lib/modules/4.4.4/modules.softdep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Soft dependencies extracted from modules themselves. |
3 changes: 3 additions & 0 deletions
3
testsuite/rootfs-pristine/test-modprobe/weakdep-loop/lib/modules/4.4.4/modules.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Aliases for symbols, used by symbol_request(). | ||
alias symbol:printB mod_loop_b | ||
alias symbol:printA mod_loop_a |
Binary file added
BIN
+78 Bytes
testsuite/rootfs-pristine/test-modprobe/weakdep-loop/lib/modules/4.4.4/modules.symbols.bin
Binary file not shown.
1 change: 1 addition & 0 deletions
1
testsuite/rootfs-pristine/test-modprobe/weakdep-loop/lib/modules/4.4.4/modules.weakdep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Weak dependencies extracted from modules themselves. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mod-loop-b: mod_loop_a mod_simple | ||
mod-weakdep: mod_simple |
1 change: 1 addition & 0 deletions
1
testsuite/rootfs-pristine/test-user/etc/modprobe.d/dumb-weakdep.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
weakdep mod-loop-b mod-loop-a mod-simple |
1 change: 1 addition & 0 deletions
1
testsuite/rootfs-pristine/test-user/lib/modules/4.4.4/modules.alias
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Aliases extracted from modules themselves. |
Binary file added
BIN
+12 Bytes
testsuite/rootfs-pristine/test-user/lib/modules/4.4.4/modules.alias.bin
Binary file not shown.
Empty file.
Empty file.
4 changes: 4 additions & 0 deletions
4
testsuite/rootfs-pristine/test-user/lib/modules/4.4.4/modules.dep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
kernel/mod-weakdep.ko: | ||
kernel/mod-simple.ko: | ||
kernel/mod-loop-b.ko: | ||
kernel/mod-loop-a.ko: kernel/mod-loop-b.ko |
Binary file added
BIN
+242 Bytes
testsuite/rootfs-pristine/test-user/lib/modules/4.4.4/modules.dep.bin
Binary file not shown.
Empty file.
1 change: 1 addition & 0 deletions
1
testsuite/rootfs-pristine/test-user/lib/modules/4.4.4/modules.softdep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Soft dependencies extracted from modules themselves. |
3 changes: 3 additions & 0 deletions
3
testsuite/rootfs-pristine/test-user/lib/modules/4.4.4/modules.symbols
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Aliases for symbols, used by symbol_request(). | ||
alias symbol:printB mod_loop_b | ||
alias symbol:printA mod_loop_a |
Binary file added
BIN
+78 Bytes
testsuite/rootfs-pristine/test-user/lib/modules/4.4.4/modules.symbols.bin
Binary file not shown.
2 changes: 2 additions & 0 deletions
2
testsuite/rootfs-pristine/test-user/lib/modules/4.4.4/modules.weakdep
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Weak dependencies extracted from modules themselves. | ||
weakdep mod_weakdep mod-simple |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright Red Hat | ||
* | ||
* 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. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <errno.h> | ||
#include <inttypes.h> | ||
#include <stddef.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
#include <libkmod/libkmod.h> | ||
|
||
#include "testsuite.h" | ||
|
||
#define TEST_USER_ROOTFS TESTSUITE_ROOTFS "test-user/" | ||
#define TEST_USER_KERNEL_DIR TEST_USER_ROOTFS "lib/modules/4.4.4/" | ||
|
||
static const char *const test_user_config_paths[] = { | ||
TEST_USER_ROOTFS "etc/modprobe.d", | ||
NULL | ||
}; | ||
|
||
static const char *const mod_name[] = { | ||
"mod-loop-b", | ||
"mod-weakdep", | ||
NULL | ||
}; | ||
|
||
static int test_user_weakdep(const struct test *t) | ||
{ | ||
struct kmod_ctx *ctx; | ||
int mod_name_index = 0; | ||
int err; | ||
|
||
ctx = kmod_new(TEST_USER_KERNEL_DIR, test_user_config_paths); | ||
if (ctx == NULL) | ||
exit(EXIT_FAILURE); | ||
|
||
while (mod_name[mod_name_index]) { | ||
struct kmod_list *list = NULL; | ||
struct kmod_module *mod = NULL; | ||
struct kmod_list *mod_list = NULL; | ||
struct kmod_list *itr = NULL; | ||
|
||
printf("%s:", mod_name[mod_name_index]); | ||
err = kmod_module_new_from_lookup(ctx, mod_name[mod_name_index], &list); | ||
if (list == NULL || err < 0) { | ||
fprintf(stderr, "module %s not found in directory %s\n", | ||
mod_name[mod_name_index], | ||
ctx ? kmod_get_dirname(ctx) : "(missing)"); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
mod = kmod_module_get_module(list); | ||
|
||
err = kmod_module_get_weakdeps(mod, &mod_list); | ||
if (err) { | ||
fprintf(stderr, "weak dependencies can not be read for %s (%d)\n", | ||
mod_name[mod_name_index], err); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
kmod_list_foreach(itr, mod_list) { | ||
struct kmod_module *weakdep_mod = kmod_module_get_module(itr); | ||
const char *weakdep_name = kmod_module_get_name(weakdep_mod); | ||
|
||
printf(" %s", weakdep_name); | ||
kmod_module_unref(weakdep_mod); | ||
} | ||
printf("\n"); | ||
|
||
kmod_module_unref_list(mod_list); | ||
kmod_module_unref(mod); | ||
kmod_module_unref_list(list); | ||
|
||
mod_name_index++; | ||
} | ||
|
||
kmod_unref(ctx); | ||
|
||
return EXIT_SUCCESS; | ||
} | ||
DEFINE_TEST(test_user_weakdep, | ||
.description = "check if modprobe breaks weakdep2", | ||
.config = { | ||
[TC_UNAME_R] = "4.4.4", | ||
[TC_ROOTFS] = TESTSUITE_ROOTFS "test-user", | ||
[TC_INIT_MODULE_RETCODES] = "", | ||
}, | ||
.need_spawn = true, | ||
.output = { | ||
.out = TESTSUITE_ROOTFS "test-user/correct-weakdep.txt", | ||
}); | ||
|
||
TESTSUITE_MAIN(); |
Oops, something went wrong.