]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
selftests/nolibc: disable brk()/sbrk() tests on musl
authorThomas Weißschuh <linux@weissschuh.net>
Tue, 23 Apr 2024 22:15:33 +0000 (00:15 +0200)
committerThomas Weißschuh <linux@weissschuh.net>
Sat, 29 Jun 2024 07:44:53 +0000 (09:44 +0200)
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>
Acked-by: Willy Tarreau <w@1wt.eu>
Link: https://lore.kernel.org/r/20240424-nolibc-musl-brk-v1-1-b49882dd9a93@weissschuh.net
tools/testing/selftests/nolibc/nolibc-test.c

index 994477ee87befc23c3881688b7d89fc8d6039fe1..b9c84d42edbe032f2a60ca3c7f2d58508e89da29 100644 (file)
@@ -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;