Skip to content

Commit c54ba41

Browse files
wtarreaupaulmckrcu
authored andcommitted
selftests/nolibc: Add a "run-user" target to test the program in user land
When developing tests, it is much faster to use the QEMU Linux emulator instead of the system emulator, which among other things avoids kernel-build latencies. Although use of the QEMU Linux emulator does have its limitations (please see below), it is sufficient to test startup code, stdlib code, and syscall calling conventions. However, the current mainline Linux-kernel nolibc setup does not support this. Therefore, add a "run-user" target that immediately executes the prebuilt executable. Again, this approach does have its limitations. For example, the executable runs with the user's privilege level, which can cause some false-positive failures due to insufficient permissions. In addition, if the underlying kernel is old enough to lack some features that nolibc relies on, the result will be false-positive failures in the corresponding tests. However, for nolibc changes not affected by these limittions, the result is a much faster code-compile-test-debug cycle. With this patch, running a userland test is as simple as issuing: make ARCH=xxx CROSS_COMPILE=xxx run-user Signed-off-by: Willy Tarreau <[email protected]> Tested-by: Ammar Faizi <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent f9b0669 commit c54ba41

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

tools/testing/selftests/nolibc/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ help:
8080
@echo " help this help"
8181
@echo " sysroot create the nolibc sysroot here (uses \$$ARCH)"
8282
@echo " nolibc-test build the executable (uses \$$CC and \$$CROSS_COMPILE)"
83+
@echo " run-user runs the executable under QEMU (uses \$$ARCH, \$$TEST)"
8384
@echo " initramfs prepare the initramfs with nolibc-test"
8485
@echo " defconfig create a fresh new default config (uses \$$ARCH)"
8586
@echo " kernel (re)build the kernel with the initramfs (uses \$$ARCH)"
@@ -113,6 +114,11 @@ nolibc-test: nolibc-test.c sysroot/$(ARCH)/include
113114
$(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
114115
-nostdlib -static -Isysroot/$(ARCH)/include $< -lgcc
115116

117+
# qemu user-land test
118+
run-user: nolibc-test
119+
$(Q)qemu-$(QEMU_ARCH) ./nolibc-test > "$(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+
116122
initramfs: nolibc-test
117123
$(QUIET_MKDIR)mkdir -p initramfs
118124
$(call QUIET_INSTALL, initramfs/init)

0 commit comments

Comments
 (0)