From c718ba805208e55d675defe9b2a66852e2ae038c Mon Sep 17 00:00:00 2001 From: Joonas Lahtinen Date: Tue, 12 Sep 2017 18:44:10 +0300 Subject: lib/igt_kmod: Allow specifying libkmod config via environment variables Allow specifying the kernel module configuration via environment variables. This allows enumerating the subtests of the kselftest wrappers from sysroot directory. IGT_KMOD_CONFIG_PATHS="" \ IGT_KMOD_DIRNAME="/path/to/sysroot/lib/modules/X.Y.Z" \ tests/drm_mm --list-subtests Signed-off-by: Joonas Lahtinen Cc: Chris Wilson Cc: Petri Latvala Cc: Arkadiusz Hiler Cc: Daniel Vetter Reviewed-by: Chris Wilson --- lib/igt_kmod.c | 44 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 40 insertions(+), 4 deletions(-) (limited to 'lib/igt_kmod.c') diff --git a/lib/igt_kmod.c b/lib/igt_kmod.c index 58624cd1..f468a4da 100644 --- a/lib/igt_kmod.c +++ b/lib/igt_kmod.c @@ -56,14 +56,50 @@ static void squelch(void *data, int priority, static struct kmod_ctx *kmod_ctx(void) { static struct kmod_ctx *ctx; + const char **config_paths = NULL; + char *config_paths_str; + char *dirname; + + if (ctx) + goto out; + + dirname = getenv("IGT_KMOD_DIRNAME"); + if (dirname) + igt_debug("kmod dirname = %s\n", dirname); + + config_paths_str = getenv("IGT_KMOD_CONFIG_PATHS"); + if (config_paths_str) + igt_debug("kmod config paths = %s\n", config_paths_str); + + if (config_paths_str) { + unsigned count = !!strlen(config_paths_str); + unsigned i; + char* p; + + p = config_paths_str; + while ((p = strchr(p, ':'))) p++, count++; - if (!ctx) { - ctx = kmod_new(NULL, NULL); - igt_assert(ctx != NULL); - kmod_set_log_fn(ctx, squelch, NULL); + config_paths = malloc(sizeof(*config_paths) * (count + 1)); + igt_assert(config_paths != NULL); + + p = config_paths_str; + for (i = 0; i < count; ++i) { + config_paths[i] = p; + + if ((p = strchr(p, ':'))) + *p++ = '\0'; + } + config_paths[i] = NULL; } + ctx = kmod_new(dirname, config_paths); + igt_assert(ctx != NULL); + + free(config_paths); + + kmod_set_log_fn(ctx, squelch, NULL); +out: return ctx; } -- cgit v1.2.3