Re: [PATCH 3/3] tools/nolibc: add testcases for vfprintf

From: Willy Tarreau
Date: Sun Apr 02 2023 - 03:51:22 EST


On Tue, Mar 28, 2023 at 09:01:31PM +0000, Thomas Weißschuh wrote:
> vfprintf() is complex and so far did not have proper tests.

This is an excellent idea, I totally agree, and I wouldn't be surprised
if there were still bugs there.

> + switch (test + __LINE__ + 1) {
> + CASE_TEST(empty); EXPECT_VFPRINTF(0, "", ""); break;
> + CASE_TEST(simple); EXPECT_VFPRINTF(3, "foo", "foo"); break;
> + CASE_TEST(string); EXPECT_VFPRINTF(3, "foo", "%s", "foo"); break;
> + CASE_TEST(number); EXPECT_VFPRINTF(4, "1234", "%d", 1234); break;
> + CASE_TEST(negnumber); EXPECT_VFPRINTF(5, "-1234", "%d", -1234); break;
> + CASE_TEST(unsigned); EXPECT_VFPRINTF(5, "12345", "%u", 12345); break;
> + CASE_TEST(char); EXPECT_VFPRINTF(1, "c", "%c", 'c'); break;
> + CASE_TEST(hex); EXPECT_VFPRINTF(1, "f", "%x", 0xf); break;
> + CASE_TEST(pointer); EXPECT_VFPRINTF(3, "0x0", "%p", NULL); break;

I don't see a reason why not to move them to the stdlib category, since
these tests are there to validate that the libc-provided functions do
work. Maybe you intended to further extend it ? In this case maybe we
could move that to an "stdio" category then but I'd rather avoid having
one category per function or it will quickly become annoying to select
groups of tests. So let's just prefix these test names with "printf_"
and either merge them with "stdlib" or name the category "stdio", as
you prefer.

Thank you!
Willy