Skip to content

Commit 662ea60

Browse files
wtarreaupaulmckrcu
authored andcommitted
selftests/nolibc: add a "run" target to start the kernel in QEMU
The "run" target will build the kernel and start it in QEMU. The "rerun" target will not have the kernel dependency and will just try to start QEMU. The QEMU architecture used to start the kernel is derived from the configured ARCH. This might need to be improved for archs which include different variants under the same name (mips vs mipsel, +/-64, riscv32 vs riscv64). This could be tested for i386, x86, arm, arm64, mips and riscv (the later two reporting issues on some tests). It is possible to pass a test specification for nolibc-test in the TEST variable, which will be passed as-is as NOLIBC_TEST. On success, the number of successful tests is printed. On failure, failed lines are individually printed. Signed-off-by: Willy Tarreau <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 5c43fd7 commit 662ea60

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

tools/testing/selftests/nolibc/Makefile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,27 @@ DEFCONFIG_mips = malta_defconfig
3131
DEFCONFIG_riscv = defconfig
3232
DEFCONFIG = $(DEFCONFIG_$(ARCH))
3333

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+
3455
# OUTPUT is only set when run from the main makefile, otherwise
3556
# it defaults to this nolibc directory.
3657
OUTPUT ?= $(CURDIR)/
@@ -61,8 +82,20 @@ defconfig:
6182
kernel: initramfs
6283
$(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME) CONFIG_INITRAMFS_SOURCE=$(CURDIR)/initramfs
6384

85+
# run the tests after building the kernel
86+
run: kernel
87+
$(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(srctree)/$(IMAGE)" -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
88+
$(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."
89+
90+
# re-run the tests from an existing kernel
91+
rerun:
92+
$(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(srctree)/$(IMAGE)" -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
93+
$(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."
94+
6495
clean:
6596
$(call QUIET_CLEAN, nolibc-test)
6697
$(Q)rm -f nolibc-test
6798
$(call QUIET_CLEAN, initramfs)
6899
$(Q)rm -rf initramfs
100+
$(call QUIET_CLEAN, run.out)
101+
$(Q)rm -rf run.out

0 commit comments

Comments
 (0)