[PATCH i-g-t 2/4] tests/i915/kms_frontbuffer_tracking: Split drrs into separate helper

Jouni Högander jouni.hogander at intel.com
Mon Apr 3 07:01:08 UTC 2023


Split drrs handling into separate helper to be used by other testcases
as well.

Signed-off-by: Jouni Högander <jouni.hogander at intel.com>
---
 tests/i915/kms_drrs_helper.c          | 70 ++++++++++++++++++++++++++
 tests/i915/kms_drrs_helper.h          | 14 ++++++
 tests/i915/kms_frontbuffer_tracking.c | 72 ++-------------------------
 tests/meson.build                     |  2 +-
 4 files changed, 90 insertions(+), 68 deletions(-)
 create mode 100644 tests/i915/kms_drrs_helper.c
 create mode 100644 tests/i915/kms_drrs_helper.h

diff --git a/tests/i915/kms_drrs_helper.c b/tests/i915/kms_drrs_helper.c
new file mode 100644
index 00000000..b32218ba
--- /dev/null
+++ b/tests/i915/kms_drrs_helper.c
@@ -0,0 +1,70 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2023 Intel Corporation
+ */
+
+#include <fcntl.h>
+
+#include "igt.h"
+#include "igt_sysfs.h"
+
+#include "kms_drrs_helper.h"
+
+bool is_drrs_supported(int device, enum pipe pipe)
+{
+	char buf[256];
+	int dir;
+
+	dir = igt_debugfs_pipe_dir(device, pipe, O_DIRECTORY);
+	igt_require_fd(dir);
+	igt_debugfs_simple_read(dir, "i915_drrs_status", buf, sizeof(buf));
+	close(dir);
+	if (*buf == '\0')
+		return false;
+
+	return !strcasestr(buf, "DRRS enabled:");
+}
+
+bool output_has_drrs(int device, igt_output_t *output)
+{
+	char buf[256];
+	int dir;
+
+	dir = igt_debugfs_connector_dir(device, output->name, O_DIRECTORY);
+	igt_require_fd(dir);
+	igt_debugfs_simple_read(dir, "i915_drrs_type", buf, sizeof(buf));
+	close(dir);
+
+	return strstr(buf, "seamless");
+}
+
+static void drrs_set(int device, enum pipe pipe, unsigned int val)
+{
+	char buf[2];
+	int dir, ret;
+
+	igt_debug("Manually %sabling DRRS. %u\n", val ? "en" : "dis", val);
+	snprintf(buf, sizeof(buf), "%d", val);
+
+	dir = igt_debugfs_pipe_dir(device, pipe, O_DIRECTORY);
+	igt_require_fd(dir);
+	ret = igt_sysfs_write(dir, "i915_drrs_ctl", buf, sizeof(buf) - 1);
+
+	/*
+	 * drrs_enable() is called on DRRS capable platform only,
+	 * whereas drrs_disable() is called on all platforms.
+	 * So handle the failure of debugfs_write only for drrs_enable().
+	 */
+	if (val)
+		igt_assert_f(ret == (sizeof(buf) - 1), "debugfs_write failed");
+}
+
+void drrs_enable(int device, enum pipe pipe)
+{
+	drrs_set(device, pipe, 1);
+}
+
+void drrs_disable(int device, enum pipe pipe)
+{
+	drrs_set(device, pipe, 0);
+}
diff --git a/tests/i915/kms_drrs_helper.h b/tests/i915/kms_drrs_helper.h
new file mode 100644
index 00000000..d516d3f4
--- /dev/null
+++ b/tests/i915/kms_drrs_helper.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: MIT */
+/*
+ * Copyright © 2022 Intel Corporation
+ */
+
+#ifndef IGT_KMS_DRRS_HELPER_H
+#define IGT_KMS_DRRS_HELPER_H
+
+bool is_drrs_supported(int device, enum pipe pipe);
+bool output_has_drrs(int device, igt_output_t *output);
+void drrs_enable(int device, enum pipe pipe);
+void drrs_disable(int device, enum pipe pipe);
+
+#endif
diff --git a/tests/i915/kms_frontbuffer_tracking.c b/tests/i915/kms_frontbuffer_tracking.c
index e78073e5..c79830db 100644
--- a/tests/i915/kms_frontbuffer_tracking.c
+++ b/tests/i915/kms_frontbuffer_tracking.c
@@ -36,6 +36,7 @@
 #include "igt_sysfs.h"
 #include "igt_psr.h"
 
+#include "kms_drrs_helper.h"
 #include "kms_fbc_helper.h"
 
 #define TIME SLOW_QUICK(1000, 10000)
@@ -747,32 +748,6 @@ static void __debugfs_read_crtc(const char *param, char *buf, int len)
 	close(dir);
 }
 
-static int __debugfs_write_crtc(const char *param, const char *buf, int len)
-{
-	int dir, ret;
-	enum pipe pipe;
-
-	pipe = prim_mode_params.pipe;
-	dir = igt_debugfs_pipe_dir(drm.fd, pipe, O_DIRECTORY);
-	igt_require_fd(dir);
-	ret = igt_sysfs_write(dir, param, buf, len - 1);
-	close(dir);
-
-	return ret;
-}
-
-static void __debugfs_read_connector(const char *param, char *buf, int len)
-{
-	int dir;
-	igt_output_t *output;
-
-	output = prim_mode_params.output;
-	dir = igt_debugfs_connector_dir(drm.fd, output->name, O_DIRECTORY);
-	igt_require_fd(dir);
-	igt_debugfs_simple_read(dir, param, buf, len);
-	close(dir);
-}
-
 #define debugfs_read_crtc(p, arr) __debugfs_read_crtc(p, arr, sizeof(arr))
 #define debugfs_write_crtc(p, arr) __debugfs_write_crtc(p, arr, sizeof(arr))
 #define debugfs_read_connector(p, arr) __debugfs_read_connector(p, arr, sizeof(arr))
@@ -798,24 +773,6 @@ static bool fbc_is_enabled(int lvl)
 	return strstr(buf, "FBC enabled\n");
 }
 
-static void drrs_set(unsigned int val)
-{
-	char buf[2];
-	int ret;
-
-	igt_debug("Manually %sabling DRRS. %u\n", val ? "en" : "dis", val);
-	snprintf(buf, sizeof(buf), "%d", val);
-	ret = debugfs_write_crtc("i915_drrs_ctl", buf);
-
-	/*
-	 * drrs_enable() is called on DRRS capable platform only,
-	 * whereas drrs_disable() is called on all platforms.
-	 * So handle the failure of debugfs_write only for drrs_enable().
-	 */
-	if (val)
-		igt_assert_f(ret == (sizeof(buf) - 1), "debugfs_write failed");
-}
-
 static bool is_drrs_high(void)
 {
 	char buf[MAX_DRRS_STATUS_BUF_LEN];
@@ -832,14 +789,6 @@ static bool is_drrs_low(void)
 	return strstr(buf, "DRRS refresh rate: low");
 }
 
-static bool is_drrs_supported(void)
-{
-	char buf[MAX_DRRS_STATUS_BUF_LEN];
-
-	debugfs_read_crtc("i915_drrs_status", buf);
-	return strcasestr(buf, "DRRS enabled:");
-}
-
 static bool is_drrs_inactive(void)
 {
 	char buf[MAX_DRRS_STATUS_BUF_LEN];
@@ -856,14 +805,6 @@ static void drrs_print_status(void)
 	igt_info("DRRS STATUS :\n%s\n", buf);
 }
 
-static bool output_has_drrs(void)
-{
-	char buf[MAX_DRRS_STATUS_BUF_LEN];
-
-	debugfs_read_connector("i915_drrs_type", buf);
-	return strstr(buf, "seamless");
-}
-
 static struct timespec fbc_get_last_action(void)
 {
 	struct timespec ret = { 0, 0 };
@@ -984,9 +925,6 @@ static bool drrs_wait_until_rr_switch_to_low(void)
 	return igt_wait(is_drrs_low(), 5000, 1);
 }
 
-#define drrs_enable()  drrs_set(1)
-#define drrs_disable() drrs_set(0)
-
 static struct rect pat1_get_rect(struct fb_region *fb, int r)
 {
 	struct rect rect;
@@ -1188,8 +1126,8 @@ static bool disable_features(const struct test_mode *t)
 	if (t->feature == FEATURE_DEFAULT)
 		return false;
 
-	drrs_disable();
 	fbc_disable(drm.fd);
+	drrs_disable(drm.fd, prim_mode_params.pipe);
 	return psr.can_test ? psr_disable(drm.fd, drm.debugfs) : false;
 }
 
@@ -1466,12 +1404,12 @@ static void teardown_psr(void)
 
 static void setup_drrs(void)
 {
-	if (!output_has_drrs()) {
+	if (!output_has_drrs(drm.fd, prim_mode_params.output)) {
 		igt_info("Can't test DRRS: no usable screen.\n");
 		return;
 	}
 
-	if (!is_drrs_supported()) {
+	if (!is_drrs_supported(drm.fd, prim_mode_params.pipe)) {
 		igt_info("Can't test DRRS: Not supported.\n");
 		return;
 	}
@@ -1790,7 +1728,7 @@ static bool enable_features_for_test(const struct test_mode *t)
 	if (t->feature & FEATURE_PSR)
 		ret = psr_enable(drm.fd, drm.debugfs, PSR_MODE_1);
 	if (t->feature & FEATURE_DRRS)
-		drrs_enable();
+		drrs_enable(drm.fd, prim_mode_params.pipe);
 
 	return ret;
 }
diff --git a/tests/meson.build b/tests/meson.build
index 3c1151f5..11374787 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -486,7 +486,7 @@ test_executables += executable('kms_psr2_sf',
 test_list += 'kms_psr2_sf'
 
 test_executables += executable('kms_frontbuffer_tracking',
-	   [ join_paths('i915', 'kms_frontbuffer_tracking.c'), join_paths ('i915', 'kms_fbc_helper.c')],
+	   [ join_paths('i915', 'kms_frontbuffer_tracking.c'), join_paths ('i915', 'kms_fbc_helper.c'), join_paths ('i915', 'kms_drrs_helper.c')],
 	   dependencies : test_deps,
 	   install_dir : libexecdir,
 	   install_rpath : libexecdir_rpathdir,
-- 
2.34.1



More information about the Intel-gfx-trybot mailing list