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 #
17 ifneq ($(BUILD_TINY_ANDROID), true)
19 LOCAL_PATH := $(call my-dir)
21 # -----------------------------------------------------------------------------
22 # Benchmarks.
23 # -----------------------------------------------------------------------------
25 benchmark_c_flags = \
26 -O2 \
27 -Wall -Wextra \
28 -Werror \
29 -fno-builtin \
31 benchmark_src_files = \
32 benchmark_main.cpp \
33 math_benchmark.cpp \
34 property_benchmark.cpp \
35 string_benchmark.cpp \
36 time_benchmark.cpp \
38 # Build benchmarks for the device (with bionic's .so). Run with:
39 # adb shell bionic-benchmarks
40 include $(CLEAR_VARS)
41 LOCAL_MODULE := bionic-benchmarks
42 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
43 LOCAL_CFLAGS += $(benchmark_c_flags)
44 LOCAL_C_INCLUDES += external/stlport/stlport bionic/ bionic/libstdc++/include
45 LOCAL_SHARED_LIBRARIES += libstlport
46 LOCAL_SRC_FILES := $(benchmark_src_files)
47 include $(BUILD_EXECUTABLE)
49 # -----------------------------------------------------------------------------
50 # Unit tests.
51 # -----------------------------------------------------------------------------
53 test_c_flags = \
54 -fstack-protector-all \
55 -g \
56 -Wall -Wextra \
57 -Werror \
58 -fno-builtin \
60 test_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 \
90 test_dynamic_ldflags = -Wl,--export-dynamic -Wl,-u,DlSymTestFunction
91 test_dynamic_src_files = \
92 dlfcn_test.cpp \
94 test_fortify_static_libraries = \
95 fortify1-tests-gcc fortify2-tests-gcc fortify1-tests-clang fortify2-tests-clang
97 include $(CLEAR_VARS)
98 LOCAL_MODULE := bionic-unit-tests-unwind-test-impl
99 LOCAL_CFLAGS += $(test_c_flags) -fexceptions -fnon-call-exceptions
100 LOCAL_SRC_FILES := stack_unwinding_test_impl.c
101 include $(BUILD_STATIC_LIBRARY)
103 include $(CLEAR_VARS)
104 LOCAL_MODULE := bionic-unit-tests-unwind-test-impl-host
105 LOCAL_CFLAGS += $(test_c_flags) -fexceptions -fnon-call-exceptions
106 LOCAL_SRC_FILES := stack_unwinding_test_impl.c
107 include $(BUILD_HOST_STATIC_LIBRARY)
109 # Build tests for the device (with bionic's .so). Run with:
110 # adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests
111 include $(CLEAR_VARS)
112 LOCAL_MODULE := bionic-unit-tests
113 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
114 LOCAL_CFLAGS += $(test_c_flags)
115 LOCAL_LDFLAGS += $(test_dynamic_ldflags)
116 LOCAL_SHARED_LIBRARIES += libdl
117 LOCAL_SRC_FILES := $(test_src_files) $(test_dynamic_src_files)
118 LOCAL_WHOLE_STATIC_LIBRARIES := $(test_fortify_static_libraries)
119 LOCAL_STATIC_LIBRARIES += bionic-unit-tests-unwind-test-impl
120 include $(BUILD_NATIVE_TEST)
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
124 include $(CLEAR_VARS)
125 LOCAL_MODULE := bionic-unit-tests-static
126 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
127 LOCAL_FORCE_STATIC_EXECUTABLE := true
128 LOCAL_WHOLE_STATIC_LIBRARIES += libBionicTests
129 LOCAL_STATIC_LIBRARIES += libstlport_static libstdc++ libm libc
130 include $(BUILD_NATIVE_TEST)
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 # -----------------------------------------------------------------------------
137 include $(CLEAR_VARS)
138 LOCAL_MODULE := libBionicTests
139 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
140 LOCAL_CFLAGS += $(test_c_flags)
141 LOCAL_SRC_FILES := $(test_src_files)
142 LOCAL_CFLAGS += \
143 -DGTEST_OS_LINUX_ANDROID \
144 -DGTEST_HAS_STD_STRING \
146 LOCAL_C_INCLUDES += \
147 bionic bionic/libstdc++/include \
148 external/gtest/include \
149 external/stlport/stlport \
151 LOCAL_WHOLE_STATIC_LIBRARIES := \
152 $(test_fortify_static_libraries) \
153 bionic-unit-tests-unwind-test-impl \
155 include $(BUILD_STATIC_LIBRARY)
157 # -----------------------------------------------------------------------------
158 # Test library for the unit tests.
159 # -----------------------------------------------------------------------------
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.
163 ifneq ($(TARGET_ARCH),mips)
164 include $(CLEAR_VARS)
165 LOCAL_MODULE := no-elf-hash-table-library
166 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
167 LOCAL_SRC_FILES := empty.cpp
168 LOCAL_LDFLAGS := -Wl,--hash-style=gnu
169 include $(BUILD_SHARED_LIBRARY)
170 endif
172 # -----------------------------------------------------------------------------
173 # Unit tests built against glibc.
174 # -----------------------------------------------------------------------------
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.
180 ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
181 include $(CLEAR_VARS)
182 LOCAL_MODULE := bionic-unit-tests-glibc
183 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
184 LOCAL_CFLAGS += $(test_c_flags)
185 LOCAL_LDFLAGS += -lpthread -ldl -lrt
186 LOCAL_LDFLAGS += $(test_dynamic_ldflags)
187 LOCAL_SRC_FILES := $(test_src_files) $(test_dynamic_src_files)
188 LOCAL_STATIC_LIBRARIES += bionic-unit-tests-unwind-test-impl-host
189 include $(BUILD_HOST_NATIVE_TEST)
190 endif
192 # -----------------------------------------------------------------------------
193 # Run the unit tests built against x86 bionic on an x86 host.
194 # -----------------------------------------------------------------------------
196 ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
197 ifeq ($(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.
202 bionic-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
211 endif
212 endif
214 # -----------------------------------------------------------------------------
215 # FORTIFY_SOURCE tests
216 # -----------------------------------------------------------------------------
218 fortify_c_includes = \
219 bionic \
220 bionic/libstdc++/include \
221 external/stlport/stlport \
222 external/gtest/include
223 fortify_test_files = fortify_test.cpp
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.
229 fortify_c_flags = $(test_c_flags) -Wno-error=unused-parameter
231 include $(CLEAR_VARS)
232 LOCAL_SRC_FILES := $(fortify_test_files)
233 LOCAL_MODULE := fortify1-tests-gcc
234 LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DTEST_NAME=Fortify1_Gcc
235 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
236 LOCAL_C_INCLUDES += $(fortify_c_includes)
237 include $(BUILD_STATIC_LIBRARY)
239 include $(CLEAR_VARS)
240 LOCAL_SRC_FILES := $(fortify_test_files)
241 LOCAL_MODULE := fortify2-tests-gcc
242 LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -DTEST_NAME=Fortify2_Gcc
243 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
244 LOCAL_C_INCLUDES += $(fortify_c_includes)
245 include $(BUILD_STATIC_LIBRARY)
247 include $(CLEAR_VARS)
248 LOCAL_SRC_FILES := $(fortify_test_files)
249 LOCAL_MODULE := fortify1-tests-clang
250 LOCAL_CLANG := true
251 LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DTEST_NAME=Fortify1_Clang
252 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
253 LOCAL_C_INCLUDES += $(fortify_c_includes)
254 include $(BUILD_STATIC_LIBRARY)
256 include $(CLEAR_VARS)
257 LOCAL_SRC_FILES := $(fortify_test_files)
258 LOCAL_MODULE := fortify2-tests-clang
259 LOCAL_CLANG := true
260 LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -DTEST_NAME=Fortify2_Clang
261 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
262 LOCAL_C_INCLUDES += $(fortify_c_includes)
263 include $(BUILD_STATIC_LIBRARY)
265 endif # !BUILD_TINY_ANDROID