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