Android.mk revision 5b9310e502003e584bcb3a028ca3db7aa4d3f01b
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    signal_test.cpp \
75    stack_protector_test.cpp \
76    stack_unwinding_test.cpp \
77    statvfs_test.cpp \
78    stdio_test.cpp \
79    stdlib_test.cpp \
80    string_test.cpp \
81    strings_test.cpp \
82    stubs_test.cpp \
83    sys_select_test.cpp \
84    sys_sendfile_test.cpp \
85    sys_stat_test.cpp \
86    system_properties_test.cpp \
87    time_test.cpp \
88    unistd_test.cpp \
89
90test_dynamic_ldflags = -Wl,--export-dynamic -Wl,-u,DlSymTestFunction
91test_dynamic_src_files = \
92    dlfcn_test.cpp \
93
94test_fortify_static_libraries = \
95    fortify1-tests-gcc fortify2-tests-gcc fortify1-tests-clang fortify2-tests-clang
96
97include $(CLEAR_VARS)
98LOCAL_MODULE := bionic-unit-tests-unwind-test-impl
99LOCAL_CFLAGS += $(test_c_flags) -fexceptions -fnon-call-exceptions
100LOCAL_SRC_FILES := stack_unwinding_test_impl.c
101include $(BUILD_STATIC_LIBRARY)
102
103include $(CLEAR_VARS)
104LOCAL_MODULE := bionic-unit-tests-unwind-test-impl-host
105LOCAL_CFLAGS += $(test_c_flags) -fexceptions -fnon-call-exceptions
106LOCAL_SRC_FILES := stack_unwinding_test_impl.c
107include $(BUILD_HOST_STATIC_LIBRARY)
108
109# Build tests for the device (with bionic's .so). Run with:
110#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests
111include $(CLEAR_VARS)
112LOCAL_MODULE := bionic-unit-tests
113LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
114LOCAL_CFLAGS += $(test_c_flags)
115LOCAL_LDFLAGS += $(test_dynamic_ldflags)
116LOCAL_SHARED_LIBRARIES += libdl
117LOCAL_SRC_FILES := $(test_src_files) $(test_dynamic_src_files)
118LOCAL_WHOLE_STATIC_LIBRARIES := $(test_fortify_static_libraries)
119LOCAL_STATIC_LIBRARIES += bionic-unit-tests-unwind-test-impl
120include $(BUILD_NATIVE_TEST)
121
122# Build tests for the device (with bionic's .a). Run with:
123#   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static
124include $(CLEAR_VARS)
125LOCAL_MODULE := bionic-unit-tests-static
126LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
127LOCAL_FORCE_STATIC_EXECUTABLE := true
128LOCAL_WHOLE_STATIC_LIBRARIES += libBionicTests
129LOCAL_STATIC_LIBRARIES += libstlport_static libstdc++ libm libc
130include $(BUILD_NATIVE_TEST)
131
132# -----------------------------------------------------------------------------
133# We build the static unit tests as a library so they can be used both for
134# bionic-unit-tests-static and also as part of CTS.
135# -----------------------------------------------------------------------------
136
137include $(CLEAR_VARS)
138LOCAL_MODULE := libBionicTests
139LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
140LOCAL_CFLAGS += $(test_c_flags)
141LOCAL_SRC_FILES := $(test_src_files)
142LOCAL_CFLAGS += \
143    -DGTEST_OS_LINUX_ANDROID \
144    -DGTEST_HAS_STD_STRING \
145
146LOCAL_C_INCLUDES += \
147    bionic bionic/libstdc++/include \
148    external/gtest/include \
149    external/stlport/stlport \
150
151LOCAL_WHOLE_STATIC_LIBRARIES := \
152    $(test_fortify_static_libraries) \
153    bionic-unit-tests-unwind-test-impl \
154
155include $(BUILD_STATIC_LIBRARY)
156
157# -----------------------------------------------------------------------------
158# Test library for the unit tests.
159# -----------------------------------------------------------------------------
160
161# Build no-elf-hash-table-library.so to test dlopen(3) on a library that
162# only has a GNU-style hash table. MIPS doesn't support GNU hash style.
163ifneq ($(TARGET_ARCH),mips)
164include $(CLEAR_VARS)
165LOCAL_MODULE := no-elf-hash-table-library
166LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
167LOCAL_SRC_FILES := empty.cpp
168LOCAL_LDFLAGS := -Wl,--hash-style=gnu
169include $(BUILD_SHARED_LIBRARY)
170endif
171
172# -----------------------------------------------------------------------------
173# Unit tests built against glibc.
174# -----------------------------------------------------------------------------
175
176# Build tests for the host (with glibc).
177# Note that this will build against glibc, so it's not useful for testing
178# bionic's implementation, but it does let you use glibc as a reference
179# implementation for testing the tests themselves.
180ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
181include $(CLEAR_VARS)
182LOCAL_MODULE := bionic-unit-tests-glibc
183LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
184LOCAL_CFLAGS += $(test_c_flags)
185LOCAL_LDFLAGS += -lpthread -ldl -lrt
186LOCAL_LDFLAGS += $(test_dynamic_ldflags)
187LOCAL_SRC_FILES := $(test_src_files) $(test_dynamic_src_files)
188LOCAL_STATIC_LIBRARIES += bionic-unit-tests-unwind-test-impl-host
189include $(BUILD_HOST_NATIVE_TEST)
190endif
191
192# -----------------------------------------------------------------------------
193# Run the unit tests built against x86 bionic on an x86 host.
194# -----------------------------------------------------------------------------
195
196ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
197ifeq ($(TARGET_ARCH),x86)
198# gtest needs EXTERNAL_STORAGE for death test output.
199# bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT.
200# We create /data/local/tmp to be as much like the regular target environment
201# as possible.
202bionic-unit-tests-run-on-host: bionic-unit-tests $(TARGET_OUT_EXECUTABLES)/linker
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	EXTERNAL_STORAGE=$(TARGET_OUT_DATA)/local/tmp \
209	LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \
210		$(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests
211endif
212endif
213
214# -----------------------------------------------------------------------------
215# FORTIFY_SOURCE tests
216# -----------------------------------------------------------------------------
217
218fortify_c_includes = \
219    bionic \
220    bionic/libstdc++/include \
221    external/stlport/stlport \
222    external/gtest/include
223fortify_test_files = fortify_test.cpp
224
225# -Wno-error=unused-parameter needed as
226# external/stlport/stlport/stl/_threads.c (included from
227# external/gtest/include/gtest/gtest.h) does not compile cleanly under
228# clang. TODO: fix this.
229fortify_c_flags = $(test_c_flags) -Wno-error=unused-parameter
230
231include $(CLEAR_VARS)
232LOCAL_SRC_FILES := $(fortify_test_files)
233LOCAL_MODULE := fortify1-tests-gcc
234LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DTEST_NAME=Fortify1_Gcc
235LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
236LOCAL_C_INCLUDES += $(fortify_c_includes)
237include $(BUILD_STATIC_LIBRARY)
238
239include $(CLEAR_VARS)
240LOCAL_SRC_FILES := $(fortify_test_files)
241LOCAL_MODULE := fortify2-tests-gcc
242LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -DTEST_NAME=Fortify2_Gcc
243LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
244LOCAL_C_INCLUDES += $(fortify_c_includes)
245include $(BUILD_STATIC_LIBRARY)
246
247include $(CLEAR_VARS)
248LOCAL_SRC_FILES := $(fortify_test_files)
249LOCAL_MODULE := fortify1-tests-clang
250LOCAL_CLANG := true
251LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DTEST_NAME=Fortify1_Clang
252LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
253LOCAL_C_INCLUDES += $(fortify_c_includes)
254include $(BUILD_STATIC_LIBRARY)
255
256include $(CLEAR_VARS)
257LOCAL_SRC_FILES := $(fortify_test_files)
258LOCAL_MODULE := fortify2-tests-clang
259LOCAL_CLANG := true
260LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -DTEST_NAME=Fortify2_Clang
261LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
262LOCAL_C_INCLUDES += $(fortify_c_includes)
263include $(BUILD_STATIC_LIBRARY)
264
265endif # !BUILD_TINY_ANDROID
266