Skip to content

Commit dda0ba4

Browse files
committed
Merge tag 'nolibc.2022.09.30a' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu
Pull nolibc updates from Paul McKenney: "Most notably greatly improved testing. These tests are located in tools/testing/selftests/nolibc. The output of "make help" is as follows: Supported targets under selftests/nolibc: all call the "run" target below help this help sysroot create the nolibc sysroot here (uses $ARCH) nolibc-test build the executable (uses $CC and $CROSS_COMPILE) initramfs prepare the initramfs with nolibc-test defconfig create a fresh new default config (uses $ARCH) kernel (re)build the kernel with the initramfs (uses $ARCH) run runs the kernel in QEMU after building it (uses $ARCH, $TEST) rerun runs a previously prebuilt kernel in QEMU (uses $ARCH, $TEST) clean clean the sysroot, initramfs, build and output files The output file is "run.out". Test ranges may be passed using $TEST. Currently using the following variables: ARCH = x86 CROSS_COMPILE = CC = gcc OUTPUT = /home/git/linux-rcu/tools/testing/selftests/nolibc/ TEST = QEMU_ARCH = x86_64 [determined from $ARCH] IMAGE_NAME = bzImage [determined from $ARCH] The output of a successful x86 "make run" is currently as follows, with kernel build output omitted: $ make run 71 test(s) passed." * tag 'nolibc.2022.09.30a' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu: selftests/nolibc: Avoid generated files being committed selftests/nolibc: add a "help" target selftests/nolibc: "sysroot" target installs a local copy of the sysroot selftests/nolibc: add a "run" target to start the kernel in QEMU selftests/nolibc: add a "defconfig" target selftests/nolibc: add a "kernel" target to build the kernel with the initramfs selftests/nolibc: support glibc as well selftests/nolibc: condition some tests on /proc existence selftests/nolibc: recreate and populate /dev and /proc if missing selftests/nolibc: on x86, support exiting with isa-debug-exit selftests/nolibc: exit with poweroff on success when getpid() == 1 selftests/nolibc: add a few tests for some libc functions selftests/nolibc: implement a few tests for various syscalls selftests/nolibc: support a test definition format selftests/nolibc: add basic infrastructure to ease creation of nolibc tests tools/nolibc: make sys_mmap() automatically use the right __NR_mmap definition tools/nolibc: fix build warning in sys_mmap() when my_syscall6 is not defined tools/nolibc: make argc 32-bit in riscv startup code
2 parents 0382396 + 43cf168 commit dda0ba4

File tree

6 files changed

+900
-3
lines changed

6 files changed

+900
-3
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14449,6 +14449,7 @@ M: Willy Tarreau <[email protected]>
1444914449
S: Maintained
1445014450
T: git git://git.kernel.org/pub/scm/linux/kernel/git/wtarreau/nolibc.git
1445114451
F: tools/include/nolibc/
14452+
F: tools/testing/selftests/nolibc/
1445214453

1445314454
NSDEPS
1445414455
M: Matthias Maennich <[email protected]>

tools/include/nolibc/arch-riscv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ __asm__ (".section .text\n"
190190
".option norelax\n"
191191
"lla gp, __global_pointer$\n"
192192
".option pop\n"
193-
"ld a0, 0(sp)\n" // argc (a0) was in the stack
193+
"lw a0, 0(sp)\n" // argc (a0) was in the stack
194194
"add a1, sp, "SZREG"\n" // argv (a1) = sp
195195
"slli a2, a0, "PTRLOG"\n" // envp (a2) = SZREG*argc ...
196196
"add a2, a2, "SZREG"\n" // + SZREG (skip null)

tools/include/nolibc/sys.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,12 +692,12 @@ void *sys_mmap(void *addr, size_t length, int prot, int flags, int fd,
692692
{
693693
#ifndef my_syscall6
694694
/* Function not implemented. */
695-
return -ENOSYS;
695+
return (void *)-ENOSYS;
696696
#else
697697

698698
int n;
699699

700-
#if defined(__i386__)
700+
#if defined(__NR_mmap2)
701701
n = __NR_mmap2;
702702
offset >>= 12;
703703
#else
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/initramfs/
2+
/nolibc-test
3+
/run.out
4+
/sysroot/
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# SPDX-License-Identifier: GPL-2.0
2+
# Makefile for nolibc tests
3+
include ../../../scripts/Makefile.include
4+
5+
# we're in ".../tools/testing/selftests/nolibc"
6+
ifeq ($(srctree),)
7+
srctree := $(patsubst %/tools/testing/selftests/,%,$(dir $(CURDIR)))
8+
endif
9+
10+
ifeq ($(ARCH),)
11+
include $(srctree)/scripts/subarch.include
12+
ARCH = $(SUBARCH)
13+
endif
14+
15+
# kernel image names by architecture
16+
IMAGE_i386 = arch/x86/boot/bzImage
17+
IMAGE_x86 = arch/x86/boot/bzImage
18+
IMAGE_arm64 = arch/arm64/boot/Image
19+
IMAGE_arm = arch/arm/boot/zImage
20+
IMAGE_mips = vmlinuz
21+
IMAGE_riscv = arch/riscv/boot/Image
22+
IMAGE = $(IMAGE_$(ARCH))
23+
IMAGE_NAME = $(notdir $(IMAGE))
24+
25+
# default kernel configurations that appear to be usable
26+
DEFCONFIG_i386 = defconfig
27+
DEFCONFIG_x86 = defconfig
28+
DEFCONFIG_arm64 = defconfig
29+
DEFCONFIG_arm = multi_v7_defconfig
30+
DEFCONFIG_mips = malta_defconfig
31+
DEFCONFIG_riscv = defconfig
32+
DEFCONFIG = $(DEFCONFIG_$(ARCH))
33+
34+
# optional tests to run (default = all)
35+
TEST =
36+
37+
# QEMU_ARCH: arch names used by qemu
38+
QEMU_ARCH_i386 = i386
39+
QEMU_ARCH_x86 = x86_64
40+
QEMU_ARCH_arm64 = aarch64
41+
QEMU_ARCH_arm = arm
42+
QEMU_ARCH_mips = mipsel # works with malta_defconfig
43+
QEMU_ARCH_riscv = riscv64
44+
QEMU_ARCH = $(QEMU_ARCH_$(ARCH))
45+
46+
# QEMU_ARGS : some arch-specific args to pass to qemu
47+
QEMU_ARGS_i386 = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=%)"
48+
QEMU_ARGS_x86 = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=%)"
49+
QEMU_ARGS_arm64 = -M virt -cpu cortex-a53 -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)"
50+
QEMU_ARGS_arm = -M virt -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)"
51+
QEMU_ARGS_mips = -M malta -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)"
52+
QEMU_ARGS_riscv = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
53+
QEMU_ARGS = $(QEMU_ARGS_$(ARCH))
54+
55+
# OUTPUT is only set when run from the main makefile, otherwise
56+
# it defaults to this nolibc directory.
57+
OUTPUT ?= $(CURDIR)/
58+
59+
ifeq ($(V),1)
60+
Q=
61+
else
62+
Q=@
63+
endif
64+
65+
CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables
66+
LDFLAGS := -s
67+
68+
help:
69+
@echo "Supported targets under selftests/nolibc:"
70+
@echo " all call the \"run\" target below"
71+
@echo " help this help"
72+
@echo " sysroot create the nolibc sysroot here (uses \$$ARCH)"
73+
@echo " nolibc-test build the executable (uses \$$CC and \$$CROSS_COMPILE)"
74+
@echo " initramfs prepare the initramfs with nolibc-test"
75+
@echo " defconfig create a fresh new default config (uses \$$ARCH)"
76+
@echo " kernel (re)build the kernel with the initramfs (uses \$$ARCH)"
77+
@echo " run runs the kernel in QEMU after building it (uses \$$ARCH, \$$TEST)"
78+
@echo " rerun runs a previously prebuilt kernel in QEMU (uses \$$ARCH, \$$TEST)"
79+
@echo " clean clean the sysroot, initramfs, build and output files"
80+
@echo ""
81+
@echo "The output file is \"run.out\". Test ranges may be passed using \$$TEST."
82+
@echo ""
83+
@echo "Currently using the following variables:"
84+
@echo " ARCH = $(ARCH)"
85+
@echo " CROSS_COMPILE = $(CROSS_COMPILE)"
86+
@echo " CC = $(CC)"
87+
@echo " OUTPUT = $(OUTPUT)"
88+
@echo " TEST = $(TEST)"
89+
@echo " QEMU_ARCH = $(if $(QEMU_ARCH),$(QEMU_ARCH),UNKNOWN_ARCH) [determined from \$$ARCH]"
90+
@echo " IMAGE_NAME = $(if $(IMAGE_NAME),$(IMAGE_NAME),UNKNOWN_ARCH) [determined from \$$ARCH]"
91+
@echo ""
92+
93+
all: run
94+
95+
sysroot: sysroot/$(ARCH)/include
96+
97+
sysroot/$(ARCH)/include:
98+
$(QUIET_MKDIR)mkdir -p sysroot
99+
$(Q)$(MAKE) -C ../../../include/nolibc ARCH=$(ARCH) OUTPUT=$(CURDIR)/sysroot/ headers_standalone
100+
$(Q)mv sysroot/sysroot sysroot/$(ARCH)
101+
102+
nolibc-test: nolibc-test.c sysroot/$(ARCH)/include
103+
$(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
104+
-nostdlib -static -Isysroot/$(ARCH)/include $< -lgcc
105+
106+
initramfs: nolibc-test
107+
$(QUIET_MKDIR)mkdir -p initramfs
108+
$(call QUIET_INSTALL, initramfs/init)
109+
$(Q)cp nolibc-test initramfs/init
110+
111+
defconfig:
112+
$(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) mrproper $(DEFCONFIG) prepare
113+
114+
kernel: initramfs
115+
$(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME) CONFIG_INITRAMFS_SOURCE=$(CURDIR)/initramfs
116+
117+
# run the tests after building the kernel
118+
run: kernel
119+
$(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(srctree)/$(IMAGE)" -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
120+
$(Q)grep -w FAIL "$(CURDIR)/run.out" && echo "See all results in $(CURDIR)/run.out" || echo "$$(grep -c ^[0-9].*OK $(CURDIR)/run.out) test(s) passed."
121+
122+
# re-run the tests from an existing kernel
123+
rerun:
124+
$(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(srctree)/$(IMAGE)" -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
125+
$(Q)grep -w FAIL "$(CURDIR)/run.out" && echo "See all results in $(CURDIR)/run.out" || echo "$$(grep -c ^[0-9].*OK $(CURDIR)/run.out) test(s) passed."
126+
127+
clean:
128+
$(call QUIET_CLEAN, sysroot)
129+
$(Q)rm -rf sysroot
130+
$(call QUIET_CLEAN, nolibc-test)
131+
$(Q)rm -f nolibc-test
132+
$(call QUIET_CLEAN, initramfs)
133+
$(Q)rm -rf initramfs
134+
$(call QUIET_CLEAN, run.out)
135+
$(Q)rm -rf run.out

0 commit comments

Comments
 (0)