Commit | Line | Data |
---|---|---|
362aecb2 WT |
1 | # SPDX-License-Identifier: GPL-2.0 |
2 | # Makefile for nolibc tests | |
3 | include ../../../scripts/Makefile.include | |
69620b3a | 4 | include ../../../scripts/utilities.mak |
077b70fb TW |
5 | # We need this for the "cc-option" macro. |
6 | include ../../../build/Build.include | |
362aecb2 | 7 | |
69620b3a TW |
8 | ifneq ($(O),) |
9 | ifneq ($(call is-absolute,$(O)),y) | |
10 | $(error Only absolute O= parameters are supported) | |
11 | endif | |
12 | endif | |
13 | ||
362aecb2 WT |
14 | # we're in ".../tools/testing/selftests/nolibc" |
15 | ifeq ($(srctree),) | |
16 | srctree := $(patsubst %/tools/testing/selftests/,%,$(dir $(CURDIR))) | |
17 | endif | |
18 | ||
19 | ifeq ($(ARCH),) | |
20 | include $(srctree)/scripts/subarch.include | |
21 | ARCH = $(SUBARCH) | |
22 | endif | |
23 | ||
69620b3a TW |
24 | objtree ?= $(srctree) |
25 | ||
c6c3734f ZW |
26 | # XARCH extends the kernel's ARCH with a few variants of the same |
27 | # architecture that only differ by the configuration, the toolchain | |
28 | # and the Qemu program used. It is copied as-is into ARCH except for | |
29 | # a few specific values which are mapped like this: | |
30 | # | |
31 | # XARCH | ARCH | config | |
32 | # -------------|-----------|------------------------- | |
33 | # ppc | powerpc | 32 bits | |
34 | # ppc64 | powerpc | 64 bits big endian | |
35 | # ppc64le | powerpc | 64 bits little endian | |
36 | # | |
37 | # It is recommended to only use XARCH, though it does not harm if | |
38 | # ARCH is already set. For simplicity, ARCH is sufficient for all | |
39 | # architectures where both are equal. | |
40 | ||
41 | # configure default variants for target kernel supported architectures | |
587e9845 | 42 | XARCH_powerpc = ppc |
c4c20a7d | 43 | XARCH_mips = mips32le |
c6c3734f ZW |
44 | XARCH = $(or $(XARCH_$(ARCH)),$(ARCH)) |
45 | ||
46 | # map from user input variants to their kernel supported architectures | |
587e9845 | 47 | ARCH_ppc = powerpc |
faeb4e09 | 48 | ARCH_ppc64 = powerpc |
8a5040cb | 49 | ARCH_ppc64le = powerpc |
c4c20a7d | 50 | ARCH_mips32le = mips |
b4b9fb91 | 51 | ARCH_mips32be = mips |
c6c3734f ZW |
52 | ARCH := $(or $(ARCH_$(XARCH)),$(XARCH)) |
53 | ||
d248cabf | 54 | # kernel image names by architecture |
82e44139 FC |
55 | IMAGE_i386 = arch/x86/boot/bzImage |
56 | IMAGE_x86_64 = arch/x86/boot/bzImage | |
57 | IMAGE_x86 = arch/x86/boot/bzImage | |
58 | IMAGE_arm64 = arch/arm64/boot/Image | |
59 | IMAGE_arm = arch/arm/boot/zImage | |
c4c20a7d | 60 | IMAGE_mips32le = vmlinuz |
b4b9fb91 | 61 | IMAGE_mips32be = vmlinuz |
587e9845 | 62 | IMAGE_ppc = vmlinux |
faeb4e09 | 63 | IMAGE_ppc64 = vmlinux |
8a5040cb | 64 | IMAGE_ppc64le = arch/powerpc/boot/zImage |
82e44139 FC |
65 | IMAGE_riscv = arch/riscv/boot/Image |
66 | IMAGE_s390 = arch/s390/boot/bzImage | |
6cd77def | 67 | IMAGE_loongarch = arch/loongarch/boot/vmlinuz.efi |
69620b3a | 68 | IMAGE = $(objtree)/$(IMAGE_$(XARCH)) |
82e44139 | 69 | IMAGE_NAME = $(notdir $(IMAGE)) |
d248cabf | 70 | |
5c43fd79 | 71 | # default kernel configurations that appear to be usable |
82e44139 FC |
72 | DEFCONFIG_i386 = defconfig |
73 | DEFCONFIG_x86_64 = defconfig | |
74 | DEFCONFIG_x86 = defconfig | |
75 | DEFCONFIG_arm64 = defconfig | |
76 | DEFCONFIG_arm = multi_v7_defconfig | |
c4c20a7d | 77 | DEFCONFIG_mips32le = malta_defconfig |
b4b9fb91 | 78 | DEFCONFIG_mips32be = malta_defconfig |
587e9845 | 79 | DEFCONFIG_ppc = pmac32_defconfig |
faeb4e09 | 80 | DEFCONFIG_ppc64 = powernv_be_defconfig |
8a5040cb | 81 | DEFCONFIG_ppc64le = powernv_defconfig |
82e44139 FC |
82 | DEFCONFIG_riscv = defconfig |
83 | DEFCONFIG_s390 = defconfig | |
6cd77def | 84 | DEFCONFIG_loongarch = defconfig |
c6c3734f | 85 | DEFCONFIG = $(DEFCONFIG_$(XARCH)) |
5c43fd79 | 86 | |
b4b9fb91 | 87 | EXTRACONFIG_mips32be = -d CONFIG_CPU_LITTLE_ENDIAN -e CONFIG_CPU_BIG_ENDIAN |
3ab1e9db TW |
88 | EXTRACONFIG = $(EXTRACONFIG_$(XARCH)) |
89 | ||
662ea60e WT |
90 | # optional tests to run (default = all) |
91 | TEST = | |
92 | ||
93 | # QEMU_ARCH: arch names used by qemu | |
82e44139 FC |
94 | QEMU_ARCH_i386 = i386 |
95 | QEMU_ARCH_x86_64 = x86_64 | |
96 | QEMU_ARCH_x86 = x86_64 | |
97 | QEMU_ARCH_arm64 = aarch64 | |
98 | QEMU_ARCH_arm = arm | |
c4c20a7d | 99 | QEMU_ARCH_mips32le = mipsel # works with malta_defconfig |
b4b9fb91 | 100 | QEMU_ARCH_mips32be = mips |
587e9845 | 101 | QEMU_ARCH_ppc = ppc |
faeb4e09 | 102 | QEMU_ARCH_ppc64 = ppc64 |
17362f3d | 103 | QEMU_ARCH_ppc64le = ppc64 |
82e44139 FC |
104 | QEMU_ARCH_riscv = riscv64 |
105 | QEMU_ARCH_s390 = s390x | |
6cd77def | 106 | QEMU_ARCH_loongarch = loongarch64 |
c6c3734f | 107 | QEMU_ARCH = $(QEMU_ARCH_$(XARCH)) |
662ea60e | 108 | |
d7233e2b TW |
109 | QEMU_ARCH_USER_ppc64le = ppc64le |
110 | QEMU_ARCH_USER = $(or $(QEMU_ARCH_USER_$(XARCH)),$(QEMU_ARCH_$(XARCH))) | |
111 | ||
bdeeeaba TW |
112 | QEMU_BIOS_DIR = /usr/share/edk2/ |
113 | QEMU_BIOS_loongarch = $(QEMU_BIOS_DIR)/loongarch64/OVMF_CODE.fd | |
114 | ||
115 | ifneq ($(QEMU_BIOS_$(XARCH)),) | |
116 | QEMU_ARGS_BIOS = -bios $(QEMU_BIOS_$(XARCH)) | |
117 | endif | |
118 | ||
662ea60e | 119 | # QEMU_ARGS : some arch-specific args to pass to qemu |
82e44139 FC |
120 | QEMU_ARGS_i386 = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=%)" |
121 | QEMU_ARGS_x86_64 = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=%)" | |
122 | QEMU_ARGS_x86 = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=%)" | |
123 | QEMU_ARGS_arm64 = -M virt -cpu cortex-a53 -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)" | |
124 | QEMU_ARGS_arm = -M virt -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)" | |
c4c20a7d | 125 | QEMU_ARGS_mips32le = -M malta -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)" |
b4b9fb91 | 126 | QEMU_ARGS_mips32be = -M malta -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)" |
587e9845 | 127 | QEMU_ARGS_ppc = -M g3beige -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" |
faeb4e09 | 128 | QEMU_ARGS_ppc64 = -M powernv -append "console=hvc0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" |
8a5040cb | 129 | QEMU_ARGS_ppc64le = -M powernv -append "console=hvc0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" |
82e44139 FC |
130 | QEMU_ARGS_riscv = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" |
131 | QEMU_ARGS_s390 = -M s390-ccw-virtio -m 1G -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)" | |
6cd77def | 132 | QEMU_ARGS_loongarch = -M virt -append "console=ttyS0,115200 panic=-1 $(TEST:%=NOLIBC_TEST=%)" |
bdeeeaba | 133 | QEMU_ARGS = $(QEMU_ARGS_$(XARCH)) $(QEMU_ARGS_BIOS) $(QEMU_ARGS_EXTRA) |
662ea60e | 134 | |
362aecb2 WT |
135 | # OUTPUT is only set when run from the main makefile, otherwise |
136 | # it defaults to this nolibc directory. | |
137 | OUTPUT ?= $(CURDIR)/ | |
138 | ||
139 | ifeq ($(V),1) | |
140 | Q= | |
141 | else | |
142 | Q=@ | |
143 | endif | |
144 | ||
95315486 | 145 | CFLAGS_i386 = $(call cc-option,-m32) |
587e9845 | 146 | CFLAGS_ppc = -m32 -mbig-endian -mno-vsx $(call cc-option,-mmultiple) |
faeb4e09 | 147 | CFLAGS_ppc64 = -m64 -mbig-endian -mno-vsx $(call cc-option,-mmultiple) |
8a5040cb | 148 | CFLAGS_ppc64le = -m64 -mlittle-endian -mno-vsx $(call cc-option,-mabi=elfv2) |
0043e6f2 | 149 | CFLAGS_s390 = -m64 |
54410245 | 150 | CFLAGS_mips32le = -EL -mabi=32 -fPIC |
b4b9fb91 | 151 | CFLAGS_mips32be = -EB -mabi=32 |
0093c2da | 152 | CFLAGS_STACKPROTECTOR ?= $(call cc-option,-mstack-protector-guard=global $(call cc-option,-fstack-protector-all)) |
45f65f8d | 153 | CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables -std=c89 -W -Wall -Wextra \ |
255ffeee | 154 | $(call cc-option,-fno-stack-protector) \ |
c6c3734f | 155 | $(CFLAGS_$(XARCH)) $(CFLAGS_STACKPROTECTOR) |
711edef8 | 156 | LDFLAGS := |
362aecb2 | 157 | |
4beb9be8 | 158 | REPORT ?= awk '/\[OK\][\r]*$$/{p++} /\[FAIL\][\r]*$$/{if (!f) printf("\n"); f++; print;} /\[SKIPPED\][\r]*$$/{s++} \ |
7d92e893 | 159 | END{ printf("\n%3d test(s): %3d passed, %3d skipped, %3d failed => status: ", p+s+f, p, s, f); \ |
c0315c79 | 160 | if (f) printf("failure\n"); else if (s) printf("warning\n"); else printf("success\n");; \ |
7d92e893 | 161 | printf("\nSee all results in %s\n", ARGV[1]); }' |
5ef95663 | 162 | |
ffc297fe WT |
163 | help: |
164 | @echo "Supported targets under selftests/nolibc:" | |
45839d09 TW |
165 | @echo " all call the \"run\" target below" |
166 | @echo " help this help" | |
167 | @echo " sysroot create the nolibc sysroot here (uses \$$ARCH)" | |
168 | @echo " nolibc-test build the executable (uses \$$CC and \$$CROSS_COMPILE)" | |
169 | @echo " libc-test build an executable using the compiler's default libc instead" | |
170 | @echo " run-user runs the executable under QEMU (uses \$$XARCH, \$$TEST)" | |
171 | @echo " initramfs.cpio prepare the initramfs archive with nolibc-test" | |
172 | @echo " initramfs prepare the initramfs tree with nolibc-test" | |
173 | @echo " defconfig create a fresh new default config (uses \$$XARCH)" | |
174 | @echo " kernel (re)build the kernel (uses \$$XARCH)" | |
175 | @echo " kernel-standalone (re)build the kernel with the initramfs (uses \$$XARCH)" | |
176 | @echo " run runs the kernel in QEMU after building it (uses \$$XARCH, \$$TEST)" | |
177 | @echo " rerun runs a previously prebuilt kernel in QEMU (uses \$$XARCH, \$$TEST)" | |
178 | @echo " clean clean the sysroot, initramfs, build and output files" | |
ffc297fe WT |
179 | @echo "" |
180 | @echo "The output file is \"run.out\". Test ranges may be passed using \$$TEST." | |
181 | @echo "" | |
182 | @echo "Currently using the following variables:" | |
183 | @echo " ARCH = $(ARCH)" | |
c6c3734f | 184 | @echo " XARCH = $(XARCH)" |
ffc297fe WT |
185 | @echo " CROSS_COMPILE = $(CROSS_COMPILE)" |
186 | @echo " CC = $(CC)" | |
187 | @echo " OUTPUT = $(OUTPUT)" | |
188 | @echo " TEST = $(TEST)" | |
c6c3734f ZW |
189 | @echo " QEMU_ARCH = $(if $(QEMU_ARCH),$(QEMU_ARCH),UNKNOWN_ARCH) [determined from \$$XARCH]" |
190 | @echo " IMAGE_NAME = $(if $(IMAGE_NAME),$(IMAGE_NAME),UNKNOWN_ARCH) [determined from \$$XARCH]" | |
ffc297fe WT |
191 | @echo "" |
192 | ||
193 | all: run | |
362aecb2 | 194 | |
b25c5284 WT |
195 | sysroot: sysroot/$(ARCH)/include |
196 | ||
197 | sysroot/$(ARCH)/include: | |
4a95be7e | 198 | $(Q)rm -rf sysroot/$(ARCH) sysroot/sysroot |
b25c5284 | 199 | $(QUIET_MKDIR)mkdir -p sysroot |
69620b3a | 200 | $(Q)$(MAKE) -C $(srctree) outputmakefile |
7263c9d9 | 201 | $(Q)$(MAKE) -C $(srctree)/tools/include/nolibc ARCH=$(ARCH) OUTPUT=$(CURDIR)/sysroot/ headers_standalone |
b25c5284 WT |
202 | $(Q)mv sysroot/sysroot sysroot/$(ARCH) |
203 | ||
850fad7d | 204 | ifneq ($(NOLIBC_SYSROOT),0) |
b8c60e8f | 205 | nolibc-test: nolibc-test.c nolibc-test-linkage.c sysroot/$(ARCH)/include |
362aecb2 | 206 | $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \ |
b8c60e8f | 207 | -nostdlib -nostdinc -static -Isysroot/$(ARCH)/include nolibc-test.c nolibc-test-linkage.c -lgcc |
850fad7d | 208 | else |
b8c60e8f | 209 | nolibc-test: nolibc-test.c nolibc-test-linkage.c |
850fad7d | 210 | $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \ |
7263c9d9 | 211 | -nostdlib -static -include $(srctree)/tools/include/nolibc/nolibc.h nolibc-test.c nolibc-test-linkage.c -lgcc |
850fad7d | 212 | endif |
362aecb2 | 213 | |
b8c60e8f TW |
214 | libc-test: nolibc-test.c nolibc-test-linkage.c |
215 | $(QUIET_CC)$(HOSTCC) -o $@ nolibc-test.c nolibc-test-linkage.c | |
fc82d7db | 216 | |
b8143407 | 217 | # local libc-test |
cfb672f9 ZW |
218 | run-libc-test: libc-test |
219 | $(Q)./libc-test > "$(CURDIR)/run.out" || : | |
220 | $(Q)$(REPORT) $(CURDIR)/run.out | |
221 | ||
b8143407 ZW |
222 | # local nolibc-test |
223 | run-nolibc-test: nolibc-test | |
224 | $(Q)./nolibc-test > "$(CURDIR)/run.out" || : | |
225 | $(Q)$(REPORT) $(CURDIR)/run.out | |
226 | ||
c54ba417 WT |
227 | # qemu user-land test |
228 | run-user: nolibc-test | |
d7233e2b | 229 | $(Q)qemu-$(QEMU_ARCH_USER) ./nolibc-test > "$(CURDIR)/run.out" || : |
5ef95663 | 230 | $(Q)$(REPORT) $(CURDIR)/run.out |
c54ba417 | 231 | |
45839d09 | 232 | initramfs.cpio: kernel nolibc-test |
69620b3a | 233 | $(QUIET_GEN)echo 'file /init nolibc-test 755 0 0' | $(objtree)/usr/gen_init_cpio - > initramfs.cpio |
45839d09 | 234 | |
362aecb2 WT |
235 | initramfs: nolibc-test |
236 | $(QUIET_MKDIR)mkdir -p initramfs | |
237 | $(call QUIET_INSTALL, initramfs/init) | |
238 | $(Q)cp nolibc-test initramfs/init | |
239 | ||
5c43fd79 WT |
240 | defconfig: |
241 | $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) mrproper $(DEFCONFIG) prepare | |
3ab1e9db TW |
242 | $(Q)if [ -n "$(EXTRACONFIG)" ]; then \ |
243 | $(srctree)/scripts/config --file $(objtree)/.config $(EXTRACONFIG); \ | |
244 | $(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) olddefconfig < /dev/null; \ | |
245 | fi | |
5c43fd79 | 246 | |
45839d09 | 247 | kernel: |
89b212d4 | 248 | $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME) < /dev/null |
45839d09 TW |
249 | |
250 | kernel-standalone: initramfs | |
89b212d4 | 251 | $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME) CONFIG_INITRAMFS_SOURCE=$(CURDIR)/initramfs < /dev/null |
d248cabf | 252 | |
662ea60e | 253 | # run the tests after building the kernel |
45839d09 | 254 | run: kernel initramfs.cpio |
69620b3a | 255 | $(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(IMAGE)" -initrd initramfs.cpio -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out" |
5ef95663 | 256 | $(Q)$(REPORT) $(CURDIR)/run.out |
662ea60e WT |
257 | |
258 | # re-run the tests from an existing kernel | |
259 | rerun: | |
69620b3a | 260 | $(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(IMAGE)" -initrd initramfs.cpio -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out" |
5ef95663 | 261 | $(Q)$(REPORT) $(CURDIR)/run.out |
662ea60e | 262 | |
ce1bb82b ZW |
263 | # report with existing test log |
264 | report: | |
265 | $(Q)$(REPORT) $(CURDIR)/run.out | |
266 | ||
362aecb2 | 267 | clean: |
b25c5284 WT |
268 | $(call QUIET_CLEAN, sysroot) |
269 | $(Q)rm -rf sysroot | |
362aecb2 WT |
270 | $(call QUIET_CLEAN, nolibc-test) |
271 | $(Q)rm -f nolibc-test | |
fc82d7db TW |
272 | $(call QUIET_CLEAN, libc-test) |
273 | $(Q)rm -f libc-test | |
45839d09 TW |
274 | $(call QUIET_CLEAN, initramfs.cpio) |
275 | $(Q)rm -rf initramfs.cpio | |
362aecb2 WT |
276 | $(call QUIET_CLEAN, initramfs) |
277 | $(Q)rm -rf initramfs | |
662ea60e WT |
278 | $(call QUIET_CLEAN, run.out) |
279 | $(Q)rm -rf run.out | |
4a95be7e WT |
280 | |
281 | .PHONY: sysroot/$(ARCH)/include |