Android.mk revision e7c59f9e2041812c597ff1c8689d47d1bfd32883
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
25test_c_flags = \
26    -fstack-protector-all \
27    -g \
28    -Wall -Wextra \
29    -Werror \
30    -fno-builtin \
31
32ifeq ($(TARGET_ARCH),aarch64)
33  $(info TODO: $(LOCAL_PATH)/Android.mk -fstack-protector not yet available for the AArch64 toolchain)
34  test_c_flags += -fno-stack-protector
35endif # aarch64
36
37test_src_files = \
38    buffer_tests.cpp \
39    dirent_test.cpp \
40    eventfd_test.cpp \
41    fcntl_test.cpp \
42    fenv_test.cpp \
43    getauxval_test.cpp \
44    getcwd_test.cpp \
45    inttypes_test.cpp \
46    libc_logging_test.cpp \
47    libgen_test.cpp \
48    malloc_test.cpp \
49    math_test.cpp \
50    netdb_test.cpp \
51    pthread_test.cpp \
52    regex_test.cpp \
53    sched_test.cpp \
54    signal_test.cpp \
55    stack_protector_test.cpp \
56    stack_unwinding_test.cpp \
57    statvfs_test.cpp \
58    stdio_test.cpp \
59    stdlib_test.cpp \
60    string_test.cpp \
61    strings_test.cpp \
62    stubs_test.cpp \
63    sys_epoll_test.cpp \
64    sys_select_test.cpp \
65    sys_sendfile_test.cpp \
66    sys_stat_test.cpp \
67    sys_syscall_test.cpp \
68    sys_time_test.cpp \
69    system_properties_test.cpp \
70    time_test.cpp \
71    unistd_test.cpp \
72
73test_dynamic_ldflags = -Wl,--export-dynamic -Wl,-u,DlSymTestFunction
74test_dynamic_src_files = \
75    dlfcn_test.cpp \
76
77test_fortify_static_libraries = \
78    fortify1-tests-gcc fortify2-tests-gcc fortify1-tests-clang fortify2-tests-clang
79
80include $(CLEAR_VARS)
81LOCAL_MODULE := bionic-unit-tests-unwind-test-impl
82LOCAL_CFLAGS += $(test_c_flags) -fexceptions -fnon-call-exceptions
83LOCAL_SRC_FILES := stack_unwinding_test_impl.c
84include $(BUILD_STATIC_LIBRARY)
85
86include $(CLEAR_VARS)
87LOCAL_MODULE := bionic-unit-tests-unwind-test-impl-host
88LOCAL_CFLAGS += $(test_c_flags) -fexceptions -fnon-call-exceptions
89LOCAL_SRC_FILES := stack_unwinding_test_impl.c
90include $(BUILD_HOST_STATIC_LIBRARY)
91
92# Build tests for the device (with bionic's .so). Run with:
93#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests
94include $(CLEAR_VARS)
95LOCAL_MODULE := bionic-unit-tests
96LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
97LOCAL_CFLAGS += $(test_c_flags)
98LOCAL_LDFLAGS += $(test_dynamic_ldflags)
99LOCAL_SHARED_LIBRARIES += libdl
100LOCAL_SRC_FILES := $(test_src_files) $(test_dynamic_src_files)
101LOCAL_WHOLE_STATIC_LIBRARIES := $(test_fortify_static_libraries)
102LOCAL_STATIC_LIBRARIES += bionic-unit-tests-unwind-test-impl
103include $(BUILD_NATIVE_TEST)
104
105# Build tests for the device (with bionic's .a). Run with:
106#   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static
107include $(CLEAR_VARS)
108LOCAL_MODULE := bionic-unit-tests-static
109LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
110LOCAL_FORCE_STATIC_EXECUTABLE := true
111LOCAL_WHOLE_STATIC_LIBRARIES += libBionicTests
112LOCAL_STATIC_LIBRARIES += libstlport_static libstdc++ libm libc
113include $(BUILD_NATIVE_TEST)
114
115# -----------------------------------------------------------------------------
116# We build the static unit tests as a library so they can be used both for
117# bionic-unit-tests-static and also as part of CTS.
118# -----------------------------------------------------------------------------
119
120include $(CLEAR_VARS)
121LOCAL_MODULE := libBionicTests
122LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
123LOCAL_CFLAGS += $(test_c_flags)
124LOCAL_SRC_FILES := $(test_src_files)
125LOCAL_CFLAGS += \
126    -DGTEST_OS_LINUX_ANDROID \
127    -DGTEST_HAS_STD_STRING \
128
129LOCAL_C_INCLUDES += \
130    bionic bionic/libstdc++/include \
131    external/gtest/include \
132    external/stlport/stlport \
133
134LOCAL_WHOLE_STATIC_LIBRARIES := \
135    $(test_fortify_static_libraries) \
136    bionic-unit-tests-unwind-test-impl \
137
138include $(BUILD_STATIC_LIBRARY)
139
140# -----------------------------------------------------------------------------
141# Test library for the unit tests.
142# -----------------------------------------------------------------------------
143
144# Build no-elf-hash-table-library.so to test dlopen(3) on a library that
145# only has a GNU-style hash table. MIPS doesn't support GNU hash style.
146ifneq ($(TARGET_ARCH),mips)
147include $(CLEAR_VARS)
148LOCAL_MODULE := no-elf-hash-table-library
149LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
150LOCAL_SRC_FILES := empty.cpp
151LOCAL_LDFLAGS := -Wl,--hash-style=gnu
152include $(BUILD_SHARED_LIBRARY)
153endif
154
155# -----------------------------------------------------------------------------
156# Unit tests built against glibc.
157# -----------------------------------------------------------------------------
158
159# Build tests for the host (with glibc).
160# Note that this will build against glibc, so it's not useful for testing
161# bionic's implementation, but it does let you use glibc as a reference
162# implementation for testing the tests themselves.
163ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
164include $(CLEAR_VARS)
165LOCAL_MODULE := bionic-unit-tests-glibc
166LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
167LOCAL_CFLAGS += $(test_c_flags)
168LOCAL_LDFLAGS += -lpthread -ldl -lrt
169LOCAL_LDFLAGS += $(test_dynamic_ldflags)
170LOCAL_SRC_FILES := $(test_src_files) $(test_dynamic_src_files)
171LOCAL_STATIC_LIBRARIES += bionic-unit-tests-unwind-test-impl-host
172include $(BUILD_HOST_NATIVE_TEST)
173
174# gtest needs ANDROID_DATA/local/tmp for death test output.
175# Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
176# Use the current target out directory as ANDROID_DATA.
177bionic-unit-tests-glibc-run: bionic-unit-tests-glibc
178	mkdir -p $(TARGET_OUT_DATA)/local/tmp
179	ANDROID_DATA=$(TARGET_OUT_DATA) \
180	ANDROID_ROOT=$(TARGET_OUT) \
181		$(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc
182endif
183
184# -----------------------------------------------------------------------------
185# Run the unit tests built against x86 bionic on an x86 host.
186# -----------------------------------------------------------------------------
187
188ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
189ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
190ifeq ($(TARGET_ARCH),x86)
191LINKER = linker
192else
193LINKER = linker64
194endif
195# gtest needs ANDROID_DATA/local/tmp for death test output.
196# Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
197# bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT.
198bionic-unit-tests-run-on-host: bionic-unit-tests $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh
199	if [ ! -d /system -o ! -d /system/bin ]; then \
200	  echo "Attempting to create /system/bin"; \
201	  sudo mkdir -p -m 0777 /system/bin; \
202	fi
203	mkdir -p $(TARGET_OUT_DATA)/local/tmp
204	cp $(TARGET_OUT_EXECUTABLES)/$(LINKER) /system/bin
205	cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin
206	ANDROID_DATA=$(TARGET_OUT_DATA) \
207	ANDROID_ROOT=$(TARGET_OUT) \
208	LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \
209		$(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests
210endif
211endif
212
213# -----------------------------------------------------------------------------
214# FORTIFY_SOURCE tests
215# -----------------------------------------------------------------------------
216
217fortify_c_includes = \
218    bionic \
219    bionic/libstdc++/include \
220    external/stlport/stlport \
221    external/gtest/include
222fortify_test_files = fortify_test.cpp
223
224# -Wno-error=unused-parameter needed as
225# external/stlport/stlport/stl/_threads.c (included from
226# external/gtest/include/gtest/gtest.h) does not compile cleanly under
227# clang. TODO: fix this.
228fortify_c_flags = $(test_c_flags) -Wno-error=unused-parameter
229
230include $(CLEAR_VARS)
231LOCAL_SRC_FILES := $(fortify_test_files)
232LOCAL_MODULE := fortify1-tests-gcc
233LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DTEST_NAME=Fortify1_Gcc
234LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
235LOCAL_C_INCLUDES += $(fortify_c_includes)
236include $(BUILD_STATIC_LIBRARY)
237
238include $(CLEAR_VARS)
239LOCAL_SRC_FILES := $(fortify_test_files)
240LOCAL_MODULE := fortify2-tests-gcc
241LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -DTEST_NAME=Fortify2_Gcc
242LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
243LOCAL_C_INCLUDES += $(fortify_c_includes)
244include $(BUILD_STATIC_LIBRARY)
245
246include $(CLEAR_VARS)
247LOCAL_SRC_FILES := $(fortify_test_files)
248LOCAL_MODULE := fortify1-tests-clang
249LOCAL_CLANG := true
250LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DTEST_NAME=Fortify1_Clang
251LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
252LOCAL_C_INCLUDES += $(fortify_c_includes)
253include $(BUILD_STATIC_LIBRARY)
254
255include $(CLEAR_VARS)
256LOCAL_SRC_FILES := $(fortify_test_files)
257LOCAL_MODULE := fortify2-tests-clang
258LOCAL_CLANG := true
259LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -DTEST_NAME=Fortify2_Clang
260LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
261LOCAL_C_INCLUDES += $(fortify_c_includes)
262include $(BUILD_STATIC_LIBRARY)
263
264endif # !BUILD_TINY_ANDROID
265