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