Skip to content

Commit 7004a2e

Browse files
committed
Merge tag 'linux_kselftest-nolibc-6.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest
Pull nolibc updates from Shuah Khan: - add support for waitid() - use waitid() over waitpid() - use a pipe in vfprintf tests - skip tests for unimplemented syscalls - rename riscv to riscv64 - add configurations for riscv32 - add detecting missing toolchain to run-tests.sh * tag 'linux_kselftest-nolibc-6.14-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/shuah/linux-kselftest: selftests/nolibc: add configurations for riscv32 selftests/nolibc: rename riscv to riscv64 selftests/nolibc: skip tests for unimplemented syscalls selftests/nolibc: use a pipe to in vfprintf tests selftests/nolibc: use waitid() over waitpid() tools/nolibc: add support for waitid() selftests/nolibc: run-tests.sh: detect missing toolchain
2 parents e8f17cb + 24728b7 commit 7004a2e

File tree

4 files changed

+63
-19
lines changed

4 files changed

+63
-19
lines changed

tools/include/nolibc/sys.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <linux/prctl.h>
2424
#include <linux/resource.h>
2525
#include <linux/utsname.h>
26+
#include <linux/signal.h>
2627

2728
#include "arch.h"
2829
#include "errno.h"
@@ -1225,6 +1226,23 @@ pid_t waitpid(pid_t pid, int *status, int options)
12251226
}
12261227

12271228

1229+
/*
1230+
* int waitid(idtype_t idtype, id_t id, siginfo_t *infop, int options);
1231+
*/
1232+
1233+
static __attribute__((unused))
1234+
int sys_waitid(int which, pid_t pid, siginfo_t *infop, int options, struct rusage *rusage)
1235+
{
1236+
return my_syscall5(__NR_waitid, which, pid, infop, options, rusage);
1237+
}
1238+
1239+
static __attribute__((unused))
1240+
int waitid(int which, pid_t pid, siginfo_t *infop, int options)
1241+
{
1242+
return __sysret(sys_waitid(which, pid, infop, options, NULL));
1243+
}
1244+
1245+
12281246
/*
12291247
* ssize_t write(int fd, const void *buf, size_t count);
12301248
*/

tools/testing/selftests/nolibc/Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ cc-option = $(call __cc-option, $(CC),$(CLANG_CROSS_FLAGS),$(1),$(2))
4343
# configure default variants for target kernel supported architectures
4444
XARCH_powerpc = ppc
4545
XARCH_mips = mips32le
46+
XARCH_riscv = riscv64
4647
XARCH = $(or $(XARCH_$(ARCH)),$(ARCH))
4748

4849
# map from user input variants to their kernel supported architectures
@@ -51,6 +52,8 @@ ARCH_ppc64 = powerpc
5152
ARCH_ppc64le = powerpc
5253
ARCH_mips32le = mips
5354
ARCH_mips32be = mips
55+
ARCH_riscv32 = riscv
56+
ARCH_riscv64 = riscv
5457
ARCH := $(or $(ARCH_$(XARCH)),$(XARCH))
5558

5659
# kernel image names by architecture
@@ -65,6 +68,8 @@ IMAGE_ppc = vmlinux
6568
IMAGE_ppc64 = vmlinux
6669
IMAGE_ppc64le = arch/powerpc/boot/zImage
6770
IMAGE_riscv = arch/riscv/boot/Image
71+
IMAGE_riscv32 = arch/riscv/boot/Image
72+
IMAGE_riscv64 = arch/riscv/boot/Image
6873
IMAGE_s390 = arch/s390/boot/bzImage
6974
IMAGE_loongarch = arch/loongarch/boot/vmlinuz.efi
7075
IMAGE = $(objtree)/$(IMAGE_$(XARCH))
@@ -82,6 +87,8 @@ DEFCONFIG_ppc = pmac32_defconfig
8287
DEFCONFIG_ppc64 = powernv_be_defconfig
8388
DEFCONFIG_ppc64le = powernv_defconfig
8489
DEFCONFIG_riscv = defconfig
90+
DEFCONFIG_riscv32 = rv32_defconfig
91+
DEFCONFIG_riscv64 = defconfig
8592
DEFCONFIG_s390 = defconfig
8693
DEFCONFIG_loongarch = defconfig
8794
DEFCONFIG = $(DEFCONFIG_$(XARCH))
@@ -104,6 +111,8 @@ QEMU_ARCH_ppc = ppc
104111
QEMU_ARCH_ppc64 = ppc64
105112
QEMU_ARCH_ppc64le = ppc64
106113
QEMU_ARCH_riscv = riscv64
114+
QEMU_ARCH_riscv32 = riscv32
115+
QEMU_ARCH_riscv64 = riscv64
107116
QEMU_ARCH_s390 = s390x
108117
QEMU_ARCH_loongarch = loongarch64
109118
QEMU_ARCH = $(QEMU_ARCH_$(XARCH))
@@ -130,6 +139,8 @@ QEMU_ARGS_ppc = -M g3beige -append "console=ttyS0 panic=-1 $(TEST:%=NOLIB
130139
QEMU_ARGS_ppc64 = -M powernv -append "console=hvc0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
131140
QEMU_ARGS_ppc64le = -M powernv -append "console=hvc0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
132141
QEMU_ARGS_riscv = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
142+
QEMU_ARGS_riscv32 = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
143+
QEMU_ARGS_riscv64 = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
133144
QEMU_ARGS_s390 = -M s390-ccw-virtio -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
134145
QEMU_ARGS_loongarch = -M virt -append "console=ttyS0,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
135146
QEMU_ARGS = -m 1G $(QEMU_ARGS_$(XARCH)) $(QEMU_ARGS_BIOS) $(QEMU_ARGS_EXTRA)

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

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,10 @@ int expect_syszr(int expr, int llen)
302302
{
303303
int ret = 0;
304304

305-
if (expr) {
305+
if (errno == ENOSYS) {
306+
llen += printf(" = ENOSYS");
307+
result(llen, SKIPPED);
308+
} else if (expr) {
306309
ret = 1;
307310
llen += printf(" = %d %s ", expr, errorname(errno));
308311
result(llen, FAIL);
@@ -342,7 +345,10 @@ int expect_sysne(int expr, int llen, int val)
342345
{
343346
int ret = 0;
344347

345-
if (expr == val) {
348+
if (errno == ENOSYS) {
349+
llen += printf(" = ENOSYS");
350+
result(llen, SKIPPED);
351+
} else if (expr == val) {
346352
ret = 1;
347353
llen += printf(" = %d %s ", expr, errorname(errno));
348354
result(llen, FAIL);
@@ -367,7 +373,9 @@ int expect_syserr2(int expr, int expret, int experr1, int experr2, int llen)
367373
int _errno = errno;
368374

369375
llen += printf(" = %d %s ", expr, errorname(_errno));
370-
if (expr != expret || (_errno != experr1 && _errno != experr2)) {
376+
if (errno == ENOSYS) {
377+
result(llen, SKIPPED);
378+
} else if (expr != expret || (_errno != experr1 && _errno != experr2)) {
371379
ret = 1;
372380
if (experr2 == 0)
373381
llen += printf(" != (%d %s) ", expret, errorname(experr1));
@@ -1229,19 +1237,20 @@ int run_stdlib(int min, int max)
12291237

12301238
static int expect_vfprintf(int llen, int c, const char *expected, const char *fmt, ...)
12311239
{
1232-
int ret, fd;
1240+
int ret, pipefd[2];
12331241
ssize_t w, r;
12341242
char buf[100];
12351243
FILE *memfile;
12361244
va_list args;
12371245

1238-
fd = open("/tmp", O_TMPFILE | O_EXCL | O_RDWR, 0600);
1239-
if (fd == -1) {
1240-
result(llen, SKIPPED);
1241-
return 0;
1246+
ret = pipe(pipefd);
1247+
if (ret == -1) {
1248+
llen += printf(" pipe() != %s", strerror(errno));
1249+
result(llen, FAIL);
1250+
return 1;
12421251
}
12431252

1244-
memfile = fdopen(fd, "w+");
1253+
memfile = fdopen(pipefd[1], "w");
12451254
if (!memfile) {
12461255
result(llen, FAIL);
12471256
return 1;
@@ -1257,13 +1266,10 @@ static int expect_vfprintf(int llen, int c, const char *expected, const char *fm
12571266
return 1;
12581267
}
12591268

1260-
fflush(memfile);
1261-
lseek(fd, 0, SEEK_SET);
1262-
1263-
r = read(fd, buf, sizeof(buf) - 1);
1264-
12651269
fclose(memfile);
12661270

1271+
r = read(pipefd[0], buf, sizeof(buf) - 1);
1272+
12671273
if (r != w) {
12681274
llen += printf(" written(%d) != read(%d)", (int)w, (int)r);
12691275
result(llen, FAIL);
@@ -1323,7 +1329,8 @@ static int run_protection(int min __attribute__((unused)),
13231329
int max __attribute__((unused)))
13241330
{
13251331
pid_t pid;
1326-
int llen = 0, status;
1332+
int llen = 0, ret;
1333+
siginfo_t siginfo = {};
13271334
struct rlimit rlimit = { 0, 0 };
13281335

13291336
llen += printf("0 -fstackprotector ");
@@ -1361,10 +1368,11 @@ static int run_protection(int min __attribute__((unused)),
13611368
return 1;
13621369

13631370
default:
1364-
pid = waitpid(pid, &status, 0);
1371+
ret = waitid(P_PID, pid, &siginfo, WEXITED);
13651372

1366-
if (pid == -1 || !WIFSIGNALED(status) || WTERMSIG(status) != SIGABRT) {
1367-
llen += printf("waitpid()");
1373+
if (ret != 0 || siginfo.si_signo != SIGCHLD ||
1374+
siginfo.si_code != CLD_KILLED || siginfo.si_status != SIGABRT) {
1375+
llen += printf("waitid()");
13681376
result(llen, FAIL);
13691377
return 1;
13701378
}

tools/testing/selftests/nolibc/run-tests.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ perform_download=0
1717
test_mode=system
1818
werror=1
1919
llvm=
20-
archs="i386 x86_64 arm64 arm mips32le mips32be ppc ppc64 ppc64le riscv s390 loongarch"
20+
archs="i386 x86_64 arm64 arm mips32le mips32be ppc ppc64 ppc64le riscv32 riscv64 s390 loongarch"
2121

2222
TEMP=$(getopt -o 'j:d:c:b:a:m:pelh' -n "$0" -- "$@")
2323

@@ -143,6 +143,13 @@ test_arch() {
143143
arch=$1
144144
ct_arch=$(crosstool_arch "$arch")
145145
ct_abi=$(crosstool_abi "$1")
146+
147+
if [ ! -d "${download_location}gcc-${crosstool_version}-nolibc/${ct_arch}-${ct_abi}/bin/." ]; then
148+
echo "No toolchain found in ${download_location}gcc-${crosstool_version}-nolibc/${ct_arch}-${ct_abi}."
149+
echo "Did you install the toolchains or set the correct arch ? Rerun with -h for help."
150+
return 1
151+
fi
152+
146153
cross_compile=$(realpath "${download_location}gcc-${crosstool_version}-nolibc/${ct_arch}-${ct_abi}/bin/${ct_arch}-${ct_abi}-")
147154
build_dir="${build_location}/${arch}"
148155
if [ "$werror" -ne 0 ]; then

0 commit comments

Comments
 (0)