* [PATCH] selftests/nolibc: disable brk()/sbrk() tests on musl
@ 2024-04-23 22:15 Thomas Weißschuh
2024-04-24 2:13 ` Willy Tarreau
0 siblings, 1 reply; 3+ messages in thread
From: Thomas Weißschuh @ 2024-04-23 22:15 UTC (permalink / raw)
To: Willy Tarreau, Shuah Khan
Cc: linux-kselftest, linux-kernel, Thomas Weißschuh
On musl calls to brk() and sbrk() always fail with ENOMEM.
Detect this and skip the tests on musl.
Tested on glibc 2.39 and musl 1.2.5 in addition to nolibc.
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
tools/testing/selftests/nolibc/nolibc-test.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index 94bb6e11c16f..89be9ba95179 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -942,6 +942,7 @@ int run_syscall(int min, int max)
int ret = 0;
void *p1, *p2;
int has_gettid = 1;
+ int has_brk;
/* <proc> indicates whether or not /proc is mounted */
proc = stat("/proc", &stat_buf) == 0;
@@ -954,6 +955,9 @@ int run_syscall(int min, int max)
has_gettid = __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 30);
#endif
+ /* on musl setting brk()/sbrk() always fails */
+ has_brk = brk(0) == 0;
+
for (test = min; test >= 0 && test <= max; test++) {
int llen = 0; /* line length */
@@ -969,9 +973,9 @@ int run_syscall(int min, int max)
CASE_TEST(kill_0); EXPECT_SYSZR(1, kill(getpid(), 0)); break;
CASE_TEST(kill_CONT); EXPECT_SYSZR(1, kill(getpid(), 0)); break;
CASE_TEST(kill_BADPID); EXPECT_SYSER(1, kill(INT_MAX, 0), -1, ESRCH); break;
- CASE_TEST(sbrk_0); EXPECT_PTRNE(1, sbrk(0), (void *)-1); break;
- CASE_TEST(sbrk); if ((p1 = p2 = sbrk(4096)) != (void *)-1) p2 = sbrk(-4096); EXPECT_SYSZR(1, (p2 == (void *)-1) || p2 == p1); break;
- CASE_TEST(brk); EXPECT_SYSZR(1, brk(sbrk(0))); break;
+ CASE_TEST(sbrk_0); EXPECT_PTRNE(has_brk, sbrk(0), (void *)-1); break;
+ CASE_TEST(sbrk); if ((p1 = p2 = sbrk(4096)) != (void *)-1) p2 = sbrk(-4096); EXPECT_SYSZR(has_brk, (p2 == (void *)-1) || p2 == p1); break;
+ CASE_TEST(brk); EXPECT_SYSZR(has_brk, brk(sbrk(0))); break;
CASE_TEST(chdir_root); EXPECT_SYSZR(1, chdir("/")); chdir(getenv("PWD")); break;
CASE_TEST(chdir_dot); EXPECT_SYSZR(1, chdir(".")); break;
CASE_TEST(chdir_blah); EXPECT_SYSER(1, chdir("/blah"), -1, ENOENT); break;
---
base-commit: 0adab2b6b7336fb6ee3c6456a432dad3b1d25647
change-id: 20240423-nolibc-musl-brk-7784add29801
Best regards,
--
Thomas Weißschuh <linux@weissschuh.net>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] selftests/nolibc: disable brk()/sbrk() tests on musl
2024-04-23 22:15 [PATCH] selftests/nolibc: disable brk()/sbrk() tests on musl Thomas Weißschuh
@ 2024-04-24 2:13 ` Willy Tarreau
2024-04-24 22:02 ` Willy Tarreau
0 siblings, 1 reply; 3+ messages in thread
From: Willy Tarreau @ 2024-04-24 2:13 UTC (permalink / raw)
To: Thomas Weißschuh; +Cc: Shuah Khan, linux-kselftest, linux-kernel
On Wed, Apr 24, 2024 at 12:15:33AM +0200, Thomas Weißschuh wrote:
> On musl calls to brk() and sbrk() always fail with ENOMEM.
> Detect this and skip the tests on musl.
>
> Tested on glibc 2.39 and musl 1.2.5 in addition to nolibc.
>
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> ---
> tools/testing/selftests/nolibc/nolibc-test.c | 10 +++++++---
> 1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> index 94bb6e11c16f..89be9ba95179 100644
> --- a/tools/testing/selftests/nolibc/nolibc-test.c
> +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> @@ -942,6 +942,7 @@ int run_syscall(int min, int max)
> int ret = 0;
> void *p1, *p2;
> int has_gettid = 1;
> + int has_brk;
>
> /* <proc> indicates whether or not /proc is mounted */
> proc = stat("/proc", &stat_buf) == 0;
> @@ -954,6 +955,9 @@ int run_syscall(int min, int max)
> has_gettid = __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 30);
> #endif
>
> + /* on musl setting brk()/sbrk() always fails */
> + has_brk = brk(0) == 0;
> +
> for (test = min; test >= 0 && test <= max; test++) {
> int llen = 0; /* line length */
>
> @@ -969,9 +973,9 @@ int run_syscall(int min, int max)
> CASE_TEST(kill_0); EXPECT_SYSZR(1, kill(getpid(), 0)); break;
> CASE_TEST(kill_CONT); EXPECT_SYSZR(1, kill(getpid(), 0)); break;
> CASE_TEST(kill_BADPID); EXPECT_SYSER(1, kill(INT_MAX, 0), -1, ESRCH); break;
> - CASE_TEST(sbrk_0); EXPECT_PTRNE(1, sbrk(0), (void *)-1); break;
> - CASE_TEST(sbrk); if ((p1 = p2 = sbrk(4096)) != (void *)-1) p2 = sbrk(-4096); EXPECT_SYSZR(1, (p2 == (void *)-1) || p2 == p1); break;
> - CASE_TEST(brk); EXPECT_SYSZR(1, brk(sbrk(0))); break;
> + CASE_TEST(sbrk_0); EXPECT_PTRNE(has_brk, sbrk(0), (void *)-1); break;
> + CASE_TEST(sbrk); if ((p1 = p2 = sbrk(4096)) != (void *)-1) p2 = sbrk(-4096); EXPECT_SYSZR(has_brk, (p2 == (void *)-1) || p2 == p1); break;
> + CASE_TEST(brk); EXPECT_SYSZR(has_brk, brk(sbrk(0))); break;
> CASE_TEST(chdir_root); EXPECT_SYSZR(1, chdir("/")); chdir(getenv("PWD")); break;
> CASE_TEST(chdir_dot); EXPECT_SYSZR(1, chdir(".")); break;
> CASE_TEST(chdir_blah); EXPECT_SYSER(1, chdir("/blah"), -1, ENOENT); break;
Looks good, thank you Thomas!
Willy
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] selftests/nolibc: disable brk()/sbrk() tests on musl
2024-04-24 2:13 ` Willy Tarreau
@ 2024-04-24 22:02 ` Willy Tarreau
0 siblings, 0 replies; 3+ messages in thread
From: Willy Tarreau @ 2024-04-24 22:02 UTC (permalink / raw)
To: Thomas Weißschuh; +Cc: Shuah Khan, linux-kselftest, linux-kernel
On Wed, Apr 24, 2024 at 04:13:13AM +0200, Willy Tarreau wrote:
> On Wed, Apr 24, 2024 at 12:15:33AM +0200, Thomas Weißschuh wrote:
> > On musl calls to brk() and sbrk() always fail with ENOMEM.
> > Detect this and skip the tests on musl.
> >
> > Tested on glibc 2.39 and musl 1.2.5 in addition to nolibc.
> >
> > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> > ---
> > tools/testing/selftests/nolibc/nolibc-test.c | 10 +++++++---
> > 1 file changed, 7 insertions(+), 3 deletions(-)
> >
> > diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
> > index 94bb6e11c16f..89be9ba95179 100644
> > --- a/tools/testing/selftests/nolibc/nolibc-test.c
> > +++ b/tools/testing/selftests/nolibc/nolibc-test.c
> > @@ -942,6 +942,7 @@ int run_syscall(int min, int max)
> > int ret = 0;
> > void *p1, *p2;
> > int has_gettid = 1;
> > + int has_brk;
> >
> > /* <proc> indicates whether or not /proc is mounted */
> > proc = stat("/proc", &stat_buf) == 0;
> > @@ -954,6 +955,9 @@ int run_syscall(int min, int max)
> > has_gettid = __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 30);
> > #endif
> >
> > + /* on musl setting brk()/sbrk() always fails */
> > + has_brk = brk(0) == 0;
> > +
> > for (test = min; test >= 0 && test <= max; test++) {
> > int llen = 0; /* line length */
> >
> > @@ -969,9 +973,9 @@ int run_syscall(int min, int max)
> > CASE_TEST(kill_0); EXPECT_SYSZR(1, kill(getpid(), 0)); break;
> > CASE_TEST(kill_CONT); EXPECT_SYSZR(1, kill(getpid(), 0)); break;
> > CASE_TEST(kill_BADPID); EXPECT_SYSER(1, kill(INT_MAX, 0), -1, ESRCH); break;
> > - CASE_TEST(sbrk_0); EXPECT_PTRNE(1, sbrk(0), (void *)-1); break;
> > - CASE_TEST(sbrk); if ((p1 = p2 = sbrk(4096)) != (void *)-1) p2 = sbrk(-4096); EXPECT_SYSZR(1, (p2 == (void *)-1) || p2 == p1); break;
> > - CASE_TEST(brk); EXPECT_SYSZR(1, brk(sbrk(0))); break;
> > + CASE_TEST(sbrk_0); EXPECT_PTRNE(has_brk, sbrk(0), (void *)-1); break;
> > + CASE_TEST(sbrk); if ((p1 = p2 = sbrk(4096)) != (void *)-1) p2 = sbrk(-4096); EXPECT_SYSZR(has_brk, (p2 == (void *)-1) || p2 == p1); break;
> > + CASE_TEST(brk); EXPECT_SYSZR(has_brk, brk(sbrk(0))); break;
> > CASE_TEST(chdir_root); EXPECT_SYSZR(1, chdir("/")); chdir(getenv("PWD")); break;
> > CASE_TEST(chdir_dot); EXPECT_SYSZR(1, chdir(".")); break;
> > CASE_TEST(chdir_blah); EXPECT_SYSER(1, chdir("/blah"), -1, ENOENT); break;
>
> Looks good, thank you Thomas!
BTW, Acked-by: Willy Tarreau <w@1wt.eu>
Willy
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-24 22:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-23 22:15 [PATCH] selftests/nolibc: disable brk()/sbrk() tests on musl Thomas Weißschuh
2024-04-24 2:13 ` Willy Tarreau
2024-04-24 22:02 ` Willy Tarreau
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox