summaryrefslogtreecommitdiff
path: root/tools/testing
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2026-08-18 10:50:44 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2026-08-18 10:50:44 -0700
commit2063dd9d0b5a495d93f466f698bf0329809647ee (patch)
treeb7ea54e4ed2f2a5fec477d376d13ff66929e48d5 /tools/testing
parent7b24dd46a70e94d8db83b50a04d46690fac216d0 (diff)
parentb58afc8d1cf85688601b8d7e271125fff666f661 (diff)
Merge tag 'nolibc-20260814-for-7.3-1' of git://git.kernel.org/pub/scm/linux/kernel/git/nolibc/linux-nolibc
Pull nolibc updates from Thomas Weißschuh: - New architecture: Alpha - New library functionality: readlink(), getcwd() - Various bugfixes and cleanups * tag 'nolibc-20260814-for-7.3-1' of git://git.kernel.org/pub/scm/linux/kernel/git/nolibc/linux-nolibc: tools/nolibc: add support for Alpha tools/nolibc/powerpc: mark ctr and xer as clobbered by system call tools/nolibc: remove dead __ARCH_WANT_SYS_OLD_SELECT selftests/nolibc: add debug information tools/nolibc: mark arg1 operand in __nolibc_syscall0() as write-only selftests/nolibc: Add test for getcwd() and readlink() tools/nolibc: unistd: Add readlink() tools/nolibc: unistd: Add getcwd()
Diffstat (limited to 'tools/testing')
-rw-r--r--tools/testing/selftests/nolibc/Makefile.include2
-rw-r--r--tools/testing/selftests/nolibc/Makefile.nolibc2
-rw-r--r--tools/testing/selftests/nolibc/nolibc-test.c57
-rwxr-xr-xtools/testing/selftests/nolibc/run-tests.sh3
4 files changed, 62 insertions, 2 deletions
diff --git a/tools/testing/selftests/nolibc/Makefile.include b/tools/testing/selftests/nolibc/Makefile.include
index c30ca3a9ef14..ea520eac64a6 100644
--- a/tools/testing/selftests/nolibc/Makefile.include
+++ b/tools/testing/selftests/nolibc/Makefile.include
@@ -5,7 +5,7 @@ _CFLAGS_STACKPROTECTOR ?= $(call try-run, \
echo 'void foo(void) {}' | $(CC) -x c - -o - -S $(CLANG_CROSS_FLAGS) $(__CFLAGS_STACKPROTECTOR) | grep -q __stack_chk_guard, \
$(__CFLAGS_STACKPROTECTOR))
_CFLAGS_SANITIZER ?= $(call cc-option,-fsanitize=undefined -fsanitize-trap=all)
-CFLAGS_NOLIBC_TEST ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 \
+CFLAGS_NOLIBC_TEST ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -ggdb \
-W -Wall -Wextra -Wundef -Wwrite-strings \
$(call cc-option,-fno-stack-protector) $(call cc-option,-Wmissing-prototypes) \
$(_CFLAGS_STACKPROTECTOR) $(_CFLAGS_SANITIZER)
diff --git a/tools/testing/selftests/nolibc/Makefile.nolibc b/tools/testing/selftests/nolibc/Makefile.nolibc
index 06f881e2e90c..f70c8dfca018 100644
--- a/tools/testing/selftests/nolibc/Makefile.nolibc
+++ b/tools/testing/selftests/nolibc/Makefile.nolibc
@@ -112,6 +112,7 @@ EXTRACONFIG_armthumb = -e CONFIG_NAMESPACES
EXTRACONFIG_sparc32 = -e CONFIG_TMPFS
EXTRACONFIG_m68k = -e CONFIG_BLK_DEV_INITRD
EXTRACONFIG_sh4 = -e CONFIG_BLK_DEV_INITRD -e CONFIG_CMDLINE_FROM_BOOTLOADER
+EXTRACONFIG_alpha = -e CONFIG_BLK_DEV_INITRD
EXTRACONFIG = $(EXTRACONFIG_$(XARCH))
# optional tests to run (default = all)
@@ -174,6 +175,7 @@ QEMU_ARGS_m68k = -M virt -append "console=ttyGF0,115200 panic=-1 $(TEST:%=
QEMU_ARGS_sh4 = -M r2d -serial file:/dev/stdout -append "console=ttySC1,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
QEMU_ARGS_openrisc = -M virt -m 512M -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
QEMU_ARGS_parisc32 = -M B160L -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
+QEMU_ARGS_alpha = -M clipper -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
QEMU_ARGS = -m 1G $(QEMU_ARGS_$(XARCH)) $(QEMU_ARGS_BIOS) $(QEMU_ARGS_EXTRA)
# OUTPUT is only set when run from the main makefile, otherwise
diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c
index c1c1ce43a047..ed860b0a15a1 100644
--- a/tools/testing/selftests/nolibc/nolibc-test.c
+++ b/tools/testing/selftests/nolibc/nolibc-test.c
@@ -756,6 +756,10 @@ int run_startup(int min, int max)
/* checking NULL for argv/argv0, environ and _auxv is not enough, let's compare with sbrk(0) or &end */
extern char end;
char *brk = sbrk(0) != (void *)-1 ? sbrk(0) : &end;
+#if defined(__alpha__)
+ /* the ordering above does not work on an alpha kernel due to STACK_TOP != TASK_SIZE */
+ brk = NULL;
+#endif
/* differ from nolibc, both glibc and musl have no global _auxv */
const unsigned long *test_auxv = (void *)-1;
#ifdef NOLIBC
@@ -854,6 +858,58 @@ static int test_dirent(void)
return 0;
}
+int test_getcwd(void)
+{
+ char cwd_syscall[PATH_MAX];
+ char cwd_proc[PATH_MAX];
+ ssize_t len;
+
+ /* Read where the link /proc/self/cwd points */
+ len = readlink("/proc/self/cwd", cwd_proc, sizeof(cwd_proc) - 1);
+ if (len <= 0)
+ return __LINE__;
+
+ /* Terminate the string from readlink() */
+ cwd_proc[len] = '\0';
+
+ /* Get the cwd via syscall */
+ if (getcwd(cwd_syscall, sizeof(cwd_syscall)) == NULL)
+ return __LINE__;
+
+ /* Fail if they aren't the same */
+ if (strcmp(cwd_proc, cwd_syscall) != 0)
+ return __LINE__;
+
+ /* Try getcwd() with NULL for the buffer,
+ * should return NULL and an error in errno.
+ * Other libc's allow this by allocating a buffer
+ * internally.
+ */
+ if (is_nolibc) {
+ errno = 0;
+ if (getcwd(NULL, 0) != NULL || !errno)
+ return __LINE__;
+ }
+
+ /* Try getcwd() with a buffer but make the size 0,
+ * should return NULL and an error in errno.
+ */
+ errno = 0;
+ if (getcwd(cwd_syscall, 0) != NULL || !errno)
+ return __LINE__;
+
+ /* Try getcwd() with a buffer but make the size 1,
+ * should return NULL and an error in errno because
+ * the string written to the buffer is terminated
+ * so you need at least 2 bytes even for "/".
+ */
+ errno = 0;
+ if (getcwd(cwd_syscall, 1) != NULL || !errno)
+ return __LINE__;
+
+ return 0;
+}
+
int test_getrandom(void)
{
uint64_t rng = 0;
@@ -1555,6 +1611,7 @@ int run_syscall(int min, int max)
CASE_TEST(clock_getres); EXPECT_SYSZR(1, clock_getres(CLOCK_MONOTONIC, &ts)); break;
CASE_TEST(clock_gettime); EXPECT_SYSZR(1, clock_gettime(CLOCK_MONOTONIC, &ts)); break;
CASE_TEST(clock_settime); EXPECT_SYSER(1, clock_settime(CLOCK_MONOTONIC, &ts), -1, EINVAL); break;
+ CASE_TEST(getcwd); EXPECT_SYSZR(proc, test_getcwd()); break;
CASE_TEST(getpid); EXPECT_SYSNE(1, getpid(), -1); break;
CASE_TEST(getppid); EXPECT_SYSNE(1, getppid(), -1); break;
CASE_TEST(gettid); EXPECT_SYSNE(has_gettid, gettid(), -1); break;
diff --git a/tools/testing/selftests/nolibc/run-tests.sh b/tools/testing/selftests/nolibc/run-tests.sh
index 6460e25001de..dc0b1649c641 100755
--- a/tools/testing/selftests/nolibc/run-tests.sh
+++ b/tools/testing/selftests/nolibc/run-tests.sh
@@ -30,6 +30,7 @@ all_archs=(
m68k
sh4
parisc32
+ alpha
)
archs="${all_archs[@]}"
@@ -193,7 +194,7 @@ test_arch() {
exit 1
esac
printf '%-15s' "$arch:"
- if [ "$arch" = "m68k" -o "$arch" = "sh4" -o "$arch" = "openrisc" -o "$arch" = "parisc32" ] && [ "$llvm" = "1" ]; then
+ if [ "$arch" = "m68k" -o "$arch" = "sh4" -o "$arch" = "openrisc" -o "$arch" = "parisc32" -o "$arch" = "alpha" ] && [ "$llvm" = "1" ]; then
echo "Unsupported configuration"
return
fi