1# -*- Mode: makefile -*- 2# 3# TCG tests 4# 5# These are complicated by the fact we want to build them for guest 6# systems. This requires knowing what guests we are building and which 7# ones we have cross-compilers for or docker images with 8# cross-compilers. 9# 10# The tests themselves should be as minimal as possible as 11# cross-compilers don't always have a large amount of libraries 12# available. 13# 14# We only include the host build system for SRC_PATH and we don't 15# bother with the common rules.mk. We expect the following: 16# 17# CC - the C compiler command 18# EXTRA_CFLAGS - any extra CFLAGS 19# BUILD_STATIC - are we building static binaries 20# 21# By default all tests are statically compiled but some host systems 22# may not package static libraries by default. If an external 23# cross-compiler can only build dynamic libraries the user might need 24# to make extra efforts to ensure ld.so can link at runtime when the 25# tests are run. 26# 27# We also accept SPEED=slow to enable slower running tests 28# 29# We also expect to be in the tests build dir for the FOO-(linux-user|softmmu). 30# 31 32-include ../../config-host.mak 33-include ../config-target.mak 34 35# for including , in command strings 36COMMA := , 37 38quiet-command = $(if $(V),$1,$(if $(2),@printf " %-7s %s\n" $2 $3 && $1, @$1)) 39 40# $1 = test name, $2 = cmd, $3 = desc 41ifdef CONFIG_USER_ONLY 42run-test = $(call quiet-command, timeout $(TIMEOUT) $2 > $1.out,"TEST",$3) 43else 44run-test = $(call quiet-command, timeout $(TIMEOUT) $2,"TEST",$3) 45endif 46 47# $1 = test name, $2 = reference 48diff-out = $(call quiet-command, diff -u $1.out $2 | head -n 10,"DIFF","$1.out with $2") 49 50# $1 = test name, $2 = reason 51skip-test = @printf " SKIPPED %s on $(TARGET_NAME) because %s\n" $1 $2 52 53# Tests we are building 54TESTS= 55 56# Start with a blank slate, the build targets get to add stuff first 57CFLAGS= 58QEMU_CFLAGS= 59LDFLAGS= 60 61# The QEMU for this TARGET 62ifdef CONFIG_USER_ONLY 63QEMU=../qemu-$(TARGET_NAME) 64else 65QEMU=../qemu-system-$(TARGET_NAME) 66endif 67QEMU_OPTS= 68 69 70# If TCG debugging is enabled things are a lot slower 71ifeq ($(CONFIG_DEBUG_TCG),y) 72TIMEOUT=45 73else 74TIMEOUT=15 75endif 76 77ifdef CONFIG_USER_ONLY 78# The order we include is important. We include multiarch, base arch 79# and finally arch if it's not the same as base arch. 80-include $(SRC_PATH)/tests/tcg/multiarch/Makefile.target 81-include $(SRC_PATH)/tests/tcg/$(TARGET_BASE_ARCH)/Makefile.target 82ifneq ($(TARGET_BASE_ARCH),$(TARGET_NAME)) 83-include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.target 84endif 85 86# Add the common build options 87CFLAGS+=-Wall -O0 -g -fno-strict-aliasing 88ifeq ($(BUILD_STATIC),y) 89LDFLAGS+=-static 90endif 91 92%: %.c 93 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS) 94else 95# For softmmu targets we include a different Makefile fragement as the 96# build options for bare programs are usually pretty different. They 97# are expected to provide their own build recipes. 98-include $(SRC_PATH)/tests/tcg/minilib/Makefile.target 99-include $(SRC_PATH)/tests/tcg/$(TARGET_BASE_ARCH)/Makefile.softmmu-target 100ifneq ($(TARGET_BASE_ARCH),$(TARGET_NAME)) 101-include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.softmmu-target 102endif 103 104endif 105 106all: $(TESTS) 107 108# 109# Test Runners 110# 111# By default we just run the test with the appropriate QEMU for the 112# target. More advanced tests may want to override the runner in their 113# specific make rules. Additional runners for the same binary should 114# be added to EXTRA_RUNS. 115# 116 117RUN_TESTS=$(patsubst %,run-%, $(TESTS)) 118RUN_TESTS+=$(EXTRA_RUNS) 119 120ifdef CONFIG_USER_ONLY 121run-%: % 122 $(call run-test, $<, $(QEMU) $(QEMU_OPTS) $<, "$< on $(TARGET_NAME)") 123else 124run-%: % 125 $(call run-test, $<, \ 126 $(QEMU) -monitor none -display none \ 127 -chardev file$(COMMA)path=$<.out$(COMMA)id=output \ 128 $(QEMU_OPTS) $<, \ 129 "$< on $(TARGET_NAME)") 130endif 131 132gdb-%: % 133 gdb --args $(QEMU) $(QEMU_OPTS) $< 134 135.PHONY: run 136run: $(RUN_TESTS) 137 138# There is no clean target, the calling make just rm's the tests build dir 139