Android.mk revision 8de1ddece0d0b85eafeb86c06cf3a734dadf2b55
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
17ifneq ($(BUILD_TINY_ANDROID),true)
18
19LOCAL_PATH := $(call my-dir)
20
21# -----------------------------------------------------------------------------
22# Unit tests.
23# -----------------------------------------------------------------------------
24
25ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
26build_host := true
27else
28build_host := false
29endif
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    ctype_test.cpp \
56    dirent_test.cpp \
57    eventfd_test.cpp \
58    fcntl_test.cpp \
59    fenv_test.cpp \
60    ftw_test.cpp \
61    getauxval_test.cpp \
62    getcwd_test.cpp \
63    inttypes_test.cpp \
64    libc_logging_test.cpp \
65    libgen_test.cpp \
66    locale_test.cpp \
67    malloc_test.cpp \
68    math_cos_test.cpp \
69    math_cosf_test.cpp \
70    math_exp_test.cpp \
71    math_expf_test.cpp \
72    math_log_test.cpp \
73    math_logf_test.cpp \
74    math_pow_test.cpp \
75    math_powf_test.cpp \
76    math_sin_test.cpp \
77    math_sinf_test.cpp \
78    math_sincos_test.cpp \
79    math_sincosf_test.cpp \
80    math_tan_test.cpp \
81    math_tanf_test.cpp \
82    math_test.cpp \
83    mntent_test.cpp \
84    netdb_test.cpp \
85    pthread_test.cpp \
86    regex_test.cpp \
87    sched_test.cpp \
88    search_test.cpp \
89    signal_test.cpp \
90    stack_protector_test.cpp \
91    stack_unwinding_test.cpp \
92    stdatomic_test.cpp \
93    stdint_test.cpp \
94    stdio_test.cpp \
95    stdlib_test.cpp \
96    string_test.cpp \
97    strings_test.cpp \
98    stubs_test.cpp \
99    sstream_test.cpp \
100    sys_epoll_test.cpp \
101    sys_mman_test.cpp \
102    sys_resource_test.cpp \
103    sys_select_test.cpp \
104    sys_sendfile_test.cpp \
105    sys_socket_test.cpp \
106    sys_stat_test.cpp \
107    sys_statvfs_test.cpp \
108    sys_syscall_test.cpp \
109    sys_time_test.cpp \
110    sys_types_test.cpp \
111    sys_vfs_test.cpp \
112    system_properties_test.cpp \
113    time_test.cpp \
114    uchar_test.cpp \
115    uniqueptr_test.cpp \
116    unistd_test.cpp \
117    wchar_test.cpp \
118
119libBionicStandardTests_cflags := \
120    $(test_cflags) \
121
122ifeq ($(MALLOC_IMPL),dlmalloc)
123  libBionicStandardTests_cflags += -DUSE_DLMALLOC
124else
125  libBionicStandardTests_cflags += -DUSE_JEMALLOC
126endif
127
128libBionicStandardTests_cppflags := \
129    $(test_cppflags) \
130
131libBionicStandardTests_c_includes := \
132    bionic/libc \
133
134libBionicStandardTests_ldlibs_host := \
135    -lrt \
136
137libBionicStandardTests_whole_static_libraries := \
138    libBionicUnwindTest \
139
140module := libBionicStandardTests
141module_tag := optional
142build_type := target
143build_target := STATIC_TEST_LIBRARY
144include $(LOCAL_PATH)/Android.build.mk
145build_type := host
146include $(LOCAL_PATH)/Android.build.mk
147
148# -----------------------------------------------------------------------------
149# Special stack unwinding test library compiled with special flags.
150# -----------------------------------------------------------------------------
151libBionicUnwindTest_cflags := \
152    $(test_cflags) \
153    -fexceptions \
154    -fnon-call-exceptions \
155
156libBionicUnwindTest_src_files := \
157    stack_unwinding_test_impl.c \
158
159module := libBionicUnwindTest
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
167# -----------------------------------------------------------------------------
168# Fortify tests.
169# -----------------------------------------------------------------------------
170$(foreach compiler,gcc clang, \
171  $(foreach test,1 2, \
172    $(eval fortify$(test)-tests-$(compiler)_cflags := \
173      $(test_cflags) \
174      -U_FORTIFY_SOURCE \
175      -D_FORTIFY_SOURCE=$(test) \
176      -DTEST_NAME=Fortify$(test)_$(compiler)); \
177    $(eval fortify$(test)-tests-$(compiler)_cflags_host := \
178      -Wno-error); \
179    $(eval fortify$(test)-tests-$(compiler)_src_files := \
180      fortify_test.cpp); \
181    $(eval fortify_libs += fortify$(test)-tests-$(compiler)); \
182  ) \
183)
184
185module := fortify1-tests-gcc
186module_tag := optional
187build_type := target
188build_target := STATIC_TEST_LIBRARY
189include $(LOCAL_PATH)/Android.build.mk
190build_type := host
191include $(LOCAL_PATH)/Android.build.mk
192
193module := fortify2-tests-gcc
194module_tag := optional
195build_type := target
196build_target := STATIC_TEST_LIBRARY
197include $(LOCAL_PATH)/Android.build.mk
198build_type := host
199include $(LOCAL_PATH)/Android.build.mk
200
201fortify1-tests-clang_clang_target := true
202fortify1-tests-clang_cflags_host := -D__clang__
203
204module := fortify1-tests-clang
205module_tag := optional
206build_type := target
207build_target := STATIC_TEST_LIBRARY
208include $(LOCAL_PATH)/Android.build.mk
209build_type := host
210include $(LOCAL_PATH)/Android.build.mk
211
212fortify2-tests-clang_clang_target := true
213
214fortify2-tests-clang_cflags_host := -D__clang__
215
216module := fortify2-tests-clang
217module_tag := optional
218build_type := target
219build_target := STATIC_TEST_LIBRARY
220include $(LOCAL_PATH)/Android.build.mk
221build_type := host
222include $(LOCAL_PATH)/Android.build.mk
223
224# -----------------------------------------------------------------------------
225# Library of all tests (excluding the dynamic linker tests).
226# -----------------------------------------------------------------------------
227libBionicTests_whole_static_libraries := \
228    libBionicStandardTests \
229    $(fortify_libs) \
230
231module := libBionicTests
232module_tag := optional
233build_type := target
234build_target := STATIC_TEST_LIBRARY
235include $(LOCAL_PATH)/Android.build.mk
236build_type := host
237include $(LOCAL_PATH)/Android.build.mk
238
239# -----------------------------------------------------------------------------
240# Tests for the device using bionic's .so. Run with:
241#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests32
242#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests64
243# -----------------------------------------------------------------------------
244bionic-unit-tests_whole_static_libraries := \
245    libBionicTests \
246
247bionic-unit-tests_src_files := \
248    atexit_test.cpp \
249    dlext_test.cpp \
250    dlfcn_test.cpp \
251
252bionic-unit-tests_cflags := $(test_cflags)
253bionic-unit-tests_cppflags := $(test_cppflags)
254
255bionic-unit-tests_ldflags := \
256    -Wl,--export-dynamic \
257    -Wl,-u,DlSymTestFunction \
258
259bionic-unit-tests_c_includes := \
260    bionic/libc \
261    $(call include-path-for, libpagemap) \
262
263bionic-unit-tests_shared_libraries_target := \
264    libdl \
265    libpagemap \
266
267module := bionic-unit-tests
268module_tag := optional
269build_type := target
270build_target := NATIVE_TEST
271include $(LOCAL_PATH)/Android.build.mk
272
273# -----------------------------------------------------------------------------
274# Tests for the device linked against bionic's static library. Run with:
275#   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static32
276#   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static64
277# -----------------------------------------------------------------------------
278bionic-unit-tests-static_whole_static_libraries := \
279    libBionicTests \
280
281bionic-unit-tests-static_static_libraries := \
282    libstlport_static \
283    libm \
284    libc \
285    libstdc++ \
286
287bionic-unit-tests-static_force_static_executable := true
288
289module := bionic-unit-tests-static
290module_tag := optional
291build_type := target
292build_target := NATIVE_TEST
293include $(LOCAL_PATH)/Android.build.mk
294
295# -----------------------------------------------------------------------------
296# Tests to run on the host and linked against glibc. Run with:
297#   cd bionic/tests; mm bionic-unit-tests-glibc-run
298# -----------------------------------------------------------------------------
299
300ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
301
302bionic-unit-tests-glibc_src_files := \
303    atexit_test.cpp \
304
305bionic-unit-tests-glibc_whole_static_libraries := \
306    libBionicStandardTests \
307
308bionic-unit-tests-glibc_ldlibs := \
309    -lrt -ldl \
310
311bionic-unit-tests-glibc_cflags := $(test_cflags)
312bionic-unit-tests-glibc_cppflags := $(test_cppflags)
313
314module := bionic-unit-tests-glibc
315module_tag := optional
316build_type := host
317build_target := NATIVE_TEST
318include $(LOCAL_PATH)/Android.build.mk
319
320ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm mips x86))
321LINKER = linker64
322NATIVE_TEST_SUFFIX=64
323else
324LINKER = linker
325NATIVE_TEST_SUFFIX=32
326endif
327
328# gtest needs ANDROID_DATA/local/tmp for death test output.
329# Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
330# Use the current target out directory as ANDROID_DATA.
331# BIONIC_TEST_FLAGS is either empty or it comes from the user.
332bionic-unit-tests-glibc-run: bionic-unit-tests-glibc
333	mkdir -p $(TARGET_OUT_DATA)/local/tmp
334	ANDROID_DATA=$(TARGET_OUT_DATA) \
335	ANDROID_ROOT=$(TARGET_OUT) \
336		$(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS)
337
338# -----------------------------------------------------------------------------
339# Run the unit tests built against x86 bionic on an x86 host.
340# -----------------------------------------------------------------------------
341
342ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
343# gtest needs ANDROID_DATA/local/tmp for death test output.
344# Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
345# bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT.
346# BIONIC_TEST_FLAGS is either empty or it comes from the user.
347bionic-unit-tests-run-on-host: bionic-unit-tests $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh
348	if [ ! -d /system -o ! -d /system/bin ]; then \
349	  echo "Attempting to create /system/bin"; \
350	  sudo mkdir -p -m 0777 /system/bin; \
351	fi
352	mkdir -p $(TARGET_OUT_DATA)/local/tmp
353	cp $(TARGET_OUT_EXECUTABLES)/$(LINKER) /system/bin
354	cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin
355	ANDROID_DATA=$(TARGET_OUT_DATA) \
356	ANDROID_ROOT=$(TARGET_OUT) \
357	LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \
358		$(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS)
359endif
360
361ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86_64))
362# add target to run lp32 tests
363bionic-unit-tests-run-on-host32: bionic-unit-tests_32 $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh
364	if [ ! -d /system -o ! -d /system/bin ]; then \
365	  echo "Attempting to create /system/bin"; \
366	  sudo mkdir -p -m 0777 /system/bin; \
367	fi
368	mkdir -p $(TARGET_OUT_DATA)/local/tmp
369	cp $(TARGET_OUT_EXECUTABLES)/linker /system/bin
370	cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin
371	ANDROID_DATA=$(TARGET_OUT_DATA) \
372	ANDROID_ROOT=$(TARGET_OUT) \
373	LD_LIBRARY_PATH=$(2ND_TARGET_OUT_SHARED_LIBRARIES) \
374		$(2ND_TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests32 $(BIONIC_TEST_FLAGS)
375endif
376
377endif # linux-x86
378
379include $(call first-makefiles-under,$(LOCAL_PATH))
380endif # !BUILD_TINY_ANDROID
381