[igt-dev] [PATCH i-g-t] igt/kms_frontbuffer_tracking: Restore modparams around test

Chris Wilson chris at chris-wilson.co.uk
Mon Aug 6 20:22:39 UTC 2018


Save the module parameters from setup and restore them on teardown, so
that we leave the system in the same state as we found it.

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 tests/kms_frontbuffer_tracking.c | 43 +++++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 4 deletions(-)

diff --git a/tests/kms_frontbuffer_tracking.c b/tests/kms_frontbuffer_tracking.c
index 1dfd7c1ce..503a6fb6d 100644
--- a/tests/kms_frontbuffer_tracking.c
+++ b/tests/kms_frontbuffer_tracking.c
@@ -155,6 +155,7 @@ struct rect {
 struct {
 	int fd;
 	int debugfs;
+	int modparams;
 	igt_display_t display;
 
 	drm_intel_bufmgr *bufmgr;
@@ -939,10 +940,10 @@ static bool drrs_wait_until_rr_switch_to_low(void)
 	return igt_wait(is_drrs_low(), 5000, 1);
 }
 
-#define fbc_enable() igt_set_module_param_int("enable_fbc", 1)
-#define fbc_disable() igt_set_module_param_int("enable_fbc", 0)
-#define psr_enable() igt_set_module_param_int("enable_psr", 1)
-#define psr_disable() igt_set_module_param_int("enable_psr", 0)
+#define fbc_enable() igt_sysfs_set(drm.modparams, "enable_fbc", "1")
+#define fbc_disable() igt_sysfs_set(drm.modparams, "enable_fbc", "0")
+#define psr_enable() igt_sysfs_set(drm.modparams, "enable_psr", "1")
+#define psr_disable() igt_sysfs_set(drm.modparams, "enable_psr", "0")
 #define drrs_enable()	drrs_set(1)
 #define drrs_disable()	drrs_set(0)
 
@@ -1286,6 +1287,7 @@ static void setup_drm(void)
 {
 	drm.fd = drm_open_driver_master(DRIVER_INTEL);
 	drm.debugfs = igt_debugfs_dir(drm.fd);
+	drm.modparams = igt_sysfs_open_parameters(drm.fd);
 
 	kmstest_set_vt_graphics_mode();
 	igt_display_init(&drm.display, drm.fd);
@@ -1299,6 +1301,7 @@ static void teardown_drm(void)
 {
 	drm_intel_bufmgr_destroy(drm.bufmgr);
 	igt_display_fini(&drm.display);
+	close(drm.modparams);
 	close(drm.fd);
 }
 
@@ -1467,11 +1470,40 @@ static void setup_drrs(void)
 	drrs.can_test = true;
 }
 
+static struct {
+	const char *param;
+	char buf[12];
+	int len;
+} modparams[] = {
+	{ "enable_psr" },
+	{ "enable_fbc" },
+	{ }
+};
+
+static void save_modparams(void)
+{
+	for (typeof(*modparams) *p = modparams; p->param; p++)
+		p->len = igt_sysfs_read(drm.modparams,
+					p->param, p->buf, sizeof(p->buf));
+}
+
+static void restore_modparams(void)
+{
+	for (typeof(*modparams) *p = modparams; p->param; p++) {
+		if (p->len <= 0)
+			continue;
+
+		igt_sysfs_write(drm.modparams, p->param, p->buf, p->len);
+	}
+}
+
 static void setup_environment(void)
 {
 	setup_drm();
 	setup_modeset();
 
+	save_modparams();
+
 	setup_fbc();
 	setup_psr();
 	setup_drrs();
@@ -1486,6 +1518,9 @@ static void teardown_environment(void)
 	teardown_crcs();
 	teardown_psr();
 	teardown_fbc();
+
+	restore_modparams();
+
 	teardown_modeset();
 	teardown_drm();
 }
-- 
2.18.0



More information about the igt-dev mailing list