1362aecb2SWilly Tarreau# SPDX-License-Identifier: GPL-2.0
2362aecb2SWilly Tarreau# Makefile for nolibc tests
31a1200b6SThomas Weißschuh# we're in ".../tools/testing/selftests/nolibc"
41a1200b6SThomas Weißschuhifeq ($(srctree),)
51a1200b6SThomas Weißschuhsrctree := $(patsubst %/tools/testing/selftests/,%,$(dir $(CURDIR)))
61a1200b6SThomas Weißschuhendif
71a1200b6SThomas Weißschuh
81a1200b6SThomas Weißschuhinclude $(srctree)/tools/scripts/utilities.mak
91bd75aebSThomas Weißschuh# We need this for the "__cc-option" macro.
101bd75aebSThomas Weißschuhinclude $(srctree)/scripts/Makefile.compiler
11362aecb2SWilly Tarreau
1269620b3aSThomas Weißschuhifneq ($(O),)
1369620b3aSThomas Weißschuhifneq ($(call is-absolute,$(O)),y)
1469620b3aSThomas Weißschuh$(error Only absolute O= parameters are supported)
1569620b3aSThomas Weißschuhendif
16ae574ae3SThomas Weißschuhobjtree := $(O)
17ae574ae3SThomas Weißschuhelse
18ae574ae3SThomas Weißschuhobjtree ?= $(srctree)
1969620b3aSThomas Weißschuhendif
2069620b3aSThomas Weißschuh
21362aecb2SWilly Tarreauifeq ($(ARCH),)
22362aecb2SWilly Tarreauinclude $(srctree)/scripts/subarch.include
23362aecb2SWilly TarreauARCH = $(SUBARCH)
24362aecb2SWilly Tarreauendif
25362aecb2SWilly Tarreau
261bd75aebSThomas Weißschuhcc-option = $(call __cc-option, $(CC),$(CLANG_CROSS_FLAGS),$(1),$(2))
271bd75aebSThomas Weißschuh
28c6c3734fSZhangjin Wu# XARCH extends the kernel's ARCH with a few variants of the same
29c6c3734fSZhangjin Wu# architecture that only differ by the configuration, the toolchain
30c6c3734fSZhangjin Wu# and the Qemu program used. It is copied as-is into ARCH except for
31c6c3734fSZhangjin Wu# a few specific values which are mapped like this:
32c6c3734fSZhangjin Wu#
33c6c3734fSZhangjin Wu#  XARCH        | ARCH      | config
34c6c3734fSZhangjin Wu#  -------------|-----------|-------------------------
35c6c3734fSZhangjin Wu#  ppc          | powerpc   | 32 bits
36c6c3734fSZhangjin Wu#  ppc64        | powerpc   | 64 bits big endian
37c6c3734fSZhangjin Wu#  ppc64le      | powerpc   | 64 bits little endian
38c6c3734fSZhangjin Wu#
39c6c3734fSZhangjin Wu# It is recommended to only use XARCH, though it does not harm if
40c6c3734fSZhangjin Wu# ARCH is already set. For simplicity, ARCH is sufficient for all
41c6c3734fSZhangjin Wu# architectures where both are equal.
42c6c3734fSZhangjin Wu
43c6c3734fSZhangjin Wu# configure default variants for target kernel supported architectures
44587e9845SZhangjin WuXARCH_powerpc    = ppc
45c4c20a7dSThomas WeißschuhXARCH_mips       = mips32le
46a47b4b9fSThomas WeißschuhXARCH_riscv      = riscv64
47c6c3734fSZhangjin WuXARCH            = $(or $(XARCH_$(ARCH)),$(ARCH))
48c6c3734fSZhangjin Wu
49c6c3734fSZhangjin Wu# map from user input variants to their kernel supported architectures
50*cb839e0cSThomas WeißschuhARCH_armthumb    = arm
51587e9845SZhangjin WuARCH_ppc         = powerpc
52faeb4e09SZhangjin WuARCH_ppc64       = powerpc
538a5040cbSZhangjin WuARCH_ppc64le     = powerpc
54c4c20a7dSThomas WeißschuhARCH_mips32le    = mips
55b4b9fb91SThomas WeißschuhARCH_mips32be    = mips
5660fe1823SThomas WeißschuhARCH_riscv32     = riscv
57a47b4b9fSThomas WeißschuhARCH_riscv64     = riscv
583d1e67c6SThomas WeißschuhARCH_s390x       = s390
59c6c3734fSZhangjin WuARCH            := $(or $(ARCH_$(XARCH)),$(XARCH))
60c6c3734fSZhangjin Wu
61d248cabfSWilly Tarreau# kernel image names by architecture
62d248cabfSWilly TarreauIMAGE_i386       = arch/x86/boot/bzImage
63f9b06695SWilly TarreauIMAGE_x86_64     = arch/x86/boot/bzImage
64d248cabfSWilly TarreauIMAGE_x86        = arch/x86/boot/bzImage
65d248cabfSWilly TarreauIMAGE_arm64      = arch/arm64/boot/Image
66d248cabfSWilly TarreauIMAGE_arm        = arch/arm/boot/zImage
67*cb839e0cSThomas WeißschuhIMAGE_armthumb   = arch/arm/boot/zImage
68c4c20a7dSThomas WeißschuhIMAGE_mips32le   = vmlinuz
69b4b9fb91SThomas WeißschuhIMAGE_mips32be   = vmlinuz
70587e9845SZhangjin WuIMAGE_ppc        = vmlinux
71faeb4e09SZhangjin WuIMAGE_ppc64      = vmlinux
728a5040cbSZhangjin WuIMAGE_ppc64le    = arch/powerpc/boot/zImage
73d248cabfSWilly TarreauIMAGE_riscv      = arch/riscv/boot/Image
7460fe1823SThomas WeißschuhIMAGE_riscv32    = arch/riscv/boot/Image
75a47b4b9fSThomas WeißschuhIMAGE_riscv64    = arch/riscv/boot/Image
763d1e67c6SThomas WeißschuhIMAGE_s390x      = arch/s390/boot/bzImage
779c812b01SThomas WeißschuhIMAGE_s390       = arch/s390/boot/bzImage
786cd77defSFeiyang ChenIMAGE_loongarch  = arch/loongarch/boot/vmlinuz.efi
7969620b3aSThomas WeißschuhIMAGE            = $(objtree)/$(IMAGE_$(XARCH))
80d248cabfSWilly TarreauIMAGE_NAME       = $(notdir $(IMAGE))
81d248cabfSWilly Tarreau
825c43fd79SWilly Tarreau# default kernel configurations that appear to be usable
835c43fd79SWilly TarreauDEFCONFIG_i386       = defconfig
84f9b06695SWilly TarreauDEFCONFIG_x86_64     = defconfig
855c43fd79SWilly TarreauDEFCONFIG_x86        = defconfig
865c43fd79SWilly TarreauDEFCONFIG_arm64      = defconfig
875c43fd79SWilly TarreauDEFCONFIG_arm        = multi_v7_defconfig
88*cb839e0cSThomas WeißschuhDEFCONFIG_armthumb   = multi_v7_defconfig
89c4c20a7dSThomas WeißschuhDEFCONFIG_mips32le   = malta_defconfig
90e16214dcSThomas WeißschuhDEFCONFIG_mips32be   = malta_defconfig generic/eb.config
91587e9845SZhangjin WuDEFCONFIG_ppc        = pmac32_defconfig
92faeb4e09SZhangjin WuDEFCONFIG_ppc64      = powernv_be_defconfig
938a5040cbSZhangjin WuDEFCONFIG_ppc64le    = powernv_defconfig
945c43fd79SWilly TarreauDEFCONFIG_riscv      = defconfig
9560fe1823SThomas WeißschuhDEFCONFIG_riscv32    = rv32_defconfig
96a47b4b9fSThomas WeißschuhDEFCONFIG_riscv64    = defconfig
973d1e67c6SThomas WeißschuhDEFCONFIG_s390x      = defconfig
989c812b01SThomas WeißschuhDEFCONFIG_s390       = defconfig compat.config
996cd77defSFeiyang ChenDEFCONFIG_loongarch  = defconfig
100c6c3734fSZhangjin WuDEFCONFIG            = $(DEFCONFIG_$(XARCH))
1015c43fd79SWilly Tarreau
1023ab1e9dbSThomas WeißschuhEXTRACONFIG           = $(EXTRACONFIG_$(XARCH))
1033ab1e9dbSThomas Weißschuh
104662ea60eSWilly Tarreau# optional tests to run (default = all)
105662ea60eSWilly TarreauTEST =
106662ea60eSWilly Tarreau
107662ea60eSWilly Tarreau# QEMU_ARCH: arch names used by qemu
108662ea60eSWilly TarreauQEMU_ARCH_i386       = i386
109f9b06695SWilly TarreauQEMU_ARCH_x86_64     = x86_64
110662ea60eSWilly TarreauQEMU_ARCH_x86        = x86_64
111662ea60eSWilly TarreauQEMU_ARCH_arm64      = aarch64
112662ea60eSWilly TarreauQEMU_ARCH_arm        = arm
113*cb839e0cSThomas WeißschuhQEMU_ARCH_armthumb   = arm
114c4c20a7dSThomas WeißschuhQEMU_ARCH_mips32le   = mipsel  # works with malta_defconfig
115b4b9fb91SThomas WeißschuhQEMU_ARCH_mips32be  = mips
116587e9845SZhangjin WuQEMU_ARCH_ppc        = ppc
117faeb4e09SZhangjin WuQEMU_ARCH_ppc64      = ppc64
11817362f3dSThomas WeißschuhQEMU_ARCH_ppc64le    = ppc64
119662ea60eSWilly TarreauQEMU_ARCH_riscv      = riscv64
12060fe1823SThomas WeißschuhQEMU_ARCH_riscv32    = riscv32
121a47b4b9fSThomas WeißschuhQEMU_ARCH_riscv64    = riscv64
1223d1e67c6SThomas WeißschuhQEMU_ARCH_s390x      = s390x
1239c812b01SThomas WeißschuhQEMU_ARCH_s390       = s390x
1246cd77defSFeiyang ChenQEMU_ARCH_loongarch  = loongarch64
125c6c3734fSZhangjin WuQEMU_ARCH            = $(QEMU_ARCH_$(XARCH))
126662ea60eSWilly Tarreau
127d7233e2bSThomas WeißschuhQEMU_ARCH_USER_ppc64le = ppc64le
128d7233e2bSThomas WeißschuhQEMU_ARCH_USER         = $(or $(QEMU_ARCH_USER_$(XARCH)),$(QEMU_ARCH_$(XARCH)))
129d7233e2bSThomas Weißschuh
130bdeeeabaSThomas WeißschuhQEMU_BIOS_DIR = /usr/share/edk2/
131bdeeeabaSThomas WeißschuhQEMU_BIOS_loongarch = $(QEMU_BIOS_DIR)/loongarch64/OVMF_CODE.fd
132bdeeeabaSThomas Weißschuh
133bdeeeabaSThomas Weißschuhifneq ($(QEMU_BIOS_$(XARCH)),)
134bdeeeabaSThomas WeißschuhQEMU_ARGS_BIOS = -bios $(QEMU_BIOS_$(XARCH))
135bdeeeabaSThomas Weißschuhendif
136bdeeeabaSThomas Weißschuh
137662ea60eSWilly Tarreau# QEMU_ARGS : some arch-specific args to pass to qemu
138662ea60eSWilly TarreauQEMU_ARGS_i386       = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=%)"
139f9b06695SWilly TarreauQEMU_ARGS_x86_64     = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=%)"
140662ea60eSWilly TarreauQEMU_ARGS_x86        = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=%)"
141662ea60eSWilly TarreauQEMU_ARGS_arm64      = -M virt -cpu cortex-a53 -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)"
142662ea60eSWilly TarreauQEMU_ARGS_arm        = -M virt -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)"
143*cb839e0cSThomas WeißschuhQEMU_ARGS_armthumb   = -M virt -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)"
144c4c20a7dSThomas WeißschuhQEMU_ARGS_mips32le   = -M malta -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)"
145b4b9fb91SThomas WeißschuhQEMU_ARGS_mips32be   = -M malta -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)"
146587e9845SZhangjin WuQEMU_ARGS_ppc        = -M g3beige -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
147faeb4e09SZhangjin WuQEMU_ARGS_ppc64      = -M powernv -append "console=hvc0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
1488a5040cbSZhangjin WuQEMU_ARGS_ppc64le    = -M powernv -append "console=hvc0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
149662ea60eSWilly TarreauQEMU_ARGS_riscv      = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
15060fe1823SThomas WeißschuhQEMU_ARGS_riscv32    = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
151a47b4b9fSThomas WeißschuhQEMU_ARGS_riscv64    = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
1523d1e67c6SThomas WeißschuhQEMU_ARGS_s390x      = -M s390-ccw-virtio -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
1539c812b01SThomas WeißschuhQEMU_ARGS_s390       = -M s390-ccw-virtio -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
1546cd77defSFeiyang ChenQEMU_ARGS_loongarch  = -M virt -append "console=ttyS0,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
155ad0558f3SThomas WeißschuhQEMU_ARGS            = -m 1G $(QEMU_ARGS_$(XARCH)) $(QEMU_ARGS_BIOS) $(QEMU_ARGS_EXTRA)
156662ea60eSWilly Tarreau
157362aecb2SWilly Tarreau# OUTPUT is only set when run from the main makefile, otherwise
158362aecb2SWilly Tarreau# it defaults to this nolibc directory.
159362aecb2SWilly TarreauOUTPUT ?= $(CURDIR)/
160362aecb2SWilly Tarreau
161362aecb2SWilly Tarreauifeq ($(V),1)
162362aecb2SWilly TarreauQ=
163362aecb2SWilly Tarreauelse
164362aecb2SWilly TarreauQ=@
165362aecb2SWilly Tarreauendif
166362aecb2SWilly Tarreau
16795315486SThomas WeißschuhCFLAGS_i386 = $(call cc-option,-m32)
168f8bedb30SThomas WeißschuhCFLAGS_arm = -marm
169*cb839e0cSThomas WeißschuhCFLAGS_armthumb = -mthumb -march=armv6t2
170587e9845SZhangjin WuCFLAGS_ppc = -m32 -mbig-endian -mno-vsx $(call cc-option,-mmultiple)
171faeb4e09SZhangjin WuCFLAGS_ppc64 = -m64 -mbig-endian -mno-vsx $(call cc-option,-mmultiple)
1728a5040cbSZhangjin WuCFLAGS_ppc64le = -m64 -mlittle-endian -mno-vsx $(call cc-option,-mabi=elfv2)
1733d1e67c6SThomas WeißschuhCFLAGS_s390x = -m64
1749c812b01SThomas WeißschuhCFLAGS_s390 = -m31
17554410245SThomas WeißschuhCFLAGS_mips32le = -EL -mabi=32 -fPIC
176b4b9fb91SThomas WeißschuhCFLAGS_mips32be = -EB -mabi=32
1770093c2daSThomas WeißschuhCFLAGS_STACKPROTECTOR ?= $(call cc-option,-mstack-protector-guard=global $(call cc-option,-fstack-protector-all))
17845f65f8dSThomas WeißschuhCFLAGS  ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -W -Wall -Wextra \
1794da4e35eSThomas Weißschuh		$(call cc-option,-fno-stack-protector) $(call cc-option,-Wmissing-prototypes) \
180774e6ef2SThomas Weißschuh		$(CFLAGS_$(XARCH)) $(CFLAGS_STACKPROTECTOR) $(CFLAGS_EXTRA)
181711edef8SThomas WeißschuhLDFLAGS :=
182362aecb2SWilly Tarreau
183801cf69cSThomas WeißschuhLIBGCC := -lgcc
184801cf69cSThomas Weißschuh
185801cf69cSThomas Weißschuhifneq ($(LLVM),)
186801cf69cSThomas Weißschuh# Not needed for clang
187801cf69cSThomas WeißschuhLIBGCC :=
188801cf69cSThomas Weißschuhendif
189801cf69cSThomas Weißschuh
190ae574ae3SThomas Weißschuh# Modify CFLAGS based on LLVM=
191ae574ae3SThomas Weißschuhinclude $(srctree)/tools/scripts/Makefile.include
192ae574ae3SThomas Weißschuh
1938404af7eSThomas Weißschuh# GCC uses "s390", clang "systemz"
1948404af7eSThomas WeißschuhCLANG_CROSS_FLAGS := $(subst --target=s390-linux,--target=systemz-linux,$(CLANG_CROSS_FLAGS))
1958404af7eSThomas Weißschuh
1964beb9be8SZhangjin WuREPORT  ?= awk '/\[OK\][\r]*$$/{p++} /\[FAIL\][\r]*$$/{if (!f) printf("\n"); f++; print;} /\[SKIPPED\][\r]*$$/{s++} \
1977d92e893SZhangjin Wu		END{ printf("\n%3d test(s): %3d passed, %3d skipped, %3d failed => status: ", p+s+f, p, s, f); \
198ddae1d7fSThomas Weißschuh		if (f || !p) printf("failure\n"); else if (s) printf("warning\n"); else printf("success\n");; \
1997d92e893SZhangjin Wu		printf("\nSee all results in %s\n", ARGV[1]); }'
2005ef95663SZhangjin Wu
201ffc297feSWilly Tarreauhelp:
202ffc297feSWilly Tarreau	@echo "Supported targets under selftests/nolibc:"
203ffc297feSWilly Tarreau	@echo "  all               call the \"run\" target below"
204ffc297feSWilly Tarreau	@echo "  help              this help"
205ffc297feSWilly Tarreau	@echo "  sysroot           create the nolibc sysroot here (uses \$$ARCH)"
206ffc297feSWilly Tarreau	@echo "  nolibc-test       build the executable (uses \$$CC and \$$CROSS_COMPILE)"
207fc82d7dbSThomas Weißschuh	@echo "  libc-test         build an executable using the compiler's default libc instead"
208c6c3734fSZhangjin Wu	@echo "  run-user          runs the executable under QEMU (uses \$$XARCH, \$$TEST)"
20945839d09SThomas Weißschuh	@echo "  initramfs.cpio    prepare the initramfs archive with nolibc-test"
21045839d09SThomas Weißschuh	@echo "  initramfs         prepare the initramfs tree with nolibc-test"
211c6c3734fSZhangjin Wu	@echo "  defconfig         create a fresh new default config (uses \$$XARCH)"
21245839d09SThomas Weißschuh	@echo "  kernel            (re)build the kernel (uses \$$XARCH)"
21345839d09SThomas Weißschuh	@echo "  kernel-standalone (re)build the kernel with the initramfs (uses \$$XARCH)"
214c6c3734fSZhangjin Wu	@echo "  run               runs the kernel in QEMU after building it (uses \$$XARCH, \$$TEST)"
215c6c3734fSZhangjin Wu	@echo "  rerun             runs a previously prebuilt kernel in QEMU (uses \$$XARCH, \$$TEST)"
216ffc297feSWilly Tarreau	@echo "  clean             clean the sysroot, initramfs, build and output files"
217ffc297feSWilly Tarreau	@echo ""
218ffc297feSWilly Tarreau	@echo "The output file is \"run.out\". Test ranges may be passed using \$$TEST."
219ffc297feSWilly Tarreau	@echo ""
220ffc297feSWilly Tarreau	@echo "Currently using the following variables:"
221ffc297feSWilly Tarreau	@echo "  ARCH          = $(ARCH)"
222c6c3734fSZhangjin Wu	@echo "  XARCH         = $(XARCH)"
223ffc297feSWilly Tarreau	@echo "  CROSS_COMPILE = $(CROSS_COMPILE)"
224ffc297feSWilly Tarreau	@echo "  CC            = $(CC)"
225ffc297feSWilly Tarreau	@echo "  OUTPUT        = $(OUTPUT)"
226ffc297feSWilly Tarreau	@echo "  TEST          = $(TEST)"
227c6c3734fSZhangjin Wu	@echo "  QEMU_ARCH     = $(if $(QEMU_ARCH),$(QEMU_ARCH),UNKNOWN_ARCH) [determined from \$$XARCH]"
228c6c3734fSZhangjin Wu	@echo "  IMAGE_NAME    = $(if $(IMAGE_NAME),$(IMAGE_NAME),UNKNOWN_ARCH) [determined from \$$XARCH]"
229ffc297feSWilly Tarreau	@echo ""
230ffc297feSWilly Tarreau
231ffc297feSWilly Tarreauall: run
232362aecb2SWilly Tarreau
233b25c5284SWilly Tarreausysroot: sysroot/$(ARCH)/include
234b25c5284SWilly Tarreau
235d7d271ecSThomas Weißschuhsysroot/$(ARCH)/include: | defconfig
2364a95be7eSWilly Tarreau	$(Q)rm -rf sysroot/$(ARCH) sysroot/sysroot
237b25c5284SWilly Tarreau	$(QUIET_MKDIR)mkdir -p sysroot
23869620b3aSThomas Weißschuh	$(Q)$(MAKE) -C $(srctree) outputmakefile
2397263c9d9SThomas Weißschuh	$(Q)$(MAKE) -C $(srctree)/tools/include/nolibc ARCH=$(ARCH) OUTPUT=$(CURDIR)/sysroot/ headers_standalone
240b25c5284SWilly Tarreau	$(Q)mv sysroot/sysroot sysroot/$(ARCH)
241b25c5284SWilly Tarreau
242850fad7dSZhangjin Wuifneq ($(NOLIBC_SYSROOT),0)
243b8c60e8fSThomas Weißschuhnolibc-test: nolibc-test.c nolibc-test-linkage.c sysroot/$(ARCH)/include
244362aecb2SWilly Tarreau	$(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
245801cf69cSThomas Weißschuh	  -nostdlib -nostdinc -static -Isysroot/$(ARCH)/include nolibc-test.c nolibc-test-linkage.c $(LIBGCC)
246850fad7dSZhangjin Wuelse
247b8c60e8fSThomas Weißschuhnolibc-test: nolibc-test.c nolibc-test-linkage.c
248850fad7dSZhangjin Wu	$(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
249801cf69cSThomas Weißschuh	  -nostdlib -static -include $(srctree)/tools/include/nolibc/nolibc.h nolibc-test.c nolibc-test-linkage.c $(LIBGCC)
250850fad7dSZhangjin Wuendif
251362aecb2SWilly Tarreau
252b8c60e8fSThomas Weißschuhlibc-test: nolibc-test.c nolibc-test-linkage.c
253b8c60e8fSThomas Weißschuh	$(QUIET_CC)$(HOSTCC) -o $@ nolibc-test.c nolibc-test-linkage.c
254fc82d7dbSThomas Weißschuh
255b8143407SZhangjin Wu# local libc-test
256cfb672f9SZhangjin Wurun-libc-test: libc-test
257cfb672f9SZhangjin Wu	$(Q)./libc-test > "$(CURDIR)/run.out" || :
258cfb672f9SZhangjin Wu	$(Q)$(REPORT) $(CURDIR)/run.out
259cfb672f9SZhangjin Wu
260b8143407SZhangjin Wu# local nolibc-test
261b8143407SZhangjin Wurun-nolibc-test: nolibc-test
262b8143407SZhangjin Wu	$(Q)./nolibc-test > "$(CURDIR)/run.out" || :
263b8143407SZhangjin Wu	$(Q)$(REPORT) $(CURDIR)/run.out
264b8143407SZhangjin Wu
265c54ba417SWilly Tarreau# qemu user-land test
266c54ba417SWilly Tarreaurun-user: nolibc-test
267d7233e2bSThomas Weißschuh	$(Q)qemu-$(QEMU_ARCH_USER) ./nolibc-test > "$(CURDIR)/run.out" || :
2685ef95663SZhangjin Wu	$(Q)$(REPORT) $(CURDIR)/run.out
269c54ba417SWilly Tarreau
27045839d09SThomas Weißschuhinitramfs.cpio: kernel nolibc-test
27169620b3aSThomas Weißschuh	$(QUIET_GEN)echo 'file /init nolibc-test 755 0 0' | $(objtree)/usr/gen_init_cpio - > initramfs.cpio
27245839d09SThomas Weißschuh
273362aecb2SWilly Tarreauinitramfs: nolibc-test
274362aecb2SWilly Tarreau	$(QUIET_MKDIR)mkdir -p initramfs
275362aecb2SWilly Tarreau	$(call QUIET_INSTALL, initramfs/init)
276362aecb2SWilly Tarreau	$(Q)cp nolibc-test initramfs/init
277362aecb2SWilly Tarreau
2785c43fd79SWilly Tarreaudefconfig:
27925d5ef9eSThomas Weißschuh	$(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(DEFCONFIG)
2803ab1e9dbSThomas Weißschuh	$(Q)if [ -n "$(EXTRACONFIG)" ]; then \
2813ab1e9dbSThomas Weißschuh		$(srctree)/scripts/config --file $(objtree)/.config $(EXTRACONFIG); \
2823ab1e9dbSThomas Weißschuh		$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) olddefconfig < /dev/null; \
2833ab1e9dbSThomas Weißschuh	fi
2845c43fd79SWilly Tarreau
285d7d271ecSThomas Weißschuhkernel: | defconfig
28689b212d4SThomas Weißschuh	$(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME) < /dev/null
28745839d09SThomas Weißschuh
288d7d271ecSThomas Weißschuhkernel-standalone: initramfs | defconfig
28989b212d4SThomas Weißschuh	$(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME) CONFIG_INITRAMFS_SOURCE=$(CURDIR)/initramfs < /dev/null
290d248cabfSWilly Tarreau
291662ea60eSWilly Tarreau# run the tests after building the kernel
29245839d09SThomas Weißschuhrun: kernel initramfs.cpio
29369620b3aSThomas Weißschuh	$(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(IMAGE)" -initrd initramfs.cpio -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
2945ef95663SZhangjin Wu	$(Q)$(REPORT) $(CURDIR)/run.out
295662ea60eSWilly Tarreau
296662ea60eSWilly Tarreau# re-run the tests from an existing kernel
297662ea60eSWilly Tarreaurerun:
29869620b3aSThomas Weißschuh	$(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(IMAGE)" -initrd initramfs.cpio -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
2995ef95663SZhangjin Wu	$(Q)$(REPORT) $(CURDIR)/run.out
300662ea60eSWilly Tarreau
301ce1bb82bSZhangjin Wu# report with existing test log
302ce1bb82bSZhangjin Wureport:
303ce1bb82bSZhangjin Wu	$(Q)$(REPORT) $(CURDIR)/run.out
304ce1bb82bSZhangjin Wu
305362aecb2SWilly Tarreauclean:
306b25c5284SWilly Tarreau	$(call QUIET_CLEAN, sysroot)
307b25c5284SWilly Tarreau	$(Q)rm -rf sysroot
308362aecb2SWilly Tarreau	$(call QUIET_CLEAN, nolibc-test)
309362aecb2SWilly Tarreau	$(Q)rm -f nolibc-test
310fc82d7dbSThomas Weißschuh	$(call QUIET_CLEAN, libc-test)
311fc82d7dbSThomas Weißschuh	$(Q)rm -f libc-test
31245839d09SThomas Weißschuh	$(call QUIET_CLEAN, initramfs.cpio)
31345839d09SThomas Weißschuh	$(Q)rm -rf initramfs.cpio
314362aecb2SWilly Tarreau	$(call QUIET_CLEAN, initramfs)
315362aecb2SWilly Tarreau	$(Q)rm -rf initramfs
316662ea60eSWilly Tarreau	$(call QUIET_CLEAN, run.out)
317662ea60eSWilly Tarreau	$(Q)rm -rf run.out
3184a95be7eSWilly Tarreau
3194a95be7eSWilly Tarreau.PHONY: sysroot/$(ARCH)/include
320