summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Laight <david.laight.linux@gmail.com>2026-03-08 11:37:42 +0000
committerThomas Weißschuh <linux@weissschuh.net>2026-03-20 17:58:26 +0100
commit9bc019e7ba1f797ad7e24ebb33f4fa0be011ce5b (patch)
tree24dc15ae858bf73c777c8bb8476c5fa298f99f6a
parent248c7cf60c808f09044af1ce1d2c7c707696dc1e (diff)
downloadlinux-9bc019e7ba1f797ad7e24ebb33f4fa0be011ce5b.tar.gz
linux-9bc019e7ba1f797ad7e24ebb33f4fa0be011ce5b.zip
selftests/nolibc: Use printf variable field widths and precisions
Now that printf supports '*' for field widths and precisions then can be used to simplify the test output. - aligning the "[OK]" strings. - reporting the expected sprintf() output when there is a mismatch. Signed-off-by: David Laight <david.laight.linux@gmail.com> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260308113742.12649-18-david.laight.linux@gmail.com Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
-rw-r--r--tools/testing/selftests/nolibc/nolibc-test.c26
1 files changed, 5 insertions, 21 deletions
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 7836162dcd2f..0ca695acbc44 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -164,21 +164,6 @@ static const char *errorname(int err)
}
}
-static void align_result(size_t llen)
-{
- const size_t align = 64;
- char buf[align];
- size_t n;
-
- if (llen >= align)
- return;
-
- n = align - llen;
- memset(buf, ' ', n);
- buf[n] = '\0';
- fputs(buf, stdout);
-}
-
enum RESULT {
OK,
FAIL,
@@ -196,8 +181,10 @@ static void result(int llen, enum RESULT r)
else
msg = " [FAIL]";
- align_result(llen);
- puts(msg);
+ llen = 64 - llen;
+ if (llen < 0)
+ llen = 0;
+ printf("%*s%s\n", llen, "", msg);
}
/* The tests below are intended to be used by the macroes, which evaluate
@@ -1700,10 +1687,7 @@ static int expect_vfprintf(int llen, const char *expected, const char *fmt, ...)
}
if (memcmp(expected, buf, cmp_len) || buf[cmp_len]) {
- /* Copy and truncate until "%.*s" supported */
- memcpy(buf, expected, cmp_len);
- buf[cmp_len] = 0;
- llen += printf(" should be \"%s\"", buf);
+ llen += printf(" should be \"%.*s\"", VFPRINTF_LEN, expected);
result(llen, FAIL);
return 1;
}