Android.mk revision b6e3e800d26d8ca05aca65e529cc31a180fb58d4
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#
16
17LOCAL_PATH := $(call my-dir)
18
19# -----------------------------------------------------------------------------
20# Unit tests.
21# -----------------------------------------------------------------------------
22
23ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
24build_host := true
25else
26build_host := false
27endif
28
29common_additional_dependencies := $(LOCAL_PATH)/Android.mk $(LOCAL_PATH)/Android.build.mk
30
31# -----------------------------------------------------------------------------
32# All standard tests.
33# -----------------------------------------------------------------------------
34test_cflags = \
35    -fstack-protector-all \
36    -g \
37    -Wall -Wextra -Wunused \
38    -Werror \
39    -fno-builtin \
40
41test_cflags += -D__STDC_LIMIT_MACROS  # For glibc.
42
43ifeq ($(MALLOC_IMPL),dlmalloc)
44test_cflags += -DUSE_DLMALLOC
45else
46test_cflags += -DUSE_JEMALLOC
47endif
48
49test_cppflags = \
50    -std=gnu++11 \
51
52libBionicStandardTests_src_files := \
53    arpa_inet_test.cpp \
54    buffer_tests.cpp \
55    complex_test.cpp \
56    ctype_test.cpp \
57    dirent_test.cpp \
58    error_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    pty_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_personality_test.cpp \
96    sys_resource_test.cpp \
97    sys_select_test.cpp \
98    sys_sendfile_test.cpp \
99    sys_socket_test.cpp \
100    sys_stat_test.cpp \
101    sys_statvfs_test.cpp \
102    sys_syscall_test.cpp \
103    sys_sysinfo_test.cpp \
104    sys_time_test.cpp \
105    sys_types_test.cpp \
106    sys_vfs_test.cpp \
107    system_properties_test.cpp \
108    time_test.cpp \
109    uchar_test.cpp \
110    uniqueptr_test.cpp \
111    unistd_test.cpp \
112    utmp_test.cpp \
113    wchar_test.cpp \
114
115libBionicStandardTests_cflags := \
116    $(test_cflags) \
117
118ifeq ($(MALLOC_IMPL),dlmalloc)
119  libBionicStandardTests_cflags += -DUSE_DLMALLOC
120else
121  libBionicStandardTests_cflags += -DUSE_JEMALLOC
122endif
123
124libBionicStandardTests_cppflags := \
125    $(test_cppflags) \
126
127libBionicStandardTests_c_includes := \
128    bionic/libc \
129    external/tinyxml2 \
130
131libBionicStandardTests_ldlibs_host := \
132    -lrt \
133
134module := libBionicStandardTests
135module_tag := optional
136build_type := target
137build_target := STATIC_TEST_LIBRARY
138include $(LOCAL_PATH)/Android.build.mk
139build_type := host
140include $(LOCAL_PATH)/Android.build.mk
141
142# -----------------------------------------------------------------------------
143# Fortify tests.
144# -----------------------------------------------------------------------------
145$(foreach compiler,gcc clang, \
146  $(foreach test,1 2, \
147    $(eval fortify$(test)-tests-$(compiler)_cflags := \
148      $(test_cflags) \
149      -Wno-error \
150      -U_FORTIFY_SOURCE \
151      -D_FORTIFY_SOURCE=$(test) \
152      -DTEST_NAME=Fortify$(test)_$(compiler)); \
153    $(eval fortify$(test)-tests-$(compiler)_src_files := \
154      fortify_test.cpp); \
155    $(eval fortify_libs += fortify$(test)-tests-$(compiler)); \
156  ) \
157)
158
159module := fortify1-tests-gcc
160module_tag := optional
161build_type := target
162build_target := STATIC_TEST_LIBRARY
163include $(LOCAL_PATH)/Android.build.mk
164build_type := host
165include $(LOCAL_PATH)/Android.build.mk
166
167module := fortify2-tests-gcc
168module_tag := optional
169build_type := target
170build_target := STATIC_TEST_LIBRARY
171include $(LOCAL_PATH)/Android.build.mk
172build_type := host
173include $(LOCAL_PATH)/Android.build.mk
174
175fortify1-tests-clang_clang_target := true
176fortify1-tests-clang_cflags_host := -D__clang__
177
178module := fortify1-tests-clang
179module_tag := optional
180build_type := target
181build_target := STATIC_TEST_LIBRARY
182include $(LOCAL_PATH)/Android.build.mk
183build_type := host
184include $(LOCAL_PATH)/Android.build.mk
185
186fortify2-tests-clang_clang_target := true
187
188fortify2-tests-clang_cflags_host := -D__clang__
189
190module := fortify2-tests-clang
191module_tag := optional
192build_type := target
193build_target := STATIC_TEST_LIBRARY
194include $(LOCAL_PATH)/Android.build.mk
195build_type := host
196include $(LOCAL_PATH)/Android.build.mk
197
198# -----------------------------------------------------------------------------
199# Library of all tests (excluding the dynamic linker tests).
200# -----------------------------------------------------------------------------
201libBionicTests_whole_static_libraries := \
202    libBionicStandardTests \
203    $(fortify_libs) \
204
205module := libBionicTests
206module_tag := optional
207build_type := target
208build_target := STATIC_TEST_LIBRARY
209include $(LOCAL_PATH)/Android.build.mk
210build_type := host
211include $(LOCAL_PATH)/Android.build.mk
212
213# -----------------------------------------------------------------------------
214# Library of bionic customized gtest main function.
215# -----------------------------------------------------------------------------
216libBionicGtestMain_src_files := gtest_main.cpp
217
218libBionicGtestMain_cflags := $(test_cflags)
219
220libBionicGtestMain_cppflags := $(test_cppflags)
221
222module := libBionicGtestMain
223module_tag := optional
224build_type := target
225build_target := STATIC_TEST_LIBRARY
226include $(LOCAL_PATH)/Android.build.mk
227build_type := host
228include $(LOCAL_PATH)/Android.build.mk
229
230# -----------------------------------------------------------------------------
231# Tests for the device using bionic's .so. Run with:
232#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests32
233#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests64
234# -----------------------------------------------------------------------------
235bionic-unit-tests_whole_static_libraries := \
236    libBionicTests \
237    libBionicGtestMain \
238
239bionic-unit-tests_static_libraries := \
240    libtinyxml2 \
241    liblog \
242
243bionic-unit-tests_src_files := \
244    atexit_test.cpp \
245    dl_test.cpp \
246    dlext_test.cpp \
247    dlfcn_test.cpp \
248
249bionic-unit-tests_cflags := $(test_cflags)
250
251bionic-unit-tests_conlyflags := \
252    -fexceptions \
253    -fnon-call-exceptions \
254
255bionic-unit-tests_cppflags := $(test_cppflags)
256
257bionic-unit-tests_ldflags := \
258    -Wl,--export-dynamic
259
260bionic-unit-tests_c_includes := \
261    bionic/libc \
262    $(call include-path-for, libpagemap) \
263
264bionic-unit-tests_shared_libraries_target := \
265    libdl \
266    libpagemap \
267    libdl_preempt_test_1 \
268    libdl_preempt_test_2
269
270ifneq ($(filter $(TARGET_ARCH),arm arm64),$(TARGET_ARCH))
271bionic-unit-tests_shared_libraries_target += libdl_test_df_1_global
272endif
273
274module := bionic-unit-tests
275module_tag := optional
276build_type := target
277build_target := NATIVE_TEST
278include $(LOCAL_PATH)/Android.build.mk
279
280# -----------------------------------------------------------------------------
281# Tests for the device linked against bionic's static library. Run with:
282#   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static32
283#   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static64
284# -----------------------------------------------------------------------------
285bionic-unit-tests-static_whole_static_libraries := \
286    libBionicTests \
287    libBionicGtestMain \
288
289bionic-unit-tests-static_static_libraries := \
290    libm \
291    libc \
292    libc++_static \
293    libdl \
294    libtinyxml2 \
295    liblog \
296
297bionic-unit-tests-static_force_static_executable := true
298
299# libc and libc++ both define std::nothrow. libc's is a private symbol, but this
300# still causes issues when linking libc.a and libc++.a, since private isn't
301# effective until it has been linked. To fix this, just allow multiple symbol
302# definitions for the static tests.
303bionic-unit-tests-static_ldflags := -Wl,--allow-multiple-definition
304
305module := bionic-unit-tests-static
306module_tag := optional
307build_type := target
308build_target := NATIVE_TEST
309include $(LOCAL_PATH)/Android.build.mk
310
311# -----------------------------------------------------------------------------
312# Tests to run on the host and linked against glibc. Run with:
313#   cd bionic/tests; mm bionic-unit-tests-glibc-run
314# -----------------------------------------------------------------------------
315
316ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
317
318bionic-unit-tests-glibc_src_files := \
319    atexit_test.cpp \
320    dlfcn_test.cpp \
321    dl_test.cpp \
322
323bionic-unit-tests-glibc_shared_libraries := \
324    libdl_preempt_test_1 \
325    libdl_preempt_test_2
326
327bionic-unit-tests-glibc_shared_libraries += libdl_test_df_1_global
328
329bionic-unit-tests-glibc_whole_static_libraries := \
330    libBionicStandardTests \
331    libBionicGtestMain \
332    $(fortify_libs) \
333
334bionic-unit-tests-glibc_ldlibs := \
335    -lrt -ldl -lutil \
336
337bionic-unit-tests-glibc_c_includes := \
338    bionic/libc \
339
340bionic-unit-tests-glibc_cflags := $(test_cflags)
341bionic-unit-tests-glibc_cppflags := $(test_cppflags)
342bionic-unit-tests-glibc_ldflags := -Wl,--export-dynamic
343
344bionic-unit-tests-glibc_allow_asan := true
345
346module := bionic-unit-tests-glibc
347module_tag := optional
348build_type := host
349build_target := NATIVE_TEST
350include $(LOCAL_PATH)/Android.build.mk
351
352# -----------------------------------------------------------------------------
353# Compile time tests.
354# -----------------------------------------------------------------------------
355
356# Some of these are intentionally using = instead of := since we need access to
357# some variables not initialtized until we're in the build system.
358
359include $(CLEAR_VARS)
360LOCAL_ADDITIONAL_DEPENDENCIES := \
361    $(LOCAL_PATH)/Android.mk \
362    $(LOCAL_PATH)/file-check-cxx \
363    | $(HOST_OUT_EXECUTABLES)/FileCheck$(HOST_EXECUTABLE_SUFFIX) \
364
365LOCAL_CXX = $(LOCAL_PATH)/file-check-cxx \
366    $(HOST_OUT_EXECUTABLES)/FileCheck \
367    $($(LOCAL_2ND_ARCH_VAR_PREFIX)CXX_BARE) \
368    GCC \
369
370LOCAL_CLANG := false
371LOCAL_MODULE := bionic-compile-time-tests-g++
372LOCAL_CPPFLAGS := -Wall
373LOCAL_SRC_FILES := fortify_sprintf_warnings.cpp
374include $(BUILD_STATIC_LIBRARY)
375
376include $(CLEAR_VARS)
377LOCAL_ADDITIONAL_DEPENDENCIES := \
378    $(LOCAL_PATH)/Android.mk \
379    $(LOCAL_PATH)/file-check-cxx \
380    | $(HOST_OUT_EXECUTABLES)/FileCheck$(HOST_EXECUTABLE_SUFFIX) \
381
382LOCAL_CXX := $(LOCAL_PATH)/file-check-cxx \
383    $(HOST_OUT_EXECUTABLES)/FileCheck \
384    $(LLVM_PREBUILTS_PATH)/clang++ \
385    CLANG \
386
387LOCAL_CLANG := true
388LOCAL_MODULE := bionic-compile-time-tests-clang++
389LOCAL_CPPFLAGS := -Wall
390# FileCheck will error if there aren't any CLANG: lines in the file, but there
391# don't appear to be any cases where clang _does_ emit warnings for sn?printf :(
392LOCAL_SRC_FILES :=
393include $(BUILD_STATIC_LIBRARY)
394
395# -----------------------------------------------------------------------------
396# Host glibc tests.
397# -----------------------------------------------------------------------------
398
399# gtest needs ANDROID_DATA/local/tmp for death test output.
400# Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
401# Use the current target out directory as ANDROID_DATA.
402# BIONIC_TEST_FLAGS is either empty or it comes from the user.
403bionic-unit-tests-glibc-run: bionic-unit-tests-glibc
404	mkdir -p $(TARGET_OUT_DATA)/local/tmp
405	ANDROID_DATA=$(TARGET_OUT_DATA) \
406	ANDROID_ROOT=$(TARGET_OUT) \
407		$(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc64 $(BIONIC_TEST_FLAGS)
408
409# -----------------------------------------------------------------------------
410# Run the unit tests built against x86 bionic on an x86 host.
411# -----------------------------------------------------------------------------
412
413include $(LOCAL_PATH)/../build/run-on-host.mk
414
415ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
416
417TEST_TIMEOUT := 0
418
419# BIONIC_TEST_FLAGS is either empty or it comes from the user.
420bionic-unit-tests-run-on-host32: bionic-unit-tests bionic-prepare-run-on-host
421	ANDROID_DATA=$(TARGET_OUT_DATA) \
422	ANDROID_DNS_MODE=local \
423	ANDROID_ROOT=$(TARGET_OUT) \
424		timeout $(TEST_TIMEOUT) \
425		$(TARGET_OUT_DATA)/nativetest/bionic-unit-tests/bionic-unit-tests32 $(BIONIC_TEST_FLAGS)
426
427ifeq ($(TARGET_IS_64_BIT),true)
428# add target to run lp64 tests
429bionic-unit-tests-run-on-host64: bionic-unit-tests bionic-prepare-run-on-host
430	ANDROID_DATA=$(TARGET_OUT_DATA) \
431	ANDROID_DNS_MODE=local \
432	ANDROID_ROOT=$(TARGET_OUT) \
433		timeout $(TEST_TIMEOUT) \
434		$(TARGET_OUT_DATA)/nativetest64/bionic-unit-tests/bionic-unit-tests64 $(BIONIC_TEST_FLAGS)
435endif
436
437endif # x86 x86_64
438endif # linux-x86
439
440include $(call first-makefiles-under,$(LOCAL_PATH))
441