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