Skip to content

Commit 6cada28

Browse files
committed
selftests/nolibc: disable brk()/sbrk() tests on musl
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 <[email protected]> Acked-by: Willy Tarreau <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 92098b1 commit 6cada28

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

tools/testing/selftests/nolibc/nolibc-test.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,7 @@ int run_syscall(int min, int max)
942942
int ret = 0;
943943
void *p1, *p2;
944944
int has_gettid = 1;
945+
int has_brk;
945946

946947
/* <proc> indicates whether or not /proc is mounted */
947948
proc = stat("/proc", &stat_buf) == 0;
@@ -954,6 +955,9 @@ int run_syscall(int min, int max)
954955
has_gettid = __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 30);
955956
#endif
956957

958+
/* on musl setting brk()/sbrk() always fails */
959+
has_brk = brk(0) == 0;
960+
957961
for (test = min; test >= 0 && test <= max; test++) {
958962
int llen = 0; /* line length */
959963

@@ -969,9 +973,9 @@ int run_syscall(int min, int max)
969973
CASE_TEST(kill_0); EXPECT_SYSZR(1, kill(getpid(), 0)); break;
970974
CASE_TEST(kill_CONT); EXPECT_SYSZR(1, kill(getpid(), 0)); break;
971975
CASE_TEST(kill_BADPID); EXPECT_SYSER(1, kill(INT_MAX, 0), -1, ESRCH); break;
972-
CASE_TEST(sbrk_0); EXPECT_PTRNE(1, sbrk(0), (void *)-1); break;
973-
CASE_TEST(sbrk); if ((p1 = p2 = sbrk(4096)) != (void *)-1) p2 = sbrk(-4096); EXPECT_SYSZR(1, (p2 == (void *)-1) || p2 == p1); break;
974-
CASE_TEST(brk); EXPECT_SYSZR(1, brk(sbrk(0))); break;
976+
CASE_TEST(sbrk_0); EXPECT_PTRNE(has_brk, sbrk(0), (void *)-1); break;
977+
CASE_TEST(sbrk); if ((p1 = p2 = sbrk(4096)) != (void *)-1) p2 = sbrk(-4096); EXPECT_SYSZR(has_brk, (p2 == (void *)-1) || p2 == p1); break;
978+
CASE_TEST(brk); EXPECT_SYSZR(has_brk, brk(sbrk(0))); break;
975979
CASE_TEST(chdir_root); EXPECT_SYSZR(1, chdir("/")); chdir(getenv("PWD")); break;
976980
CASE_TEST(chdir_dot); EXPECT_SYSZR(1, chdir(".")); break;
977981
CASE_TEST(chdir_blah); EXPECT_SYSER(1, chdir("/blah"), -1, ENOENT); break;

0 commit comments

Comments
 (0)