]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
selftests/nolibc: Fix build with host headers and libc
authorDavid Laight <david.laight.linux@gmail.com>
Mon, 23 Feb 2026 10:17:21 +0000 (10:17 +0000)
committerThomas Weißschuh <linux@weissschuh.net>
Fri, 20 Mar 2026 16:45:45 +0000 (17:45 +0100)
Many systems don't have strlcpy() or strlcat() and readdir_r() is
deprecated. This makes the tests fail to build with the host headers.
Disable the 'directories' test and define strlcpy(), strlcat() and
readdir_r() using #defines so that the code compiles.

Fixes: 6fe8360b16acb ("selftests/nolibc: also test libc-test through regular selftest framework")
Signed-off-by: David Laight <david.laight.linux@gmail.com>
Link: https://patch.msgid.link/20260223101735.2922-4-david.laight.linux@gmail.com
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
tools/testing/selftests/nolibc/nolibc-test.c

index 1aca8468eac4b3b75e7bd0f9f3b3b50c3331a3a3..801b2ad188537e989723ba52329a1f1586851576 100644 (file)
@@ -82,6 +82,20 @@ static const int is_glibc =
 #endif
 ;
 
+#if !defined(NOLIBC)
+/* Some disabled tests may not compile. */
+
+/* strlcat() and strlcpy() may not be in the system headers. */
+#undef strlcat
+#undef strlcpy
+#define strlcat(d, s, l) 0
+#define strlcpy(d, s, l) 0
+
+/* readdir_r() is likely to be marked deprecated */
+#undef readdir_r
+#define readdir_r(dir, dirent, result) ((errno = EINVAL), -1)
+#endif
+
 /* definition of a series of tests */
 struct test {
        const char *name;              /* test name */
@@ -1416,7 +1430,7 @@ int run_syscall(int min, int max)
                CASE_TEST(fork);              EXPECT_SYSZR(1, test_fork(FORK_STANDARD)); break;
                CASE_TEST(getdents64_root);   EXPECT_SYSNE(1, test_getdents64("/"), -1); break;
                CASE_TEST(getdents64_null);   EXPECT_SYSER(1, test_getdents64("/dev/null"), -1, ENOTDIR); break;
-               CASE_TEST(directories);       EXPECT_SYSZR(proc, test_dirent()); break;
+               CASE_TEST(directories);       EXPECT_SYSZR(is_nolibc && proc, test_dirent()); break;
                CASE_TEST(getrandom);         EXPECT_SYSZR(1, test_getrandom()); break;
                CASE_TEST(gettimeofday_tv);   EXPECT_SYSZR(1, gettimeofday(&tv, NULL)); break;
                CASE_TEST(gettimeofday_tv_tz);EXPECT_SYSZR(1, gettimeofday(&tv, &tz)); break;