Android.mk revision 14669a939d113214a4a20b9318fca0992d5453f0
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 -Wunused \
38    -Werror \
39    -fno-builtin \
40
41test_cflags += -D__STDC_LIMIT_MACROS  # For glibc.
42
43ifeq ($(MALLOC_IMPL),dlmalloc)
44test_cflags += -DUSE_DLMALLOC
45else
46test_cflags += -DUSE_JEMALLOC
47endif
48
49test_cppflags = \
50    -std=gnu++11 \
51
52libBionicStandardTests_src_files := \
53    arpa_inet_test.cpp \
54    buffer_tests.cpp \
55    ctype_test.cpp \
56    dirent_test.cpp \
57    eventfd_test.cpp \
58    fcntl_test.cpp \
59    fenv_test.cpp \
60    ftw_test.cpp \
61    getauxval_test.cpp \
62    getcwd_test.cpp \
63    inttypes_test.cpp \
64    libc_logging_test.cpp \
65    libgen_test.cpp \
66    locale_test.cpp \
67    malloc_test.cpp \
68    math_cos_test.cpp \
69    math_cosf_test.cpp \
70    math_exp_test.cpp \
71    math_expf_test.cpp \
72    math_log_test.cpp \
73    math_logf_test.cpp \
74    math_pow_test.cpp \
75    math_powf_test.cpp \
76    math_sin_test.cpp \
77    math_sinf_test.cpp \
78    math_sincos_test.cpp \
79    math_sincosf_test.cpp \
80    math_tan_test.cpp \
81    math_tanf_test.cpp \
82    math_test.cpp \
83    mntent_test.cpp \
84    netdb_test.cpp \
85    pthread_test.cpp \
86    regex_test.cpp \
87    sched_test.cpp \
88    search_test.cpp \
89    signal_test.cpp \
90    stack_protector_test.cpp \
91    stack_unwinding_test.cpp \
92    stdatomic_test.cpp \
93    stdint_test.cpp \
94    stdio_test.cpp \
95    stdio_ext_test.cpp \
96    stdlib_test.cpp \
97    string_test.cpp \
98    string_posix_strerror_r_test.cpp \
99    strings_test.cpp \
100    stubs_test.cpp \
101    sstream_test.cpp \
102    sys_epoll_test.cpp \
103    sys_mman_test.cpp \
104    sys_resource_test.cpp \
105    sys_select_test.cpp \
106    sys_sendfile_test.cpp \
107    sys_socket_test.cpp \
108    sys_stat_test.cpp \
109    sys_statvfs_test.cpp \
110    sys_syscall_test.cpp \
111    sys_time_test.cpp \
112    sys_types_test.cpp \
113    sys_vfs_test.cpp \
114    system_properties_test.cpp \
115    time_test.cpp \
116    uchar_test.cpp \
117    uniqueptr_test.cpp \
118    unistd_test.cpp \
119    wchar_test.cpp \
120
121libBionicStandardTests_cflags := \
122    $(test_cflags) \
123
124ifeq ($(MALLOC_IMPL),dlmalloc)
125  libBionicStandardTests_cflags += -DUSE_DLMALLOC
126else
127  libBionicStandardTests_cflags += -DUSE_JEMALLOC
128endif
129
130libBionicStandardTests_cppflags := \
131    $(test_cppflags) \
132
133libBionicStandardTests_c_includes := \
134    bionic/libc \
135    external/tinyxml2 \
136
137libBionicStandardTests_ldlibs_host := \
138    -lrt \
139
140libBionicStandardTests_whole_static_libraries := \
141    libBionicUnwindTest \
142
143module := libBionicStandardTests
144module_tag := optional
145build_type := target
146build_target := STATIC_TEST_LIBRARY
147include $(LOCAL_PATH)/Android.build.mk
148build_type := host
149include $(LOCAL_PATH)/Android.build.mk
150
151# -----------------------------------------------------------------------------
152# Special stack unwinding test library compiled with special flags.
153# -----------------------------------------------------------------------------
154libBionicUnwindTest_cflags := \
155    $(test_cflags) \
156    -fexceptions \
157    -fnon-call-exceptions \
158
159libBionicUnwindTest_src_files := \
160    stack_unwinding_test_impl.c \
161
162module := libBionicUnwindTest
163module_tag := optional
164build_type := target
165build_target := STATIC_TEST_LIBRARY
166include $(LOCAL_PATH)/Android.build.mk
167build_type := host
168include $(LOCAL_PATH)/Android.build.mk
169
170# -----------------------------------------------------------------------------
171# Fortify tests.
172# -----------------------------------------------------------------------------
173$(foreach compiler,gcc clang, \
174  $(foreach test,1 2, \
175    $(eval fortify$(test)-tests-$(compiler)_cflags := \
176      $(test_cflags) \
177      -U_FORTIFY_SOURCE \
178      -D_FORTIFY_SOURCE=$(test) \
179      -DTEST_NAME=Fortify$(test)_$(compiler)); \
180    $(eval fortify$(test)-tests-$(compiler)_cflags_host := \
181      -Wno-error); \
182    $(eval fortify$(test)-tests-$(compiler)_src_files := \
183      fortify_test.cpp); \
184    $(eval fortify_libs += fortify$(test)-tests-$(compiler)); \
185  ) \
186)
187
188module := fortify1-tests-gcc
189module_tag := optional
190build_type := target
191build_target := STATIC_TEST_LIBRARY
192include $(LOCAL_PATH)/Android.build.mk
193build_type := host
194include $(LOCAL_PATH)/Android.build.mk
195
196module := fortify2-tests-gcc
197module_tag := optional
198build_type := target
199build_target := STATIC_TEST_LIBRARY
200include $(LOCAL_PATH)/Android.build.mk
201build_type := host
202include $(LOCAL_PATH)/Android.build.mk
203
204fortify1-tests-clang_clang_target := true
205fortify1-tests-clang_cflags_host := -D__clang__
206
207module := fortify1-tests-clang
208module_tag := optional
209build_type := target
210build_target := STATIC_TEST_LIBRARY
211include $(LOCAL_PATH)/Android.build.mk
212build_type := host
213include $(LOCAL_PATH)/Android.build.mk
214
215fortify2-tests-clang_clang_target := true
216
217fortify2-tests-clang_cflags_host := -D__clang__
218
219module := fortify2-tests-clang
220module_tag := optional
221build_type := target
222build_target := STATIC_TEST_LIBRARY
223include $(LOCAL_PATH)/Android.build.mk
224build_type := host
225include $(LOCAL_PATH)/Android.build.mk
226
227# -----------------------------------------------------------------------------
228# Library of all tests (excluding the dynamic linker tests).
229# -----------------------------------------------------------------------------
230libBionicTests_whole_static_libraries := \
231    libBionicStandardTests \
232    $(fortify_libs) \
233
234module := libBionicTests
235module_tag := optional
236build_type := target
237build_target := STATIC_TEST_LIBRARY
238include $(LOCAL_PATH)/Android.build.mk
239build_type := host
240include $(LOCAL_PATH)/Android.build.mk
241
242# -----------------------------------------------------------------------------
243# Tests for the device using bionic's .so. Run with:
244#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests32
245#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests64
246# -----------------------------------------------------------------------------
247bionic-unit-tests_whole_static_libraries := \
248    libBionicTests \
249
250bionic-unit-tests_static_libraries := \
251    libtinyxml2 \
252    liblog \
253
254bionic-unit-tests_src_files := \
255    atexit_test.cpp \
256    dlext_test.cpp \
257    dlfcn_test.cpp \
258
259bionic-unit-tests_cflags := $(test_cflags)
260bionic-unit-tests_cppflags := $(test_cppflags)
261
262bionic-unit-tests_ldflags := \
263    -Wl,--export-dynamic \
264    -Wl,-u,DlSymTestFunction \
265
266bionic-unit-tests_c_includes := \
267    bionic/libc \
268    $(call include-path-for, libpagemap) \
269
270bionic-unit-tests_shared_libraries_target := \
271    libdl \
272    libpagemap \
273
274module := bionic-unit-tests
275module_tag := optional
276build_type := target
277build_target := NATIVE_TEST
278include $(LOCAL_PATH)/Android.build.mk
279
280# -----------------------------------------------------------------------------
281# Tests for the device linked against bionic's static library. Run with:
282#   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static32
283#   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static64
284# -----------------------------------------------------------------------------
285bionic-unit-tests-static_whole_static_libraries := \
286    libBionicTests \
287
288bionic-unit-tests-static_static_libraries := \
289    libstlport_static \
290    libm \
291    libc \
292    libstdc++ \
293    libtinyxml2 \
294    liblog \
295
296bionic-unit-tests-static_force_static_executable := true
297
298module := bionic-unit-tests-static
299module_tag := optional
300build_type := target
301build_target := NATIVE_TEST
302include $(LOCAL_PATH)/Android.build.mk
303
304# -----------------------------------------------------------------------------
305# Tests to run on the host and linked against glibc. Run with:
306#   cd bionic/tests; mm bionic-unit-tests-glibc-run
307# -----------------------------------------------------------------------------
308
309ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
310
311bionic-unit-tests-glibc_src_files := \
312    atexit_test.cpp \
313
314bionic-unit-tests-glibc_whole_static_libraries := \
315    libBionicStandardTests \
316
317bionic-unit-tests-glibc_ldlibs := \
318    -lrt -ldl \
319
320bionic-unit-tests-glibc_cflags := $(test_cflags)
321bionic-unit-tests-glibc_cppflags := $(test_cppflags)
322
323module := bionic-unit-tests-glibc
324module_tag := optional
325build_type := host
326build_target := NATIVE_TEST
327include $(LOCAL_PATH)/Android.build.mk
328
329ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm mips x86))
330LINKER = linker64
331NATIVE_TEST_SUFFIX=64
332else
333LINKER = linker
334NATIVE_TEST_SUFFIX=32
335endif
336
337# gtest needs ANDROID_DATA/local/tmp for death test output.
338# Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
339# Use the current target out directory as ANDROID_DATA.
340# BIONIC_TEST_FLAGS is either empty or it comes from the user.
341bionic-unit-tests-glibc-run: bionic-unit-tests-glibc
342	mkdir -p $(TARGET_OUT_DATA)/local/tmp
343	ANDROID_DATA=$(TARGET_OUT_DATA) \
344	ANDROID_ROOT=$(TARGET_OUT) \
345		$(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS)
346
347# -----------------------------------------------------------------------------
348# Run the unit tests built against x86 bionic on an x86 host.
349# -----------------------------------------------------------------------------
350
351ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
352# gtest needs ANDROID_DATA/local/tmp for death test output.
353# Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
354# bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT.
355# BIONIC_TEST_FLAGS is either empty or it comes from the user.
356bionic-unit-tests-run-on-host: bionic-unit-tests $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh
357	if [ ! -d /system -o ! -d /system/bin ]; then \
358	  echo "Attempting to create /system/bin"; \
359	  sudo mkdir -p -m 0777 /system/bin; \
360	fi
361	mkdir -p $(TARGET_OUT_DATA)/local/tmp
362	cp $(TARGET_OUT_EXECUTABLES)/$(LINKER) /system/bin
363	cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin
364	ANDROID_DATA=$(TARGET_OUT_DATA) \
365	ANDROID_ROOT=$(TARGET_OUT) \
366	LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \
367		$(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS)
368endif
369
370ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86_64))
371# add target to run lp32 tests
372bionic-unit-tests-run-on-host32: bionic-unit-tests_32 $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh
373	if [ ! -d /system -o ! -d /system/bin ]; then \
374	  echo "Attempting to create /system/bin"; \
375	  sudo mkdir -p -m 0777 /system/bin; \
376	fi
377	mkdir -p $(TARGET_OUT_DATA)/local/tmp
378	cp $(TARGET_OUT_EXECUTABLES)/linker /system/bin
379	cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin
380	ANDROID_DATA=$(TARGET_OUT_DATA) \
381	ANDROID_ROOT=$(TARGET_OUT) \
382	LD_LIBRARY_PATH=$(2ND_TARGET_OUT_SHARED_LIBRARIES) \
383		$(2ND_TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests32 $(BIONIC_TEST_FLAGS)
384endif
385
386endif # linux-x86
387
388include $(call first-makefiles-under,$(LOCAL_PATH))
389endif # !BUILD_TINY_ANDROID
390