Extract bionic-prepare-run-on-host to inc file.
[android-sdk/platform-bionic.git] / tests / Android.mk
1 #
2 # Copyright (C) 2012 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 #
17 ifneq ($(BUILD_TINY_ANDROID),true)
19 LOCAL_PATH := $(call my-dir)
21 # -----------------------------------------------------------------------------
22 # Unit tests.
23 # -----------------------------------------------------------------------------
25 ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
26 build_host := true
27 else
28 build_host := false
29 endif
31 common_additional_dependencies := $(LOCAL_PATH)/Android.mk $(LOCAL_PATH)/Android.build.mk
33 # -----------------------------------------------------------------------------
34 # All standard tests.
35 # -----------------------------------------------------------------------------
36 test_cflags = \
37     -fstack-protector-all \
38     -g \
39     -Wall -Wextra -Wunused \
40     -Werror \
41     -fno-builtin \
43 test_cflags += -D__STDC_LIMIT_MACROS  # For glibc.
45 ifeq ($(MALLOC_IMPL),dlmalloc)
46 test_cflags += -DUSE_DLMALLOC
47 else
48 test_cflags += -DUSE_JEMALLOC
49 endif
51 test_cppflags = \
52     -std=gnu++11 \
54 libBionicStandardTests_src_files := \
55     arpa_inet_test.cpp \
56     buffer_tests.cpp \
57     complex_test.cpp \
58     ctype_test.cpp \
59     dirent_test.cpp \
60     eventfd_test.cpp \
61     fcntl_test.cpp \
62     fenv_test.cpp \
63     ftw_test.cpp \
64     getauxval_test.cpp \
65     getcwd_test.cpp \
66     inttypes_test.cpp \
67     libc_logging_test.cpp \
68     libgen_test.cpp \
69     locale_test.cpp \
70     malloc_test.cpp \
71     math_test.cpp \
72     mntent_test.cpp \
73     netdb_test.cpp \
74     pthread_test.cpp \
75     regex_test.cpp \
76     sched_test.cpp \
77     search_test.cpp \
78     semaphore_test.cpp \
79     setjmp_test.cpp \
80     signal_test.cpp \
81     stack_protector_test.cpp \
82     stack_unwinding_test.cpp \
83     stdatomic_test.cpp \
84     stdint_test.cpp \
85     stdio_test.cpp \
86     stdio_ext_test.cpp \
87     stdlib_test.cpp \
88     string_test.cpp \
89     string_posix_strerror_r_test.cpp \
90     strings_test.cpp \
91     stubs_test.cpp \
92     sstream_test.cpp \
93     sys_epoll_test.cpp \
94     sys_mman_test.cpp \
95     sys_resource_test.cpp \
96     sys_select_test.cpp \
97     sys_sendfile_test.cpp \
98     sys_socket_test.cpp \
99     sys_stat_test.cpp \
100     sys_statvfs_test.cpp \
101     sys_syscall_test.cpp \
102     sys_sysinfo_test.cpp \
103     sys_time_test.cpp \
104     sys_types_test.cpp \
105     sys_vfs_test.cpp \
106     system_properties_test.cpp \
107     time_test.cpp \
108     uchar_test.cpp \
109     uniqueptr_test.cpp \
110     unistd_test.cpp \
111     wchar_test.cpp \
113 libBionicStandardTests_cflags := \
114     $(test_cflags) \
116 ifeq ($(MALLOC_IMPL),dlmalloc)
117   libBionicStandardTests_cflags += -DUSE_DLMALLOC
118 else
119   libBionicStandardTests_cflags += -DUSE_JEMALLOC
120 endif
122 libBionicStandardTests_cppflags := \
123     $(test_cppflags) \
125 libBionicStandardTests_c_includes := \
126     bionic/libc \
127     external/tinyxml2 \
129 libBionicStandardTests_ldlibs_host := \
130     -lrt \
132 module := libBionicStandardTests
133 module_tag := optional
134 build_type := target
135 build_target := STATIC_TEST_LIBRARY
136 include $(LOCAL_PATH)/Android.build.mk
137 build_type := host
138 include $(LOCAL_PATH)/Android.build.mk
140 # -----------------------------------------------------------------------------
141 # Fortify tests.
142 # -----------------------------------------------------------------------------
143 $(foreach compiler,gcc clang, \
144   $(foreach test,1 2, \
145     $(eval fortify$(test)-tests-$(compiler)_cflags := \
146       $(test_cflags) \
147       -Wno-error \
148       -U_FORTIFY_SOURCE \
149       -D_FORTIFY_SOURCE=$(test) \
150       -DTEST_NAME=Fortify$(test)_$(compiler)); \
151     $(eval fortify$(test)-tests-$(compiler)_src_files := \
152       fortify_test.cpp); \
153     $(eval fortify_libs += fortify$(test)-tests-$(compiler)); \
154   ) \
157 module := fortify1-tests-gcc
158 module_tag := optional
159 build_type := target
160 build_target := STATIC_TEST_LIBRARY
161 include $(LOCAL_PATH)/Android.build.mk
162 build_type := host
163 include $(LOCAL_PATH)/Android.build.mk
165 module := fortify2-tests-gcc
166 module_tag := optional
167 build_type := target
168 build_target := STATIC_TEST_LIBRARY
169 include $(LOCAL_PATH)/Android.build.mk
170 build_type := host
171 include $(LOCAL_PATH)/Android.build.mk
173 fortify1-tests-clang_clang_target := true
174 fortify1-tests-clang_cflags_host := -D__clang__
176 module := fortify1-tests-clang
177 module_tag := optional
178 build_type := target
179 build_target := STATIC_TEST_LIBRARY
180 include $(LOCAL_PATH)/Android.build.mk
181 build_type := host
182 include $(LOCAL_PATH)/Android.build.mk
184 fortify2-tests-clang_clang_target := true
186 fortify2-tests-clang_cflags_host := -D__clang__
188 module := fortify2-tests-clang
189 module_tag := optional
190 build_type := target
191 build_target := STATIC_TEST_LIBRARY
192 include $(LOCAL_PATH)/Android.build.mk
193 build_type := host
194 include $(LOCAL_PATH)/Android.build.mk
196 # -----------------------------------------------------------------------------
197 # Library of all tests (excluding the dynamic linker tests).
198 # -----------------------------------------------------------------------------
199 libBionicTests_whole_static_libraries := \
200     libBionicStandardTests \
201     $(fortify_libs) \
203 module := libBionicTests
204 module_tag := optional
205 build_type := target
206 build_target := STATIC_TEST_LIBRARY
207 include $(LOCAL_PATH)/Android.build.mk
208 build_type := host
209 include $(LOCAL_PATH)/Android.build.mk
211 # -----------------------------------------------------------------------------
212 # Tests for the device using bionic's .so. Run with:
213 #   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests32
214 #   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests64
215 # -----------------------------------------------------------------------------
216 bionic-unit-tests_whole_static_libraries := \
217     libBionicTests \
219 bionic-unit-tests_static_libraries := \
220     libtinyxml2 \
221     liblog \
223 bionic-unit-tests_src_files := \
224     atexit_test.cpp \
225     dl_test.cpp \
226     dlext_test.cpp \
227     dlfcn_test.cpp \
229 bionic-unit-tests_cflags := $(test_cflags)
231 bionic-unit-tests_conlyflags := \
232     -fexceptions \
233     -fnon-call-exceptions \
235 bionic-unit-tests_cppflags := $(test_cppflags)
237 bionic-unit-tests_ldflags := \
238     -Wl,--export-dynamic
240 bionic-unit-tests_c_includes := \
241     bionic/libc \
242     $(call include-path-for, libpagemap) \
244 bionic-unit-tests_shared_libraries_target := \
245     libdl \
246     libpagemap \
247     libdl_preempt_test_1 \
248     libdl_preempt_test_2
250 ifneq ($(filter $(TARGET_ARCH),arm arm64),$(TARGET_ARCH))
251 bionic-unit-tests_shared_libraries_target += libdl_test_df_1_global
252 endif
254 module := bionic-unit-tests
255 module_tag := optional
256 build_type := target
257 build_target := NATIVE_TEST
258 include $(LOCAL_PATH)/Android.build.mk
260 # -----------------------------------------------------------------------------
261 # Tests for the device linked against bionic's static library. Run with:
262 #   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static32
263 #   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static64
264 # -----------------------------------------------------------------------------
265 bionic-unit-tests-static_whole_static_libraries := \
266     libBionicTests \
268 bionic-unit-tests-static_static_libraries := \
269     libm \
270     libc \
271     libc++_static \
272     libdl \
273     libtinyxml2 \
274     liblog \
276 bionic-unit-tests-static_force_static_executable := true
278 # libc and libc++ both define std::nothrow. libc's is a private symbol, but this
279 # still causes issues when linking libc.a and libc++.a, since private isn't
280 # effective until it has been linked. To fix this, just allow multiple symbol
281 # definitions for the static tests.
282 bionic-unit-tests-static_ldflags := -Wl,--allow-multiple-definition
284 module := bionic-unit-tests-static
285 module_tag := optional
286 build_type := target
287 build_target := NATIVE_TEST
288 include $(LOCAL_PATH)/Android.build.mk
290 # -----------------------------------------------------------------------------
291 # Tests to run on the host and linked against glibc. Run with:
292 #   cd bionic/tests; mm bionic-unit-tests-glibc-run
293 # -----------------------------------------------------------------------------
295 ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
297 bionic-unit-tests-glibc_src_files := \
298     atexit_test.cpp \
299     dlfcn_test.cpp \
300     dl_test.cpp \
302 bionic-unit-tests-glibc_shared_libraries := \
303     libdl_preempt_test_1 \
304     libdl_preempt_test_2
306 bionic-unit-tests-glibc_shared_libraries += libdl_test_df_1_global
308 bionic-unit-tests-glibc_whole_static_libraries := \
309     libBionicStandardTests \
311 bionic-unit-tests-glibc_ldlibs := \
312     -lrt -ldl \
314 bionic-unit-tests-glibc_c_includes := \
315     bionic/libc \
317 bionic-unit-tests-glibc_cflags := $(test_cflags)
318 bionic-unit-tests-glibc_cppflags := $(test_cppflags)
319 bionic-unit-tests-glibc_ldflags := -Wl,--export-dynamic
321 bionic-unit-tests-glibc_allow_asan := true
323 module := bionic-unit-tests-glibc
324 module_tag := optional
325 build_type := host
326 build_target := NATIVE_TEST
327 include $(LOCAL_PATH)/Android.build.mk
329 # -----------------------------------------------------------------------------
330 # Compile time tests.
331 # -----------------------------------------------------------------------------
333 # Some of these are intentionally using = instead of := since we need access to
334 # some variables not initialtized until we're in the build system.
336 include $(CLEAR_VARS)
337 LOCAL_ADDITIONAL_DEPENDENCIES := \
338     $(LOCAL_PATH)/Android.mk \
339     $(LOCAL_PATH)/file-check-cxx \
340     | $(HOST_OUT_EXECUTABLES)/FileCheck$(HOST_EXECUTABLE_SUFFIX) \
342 LOCAL_CXX = $(LOCAL_PATH)/file-check-cxx \
343     $(HOST_OUT_EXECUTABLES)/FileCheck \
344     $($(LOCAL_2ND_ARCH_VAR_PREFIX)CXX_BARE) \
345     GCC \
347 LOCAL_CLANG := false
348 LOCAL_MODULE := bionic-compile-time-tests-g++
349 LOCAL_CXXFLAGS := -Wall
350 LOCAL_SRC_FILES := fortify_sprintf_warnings.cpp
351 include $(BUILD_STATIC_LIBRARY)
353 include $(CLEAR_VARS)
354 LOCAL_ADDITIONAL_DEPENDENCIES := \
355     $(LOCAL_PATH)/Android.mk \
356     $(LOCAL_PATH)/file-check-cxx \
357     | $(HOST_OUT_EXECUTABLES)/FileCheck$(HOST_EXECUTABLE_SUFFIX) \
359 LOCAL_CXX := $(LOCAL_PATH)/file-check-cxx \
360     $(HOST_OUT_EXECUTABLES)/FileCheck \
361     $(LLVM_PREBUILTS_PATH)/clang++ \
362     CLANG \
364 LOCAL_CLANG := true
365 LOCAL_MODULE := bionic-compile-time-tests-clang++
366 LOCAL_CXXFLAGS := -Wall
367 # FileCheck will error if there aren't any CLANG: lines in the file, but there
368 # don't appear to be any cases where clang _does_ emit warnings for sn?printf :(
369 LOCAL_SRC_FILES :=
370 include $(BUILD_STATIC_LIBRARY)
372 # -----------------------------------------------------------------------------
373 # Host glibc tests.
374 # -----------------------------------------------------------------------------
376 # gtest needs ANDROID_DATA/local/tmp for death test output.
377 # Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
378 # Use the current target out directory as ANDROID_DATA.
379 # BIONIC_TEST_FLAGS is either empty or it comes from the user.
380 bionic-unit-tests-glibc-run: bionic-unit-tests-glibc
381         mkdir -p $(TARGET_OUT_DATA)/local/tmp
382         ANDROID_DATA=$(TARGET_OUT_DATA) \
383         ANDROID_ROOT=$(TARGET_OUT) \
384                 $(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc64 $(BIONIC_TEST_FLAGS)
386 # -----------------------------------------------------------------------------
387 # Run the unit tests built against x86 bionic on an x86 host.
388 # -----------------------------------------------------------------------------
390 include $(LOCAL_PATH)/../build/run-on-host.mk
392 ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
393 # BIONIC_TEST_FLAGS is either empty or it comes from the user.
394 bionic-unit-tests-run-on-host32: bionic-unit-tests bionic-prepare-run-on-host
395         ANDROID_DATA=$(TARGET_OUT_DATA) \
396         ANDROID_DNS_MODE=local \
397         ANDROID_ROOT=$(TARGET_OUT) \
398                 $(TARGET_OUT_DATA)/nativetest/bionic-unit-tests/bionic-unit-tests32 $(BIONIC_TEST_FLAGS)
400 ifeq ($(TARGET_IS_64_BIT),true)
401 # add target to run lp64 tests
402 bionic-unit-tests-run-on-host64: bionic-unit-tests bionic-prepare-run-on-host
403         ANDROID_DATA=$(TARGET_OUT_DATA) \
404         ANDROID_DNS_MODE=local \
405         ANDROID_ROOT=$(TARGET_OUT) \
406                 $(TARGET_OUT_DATA)/nativetest64/bionic-unit-tests/bionic-unit-tests64 $(BIONIC_TEST_FLAGS)
407 endif
409 endif # x86 x86_64
410 endif # linux-x86
412 include $(call first-makefiles-under,$(LOCAL_PATH))
413 endif # !BUILD_TINY_ANDROID