summaryrefslogtreecommitdiff
path: root/tools/testing
diff options
context:
space:
mode:
authorDavid Laight <david.laight.linux@gmail.com>2026-03-08 14:37:34 +0300
committerThomas Weißschuh <linux@weissschuh.net>2026-03-20 19:55:28 +0300
commit125632871929e9bf5b0bc907c8fef2d326e4623a (patch)
tree24fd554509943c5d478d766db7c91d2dbd8fcc7f /tools/testing
parent85f1152778f8cdc563ada12a3fc48c962b408d94 (diff)
downloadlinux-125632871929e9bf5b0bc907c8fef2d326e4623a.tar.xz
tools/nolibc/printf: Add support for length modifiers tzqL and formats iX
Length modifiers t (ptrdiff_t) and z (size_t) are aliases for l (long), q and L are 64bit the same as j (intmax). Format i is an alias for d and X similar to x but upper case. Supporting them is mostly just adding the relevant bit to the bit pattern used for matching characters. Although %X is detected the output will be lower case. Change/add tests to use conversions i and X, and length modifiers L and ll. Use the correct minimum value for "%Li". Signed-off-by: David Laight <david.laight.linux@gmail.com> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260308113742.12649-10-david.laight.linux@gmail.com [Thomas: Fix up testcases for musl libc] Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Diffstat (limited to 'tools/testing')
-rw-r--r--tools/testing/selftests/nolibc/nolibc-test.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index d8949aa1dee3..6fa2346c655a 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -1834,11 +1834,19 @@ static int run_printf(int min, int max)
CASE_TEST(number); EXPECT_VFPRINTF(1, "1234", "%d", 1234); break;
CASE_TEST(negnumber); EXPECT_VFPRINTF(1, "-1234", "%d", -1234); break;
CASE_TEST(unsigned); EXPECT_VFPRINTF(1, "12345", "%u", 12345); break;
+ CASE_TEST(signed_max); EXPECT_VFPRINTF(1, "2147483647", "%i", ~0u >> 1); break;
+ CASE_TEST(signed_min); EXPECT_VFPRINTF(1, "-2147483648", "%i", (~0u >> 1) + 1); break;
+ CASE_TEST(unsigned_max); EXPECT_VFPRINTF(1, "4294967295", "%u", ~0u); break;
CASE_TEST(char); EXPECT_VFPRINTF(1, "c", "%c", 'c'); break;
- CASE_TEST(hex); EXPECT_VFPRINTF(1, "f", "%x", 0xf); break;
+ CASE_TEST(hex_nolibc); EXPECT_VFPRINTF(is_nolibc, "|f|d|", "|%x|%X|", 0xf, 0xd); break;
+ CASE_TEST(hex_libc); EXPECT_VFPRINTF(!is_nolibc, "|f|D|", "|%x|%X|", 0xf, 0xd); break;
CASE_TEST(pointer); EXPECT_VFPRINTF(1, "0x1", "%p", (void *) 0x1); break;
- CASE_TEST(uintmax_t); EXPECT_VFPRINTF(1, "18446744073709551615", "%ju", 0xffffffffffffffffULL); break;
- CASE_TEST(intmax_t); EXPECT_VFPRINTF(1, "-9223372036854775807", "%jd", 0x8000000000000001LL); break;
+ CASE_TEST(percent); EXPECT_VFPRINTF(1, "a%d42%69%", "a%%d%d%%%d%%", 42, 69); break;
+ CASE_TEST(perc_qual); EXPECT_VFPRINTF(is_nolibc || is_glibc, "a%d2", "a%-14l%d%d", 2); break;
+ CASE_TEST(invalid); EXPECT_VFPRINTF(is_nolibc || is_glibc, "a%12yx3%y42%P", "a%12yx%d%y%d%P", 3, 42); break;
+ CASE_TEST(intmax_max); EXPECT_VFPRINTF(1, "9223372036854775807", "%lld", ~0ULL >> 1); break;
+ CASE_TEST(intmax_min); EXPECT_VFPRINTF(is_nolibc || is_glibc, "-9223372036854775808", "%Li", (~0ULL >> 1) + 1); break;
+ CASE_TEST(uintmax_max); EXPECT_VFPRINTF(1, "18446744073709551615", "%ju", ~0ULL); break;
CASE_TEST(truncation); EXPECT_VFPRINTF(1, "0123456789012345678901234", "%s", "0123456789012345678901234"); break;
CASE_TEST(string_width); EXPECT_VFPRINTF(1, " 1", "%10s", "1"); break;
CASE_TEST(number_width); EXPECT_VFPRINTF(1, " 1", "%10d", 1); break;