[PATCH i-g-t v3 1/1] tests/kms_hdr: Test brightness manipulation in HDR mode

Santhosh Reddy Guddati santhosh.reddy.guddati at intel.com
Wed Oct 2 14:55:03 UTC 2024


Add subtest for backlight control on hdr enabled edp panels
by changing brightness via sysfs.

v2: adjust brightness range, refactor and restore brightness (Pranay)

v3: reuse functions, add flags to avoid duplicate code (Suraj)

Signed-off-by: Santhosh Reddy Guddati <santhosh.reddy.guddati at intel.com>
---
 tests/kms_hdr.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 82 insertions(+), 1 deletion(-)

diff --git a/tests/kms_hdr.c b/tests/kms_hdr.c
index f123c6b36..0f07e770b 100644
--- a/tests/kms_hdr.c
+++ b/tests/kms_hdr.c
@@ -64,6 +64,10 @@
  * Description: Tests static toggle with suspend
  * Functionality: colorspace, static_hdr, suspend
  *
+ * SUBTEST: brightness-with-hdr
+ * Description: Tests brightness with HDR
+ * Functionality: colorspace, static_hdr
+ *
  * SUBTEST: static-%s
  * Description: Tests %arg[1].
  * Functionality: colorspace, static_hdr
@@ -81,6 +85,8 @@ IGT_TEST_DESCRIPTION("Test HDR metadata interfaces and bpc switch");
 #define HDR_STATIC_METADATA_BLOCK       0x06
 #define USE_EXTENDED_TAG		0x07
 
+#define INTEL_BACKLIGHT_PATH "/sys/class/backlight/intel_backlight"
+
 /* DRM HDR definitions. Not in the UAPI header, unfortunately. */
 enum hdmi_metadata_type {
 	HDMI_STATIC_METADATA_TYPE1 = 0,
@@ -100,6 +106,7 @@ enum {
 	TEST_SWAP = 1 << 3,
 	TEST_INVALID_METADATA_SIZES = 1 << 4,
 	TEST_INVALID_HDR = 1 << 5,
+	TEST_BRIGHTNESS = 1 << 6,
 };
 
 /* BPC connector state. */
@@ -448,6 +455,72 @@ static void fill_hdr_output_metadata_st2048(struct hdr_output_metadata *meta)
 	meta->hdmi_metadata_type1.max_cll = 500;   /* 500 nits */
 }
 
+/* TODO: Move adjust_brightness to lib/igt_sysfs to reuse in other tests. */
+static void adjust_brightness(data_t *data, uint32_t flags)
+{
+	char brightness_path[1024];
+	int brightness_fd;
+	char brightness_value[64];
+	int current_brightness;
+	int max_brightness;
+	int read_brightness;
+	int fd, i;
+
+	/* Get max brightness */
+	snprintf(brightness_path, sizeof(brightness_path),
+		 "%s/%s", INTEL_BACKLIGHT_PATH, "max_brightness");
+	fd = open(brightness_path, O_RDONLY);
+	igt_assert_f(fd >= 0, "Failed to open %s\n", brightness_path);
+
+	igt_assert(read(fd, brightness_value, sizeof(brightness_value)) > 0);
+
+	max_brightness = atoi(brightness_value);
+
+	close(fd);
+
+	/* Get current brightness */
+	snprintf(brightness_path, sizeof(brightness_path),
+		 "%s/%s", INTEL_BACKLIGHT_PATH, "brightness");
+	fd = open(brightness_path, O_RDONLY);
+	igt_assert_f(fd >= 0, "Failed to open %s\n", brightness_path);
+
+	igt_assert(read(fd, brightness_value, sizeof(brightness_value)) > 0);
+
+	current_brightness = atoi(brightness_value);
+
+	close(fd);
+
+	for (i = 0; i <= max_brightness; i += 50) {
+		fd = open(brightness_path, O_WRONLY);
+		igt_assert_f(fd >= 0, "Failed to open %s\n", brightness_path);
+
+		snprintf(brightness_value, sizeof(brightness_value), "%d", i);
+		igt_assert(write(fd, brightness_value, strlen(brightness_value)) > 0);
+
+		close(fd);
+
+		/* Verify brightness adjustment */
+		fd = open(brightness_path, O_RDONLY);
+		igt_assert(fd >= 0);
+
+		igt_assert(read(fd, brightness_value, sizeof(brightness_value)) > 0);
+
+		read_brightness = atoi(brightness_value);
+
+		igt_assert_eq(read_brightness, i);
+
+		close(fd);
+	}
+
+	fd = open(brightness_path, O_WRONLY);
+	igt_assert_f(fd >= 0, "Failed to open %s\n", brightness_path);
+
+	snprintf(brightness_value, sizeof(brightness_value), "%d", current_brightness);
+	igt_assert(write(brightness_fd, brightness_value, strlen(brightness_value)) > 0);
+
+	close(fd);
+}
+
 static void test_static_toggle(data_t *data, enum pipe pipe,
 			       igt_output_t *output,
 			       uint32_t flags)
@@ -483,6 +556,9 @@ static void test_static_toggle(data_t *data, enum pipe pipe,
 		igt_assert_eq(system("dmesg|tail -n 1000|grep -E \"Unknown EOTF [0-9]+\""), 0);
 		goto cleanup;
 	}
+	if (flags & TEST_BRIGHTNESS)
+		adjust_brightness(data, flags);
+
 	igt_assert_output_bpc_equal(data->fd, pipe, output->name, 10);
 
 	/* Verify that the CRC are equal after DPMS or suspend. */
@@ -685,7 +761,8 @@ static void test_hdr(data_t *data, uint32_t flags)
 
 			igt_dynamic_f("pipe-%s-%s",
 				      kmstest_pipe_name(pipe), output->name) {
-				if (flags & (TEST_NONE | TEST_DPMS | TEST_SUSPEND | TEST_INVALID_HDR))
+				if (flags & (TEST_NONE | TEST_DPMS | TEST_SUSPEND |
+					     TEST_INVALID_HDR | TEST_BRIGHTNESS))
 					test_static_toggle(data, pipe, output, flags);
 				if (flags & TEST_SWAP)
 					test_static_swap(data, pipe, output);
@@ -734,6 +811,10 @@ igt_main
 	igt_subtest_with_dynamic("static-toggle-suspend")
 		test_hdr(&data, TEST_SUSPEND);
 
+	igt_describe("Tests brightness while entering and exiting HDR mode");
+	igt_subtest_with_dynamic("brightness-with-hdr")
+		test_hdr(&data, TEST_BRIGHTNESS);
+
 	igt_describe("Tests swapping static HDR metadata");
 	igt_subtest_with_dynamic("static-swap")
 		test_hdr(&data, TEST_SWAP);
-- 
2.34.1



More information about the igt-dev mailing list