[PATCH] printf: add escaped-string format tests
From: Shuvam Pandey
Date: Sun Apr 05 2026 - 20:42:51 EST
printf_kunit leaves escaped_str() empty even though printk-formats.rst
documents %*pE conversions and says that omitting the field width
escapes one byte only.
Add tests for the documented %*pE, %*pEhp, and %*pEa conversions, and
for the single-byte %pE default when the field width is omitted.
Signed-off-by: Shuvam Pandey <shuvampandey1@xxxxxxxxx>
---
lib/tests/printf_kunit.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/lib/tests/printf_kunit.c b/lib/tests/printf_kunit.c
index f6f21b445..8ea67abf1 100644
--- a/lib/tests/printf_kunit.c
+++ b/lib/tests/printf_kunit.c
@@ -394,6 +394,14 @@ addr(struct kunit *kunittest)
static void
escaped_str(struct kunit *kunittest)
{
+ const u8 buf[] = { 0x1b, 0x62, 0x20, 0x5c, 0x43,
+ 0x07, 0x22, 0x90, 0x0d, 0x5d };
+
+ test("\\eb \\C\\a\"\\220\\r]", "%*pE", 10, buf);
+ test("\\x1bb \\C\\x07\"\\x90\\x0d]", "%*pEhp", 10, buf);
+ test("\\e\\142\\040\\\\\\103\\a\\\"\\220\\r\\135",
+ "%*pEa", 10, buf);
+ test("\\e", "%pE", buf);
}
static void