diff mbox

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

Message ID 20170912154410.27815-1-joonas.lahtinen@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Joonas Lahtinen Sept. 12, 2017, 3:44 p.m. UTC
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@linux.intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Petri Latvala <petri.latvala@intel.com>
Cc: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 lib/igt_kmod.c | 44 ++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 40 insertions(+), 4 deletions(-)

Comments

Chris Wilson Sept. 12, 2017, 3:51 p.m. UTC | #1
Quoting Joonas Lahtinen (2017-09-12 16:44:10)
> 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

Just one quibble, but shouldn't it be PATH?  E.g.
	PATH=
	LD_LIBRARY_PATH=
etc are similar colon-delimited sets of search directories.
Then again, if they are not search directories, then just
IGT_KMOD_CONFIG=

DIRNAME or just DIR? Names are where the best bikesheds are built.
-Chris
Chris Wilson Sept. 13, 2017, 10:37 a.m. UTC | #2
Quoting Chris Wilson (2017-09-12 16:51:40)
> Quoting Joonas Lahtinen (2017-09-12 16:44:10)
> > 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
> 
> Just one quibble, but shouldn't it be PATH?  E.g.

On reflection, they match the libkmod names, so who am I to judge?
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
-Chris
Joonas Lahtinen Sept. 13, 2017, 12:40 p.m. UTC | #3
On Wed, 2017-09-13 at 11:37 +0100, Chris Wilson wrote:
> Quoting Chris Wilson (2017-09-12 16:51:40)
> > Quoting Joonas Lahtinen (2017-09-12 16:44:10)
> > > 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
> > 
> > Just one quibble, but shouldn't it be PATH?  E.g.
> 
> On reflection, they match the libkmod names, so who am I to judge?
> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>

Yeah, I was considering IGT_MODULE_PATH and IGT_MODULE_CONFIG_PATH, but
that would have indicated they might be used in other ways too,
strictly sticking to KMOD convention seemed would cause least
confusion.

This is now pushed, thanks for the review.

Regards, Joonas
diff mbox

Patch

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