1# -*- Mode: makefile -*-
2#
3# Multiarch Tests - included from tests/tcg/Makefile.target
4#
5# These tests are plain C and built without any architecture specific code.
6#
7
8MULTIARCH_SRC=$(SRC_PATH)/tests/tcg/multiarch
9
10# Set search path for all sources
11VPATH 	       += $(MULTIARCH_SRC)
12MULTIARCH_SRCS =  $(notdir $(wildcard $(MULTIARCH_SRC)/*.c))
13ifeq ($(filter %-linux-user, $(TARGET)),$(TARGET))
14VPATH 	       += $(MULTIARCH_SRC)/linux
15MULTIARCH_SRCS += $(notdir $(wildcard $(MULTIARCH_SRC)/linux/*.c))
16endif
17MULTIARCH_TESTS = $(MULTIARCH_SRCS:.c=)
18
19#
20# The following are any additional rules needed to build things
21#
22
23
24float_%: LDFLAGS+=-lm
25float_%: float_%.c libs/float_helpers.c
26	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< $(MULTIARCH_SRC)/libs/float_helpers.c -o $@ $(LDFLAGS)
27
28run-float_%: float_%
29	$(call run-test,$<, $(QEMU) $(QEMU_OPTS) $<)
30	$(call conditional-diff-out,$<,$(SRC_PATH)/tests/tcg/$(TARGET_NAME)/$<.ref)
31
32
33testthread: LDFLAGS+=-lpthread
34
35threadcount: LDFLAGS+=-lpthread
36
37signals: LDFLAGS+=-lrt -lpthread
38
39munmap-pthread: CFLAGS+=-pthread
40munmap-pthread: LDFLAGS+=-pthread
41
42vma-pthread: CFLAGS+=-pthread
43vma-pthread: LDFLAGS+=-pthread
44
45sigreturn-sigmask: CFLAGS+=-pthread
46sigreturn-sigmask: LDFLAGS+=-pthread
47
48# The vma-pthread seems very sensitive on gitlab and we currently
49# don't know if its exposing a real bug or the test is flaky.
50ifneq ($(GITLAB_CI),)
51run-vma-pthread: vma-pthread
52	$(call skip-test, $<, "flaky on CI?")
53run-plugin-vma-pthread-with-%: vma-pthread
54	$(call skip-test, $<, "flaky on CI?")
55endif
56
57run-test-mmap: test-mmap
58	$(call run-test, test-mmap, $(QEMU) $<, $< (default))
59
60ifneq ($(GDB),)
61GDB_SCRIPT=$(SRC_PATH)/tests/guest-debug/run-test.py
62
63run-gdbstub-sha1: sha1
64	$(call run-test, $@, $(GDB_SCRIPT) \
65		--gdb $(GDB) \
66		--qemu $(QEMU) --qargs "$(QEMU_OPTS)" \
67		--bin $< --test $(MULTIARCH_SRC)/gdbstub/sha1.py, \
68	basic gdbstub support)
69
70run-gdbstub-qxfer-auxv-read: sha1
71	$(call run-test, $@, $(GDB_SCRIPT) \
72		--gdb $(GDB) \
73		--qemu $(QEMU) --qargs "$(QEMU_OPTS)" \
74		--bin $< --test $(MULTIARCH_SRC)/gdbstub/test-qxfer-auxv-read.py, \
75	basic gdbstub qXfer:auxv:read support)
76
77run-gdbstub-qxfer-siginfo-read: segfault
78	$(call run-test, $@, $(GDB_SCRIPT) \
79		--gdb $(GDB) \
80		--qemu $(QEMU) --qargs "$(QEMU_OPTS)" \
81		--bin "$< -s" --test $(MULTIARCH_SRC)/gdbstub/test-qxfer-siginfo-read.py, \
82	basic gdbstub qXfer:siginfo:read support)
83
84run-gdbstub-proc-mappings: sha1
85	$(call run-test, $@, $(GDB_SCRIPT) \
86		--gdb $(GDB) \
87		--qemu $(QEMU) --qargs "$(QEMU_OPTS)" \
88		--bin $< --test $(MULTIARCH_SRC)/gdbstub/test-proc-mappings.py, \
89	proc mappings support)
90
91run-gdbstub-thread-breakpoint: testthread
92	$(call run-test, $@, $(GDB_SCRIPT) \
93		--gdb $(GDB) \
94		--qemu $(QEMU) --qargs "$(QEMU_OPTS)" \
95		--bin $< --test $(MULTIARCH_SRC)/gdbstub/test-thread-breakpoint.py, \
96	hitting a breakpoint on non-main thread)
97
98run-gdbstub-registers: sha512
99	$(call run-test, $@, $(GDB_SCRIPT) \
100		--gdb $(GDB) \
101		--qemu $(QEMU) --qargs "$(QEMU_OPTS)" \
102		--bin $< --test $(MULTIARCH_SRC)/gdbstub/registers.py, \
103	checking register enumeration)
104
105run-gdbstub-prot-none: prot-none
106	$(call run-test, $@, env PROT_NONE_PY=1 $(GDB_SCRIPT) \
107		--gdb $(GDB) \
108		--qemu $(QEMU) --qargs "$(QEMU_OPTS)" \
109		--bin $< --test $(MULTIARCH_SRC)/gdbstub/prot-none.py, \
110	accessing PROT_NONE memory)
111
112run-gdbstub-catch-syscalls: catch-syscalls
113	$(call run-test, $@, $(GDB_SCRIPT) \
114		--gdb $(GDB) \
115		--qemu $(QEMU) --qargs "$(QEMU_OPTS)" \
116		--bin $< --test $(MULTIARCH_SRC)/gdbstub/catch-syscalls.py, \
117	hitting a syscall catchpoint)
118
119run-gdbstub-follow-fork-mode-child: follow-fork-mode
120	$(call run-test, $@, $(GDB_SCRIPT) \
121		--gdb $(GDB) \
122		--qemu $(QEMU) --qargs "$(QEMU_OPTS)" \
123		--bin $< --test $(MULTIARCH_SRC)/gdbstub/follow-fork-mode-child.py, \
124	following children on fork)
125
126run-gdbstub-follow-fork-mode-parent: follow-fork-mode
127	$(call run-test, $@, $(GDB_SCRIPT) \
128		--gdb $(GDB) \
129		--qemu $(QEMU) --qargs "$(QEMU_OPTS)" \
130		--bin $< --test $(MULTIARCH_SRC)/gdbstub/follow-fork-mode-parent.py, \
131	following parents on fork)
132
133else
134run-gdbstub-%:
135	$(call skip-test, "gdbstub test $*", "need working gdb with $(patsubst -%,,$(TARGET_NAME)) support")
136endif
137EXTRA_RUNS += run-gdbstub-sha1 run-gdbstub-qxfer-auxv-read \
138	      run-gdbstub-proc-mappings run-gdbstub-thread-breakpoint \
139	      run-gdbstub-registers run-gdbstub-prot-none \
140	      run-gdbstub-catch-syscalls run-gdbstub-follow-fork-mode-child \
141	      run-gdbstub-follow-fork-mode-parent \
142	      run-gdbstub-qxfer-siginfo-read
143
144# ARM Compatible Semi Hosting Tests
145#
146# Despite having ARM in the name we actually have several
147# architectures that implement it. We gate the tests on the feature
148# appearing in config.
149#
150ifeq ($(CONFIG_ARM_COMPATIBLE_SEMIHOSTING),y)
151VPATH += $(MULTIARCH_SRC)/arm-compat-semi
152
153# Add -I path back to TARGET_NAME for semicall.h
154semihosting: CFLAGS+=-I$(SRC_PATH)/tests/tcg/$(TARGET_NAME)
155
156run-semihosting: semihosting
157	$(call run-test,$<,$(QEMU) $< 2> $<.err)
158
159run-plugin-semihosting-with-%:
160	$(call run-test, $@, $(QEMU) $(QEMU_OPTS) \
161		-plugin $(PLUGIN_LIB)/$(call extract-plugin,$@) \
162		 $(call strip-plugin,$<) 2> $<.err, \
163		$< with $*)
164
165semiconsole: CFLAGS+=-I$(SRC_PATH)/tests/tcg/$(TARGET_NAME)
166
167run-semiconsole: semiconsole
168	$(call skip-test, $<, "MANUAL ONLY")
169
170run-plugin-semiconsole-with-%:
171	$(call skip-test, $<, "MANUAL ONLY")
172
173TESTS += semihosting semiconsole
174endif
175
176# Test plugin memory access instrumentation
177run-plugin-test-plugin-mem-access-with-libmem.so: \
178	PLUGIN_ARGS=$(COMMA)print-accesses=true
179run-plugin-test-plugin-mem-access-with-libmem.so: \
180	CHECK_PLUGIN_OUTPUT_COMMAND= \
181	$(SRC_PATH)/tests/tcg/multiarch/check-plugin-output.sh \
182	$(QEMU) $<
183
184test-plugin-mem-access: CFLAGS+=-pthread -O0
185test-plugin-mem-access: LDFLAGS+=-pthread -O0
186
187# Update TESTS
188TESTS += $(MULTIARCH_TESTS)
189