1#
2# Copyright (C) 2011 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
17LOCAL_PATH := art
18
19TEST_COMMON_SRC_FILES := \
20	compiler/driver/compiler_driver_test.cc \
21	compiler/elf_writer_test.cc \
22	compiler/image_test.cc \
23	compiler/jni/jni_compiler_test.cc \
24	compiler/oat_test.cc \
25	compiler/output_stream_test.cc \
26	compiler/utils/dedupe_set_test.cc \
27	compiler/utils/arm/managed_register_arm_test.cc \
28	compiler/utils/x86/managed_register_x86_test.cc \
29	runtime/barrier_test.cc \
30	runtime/base/histogram_test.cc \
31	runtime/base/mutex_test.cc \
32	runtime/base/timing_logger_test.cc \
33	runtime/base/unix_file/fd_file_test.cc \
34	runtime/base/unix_file/mapped_file_test.cc \
35	runtime/base/unix_file/null_file_test.cc \
36	runtime/base/unix_file/random_access_file_utils_test.cc \
37	runtime/base/unix_file/string_file_test.cc \
38	runtime/class_linker_test.cc \
39	runtime/dex_file_test.cc \
40	runtime/dex_instruction_visitor_test.cc \
41	runtime/dex_method_iterator_test.cc \
42	runtime/entrypoints/math_entrypoints_test.cc \
43	runtime/exception_test.cc \
44	runtime/gc/accounting/space_bitmap_test.cc \
45	runtime/gc/heap_test.cc \
46	runtime/gc/space/space_test.cc \
47	runtime/gtest_test.cc \
48	runtime/indenter_test.cc \
49	runtime/indirect_reference_table_test.cc \
50	runtime/intern_table_test.cc \
51	runtime/jni_internal_test.cc \
52	runtime/mem_map_test.cc \
53	runtime/mirror/dex_cache_test.cc \
54	runtime/mirror/object_test.cc \
55	runtime/reference_table_test.cc \
56	runtime/runtime_test.cc \
57	runtime/thread_pool_test.cc \
58	runtime/utils_test.cc \
59	runtime/verifier/method_verifier_test.cc \
60	runtime/verifier/reg_type_test.cc \
61	runtime/zip_archive_test.cc
62
63ifeq ($(ART_SEA_IR_MODE),true)
64TEST_COMMON_SRC_FILES += \
65	compiler/utils/scoped_hashtable_test.cc \
66	compiler/sea_ir/types/type_data_test.cc \
67	compiler/sea_ir/types/type_inference_visitor_test.cc \
68	compiler/sea_ir/ir/regions_test.cc
69endif
70
71TEST_TARGET_SRC_FILES := \
72	$(TEST_COMMON_SRC_FILES)
73
74TEST_HOST_SRC_FILES := \
75	$(TEST_COMMON_SRC_FILES) \
76	compiler/utils/x86/assembler_x86_test.cc
77
78ART_HOST_TEST_EXECUTABLES :=
79ART_TARGET_TEST_EXECUTABLES :=
80ART_HOST_TEST_TARGETS :=
81ART_TARGET_TEST_TARGETS :=
82
83ART_TEST_CFLAGS :=
84ifeq ($(ART_USE_PORTABLE_COMPILER),true)
85  ART_TEST_CFLAGS += -DART_USE_PORTABLE_COMPILER=1
86endif
87
88# $(1): target or host
89# $(2): file name
90define build-art-test
91  ifneq ($(1),target)
92    ifneq ($(1),host)
93      $$(error expected target or host for argument 1, received $(1))
94    endif
95  endif
96
97  art_target_or_host := $(1)
98  art_gtest_filename := $(2)
99
100  art_gtest_name := $$(notdir $$(basename $$(art_gtest_filename)))
101
102  include $(CLEAR_VARS)
103  ifeq ($$(art_target_or_host),target)
104    include external/stlport/libstlport.mk
105  endif
106
107  LOCAL_CPP_EXTENSION := $(ART_CPP_EXTENSION)
108  LOCAL_MODULE := $$(art_gtest_name)
109  ifeq ($$(art_target_or_host),target)
110    LOCAL_MODULE_TAGS := tests
111  endif
112  LOCAL_SRC_FILES := $$(art_gtest_filename) runtime/common_test.cc
113  LOCAL_C_INCLUDES += $(ART_C_INCLUDES) art/runtime art/compiler
114  LOCAL_SHARED_LIBRARIES += libartd-compiler libartd
115  # dex2oatd is needed to go libartd-compiler and libartd
116  LOCAL_REQUIRED_MODULES := dex2oatd
117
118  LOCAL_ADDITIONAL_DEPENDENCIES := art/build/Android.common.mk
119  LOCAL_ADDITIONAL_DEPENDENCIES += art/build/Android.gtest.mk
120
121  # Mac OS linker doesn't understand --export-dynamic.
122  ifneq ($(HOST_OS)-$$(art_target_or_host),darwin-host)
123    # Allow jni_compiler_test to find Java_MyClassNatives_bar within itself using dlopen(NULL, ...).
124    LOCAL_LDFLAGS := -Wl,--export-dynamic -Wl,-u,Java_MyClassNatives_bar -Wl,-u,Java_MyClassNatives_sbar
125  endif
126
127  LOCAL_CFLAGS := $(ART_TEST_CFLAGS)
128  ifeq ($$(art_target_or_host),target)
129    LOCAL_CLANG := $(ART_TARGET_CLANG)
130    LOCAL_CFLAGS += $(ART_TARGET_CFLAGS) $(ART_TARGET_DEBUG_CFLAGS)
131    LOCAL_SHARED_LIBRARIES += libdl libicuuc libicui18n libnativehelper libz libcutils
132    LOCAL_STATIC_LIBRARIES += libgtest
133    LOCAL_MODULE_PATH := $(ART_NATIVETEST_OUT)
134    include $(LLVM_DEVICE_BUILD_MK)
135    include $(BUILD_EXECUTABLE)
136    art_gtest_exe := $$(LOCAL_MODULE_PATH)/$$(LOCAL_MODULE)
137    ART_TARGET_TEST_EXECUTABLES += $$(art_gtest_exe)
138  else # host
139    LOCAL_CLANG := $(ART_HOST_CLANG)
140    LOCAL_CFLAGS += $(ART_HOST_CFLAGS) $(ART_HOST_DEBUG_CFLAGS)
141    LOCAL_SHARED_LIBRARIES += libicuuc-host libicui18n-host libnativehelper libz-host
142    LOCAL_STATIC_LIBRARIES += libcutils
143    ifeq ($(HOST_OS),darwin)
144      # Mac OS complains about unresolved symbols if you don't include this.
145      LOCAL_WHOLE_STATIC_LIBRARIES := libgtest_host
146    endif
147    include $(LLVM_HOST_BUILD_MK)
148    include $(BUILD_HOST_EXECUTABLE)
149    art_gtest_exe := $(HOST_OUT_EXECUTABLES)/$$(LOCAL_MODULE)
150    ART_HOST_TEST_EXECUTABLES += $$(art_gtest_exe)
151  endif
152art_gtest_target := test-art-$$(art_target_or_host)-gtest-$$(art_gtest_name)
153ifeq ($$(art_target_or_host),target)
154.PHONY: $$(art_gtest_target)
155$$(art_gtest_target): $$(art_gtest_exe) test-art-target-sync
156	adb shell touch $(ART_TEST_DIR)/$$@
157	adb shell rm $(ART_TEST_DIR)/$$@
158	adb shell chmod 755 $(ART_NATIVETEST_DIR)/$$(notdir $$<)
159	adb shell sh -c "$(ART_NATIVETEST_DIR)/$$(notdir $$<) && touch $(ART_TEST_DIR)/$$@"
160	$(hide) (adb pull $(ART_TEST_DIR)/$$@ /tmp/ && echo $$@ PASSED) || (echo $$@ FAILED && exit 1)
161	$(hide) rm /tmp/$$@
162
163ART_TARGET_TEST_TARGETS += $$(art_gtest_target)
164else
165.PHONY: $$(art_gtest_target)
166$$(art_gtest_target): $$(art_gtest_exe) test-art-host-dependencies
167	$$<
168	@echo $$@ PASSED
169
170ART_HOST_TEST_TARGETS += $$(art_gtest_target)
171endif
172endef
173
174ifeq ($(ART_BUILD_TARGET),true)
175  $(foreach file,$(TEST_TARGET_SRC_FILES), $(eval $(call build-art-test,target,$(file))))
176endif
177ifeq ($(WITH_HOST_DALVIK),true)
178  ifeq ($(ART_BUILD_HOST),true)
179    $(foreach file,$(TEST_HOST_SRC_FILES), $(eval $(call build-art-test,host,$(file))))
180  endif
181endif
182