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