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