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