xref: /openbmc/qemu/tests/tcg/Makefile.target (revision 0b84b662)
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
32all:
33-include ../../config-host.mak
34-include ../config-$(TARGET).mak
35
36# for including , in command strings
37COMMA := ,
38
39quiet-command = $(if $(V),$1,$(if $(2),@printf "  %-7s %s\n" $2 $3 && $1, @$1))
40
41# $1 = test name, $2 = cmd, $3 = desc
42ifdef CONFIG_USER_ONLY
43run-test = $(call quiet-command, timeout $(TIMEOUT) $2 > $1.out,"TEST",$3)
44else
45run-test = $(call quiet-command, timeout $(TIMEOUT) $2,"TEST",$3)
46endif
47
48# $1 = test name, $2 = reference
49# to work around the pipe squashing the status we only pipe the result if
50# we know it failed and then force failure at the end.
51diff-out = $(call quiet-command, diff -q $1.out $2 || \
52                                 (diff -u $1.out $2 | head -n 10 && false), \
53                                 "DIFF","$1.out with $2")
54
55# $1 = test name, $2 = reason
56skip-test = @printf "  SKIPPED %s on $(TARGET_NAME) because %s\n" $1 $2
57
58# Tests we are building
59TESTS=
60
61# Start with a blank slate, the build targets get to add stuff first
62CFLAGS=
63QEMU_CFLAGS=
64LDFLAGS=
65
66QEMU_OPTS=
67
68
69# If TCG debugging is enabled things are a lot slower
70ifeq ($(CONFIG_DEBUG_TCG),y)
71TIMEOUT=45
72else
73TIMEOUT=15
74endif
75
76ifdef CONFIG_USER_ONLY
77# The order we include is important. We include multiarch, base arch
78# and finally arch if it's not the same as base arch.
79-include $(SRC_PATH)/tests/tcg/multiarch/Makefile.target
80-include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.target
81
82# Add the common build options
83CFLAGS+=-Wall -O0 -g -fno-strict-aliasing
84ifeq ($(BUILD_STATIC),y)
85LDFLAGS+=-static
86endif
87
88%: %.c
89	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS)
90else
91# For softmmu targets we include a different Makefile fragement as the
92# build options for bare programs are usually pretty different. They
93# are expected to provide their own build recipes.
94-include $(SRC_PATH)/tests/tcg/minilib/Makefile.target
95-include $(SRC_PATH)/tests/tcg/multiarch/system/Makefile.softmmu-target
96-include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.softmmu-target
97
98endif
99
100all: $(TESTS)
101
102#
103# Test Runners
104#
105# By default we just run the test with the appropriate QEMU for the
106# target. More advanced tests may want to override the runner in their
107# specific make rules. Additional runners for the same binary should
108# be added to EXTRA_RUNS.
109#
110
111RUN_TESTS=$(patsubst %,run-%, $(TESTS))
112RUN_TESTS+=$(EXTRA_RUNS)
113
114ifdef CONFIG_USER_ONLY
115run-%: %
116	$(call run-test, $<, $(QEMU) $(QEMU_OPTS) $<, "$< on $(TARGET_NAME)")
117else
118run-%: %
119	$(call run-test, $<, \
120	  $(QEMU) -monitor none -display none \
121		  -chardev file$(COMMA)path=$<.out$(COMMA)id=output \
122	   	  $(QEMU_OPTS) $<, \
123	  "$< on $(TARGET_NAME)")
124endif
125
126gdb-%: %
127	gdb --args $(QEMU) $(QEMU_OPTS) $<
128
129.PHONY: run
130run: $(RUN_TESTS)
131
132# There is no clean target, the calling make just rm's the tests build dir
133