• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#
2# Copyright (C) 2023 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16
17################################################################################
18#
19# Run host tests
20#
21# Tests are being run with errors ignored, so that they don't break the build.
22# Gtest reports should be parsed as a separate step (b/34749275).
23# If test crashes before writing into xml, failure is not detected.
24# Thus, we create malformed xml result before launching the test.
25#
26################################################################################
27
28.PHONY: berberis_host_tests_result
29
30.PHONY: berberis_run_host_tests
31
32# Test binaries are build as native bridge targets. So we only enable test runs when native bridge
33# is configured for riscv64.
34ifeq ($(TARGET_NATIVE_BRIDGE_ABI),riscv64)
35berberis_all: berberis_host_tests_result
36endif
37
38test_dir := $(call intermediates-dir-for,PACKAGING,berberis_tests)
39
40gen_failure_template := $(BERBERIS_DIR)/tests/gen_gtest_failure_template.py
41runner_riscv64 := $(HOST_OUT)/bin/berberis_program_runner_riscv64
42# Android's make environment only exposes this path as part of CLANG_HOST_GLOBAL_CFLAGS. It is
43# difficult to extract it from there. On the other hand it hasn't changed between R and U.
44# So we simply hardcode it as it's low maintenance.
45host_libc_root := prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.17-4.8
46
47test_guard := $(test_dir)/remove_me_to_trigger_tests_run
48test_trigger := $(test_dir)/test_run_trigger
49
50
51$(test_guard):
52	echo dummy > $@
53
54$(test_trigger): $(test_guard)
55	-rm $<
56	echo dummy > $@
57
58
59# Run gtest
60# $(1): test name
61# $(2): result path
62# $(3): binary path
63# $(4): env
64define run_test
65
66$(2): $(3) $(gen_failure_template) $(test_trigger)
67	$(gen_failure_template) berberis_host_tests $(1) >$(2)
68	-$(4) $(3) --gtest_output=xml:$(2)
69
70endef
71
72
73# Run x86_64_riscv64 gtest
74# $(1): test name
75# $(2): result path
76# $(3): binary path
77# $(4): env
78define run_test_x86_64_riscv64
79
80$(2): $(3) $(runner_riscv64) $(gen_failure_template) $(test_trigger)
81	$(gen_failure_template) berberis_host_tests_riscv64 $(1) >$(2)
82	# Force running with the prebuilt host libc due to b/254755879.
83	-$(4) LD_LIBRARY_PATH=$(host_libc_root)/x86_64-linux/lib64:$(host_libc_root)/sysroot/usr/lib \
84		$(host_libc_root)/sysroot/usr/lib/ld-linux-x86-64.so.2 \
85		$(runner_riscv64) $(3) --gtest_output=xml:$(2)
86
87endef
88
89
90# Add gtest to run
91# $(1): test name
92# $(2): run rule
93# $(3): binary path
94# $(4): env
95define add_test
96
97# Rule to create result file.
98$(call $(2),$(1),$(test_dir)/$(1)_result.xml,$(3),$(4))
99
100berberis_host_tests_result: $(test_dir)/$(1)_result.xml
101
102$$(call dist-for-goals,berberis_host_tests_result, $(test_dir)/$(1)_result.xml:gtest/$(1)_result.xml)
103
104# Rule to check result file for errors.
105.PHONY: $(1)_check_errors
106$(1)_check_errors: $(test_dir)/$(1)_result.xml
107	grep "testsuites.*failures=\"0\"" $(test_dir)/$(1)_result.xml
108
109berberis_run_host_tests: $(1)_check_errors
110
111endef
112
113
114# ATTENTION: no spaces or line continuations around test name!
115
116ifeq ($(BUILD_BERBERIS_RISCV64_TO_X86_64),true)
117
118# berberis_ndk_program_tests
119
120$(eval $(call add_test,berberis_ndk_program_tests_interpret_only,\
121	run_test_x86_64_riscv64,\
122	$(TARGET_OUT_TESTCASES)/berberis_ndk_program_tests_static.native_bridge/x86_64/berberis_ndk_program_tests_static,\
123	BERBERIS_MODE=interpret-only))
124
125$(eval $(call add_test,berberis_ndk_program_tests_lite_translate_or_interpret,\
126	run_test_x86_64_riscv64,\
127	$(TARGET_OUT_TESTCASES)/berberis_ndk_program_tests_static.native_bridge/x86_64/berberis_ndk_program_tests_static,\
128	BERBERIS_MODE=lite-translate-or-interpret))
129
130$(eval $(call add_test,berberis_ndk_program_tests_heavy_optimize_or_interpret,\
131	run_test_x86_64_riscv64,\
132	$(TARGET_OUT_TESTCASES)/berberis_ndk_program_tests_static.native_bridge/x86_64/berberis_ndk_program_tests_static,\
133	BERBERIS_MODE=heavy-optimize-or-interpret))
134
135$(eval $(call add_test,berberis_ndk_program_tests_two_gear,\
136	run_test_x86_64_riscv64,\
137	$(TARGET_OUT_TESTCASES)/berberis_ndk_program_tests_static.native_bridge/x86_64/berberis_ndk_program_tests_static,\
138	BERBERIS_MODE=two-gear))
139
140# inline_asm_tests_riscv64
141
142$(eval $(call add_test,inline_asm_tests_riscv64_interpret_only,\
143	run_test_x86_64_riscv64,\
144	$(TARGET_OUT_TESTCASES)/inline_asm_tests_riscv64.native_bridge/x86_64/inline_asm_tests_riscv64,\
145	BERBERIS_MODE=interpret-only))
146
147$(eval $(call add_test,inline_asm_tests_riscv64_lite_translate_or_interpret,\
148	run_test_x86_64_riscv64,\
149	$(TARGET_OUT_TESTCASES)/inline_asm_tests_riscv64.native_bridge/x86_64/inline_asm_tests_riscv64,\
150	BERBERIS_MODE=lite-translate-or-interpret))
151
152$(eval $(call add_test,inline_asm_tests_riscv64_heavy_optimize_or_interpret,\
153	run_test_x86_64_riscv64,\
154	$(TARGET_OUT_TESTCASES)/inline_asm_tests_riscv64.native_bridge/x86_64/inline_asm_tests_riscv64,\
155	BERBERIS_MODE=heavy-optimize-or-interpret))
156
157$(eval $(call add_test,inline_asm_tests_riscv64_two_gear,\
158	run_test_x86_64_riscv64,\
159	$(TARGET_OUT_TESTCASES)/inline_asm_tests_riscv64.native_bridge/x86_64/inline_asm_tests_riscv64,\
160	BERBERIS_MODE=two-gear))
161
162# berberis_host_tests
163
164$(eval $(call add_test,berberis_host_tests,\
165	run_test,\
166	$(HOST_OUT)/nativetest64/berberis_host_tests/berberis_host_tests))
167
168endif  # BUILD_BERBERIS_RISCV64_TO_X86_64
169
170
171test_dir :=
172gen_failure_template :=
173runner_riscv64 :=
174host_libc_root :=
175test_guard :=
176test_trigger :=
177run_test :=
178run_test_x86_64_riscv64 :=
179add_test :=
180