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