diff mbox

[i-g-t] HAX igt/drv_module_reload: Revamp fault-injection

Message ID 20180607125930.31000-1-chris@chris-wilson.co.uk (mailing list archive)
State New, archived
Headers show

Commit Message

Chris Wilson June 7, 2018, 12:59 p.m. UTC
The current method of checking for a failed module load is flawed, as we
only report the error on probing it is not being reported back by
modprobe. So we have to dig inside the module_parameters while the
module is still loaded to discover the error.

v2: Expect i915.inject_load_failure to be zero on success

w/o display
---
 tests/drv_module_reload.c | 47 ++++++++++++++++++++++++++++++++++-----
 1 file changed, 42 insertions(+), 5 deletions(-)
diff mbox

Patch

diff --git a/tests/drv_module_reload.c b/tests/drv_module_reload.c
index 3046d8227..d88851b68 100644
--- a/tests/drv_module_reload.c
+++ b/tests/drv_module_reload.c
@@ -234,6 +234,40 @@  reload(const char *opts_i915)
 	return err;
 }
 
+static int open_parameters(const char *module_name)
+{
+	char path[256];
+
+	snprintf(path, sizeof(path), "/sys/module/%s/parameters", module_name);
+	return open(path, O_RDONLY);
+}
+
+static int
+inject_fault(const char *module_name, const char *opt, int fault)
+{
+	char buf[1024];
+	int dir;
+
+	igt_assert(fault > 0);
+	snprintf(buf, sizeof(buf), "%s=%d disable_display=1", opt, fault);
+
+	if (igt_kmod_load(module_name, buf)) {
+		igt_warn("Failed to load module '%s' with options '%s'\n",
+			 module_name, buf);
+		return 1;
+	}
+
+	dir = open_parameters(module_name);
+	igt_sysfs_scanf(dir, opt, "%d", &fault);
+	close(dir);
+
+	igt_debug("Loaded '%s %s', result=%d\n", module_name, buf, fault);
+
+	igt_kmod_unload(module_name, 0);
+
+	return fault;
+}
+
 static void
 gem_sanitycheck(void)
 {
@@ -320,12 +354,15 @@  igt_main
 		igt_assert_eq(reload("disable_display=1"), 0);
 
 	igt_subtest("basic-reload-inject") {
-		char buf[64];
 		int i = 0;
-		do {
-			snprintf(buf, sizeof(buf),
-				 "inject_load_failure=%d", ++i);
-		} while (reload(buf));
+
+		igt_i915_driver_unload();
+
+		while (inject_fault("i915", "inject_load_failure", ++i) == 0)
+			;
+
+		/* We expect to hit at least one fault! */
+		igt_assert(i > 1);
 	}
 
 	igt_fixture {