Android.mk revision 345b49a7c07fde18e9397ffba9079ff81a4c3d74
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 \
38    -Werror \
39    -fno-builtin \
40
41libBionicStandardTests_src_files := \
42    buffer_tests.cpp \
43    ctype_test.cpp \
44    dirent_test.cpp \
45    eventfd_test.cpp \
46    fcntl_test.cpp \
47    fenv_test.cpp \
48    ftw_test.cpp \
49    getauxval_test.cpp \
50    getcwd_test.cpp \
51    inttypes_test.cpp \
52    libc_logging_test.cpp \
53    libgen_test.cpp \
54    locale_test.cpp \
55    malloc_test.cpp \
56    math_test.cpp \
57    netdb_test.cpp \
58    pthread_test.cpp \
59    regex_test.cpp \
60    sched_test.cpp \
61    signal_test.cpp \
62    stack_protector_test.cpp \
63    stack_unwinding_test.cpp \
64    stack_unwinding_test_impl.c \
65    stdint_test.cpp \
66    stdio_test.cpp \
67    stdlib_test.cpp \
68    string_test.cpp \
69    strings_test.cpp \
70    stubs_test.cpp \
71    sstream_test.cpp \
72    sys_epoll_test.cpp \
73    sys_mman_test.cpp \
74    sys_resource_test.cpp \
75    sys_select_test.cpp \
76    sys_sendfile_test.cpp \
77    sys_socket_test.cpp \
78    sys_stat_test.cpp \
79    sys_statvfs_test.cpp \
80    sys_syscall_test.cpp \
81    sys_time_test.cpp \
82    sys_types_test.cpp \
83    sys_vfs_test.cpp \
84    system_properties_test.cpp \
85    time_test.cpp \
86    unistd_test.cpp \
87    wchar_test.cpp \
88
89libBionicStandardTests_cflags := \
90    $(test_cflags) \
91
92libBionicStandardTests_ldlibs_host := \
93    -lrt \
94
95module := libBionicStandardTests
96module_tag := optional
97build_type := target
98build_target := STATIC_TEST_LIBRARY
99include $(LOCAL_PATH)/Android.build.mk
100build_type := host
101include $(LOCAL_PATH)/Android.build.mk
102
103# -----------------------------------------------------------------------------
104# Fortify tests.
105# -----------------------------------------------------------------------------
106$(foreach compiler,gcc clang, \
107  $(foreach test,1 2, \
108    $(eval fortify$(test)-tests-$(compiler)_cflags := \
109      $(test_cflags) \
110      -U_FORTIFY_SOURCE \
111      -D_FORTIFY_SOURCE=$(test) \
112      -DTEST_NAME=Fortify$(test)_$(compiler)); \
113    $(eval fortify$(test)-tests-$(compiler)_cflags_host := \
114      -Wno-error); \
115    $(eval fortify$(test)-tests-$(compiler)_src_files := \
116      fortify_test.cpp); \
117    $(eval fortify_libs += fortify$(test)-tests-$(compiler)); \
118  ) \
119)
120
121module := fortify1-tests-gcc
122module_tag := optional
123build_type := target
124build_target := STATIC_TEST_LIBRARY
125include $(LOCAL_PATH)/Android.build.mk
126build_type := host
127include $(LOCAL_PATH)/Android.build.mk
128
129module := fortify2-tests-gcc
130module_tag := optional
131build_type := target
132build_target := STATIC_TEST_LIBRARY
133include $(LOCAL_PATH)/Android.build.mk
134build_type := host
135include $(LOCAL_PATH)/Android.build.mk
136
137fortify1-tests-clang_clang_target := true
138fortify1-tests-clang_cflags_host := -D__clang__
139
140module := fortify1-tests-clang
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
148fortify2-tests-clang_clang_target := true
149
150fortify2-tests-clang_cflags_host := -D__clang__
151
152module := fortify2-tests-clang
153module_tag := optional
154build_type := target
155build_target := STATIC_TEST_LIBRARY
156include $(LOCAL_PATH)/Android.build.mk
157build_type := host
158include $(LOCAL_PATH)/Android.build.mk
159
160# -----------------------------------------------------------------------------
161# Library of all tests (excluding the dynamic linker tests).
162# -----------------------------------------------------------------------------
163libBionicTests_whole_static_libraries := \
164    libBionicStandardTests \
165    $(fortify_libs) \
166
167module := libBionicTests
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
175# -----------------------------------------------------------------------------
176# Library used by dlfcn tests.
177# -----------------------------------------------------------------------------
178ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),mips mips64))
179no-elf-hash-table-library_src_files := \
180    empty.cpp \
181
182no-elf-hash-table-library_ldflags := \
183    -Wl,--hash-style=gnu \
184
185module := no-elf-hash-table-library
186module_tag := optional
187build_type := target
188build_target := SHARED_LIBRARY
189include $(LOCAL_PATH)/Android.build.mk
190endif
191
192# -----------------------------------------------------------------------------
193# Library used by dlext tests.
194# -----------------------------------------------------------------------------
195libdlext_test_src_files := \
196    dlext_test_library.cpp \
197
198module := libdlext_test
199module_tag := optional
200build_type := target
201build_target := SHARED_LIBRARY
202include $(LOCAL_PATH)/Android.build.mk
203
204# -----------------------------------------------------------------------------
205# Tests for the device using bionic's .so. Run with:
206#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests
207# -----------------------------------------------------------------------------
208bionic-unit-tests_whole_static_libraries := \
209    libBionicTests \
210
211bionic-unit-tests_src_files := \
212    dlext_test.cpp \
213    dlfcn_test.cpp \
214
215bionic-unit-tests_ldflags := \
216    -Wl,--export-dynamic \
217    -Wl,-u,DlSymTestFunction \
218
219bionic-unit-tests_shared_libraries_target := \
220    libdl \
221
222module := bionic-unit-tests
223module_tag := optional
224multilib := both
225build_type := target
226build_target := NATIVE_TEST
227include $(LOCAL_PATH)/Android.build.mk
228
229# -----------------------------------------------------------------------------
230# Tests for the device linked against bionic's static library. Run with:
231#   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static
232# -----------------------------------------------------------------------------
233bionic-unit-tests-static_whole_static_libraries := \
234    libBionicTests \
235
236bionic-unit-tests-static_static_libraries := \
237    libstlport_static \
238    libm \
239    libc \
240    libstdc++ \
241
242bionic-unit-tests-static_force_static_executable := true
243
244module := bionic-unit-tests-static
245module_tag := optional
246multilib := both
247build_type := target
248build_target := NATIVE_TEST
249include $(LOCAL_PATH)/Android.build.mk
250
251# -----------------------------------------------------------------------------
252# Tests to run on the host and linked against glibc. Run with:
253#   cd bionic/tests; mm bionic-unit-tests-glibc-run
254# -----------------------------------------------------------------------------
255bionic-unit-tests-glibc_whole_static_libraries := \
256    libBionicStandardTests \
257
258bionic-unit-tests-glibc_ldlibs := \
259    -lrt \
260
261module := bionic-unit-tests-glibc
262module_tag := optional
263build_type := host
264build_target := NATIVE_TEST
265include $(LOCAL_PATH)/Android.build.mk
266
267# gtest needs ANDROID_DATA/local/tmp for death test output.
268# Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
269# Use the current target out directory as ANDROID_DATA.
270# BIONIC_TEST_FLAGS is either empty or it comes from the user.
271bionic-unit-tests-glibc-run: bionic-unit-tests-glibc
272	mkdir -p $(TARGET_OUT_DATA)/local/tmp
273	ANDROID_DATA=$(TARGET_OUT_DATA) \
274	ANDROID_ROOT=$(TARGET_OUT) \
275		$(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc $(BIONIC_TEST_FLAGS)
276
277# -----------------------------------------------------------------------------
278# Run the unit tests built against x86 bionic on an x86 host.
279# -----------------------------------------------------------------------------
280ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
281ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
282ifeq ($(TARGET_ARCH),x86)
283LINKER = linker
284else
285LINKER = linker64
286endif
287# gtest needs ANDROID_DATA/local/tmp for death test output.
288# Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
289# bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT.
290# BIONIC_TEST_FLAGS is either empty or it comes from the user.
291bionic-unit-tests-run-on-host: bionic-unit-tests $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh
292	if [ ! -d /system -o ! -d /system/bin ]; then \
293	  echo "Attempting to create /system/bin"; \
294	  sudo mkdir -p -m 0777 /system/bin; \
295	fi
296	mkdir -p $(TARGET_OUT_DATA)/local/tmp
297	cp $(TARGET_OUT_EXECUTABLES)/$(LINKER) /system/bin
298	cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin
299	ANDROID_DATA=$(TARGET_OUT_DATA) \
300	ANDROID_ROOT=$(TARGET_OUT) \
301	LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \
302		$(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests $(BIONIC_TEST_FLAGS)
303endif
304endif
305
306endif # !BUILD_TINY_ANDROID
307