public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Willy Tarreau <w@1wt.eu>
To: "licheng.li" <im.lechain@gmail.com>
Cc: "Thomas Weißschuh" <linux@weissschuh.net>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] selftests/nolibc: add tests for printf left alignment
Date: Wed, 28 Jan 2026 08:51:33 +0100	[thread overview]
Message-ID: <aXnABWo3g2XVN2HK@1wt.eu> (raw)
In-Reply-To: <20260126031038.35387-2-im.lechain@gmail.com>

On Mon, Jan 26, 2026 at 11:10:38AM +0800, licheng.li wrote:
> From: Cheng Li <im.lechain@gmail.com>
> 
> This patch adds validation for the recently added '-' flag support in
> printf(). It ensures that strings and numbers are correctly padded
> with spaces on the right side when the left-alignment flag is used.
> 
> The test adds minimal overhead to the test binary size.
> On x86_64:
> 
>   text    data     bss     dec     hex filename
>  43677     248     112   44037    ac05 nolibc-test (before)
>  43761     248     112   44121    ac59 nolibc-test (after)
> 
> The test logic adds 84 bytes.
> 
> Signed-off-by: Cheng Li <im.lechain@gmail.com>
> ---
>  tools/testing/selftests/nolibc/nolibc-test.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> index 3c5a226dad3a..3d47711cad8f 100644
> --- a/tools/testing/selftests/nolibc/nolibc-test.c
> +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> @@ -1723,6 +1723,7 @@ 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(left_align);   EXPECT_VFPRINTF(10, "foo      |", "%-9s|", "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;

Your first patch also made a special case of the '0', that will
pad with zeroes on the left, and which is not obvious when reading
the code (BTW I'm realizing now that it's not mentioned in the
commit message), so in my opinion your patch should also test for
this case, which could easily be overlooked and broken by accident.

Thanks,
Willy

  reply	other threads:[~2026-01-28  7:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-26  3:10 [PATCH 1/2] tools/nolibc: support left-aligned printing in printf licheng.li
2026-01-26  3:10 ` [PATCH 2/2] selftests/nolibc: add tests for printf left alignment licheng.li
2026-01-28  7:51   ` Willy Tarreau [this message]
2026-01-28  7:47 ` [PATCH 1/2] tools/nolibc: support left-aligned printing in printf Willy Tarreau
2026-01-28  7:53   ` Willy Tarreau

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=aXnABWo3g2XVN2HK@1wt.eu \
    --to=w@1wt.eu \
    --cc=im.lechain@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@weissschuh.net \
    /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