Android.mk revision 7a39094465bbd01a22565fce1f1155c762f8d145
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_cflags := \ 111 $(test_cflags) \ 112 113libBionicStandardTests_cppflags := \ 114 $(test_cppflags) \ 115 116libBionicStandardTests_ldlibs_host := \ 117 -lrt \ 118 119module := libBionicStandardTests 120module_tag := optional 121build_type := target 122build_target := STATIC_TEST_LIBRARY 123include $(LOCAL_PATH)/Android.build.mk 124build_type := host 125include $(LOCAL_PATH)/Android.build.mk 126 127# ----------------------------------------------------------------------------- 128# Fortify tests. 129# ----------------------------------------------------------------------------- 130$(foreach compiler,gcc clang, \ 131 $(foreach test,1 2, \ 132 $(eval fortify$(test)-tests-$(compiler)_cflags := \ 133 $(test_cflags) \ 134 -U_FORTIFY_SOURCE \ 135 -D_FORTIFY_SOURCE=$(test) \ 136 -DTEST_NAME=Fortify$(test)_$(compiler)); \ 137 $(eval fortify$(test)-tests-$(compiler)_cflags_host := \ 138 -Wno-error); \ 139 $(eval fortify$(test)-tests-$(compiler)_src_files := \ 140 fortify_test.cpp); \ 141 $(eval fortify_libs += fortify$(test)-tests-$(compiler)); \ 142 ) \ 143) 144 145module := fortify1-tests-gcc 146module_tag := optional 147build_type := target 148build_target := STATIC_TEST_LIBRARY 149include $(LOCAL_PATH)/Android.build.mk 150build_type := host 151include $(LOCAL_PATH)/Android.build.mk 152 153module := fortify2-tests-gcc 154module_tag := optional 155build_type := target 156build_target := STATIC_TEST_LIBRARY 157include $(LOCAL_PATH)/Android.build.mk 158build_type := host 159include $(LOCAL_PATH)/Android.build.mk 160 161fortify1-tests-clang_clang_target := true 162fortify1-tests-clang_cflags_host := -D__clang__ 163 164module := fortify1-tests-clang 165module_tag := optional 166build_type := target 167build_target := STATIC_TEST_LIBRARY 168include $(LOCAL_PATH)/Android.build.mk 169build_type := host 170include $(LOCAL_PATH)/Android.build.mk 171 172fortify2-tests-clang_clang_target := true 173 174fortify2-tests-clang_cflags_host := -D__clang__ 175 176module := fortify2-tests-clang 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 184# ----------------------------------------------------------------------------- 185# Library of all tests (excluding the dynamic linker tests). 186# ----------------------------------------------------------------------------- 187libBionicTests_whole_static_libraries := \ 188 libBionicStandardTests \ 189 $(fortify_libs) \ 190 191module := libBionicTests 192module_tag := optional 193build_type := target 194build_target := STATIC_TEST_LIBRARY 195include $(LOCAL_PATH)/Android.build.mk 196build_type := host 197include $(LOCAL_PATH)/Android.build.mk 198 199# ----------------------------------------------------------------------------- 200# Library used by dlfcn tests. 201# ----------------------------------------------------------------------------- 202ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),mips mips64)) 203no-elf-hash-table-library_src_files := \ 204 empty.cpp \ 205 206no-elf-hash-table-library_ldflags := \ 207 -Wl,--hash-style=gnu \ 208 209module := no-elf-hash-table-library 210module_tag := optional 211build_type := target 212build_target := SHARED_LIBRARY 213include $(LOCAL_PATH)/Android.build.mk 214endif 215 216# ----------------------------------------------------------------------------- 217# Library used by dlext tests - with/without GNU RELRO program header 218# ----------------------------------------------------------------------------- 219libdlext_test_src_files := \ 220 dlext_test_library.cpp \ 221 222libdlext_test_ldflags := \ 223 -Wl,-z,relro \ 224 225module := libdlext_test 226module_tag := optional 227build_type := target 228build_target := SHARED_LIBRARY 229include $(LOCAL_PATH)/Android.build.mk 230 231# ----------------------------------------------------------------------------- 232# create symlink to libdlext_test.so for symlink test 233# ----------------------------------------------------------------------------- 234libdlext_origin := $(LOCAL_INSTALLED_MODULE) 235libdlext_sym := $(subst libdlext_test,libdlext_test_v2,$(libdlext_origin)) 236$(libdlext_sym): $(libdlext_origin) 237 @echo "Symlink: $@ -> $(notdir $<)" 238 @mkdir -p $(dir $@) 239 $(hide) ln -sf $(notdir $<) $@ 240 241ALL_MODULES := \ 242 $(ALL_MODULES) $(libdlext_sym) 243 244ifneq ($(TARGET_2ND_ARCH),) 245# link 64 bit .so 246libdlext_origin := $(TARGET_OUT)/lib64/libdlext_test.so 247libdlext_sym := $(subst libdlext_test,libdlext_test_v2,$(libdlext_origin)) 248$(libdlext_sym): $(libdlext_origin) 249 @echo "Symlink: $@ -> $(notdir $<)" 250 @mkdir -p $(dir $@) 251 $(hide) ln -sf $(notdir $<) $@ 252 253ALL_MODULES := \ 254 $(ALL_MODULES) $(libdlext_sym) 255endif 256 257libdlext_test_norelro_src_files := \ 258 dlext_test_library.cpp \ 259 260libdlext_test_norelro_ldflags := \ 261 -Wl,-z,norelro \ 262 263module := libdlext_test_norelro 264module_tag := optional 265build_type := target 266build_target := SHARED_LIBRARY 267include $(LOCAL_PATH)/Android.build.mk 268 269# ----------------------------------------------------------------------------- 270# Library used by atexit tests 271# ----------------------------------------------------------------------------- 272 273libtest_atexit_src_files := \ 274 atexit_testlib.cpp 275 276module := libtest_atexit 277build_type := target 278build_target := SHARED_LIBRARY 279include $(LOCAL_PATH)/Android.build.mk 280 281# ----------------------------------------------------------------------------- 282# Tests for the device using bionic's .so. Run with: 283# adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests 284# ----------------------------------------------------------------------------- 285bionic-unit-tests_whole_static_libraries := \ 286 libBionicTests \ 287 288bionic-unit-tests_src_files := \ 289 atexit_test.cpp \ 290 dlext_test.cpp \ 291 dlfcn_test.cpp \ 292 293bionic-unit-tests_cppflags := \ 294 $(test_cppflags) 295 296bionic-unit-tests_ldflags := \ 297 -Wl,--export-dynamic \ 298 -Wl,-u,DlSymTestFunction \ 299 300bionic-unit-tests_c_includes := \ 301 $(call include-path-for, libpagemap) \ 302 303bionic-unit-tests_shared_libraries_target := \ 304 libdl \ 305 libpagemap \ 306 307module := bionic-unit-tests 308module_tag := optional 309bionic-unit-tests_multilib := both 310build_type := target 311build_target := NATIVE_TEST 312include $(LOCAL_PATH)/Android.build.mk 313 314# ----------------------------------------------------------------------------- 315# Tests for the device linked against bionic's static library. Run with: 316# adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static 317# ----------------------------------------------------------------------------- 318bionic-unit-tests-static_whole_static_libraries := \ 319 libBionicTests \ 320 321bionic-unit-tests-static_static_libraries := \ 322 libstlport_static \ 323 libm \ 324 libc \ 325 libstdc++ \ 326 327bionic-unit-tests-static_force_static_executable := true 328 329module := bionic-unit-tests-static 330module_tag := optional 331bionic-unit-tests-static_multilib := both 332build_type := target 333build_target := NATIVE_TEST 334include $(LOCAL_PATH)/Android.build.mk 335 336# ----------------------------------------------------------------------------- 337# Tests to run on the host and linked against glibc. Run with: 338# cd bionic/tests; mm bionic-unit-tests-glibc-run 339# ----------------------------------------------------------------------------- 340 341ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86) 342 343bionic-unit-tests-glibc_src_files := \ 344 atexit_test.cpp \ 345 346bionic-unit-tests-glibc_whole_static_libraries := \ 347 libBionicStandardTests \ 348 349bionic-unit-tests-glibc_ldlibs := \ 350 -lrt -ldl \ 351 352bionic-unit-tests-glibc_cppflags := \ 353 $(test_cppflags) 354 355module := bionic-unit-tests-glibc 356module_tag := optional 357bionic-unit-tests-glibc_multilib := both 358build_type := host 359build_target := NATIVE_TEST 360include $(LOCAL_PATH)/Android.build.mk 361 362ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm mips x86)) 363LINKER = linker64 364NATIVE_TEST_SUFFIX=64 365else 366LINKER = linker 367NATIVE_TEST_SUFFIX=32 368endif 369 370# gtest needs ANDROID_DATA/local/tmp for death test output. 371# Make sure to create ANDROID_DATA/local/tmp if doesn't exist. 372# Use the current target out directory as ANDROID_DATA. 373# BIONIC_TEST_FLAGS is either empty or it comes from the user. 374bionic-unit-tests-glibc-run: bionic-unit-tests-glibc 375 mkdir -p $(TARGET_OUT_DATA)/local/tmp 376 ANDROID_DATA=$(TARGET_OUT_DATA) \ 377 ANDROID_ROOT=$(TARGET_OUT) \ 378 $(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS) 379 380# ----------------------------------------------------------------------------- 381# Run the unit tests built against x86 bionic on an x86 host. 382# ----------------------------------------------------------------------------- 383 384ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64)) 385# gtest needs ANDROID_DATA/local/tmp for death test output. 386# Make sure to create ANDROID_DATA/local/tmp if doesn't exist. 387# bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT. 388# BIONIC_TEST_FLAGS is either empty or it comes from the user. 389bionic-unit-tests-run-on-host: bionic-unit-tests $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh 390 if [ ! -d /system -o ! -d /system/bin ]; then \ 391 echo "Attempting to create /system/bin"; \ 392 sudo mkdir -p -m 0777 /system/bin; \ 393 fi 394 mkdir -p $(TARGET_OUT_DATA)/local/tmp 395 cp $(TARGET_OUT_EXECUTABLES)/$(LINKER) /system/bin 396 cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin 397 ANDROID_DATA=$(TARGET_OUT_DATA) \ 398 ANDROID_ROOT=$(TARGET_OUT) \ 399 LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \ 400 $(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS) 401endif 402 403endif # linux-x86 404 405endif # !BUILD_TINY_ANDROID 406