Igt-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Gil Dekel <gildekel@google.com>
To: igt-dev@lists.freedesktop.org
Cc: Gil Dekel <gildekel@google.com>,
	Swati Sharma <swati2.sharma@intel.com>,
	 Karthik B S <karthik.b.s@intel.com>,
	Jani Nikula <jani.nikula@intel.com>,
	 Kamil Konieczny <kamil.konieczny@linux.intel.com>,
	Mark Yacoub <markyacoub@google.com>
Subject: [PATCH i-g-t] tests/kms_hdr: Use /dev/kmsg in invalid-hdr
Date: Tue, 24 Nov 2026 14:44:38 -0500	[thread overview]
Message-ID: <20261124194438.314352-1-gildekel@google.com> (raw)

invalid-hdr checks that the kernel rejected the EOTF by running
system("dmesg|tail -n 1000|grep -E \"Unknown EOTF [0-9]+\""). That grep
also matches "Unknown EOTF" lines left in the ring buffer by earlier
format iterations, the preceding TEST_ONLY check, or other outputs, so
it can pass when the commit under test logged nothing; conversely,
verbose DRM_UT_KMS modeset logs after infoframe setup can push the line
past tail -n 1000. It also requires sh, dmesg, tail, and grep on the
target.

Open /dev/kmsg with O_NONBLOCK and seek to SEEK_END right before the
HDR metadata commit (skipping if /dev/kmsg is inaccessible). After the
commit, read records until EAGAIN, continue past EPIPE if older records
were overwritten, and assert that a record logged during this commit
contains "Unknown EOTF <n>".

Cc: Swati Sharma <swati2.sharma@intel.com>
Cc: Karthik B S <karthik.b.s@intel.com>
Cc: Jani Nikula <jani.nikula@intel.com>
Cc: Kamil Konieczny <kamil.konieczny@linux.intel.com>
Cc: Mark Yacoub <markyacoub@google.com>
Assisted-by: Claude:claude-fable-5.2
Signed-off-by: Gil Dekel <gildekel@google.com>
---

Notes:
    Resent standalone after withdrawing patches 1/3 and 2/3 of the HDR
    DisplayID series in favor of Simon Ser's libdisplay-info conversion:
    https://lists.freedesktop.org/archives/igt-dev/2026-November/118994.html
    
    Changes since patch 3/3 of that series:
    - Skip cleanly on EACCES/EPERM/ENOENT when opening /dev/kmsg in
      restricted environments.

 tests/kms_hdr.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 50 insertions(+), 1 deletion(-)

diff --git a/tests/kms_hdr.c b/tests/kms_hdr.c
index e23d5e469..e273c6932 100644
--- a/tests/kms_hdr.c
+++ b/tests/kms_hdr.c
@@ -29,6 +29,8 @@
  */
 
 #include "igt.h"
+#include <ctype.h>
+#include <errno.h>
 #include <fcntl.h>
 #include <termios.h>
 #include <unistd.h>
@@ -354,6 +356,46 @@ static void adjust_brightness(data_t *data, uint32_t flags)
 	igt_assert_eq(igt_backlight_write(context.old, "brightness", &context), 0);
 }
 
+/*
+ * Opens /dev/kmsg positioned at its end, so that only kernel messages
+ * logged after this call are read back.
+ */
+static int kmsg_open_at_end(void)
+{
+	int fd = open("/dev/kmsg", O_RDONLY | O_NONBLOCK);
+
+	if (fd < 0 && (errno == EACCES || errno == EPERM || errno == ENOENT))
+		igt_skip("Cannot open /dev/kmsg: %s\n", strerror(errno));
+	igt_assert_f(fd >= 0, "Failed to open /dev/kmsg: %s\n", strerror(errno));
+	igt_assert(lseek(fd, 0, SEEK_END) >= 0);
+
+	return fd;
+}
+
+/* Returns true if a record read from @kmsg_fd contains "Unknown EOTF <n>". */
+static bool kmsg_has_unknown_eotf(int kmsg_fd)
+{
+	static const char pattern[] = "Unknown EOTF ";
+	char buf[8192];
+	ssize_t len;
+
+	for (;;) {
+		const char *match;
+
+		/* Each read() returns one record, EAGAIN once drained. */
+		len = read(kmsg_fd, buf, sizeof(buf) - 1);
+		if (len < 0 && errno == EPIPE)
+			continue; /* Older records were overwritten, keep going. */
+		if (len <= 0)
+			return false;
+
+		buf[len] = '\0';
+		match = strstr(buf, pattern);
+		if (match && isdigit((unsigned char)match[sizeof(pattern) - 1]))
+			return true;
+	}
+}
+
 static void test_static_toggle(data_t *data, igt_crtc_t *crtc,
 			       uint32_t format, uint32_t flags)
 {
@@ -361,6 +403,7 @@ static void test_static_toggle(data_t *data, igt_crtc_t *crtc,
 	struct hdr_output_metadata hdr;
 	igt_crc_t ref_crc, new_crc;
 	int afb_id;
+	int kmsg_fd = -1;
 
 	/* 10-bit formats are slow, so limit the size. */
 	afb_id = igt_create_fb(data->fd, 512, 512,
@@ -392,11 +435,17 @@ static void test_static_toggle(data_t *data, igt_crtc_t *crtc,
 	}
 
 	/* Apply HDR metadata and 10bpc. We expect a modeset for entering. */
+	if (flags & TEST_INVALID_HDR)
+		kmsg_fd = kmsg_open_at_end();
 	igt_hdr_set_metadata(data->output, &hdr);
 	igt_output_set_prop_value(data->output, IGT_CONNECTOR_MAX_BPC, 10);
 	igt_display_commit_atomic(display, DRM_MODE_ATOMIC_ALLOW_MODESET, NULL);
 	if (flags & TEST_INVALID_HDR) {
-		igt_assert_eq(system("dmesg|tail -n 1000|grep -E \"Unknown EOTF [0-9]+\""), 0);
+		bool logged = kmsg_has_unknown_eotf(kmsg_fd);
+
+		close(kmsg_fd);
+		igt_assert_f(logged,
+			     "Kernel did not log \"Unknown EOTF\" for invalid HDR metadata\n");
 		return;
 	}
 
-- 
Gil Dekel, Senior SWE, Google | Android Laptops & Tablets Display


             reply	other threads:[~2026-11-25  9:51 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 19:44 Gil Dekel [this message]
2026-11-25 20:43 ` ✓ Xe.CI.BAT: success for tests/kms_hdr: Use /dev/kmsg in invalid-hdr Patchwork
2026-11-25 20:55 ` ✓ i915.CI.BAT: " Patchwork
2026-11-26  4:46 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-11-27  2:39 ` ✗ i915.CI.Full: " Patchwork
2026-12-01 20:26 ` [PATCH i-g-t] " Gil Dekel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261124194438.314352-1-gildekel@google.com \
    --to=gildekel@google.com \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=jani.nikula@intel.com \
    --cc=kamil.konieczny@linux.intel.com \
    --cc=karthik.b.s@intel.com \
    --cc=markyacoub@google.com \
    --cc=swati2.sharma@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox