Re: [PATCH v2 next 10/11] selftests/nolibc: Increase coverage of printf format tests

From: Thomas Weißschuh

Date: Mon Feb 16 2026 - 15:23:59 EST


On 2026-02-06 19:11:20+0000, david.laight.linux@xxxxxxxxx wrote:
> From: David Laight <david.laight.linux@xxxxxxxxx>
>
> Extra tests include:
> - %%, including ignored modifiers.
> - Invalid formats copied to output buffer (matches glibc).
> - Left aligned output "%-..."
> - Zero padding "%0...".
> - "(nil)" for NULL pointers (matches glibc).
> - Alternate form "%#x" (prepends 0x in non-zero).
> - Field precision as well as width, printf("%.0d", 0) is "".
> - Variable length width and precision "%*.*d".
> - Length qualifiers L and ll.
> - Conversion specifiers i and X.
> - More 'corner' cases.
>
> There are no explicit tests of long (l, t or z) because they would
> have to differ between 32bit and 64bit.
>
> Set the expected length to zero for all the non-truncating tests.
> (Annoying when a test is changed.)
>
> Signed-off-by: David Laight <david.laight.linux@xxxxxxxxx>
> ---
>
> Changes for v2:
> - Formally patch 11.
> - Remove broken __attribute__ on expect_vfprintf().
> - Add extra test for "#01x".
>
> tools/testing/selftests/nolibc/nolibc-test.c | 49 +++++++++++++++-----
> 1 file changed, 37 insertions(+), 12 deletions(-)

(...)

> + CASE_TEST(num_pad_trunc);EXPECT_VFPRINTF(40, " 0000000000", "%040d", 5); break; /* max 30 '0' can be added */

This fails in 'libc-test' with glibc and musl:

32 num_pad_trunc "00000000000000000000" should be " 0000000000" [FAIL]

> + CASE_TEST(number_prec); EXPECT_VFPRINTF(0, " 00005", "%10.5d", 5); break;

(...)