public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] selftests/nolibc: fix libc-test with musl libc
@ 2026-03-18 17:20 Thomas Weißschuh
  2026-03-18 22:52 ` David Laight
  0 siblings, 1 reply; 6+ messages in thread
From: Thomas Weißschuh @ 2026-03-18 17:20 UTC (permalink / raw)
  To: Willy Tarreau, Daniel Palmer, David Laight
  Cc: linux-kernel, Thomas Weißschuh

Some of the nolibc testcases fail on musl. In these cases nolibc mirrors
the non-standard behavior of glibc.

Avoid the failures by only running these testcases on nolibc itself.

Fixes: a5f00be9b3b0 ("tools/nolibc: Add a simple test for writing to a FILE and reading it back")
Fixes: d94393e48c09 ("tools/nolibc/printf: Add support for length modifiers tzqL and formats iX")
Fixes: c2d234d3dc56 ("tools/nolibc/printf: Special case 0 and add support for %#x")
Fixes: 63befd993da4 ("tools/nolibc/printf: Add support for zero padding and field precision")
Fixes: d94393e48c09 ("tools/nolibc/printf: Add support for length modifiers tzqL and formats iX")
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
I am thinking about folding the printf fixups directly into the original
patches. Any objections?
---
 tools/testing/selftests/nolibc/nolibc-test.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 180611aabbfb..b03fb9aeb54e 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -867,7 +867,7 @@ int test_file_stream(void)
 
 	errno = 0;
 	r = fwrite("foo", 1, 3, f);
-	if (r != 0 || errno != EBADF) {
+	if (r != 0 || (is_nolibc && errno != EBADF)) {
 		fclose(f);
 		return -1;
 	}
@@ -1824,13 +1824,13 @@ static int run_printf(int min, int max)
 		CASE_TEST(hex_alt_prec); EXPECT_VFPRINTF(1, "| 0x02|0x03| 0x123|", "|%#5.2x|%#04x|%#6.2x|", 2, 3, 0x123); break;
 		CASE_TEST(hex_0_alt);    EXPECT_VFPRINTF(1, "|0|0000|   00|", "|%#x|%#04x|%#5.2x|", 0, 0, 0); break;
 		CASE_TEST(pointer);      EXPECT_VFPRINTF(1, "0x1", "%p", (void *) 0x1); break;
-		CASE_TEST(pointer_NULL); EXPECT_VFPRINTF(1, "|(nil)|(nil)|", "|%p|%.4p|", (void *)0, (void *)0); break;
-		CASE_TEST(string_NULL);  EXPECT_VFPRINTF(1, "|(null)||(null)|", "|%s|%.5s|%.6s|", (void *)0, (void *)0, (void *)0); break;
+		CASE_TEST(pointer_NULL); EXPECT_VFPRINTF(is_nolibc, "|(nil)|(nil)|", "|%p|%.4p|", (void *)0, (void *)0); break;
+		CASE_TEST(string_NULL);  EXPECT_VFPRINTF(is_nolibc, "|(null)||(null)|", "|%s|%.5s|%.6s|", (void *)0, (void *)0, (void *)0); break;
 		CASE_TEST(percent);      EXPECT_VFPRINTF(1, "a%d42%69%", "a%%d%d%%%d%%", 42, 69); break;
-		CASE_TEST(perc_qual);    EXPECT_VFPRINTF(1, "a%d2", "a%-14l%d%d", 2); break;
-		CASE_TEST(invalid);      EXPECT_VFPRINTF(1, "a%12yx3%y42%P", "a%12yx%d%y%d%P", 3, 42); break;
+		CASE_TEST(perc_qual);    EXPECT_VFPRINTF(is_nolibc, "a%d2", "a%-14l%d%d", 2); break;
+		CASE_TEST(invalid);      EXPECT_VFPRINTF(is_nolibc, "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(1, "-9223372036854775808", "%Li", (~0ULL >> 1) + 1); break;
+		CASE_TEST(intmax_min);   EXPECT_VFPRINTF(is_nolibc, "-9223372036854775808", "%Li", (~0ULL >> 1) + 1); break;
 		CASE_TEST(uintmax_max);  EXPECT_VFPRINTF(1, "18446744073709551615", "%ju", ~0ULL); break;
 		CASE_TEST(truncation);   EXPECT_VFPRINTF(1, "012345678901234567890123456789", "%s", "012345678901234567890123456789"); break;
 		CASE_TEST(string_width); EXPECT_VFPRINTF(1, "         1", "%10s", "1"); break;

---
base-commit: d59131de97ee69ab4e4b8926089a6e953d699b11
change-id: 20260318-nolibc-tests-musl-61c46f82fbec

Best regards,
-- 
Thomas Weißschuh <linux@weissschuh.net>


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] selftests/nolibc: fix libc-test with musl libc
  2026-03-18 17:20 [PATCH] selftests/nolibc: fix libc-test with musl libc Thomas Weißschuh
@ 2026-03-18 22:52 ` David Laight
  2026-03-19 10:52   ` David Laight
  0 siblings, 1 reply; 6+ messages in thread
From: David Laight @ 2026-03-18 22:52 UTC (permalink / raw)
  To: Thomas Weißschuh; +Cc: Willy Tarreau, Daniel Palmer, linux-kernel

On Wed, 18 Mar 2026 18:20:46 +0100
Thomas Weißschuh <linux@weissschuh.net> wrote:

> Some of the nolibc testcases fail on musl. In these cases nolibc mirrors
> the non-standard behavior of glibc.
> 
> Avoid the failures by only running these testcases on nolibc itself.
> 
> Fixes: a5f00be9b3b0 ("tools/nolibc: Add a simple test for writing to a FILE and reading it back")
> Fixes: d94393e48c09 ("tools/nolibc/printf: Add support for length modifiers tzqL and formats iX")
> Fixes: c2d234d3dc56 ("tools/nolibc/printf: Special case 0 and add support for %#x")
> Fixes: 63befd993da4 ("tools/nolibc/printf: Add support for zero padding and field precision")
> Fixes: d94393e48c09 ("tools/nolibc/printf: Add support for length modifiers tzqL and formats iX")
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
> I am thinking about folding the printf fixups directly into the original
> patches. Any objections?
> ---
>  tools/testing/selftests/nolibc/nolibc-test.c | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> index 180611aabbfb..b03fb9aeb54e 100644
> --- a/tools/testing/selftests/nolibc/nolibc-test.c
> +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> @@ -867,7 +867,7 @@ int test_file_stream(void)
>  
>  	errno = 0;
>  	r = fwrite("foo", 1, 3, f);
> -	if (r != 0 || errno != EBADF) {
> +	if (r != 0 || (is_nolibc && errno != EBADF)) {
>  		fclose(f);
>  		return -1;
>  	}
> @@ -1824,13 +1824,13 @@ static int run_printf(int min, int max)
>  		CASE_TEST(hex_alt_prec); EXPECT_VFPRINTF(1, "| 0x02|0x03| 0x123|", "|%#5.2x|%#04x|%#6.2x|", 2, 3, 0x123); break;
>  		CASE_TEST(hex_0_alt);    EXPECT_VFPRINTF(1, "|0|0000|   00|", "|%#x|%#04x|%#5.2x|", 0, 0, 0); break;
>  		CASE_TEST(pointer);      EXPECT_VFPRINTF(1, "0x1", "%p", (void *) 0x1); break;
> -		CASE_TEST(pointer_NULL); EXPECT_VFPRINTF(1, "|(nil)|(nil)|", "|%p|%.4p|", (void *)0, (void *)0); break;
> -		CASE_TEST(string_NULL);  EXPECT_VFPRINTF(1, "|(null)||(null)|", "|%s|%.5s|%.6s|", (void *)0, (void *)0, (void *)0); break;
> +		CASE_TEST(pointer_NULL); EXPECT_VFPRINTF(is_nolibc, "|(nil)|(nil)|", "|%p|%.4p|", (void *)0, (void *)0); break;
> +		CASE_TEST(string_NULL);  EXPECT_VFPRINTF(is_nolibc, "|(null)||(null)|", "|%s|%.5s|%.6s|", (void *)0, (void *)0, (void *)0); break;
>  		CASE_TEST(percent);      EXPECT_VFPRINTF(1, "a%d42%69%", "a%%d%d%%%d%%", 42, 69); break;
> -		CASE_TEST(perc_qual);    EXPECT_VFPRINTF(1, "a%d2", "a%-14l%d%d", 2); break;
> -		CASE_TEST(invalid);      EXPECT_VFPRINTF(1, "a%12yx3%y42%P", "a%12yx%d%y%d%P", 3, 42); break;
> +		CASE_TEST(perc_qual);    EXPECT_VFPRINTF(is_nolibc, "a%d2", "a%-14l%d%d", 2); break;
> +		CASE_TEST(invalid);      EXPECT_VFPRINTF(is_nolibc, "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(1, "-9223372036854775808", "%Li", (~0ULL >> 1) + 1); break;
> +		CASE_TEST(intmax_min);   EXPECT_VFPRINTF(is_nolibc, "-9223372036854775808", "%Li", (~0ULL >> 1) + 1); break;
>  		CASE_TEST(uintmax_max);  EXPECT_VFPRINTF(1, "18446744073709551615", "%ju", ~0ULL); break;
>  		CASE_TEST(truncation);   EXPECT_VFPRINTF(1, "012345678901234567890123456789", "%s", "012345678901234567890123456789"); break;
>  		CASE_TEST(string_width); EXPECT_VFPRINTF(1, "         1", "%10s", "1"); break;

Hmmm....
Those are deliberately matching glibc behaviour, at least annotating that
might be useful.
Can you think of a way of detecting whether glibc is being used?
Even !is_musl might be better than is_nolibc - even even they are the same.

I'm guessing musl doesn't support 'L' as a length modifier for integers ?
(I'm pretty sure that comes from M$.)
The intmax_min test could use %qi instead since that is checking the value as well.
Another test for %Li could be added, I just mixed the formats up a bit.

	David 


> 
> ---
> base-commit: d59131de97ee69ab4e4b8926089a6e953d699b11
> change-id: 20260318-nolibc-tests-musl-61c46f82fbec
> 
> Best regards,


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] selftests/nolibc: fix libc-test with musl libc
  2026-03-18 22:52 ` David Laight
@ 2026-03-19 10:52   ` David Laight
  2026-03-19 16:18     ` Thomas Weißschuh
  0 siblings, 1 reply; 6+ messages in thread
From: David Laight @ 2026-03-19 10:52 UTC (permalink / raw)
  To: Thomas Weißschuh; +Cc: Willy Tarreau, Daniel Palmer, linux-kernel

On Wed, 18 Mar 2026 22:52:31 +0000
David Laight <david.laight.linux@gmail.com> wrote:

> On Wed, 18 Mar 2026 18:20:46 +0100
> Thomas Weißschuh <linux@weissschuh.net> wrote:
> 
> > Some of the nolibc testcases fail on musl. In these cases nolibc mirrors
> > the non-standard behavior of glibc.
> > 
> > Avoid the failures by only running these testcases on nolibc itself.
> > 
> > Fixes: a5f00be9b3b0 ("tools/nolibc: Add a simple test for writing to a FILE and reading it back")
> > Fixes: d94393e48c09 ("tools/nolibc/printf: Add support for length modifiers tzqL and formats iX")
> > Fixes: c2d234d3dc56 ("tools/nolibc/printf: Special case 0 and add support for %#x")
> > Fixes: 63befd993da4 ("tools/nolibc/printf: Add support for zero padding and field precision")
> > Fixes: d94393e48c09 ("tools/nolibc/printf: Add support for length modifiers tzqL and formats iX")
> > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> > ---
> > I am thinking about folding the printf fixups directly into the original
> > patches. Any objections?
> > ---
> >  tools/testing/selftests/nolibc/nolibc-test.c | 12 ++++++------
> >  1 file changed, 6 insertions(+), 6 deletions(-)
> > 
> > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> > index 180611aabbfb..b03fb9aeb54e 100644
> > --- a/tools/testing/selftests/nolibc/nolibc-test.c
> > +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> > @@ -867,7 +867,7 @@ int test_file_stream(void)
> >  
> >  	errno = 0;
> >  	r = fwrite("foo", 1, 3, f);
> > -	if (r != 0 || errno != EBADF) {
> > +	if (r != 0 || (is_nolibc && errno != EBADF)) {
> >  		fclose(f);
> >  		return -1;
> >  	}
> > @@ -1824,13 +1824,13 @@ static int run_printf(int min, int max)
> >  		CASE_TEST(hex_alt_prec); EXPECT_VFPRINTF(1, "| 0x02|0x03| 0x123|", "|%#5.2x|%#04x|%#6.2x|", 2, 3, 0x123); break;
> >  		CASE_TEST(hex_0_alt);    EXPECT_VFPRINTF(1, "|0|0000|   00|", "|%#x|%#04x|%#5.2x|", 0, 0, 0); break;
> >  		CASE_TEST(pointer);      EXPECT_VFPRINTF(1, "0x1", "%p", (void *) 0x1); break;
> > -		CASE_TEST(pointer_NULL); EXPECT_VFPRINTF(1, "|(nil)|(nil)|", "|%p|%.4p|", (void *)0, (void *)0); break;
> > -		CASE_TEST(string_NULL);  EXPECT_VFPRINTF(1, "|(null)||(null)|", "|%s|%.5s|%.6s|", (void *)0, (void *)0, (void *)0); break;
> > +		CASE_TEST(pointer_NULL); EXPECT_VFPRINTF(is_nolibc, "|(nil)|(nil)|", "|%p|%.4p|", (void *)0, (void *)0); break;
> > +		CASE_TEST(string_NULL);  EXPECT_VFPRINTF(is_nolibc, "|(null)||(null)|", "|%s|%.5s|%.6s|", (void *)0, (void *)0, (void *)0); break;
> >  		CASE_TEST(percent);      EXPECT_VFPRINTF(1, "a%d42%69%", "a%%d%d%%%d%%", 42, 69); break;
> > -		CASE_TEST(perc_qual);    EXPECT_VFPRINTF(1, "a%d2", "a%-14l%d%d", 2); break;
> > -		CASE_TEST(invalid);      EXPECT_VFPRINTF(1, "a%12yx3%y42%P", "a%12yx%d%y%d%P", 3, 42); break;
> > +		CASE_TEST(perc_qual);    EXPECT_VFPRINTF(is_nolibc, "a%d2", "a%-14l%d%d", 2); break;
> > +		CASE_TEST(invalid);      EXPECT_VFPRINTF(is_nolibc, "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(1, "-9223372036854775808", "%Li", (~0ULL >> 1) + 1); break;
> > +		CASE_TEST(intmax_min);   EXPECT_VFPRINTF(is_nolibc, "-9223372036854775808", "%Li", (~0ULL >> 1) + 1); break;
> >  		CASE_TEST(uintmax_max);  EXPECT_VFPRINTF(1, "18446744073709551615", "%ju", ~0ULL); break;
> >  		CASE_TEST(truncation);   EXPECT_VFPRINTF(1, "012345678901234567890123456789", "%s", "012345678901234567890123456789"); break;
> >  		CASE_TEST(string_width); EXPECT_VFPRINTF(1, "         1", "%10s", "1"); break;  
> 
> Hmmm....
> Those are deliberately matching glibc behaviour, at least annotating that
> might be useful.
> Can you think of a way of detecting whether glibc is being used?
> Even !is_musl might be better than is_nolibc - even even they are the same.

Thinking more, the nil/null tests want is_nolibc || is_glibc.
Setting is_glibc might be hard (unless done from the command line).
The musl people think you don't need to know because their library is conformant.
I found something from someone trying to detect pthread_setname_np(),
glibc's features.h will set __USE_GNU (and similar) that musl doesn't set.
There might also be issues with bionic and uClibc.

	David

> 
> I'm guessing musl doesn't support 'L' as a length modifier for integers ?
> (I'm pretty sure that comes from M$.)
> The intmax_min test could use %qi instead since that is checking the value as well.
> Another test for %Li could be added, I just mixed the formats up a bit.
> 
> 	David 
> 
> 
> > 
> > ---
> > base-commit: d59131de97ee69ab4e4b8926089a6e953d699b11
> > change-id: 20260318-nolibc-tests-musl-61c46f82fbec
> > 
> > Best regards,  
> 
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] selftests/nolibc: fix libc-test with musl libc
  2026-03-19 10:52   ` David Laight
@ 2026-03-19 16:18     ` Thomas Weißschuh
  2026-03-19 22:44       ` David Laight
  0 siblings, 1 reply; 6+ messages in thread
From: Thomas Weißschuh @ 2026-03-19 16:18 UTC (permalink / raw)
  To: David Laight; +Cc: Willy Tarreau, Daniel Palmer, linux-kernel

On 2026-03-19 10:52:07+0000, David Laight wrote:
> On Wed, 18 Mar 2026 22:52:31 +0000
> David Laight <david.laight.linux@gmail.com> wrote:
> 
> > On Wed, 18 Mar 2026 18:20:46 +0100
> > Thomas Weißschuh <linux@weissschuh.net> wrote:
> > 
> > > Some of the nolibc testcases fail on musl. In these cases nolibc mirrors
> > > the non-standard behavior of glibc.
> > > 
> > > Avoid the failures by only running these testcases on nolibc itself.
> > > 
> > > Fixes: a5f00be9b3b0 ("tools/nolibc: Add a simple test for writing to a FILE and reading it back")
> > > Fixes: d94393e48c09 ("tools/nolibc/printf: Add support for length modifiers tzqL and formats iX")
> > > Fixes: c2d234d3dc56 ("tools/nolibc/printf: Special case 0 and add support for %#x")
> > > Fixes: 63befd993da4 ("tools/nolibc/printf: Add support for zero padding and field precision")
> > > Fixes: d94393e48c09 ("tools/nolibc/printf: Add support for length modifiers tzqL and formats iX")
> > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> > > ---
> > > I am thinking about folding the printf fixups directly into the original
> > > patches. Any objections?
> > > ---
> > >  tools/testing/selftests/nolibc/nolibc-test.c | 12 ++++++------
> > >  1 file changed, 6 insertions(+), 6 deletions(-)
> > > 
> > > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> > > index 180611aabbfb..b03fb9aeb54e 100644
> > > --- a/tools/testing/selftests/nolibc/nolibc-test.c
> > > +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> > > @@ -867,7 +867,7 @@ int test_file_stream(void)
> > >  
> > >  	errno = 0;
> > >  	r = fwrite("foo", 1, 3, f);
> > > -	if (r != 0 || errno != EBADF) {
> > > +	if (r != 0 || (is_nolibc && errno != EBADF)) {
> > >  		fclose(f);
> > >  		return -1;
> > >  	}
> > > @@ -1824,13 +1824,13 @@ static int run_printf(int min, int max)
> > >  		CASE_TEST(hex_alt_prec); EXPECT_VFPRINTF(1, "| 0x02|0x03| 0x123|", "|%#5.2x|%#04x|%#6.2x|", 2, 3, 0x123); break;
> > >  		CASE_TEST(hex_0_alt);    EXPECT_VFPRINTF(1, "|0|0000|   00|", "|%#x|%#04x|%#5.2x|", 0, 0, 0); break;
> > >  		CASE_TEST(pointer);      EXPECT_VFPRINTF(1, "0x1", "%p", (void *) 0x1); break;
> > > -		CASE_TEST(pointer_NULL); EXPECT_VFPRINTF(1, "|(nil)|(nil)|", "|%p|%.4p|", (void *)0, (void *)0); break;
> > > -		CASE_TEST(string_NULL);  EXPECT_VFPRINTF(1, "|(null)||(null)|", "|%s|%.5s|%.6s|", (void *)0, (void *)0, (void *)0); break;
> > > +		CASE_TEST(pointer_NULL); EXPECT_VFPRINTF(is_nolibc, "|(nil)|(nil)|", "|%p|%.4p|", (void *)0, (void *)0); break;
> > > +		CASE_TEST(string_NULL);  EXPECT_VFPRINTF(is_nolibc, "|(null)||(null)|", "|%s|%.5s|%.6s|", (void *)0, (void *)0, (void *)0); break;
> > >  		CASE_TEST(percent);      EXPECT_VFPRINTF(1, "a%d42%69%", "a%%d%d%%%d%%", 42, 69); break;
> > > -		CASE_TEST(perc_qual);    EXPECT_VFPRINTF(1, "a%d2", "a%-14l%d%d", 2); break;
> > > -		CASE_TEST(invalid);      EXPECT_VFPRINTF(1, "a%12yx3%y42%P", "a%12yx%d%y%d%P", 3, 42); break;
> > > +		CASE_TEST(perc_qual);    EXPECT_VFPRINTF(is_nolibc, "a%d2", "a%-14l%d%d", 2); break;
> > > +		CASE_TEST(invalid);      EXPECT_VFPRINTF(is_nolibc, "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(1, "-9223372036854775808", "%Li", (~0ULL >> 1) + 1); break;
> > > +		CASE_TEST(intmax_min);   EXPECT_VFPRINTF(is_nolibc, "-9223372036854775808", "%Li", (~0ULL >> 1) + 1); break;
> > >  		CASE_TEST(uintmax_max);  EXPECT_VFPRINTF(1, "18446744073709551615", "%ju", ~0ULL); break;
> > >  		CASE_TEST(truncation);   EXPECT_VFPRINTF(1, "012345678901234567890123456789", "%s", "012345678901234567890123456789"); break;
> > >  		CASE_TEST(string_width); EXPECT_VFPRINTF(1, "         1", "%10s", "1"); break;  
> > 
> > Hmmm....
> > Those are deliberately matching glibc behaviour, at least annotating that
> > might be useful.
> > Can you think of a way of detecting whether glibc is being used?
> > Even !is_musl might be better than is_nolibc - even even they are the same.
> 
> Thinking more, the nil/null tests want is_nolibc || is_glibc.
> Setting is_glibc might be hard (unless done from the command line).

We already have a test for __GLIBC__.  We can also use that for
is_glibc.

> The musl people think you don't need to know because their library is conformant.
> I found something from someone trying to detect pthread_setname_np(),
> glibc's features.h will set __USE_GNU (and similar) that musl doesn't set.
> There might also be issues with bionic and uClibc.

Why would __GLIBC__ not work?

> > I'm guessing musl doesn't support 'L' as a length modifier for integers ?

Yep. 

> > (I'm pretty sure that comes from M$.)
> > The intmax_min test could use %qi instead since that is checking the value as well.
> > Another test for %Li could be added, I just mixed the formats up a bit.


Thomas

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] selftests/nolibc: fix libc-test with musl libc
  2026-03-19 16:18     ` Thomas Weißschuh
@ 2026-03-19 22:44       ` David Laight
  2026-03-22  8:43         ` Willy Tarreau
  0 siblings, 1 reply; 6+ messages in thread
From: David Laight @ 2026-03-19 22:44 UTC (permalink / raw)
  To: Thomas Weißschuh; +Cc: Willy Tarreau, Daniel Palmer, linux-kernel

On Thu, 19 Mar 2026 17:18:33 +0100
Thomas Weißschuh <linux@weissschuh.net> wrote:

> On 2026-03-19 10:52:07+0000, David Laight wrote:
> > On Wed, 18 Mar 2026 22:52:31 +0000
> > David Laight <david.laight.linux@gmail.com> wrote:
> >   
> > > On Wed, 18 Mar 2026 18:20:46 +0100
> > > Thomas Weißschuh <linux@weissschuh.net> wrote:
> > >   
> > > > Some of the nolibc testcases fail on musl. In these cases nolibc mirrors
> > > > the non-standard behavior of glibc.
> > > > 
> > > > Avoid the failures by only running these testcases on nolibc itself.
> > > > 
> > > > Fixes: a5f00be9b3b0 ("tools/nolibc: Add a simple test for writing to a FILE and reading it back")
> > > > Fixes: d94393e48c09 ("tools/nolibc/printf: Add support for length modifiers tzqL and formats iX")
> > > > Fixes: c2d234d3dc56 ("tools/nolibc/printf: Special case 0 and add support for %#x")
> > > > Fixes: 63befd993da4 ("tools/nolibc/printf: Add support for zero padding and field precision")
> > > > Fixes: d94393e48c09 ("tools/nolibc/printf: Add support for length modifiers tzqL and formats iX")
> > > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> > > > ---
> > > > I am thinking about folding the printf fixups directly into the original
> > > > patches. Any objections?
> > > > ---
> > > >  tools/testing/selftests/nolibc/nolibc-test.c | 12 ++++++------
> > > >  1 file changed, 6 insertions(+), 6 deletions(-)
> > > > 
> > > > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> > > > index 180611aabbfb..b03fb9aeb54e 100644
> > > > --- a/tools/testing/selftests/nolibc/nolibc-test.c
> > > > +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> > > > @@ -867,7 +867,7 @@ int test_file_stream(void)
> > > >  
> > > >  	errno = 0;
> > > >  	r = fwrite("foo", 1, 3, f);
> > > > -	if (r != 0 || errno != EBADF) {
> > > > +	if (r != 0 || (is_nolibc && errno != EBADF)) {
> > > >  		fclose(f);
> > > >  		return -1;
> > > >  	}
> > > > @@ -1824,13 +1824,13 @@ static int run_printf(int min, int max)
> > > >  		CASE_TEST(hex_alt_prec); EXPECT_VFPRINTF(1, "| 0x02|0x03| 0x123|", "|%#5.2x|%#04x|%#6.2x|", 2, 3, 0x123); break;
> > > >  		CASE_TEST(hex_0_alt);    EXPECT_VFPRINTF(1, "|0|0000|   00|", "|%#x|%#04x|%#5.2x|", 0, 0, 0); break;
> > > >  		CASE_TEST(pointer);      EXPECT_VFPRINTF(1, "0x1", "%p", (void *) 0x1); break;
> > > > -		CASE_TEST(pointer_NULL); EXPECT_VFPRINTF(1, "|(nil)|(nil)|", "|%p|%.4p|", (void *)0, (void *)0); break;
> > > > -		CASE_TEST(string_NULL);  EXPECT_VFPRINTF(1, "|(null)||(null)|", "|%s|%.5s|%.6s|", (void *)0, (void *)0, (void *)0); break;
> > > > +		CASE_TEST(pointer_NULL); EXPECT_VFPRINTF(is_nolibc, "|(nil)|(nil)|", "|%p|%.4p|", (void *)0, (void *)0); break;
> > > > +		CASE_TEST(string_NULL);  EXPECT_VFPRINTF(is_nolibc, "|(null)||(null)|", "|%s|%.5s|%.6s|", (void *)0, (void *)0, (void *)0); break;
> > > >  		CASE_TEST(percent);      EXPECT_VFPRINTF(1, "a%d42%69%", "a%%d%d%%%d%%", 42, 69); break;
> > > > -		CASE_TEST(perc_qual);    EXPECT_VFPRINTF(1, "a%d2", "a%-14l%d%d", 2); break;
> > > > -		CASE_TEST(invalid);      EXPECT_VFPRINTF(1, "a%12yx3%y42%P", "a%12yx%d%y%d%P", 3, 42); break;
> > > > +		CASE_TEST(perc_qual);    EXPECT_VFPRINTF(is_nolibc, "a%d2", "a%-14l%d%d", 2); break;
> > > > +		CASE_TEST(invalid);      EXPECT_VFPRINTF(is_nolibc, "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(1, "-9223372036854775808", "%Li", (~0ULL >> 1) + 1); break;
> > > > +		CASE_TEST(intmax_min);   EXPECT_VFPRINTF(is_nolibc, "-9223372036854775808", "%Li", (~0ULL >> 1) + 1); break;
> > > >  		CASE_TEST(uintmax_max);  EXPECT_VFPRINTF(1, "18446744073709551615", "%ju", ~0ULL); break;
> > > >  		CASE_TEST(truncation);   EXPECT_VFPRINTF(1, "012345678901234567890123456789", "%s", "012345678901234567890123456789"); break;
> > > >  		CASE_TEST(string_width); EXPECT_VFPRINTF(1, "         1", "%10s", "1"); break;    
> > > 
> > > Hmmm....
> > > Those are deliberately matching glibc behaviour, at least annotating that
> > > might be useful.
> > > Can you think of a way of detecting whether glibc is being used?
> > > Even !is_musl might be better than is_nolibc - even even they are the same.  
> > 
> > Thinking more, the nil/null tests want is_nolibc || is_glibc.
> > Setting is_glibc might be hard (unless done from the command line).  
> 
> We already have a test for __GLIBC__.  We can also use that for
> is_glibc.
> 
> > The musl people think you don't need to know because their library is conformant.
> > I found something from someone trying to detect pthread_setname_np(),
> > glibc's features.h will set __USE_GNU (and similar) that musl doesn't set.
> > There might also be issues with bionic and uClibc.  
> 
> Why would __GLIBC__ not work?

It wasn't mentioned in the stack overflow article I found :-(

> > > I'm guessing musl doesn't support 'L' as a length modifier for integers ?  
> 
> Yep. 
> 
> > > (I'm pretty sure that comes from M$.)

Just checked, seems not. So it must be something glibc invented.
For some reason L has always been used for 'long double' (M$ accepts l).

	David

> > > The intmax_min test could use %qi instead since that is checking the value as well.
> > > Another test for %Li could be added, I just mixed the formats up a bit.  
> 
> 
> Thomas


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] selftests/nolibc: fix libc-test with musl libc
  2026-03-19 22:44       ` David Laight
@ 2026-03-22  8:43         ` Willy Tarreau
  0 siblings, 0 replies; 6+ messages in thread
From: Willy Tarreau @ 2026-03-22  8:43 UTC (permalink / raw)
  To: David Laight; +Cc: Thomas Weißschuh, Daniel Palmer, linux-kernel

On Thu, Mar 19, 2026 at 10:44:36PM +0000, David Laight wrote:
> On Thu, 19 Mar 2026 17:18:33 +0100
> Thomas Weißschuh <linux@weissschuh.net> wrote:
> 
> > On 2026-03-19 10:52:07+0000, David Laight wrote:
> > > On Wed, 18 Mar 2026 22:52:31 +0000
> > > David Laight <david.laight.linux@gmail.com> wrote:
> > >   
> > > > On Wed, 18 Mar 2026 18:20:46 +0100
> > > > Thomas Weißschuh <linux@weissschuh.net> wrote:
> > > >   
> > > > > Some of the nolibc testcases fail on musl. In these cases nolibc mirrors
> > > > > the non-standard behavior of glibc.
> > > > > 
> > > > > Avoid the failures by only running these testcases on nolibc itself.
> > > > > 
> > > > > Fixes: a5f00be9b3b0 ("tools/nolibc: Add a simple test for writing to a FILE and reading it back")
> > > > > Fixes: d94393e48c09 ("tools/nolibc/printf: Add support for length modifiers tzqL and formats iX")
> > > > > Fixes: c2d234d3dc56 ("tools/nolibc/printf: Special case 0 and add support for %#x")
> > > > > Fixes: 63befd993da4 ("tools/nolibc/printf: Add support for zero padding and field precision")
> > > > > Fixes: d94393e48c09 ("tools/nolibc/printf: Add support for length modifiers tzqL and formats iX")
> > > > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> > > > > ---
> > > > > I am thinking about folding the printf fixups directly into the original
> > > > > patches. Any objections?
> > > > > ---
> > > > >  tools/testing/selftests/nolibc/nolibc-test.c | 12 ++++++------
> > > > >  1 file changed, 6 insertions(+), 6 deletions(-)
> > > > > 
> > > > > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> > > > > index 180611aabbfb..b03fb9aeb54e 100644
> > > > > --- a/tools/testing/selftests/nolibc/nolibc-test.c
> > > > > +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> > > > > @@ -867,7 +867,7 @@ int test_file_stream(void)
> > > > >  
> > > > >  	errno = 0;
> > > > >  	r = fwrite("foo", 1, 3, f);
> > > > > -	if (r != 0 || errno != EBADF) {
> > > > > +	if (r != 0 || (is_nolibc && errno != EBADF)) {
> > > > >  		fclose(f);
> > > > >  		return -1;
> > > > >  	}
> > > > > @@ -1824,13 +1824,13 @@ static int run_printf(int min, int max)
> > > > >  		CASE_TEST(hex_alt_prec); EXPECT_VFPRINTF(1, "| 0x02|0x03| 0x123|", "|%#5.2x|%#04x|%#6.2x|", 2, 3, 0x123); break;
> > > > >  		CASE_TEST(hex_0_alt);    EXPECT_VFPRINTF(1, "|0|0000|   00|", "|%#x|%#04x|%#5.2x|", 0, 0, 0); break;
> > > > >  		CASE_TEST(pointer);      EXPECT_VFPRINTF(1, "0x1", "%p", (void *) 0x1); break;
> > > > > -		CASE_TEST(pointer_NULL); EXPECT_VFPRINTF(1, "|(nil)|(nil)|", "|%p|%.4p|", (void *)0, (void *)0); break;
> > > > > -		CASE_TEST(string_NULL);  EXPECT_VFPRINTF(1, "|(null)||(null)|", "|%s|%.5s|%.6s|", (void *)0, (void *)0, (void *)0); break;
> > > > > +		CASE_TEST(pointer_NULL); EXPECT_VFPRINTF(is_nolibc, "|(nil)|(nil)|", "|%p|%.4p|", (void *)0, (void *)0); break;
> > > > > +		CASE_TEST(string_NULL);  EXPECT_VFPRINTF(is_nolibc, "|(null)||(null)|", "|%s|%.5s|%.6s|", (void *)0, (void *)0, (void *)0); break;
> > > > >  		CASE_TEST(percent);      EXPECT_VFPRINTF(1, "a%d42%69%", "a%%d%d%%%d%%", 42, 69); break;
> > > > > -		CASE_TEST(perc_qual);    EXPECT_VFPRINTF(1, "a%d2", "a%-14l%d%d", 2); break;
> > > > > -		CASE_TEST(invalid);      EXPECT_VFPRINTF(1, "a%12yx3%y42%P", "a%12yx%d%y%d%P", 3, 42); break;
> > > > > +		CASE_TEST(perc_qual);    EXPECT_VFPRINTF(is_nolibc, "a%d2", "a%-14l%d%d", 2); break;
> > > > > +		CASE_TEST(invalid);      EXPECT_VFPRINTF(is_nolibc, "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(1, "-9223372036854775808", "%Li", (~0ULL >> 1) + 1); break;
> > > > > +		CASE_TEST(intmax_min);   EXPECT_VFPRINTF(is_nolibc, "-9223372036854775808", "%Li", (~0ULL >> 1) + 1); break;
> > > > >  		CASE_TEST(uintmax_max);  EXPECT_VFPRINTF(1, "18446744073709551615", "%ju", ~0ULL); break;
> > > > >  		CASE_TEST(truncation);   EXPECT_VFPRINTF(1, "012345678901234567890123456789", "%s", "012345678901234567890123456789"); break;
> > > > >  		CASE_TEST(string_width); EXPECT_VFPRINTF(1, "         1", "%10s", "1"); break;    
> > > > 
> > > > Hmmm....
> > > > Those are deliberately matching glibc behaviour, at least annotating that
> > > > might be useful.
> > > > Can you think of a way of detecting whether glibc is being used?
> > > > Even !is_musl might be better than is_nolibc - even even they are the same.  
> > > 
> > > Thinking more, the nil/null tests want is_nolibc || is_glibc.
> > > Setting is_glibc might be hard (unless done from the command line).  
> > 
> > We already have a test for __GLIBC__.  We can also use that for
> > is_glibc.
> > 
> > > The musl people think you don't need to know because their library is conformant.
> > > I found something from someone trying to detect pthread_setname_np(),
> > > glibc's features.h will set __USE_GNU (and similar) that musl doesn't set.
> > > There might also be issues with bionic and uClibc.  
> > 
> > Why would __GLIBC__ not work?
> 
> It wasn't mentioned in the stack overflow article I found :-(

I confirm, I'm using it all the time as well, the macro contains the lib's
major version (2).

David you can check for such macros this way if you're interested:

  $ printf "#include <stdio.h>\n" | gcc -dM -E -xc -|grep GLIBC

Willy

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-03-22  8:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-18 17:20 [PATCH] selftests/nolibc: fix libc-test with musl libc Thomas Weißschuh
2026-03-18 22:52 ` David Laight
2026-03-19 10:52   ` David Laight
2026-03-19 16:18     ` Thomas Weißschuh
2026-03-19 22:44       ` David Laight
2026-03-22  8:43         ` Willy Tarreau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox