From: Shuicheng Lin <shuicheng.lin@intel.com>
To: igt-dev@lists.freedesktop.org
Cc: Shuicheng Lin <shuicheng.lin@intel.com>,
Kamil Konieczny <kamil.konieczny@linux.intel.com>
Subject: [PATCH 4/4] runner/resultgen: Decode kmsg escapes in ignored dmesg regex
Date: Wed, 7 Oct 2026 21:06:03 +0000 [thread overview]
Message-ID: <20261007210603.1350158-5-shuicheng.lin@intel.com> (raw)
In-Reply-To: <20261007210603.1350158-1-shuicheng.lin@intel.com>
igt_emit_ignore_dmesg_regex() passes the regex to igt_runner through
/dev/kmsg, which escapes '\' and non-printable characters as "\xNN".
resultgen compiles the ignore regex from the escaped record, so a regex
like "\(-ECANCELED\)" becomes "\x5c(-ECANCELED\x5c)", which requires a
literal backslash and silently never matches.
Factor the existing escape decoding out of
generate_formatted_dmesg_line() and apply it to the ignore regex before
compiling it. While at it, fix the bound check so that an escape at the
very end of the string is decoded too; dmesg lines always end with a
newline so it didn't matter before, but the ignore regex has it
stripped. Extend the dmesg-escapes json test to cover it.
Cc: Kamil Konieczny <kamil.konieczny@linux.intel.com>
Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com>
---
.../json_tests_data/dmesg-escapes/0/dmesg.txt | 2 +
.../json_tests_data/dmesg-escapes/README.txt | 4 ++
.../dmesg-escapes/reference.json | 2 +-
runner/resultgen.c | 48 ++++++++++++-------
4 files changed, 38 insertions(+), 18 deletions(-)
diff --git a/runner/json_tests_data/dmesg-escapes/0/dmesg.txt b/runner/json_tests_data/dmesg-escapes/0/dmesg.txt
index a585c03a0..2f109f5d4 100644
--- a/runner/json_tests_data/dmesg-escapes/0/dmesg.txt
+++ b/runner/json_tests_data/dmesg-escapes/0/dmesg.txt
@@ -9,5 +9,7 @@
6,954,3216186101159,-;Kernel shouldn't output this but cutoff escape \x1
6,954,3216186101159,-;More cutoff \x
6,954,3216186101159,-;One more \
+14,954,3216186101159,-;[IGT] add ignored dmesg regex: \x5c(-ECANCELED\x5c) .* GT: reset failed
+3,954,3216186101159,-;xe 0000:03:00.0: [drm] *ERROR* SIGID=106 FATAL (-ECANCELED) Tile0: GT0: GT: reset failed
14,955,3216186101160,-;[IGT] successtest: exiting, ret=0
6,956,3216186101299,-;Console: switching to colour frame buffer device 240x75
diff --git a/runner/json_tests_data/dmesg-escapes/README.txt b/runner/json_tests_data/dmesg-escapes/README.txt
index fbb7c6c40..9e37f9315 100644
--- a/runner/json_tests_data/dmesg-escapes/README.txt
+++ b/runner/json_tests_data/dmesg-escapes/README.txt
@@ -2,3 +2,7 @@ Unprintable characters in kernel logs, when read via /dev/kmsg, are
escaped as \xNN where NN the character's ascii code in hex. Those are
expected to be decoded to results, if they really are
printable. Kernel's idea of nonprintable is "c < 0x20 || c > 127".
+
+The same applies to regexes from igt_emit_ignore_dmesg_regex(), which
+also go through /dev/kmsg; \x5c must be decoded before the regex is
+compiled so that the error line it matches is ignored.
diff --git a/runner/json_tests_data/dmesg-escapes/reference.json b/runner/json_tests_data/dmesg-escapes/reference.json
index fc1fbd264..0af698fc2 100644
--- a/runner/json_tests_data/dmesg-escapes/reference.json
+++ b/runner/json_tests_data/dmesg-escapes/reference.json
@@ -20,7 +20,7 @@
"end":0
},
"err":"Starting subtest: first-subtest\nSubtest first-subtest: SUCCESS (0.000s)\n",
- "dmesg":"<6> [3216186.095083] Console: switching to colour dummy device 80x25\n<6> [3216186.095097] [IGT] successtest: executing\n<6> [3216186.101115] [IGT] successtest: starting subtest first-subtest\n<6> [3216186.101159] String with a\nnewline\n<6> [3216186.101159] String with a\ttab\n<6> [3216186.101159] String with an explicit\\x00NUL\n<6> [3216186.101159] The character \\x13 should be nonprintable\n<6> [3216186.101159] Escaped backslash is \\\n<6> [3216186.101159] Kernel shouldn't output this but cutoff escape \\x1\n<6> [3216186.101159] More cutoff \\x\n<6> [3216186.101159] One more \\\n<6> [3216186.101160] [IGT] successtest: exiting, ret=0\n<6> [3216186.101299] Console: switching to colour frame buffer device 240x75\n"
+ "dmesg":"<6> [3216186.095083] Console: switching to colour dummy device 80x25\n<6> [3216186.095097] [IGT] successtest: executing\n<6> [3216186.101115] [IGT] successtest: starting subtest first-subtest\n<6> [3216186.101159] String with a\nnewline\n<6> [3216186.101159] String with a\ttab\n<6> [3216186.101159] String with an explicit\\x00NUL\n<6> [3216186.101159] The character \\x13 should be nonprintable\n<6> [3216186.101159] Escaped backslash is \\\n<6> [3216186.101159] Kernel shouldn't output this but cutoff escape \\x1\n<6> [3216186.101159] More cutoff \\x\n<6> [3216186.101159] One more \\\n<6> [3216186.101159] [IGT] add ignored dmesg regex: \\(-ECANCELED\\) .* GT: reset failed\n<3> [3216186.101159] xe 0000:03:00.0: [drm] *ERROR* SIGID=106 FATAL (-ECANCELED) Tile0: GT0: GT: reset failed\n<6> [3216186.101160] [IGT] successtest: exiting, ret=0\n<6> [3216186.101299] Console: switching to colour frame buffer device 240x75\n"
}
},
"totals":{
diff --git a/runner/resultgen.c b/runner/resultgen.c
index f5a91f542..127d8a9e8 100644
--- a/runner/resultgen.c
+++ b/runner/resultgen.c
@@ -877,6 +877,33 @@ static void clean_regex(GRegex **re)
*re = NULL;
}
+/*
+ * Decode the "\\xNN" escapes that /dev/kmsg uses for '\\' and non-printable
+ * characters. @dst may be the same as @src, as the decoded string is never
+ * longer than the original.
+ */
+static void decode_kmsg_escapes(char *dst, const char *src)
+{
+ size_t len = strlen(src);
+ const char *p;
+
+ for (p = src; *p; p++, dst++) {
+ if (p - src + 3 < len &&
+ p[0] == '\\' && p[1] == 'x') {
+ int c = 0;
+ /* newline and tab are not isprint(), but they are isspace() */
+ if (sscanf(p, "\\x%2x", &c) == 1 &&
+ (isprint(c) || isspace(c))) {
+ *dst = c;
+ p += 3;
+ continue;
+ }
+ }
+ *dst = *p;
+ }
+ *dst = '\0';
+}
+
static void add_ignored_regex(GRegex **re, char *src)
{
char *s;
@@ -885,6 +912,9 @@ static void add_ignored_regex(GRegex **re, char *src)
if (s)
*s = 0;
+ /* The regex was emitted via /dev/kmsg, undo its escaping */
+ decode_kmsg_escapes(src, src);
+
if (*re)
g_regex_unref(*re);
@@ -929,7 +959,6 @@ static void generate_formatted_dmesg_line(char *message,
char prefix[512];
size_t messagelen;
size_t prefixlen;
- char *p, *f;
snprintf(prefix, sizeof(prefix),
"<%u> [%llu.%06llu] ",
@@ -947,22 +976,7 @@ static void generate_formatted_dmesg_line(char *message,
*formatted = malloc(strlen(prefix) + messagelen + 1);
strcpy(*formatted, prefix);
- f = *formatted + prefixlen;
- for (p = message; *p; p++, f++) {
- if (p - message + 4 < messagelen &&
- p[0] == '\\' && p[1] == 'x') {
- int c = 0;
- /* newline and tab are not isprint(), but they are isspace() */
- if (sscanf(p, "\\x%2x", &c) == 1 &&
- (isprint(c) || isspace(c))) {
- *f = c;
- p += 3;
- continue;
- }
- }
- *f = *p;
- }
- *f = '\0';
+ decode_kmsg_escapes(*formatted + prefixlen, message);
}
static void add_dmesg(struct json_t *obj,
--
2.43.0
next prev parent reply other threads:[~2026-10-07 21:09 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-07 21:05 [PATCH 0/4] Fix dmesg ignore regexes with backslash escapes Shuicheng Lin
2026-10-07 21:06 ` [PATCH 1/4] tests/intel/xe_exec_reset: Fix gt reset fault dmesg ignore regex Shuicheng Lin
2026-10-07 21:11 ` Cavitt, Jonathan
2026-10-08 15:07 ` Kamil Konieczny
2026-10-08 22:19 ` Lin, Shuicheng
2026-10-07 21:06 ` [PATCH 2/4] tests/intel/xe_wedged: Fix wedged " Shuicheng Lin
2026-10-08 14:33 ` Kamil Konieczny
2026-10-08 22:49 ` Lin, Shuicheng
2026-10-07 21:06 ` [PATCH 3/4] tests/intel/xe_fault_injection: Avoid backslash escapes in " Shuicheng Lin
2026-10-08 14:36 ` Kamil Konieczny
2026-10-08 22:58 ` Lin, Shuicheng
2026-10-07 21:06 ` Shuicheng Lin [this message]
2026-10-08 15:02 ` [PATCH 4/4] runner/resultgen: Decode kmsg escapes in ignored dmesg regex Kamil Konieczny
2026-10-08 23:50 ` Lin, Shuicheng
2026-10-07 21:56 ` ✓ i915.CI.BAT: success for Fix dmesg ignore regexes with backslash escapes Patchwork
2026-10-07 22:23 ` ✓ Xe.CI.BAT: " Patchwork
2026-10-08 2:12 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-10-08 6:19 ` ✓ i915.CI.Full: success " 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=20261007210603.1350158-5-shuicheng.lin@intel.com \
--to=shuicheng.lin@intel.com \
--cc=igt-dev@lists.freedesktop.org \
--cc=kamil.konieczny@linux.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.