]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
seq_buf: Export seq_buf_putmem_hex() and add KUnit tests
authorShuvam Pandey <shuvampandey1@gmail.com>
Wed, 8 Apr 2026 20:23:51 +0000 (02:08 +0545)
committerSteven Rostedt <rostedt@goodmis.org>
Thu, 21 May 2026 22:03:06 +0000 (18:03 -0400)
The seq_buf KUnit suite does not exercise seq_buf_putmem_hex().

Add one test for the len > 8 chunking path and one overflow test
where a later chunk no longer fits in the buffer.

Export seq_buf_putmem_hex() as well so SEQ_BUF_KUNIT_TEST=m links
cleanly. Without the export, modpost reports seq_buf_putmem_hex as
undefined when seq_buf_kunit is built as a module.

Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: David Gow <david@davidgow.net>
Link: https://patch.msgid.link/20260408202351.21829-1-shuvampandey1@gmail.com
Acked-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Signed-off-by: Shuvam Pandey <shuvampandey1@gmail.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
lib/seq_buf.c
lib/tests/seq_buf_kunit.c

index f3f3436d60a9403eae5b1ef9b091b027881f14fb..b59488fa8135cdb0340fbeb43d8d74db8ae13146 100644 (file)
@@ -298,6 +298,7 @@ int seq_buf_putmem_hex(struct seq_buf *s, const void *mem,
        }
        return 0;
 }
+EXPORT_SYMBOL_GPL(seq_buf_putmem_hex);
 
 /**
  * seq_buf_path - copy a path into the sequence buffer
index 8a01579a978e655cd09024d0ea9c4c9cd095263f..eb466386bbefb1c81773cdae65a8ac3df91cd8ea 100644 (file)
@@ -184,6 +184,38 @@ static void seq_buf_get_buf_commit_test(struct kunit *test)
        KUNIT_EXPECT_TRUE(test, seq_buf_has_overflowed(&s));
 }
 
+static void seq_buf_putmem_hex_test(struct kunit *test)
+{
+       DECLARE_SEQ_BUF(s, 24);
+       const u8 data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+#ifdef __BIG_ENDIAN
+       const char *expected = "0001020304050607 0809 ";
+#else
+       const char *expected = "0706050403020100 0908 ";
+#endif
+
+       KUNIT_EXPECT_EQ(test, seq_buf_putmem_hex(&s, data, sizeof(data)), 0);
+       KUNIT_EXPECT_FALSE(test, seq_buf_has_overflowed(&s));
+       KUNIT_EXPECT_EQ(test, seq_buf_used(&s), strlen(expected));
+       KUNIT_EXPECT_STREQ(test, seq_buf_str(&s), expected);
+}
+
+static void seq_buf_putmem_hex_overflow_test(struct kunit *test)
+{
+       DECLARE_SEQ_BUF(s, 20);
+       const u8 data[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
+#ifdef __BIG_ENDIAN
+       const char *expected = "0001020304050607 ";
+#else
+       const char *expected = "0706050403020100 ";
+#endif
+
+       KUNIT_EXPECT_EQ(test, seq_buf_putmem_hex(&s, data, sizeof(data)), -1);
+       KUNIT_EXPECT_TRUE(test, seq_buf_has_overflowed(&s));
+       KUNIT_EXPECT_EQ(test, seq_buf_used(&s), 20);
+       KUNIT_EXPECT_STREQ(test, seq_buf_str(&s), expected);
+}
+
 static struct kunit_case seq_buf_test_cases[] = {
        KUNIT_CASE(seq_buf_init_test),
        KUNIT_CASE(seq_buf_declare_test),
@@ -194,6 +226,8 @@ static struct kunit_case seq_buf_test_cases[] = {
        KUNIT_CASE(seq_buf_printf_test),
        KUNIT_CASE(seq_buf_printf_overflow_test),
        KUNIT_CASE(seq_buf_get_buf_commit_test),
+       KUNIT_CASE(seq_buf_putmem_hex_test),
+       KUNIT_CASE(seq_buf_putmem_hex_overflow_test),
        {}
 };