OSDN Git Service

Stack unwinding unit tests.
[android-x86/bionic.git] / tests / Android.mk
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
17 ifneq ($(BUILD_TINY_ANDROID),true)
18
19 LOCAL_PATH := $(call my-dir)
20
21 # -----------------------------------------------------------------------------
22 # Unit tests.
23 # -----------------------------------------------------------------------------
24
25 ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
26 build_host := true
27 else
28 build_host := false
29 endif
30
31 # -----------------------------------------------------------------------------
32 # All standard tests.
33 # -----------------------------------------------------------------------------
34 test_cflags = \
35     -fstack-protector-all \
36     -g \
37     -Wall -Wextra -Wunused \
38     -Werror \
39     -fno-builtin \
40
41 test_cflags += -D__STDC_LIMIT_MACROS  # For glibc.
42
43 ifeq ($(MALLOC_IMPL),dlmalloc)
44 test_cflags += -DUSE_DLMALLOC
45 else
46 test_cflags += -DUSE_JEMALLOC
47 endif
48
49 test_cppflags = \
50     -std=gnu++11 \
51
52 libBionicStandardTests_src_files := \
53     arpa_inet_test.cpp \
54     buffer_tests.cpp \
55     ctype_test.cpp \
56     dirent_test.cpp \
57     eventfd_test.cpp \
58     fcntl_test.cpp \
59     fenv_test.cpp \
60     ftw_test.cpp \
61     getauxval_test.cpp \
62     getcwd_test.cpp \
63     inttypes_test.cpp \
64     libc_logging_test.cpp \
65     libgen_test.cpp \
66     locale_test.cpp \
67     malloc_test.cpp \
68     math_cos_test.cpp \
69     math_cosf_test.cpp \
70     math_exp_test.cpp \
71     math_expf_test.cpp \
72     math_log_test.cpp \
73     math_logf_test.cpp \
74     math_pow_test.cpp \
75     math_powf_test.cpp \
76     math_sin_test.cpp \
77     math_sinf_test.cpp \
78     math_sincos_test.cpp \
79     math_sincosf_test.cpp \
80     math_tan_test.cpp \
81     math_tanf_test.cpp \
82     math_test.cpp \
83     mntent_test.cpp \
84     netdb_test.cpp \
85     pthread_test.cpp \
86     regex_test.cpp \
87     sched_test.cpp \
88     search_test.cpp \
89     signal_test.cpp \
90     stack_protector_test.cpp \
91     stdatomic_test.cpp \
92     stdint_test.cpp \
93     stdio_test.cpp \
94     stdlib_test.cpp \
95     string_test.cpp \
96     strings_test.cpp \
97     stubs_test.cpp \
98     sstream_test.cpp \
99     sys_epoll_test.cpp \
100     sys_mman_test.cpp \
101     sys_resource_test.cpp \
102     sys_select_test.cpp \
103     sys_sendfile_test.cpp \
104     sys_socket_test.cpp \
105     sys_stat_test.cpp \
106     sys_statvfs_test.cpp \
107     sys_syscall_test.cpp \
108     sys_time_test.cpp \
109     sys_types_test.cpp \
110     sys_vfs_test.cpp \
111     system_properties_test.cpp \
112     time_test.cpp \
113     uchar_test.cpp \
114     uniqueptr_test.cpp \
115     unistd_test.cpp \
116     wchar_test.cpp \
117
118 libBionicStandardTests_cflags := \
119     $(test_cflags) \
120
121 ifeq ($(MALLOC_IMPL),dlmalloc)
122   libBionicStandardTests_cflags += -DUSE_DLMALLOC
123 else
124   libBionicStandardTests_cflags += -DUSE_JEMALLOC
125 endif
126
127 libBionicStandardTests_cppflags := \
128     $(test_cppflags) \
129
130 libBionicStandardTests_c_includes := \
131     bionic/libc \
132
133 libBionicStandardTests_ldlibs_host := \
134     -lrt \
135
136 module := libBionicStandardTests
137 module_tag := optional
138 build_type := target
139 build_target := STATIC_TEST_LIBRARY
140 include $(LOCAL_PATH)/Android.build.mk
141 build_type := host
142 include $(LOCAL_PATH)/Android.build.mk
143
144 # -----------------------------------------------------------------------------
145 # Fortify tests.
146 # -----------------------------------------------------------------------------
147 $(foreach compiler,gcc clang, \
148   $(foreach test,1 2, \
149     $(eval fortify$(test)-tests-$(compiler)_cflags := \
150       $(test_cflags) \
151       -Wno-error \
152       -U_FORTIFY_SOURCE \
153       -D_FORTIFY_SOURCE=$(test) \
154       -DTEST_NAME=Fortify$(test)_$(compiler)); \
155     $(eval fortify$(test)-tests-$(compiler)_src_files := \
156       fortify_test.cpp); \
157     $(eval fortify_libs += fortify$(test)-tests-$(compiler)); \
158   ) \
159 )
160
161 module := fortify1-tests-gcc
162 module_tag := optional
163 build_type := target
164 build_target := STATIC_TEST_LIBRARY
165 include $(LOCAL_PATH)/Android.build.mk
166 build_type := host
167 include $(LOCAL_PATH)/Android.build.mk
168
169 module := fortify2-tests-gcc
170 module_tag := optional
171 build_type := target
172 build_target := STATIC_TEST_LIBRARY
173 include $(LOCAL_PATH)/Android.build.mk
174 build_type := host
175 include $(LOCAL_PATH)/Android.build.mk
176
177 fortify1-tests-clang_clang_target := true
178 fortify1-tests-clang_cflags_host := -D__clang__
179
180 module := fortify1-tests-clang
181 module_tag := optional
182 build_type := target
183 build_target := STATIC_TEST_LIBRARY
184 include $(LOCAL_PATH)/Android.build.mk
185 build_type := host
186 include $(LOCAL_PATH)/Android.build.mk
187
188 fortify2-tests-clang_clang_target := true
189
190 fortify2-tests-clang_cflags_host := -D__clang__
191
192 module := fortify2-tests-clang
193 module_tag := optional
194 build_type := target
195 build_target := STATIC_TEST_LIBRARY
196 include $(LOCAL_PATH)/Android.build.mk
197 build_type := host
198 include $(LOCAL_PATH)/Android.build.mk
199
200 # -----------------------------------------------------------------------------
201 # Library of all tests (excluding the dynamic linker tests).
202 # -----------------------------------------------------------------------------
203 libBionicTests_whole_static_libraries := \
204     libBionicStandardTests \
205     $(fortify_libs) \
206
207 module := libBionicTests
208 module_tag := optional
209 build_type := target
210 build_target := STATIC_TEST_LIBRARY
211 include $(LOCAL_PATH)/Android.build.mk
212 build_type := host
213 include $(LOCAL_PATH)/Android.build.mk
214
215 # -----------------------------------------------------------------------------
216 # Tests for the device using bionic's .so. Run with:
217 #   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests32
218 #   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests64
219 # -----------------------------------------------------------------------------
220 bionic-unit-tests_whole_static_libraries := \
221     libBionicTests \
222
223 bionic-unit-tests_src_files := \
224     atexit_test.cpp \
225     dlext_test.cpp \
226     dlfcn_test.cpp \
227     stack_unwinding_test.cpp \
228     stack_unwinding_test_impl.c \
229
230 bionic-unit-tests_cflags := $(test_cflags)
231
232 bionic-unit-tests_conlyflags := \
233     -fexceptions \
234     -fnon-call-exceptions \
235
236 bionic-unit-tests_cppflags := $(test_cppflags)
237
238 bionic-unit-tests_ldflags := \
239     -Wl,--export-dynamic \
240     -Wl,-u,DlSymTestFunction \
241
242 bionic-unit-tests_c_includes := \
243     bionic/libc \
244     $(call include-path-for, libpagemap) \
245
246 bionic-unit-tests_shared_libraries_target := \
247     libdl \
248     libpagemap \
249
250 module := bionic-unit-tests
251 module_tag := optional
252 build_type := target
253 build_target := NATIVE_TEST
254 include $(LOCAL_PATH)/Android.build.mk
255
256 # -----------------------------------------------------------------------------
257 # Tests for the device linked against bionic's static library. Run with:
258 #   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static32
259 #   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static64
260 # -----------------------------------------------------------------------------
261 bionic-unit-tests-static_whole_static_libraries := \
262     libBionicTests \
263
264 bionic-unit-tests-static_static_libraries := \
265     libstlport_static \
266     libm \
267     libc \
268     libstdc++ \
269
270 bionic-unit-tests-static_force_static_executable := true
271
272 module := bionic-unit-tests-static
273 module_tag := optional
274 build_type := target
275 build_target := NATIVE_TEST
276 include $(LOCAL_PATH)/Android.build.mk
277
278 # -----------------------------------------------------------------------------
279 # Tests to run on the host and linked against glibc. Run with:
280 #   cd bionic/tests; mm bionic-unit-tests-glibc-run
281 # -----------------------------------------------------------------------------
282
283 ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
284
285 bionic-unit-tests-glibc_src_files := \
286     atexit_test.cpp \
287
288 bionic-unit-tests-glibc_whole_static_libraries := \
289     libBionicStandardTests \
290
291 bionic-unit-tests-glibc_ldlibs := \
292     -lrt -ldl \
293
294 bionic-unit-tests-glibc_cflags := $(test_cflags)
295 bionic-unit-tests-glibc_cppflags := $(test_cppflags)
296
297 module := bionic-unit-tests-glibc
298 module_tag := optional
299 build_type := host
300 build_target := NATIVE_TEST
301 include $(LOCAL_PATH)/Android.build.mk
302
303 ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm mips x86))
304 LINKER = linker64
305 NATIVE_TEST_SUFFIX=64
306 else
307 LINKER = linker
308 NATIVE_TEST_SUFFIX=32
309 endif
310
311 # gtest needs ANDROID_DATA/local/tmp for death test output.
312 # Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
313 # Use the current target out directory as ANDROID_DATA.
314 # BIONIC_TEST_FLAGS is either empty or it comes from the user.
315 bionic-unit-tests-glibc-run: bionic-unit-tests-glibc
316         mkdir -p $(TARGET_OUT_DATA)/local/tmp
317         ANDROID_DATA=$(TARGET_OUT_DATA) \
318         ANDROID_ROOT=$(TARGET_OUT) \
319                 $(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS)
320
321 # -----------------------------------------------------------------------------
322 # Run the unit tests built against x86 bionic on an x86 host.
323 # -----------------------------------------------------------------------------
324
325 ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
326 # gtest needs ANDROID_DATA/local/tmp for death test output.
327 # Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
328 # bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT.
329 # BIONIC_TEST_FLAGS is either empty or it comes from the user.
330 bionic-unit-tests-run-on-host: bionic-unit-tests $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh
331         if [ ! -d /system -o ! -d /system/bin ]; then \
332           echo "Attempting to create /system/bin"; \
333           sudo mkdir -p -m 0777 /system/bin; \
334         fi
335         mkdir -p $(TARGET_OUT_DATA)/local/tmp
336         cp $(TARGET_OUT_EXECUTABLES)/$(LINKER) /system/bin
337         cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin
338         ANDROID_DATA=$(TARGET_OUT_DATA) \
339         ANDROID_ROOT=$(TARGET_OUT) \
340         LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \
341                 $(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS)
342 endif
343
344 ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86_64))
345 # add target to run lp32 tests
346 bionic-unit-tests-run-on-host32: bionic-unit-tests_32 $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh
347         if [ ! -d /system -o ! -d /system/bin ]; then \
348           echo "Attempting to create /system/bin"; \
349           sudo mkdir -p -m 0777 /system/bin; \
350         fi
351         mkdir -p $(TARGET_OUT_DATA)/local/tmp
352         cp $(TARGET_OUT_EXECUTABLES)/linker /system/bin
353         cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin
354         ANDROID_DATA=$(TARGET_OUT_DATA) \
355         ANDROID_ROOT=$(TARGET_OUT) \
356         LD_LIBRARY_PATH=$(2ND_TARGET_OUT_SHARED_LIBRARIES) \
357                 $(2ND_TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests32 $(BIONIC_TEST_FLAGS)
358 endif
359
360 endif # linux-x86
361
362 include $(call first-makefiles-under,$(LOCAL_PATH))
363 endif # !BUILD_TINY_ANDROID