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 ctype_test.cpp \
58 dirent_test.cpp \
59 eventfd_test.cpp \
60 fcntl_test.cpp \
61 fenv_test.cpp \
62 ftw_test.cpp \
63 getauxval_test.cpp \
64 getcwd_test.cpp \
65 inttypes_test.cpp \
66 libc_logging_test.cpp \
67 libgen_test.cpp \
68 locale_test.cpp \
69 malloc_test.cpp \
70 math_test.cpp \
71 mntent_test.cpp \
72 netdb_test.cpp \
73 pthread_test.cpp \
74 regex_test.cpp \
75 sched_test.cpp \
76 search_test.cpp \
77 semaphore_test.cpp \
78 signal_test.cpp \
79 stack_protector_test.cpp \
80 stack_unwinding_test.cpp \
81 stdatomic_test.cpp \
82 stdint_test.cpp \
83 stdio_test.cpp \
84 stdio_ext_test.cpp \
85 stdlib_test.cpp \
86 string_test.cpp \
87 string_posix_strerror_r_test.cpp \
88 strings_test.cpp \
89 stubs_test.cpp \
90 sstream_test.cpp \
91 sys_epoll_test.cpp \
92 sys_mman_test.cpp \
93 sys_resource_test.cpp \
94 sys_select_test.cpp \
95 sys_sendfile_test.cpp \
96 sys_socket_test.cpp \
97 sys_stat_test.cpp \
98 sys_statvfs_test.cpp \
99 sys_syscall_test.cpp \
100 sys_time_test.cpp \
101 sys_types_test.cpp \
102 sys_vfs_test.cpp \
103 system_properties_test.cpp \
104 time_test.cpp \
105 uchar_test.cpp \
106 uniqueptr_test.cpp \
107 unistd_test.cpp \
108 wchar_test.cpp \
110 libBionicStandardTests_cflags := \
111 $(test_cflags) \
113 ifeq ($(MALLOC_IMPL),dlmalloc)
114 libBionicStandardTests_cflags += -DUSE_DLMALLOC
115 else
116 libBionicStandardTests_cflags += -DUSE_JEMALLOC
117 endif
119 libBionicStandardTests_cppflags := \
120 $(test_cppflags) \
122 libBionicStandardTests_c_includes := \
123 bionic/libc \
124 external/tinyxml2 \
126 libBionicStandardTests_ldlibs_host := \
127 -lrt \
129 module := libBionicStandardTests
130 module_tag := optional
131 build_type := target
132 build_target := STATIC_TEST_LIBRARY
133 include $(LOCAL_PATH)/Android.build.mk
134 build_type := host
135 include $(LOCAL_PATH)/Android.build.mk
137 # -----------------------------------------------------------------------------
138 # Fortify tests.
139 # -----------------------------------------------------------------------------
140 $(foreach compiler,gcc clang, \
141 $(foreach test,1 2, \
142 $(eval fortify$(test)-tests-$(compiler)_cflags := \
143 $(test_cflags) \
144 -Wno-error \
145 -U_FORTIFY_SOURCE \
146 -D_FORTIFY_SOURCE=$(test) \
147 -DTEST_NAME=Fortify$(test)_$(compiler)); \
148 $(eval fortify$(test)-tests-$(compiler)_src_files := \
149 fortify_test.cpp); \
150 $(eval fortify_libs += fortify$(test)-tests-$(compiler)); \
151 ) \
152 )
154 module := fortify1-tests-gcc
155 module_tag := optional
156 build_type := target
157 build_target := STATIC_TEST_LIBRARY
158 include $(LOCAL_PATH)/Android.build.mk
159 build_type := host
160 include $(LOCAL_PATH)/Android.build.mk
162 module := fortify2-tests-gcc
163 module_tag := optional
164 build_type := target
165 build_target := STATIC_TEST_LIBRARY
166 include $(LOCAL_PATH)/Android.build.mk
167 build_type := host
168 include $(LOCAL_PATH)/Android.build.mk
170 fortify1-tests-clang_clang_target := true
171 fortify1-tests-clang_cflags_host := -D__clang__
173 module := fortify1-tests-clang
174 module_tag := optional
175 build_type := target
176 build_target := STATIC_TEST_LIBRARY
177 include $(LOCAL_PATH)/Android.build.mk
178 build_type := host
179 include $(LOCAL_PATH)/Android.build.mk
181 fortify2-tests-clang_clang_target := true
183 fortify2-tests-clang_cflags_host := -D__clang__
185 module := fortify2-tests-clang
186 module_tag := optional
187 build_type := target
188 build_target := STATIC_TEST_LIBRARY
189 include $(LOCAL_PATH)/Android.build.mk
190 build_type := host
191 include $(LOCAL_PATH)/Android.build.mk
193 # -----------------------------------------------------------------------------
194 # Library of all tests (excluding the dynamic linker tests).
195 # -----------------------------------------------------------------------------
196 libBionicTests_whole_static_libraries := \
197 libBionicStandardTests \
198 $(fortify_libs) \
200 module := libBionicTests
201 module_tag := optional
202 build_type := target
203 build_target := STATIC_TEST_LIBRARY
204 include $(LOCAL_PATH)/Android.build.mk
205 build_type := host
206 include $(LOCAL_PATH)/Android.build.mk
208 # -----------------------------------------------------------------------------
209 # Tests for the device using bionic's .so. Run with:
210 # adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests32
211 # adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests64
212 # -----------------------------------------------------------------------------
213 bionic-unit-tests_whole_static_libraries := \
214 libBionicTests \
216 bionic-unit-tests_static_libraries := \
217 libtinyxml2 \
218 liblog \
220 bionic-unit-tests_src_files := \
221 atexit_test.cpp \
222 dl_test.cpp \
223 dlext_test.cpp \
224 dlfcn_test.cpp \
226 bionic-unit-tests_cflags := $(test_cflags)
228 bionic-unit-tests_conlyflags := \
229 -fexceptions \
230 -fnon-call-exceptions \
232 bionic-unit-tests_cppflags := $(test_cppflags)
234 bionic-unit-tests_ldflags := \
235 -Wl,--export-dynamic
237 bionic-unit-tests_c_includes := \
238 bionic/libc \
239 $(call include-path-for, libpagemap) \
241 bionic-unit-tests_shared_libraries_target := \
242 libdl \
243 libpagemap \
244 libdl_preempt_test_1 \
245 libdl_preempt_test_2
247 ifneq ($(filter $(TARGET_ARCH),arm arm64),$(TARGET_ARCH))
248 bionic-unit-tests_shared_libraries_target += libdl_test_df_1_global
249 endif
251 module := bionic-unit-tests
252 module_tag := optional
253 build_type := target
254 build_target := NATIVE_TEST
255 include $(LOCAL_PATH)/Android.build.mk
257 # -----------------------------------------------------------------------------
258 # Tests for the device linked against bionic's static library. Run with:
259 # adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static32
260 # adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static64
261 # -----------------------------------------------------------------------------
262 bionic-unit-tests-static_whole_static_libraries := \
263 libBionicTests \
265 bionic-unit-tests-static_static_libraries := \
266 libm \
267 libc \
268 libc++_static \
269 libdl \
270 libtinyxml2 \
271 liblog \
273 bionic-unit-tests-static_force_static_executable := true
275 # libc and libc++ both define std::nothrow. libc's is a private symbol, but this
276 # still causes issues when linking libc.a and libc++.a, since private isn't
277 # effective until it has been linked. To fix this, just allow multiple symbol
278 # definitions for the static tests.
279 bionic-unit-tests-static_ldflags := -Wl,--allow-multiple-definition
281 module := bionic-unit-tests-static
282 module_tag := optional
283 build_type := target
284 build_target := NATIVE_TEST
285 include $(LOCAL_PATH)/Android.build.mk
287 # -----------------------------------------------------------------------------
288 # Tests to run on the host and linked against glibc. Run with:
289 # cd bionic/tests; mm bionic-unit-tests-glibc-run
290 # -----------------------------------------------------------------------------
292 ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
294 bionic-unit-tests-glibc_src_files := \
295 atexit_test.cpp \
296 dlfcn_test.cpp \
297 dl_test.cpp \
299 bionic-unit-tests-glibc_shared_libraries := \
300 libdl_preempt_test_1 \
301 libdl_preempt_test_2
303 ifneq ($(filter $(TARGET_ARCH),arm arm64),$(TARGET_ARCH))
304 bionic-unit-tests-glibc_shared_libraries += libdl_test_df_1_global
305 endif
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 module := bionic-unit-tests-glibc
321 module_tag := optional
322 build_type := host
323 build_target := NATIVE_TEST
324 include $(LOCAL_PATH)/Android.build.mk
326 # -----------------------------------------------------------------------------
327 # Compile time tests.
328 # -----------------------------------------------------------------------------
330 # Some of these are intentionally using = instead of := since we need access to
331 # some variables not initialtized until we're in the build system.
333 include $(CLEAR_VARS)
334 LOCAL_ADDITIONAL_DEPENDENCIES := \
335 $(LOCAL_PATH)/Android.mk \
336 $(LOCAL_PATH)/file-check-cxx \
337 | $(HOST_OUT_EXECUTABLES)/FileCheck$(HOST_EXECUTABLE_SUFFIX) \
339 LOCAL_CXX = $(LOCAL_PATH)/file-check-cxx \
340 $(HOST_OUT_EXECUTABLES)/FileCheck \
341 $($(LOCAL_2ND_ARCH_VAR_PREFIX)CXX_BARE) \
342 GCC \
344 LOCAL_CLANG := false
345 LOCAL_MODULE := bionic-compile-time-tests-g++
346 LOCAL_CXXFLAGS := -Wall
347 LOCAL_SRC_FILES := fortify_sprintf_warnings.cpp
348 include $(BUILD_STATIC_LIBRARY)
350 include $(CLEAR_VARS)
351 LOCAL_ADDITIONAL_DEPENDENCIES := \
352 $(LOCAL_PATH)/Android.mk \
353 $(LOCAL_PATH)/file-check-cxx \
354 | $(HOST_OUT_EXECUTABLES)/FileCheck$(HOST_EXECUTABLE_SUFFIX) \
356 LOCAL_CXX := $(LOCAL_PATH)/file-check-cxx \
357 $(HOST_OUT_EXECUTABLES)/FileCheck \
358 $(LLVM_PREBUILTS_PATH)/clang++ \
359 CLANG \
361 LOCAL_CLANG := true
362 LOCAL_MODULE := bionic-compile-time-tests-clang++
363 LOCAL_CXXFLAGS := -Wall
364 # FileCheck will error if there aren't any CLANG: lines in the file, but there
365 # don't appear to be any cases where clang _does_ emit warnings for sn?printf :(
366 LOCAL_SRC_FILES :=
367 include $(BUILD_STATIC_LIBRARY)
369 # -----------------------------------------------------------------------------
370 # Host glibc tests.
371 # -----------------------------------------------------------------------------
373 ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm mips x86))
374 LINKER = linker64
375 NATIVE_TEST_SUFFIX=64
376 else
377 LINKER = linker
378 NATIVE_TEST_SUFFIX=32
379 endif
381 # gtest needs ANDROID_DATA/local/tmp for death test output.
382 # Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
383 # Use the current target out directory as ANDROID_DATA.
384 # BIONIC_TEST_FLAGS is either empty or it comes from the user.
385 bionic-unit-tests-glibc-run: bionic-unit-tests-glibc
386 mkdir -p $(TARGET_OUT_DATA)/local/tmp
387 ANDROID_DATA=$(TARGET_OUT_DATA) \
388 ANDROID_ROOT=$(TARGET_OUT) \
389 $(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS)
391 # -----------------------------------------------------------------------------
392 # Run the unit tests built against x86 bionic on an x86 host.
393 # -----------------------------------------------------------------------------
395 ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
396 # gtest needs ANDROID_DATA/local/tmp for death test output.
397 # Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
398 # bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT.
399 # BIONIC_TEST_FLAGS is either empty or it comes from the user.
400 bionic-unit-tests-run-on-host-prepare: $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT)/etc/hosts $(TARGET_OUT_EXECUTABLES)/sh
401 if [ ! -d /system ]; then \
402 echo "Attempting to create /system"; \
403 sudo mkdir -p -m 0777 /system; \
404 fi
405 mkdir -p $(TARGET_OUT_DATA)/local/tmp
406 ln -fs `realpath $(TARGET_OUT)/bin` /system/
407 ln -fs `realpath $(TARGET_OUT)/etc` /system/
409 bionic-unit-tests-run-on-host: bionic-unit-tests bionic-unit-tests-run-on-host-prepare
410 ANDROID_DATA=$(TARGET_OUT_DATA) \
411 ANDROID_DNS_MODE=local \
412 ANDROID_ROOT=$(TARGET_OUT) \
413 LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \
414 $(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS)
415 endif
417 ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86_64))
418 # add target to run lp32 tests
419 bionic-unit-tests-run-on-host32: bionic-unit-tests_32 bionic-unit-tests-run-on-host-prepare
420 ANDROID_DATA=$(TARGET_OUT_DATA) \
421 ANDROID_DNS_MODE=local \
422 ANDROID_ROOT=$(TARGET_OUT) \
423 LD_LIBRARY_PATH=$(2ND_TARGET_OUT_SHARED_LIBRARIES) \
424 $(2ND_TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests32 $(BIONIC_TEST_FLAGS)
425 endif
427 endif # linux-x86
429 include $(call first-makefiles-under,$(LOCAL_PATH))
430 endif # !BUILD_TINY_ANDROID