[PATCH i-g-t v3] lib/igt_kmod: Allow to load kunit from alias
Lucas De Marchi
lucas.demarchi at intel.com
Fri Mar 8 19:31:49 UTC 2024
Instead of only allowing to load the from the module name, also allow it
from alias by using kmod_module_new_from_lookup(). With that a user can
have their on aliases and the kernel can also export a compat alias for
future module renames.
There was a bug in libkmod <= 29 that would make
kmod_module_new_from_lookup() return prematurely after a failed alias
lookup when we don't have a modules.alias file in the modules dir. So
add a workaround to check for -ENOSYS return code too. It should still
be compatible with what we are doing here.
v2: Fallback to kmod_module_new_from_name() since the kmod ctx is also
used on builder machines to determine the test lists.
v3: Add workaround to bug in libkmod
Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>
---
lib/igt_kmod.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c
index cc242838f..d581f9073 100644
--- a/lib/igt_kmod.c
+++ b/lib/igt_kmod.c
@@ -1443,6 +1443,7 @@ void igt_kunit(const char *module_name, const char *suite, const char *opts)
int igt_ktest_init(struct igt_ktest *tst,
const char *module_name)
{
+ struct kmod_list *l = NULL;
int err;
memset(tst, 0, sizeof(*tst));
@@ -1453,9 +1454,25 @@ int igt_ktest_init(struct igt_ktest *tst,
tst->kmsg = -1;
- err = kmod_module_new_from_name(kmod_ctx(), module_name, &tst->kmod);
- if (err)
+ err = kmod_module_new_from_lookup(kmod_ctx(), module_name, &l);
+
+ /*
+ * Check for -ENOSYS to workaround bug in kmod_module_new_from_lookup()
+ * from libkmod <= 29
+ */
+ if (err < 0 && err != -ENOSYS) {
return err;
+ }
+
+ /*
+ * Lookup may not resolve to a module when used to just list subtests,
+ * where module is not available. Fallback to _new_from_name().
+ */
+ if (!l)
+ return kmod_module_new_from_name(kmod_ctx(), module_name, &tst->kmod);
+
+ tst->kmod = kmod_module_get_module(l);
+ kmod_module_unref_list(l);
return 0;
}
--
2.43.0
More information about the igt-dev
mailing list