From: "licheng.li" <im.lechain@gmail.com>
To: Willy Tarreau <w@1wt.eu>
Cc: "Thomas Weißschuh" <linux@weissschuh.net>,
linux-kernel@vger.kernel.org, im.lechain@gmail.com
Subject: [PATCH v2 2/2] selftests/nolibc: add tests for printf left alignment and zero padding
Date: Wed, 28 Jan 2026 17:42:24 +0800 [thread overview]
Message-ID: <20260128094224.11299-3-im.lechain@gmail.com> (raw)
In-Reply-To: <20260128094224.11299-1-im.lechain@gmail.com>
From: Cheng Li <im.lechain@gmail.com>
This patch adds validation for the recently added left-alignment ('-')
and zero-padding ('0') flags in printf().
It ensures that:
- Fields are correctly padded with spaces on the right when the '-'
flag is used.
- Integers are correctly padded with zeroes on the left when the '0'
flag is used.
Signed-off-by: Cheng Li <im.lechain@gmail.com>
---
v2 changes:
- Added test cases for zero padding (%08d)
---
tools/testing/selftests/nolibc/nolibc-test.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 3c5a226dad3a..47b20ecf5242 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -1723,6 +1723,8 @@ 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(leading_zero); EXPECT_VFPRINTF(10, "|00000001|", "|%08d|", 1); break;
+ CASE_TEST(left_align); EXPECT_VFPRINTF(10, "|foo |", "|%-8s|", "foo"); break;
CASE_TEST(width_trunc); EXPECT_VFPRINTF(25, " ", "%25d", 1); break;
CASE_TEST(scanf); EXPECT_ZR(1, test_scanf()); break;
CASE_TEST(strerror); EXPECT_ZR(1, test_strerror()); break;
--
2.52.0
prev parent reply other threads:[~2026-01-28 9:42 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-28 9:42 [PATCH v2 0/2] tools/nolibc: printf left alignment and zero padding licheng.li
2026-01-28 9:42 ` [PATCH v2 1/2] tools/nolibc: support left alignment (-) and zero padding (0) in printf licheng.li
2026-01-29 6:41 ` Willy Tarreau
2026-01-29 6:57 ` licheng
2026-01-29 7:07 ` Willy Tarreau
2026-01-29 10:30 ` David Laight
2026-01-30 1:05 ` Cheng Li
2026-01-30 8:01 ` David Laight
2026-01-30 9:52 ` Cheng Li
2026-01-28 9:42 ` licheng.li [this message]
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=20260128094224.11299-3-im.lechain@gmail.com \
--to=im.lechain@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=w@1wt.eu \
/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