[LTP] [PATCH 07/10] lib: Add helper function for reloading kernel modules
Martin Doucha
mdoucha@suse.cz
Tue Jan 21 17:44:21 CET 2025
Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
include/tst_module.h | 3 +++
lib/tst_module.c | 28 ++++++++++++++++++++++++++++
2 files changed, 31 insertions(+)
diff --git a/include/tst_module.h b/include/tst_module.h
index 8bbaf08f3..e55321d19 100644
--- a/include/tst_module.h
+++ b/include/tst_module.h
@@ -47,4 +47,7 @@ static inline void tst_requires_module_signature_disabled(void)
tst_requires_module_signature_disabled_();
}
+void tst_modprobe(const char *mod_name, char *const argv[]);
+void tst_module_reload(const char *mod_name, char *const argv[]);
+
#endif /* TST_MODULE_H */
diff --git a/lib/tst_module.c b/lib/tst_module.c
index cec20524f..42d63ede6 100644
--- a/lib/tst_module.c
+++ b/lib/tst_module.c
@@ -146,3 +146,31 @@ void tst_requires_module_signature_disabled_(void)
if (tst_module_signature_enforced_())
tst_brkm(TCONF, NULL, "module signature is enforced, skip test");
}
+
+void tst_modprobe(const char *mod_name, char *const argv[])
+{
+ const int offset = 2; /* command name & module path */
+ int i, size = 0;
+
+ while (argv && argv[size])
+ ++size;
+ size += offset;
+
+ const char *mod_argv[size + 1]; /* + NULL in the end */
+
+ mod_argv[size] = NULL;
+ mod_argv[0] = "modprobe";
+ mod_argv[1] = mod_name;
+
+ for (i = offset; i < size; ++i)
+ mod_argv[i] = argv[i - offset];
+
+ tst_cmd(NULL, mod_argv, NULL, NULL, 0);
+}
+
+void tst_module_reload(const char *mod_name, char *const argv[])
+{
+ tst_resm(TINFO, "Reloading kernel module %s", mod_name);
+ tst_module_unload_(NULL, mod_name);
+ tst_modprobe(mod_name, argv);
+}
--
2.47.0
More information about the ltp
mailing list