Makefile 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. # SPDX-License-Identifier: GPL-2.0
  2. # Makefile for nolibc tests
  3. include ../../../scripts/Makefile.include
  4. # we're in ".../tools/testing/selftests/nolibc"
  5. ifeq ($(srctree),)
  6. srctree := $(patsubst %/tools/testing/selftests/,%,$(dir $(CURDIR)))
  7. endif
  8. ifeq ($(ARCH),)
  9. include $(srctree)/scripts/subarch.include
  10. ARCH = $(SUBARCH)
  11. endif
  12. # kernel image names by architecture
  13. IMAGE_i386 = arch/x86/boot/bzImage
  14. IMAGE_x86 = arch/x86/boot/bzImage
  15. IMAGE_arm64 = arch/arm64/boot/Image
  16. IMAGE_arm = arch/arm/boot/zImage
  17. IMAGE_mips = vmlinuz
  18. IMAGE_riscv = arch/riscv/boot/Image
  19. IMAGE = $(IMAGE_$(ARCH))
  20. IMAGE_NAME = $(notdir $(IMAGE))
  21. # default kernel configurations that appear to be usable
  22. DEFCONFIG_i386 = defconfig
  23. DEFCONFIG_x86 = defconfig
  24. DEFCONFIG_arm64 = defconfig
  25. DEFCONFIG_arm = multi_v7_defconfig
  26. DEFCONFIG_mips = malta_defconfig
  27. DEFCONFIG_riscv = defconfig
  28. DEFCONFIG = $(DEFCONFIG_$(ARCH))
  29. # optional tests to run (default = all)
  30. TEST =
  31. # QEMU_ARCH: arch names used by qemu
  32. QEMU_ARCH_i386 = i386
  33. QEMU_ARCH_x86 = x86_64
  34. QEMU_ARCH_arm64 = aarch64
  35. QEMU_ARCH_arm = arm
  36. QEMU_ARCH_mips = mipsel # works with malta_defconfig
  37. QEMU_ARCH_riscv = riscv64
  38. QEMU_ARCH = $(QEMU_ARCH_$(ARCH))
  39. # QEMU_ARGS : some arch-specific args to pass to qemu
  40. QEMU_ARGS_i386 = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=%)"
  41. QEMU_ARGS_x86 = -M pc -append "console=ttyS0,9600 i8042.noaux panic=-1 $(TEST:%=NOLIBC_TEST=%)"
  42. QEMU_ARGS_arm64 = -M virt -cpu cortex-a53 -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)"
  43. QEMU_ARGS_arm = -M virt -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)"
  44. QEMU_ARGS_mips = -M malta -append "panic=-1 $(TEST:%=NOLIBC_TEST=%)"
  45. QEMU_ARGS_riscv = -M virt -append "console=ttyS0 panic=-1 $(TEST:%=NOLIBC_TEST=%)"
  46. QEMU_ARGS = $(QEMU_ARGS_$(ARCH))
  47. # OUTPUT is only set when run from the main makefile, otherwise
  48. # it defaults to this nolibc directory.
  49. OUTPUT ?= $(CURDIR)/
  50. ifeq ($(V),1)
  51. Q=
  52. else
  53. Q=@
  54. endif
  55. CFLAGS ?= -Os -fno-ident -fno-asynchronous-unwind-tables
  56. LDFLAGS := -s
  57. help:
  58. @echo "Supported targets under selftests/nolibc:"
  59. @echo " all call the \"run\" target below"
  60. @echo " help this help"
  61. @echo " sysroot create the nolibc sysroot here (uses \$$ARCH)"
  62. @echo " nolibc-test build the executable (uses \$$CC and \$$CROSS_COMPILE)"
  63. @echo " initramfs prepare the initramfs with nolibc-test"
  64. @echo " defconfig create a fresh new default config (uses \$$ARCH)"
  65. @echo " kernel (re)build the kernel with the initramfs (uses \$$ARCH)"
  66. @echo " run runs the kernel in QEMU after building it (uses \$$ARCH, \$$TEST)"
  67. @echo " rerun runs a previously prebuilt kernel in QEMU (uses \$$ARCH, \$$TEST)"
  68. @echo " clean clean the sysroot, initramfs, build and output files"
  69. @echo ""
  70. @echo "The output file is \"run.out\". Test ranges may be passed using \$$TEST."
  71. @echo ""
  72. @echo "Currently using the following variables:"
  73. @echo " ARCH = $(ARCH)"
  74. @echo " CROSS_COMPILE = $(CROSS_COMPILE)"
  75. @echo " CC = $(CC)"
  76. @echo " OUTPUT = $(OUTPUT)"
  77. @echo " TEST = $(TEST)"
  78. @echo " QEMU_ARCH = $(if $(QEMU_ARCH),$(QEMU_ARCH),UNKNOWN_ARCH) [determined from \$$ARCH]"
  79. @echo " IMAGE_NAME = $(if $(IMAGE_NAME),$(IMAGE_NAME),UNKNOWN_ARCH) [determined from \$$ARCH]"
  80. @echo ""
  81. all: run
  82. sysroot: sysroot/$(ARCH)/include
  83. sysroot/$(ARCH)/include:
  84. $(QUIET_MKDIR)mkdir -p sysroot
  85. $(Q)$(MAKE) -C ../../../include/nolibc ARCH=$(ARCH) OUTPUT=$(CURDIR)/sysroot/ headers_standalone
  86. $(Q)mv sysroot/sysroot sysroot/$(ARCH)
  87. nolibc-test: nolibc-test.c sysroot/$(ARCH)/include
  88. $(QUIET_CC)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ \
  89. -nostdlib -static -Isysroot/$(ARCH)/include $< -lgcc
  90. initramfs: nolibc-test
  91. $(QUIET_MKDIR)mkdir -p initramfs
  92. $(call QUIET_INSTALL, initramfs/init)
  93. $(Q)cp nolibc-test initramfs/init
  94. defconfig:
  95. $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) mrproper $(DEFCONFIG) prepare
  96. kernel: initramfs
  97. $(Q)$(MAKE) -C $(srctree) ARCH=$(ARCH) CC=$(CC) CROSS_COMPILE=$(CROSS_COMPILE) $(IMAGE_NAME) CONFIG_INITRAMFS_SOURCE=$(CURDIR)/initramfs
  98. # run the tests after building the kernel
  99. run: kernel
  100. $(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(srctree)/$(IMAGE)" -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
  101. $(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."
  102. # re-run the tests from an existing kernel
  103. rerun:
  104. $(Q)qemu-system-$(QEMU_ARCH) -display none -no-reboot -kernel "$(srctree)/$(IMAGE)" -serial stdio $(QEMU_ARGS) > "$(CURDIR)/run.out"
  105. $(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."
  106. clean:
  107. $(call QUIET_CLEAN, sysroot)
  108. $(Q)rm -rf sysroot
  109. $(call QUIET_CLEAN, nolibc-test)
  110. $(Q)rm -f nolibc-test
  111. $(call QUIET_CLEAN, initramfs)
  112. $(Q)rm -rf initramfs
  113. $(call QUIET_CLEAN, run.out)
  114. $(Q)rm -rf run.out