diff mbox series

[i-g-t] tests/drv_selftest: Allow passing in module options from the command line

Message ID 20181120180757.25494-1-tvrtko.ursulin@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [i-g-t] tests/drv_selftest: Allow passing in module options from the command line | expand

Commit Message

Tvrtko Ursulin Nov. 20, 2018, 6:07 p.m. UTC
From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

A new option '--kmod-options' is added which takes a string which will be
passed to modprobe when loading the module.

This for instance allows easy override of things like the random seed when
trying to reproduce failures.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
---
 lib/igt_core.c       |  9 +++++++++
 lib/igt_kmod.h       |  2 ++
 tests/drv_selftest.c | 24 ++++++++++++++++++------
 3 files changed, 29 insertions(+), 6 deletions(-)

Comments

Chris Wilson Nov. 20, 2018, 6:16 p.m. UTC | #1
Quoting Tvrtko Ursulin (2018-11-20 18:07:57)
> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> 
> A new option '--kmod-options' is added which takes a string which will be
> passed to modprobe when loading the module.
> 
> This for instance allows easy override of things like the random seed when
> trying to reproduce failures.
 
Anyway we can simply extend the option parsing locally? (Just find it
unsightly to have test specific options in libigt.)

Stashing argc/argv in igt_subtest_init_parse_opts() and then being able
to run getopts inside igt_main {}?

I also had in mind an env for module options, which may be also useful
for the module reloading and autoloading.
-Chris
Chris Wilson Nov. 20, 2018, 6:20 p.m. UTC | #2
Quoting Chris Wilson (2018-11-20 18:16:53)
> Quoting Tvrtko Ursulin (2018-11-20 18:07:57)
> > From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> > 
> > A new option '--kmod-options' is added which takes a string which will be
> > passed to modprobe when loading the module.
> > 
> > This for instance allows easy override of things like the random seed when
> > trying to reproduce failures.
>  
> Anyway we can simply extend the option parsing locally? (Just find it
> unsightly to have test specific options in libigt.)
> 
> Stashing argc/argv in igt_subtest_init_parse_opts() and then being able
> to run getopts inside igt_main {}?

Or perhaps,

#define igt_main_argv \
        static void igt_tokencat(__real_main, __LINE__)(int argc, char **argv); \
        int main(int argc, char **argv) { \
                igt_subtest_init_parse_opts(&argc, argv, NULL, NULL, NULL, \
                                            NULL, NULL); \
                igt_tokencat(__real_main, __LINE__)(argc, char **argv); \
                igt_exit(); \
        } \
        static void igt_tokencat(__real_main, __LINE__)(int argc, char **argv) \
Tvrtko Ursulin Nov. 20, 2018, 6:27 p.m. UTC | #3
On 20/11/2018 18:16, Chris Wilson wrote:
> Quoting Tvrtko Ursulin (2018-11-20 18:07:57)
>> From: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
>>
>> A new option '--kmod-options' is added which takes a string which will be
>> passed to modprobe when loading the module.
>>
>> This for instance allows easy override of things like the random seed when
>> trying to reproduce failures.
>   
> Anyway we can simply extend the option parsing locally? (Just find it
> unsightly to have test specific options in libigt.)

Well.. it is not test specific but kmod specific but point still stands.

> Stashing argc/argv in igt_subtest_init_parse_opts() and then being able
> to run getopts inside igt_main {}?

Yep, I didn't know we have this already.

> I also had in mind an env for module options, which may be also useful
> for the module reloading and autoloading.

In that case, since modprobe(8) supports MODPROBE_OPTIONS, we could 
perhaps emulate that in igt_kmod? Or add support directly to libkmod? 
With either we wouldn't even need the command line pass through. Adding 
Lucas for an opinion since kmod seems to be his baby.

Regards,

Tvrtko
diff mbox series

Patch

diff --git a/lib/igt_core.c b/lib/igt_core.c
index e0989f538aa9..8076d636afa3 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -282,6 +282,7 @@  bool test_child;
 enum {
  OPT_LIST_SUBTESTS,
  OPT_RUN_SUBTEST,
+ OPT_KMOD_OPTIONS,
  OPT_DESCRIPTION,
  OPT_DEBUG,
  OPT_INTERACTIVE_DEBUG,
@@ -302,6 +303,8 @@  GKeyFile *igt_key_file;
 
 char *igt_frame_dump_path;
 
+char *igt_kmod_options;
+
 static bool stderr_needs_sentinel = false;
 
 const char *igt_test_name(void)
@@ -552,6 +555,7 @@  static void print_usage(const char *help_str, bool output_on_stderr)
 		   "  --run-subtest <pattern>\n"
 		   "  --debug[=log-domain]\n"
 		   "  --interactive-debug[=domain]\n"
+		   "  --kmod-options=<options-string>\n"
 		   "  --help-description\n"
 		   "  --help\n");
 	if (help_str)
@@ -660,6 +664,7 @@  static int common_init(int *argc, char **argv,
 	static struct option long_options[] = {
 		{"list-subtests", 0, 0, OPT_LIST_SUBTESTS},
 		{"run-subtest", 1, 0, OPT_RUN_SUBTEST},
+		{"kmod-options", 1, 0, OPT_KMOD_OPTIONS},
 		{"help-description", 0, 0, OPT_DESCRIPTION},
 		{"debug", optional_argument, 0, OPT_DEBUG},
 		{"interactive-debug", optional_argument, 0, OPT_INTERACTIVE_DEBUG},
@@ -757,6 +762,10 @@  static int common_init(int *argc, char **argv,
 			if (!list_subtests)
 				run_single_subtest = strdup(optarg);
 			break;
+		case OPT_KMOD_OPTIONS:
+			if (!list_subtests)
+				igt_kmod_options = strdup(optarg);
+			break;
 		case OPT_DESCRIPTION:
 			print_test_description();
 			ret = -1;
diff --git a/lib/igt_kmod.h b/lib/igt_kmod.h
index 87d36d400184..e1d286a2e2c1 100644
--- a/lib/igt_kmod.h
+++ b/lib/igt_kmod.h
@@ -28,6 +28,8 @@ 
 
 #include "igt_list.h"
 
+extern char *igt_kmod_options;
+
 bool igt_kmod_is_loaded(const char *mod_name);
 void igt_kmod_list_loaded(void);
 
diff --git a/tests/drv_selftest.c b/tests/drv_selftest.c
index 80e515c6123b..c67535bf573f 100644
--- a/tests/drv_selftest.c
+++ b/tests/drv_selftest.c
@@ -28,10 +28,22 @@  IGT_TEST_DESCRIPTION("Basic unit tests for i915.ko");
 
 igt_main
 {
-	igt_kselftests("i915",
-		       "mock_selftests=-1 disable_display=1",
-		       NULL, "mock");
-	igt_kselftests("i915",
-		       "live_selftests=-1 disable_display=1",
-		       "live_selftests", "live");
+	const char *live_opts = "live_selftests=-1 disable_display=1";
+	const char *mock_opts = "mock_selftests=-1 disable_display=1";
+	char *opts;
+	int ret;
+
+	/* Mock selftests */
+
+	ret = asprintf(&opts, "%s %s", mock_opts, igt_kmod_options ?: "");
+	igt_assert(ret > 0);
+	igt_kselftests("i915", opts, NULL, "mock");
+	free(opts);
+
+	/* Live selftests */
+
+	ret = asprintf(&opts, "%s %s", live_opts, igt_kmod_options ?: "");
+	igt_assert(ret > 0);
+	igt_kselftests("i915", opts, "live_selftests", "live");
+	free(opts);
 }