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 signal_test.cpp \
80 stack_protector_test.cpp \
81 stack_unwinding_test.cpp \
82 stdatomic_test.cpp \
83 stdint_test.cpp \
84 stdio_test.cpp \
85 stdio_ext_test.cpp \
86 stdlib_test.cpp \
87 string_test.cpp \
88 string_posix_strerror_r_test.cpp \
89 strings_test.cpp \
90 stubs_test.cpp \
91 sstream_test.cpp \
92 sys_epoll_test.cpp \
93 sys_mman_test.cpp \
94 sys_resource_test.cpp \
95 sys_select_test.cpp \
96 sys_sendfile_test.cpp \
97 sys_socket_test.cpp \
98 sys_stat_test.cpp \
99 sys_statvfs_test.cpp \
100 sys_syscall_test.cpp \
101 sys_sysinfo_test.cpp \
102 sys_time_test.cpp \
103 sys_types_test.cpp \
104 sys_vfs_test.cpp \
105 system_properties_test.cpp \
106 time_test.cpp \
107 uchar_test.cpp \
108 uniqueptr_test.cpp \
109 unistd_test.cpp \
110 wchar_test.cpp \
112 libBionicStandardTests_cflags := \
113 $(test_cflags) \
115 ifeq ($(MALLOC_IMPL),dlmalloc)
116 libBionicStandardTests_cflags += -DUSE_DLMALLOC
117 else
118 libBionicStandardTests_cflags += -DUSE_JEMALLOC
119 endif
121 libBionicStandardTests_cppflags := \
122 $(test_cppflags) \
124 libBionicStandardTests_c_includes := \
125 bionic/libc \
126 external/tinyxml2 \
128 libBionicStandardTests_ldlibs_host := \
129 -lrt \
131 module := libBionicStandardTests
132 module_tag := optional
133 build_type := target
134 build_target := STATIC_TEST_LIBRARY
135 include $(LOCAL_PATH)/Android.build.mk
136 build_type := host
137 include $(LOCAL_PATH)/Android.build.mk
139 # -----------------------------------------------------------------------------
140 # Fortify tests.
141 # -----------------------------------------------------------------------------
142 $(foreach compiler,gcc clang, \
143 $(foreach test,1 2, \
144 $(eval fortify$(test)-tests-$(compiler)_cflags := \
145 $(test_cflags) \
146 -Wno-error \
147 -U_FORTIFY_SOURCE \
148 -D_FORTIFY_SOURCE=$(test) \
149 -DTEST_NAME=Fortify$(test)_$(compiler)); \
150 $(eval fortify$(test)-tests-$(compiler)_src_files := \
151 fortify_test.cpp); \
152 $(eval fortify_libs += fortify$(test)-tests-$(compiler)); \
153 ) \
154 )
156 module := fortify1-tests-gcc
157 module_tag := optional
158 build_type := target
159 build_target := STATIC_TEST_LIBRARY
160 include $(LOCAL_PATH)/Android.build.mk
161 build_type := host
162 include $(LOCAL_PATH)/Android.build.mk
164 module := fortify2-tests-gcc
165 module_tag := optional
166 build_type := target
167 build_target := STATIC_TEST_LIBRARY
168 include $(LOCAL_PATH)/Android.build.mk
169 build_type := host
170 include $(LOCAL_PATH)/Android.build.mk
172 fortify1-tests-clang_clang_target := true
173 fortify1-tests-clang_cflags_host := -D__clang__
175 module := fortify1-tests-clang
176 module_tag := optional
177 build_type := target
178 build_target := STATIC_TEST_LIBRARY
179 include $(LOCAL_PATH)/Android.build.mk
180 build_type := host
181 include $(LOCAL_PATH)/Android.build.mk
183 fortify2-tests-clang_clang_target := true
185 fortify2-tests-clang_cflags_host := -D__clang__
187 module := fortify2-tests-clang
188 module_tag := optional
189 build_type := target
190 build_target := STATIC_TEST_LIBRARY
191 include $(LOCAL_PATH)/Android.build.mk
192 build_type := host
193 include $(LOCAL_PATH)/Android.build.mk
195 # -----------------------------------------------------------------------------
196 # Library of all tests (excluding the dynamic linker tests).
197 # -----------------------------------------------------------------------------
198 libBionicTests_whole_static_libraries := \
199 libBionicStandardTests \
200 $(fortify_libs) \
202 module := libBionicTests
203 module_tag := optional
204 build_type := target
205 build_target := STATIC_TEST_LIBRARY
206 include $(LOCAL_PATH)/Android.build.mk
207 build_type := host
208 include $(LOCAL_PATH)/Android.build.mk
210 # -----------------------------------------------------------------------------
211 # Tests for the device using bionic's .so. Run with:
212 # adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests32
213 # adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests64
214 # -----------------------------------------------------------------------------
215 bionic-unit-tests_whole_static_libraries := \
216 libBionicTests \
218 bionic-unit-tests_static_libraries := \
219 libtinyxml2 \
220 liblog \
222 bionic-unit-tests_src_files := \
223 atexit_test.cpp \
224 dl_test.cpp \
225 dlext_test.cpp \
226 dlfcn_test.cpp \
228 bionic-unit-tests_cflags := $(test_cflags)
230 bionic-unit-tests_conlyflags := \
231 -fexceptions \
232 -fnon-call-exceptions \
234 bionic-unit-tests_cppflags := $(test_cppflags)
236 bionic-unit-tests_ldflags := \
237 -Wl,--export-dynamic
239 bionic-unit-tests_c_includes := \
240 bionic/libc \
241 $(call include-path-for, libpagemap) \
243 bionic-unit-tests_shared_libraries_target := \
244 libdl \
245 libpagemap \
246 libdl_preempt_test_1 \
247 libdl_preempt_test_2
249 ifneq ($(filter $(TARGET_ARCH),arm arm64),$(TARGET_ARCH))
250 bionic-unit-tests_shared_libraries_target += libdl_test_df_1_global
251 endif
253 module := bionic-unit-tests
254 module_tag := optional
255 build_type := target
256 build_target := NATIVE_TEST
257 include $(LOCAL_PATH)/Android.build.mk
259 # -----------------------------------------------------------------------------
260 # Tests for the device linked against bionic's static library. Run with:
261 # adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static32
262 # adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static64
263 # -----------------------------------------------------------------------------
264 bionic-unit-tests-static_whole_static_libraries := \
265 libBionicTests \
267 bionic-unit-tests-static_static_libraries := \
268 libm \
269 libc \
270 libc++_static \
271 libdl \
272 libtinyxml2 \
273 liblog \
275 bionic-unit-tests-static_force_static_executable := true
277 # libc and libc++ both define std::nothrow. libc's is a private symbol, but this
278 # still causes issues when linking libc.a and libc++.a, since private isn't
279 # effective until it has been linked. To fix this, just allow multiple symbol
280 # definitions for the static tests.
281 bionic-unit-tests-static_ldflags := -Wl,--allow-multiple-definition
283 module := bionic-unit-tests-static
284 module_tag := optional
285 build_type := target
286 build_target := NATIVE_TEST
287 include $(LOCAL_PATH)/Android.build.mk
289 # -----------------------------------------------------------------------------
290 # Tests to run on the host and linked against glibc. Run with:
291 # cd bionic/tests; mm bionic-unit-tests-glibc-run
292 # -----------------------------------------------------------------------------
294 ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
296 bionic-unit-tests-glibc_src_files := \
297 atexit_test.cpp \
298 dlfcn_test.cpp \
299 dl_test.cpp \
301 bionic-unit-tests-glibc_shared_libraries := \
302 libdl_preempt_test_1 \
303 libdl_preempt_test_2
305 bionic-unit-tests-glibc_shared_libraries += libdl_test_df_1_global
307 bionic-unit-tests-glibc_whole_static_libraries := \
308 libBionicStandardTests \
310 bionic-unit-tests-glibc_ldlibs := \
311 -lrt -ldl \
313 bionic-unit-tests-glibc_c_includes := \
314 bionic/libc \
316 bionic-unit-tests-glibc_cflags := $(test_cflags)
317 bionic-unit-tests-glibc_cppflags := $(test_cppflags)
318 bionic-unit-tests-glibc_ldflags := -Wl,--export-dynamic
320 bionic-unit-tests-glibc_allow_asan := true
322 module := bionic-unit-tests-glibc
323 module_tag := optional
324 build_type := host
325 build_target := NATIVE_TEST
326 include $(LOCAL_PATH)/Android.build.mk
328 # -----------------------------------------------------------------------------
329 # Compile time tests.
330 # -----------------------------------------------------------------------------
332 # Some of these are intentionally using = instead of := since we need access to
333 # some variables not initialtized until we're in the build system.
335 include $(CLEAR_VARS)
336 LOCAL_ADDITIONAL_DEPENDENCIES := \
337 $(LOCAL_PATH)/Android.mk \
338 $(LOCAL_PATH)/file-check-cxx \
339 | $(HOST_OUT_EXECUTABLES)/FileCheck$(HOST_EXECUTABLE_SUFFIX) \
341 LOCAL_CXX = $(LOCAL_PATH)/file-check-cxx \
342 $(HOST_OUT_EXECUTABLES)/FileCheck \
343 $($(LOCAL_2ND_ARCH_VAR_PREFIX)CXX_BARE) \
344 GCC \
346 LOCAL_CLANG := false
347 LOCAL_MODULE := bionic-compile-time-tests-g++
348 LOCAL_CXXFLAGS := -Wall
349 LOCAL_SRC_FILES := fortify_sprintf_warnings.cpp
350 include $(BUILD_STATIC_LIBRARY)
352 include $(CLEAR_VARS)
353 LOCAL_ADDITIONAL_DEPENDENCIES := \
354 $(LOCAL_PATH)/Android.mk \
355 $(LOCAL_PATH)/file-check-cxx \
356 | $(HOST_OUT_EXECUTABLES)/FileCheck$(HOST_EXECUTABLE_SUFFIX) \
358 LOCAL_CXX := $(LOCAL_PATH)/file-check-cxx \
359 $(HOST_OUT_EXECUTABLES)/FileCheck \
360 $(LLVM_PREBUILTS_PATH)/clang++ \
361 CLANG \
363 LOCAL_CLANG := true
364 LOCAL_MODULE := bionic-compile-time-tests-clang++
365 LOCAL_CXXFLAGS := -Wall
366 # FileCheck will error if there aren't any CLANG: lines in the file, but there
367 # don't appear to be any cases where clang _does_ emit warnings for sn?printf :(
368 LOCAL_SRC_FILES :=
369 include $(BUILD_STATIC_LIBRARY)
371 # -----------------------------------------------------------------------------
372 # Host glibc tests.
373 # -----------------------------------------------------------------------------
375 ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm mips x86))
376 LINKER = linker64
377 NATIVE_TEST_SUFFIX=64
378 else
379 LINKER = linker
380 NATIVE_TEST_SUFFIX=32
381 endif
383 # gtest needs ANDROID_DATA/local/tmp for death test output.
384 # Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
385 # Use the current target out directory as ANDROID_DATA.
386 # BIONIC_TEST_FLAGS is either empty or it comes from the user.
387 bionic-unit-tests-glibc-run: bionic-unit-tests-glibc
388 mkdir -p $(TARGET_OUT_DATA)/local/tmp
389 ANDROID_DATA=$(TARGET_OUT_DATA) \
390 ANDROID_ROOT=$(TARGET_OUT) \
391 $(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS)
393 # -----------------------------------------------------------------------------
394 # Run the unit tests built against x86 bionic on an x86 host.
395 # -----------------------------------------------------------------------------
397 ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
398 # gtest needs ANDROID_DATA/local/tmp for death test output.
399 # Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
400 # bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT.
401 # BIONIC_TEST_FLAGS is either empty or it comes from the user.
402 bionic-unit-tests-run-on-host-prepare: $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT)/etc/hosts $(TARGET_OUT_EXECUTABLES)/sh
403 if [ ! -d /system ]; then \
404 echo "Attempting to create /system"; \
405 sudo mkdir -p -m 0777 /system; \
406 fi
407 mkdir -p $(TARGET_OUT_DATA)/local/tmp
408 ln -fs `realpath $(TARGET_OUT)/bin` /system/
409 ln -fs `realpath $(TARGET_OUT)/etc` /system/
411 bionic-unit-tests-run-on-host: bionic-unit-tests bionic-unit-tests-run-on-host-prepare
412 ANDROID_DATA=$(TARGET_OUT_DATA) \
413 ANDROID_DNS_MODE=local \
414 ANDROID_ROOT=$(TARGET_OUT) \
415 LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \
416 $(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS)
417 endif
419 ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86_64))
420 # add target to run lp32 tests
421 bionic-unit-tests-run-on-host32: bionic-unit-tests_32 bionic-unit-tests-run-on-host-prepare
422 ANDROID_DATA=$(TARGET_OUT_DATA) \
423 ANDROID_DNS_MODE=local \
424 ANDROID_ROOT=$(TARGET_OUT) \
425 LD_LIBRARY_PATH=$(2ND_TARGET_OUT_SHARED_LIBRARIES) \
426 $(2ND_TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests32 $(BIONIC_TEST_FLAGS)
427 endif
429 endif # linux-x86
431 include $(call first-makefiles-under,$(LOCAL_PATH))
432 endif # !BUILD_TINY_ANDROID