[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260130083737.1123-2-im.lechain@gmail.com>
Date: Fri, 30 Jan 2026 16:37:36 +0800
From: "licheng.li" <im.lechain@...il.com>
To: Willy Tarreau <w@....eu>,
David Laight <david.laight.linux@...il.com>
Cc: Thomas Weißschuh <linux@...ssschuh.net>,
linux-kernel@...r.kernel.org,
im.lechain@...il.com
Subject: [PATCH 2/2] selftests/nolibc: add tests for printf zero padding (0)
From: Cheng Li <im.lechain@...il.com>
This patch adds validation for the '0' flag in printf() to ensure correct
behavior for pointers, positive integers, and negative integers.
The tests specifically verify that:
- Pointers include the '0x' prefix before padding.
- Negative numbers include the '-' sign before padding.
- Width and padding are correctly calculated.
Signed-off-by: Cheng Li <im.lechain@...il.com>
---
tools/testing/selftests/nolibc/nolibc-test.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index c11fcf6c5075..77bb8796aa3d 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -1723,6 +1723,9 @@ static int run_printf(int min, int max)
CASE_TEST(truncation); EXPECT_VFPRINTF(25, "01234567890123456789", "%s", "0123456789012345678901234"); break;
CASE_TEST(string_width); EXPECT_VFPRINTF(10, " 1", "%10s", "1"); break;
CASE_TEST(number_width); EXPECT_VFPRINTF(10, " 1", "%10d", 1); break;
+ CASE_TEST(zero_pad_ptr); EXPECT_VFPRINTF(5, "0x005", "%05p", (void *)5); break;
+ CASE_TEST(zero_pad_int); EXPECT_VFPRINTF(5, "00005", "%05d", 5); break;
+ CASE_TEST(zero_pad_neg); EXPECT_VFPRINTF(5, "-0005", "%05d", -5); break;
CASE_TEST(number_left); EXPECT_VFPRINTF(10, "|-5 |", "|%-8d|", -5); break;
CASE_TEST(string_align); EXPECT_VFPRINTF(10, "|foo |", "|%-8s|", "foo"); break;
CASE_TEST(width_trunc); EXPECT_VFPRINTF(25, " ", "%25d", 1); break;
--
2.52.0
Powered by blists - more mailing lists