Android.mk revision 50321e2e66f19998970e59d666bc9af387345b3a
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# Unit tests. 23# ----------------------------------------------------------------------------- 24 25ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64)) 26build_host := true 27else 28build_host := false 29endif 30 31common_additional_dependencies := $(LOCAL_PATH)/Android.mk $(LOCAL_PATH)/Android.build.mk 32 33# ----------------------------------------------------------------------------- 34# All standard tests. 35# ----------------------------------------------------------------------------- 36test_cflags = \ 37 -fstack-protector-all \ 38 -g \ 39 -Wall -Wextra -Wunused \ 40 -Werror \ 41 -fno-builtin \ 42 43test_cflags += -D__STDC_LIMIT_MACROS # For glibc. 44 45ifeq ($(MALLOC_IMPL),dlmalloc) 46test_cflags += -DUSE_DLMALLOC 47else 48test_cflags += -DUSE_JEMALLOC 49endif 50 51test_cppflags = \ 52 -std=gnu++11 \ 53 54libBionicStandardTests_src_files := \ 55 arpa_inet_test.cpp \ 56 buffer_tests.cpp \ 57 ctype_test.cpp \ 58 dirent_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_cos_test.cpp \ 71 math_cosf_test.cpp \ 72 math_exp_test.cpp \ 73 math_expf_test.cpp \ 74 math_log_test.cpp \ 75 math_logf_test.cpp \ 76 math_pow_test.cpp \ 77 math_powf_test.cpp \ 78 math_sin_test.cpp \ 79 math_sinf_test.cpp \ 80 math_sincos_test.cpp \ 81 math_sincosf_test.cpp \ 82 math_tan_test.cpp \ 83 math_tanf_test.cpp \ 84 math_test.cpp \ 85 mntent_test.cpp \ 86 netdb_test.cpp \ 87 pthread_test.cpp \ 88 regex_test.cpp \ 89 sched_test.cpp \ 90 search_test.cpp \ 91 semaphore_test.cpp \ 92 signal_test.cpp \ 93 stack_protector_test.cpp \ 94 stack_unwinding_test.cpp \ 95 stdatomic_test.cpp \ 96 stdint_test.cpp \ 97 stdio_test.cpp \ 98 stdio_ext_test.cpp \ 99 stdlib_test.cpp \ 100 string_test.cpp \ 101 string_posix_strerror_r_test.cpp \ 102 strings_test.cpp \ 103 stubs_test.cpp \ 104 sstream_test.cpp \ 105 sys_epoll_test.cpp \ 106 sys_mman_test.cpp \ 107 sys_resource_test.cpp \ 108 sys_select_test.cpp \ 109 sys_sendfile_test.cpp \ 110 sys_socket_test.cpp \ 111 sys_stat_test.cpp \ 112 sys_statvfs_test.cpp \ 113 sys_syscall_test.cpp \ 114 sys_time_test.cpp \ 115 sys_types_test.cpp \ 116 sys_vfs_test.cpp \ 117 system_properties_test.cpp \ 118 time_test.cpp \ 119 uchar_test.cpp \ 120 uniqueptr_test.cpp \ 121 unistd_test.cpp \ 122 wchar_test.cpp \ 123 124libBionicStandardTests_cflags := \ 125 $(test_cflags) \ 126 127ifeq ($(MALLOC_IMPL),dlmalloc) 128 libBionicStandardTests_cflags += -DUSE_DLMALLOC 129else 130 libBionicStandardTests_cflags += -DUSE_JEMALLOC 131endif 132 133libBionicStandardTests_cppflags := \ 134 $(test_cppflags) \ 135 136libBionicStandardTests_c_includes := \ 137 bionic/libc \ 138 external/tinyxml2 \ 139 140libBionicStandardTests_ldlibs_host := \ 141 -lrt \ 142 143module := libBionicStandardTests 144module_tag := optional 145build_type := target 146build_target := STATIC_TEST_LIBRARY 147include $(LOCAL_PATH)/Android.build.mk 148build_type := host 149include $(LOCAL_PATH)/Android.build.mk 150 151# ----------------------------------------------------------------------------- 152# Fortify tests. 153# ----------------------------------------------------------------------------- 154$(foreach compiler,gcc clang, \ 155 $(foreach test,1 2, \ 156 $(eval fortify$(test)-tests-$(compiler)_cflags := \ 157 $(test_cflags) \ 158 -Wno-error \ 159 -U_FORTIFY_SOURCE \ 160 -D_FORTIFY_SOURCE=$(test) \ 161 -DTEST_NAME=Fortify$(test)_$(compiler)); \ 162 $(eval fortify$(test)-tests-$(compiler)_src_files := \ 163 fortify_test.cpp); \ 164 $(eval fortify_libs += fortify$(test)-tests-$(compiler)); \ 165 ) \ 166) 167 168module := fortify1-tests-gcc 169module_tag := optional 170build_type := target 171build_target := STATIC_TEST_LIBRARY 172include $(LOCAL_PATH)/Android.build.mk 173build_type := host 174include $(LOCAL_PATH)/Android.build.mk 175 176module := fortify2-tests-gcc 177module_tag := optional 178build_type := target 179build_target := STATIC_TEST_LIBRARY 180include $(LOCAL_PATH)/Android.build.mk 181build_type := host 182include $(LOCAL_PATH)/Android.build.mk 183 184fortify1-tests-clang_clang_target := true 185fortify1-tests-clang_cflags_host := -D__clang__ 186 187module := fortify1-tests-clang 188module_tag := optional 189build_type := target 190build_target := STATIC_TEST_LIBRARY 191include $(LOCAL_PATH)/Android.build.mk 192build_type := host 193include $(LOCAL_PATH)/Android.build.mk 194 195fortify2-tests-clang_clang_target := true 196 197fortify2-tests-clang_cflags_host := -D__clang__ 198 199module := fortify2-tests-clang 200module_tag := optional 201build_type := target 202build_target := STATIC_TEST_LIBRARY 203include $(LOCAL_PATH)/Android.build.mk 204build_type := host 205include $(LOCAL_PATH)/Android.build.mk 206 207# ----------------------------------------------------------------------------- 208# Library of all tests (excluding the dynamic linker tests). 209# ----------------------------------------------------------------------------- 210libBionicTests_whole_static_libraries := \ 211 libBionicStandardTests \ 212 $(fortify_libs) \ 213 214module := libBionicTests 215module_tag := optional 216build_type := target 217build_target := STATIC_TEST_LIBRARY 218include $(LOCAL_PATH)/Android.build.mk 219build_type := host 220include $(LOCAL_PATH)/Android.build.mk 221 222# ----------------------------------------------------------------------------- 223# Tests for the device using bionic's .so. Run with: 224# adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests32 225# adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests64 226# ----------------------------------------------------------------------------- 227bionic-unit-tests_whole_static_libraries := \ 228 libBionicTests \ 229 230bionic-unit-tests_static_libraries := \ 231 libtinyxml2 \ 232 liblog \ 233 234bionic-unit-tests_src_files := \ 235 atexit_test.cpp \ 236 dlext_test.cpp \ 237 dlfcn_test.cpp \ 238 239bionic-unit-tests_cflags := $(test_cflags) 240 241bionic-unit-tests_conlyflags := \ 242 -fexceptions \ 243 -fnon-call-exceptions \ 244 245bionic-unit-tests_cppflags := $(test_cppflags) 246 247bionic-unit-tests_ldflags := \ 248 -Wl,--export-dynamic \ 249 -Wl,-u,DlSymTestFunction \ 250 251bionic-unit-tests_c_includes := \ 252 bionic/libc \ 253 $(call include-path-for, libpagemap) \ 254 255bionic-unit-tests_shared_libraries_target := \ 256 libdl \ 257 libpagemap \ 258 259module := bionic-unit-tests 260module_tag := optional 261build_type := target 262build_target := NATIVE_TEST 263include $(LOCAL_PATH)/Android.build.mk 264 265# ----------------------------------------------------------------------------- 266# Tests for the device linked against bionic's static library. Run with: 267# adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static32 268# adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static64 269# ----------------------------------------------------------------------------- 270bionic-unit-tests-static_whole_static_libraries := \ 271 libBionicTests \ 272 273bionic-unit-tests-static_static_libraries := \ 274 libm \ 275 libc \ 276 libc++_static \ 277 libdl \ 278 libtinyxml2 \ 279 liblog \ 280 281bionic-unit-tests-static_force_static_executable := true 282 283# libc and libc++ both define std::nothrow. libc's is a private symbol, but this 284# still causes issues when linking libc.a and libc++.a, since private isn't 285# effective until it has been linked. To fix this, just allow multiple symbol 286# definitions for the static tests. 287bionic-unit-tests-static_ldflags := -Wl,--allow-multiple-definition 288 289module := bionic-unit-tests-static 290module_tag := optional 291build_type := target 292build_target := NATIVE_TEST 293include $(LOCAL_PATH)/Android.build.mk 294 295# ----------------------------------------------------------------------------- 296# Tests to run on the host and linked against glibc. Run with: 297# cd bionic/tests; mm bionic-unit-tests-glibc-run 298# ----------------------------------------------------------------------------- 299 300ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64)) 301 302bionic-unit-tests-glibc_src_files := \ 303 atexit_test.cpp \ 304 dlfcn_test.cpp \ 305 306bionic-unit-tests-glibc_whole_static_libraries := \ 307 libBionicStandardTests \ 308 309bionic-unit-tests-glibc_ldlibs := \ 310 -lrt -ldl \ 311 312bionic-unit-tests-glibc_c_includes := \ 313 bionic/libc \ 314 315bionic-unit-tests-glibc_cflags := $(test_cflags) 316bionic-unit-tests-glibc_cppflags := $(test_cppflags) 317bionic-unit-tests-glibc_ldflags := -Wl,--export-dynamic 318 319module := bionic-unit-tests-glibc 320module_tag := optional 321build_type := host 322build_target := NATIVE_TEST 323include $(LOCAL_PATH)/Android.build.mk 324 325# ----------------------------------------------------------------------------- 326# Compile time tests. 327# ----------------------------------------------------------------------------- 328 329# Some of these are intentionally using = instead of := since we need access to 330# some variables not initialtized until we're in the build system. 331 332include $(CLEAR_VARS) 333LOCAL_ADDITIONAL_DEPENDENCIES := \ 334 $(LOCAL_PATH)/Android.mk \ 335 $(LOCAL_PATH)/file-check-cxx \ 336 | $(HOST_OUT_EXECUTABLES)/FileCheck$(HOST_EXECUTABLE_SUFFIX) \ 337 338LOCAL_CXX = $(LOCAL_PATH)/file-check-cxx \ 339 $(HOST_OUT_EXECUTABLES)/FileCheck \ 340 $($(LOCAL_2ND_ARCH_VAR_PREFIX)CXX_BARE) \ 341 GCC \ 342 343LOCAL_CLANG := false 344LOCAL_MODULE := bionic-compile-time-tests-g++ 345LOCAL_CXXFLAGS := -Wall 346LOCAL_SRC_FILES := fortify_sprintf_warnings.cpp 347include $(BUILD_STATIC_LIBRARY) 348 349include $(CLEAR_VARS) 350LOCAL_ADDITIONAL_DEPENDENCIES := \ 351 $(LOCAL_PATH)/Android.mk \ 352 $(LOCAL_PATH)/file-check-cxx \ 353 | $(HOST_OUT_EXECUTABLES)/FileCheck$(HOST_EXECUTABLE_SUFFIX) \ 354 355LOCAL_CXX := $(LOCAL_PATH)/file-check-cxx \ 356 $(HOST_OUT_EXECUTABLES)/FileCheck \ 357 $(LLVM_PREBUILTS_PATH)/clang++ \ 358 CLANG \ 359 360LOCAL_CLANG := true 361LOCAL_MODULE := bionic-compile-time-tests-clang++ 362LOCAL_CXXFLAGS := -Wall 363# FileCheck will error if there aren't any CLANG: lines in the file, but there 364# don't appear to be any cases where clang _does_ emit warnings for sn?printf :( 365LOCAL_SRC_FILES := 366include $(BUILD_STATIC_LIBRARY) 367 368# ----------------------------------------------------------------------------- 369# Host glibc tests. 370# ----------------------------------------------------------------------------- 371 372ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm mips x86)) 373LINKER = linker64 374NATIVE_TEST_SUFFIX=64 375else 376LINKER = linker 377NATIVE_TEST_SUFFIX=32 378endif 379 380# gtest needs ANDROID_DATA/local/tmp for death test output. 381# Make sure to create ANDROID_DATA/local/tmp if doesn't exist. 382# Use the current target out directory as ANDROID_DATA. 383# BIONIC_TEST_FLAGS is either empty or it comes from the user. 384bionic-unit-tests-glibc-run: bionic-unit-tests-glibc 385 mkdir -p $(TARGET_OUT_DATA)/local/tmp 386 ANDROID_DATA=$(TARGET_OUT_DATA) \ 387 ANDROID_ROOT=$(TARGET_OUT) \ 388 $(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS) 389 390# ----------------------------------------------------------------------------- 391# Run the unit tests built against x86 bionic on an x86 host. 392# ----------------------------------------------------------------------------- 393 394ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64)) 395# gtest needs ANDROID_DATA/local/tmp for death test output. 396# Make sure to create ANDROID_DATA/local/tmp if doesn't exist. 397# bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT. 398# BIONIC_TEST_FLAGS is either empty or it comes from the user. 399bionic-unit-tests-run-on-host-prepare: $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh 400 if [ ! -d /system ]; then \ 401 echo "Attempting to create /system"; \ 402 sudo mkdir -p -m 0777 /system; \ 403 fi 404 mkdir -p $(TARGET_OUT_DATA)/local/tmp 405 ln -fs `realpath $(TARGET_OUT)/bin` /system/ 406 ln -fs `realpath $(TARGET_OUT)/etc` /system/ 407 408bionic-unit-tests-run-on-host: bionic-unit-tests bionic-unit-tests-run-on-host-prepare 409 ANDROID_DATA=$(TARGET_OUT_DATA) \ 410 ANDROID_DNS_MODE=local \ 411 ANDROID_ROOT=$(TARGET_OUT) \ 412 LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \ 413 $(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS) 414endif 415 416ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86_64)) 417# add target to run lp32 tests 418bionic-unit-tests-run-on-host32: bionic-unit-tests_32 bionic-unit-tests-run-on-host-prepare 419 ANDROID_DATA=$(TARGET_OUT_DATA) \ 420 ANDROID_DNS_MODE=local \ 421 ANDROID_ROOT=$(TARGET_OUT) \ 422 LD_LIBRARY_PATH=$(2ND_TARGET_OUT_SHARED_LIBRARIES) \ 423 $(2ND_TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests32 $(BIONIC_TEST_FLAGS) 424endif 425 426endif # linux-x86 427 428include $(call first-makefiles-under,$(LOCAL_PATH)) 429endif # !BUILD_TINY_ANDROID 430