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