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>,
	Mark Yacoub <markyacoub@google.com>
Subject: [PATCH i-g-t v2 3/3] tests/kms_hdr: Use /dev/kmsg in invalid-hdr
Date: Sat, 14 Nov 2026 19:19:04 -0500	[thread overview]
Message-ID: <20261115001917.2933254-4-gildekel@google.com> (raw)
In-Reply-To: <20261115001917.2933254-1-gildekel@google.com>

invalid-hdr checks that the kernel refused the EOTF by running
system("dmesg|tail -n 1000|grep -E \"Unknown EOTF [0-9]+\"").
That grep also matches "Unknown EOTF" lines left by earlier subtests or
other outputs, so the check can pass even when this commit logged
nothing. It also needs a shell, dmesg and grep on the target.

Open /dev/kmsg with O_NONBLOCK and seek to its end right before the
commit that sets the HDR metadata. After the commit, read the new
records until EAGAIN, skip EPIPE when older records were overwritten,
and assert that one of them contains "Unknown EOTF <n>".

Cc: Swati Sharma <swati2.sharma@intel.com>
Cc: Karthik B S <karthik.b.s@intel.com>
Cc: Mark Yacoub <markyacoub@google.com>
Assisted-by: Claude:claude-opus-5.5
Signed-off-by: Gil Dekel <gildekel@google.com>
---

Notes:
    v2: No changes.

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

diff --git a/tests/kms_hdr.c b/tests/kms_hdr.c
index e23d5e469..acfc38920 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,44 @@ 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);
+
+	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 +401,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 +433,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, Software Engineer, Google / ChromeOS Display and Graphics


  parent reply	other threads:[~2026-11-16  5:29 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-14 22:29 [PATCH i-g-t 0/3] lib/igt_hdr: Find HDR in DisplayID EDIDs Gil Dekel
2026-11-14 22:29 ` [PATCH i-g-t 1/3] lib/igt_hdr: Add a testable igt_is_edid_hdr() Gil Dekel
2026-11-14 22:29 ` [PATCH i-g-t 2/3] lib/igt_hdr: Parse DisplayID CTA data blocks Gil Dekel
2026-11-14 22:29 ` [PATCH i-g-t 3/3] tests/kms_hdr: Use /dev/kmsg in invalid-hdr Gil Dekel
2026-11-15  0:19 ` [PATCH i-g-t v2 0/3] lib/igt_hdr: Find HDR in DisplayID EDIDs Gil Dekel
2026-11-15  0:19   ` [PATCH i-g-t v2 1/3] lib/igt_hdr: Add a testable igt_is_edid_hdr() Gil Dekel
2026-11-15  0:19   ` [PATCH i-g-t v2 2/3] lib/igt_hdr: Parse DisplayID CTA data blocks Gil Dekel
2026-11-15  0:19   ` Gil Dekel [this message]
2026-11-16  7:51 ` ✓ Xe.CI.BAT: success for lib/igt_hdr: Find HDR in DisplayID EDIDs Patchwork
2026-11-16  8:07 ` ✓ i915.CI.BAT: " Patchwork
2026-11-16  9:07 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-11-16  9:40 ` [PATCH i-g-t 0/3] " Jani Nikula
2026-11-17  3:13   ` Gil Dekel
2026-11-16 11:26 ` ✗ i915.CI.Full: failure for " Patchwork

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=20261115001917.2933254-4-gildekel@google.com \
    --to=gildekel@google.com \
    --cc=igt-dev@lists.freedesktop.org \
    --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