[Intel-gfx] [PATCH i-g-t] lib/igt_kmod: Allow specifying libkmod config via environment variables

Joonas Lahtinen joonas.lahtinen at linux.intel.com
Tue Sep 12 15:44:10 UTC 2017


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 <joonas.lahtinen at linux.intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
Cc: Petri Latvala <petri.latvala at intel.com>
Cc: Arkadiusz Hiler <arkadiusz.hiler at intel.com>
Cc: Daniel Vetter <daniel.vetter at ffwll.ch>
---
 lib/igt_kmod.c | 44 ++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 40 insertions(+), 4 deletions(-)

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;
 }
 
-- 
2.13.5



More information about the Intel-gfx mailing list