Android.mk revision e6c57fcb05b0dcbfa8129bb6f7d99093f4819370
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
43ifeq ($(MALLOC_IMPL),jemalloc)
44test_cflags += -DUSE_JEMALLOC
45endif
46
47test_cppflags = \
48    -std=gnu++11 \
49
50libBionicStandardTests_src_files := \
51    arpa_inet_test.cpp \
52    buffer_tests.cpp \
53    ctype_test.cpp \
54    dirent_test.cpp \
55    eventfd_test.cpp \
56    fcntl_test.cpp \
57    fenv_test.cpp \
58    ftw_test.cpp \
59    getauxval_test.cpp \
60    getcwd_test.cpp \
61    inttypes_test.cpp \
62    libc_logging_test.cpp \
63    libgen_test.cpp \
64    locale_test.cpp \
65    malloc_test.cpp \
66    math_cos_test.cpp \
67    math_cosf_test.cpp \
68    math_exp_test.cpp \
69    math_expf_test.cpp \
70    math_log_test.cpp \
71    math_logf_test.cpp \
72    math_pow_test.cpp \
73    math_powf_test.cpp \
74    math_sin_test.cpp \
75    math_sinf_test.cpp \
76    math_sincos_test.cpp \
77    math_sincosf_test.cpp \
78    math_tan_test.cpp \
79    math_tanf_test.cpp \
80    math_test.cpp \
81    mntent_test.cpp \
82    netdb_test.cpp \
83    pthread_test.cpp \
84    regex_test.cpp \
85    sched_test.cpp \
86    signal_test.cpp \
87    stack_protector_test.cpp \
88    stack_unwinding_test.cpp \
89    stack_unwinding_test_impl.c \
90    stdatomic_test.cpp \
91    stdint_test.cpp \
92    stdio_test.cpp \
93    stdlib_test.cpp \
94    string_test.cpp \
95    strings_test.cpp \
96    stubs_test.cpp \
97    sstream_test.cpp \
98    sys_epoll_test.cpp \
99    sys_mman_test.cpp \
100    sys_resource_test.cpp \
101    sys_select_test.cpp \
102    sys_sendfile_test.cpp \
103    sys_socket_test.cpp \
104    sys_stat_test.cpp \
105    sys_statvfs_test.cpp \
106    sys_syscall_test.cpp \
107    sys_time_test.cpp \
108    sys_types_test.cpp \
109    sys_vfs_test.cpp \
110    system_properties_test.cpp \
111    time_test.cpp \
112    unistd_test.cpp \
113    wchar_test.cpp \
114
115libBionicStandardTests_cflags := \
116    $(test_cflags) \
117
118libBionicStandardTests_cppflags := \
119    $(test_cppflags) \
120
121libBionicStandardTests_ldlibs_host := \
122    -lrt \
123
124module := libBionicStandardTests
125module_tag := optional
126build_type := target
127build_target := STATIC_TEST_LIBRARY
128include $(LOCAL_PATH)/Android.build.mk
129build_type := host
130include $(LOCAL_PATH)/Android.build.mk
131
132# -----------------------------------------------------------------------------
133# Fortify tests.
134# -----------------------------------------------------------------------------
135$(foreach compiler,gcc clang, \
136  $(foreach test,1 2, \
137    $(eval fortify$(test)-tests-$(compiler)_cflags := \
138      $(test_cflags) \
139      -U_FORTIFY_SOURCE \
140      -D_FORTIFY_SOURCE=$(test) \
141      -DTEST_NAME=Fortify$(test)_$(compiler)); \
142    $(eval fortify$(test)-tests-$(compiler)_cflags_host := \
143      -Wno-error); \
144    $(eval fortify$(test)-tests-$(compiler)_src_files := \
145      fortify_test.cpp); \
146    $(eval fortify_libs += fortify$(test)-tests-$(compiler)); \
147  ) \
148)
149
150module := fortify1-tests-gcc
151module_tag := optional
152build_type := target
153build_target := STATIC_TEST_LIBRARY
154include $(LOCAL_PATH)/Android.build.mk
155build_type := host
156include $(LOCAL_PATH)/Android.build.mk
157
158module := fortify2-tests-gcc
159module_tag := optional
160build_type := target
161build_target := STATIC_TEST_LIBRARY
162include $(LOCAL_PATH)/Android.build.mk
163build_type := host
164include $(LOCAL_PATH)/Android.build.mk
165
166fortify1-tests-clang_clang_target := true
167fortify1-tests-clang_cflags_host := -D__clang__
168
169module := fortify1-tests-clang
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
177fortify2-tests-clang_clang_target := true
178
179fortify2-tests-clang_cflags_host := -D__clang__
180
181module := fortify2-tests-clang
182module_tag := optional
183build_type := target
184build_target := STATIC_TEST_LIBRARY
185include $(LOCAL_PATH)/Android.build.mk
186build_type := host
187include $(LOCAL_PATH)/Android.build.mk
188
189# -----------------------------------------------------------------------------
190# Library of all tests (excluding the dynamic linker tests).
191# -----------------------------------------------------------------------------
192libBionicTests_whole_static_libraries := \
193    libBionicStandardTests \
194    $(fortify_libs) \
195
196module := libBionicTests
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
204# -----------------------------------------------------------------------------
205# Library used by dlfcn tests.
206# -----------------------------------------------------------------------------
207ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),mips mips64))
208no-elf-hash-table-library_src_files := \
209    empty.cpp \
210
211no-elf-hash-table-library_ldflags := \
212    -Wl,--hash-style=gnu \
213
214module := no-elf-hash-table-library
215module_tag := optional
216build_type := target
217build_target := SHARED_LIBRARY
218include $(LOCAL_PATH)/Android.build.mk
219endif
220
221# -----------------------------------------------------------------------------
222# Library used by dlext tests - with/without GNU RELRO program header
223# -----------------------------------------------------------------------------
224libdlext_test_src_files := \
225    dlext_test_library.cpp \
226
227libdlext_test_ldflags := \
228    -Wl,-z,relro \
229
230module := libdlext_test
231module_tag := optional
232build_type := target
233build_target := SHARED_LIBRARY
234include $(LOCAL_PATH)/Android.build.mk
235
236# -----------------------------------------------------------------------------
237# create symlink to libdlext_test.so for symlink test
238# -----------------------------------------------------------------------------
239libdlext_origin := $(LOCAL_INSTALLED_MODULE)
240libdlext_sym := $(subst libdlext_test,libdlext_test_v2,$(libdlext_origin))
241$(libdlext_sym): $(libdlext_origin)
242	@echo "Symlink: $@ -> $(notdir $<)"
243	@mkdir -p $(dir $@)
244	$(hide) ln -sf $(notdir $<) $@
245
246ALL_MODULES := \
247  $(ALL_MODULES) $(libdlext_sym)
248
249ifneq ($(TARGET_2ND_ARCH),)
250# link 64 bit .so
251libdlext_origin := $(TARGET_OUT)/lib64/libdlext_test.so
252libdlext_sym := $(subst libdlext_test,libdlext_test_v2,$(libdlext_origin))
253$(libdlext_sym): $(libdlext_origin)
254	@echo "Symlink: $@ -> $(notdir $<)"
255	@mkdir -p $(dir $@)
256	$(hide) ln -sf $(notdir $<) $@
257
258ALL_MODULES := \
259  $(ALL_MODULES) $(libdlext_sym)
260endif
261
262libdlext_test_norelro_src_files := \
263    dlext_test_library.cpp \
264
265libdlext_test_norelro_ldflags := \
266    -Wl,-z,norelro \
267
268module := libdlext_test_norelro
269module_tag := optional
270build_type := target
271build_target := SHARED_LIBRARY
272include $(LOCAL_PATH)/Android.build.mk
273
274# -----------------------------------------------------------------------------
275# Library used by dlfcn tests
276# -----------------------------------------------------------------------------
277libtest_simple_src_files := \
278    dlopen_testlib_simple.cpp
279
280module := libtest_simple
281build_type := target
282build_target := SHARED_LIBRARY
283include $(LOCAL_PATH)/Android.build.mk
284
285
286# -----------------------------------------------------------------------------
287# Library used by atexit tests
288# -----------------------------------------------------------------------------
289
290libtest_atexit_src_files := \
291    atexit_testlib.cpp
292
293module := libtest_atexit
294build_type := target
295build_target := SHARED_LIBRARY
296include $(LOCAL_PATH)/Android.build.mk
297
298# -----------------------------------------------------------------------------
299# Tests for the device using bionic's .so. Run with:
300#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests
301# -----------------------------------------------------------------------------
302bionic-unit-tests_whole_static_libraries := \
303    libBionicTests \
304
305bionic-unit-tests_src_files := \
306    atexit_test.cpp \
307    dlext_test.cpp \
308    dlfcn_test.cpp \
309
310bionic-unit-tests_cppflags := \
311    $(test_cppflags)
312
313bionic-unit-tests_ldflags := \
314    -Wl,--export-dynamic \
315    -Wl,-u,DlSymTestFunction \
316
317bionic-unit-tests_c_includes := \
318    $(call include-path-for, libpagemap) \
319
320bionic-unit-tests_shared_libraries_target := \
321    libdl \
322    libpagemap \
323
324module := bionic-unit-tests
325module_tag := optional
326bionic-unit-tests_multilib := both
327build_type := target
328build_target := NATIVE_TEST
329include $(LOCAL_PATH)/Android.build.mk
330
331# -----------------------------------------------------------------------------
332# Tests for the device linked against bionic's static library. Run with:
333#   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static
334# -----------------------------------------------------------------------------
335bionic-unit-tests-static_whole_static_libraries := \
336    libBionicTests \
337
338bionic-unit-tests-static_static_libraries := \
339    libstlport_static \
340    libm \
341    libc \
342    libstdc++ \
343
344bionic-unit-tests-static_force_static_executable := true
345
346module := bionic-unit-tests-static
347module_tag := optional
348bionic-unit-tests-static_multilib := both
349build_type := target
350build_target := NATIVE_TEST
351include $(LOCAL_PATH)/Android.build.mk
352
353# -----------------------------------------------------------------------------
354# Tests to run on the host and linked against glibc. Run with:
355#   cd bionic/tests; mm bionic-unit-tests-glibc-run
356# -----------------------------------------------------------------------------
357
358ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
359
360bionic-unit-tests-glibc_src_files := \
361    atexit_test.cpp \
362
363bionic-unit-tests-glibc_whole_static_libraries := \
364    libBionicStandardTests \
365
366bionic-unit-tests-glibc_ldlibs := \
367    -lrt -ldl \
368
369bionic-unit-tests-glibc_cppflags := \
370    $(test_cppflags)
371
372module := bionic-unit-tests-glibc
373module_tag := optional
374bionic-unit-tests-glibc_multilib := both
375build_type := host
376build_target := NATIVE_TEST
377include $(LOCAL_PATH)/Android.build.mk
378
379ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm mips x86))
380LINKER = linker64
381NATIVE_TEST_SUFFIX=64
382else
383LINKER = linker
384NATIVE_TEST_SUFFIX=32
385endif
386
387# gtest needs ANDROID_DATA/local/tmp for death test output.
388# Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
389# Use the current target out directory as ANDROID_DATA.
390# BIONIC_TEST_FLAGS is either empty or it comes from the user.
391bionic-unit-tests-glibc-run: bionic-unit-tests-glibc
392	mkdir -p $(TARGET_OUT_DATA)/local/tmp
393	ANDROID_DATA=$(TARGET_OUT_DATA) \
394	ANDROID_ROOT=$(TARGET_OUT) \
395		$(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS)
396
397# -----------------------------------------------------------------------------
398# Run the unit tests built against x86 bionic on an x86 host.
399# -----------------------------------------------------------------------------
400
401ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
402# gtest needs ANDROID_DATA/local/tmp for death test output.
403# Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
404# bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT.
405# BIONIC_TEST_FLAGS is either empty or it comes from the user.
406bionic-unit-tests-run-on-host: bionic-unit-tests $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh
407	if [ ! -d /system -o ! -d /system/bin ]; then \
408	  echo "Attempting to create /system/bin"; \
409	  sudo mkdir -p -m 0777 /system/bin; \
410	fi
411	mkdir -p $(TARGET_OUT_DATA)/local/tmp
412	cp $(TARGET_OUT_EXECUTABLES)/$(LINKER) /system/bin
413	cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin
414	ANDROID_DATA=$(TARGET_OUT_DATA) \
415	ANDROID_ROOT=$(TARGET_OUT) \
416	LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \
417		$(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS)
418endif
419
420endif # linux-x86
421
422endif # !BUILD_TINY_ANDROID
423