Skip to content

Commit 45839d0

Browse files
committed
selftests/nolibc: don't embed initramfs into kernel image
When the initramfs is embedded into the kernel each rebuild of it will trigger a full kernel relink and all the expensive postprocessing steps. Currently nolibc-test and therefore the initramfs are always rebuild, even without source changes, leading to lots of slow kernel relinks. Instead of linking the initramfs into the kernel assemble it manually and pass it explicitly to qemu. This avoids all of the kernel relinks. Signed-off-by: Thomas Weißschuh <[email protected]> Reviewed-by: Nicolas Schier <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 4ed03f6 commit 45839d0

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

tools/testing/selftests/nolibc/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/initramfs/
2+
/initramfs.cpio
23
/libc-test
34
/nolibc-test
45
/run.out

tools/testing/selftests/nolibc/Makefile

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,20 @@ REPORT ?= awk '/\[OK\][\r]*$$/{p++} /\[FAIL\][\r]*$$/{if (!f) printf("\n"); f++
131131

132132
help:
133133
@echo "Supported targets under selftests/nolibc:"
134-
@echo " all call the \"run\" target below"
135-
@echo " help this help"
136-
@echo " sysroot create the nolibc sysroot here (uses \$$ARCH)"
137-
@echo " nolibc-test build the executable (uses \$$CC and \$$CROSS_COMPILE)"
138-
@echo " libc-test build an executable using the compiler's default libc instead"
139-
@echo " run-user runs the executable under QEMU (uses \$$XARCH, \$$TEST)"
140-
@echo " initramfs prepare the initramfs with nolibc-test"
141-
@echo " defconfig create a fresh new default config (uses \$$XARCH)"
142-
@echo " kernel (re)build the kernel with the initramfs (uses \$$XARCH)"
143-
@echo " run runs the kernel in QEMU after building it (uses \$$XARCH, \$$TEST)"
144-
@echo " rerun runs a previously prebuilt kernel in QEMU (uses \$$XARCH, \$$TEST)"
145-
@echo " clean clean the sysroot, initramfs, build and output files"
134+
@echo " all call the \"run\" target below"
135+
@echo " help this help"
136+
@echo " sysroot create the nolibc sysroot here (uses \$$ARCH)"
137+
@echo " nolibc-test build the executable (uses \$$CC and \$$CROSS_COMPILE)"
138+
@echo " libc-test build an executable using the compiler's default libc instead"
139+
@echo " run-user runs the executable under QEMU (uses \$$XARCH, \$$TEST)"
140+
@echo " initramfs.cpio prepare the initramfs archive with nolibc-test"
141+
@echo " initramfs prepare the initramfs tree with nolibc-test"
142+
@echo " defconfig create a fresh new default config (uses \$$XARCH)"
143+
@echo " kernel (re)build the kernel (uses \$$XARCH)"
144+
@echo " kernel-standalone (re)build the kernel with the initramfs (uses \$$XARCH)"
145+
@echo " run runs the kernel in QEMU after building it (uses \$$XARCH, \$$TEST)"
146+
@echo " rerun runs a previously prebuilt kernel in QEMU (uses \$$XARCH, \$$TEST)"
147+
@echo " clean clean the sysroot, initramfs, build and output files"
146148
@echo ""
147149
@echo "The output file is \"run.out\". Test ranges may be passed using \$$TEST."
148150
@echo ""
@@ -195,6 +197,9 @@ run-user: nolibc-test
195197
$(Q)qemu-$(QEMU_ARCH) ./nolibc-test > "$(CURDIR)/run.out" || :
196198
$(Q)$(REPORT) $(CURDIR)/run.out
197199

200+
initramfs.cpio: kernel nolibc-test
201+
$(QUIET_GEN)echo 'file /init nolibc-test 755 0 0' | $(srctree)/usr/gen_init_cpio - > initramfs.cpio
202+
198203
initramfs: nolibc-test
199204
$(QUIET_MKDIR)mkdir -p initramfs
200205
$(call QUIET_INSTALL, initramfs/init)
@@ -203,17 +208,20 @@ initramfs: nolibc-test
203208
defconfig:
204209
$(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) mrproper $(DEFCONFIG) prepare
205210

206-
kernel: initramfs
211+
kernel:
212+
$(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME)
213+
214+
kernel-standalone: initramfs
207215
$(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME) CONFIG_INITRAMFS_SOURCE=$(CURDIR)/initramfs
208216

209217
# run the tests after building the kernel
210-
run: kernel
211-
$(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(srctree)/$(IMAGE)" -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
218+
run: kernel initramfs.cpio
219+
$(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(srctree)/$(IMAGE)" -initrd initramfs.cpio -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
212220
$(Q)$(REPORT) $(CURDIR)/run.out
213221

214222
# re-run the tests from an existing kernel
215223
rerun:
216-
$(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(srctree)/$(IMAGE)" -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
224+
$(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(srctree)/$(IMAGE)" -initrd initramfs.cpio -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
217225
$(Q)$(REPORT) $(CURDIR)/run.out
218226

219227
# report with existing test log
@@ -227,6 +235,8 @@ clean:
227235
$(Q)rm -f nolibc-test
228236
$(call QUIET_CLEAN, libc-test)
229237
$(Q)rm -f libc-test
238+
$(call QUIET_CLEAN, initramfs.cpio)
239+
$(Q)rm -rf initramfs.cpio
230240
$(call QUIET_CLEAN, initramfs)
231241
$(Q)rm -rf initramfs
232242
$(call QUIET_CLEAN, run.out)

0 commit comments

Comments
 (0)