Android.mk revision 4d35da1df8b74c1965b2201f6089e7d7bb352def
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 31# ----------------------------------------------------------------------------- 32# All standard tests. 33# ----------------------------------------------------------------------------- 34test_cflags = \ 35 -fstack-protector-all \ 36 -g \ 37 -Wall -Wextra \ 38 -Werror \ 39 -fno-builtin \ 40 41test_cflags += -D__STDC_LIMIT_MACROS # For glibc. 42 43test_cppflags = \ 44 -std=gnu++11 \ 45 46libBionicStandardTests_src_files := \ 47 arpa_inet_test.cpp \ 48 buffer_tests.cpp \ 49 ctype_test.cpp \ 50 dirent_test.cpp \ 51 eventfd_test.cpp \ 52 fcntl_test.cpp \ 53 fenv_test.cpp \ 54 ftw_test.cpp \ 55 getauxval_test.cpp \ 56 getcwd_test.cpp \ 57 inttypes_test.cpp \ 58 libc_logging_test.cpp \ 59 libgen_test.cpp \ 60 locale_test.cpp \ 61 malloc_test.cpp \ 62 math_cos_test.cpp \ 63 math_cosf_test.cpp \ 64 math_exp_test.cpp \ 65 math_expf_test.cpp \ 66 math_log_test.cpp \ 67 math_logf_test.cpp \ 68 math_pow_test.cpp \ 69 math_powf_test.cpp \ 70 math_sin_test.cpp \ 71 math_sinf_test.cpp \ 72 math_sincos_test.cpp \ 73 math_sincosf_test.cpp \ 74 math_tan_test.cpp \ 75 math_tanf_test.cpp \ 76 math_test.cpp \ 77 mntent_test.cpp \ 78 netdb_test.cpp \ 79 pthread_test.cpp \ 80 regex_test.cpp \ 81 sched_test.cpp \ 82 signal_test.cpp \ 83 stack_protector_test.cpp \ 84 stack_unwinding_test.cpp \ 85 stack_unwinding_test_impl.c \ 86 stdint_test.cpp \ 87 stdio_test.cpp \ 88 stdlib_test.cpp \ 89 string_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_resource_test.cpp \ 96 sys_select_test.cpp \ 97 sys_sendfile_test.cpp \ 98 sys_socket_test.cpp \ 99 sys_stat_test.cpp \ 100 sys_statvfs_test.cpp \ 101 sys_syscall_test.cpp \ 102 sys_time_test.cpp \ 103 sys_types_test.cpp \ 104 sys_vfs_test.cpp \ 105 system_properties_test.cpp \ 106 time_test.cpp \ 107 unistd_test.cpp \ 108 wchar_test.cpp \ 109 110libBionicStandardTests_c_includes := \ 111 bionic/libc/private \ 112 113libBionicStandardTests_cflags := \ 114 $(test_cflags) \ 115 116libBionicStandardTests_cppflags := \ 117 $(test_cppflags) \ 118 119libBionicStandardTests_ldlibs_host := \ 120 -lrt \ 121 122module := libBionicStandardTests 123module_tag := optional 124build_type := target 125build_target := STATIC_TEST_LIBRARY 126include $(LOCAL_PATH)/Android.build.mk 127build_type := host 128include $(LOCAL_PATH)/Android.build.mk 129 130# ----------------------------------------------------------------------------- 131# Fortify tests. 132# ----------------------------------------------------------------------------- 133$(foreach compiler,gcc clang, \ 134 $(foreach test,1 2, \ 135 $(eval fortify$(test)-tests-$(compiler)_cflags := \ 136 $(test_cflags) \ 137 -U_FORTIFY_SOURCE \ 138 -D_FORTIFY_SOURCE=$(test) \ 139 -DTEST_NAME=Fortify$(test)_$(compiler)); \ 140 $(eval fortify$(test)-tests-$(compiler)_cflags_host := \ 141 -Wno-error); \ 142 $(eval fortify$(test)-tests-$(compiler)_src_files := \ 143 fortify_test.cpp); \ 144 $(eval fortify_libs += fortify$(test)-tests-$(compiler)); \ 145 ) \ 146) 147 148module := fortify1-tests-gcc 149module_tag := optional 150build_type := target 151build_target := STATIC_TEST_LIBRARY 152include $(LOCAL_PATH)/Android.build.mk 153build_type := host 154include $(LOCAL_PATH)/Android.build.mk 155 156module := fortify2-tests-gcc 157module_tag := optional 158build_type := target 159build_target := STATIC_TEST_LIBRARY 160include $(LOCAL_PATH)/Android.build.mk 161build_type := host 162include $(LOCAL_PATH)/Android.build.mk 163 164fortify1-tests-clang_clang_target := true 165fortify1-tests-clang_cflags_host := -D__clang__ 166 167module := fortify1-tests-clang 168module_tag := optional 169build_type := target 170build_target := STATIC_TEST_LIBRARY 171include $(LOCAL_PATH)/Android.build.mk 172build_type := host 173include $(LOCAL_PATH)/Android.build.mk 174 175fortify2-tests-clang_clang_target := true 176 177fortify2-tests-clang_cflags_host := -D__clang__ 178 179module := fortify2-tests-clang 180module_tag := optional 181build_type := target 182build_target := STATIC_TEST_LIBRARY 183include $(LOCAL_PATH)/Android.build.mk 184build_type := host 185include $(LOCAL_PATH)/Android.build.mk 186 187# ----------------------------------------------------------------------------- 188# Library of all tests (excluding the dynamic linker tests). 189# ----------------------------------------------------------------------------- 190libBionicTests_whole_static_libraries := \ 191 libBionicStandardTests \ 192 $(fortify_libs) \ 193 194module := libBionicTests 195module_tag := optional 196build_type := target 197build_target := STATIC_TEST_LIBRARY 198include $(LOCAL_PATH)/Android.build.mk 199build_type := host 200include $(LOCAL_PATH)/Android.build.mk 201 202# ----------------------------------------------------------------------------- 203# Library used by dlfcn tests. 204# ----------------------------------------------------------------------------- 205ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),mips mips64)) 206no-elf-hash-table-library_src_files := \ 207 empty.cpp \ 208 209no-elf-hash-table-library_ldflags := \ 210 -Wl,--hash-style=gnu \ 211 212module := no-elf-hash-table-library 213module_tag := optional 214build_type := target 215build_target := SHARED_LIBRARY 216include $(LOCAL_PATH)/Android.build.mk 217endif 218 219# ----------------------------------------------------------------------------- 220# Library used by dlext tests - with/without GNU RELRO program header 221# ----------------------------------------------------------------------------- 222libdlext_test_src_files := \ 223 dlext_test_library.cpp \ 224 225libdlext_test_ldflags := \ 226 -Wl,-z,relro \ 227 228module := libdlext_test 229module_tag := optional 230build_type := target 231build_target := SHARED_LIBRARY 232include $(LOCAL_PATH)/Android.build.mk 233 234# ----------------------------------------------------------------------------- 235# create symlink to libdlext_test.so for symlink test 236# ----------------------------------------------------------------------------- 237libdlext_origin := $(LOCAL_INSTALLED_MODULE) 238libdlext_sym := $(subst libdlext_test,libdlext_test_v2,$(libdlext_origin)) 239$(libdlext_sym): $(libdlext_origin) 240 @echo "Symlink: $@ -> $(notdir $<)" 241 @mkdir -p $(dir $@) 242 $(hide) ln -sf $(notdir $<) $@ 243 244ALL_MODULES := \ 245 $(ALL_MODULES) $(libdlext_sym) 246 247ifneq ($(TARGET_2ND_ARCH),) 248# link 64 bit .so 249libdlext_origin := $(TARGET_OUT)/lib64/libdlext_test.so 250libdlext_sym := $(subst libdlext_test,libdlext_test_v2,$(libdlext_origin)) 251$(libdlext_sym): $(libdlext_origin) 252 @echo "Symlink: $@ -> $(notdir $<)" 253 @mkdir -p $(dir $@) 254 $(hide) ln -sf $(notdir $<) $@ 255 256ALL_MODULES := \ 257 $(ALL_MODULES) $(libdlext_sym) 258endif 259 260libdlext_test_norelro_src_files := \ 261 dlext_test_library.cpp \ 262 263libdlext_test_norelro_ldflags := \ 264 -Wl,-z,norelro \ 265 266module := libdlext_test_norelro 267module_tag := optional 268build_type := target 269build_target := SHARED_LIBRARY 270include $(LOCAL_PATH)/Android.build.mk 271 272# ----------------------------------------------------------------------------- 273# Library used by atexit tests 274# ----------------------------------------------------------------------------- 275 276libtest_atexit_src_files := \ 277 atexit_testlib.cpp 278 279module := libtest_atexit 280build_type := target 281build_target := SHARED_LIBRARY 282include $(LOCAL_PATH)/Android.build.mk 283 284# ----------------------------------------------------------------------------- 285# Tests for the device using bionic's .so. Run with: 286# adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests 287# ----------------------------------------------------------------------------- 288bionic-unit-tests_whole_static_libraries := \ 289 libBionicTests \ 290 291bionic-unit-tests_src_files := \ 292 atexit_test.cpp \ 293 dlext_test.cpp \ 294 dlfcn_test.cpp \ 295 296bionic-unit-tests_cppflags := \ 297 $(test_cppflags) 298 299bionic-unit-tests_ldflags := \ 300 -Wl,--export-dynamic \ 301 -Wl,-u,DlSymTestFunction \ 302 303bionic-unit-tests_c_includes := \ 304 $(call include-path-for, libpagemap) \ 305 306bionic-unit-tests_shared_libraries_target := \ 307 libdl \ 308 libpagemap \ 309 310module := bionic-unit-tests 311module_tag := optional 312bionic-unit-tests_multilib := both 313build_type := target 314build_target := NATIVE_TEST 315include $(LOCAL_PATH)/Android.build.mk 316 317# ----------------------------------------------------------------------------- 318# Tests for the device linked against bionic's static library. Run with: 319# adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static 320# ----------------------------------------------------------------------------- 321bionic-unit-tests-static_whole_static_libraries := \ 322 libBionicTests \ 323 324bionic-unit-tests-static_static_libraries := \ 325 libm \ 326 libc \ 327 libc++ \ 328 329bionic-unit-tests-static_force_static_executable := true 330 331module := bionic-unit-tests-static 332module_tag := optional 333bionic-unit-tests-static_multilib := both 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),linux-x86) 344 345bionic-unit-tests-glibc_src_files := \ 346 atexit_test.cpp \ 347 348bionic-unit-tests-glibc_whole_static_libraries := \ 349 libBionicStandardTests \ 350 351bionic-unit-tests-glibc_ldlibs := \ 352 -lrt -ldl \ 353 354bionic-unit-tests-glibc_cppflags := \ 355 $(test_cppflags) 356 357module := bionic-unit-tests-glibc 358module_tag := optional 359bionic-unit-tests-glibc_multilib := both 360build_type := host 361build_target := NATIVE_TEST 362include $(LOCAL_PATH)/Android.build.mk 363 364ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm mips x86)) 365LINKER = linker64 366NATIVE_TEST_SUFFIX=64 367else 368LINKER = linker 369NATIVE_TEST_SUFFIX=32 370endif 371 372# gtest needs ANDROID_DATA/local/tmp for death test output. 373# Make sure to create ANDROID_DATA/local/tmp if doesn't exist. 374# Use the current target out directory as ANDROID_DATA. 375# BIONIC_TEST_FLAGS is either empty or it comes from the user. 376bionic-unit-tests-glibc-run: bionic-unit-tests-glibc 377 mkdir -p $(TARGET_OUT_DATA)/local/tmp 378 ANDROID_DATA=$(TARGET_OUT_DATA) \ 379 ANDROID_ROOT=$(TARGET_OUT) \ 380 $(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS) 381 382# ----------------------------------------------------------------------------- 383# Run the unit tests built against x86 bionic on an x86 host. 384# ----------------------------------------------------------------------------- 385 386ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64)) 387# gtest needs ANDROID_DATA/local/tmp for death test output. 388# Make sure to create ANDROID_DATA/local/tmp if doesn't exist. 389# bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT. 390# BIONIC_TEST_FLAGS is either empty or it comes from the user. 391bionic-unit-tests-run-on-host: bionic-unit-tests $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh 392 if [ ! -d /system -o ! -d /system/bin ]; then \ 393 echo "Attempting to create /system/bin"; \ 394 sudo mkdir -p -m 0777 /system/bin; \ 395 fi 396 mkdir -p $(TARGET_OUT_DATA)/local/tmp 397 cp $(TARGET_OUT_EXECUTABLES)/$(LINKER) /system/bin 398 cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin 399 ANDROID_DATA=$(TARGET_OUT_DATA) \ 400 ANDROID_ROOT=$(TARGET_OUT) \ 401 LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \ 402 $(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS) 403endif 404 405endif # linux-x86 406 407endif # !BUILD_TINY_ANDROID 408