Android.mk revision 5058a005b8dfb4bd5eefe0eb4420f1c37665b2b0
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
17LOCAL_PATH := $(call my-dir)
18
19# -----------------------------------------------------------------------------
20# Unit tests.
21# -----------------------------------------------------------------------------
22
23ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
24build_host := true
25else
26build_host := false
27endif
28
29common_additional_dependencies := $(LOCAL_PATH)/Android.mk $(LOCAL_PATH)/Android.build.mk
30
31# -----------------------------------------------------------------------------
32# All standard tests.
33# -----------------------------------------------------------------------------
34test_cflags = \
35    -fstack-protector-all \
36    -g \
37    -Wall -Wextra -Wunused \
38    -Werror \
39    -fno-builtin \
40
41test_cflags += -D__STDC_LIMIT_MACROS  # For glibc.
42
43ifeq ($(MALLOC_IMPL),dlmalloc)
44test_cflags += -DUSE_DLMALLOC
45else
46test_cflags += -DUSE_JEMALLOC
47endif
48
49test_cppflags := \
50
51libBionicStandardTests_src_files := \
52    arpa_inet_test.cpp \
53    buffer_tests.cpp \
54    complex_test.cpp \
55    ctype_test.cpp \
56    dirent_test.cpp \
57    error_test.cpp \
58    eventfd_test.cpp \
59    fcntl_test.cpp \
60    fenv_test.cpp \
61    ftw_test.cpp \
62    getauxval_test.cpp \
63    getcwd_test.cpp \
64    inttypes_test.cpp \
65    libc_logging_test.cpp \
66    libgen_basename_test.cpp \
67    libgen_test.cpp \
68    locale_test.cpp \
69    malloc_test.cpp \
70    math_test.cpp \
71    mntent_test.cpp \
72    netdb_test.cpp \
73    netinet_udp_test.cpp \
74    pthread_test.cpp \
75    pty_test.cpp \
76    regex_test.cpp \
77    sched_test.cpp \
78    search_test.cpp \
79    semaphore_test.cpp \
80    setjmp_test.cpp \
81    signal_test.cpp \
82    stack_protector_test.cpp \
83    stack_unwinding_test.cpp \
84    stdatomic_test.cpp \
85    stdint_test.cpp \
86    stdio_test.cpp \
87    stdio_ext_test.cpp \
88    stdlib_test.cpp \
89    string_test.cpp \
90    string_posix_strerror_r_test.cpp \
91    strings_test.cpp \
92    stubs_test.cpp \
93    sstream_test.cpp \
94    sys_epoll_test.cpp \
95    sys_mman_test.cpp \
96    sys_personality_test.cpp \
97    sys_prctl_test.cpp \
98    sys_procfs_test.cpp \
99    sys_resource_test.cpp \
100    sys_select_test.cpp \
101    sys_sendfile_test.cpp \
102    sys_socket_test.cpp \
103    sys_stat_test.cpp \
104    sys_statvfs_test.cpp \
105    sys_syscall_test.cpp \
106    sys_sysinfo_test.cpp \
107    sys_time_test.cpp \
108    sys_types_test.cpp \
109    sys_uio_test.cpp \
110    sys_vfs_test.cpp \
111    sys_xattr_test.cpp \
112    system_properties_test.cpp \
113    time_test.cpp \
114    uchar_test.cpp \
115    uniqueptr_test.cpp \
116    unistd_test.cpp \
117    utmp_test.cpp \
118    wchar_test.cpp \
119
120libBionicStandardTests_cflags := \
121    $(test_cflags) \
122
123ifeq ($(MALLOC_IMPL),dlmalloc)
124  libBionicStandardTests_cflags += -DUSE_DLMALLOC
125else
126  libBionicStandardTests_cflags += -DUSE_JEMALLOC
127endif
128
129libBionicStandardTests_cppflags := \
130    $(test_cppflags) \
131
132libBionicStandardTests_c_includes := \
133    bionic/libc \
134    external/tinyxml2 \
135
136libBionicStandardTests_static_libraries := \
137    libbase \
138
139libBionicStandardTests_ldlibs_host := \
140    -lrt \
141
142# Clang/llvm has incompatible long double (fp128) for x86_64.
143# https://llvm.org/bugs/show_bug.cgi?id=23897
144# This affects most of math_test.cpp.
145ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86_64))
146libBionicStandardTests_clang_target := false
147endif
148
149module := libBionicStandardTests
150module_tag := optional
151build_type := target
152build_target := STATIC_TEST_LIBRARY
153include $(LOCAL_PATH)/Android.build.mk
154build_type := host
155include $(LOCAL_PATH)/Android.build.mk
156
157# -----------------------------------------------------------------------------
158# Fortify tests.
159# -----------------------------------------------------------------------------
160$(foreach compiler,gcc clang, \
161  $(foreach test,1 2, \
162    $(eval fortify$(test)-tests-$(compiler)_cflags := \
163      $(test_cflags) \
164      -Wno-error \
165      -U_FORTIFY_SOURCE \
166      -D_FORTIFY_SOURCE=$(test) \
167      -DTEST_NAME=Fortify$(test)_$(compiler)); \
168    $(eval fortify$(test)-tests-$(compiler)_src_files := \
169      fortify_test.cpp); \
170    $(eval fortify_libs += fortify$(test)-tests-$(compiler)); \
171  ) \
172)
173
174module := fortify1-tests-gcc
175module_tag := optional
176build_type := target
177build_target := STATIC_TEST_LIBRARY
178include $(LOCAL_PATH)/Android.build.mk
179build_type := host
180include $(LOCAL_PATH)/Android.build.mk
181
182module := fortify2-tests-gcc
183module_tag := optional
184build_type := target
185build_target := STATIC_TEST_LIBRARY
186include $(LOCAL_PATH)/Android.build.mk
187build_type := host
188include $(LOCAL_PATH)/Android.build.mk
189
190fortify1-tests-clang_clang_target := true
191fortify1-tests-clang_cflags_host := -D__clang__
192
193module := fortify1-tests-clang
194module_tag := optional
195build_type := target
196build_target := STATIC_TEST_LIBRARY
197include $(LOCAL_PATH)/Android.build.mk
198build_type := host
199include $(LOCAL_PATH)/Android.build.mk
200
201fortify2-tests-clang_clang_target := true
202
203fortify2-tests-clang_cflags_host := -D__clang__
204
205module := fortify2-tests-clang
206module_tag := optional
207build_type := target
208build_target := STATIC_TEST_LIBRARY
209include $(LOCAL_PATH)/Android.build.mk
210build_type := host
211include $(LOCAL_PATH)/Android.build.mk
212
213# -----------------------------------------------------------------------------
214# Library of all tests (excluding the dynamic linker tests).
215# -----------------------------------------------------------------------------
216libBionicTests_whole_static_libraries := \
217    libBionicStandardTests \
218    $(fortify_libs) \
219
220module := libBionicTests
221module_tag := optional
222build_type := target
223build_target := STATIC_TEST_LIBRARY
224include $(LOCAL_PATH)/Android.build.mk
225build_type := host
226include $(LOCAL_PATH)/Android.build.mk
227
228# -----------------------------------------------------------------------------
229# Library of bionic customized gtest main function, with simplified output format.
230# -----------------------------------------------------------------------------
231libBionicGtestMain_src_files := gtest_main.cpp
232
233libBionicGtestMain_cflags := $(test_cflags)
234
235libBionicGtestMain_cppflags := $(test_cppflags)
236
237module := libBionicGtestMain
238module_tag := optional
239build_type := target
240build_target := STATIC_TEST_LIBRARY
241include $(LOCAL_PATH)/Android.build.mk
242build_type := host
243
244ifeq ($(HOST_OS),$(filter $(HOST_OS),linux darwin))
245saved_build_host := $(build_host)
246build_host := true
247include $(LOCAL_PATH)/Android.build.mk
248build_host := $(saved_build_host)
249endif
250
251# -----------------------------------------------------------------------------
252# Library of bionic customized gtest main function, with normal gtest output format,
253# which is needed by bionic cts test.
254# -----------------------------------------------------------------------------
255libBionicCtsGtestMain_src_files := gtest_main.cpp
256
257libBionicCtsGtestMain_cflags := $(test_cflags)
258
259libBionicCtsGtestMain_cppflags := $(test_cppflags) -DUSING_GTEST_OUTPUT_FORMAT \
260
261module := libBionicCtsGtestMain
262module_tag := optional
263build_type := target
264build_target := STATIC_TEST_LIBRARY
265include $(LOCAL_PATH)/Android.build.mk
266build_type := host
267include $(LOCAL_PATH)/Android.build.mk
268
269# -----------------------------------------------------------------------------
270# Tests for the device using bionic's .so. Run with:
271#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests32
272#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests64
273# -----------------------------------------------------------------------------
274bionic-unit-tests_whole_static_libraries := \
275    libBionicTests \
276    libBionicGtestMain \
277
278bionic-unit-tests_static_libraries := \
279    libtinyxml2 \
280    liblog \
281    libbase \
282
283# TODO: Include __cxa_thread_atexit_test.cpp to glibc tests once it is upgraded (glibc 2.18+)
284bionic-unit-tests_src_files := \
285    atexit_test.cpp \
286    dl_test.cpp \
287    dlext_test.cpp \
288    __cxa_thread_atexit_test.cpp \
289    dlfcn_test.cpp \
290    libdl_test.cpp \
291    pthread_dlfcn_test.cpp \
292    thread_local_test.cpp \
293
294bionic-unit-tests_cflags := $(test_cflags)
295
296bionic-unit-tests_conlyflags := \
297    -fexceptions \
298    -fnon-call-exceptions \
299
300bionic-unit-tests_cppflags := $(test_cppflags)
301
302bionic-unit-tests_ldflags := \
303    -Wl,--export-dynamic
304
305bionic-unit-tests_c_includes := \
306    bionic/libc \
307
308bionic-unit-tests_shared_libraries_target := \
309    libdl \
310    libpagemap \
311    libdl_preempt_test_1 \
312    libdl_preempt_test_2
313
314# Clang/llvm has incompatible long double (fp128) for x86_64.
315# https://llvm.org/bugs/show_bug.cgi?id=23897
316# This affects most of math_test.cpp.
317# For arm and arm64 target, b/25643775:
318# external/libcxx/include/sstream:859: warning: relocation refers to discarded section
319ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86_64 arm arm64))
320bionic-unit-tests_clang_target := false
321endif
322
323bionic-unit-tests_shared_libraries_target += libdl_test_df_1_global
324
325module := bionic-unit-tests
326module_tag := optional
327build_type := target
328build_target := NATIVE_TEST
329include $(LOCAL_PATH)/Android.build.mk
330
331# -----------------------------------------------------------------------------
332# Tests for the device linked against bionic's static library. Run with:
333#   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static32
334#   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static64
335# -----------------------------------------------------------------------------
336bionic-unit-tests-static_whole_static_libraries := \
337    libBionicTests \
338    libBionicGtestMain \
339
340bionic-unit-tests-static_static_libraries := \
341    libm \
342    libc \
343    libc++_static \
344    libdl \
345    libtinyxml2 \
346    liblog \
347    libbase \
348
349bionic-unit-tests-static_force_static_executable := true
350
351# libc and libc++ both define std::nothrow. libc's is a private symbol, but this
352# still causes issues when linking libc.a and libc++.a, since private isn't
353# effective until it has been linked. To fix this, just allow multiple symbol
354# definitions for the static tests.
355bionic-unit-tests-static_ldflags := -Wl,--allow-multiple-definition
356
357module := bionic-unit-tests-static
358module_tag := optional
359build_type := target
360build_target := NATIVE_TEST
361include $(LOCAL_PATH)/Android.build.mk
362
363# -----------------------------------------------------------------------------
364# Tests to run on the host and linked against glibc. Run with:
365#   cd bionic/tests; mm bionic-unit-tests-glibc-run
366# -----------------------------------------------------------------------------
367
368ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
369
370bionic-unit-tests-glibc_src_files := \
371    atexit_test.cpp \
372    dlfcn_test.cpp \
373    dl_test.cpp \
374    pthread_dlfcn_test.cpp \
375
376bionic-unit-tests-glibc_shared_libraries := \
377    libdl_preempt_test_1 \
378    libdl_preempt_test_2
379
380bionic-unit-tests-glibc_shared_libraries += libdl_test_df_1_global
381
382bionic-unit-tests-glibc_whole_static_libraries := \
383    libBionicStandardTests \
384    libBionicGtestMain \
385    $(fortify_libs) \
386
387bionic-unit-tests-glibc_static_libraries := \
388    libbase \
389    liblog \
390    libcutils \
391
392bionic-unit-tests-glibc_ldlibs := \
393    -lrt -ldl -lutil \
394
395bionic-unit-tests-glibc_c_includes := \
396    bionic/libc \
397
398bionic-unit-tests-glibc_cflags := $(test_cflags)
399bionic-unit-tests-glibc_cppflags := $(test_cppflags)
400bionic-unit-tests-glibc_ldflags := -Wl,--export-dynamic
401
402bionic-unit-tests-glibc_allow_asan := true
403
404module := bionic-unit-tests-glibc
405module_tag := optional
406build_type := host
407build_target := NATIVE_TEST
408include $(LOCAL_PATH)/Android.build.mk
409
410# -----------------------------------------------------------------------------
411# Compile time tests.
412# -----------------------------------------------------------------------------
413
414# Some of these are intentionally using = instead of := since we need access to
415# some variables not initialtized until we're in the build system.
416
417include $(CLEAR_VARS)
418LOCAL_ADDITIONAL_DEPENDENCIES := \
419    $(LOCAL_PATH)/Android.mk \
420    $(LOCAL_PATH)/file-check-cxx \
421    | $(HOST_OUT_EXECUTABLES)/FileCheck$(HOST_EXECUTABLE_SUFFIX) \
422
423LOCAL_CXX = $(LOCAL_PATH)/file-check-cxx \
424    $(HOST_OUT_EXECUTABLES)/FileCheck \
425    $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_CXX) \
426    GCC \
427
428LOCAL_CLANG := false
429LOCAL_MODULE := bionic-compile-time-tests-g++
430LOCAL_CPPFLAGS := -Wall
431# Disable color diagnostics so the warnings output matches the source
432LOCAL_CPPFLAGS +=  -fdiagnostics-color=never
433LOCAL_SRC_FILES := fortify_compilation_test.cpp
434include $(BUILD_STATIC_LIBRARY)
435
436include $(CLEAR_VARS)
437LOCAL_ADDITIONAL_DEPENDENCIES := \
438    $(LOCAL_PATH)/Android.mk \
439    $(LOCAL_PATH)/file-check-cxx \
440    | $(HOST_OUT_EXECUTABLES)/FileCheck$(HOST_EXECUTABLE_SUFFIX) \
441
442LOCAL_CXX := $(LOCAL_PATH)/file-check-cxx \
443    $(HOST_OUT_EXECUTABLES)/FileCheck \
444    $(LLVM_PREBUILTS_PATH)/clang++ \
445    CLANG \
446
447LOCAL_CLANG := true
448LOCAL_MODULE := bionic-compile-time-tests-clang++
449LOCAL_CPPFLAGS := -Wall
450# Disable color diagnostics so the warnings output matches the source
451LOCAL_CPPFLAGS += -fno-color-diagnostics
452# FileCheck will error if there aren't any CLANG: lines in the file, but there
453# don't appear to be any cases where clang _does_ emit warnings for sn?printf :(
454LOCAL_SRC_FILES :=
455include $(BUILD_STATIC_LIBRARY)
456
457# -----------------------------------------------------------------------------
458# Host glibc tests.
459# -----------------------------------------------------------------------------
460
461# gtest needs ANDROID_DATA/local/tmp for death test output.
462# Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
463# Use the current target out directory as ANDROID_DATA.
464# BIONIC_TEST_FLAGS is either empty or it comes from the user.
465.PHONY: bionic-unit-tests-glibc-run
466bionic-unit-tests-glibc-run: bionic-unit-tests-glibc
467	mkdir -p $(TARGET_OUT_DATA)/local/tmp
468	ANDROID_DATA=$(TARGET_OUT_DATA) \
469	ANDROID_ROOT=$(TARGET_OUT) \
470		$(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc64 $(BIONIC_TEST_FLAGS)
471
472# -----------------------------------------------------------------------------
473# Run the unit tests built against x86 bionic on an x86 host.
474# -----------------------------------------------------------------------------
475
476include $(LOCAL_PATH)/../build/run-on-host.mk
477
478ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
479
480TEST_TIMEOUT := 0
481
482# BIONIC_TEST_FLAGS is either empty or it comes from the user.
483.PHONY: bionic-unit-tests-run-on-host32
484bionic-unit-tests-run-on-host32: bionic-unit-tests bionic-prepare-run-on-host
485	ANDROID_DATA=$(TARGET_OUT_DATA) \
486	ANDROID_DNS_MODE=local \
487	ANDROID_ROOT=$(TARGET_OUT) \
488		timeout $(TEST_TIMEOUT) \
489		$(TARGET_OUT_DATA)/nativetest/bionic-unit-tests/bionic-unit-tests32 $(BIONIC_TEST_FLAGS)
490
491ifeq ($(TARGET_IS_64_BIT),true)
492# add target to run lp64 tests
493.PHONY: bionic-unit-tests-run-on-host64
494bionic-unit-tests-run-on-host64: bionic-unit-tests bionic-prepare-run-on-host
495	ANDROID_DATA=$(TARGET_OUT_DATA) \
496	ANDROID_DNS_MODE=local \
497	ANDROID_ROOT=$(TARGET_OUT) \
498		timeout $(TEST_TIMEOUT) \
499		$(TARGET_OUT_DATA)/nativetest64/bionic-unit-tests/bionic-unit-tests64 $(BIONIC_TEST_FLAGS)
500endif
501
502endif # x86 x86_64
503endif # linux-x86
504
505include $(call first-makefiles-under,$(LOCAL_PATH))
506