Android.mk revision 8e32b7b3543eadbb58a92443fb57d60aac92ef88
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 -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 ctype_test.cpp \ 56 dirent_test.cpp \ 57 eventfd_test.cpp \ 58 fcntl_test.cpp \ 59 fenv_test.cpp \ 60 ftw_test.cpp \ 61 getauxval_test.cpp \ 62 getcwd_test.cpp \ 63 inttypes_test.cpp \ 64 libc_logging_test.cpp \ 65 libgen_test.cpp \ 66 locale_test.cpp \ 67 malloc_test.cpp \ 68 math_cos_test.cpp \ 69 math_cosf_test.cpp \ 70 math_exp_test.cpp \ 71 math_expf_test.cpp \ 72 math_log_test.cpp \ 73 math_logf_test.cpp \ 74 math_pow_test.cpp \ 75 math_powf_test.cpp \ 76 math_sin_test.cpp \ 77 math_sinf_test.cpp \ 78 math_sincos_test.cpp \ 79 math_sincosf_test.cpp \ 80 math_tan_test.cpp \ 81 math_tanf_test.cpp \ 82 math_test.cpp \ 83 mntent_test.cpp \ 84 netdb_test.cpp \ 85 pthread_test.cpp \ 86 regex_test.cpp \ 87 sched_test.cpp \ 88 signal_test.cpp \ 89 stack_protector_test.cpp \ 90 stack_unwinding_test.cpp \ 91 stdatomic_test.cpp \ 92 stdint_test.cpp \ 93 stdio_test.cpp \ 94 stdlib_test.cpp \ 95 string_test.cpp \ 96 strings_test.cpp \ 97 stubs_test.cpp \ 98 sstream_test.cpp \ 99 sys_epoll_test.cpp \ 100 sys_mman_test.cpp \ 101 sys_resource_test.cpp \ 102 sys_select_test.cpp \ 103 sys_sendfile_test.cpp \ 104 sys_socket_test.cpp \ 105 sys_stat_test.cpp \ 106 sys_statvfs_test.cpp \ 107 sys_syscall_test.cpp \ 108 sys_time_test.cpp \ 109 sys_types_test.cpp \ 110 sys_vfs_test.cpp \ 111 system_properties_test.cpp \ 112 time_test.cpp \ 113 uchar_test.cpp \ 114 unistd_test.cpp \ 115 wchar_test.cpp \ 116 117libBionicStandardTests_cflags := \ 118 $(test_cflags) \ 119 120ifeq ($(MALLOC_IMPL),dlmalloc) 121 libBionicStandardTests_cflags += -DUSE_DLMALLOC 122else 123 libBionicStandardTests_cflags += -DUSE_JEMALLOC 124endif 125 126libBionicStandardTests_cppflags := \ 127 $(test_cppflags) \ 128 129libBionicStandardTests_c_includes := \ 130 bionic/libc \ 131 132libBionicStandardTests_ldlibs_host := \ 133 -lrt \ 134 135libBionicStandardTests_whole_static_libraries := \ 136 libBionicUnwindTest \ 137 138module := libBionicStandardTests 139module_tag := optional 140build_type := target 141build_target := STATIC_TEST_LIBRARY 142include $(LOCAL_PATH)/Android.build.mk 143build_type := host 144include $(LOCAL_PATH)/Android.build.mk 145 146# ----------------------------------------------------------------------------- 147# Special stack unwinding test library compiled with special flags. 148# ----------------------------------------------------------------------------- 149libBionicUnwindTest_cflags := \ 150 $(test_cflags) \ 151 -fexceptions \ 152 -fnon-call-exceptions \ 153 154libBionicUnwindTest_src_files := \ 155 stack_unwinding_test_impl.c \ 156 157module := libBionicUnwindTest 158module_tag := optional 159build_type := target 160build_target := STATIC_TEST_LIBRARY 161include $(LOCAL_PATH)/Android.build.mk 162build_type := host 163include $(LOCAL_PATH)/Android.build.mk 164 165# ----------------------------------------------------------------------------- 166# Fortify tests. 167# ----------------------------------------------------------------------------- 168$(foreach compiler,gcc clang, \ 169 $(foreach test,1 2, \ 170 $(eval fortify$(test)-tests-$(compiler)_cflags := \ 171 $(test_cflags) \ 172 -U_FORTIFY_SOURCE \ 173 -D_FORTIFY_SOURCE=$(test) \ 174 -DTEST_NAME=Fortify$(test)_$(compiler)); \ 175 $(eval fortify$(test)-tests-$(compiler)_cflags_host := \ 176 -Wno-error); \ 177 $(eval fortify$(test)-tests-$(compiler)_src_files := \ 178 fortify_test.cpp); \ 179 $(eval fortify_libs += fortify$(test)-tests-$(compiler)); \ 180 ) \ 181) 182 183module := fortify1-tests-gcc 184module_tag := optional 185build_type := target 186build_target := STATIC_TEST_LIBRARY 187include $(LOCAL_PATH)/Android.build.mk 188build_type := host 189include $(LOCAL_PATH)/Android.build.mk 190 191module := fortify2-tests-gcc 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 199fortify1-tests-clang_clang_target := true 200fortify1-tests-clang_cflags_host := -D__clang__ 201 202module := fortify1-tests-clang 203module_tag := optional 204build_type := target 205build_target := STATIC_TEST_LIBRARY 206include $(LOCAL_PATH)/Android.build.mk 207build_type := host 208include $(LOCAL_PATH)/Android.build.mk 209 210fortify2-tests-clang_clang_target := true 211 212fortify2-tests-clang_cflags_host := -D__clang__ 213 214module := fortify2-tests-clang 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# Library of all tests (excluding the dynamic linker tests). 224# ----------------------------------------------------------------------------- 225libBionicTests_whole_static_libraries := \ 226 libBionicStandardTests \ 227 $(fortify_libs) \ 228 229module := libBionicTests 230module_tag := optional 231build_type := target 232build_target := STATIC_TEST_LIBRARY 233include $(LOCAL_PATH)/Android.build.mk 234build_type := host 235include $(LOCAL_PATH)/Android.build.mk 236 237# ----------------------------------------------------------------------------- 238# Tests for the device using bionic's .so. Run with: 239# adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests 240# ----------------------------------------------------------------------------- 241bionic-unit-tests_whole_static_libraries := \ 242 libBionicTests \ 243 244bionic-unit-tests_src_files := \ 245 atexit_test.cpp \ 246 dlext_test.cpp \ 247 dlfcn_test.cpp \ 248 249bionic-unit-tests_cflags := $(test_cflags) 250bionic-unit-tests_cppflags := $(test_cppflags) 251 252bionic-unit-tests_ldflags := \ 253 -Wl,--export-dynamic \ 254 -Wl,-u,DlSymTestFunction \ 255 256bionic-unit-tests_c_includes := \ 257 $(call include-path-for, libpagemap) \ 258 259bionic-unit-tests_shared_libraries_target := \ 260 libdl \ 261 libpagemap \ 262 263module := bionic-unit-tests 264module_tag := optional 265build_type := target 266build_target := NATIVE_TEST 267include $(LOCAL_PATH)/Android.build.mk 268 269# ----------------------------------------------------------------------------- 270# Tests for the device linked against bionic's static library. Run with: 271# adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static 272# ----------------------------------------------------------------------------- 273bionic-unit-tests-static_whole_static_libraries := \ 274 libBionicTests \ 275 276bionic-unit-tests-static_static_libraries := \ 277 libstlport_static \ 278 libm \ 279 libc \ 280 libstdc++ \ 281 282bionic-unit-tests-static_force_static_executable := true 283 284module := bionic-unit-tests-static 285module_tag := optional 286build_type := target 287build_target := NATIVE_TEST 288include $(LOCAL_PATH)/Android.build.mk 289 290# ----------------------------------------------------------------------------- 291# Tests to run on the host and linked against glibc. Run with: 292# cd bionic/tests; mm bionic-unit-tests-glibc-run 293# ----------------------------------------------------------------------------- 294 295ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64)) 296 297bionic-unit-tests-glibc_src_files := \ 298 atexit_test.cpp \ 299 300bionic-unit-tests-glibc_whole_static_libraries := \ 301 libBionicStandardTests \ 302 303bionic-unit-tests-glibc_ldlibs := \ 304 -lrt -ldl \ 305 306bionic-unit-tests-glibc_cflags := $(test_cflags) 307bionic-unit-tests-glibc_cppflags := $(test_cppflags) 308 309module := bionic-unit-tests-glibc 310module_tag := optional 311build_type := host 312build_target := NATIVE_TEST 313include $(LOCAL_PATH)/Android.build.mk 314 315ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm mips x86)) 316LINKER = linker64 317NATIVE_TEST_SUFFIX=64 318else 319LINKER = linker 320NATIVE_TEST_SUFFIX=32 321endif 322 323# gtest needs ANDROID_DATA/local/tmp for death test output. 324# Make sure to create ANDROID_DATA/local/tmp if doesn't exist. 325# Use the current target out directory as ANDROID_DATA. 326# BIONIC_TEST_FLAGS is either empty or it comes from the user. 327bionic-unit-tests-glibc-run: bionic-unit-tests-glibc 328 mkdir -p $(TARGET_OUT_DATA)/local/tmp 329 ANDROID_DATA=$(TARGET_OUT_DATA) \ 330 ANDROID_ROOT=$(TARGET_OUT) \ 331 $(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS) 332 333# ----------------------------------------------------------------------------- 334# Run the unit tests built against x86 bionic on an x86 host. 335# ----------------------------------------------------------------------------- 336 337ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64)) 338# gtest needs ANDROID_DATA/local/tmp for death test output. 339# Make sure to create ANDROID_DATA/local/tmp if doesn't exist. 340# bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT. 341# BIONIC_TEST_FLAGS is either empty or it comes from the user. 342bionic-unit-tests-run-on-host: bionic-unit-tests $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh 343 if [ ! -d /system -o ! -d /system/bin ]; then \ 344 echo "Attempting to create /system/bin"; \ 345 sudo mkdir -p -m 0777 /system/bin; \ 346 fi 347 mkdir -p $(TARGET_OUT_DATA)/local/tmp 348 cp $(TARGET_OUT_EXECUTABLES)/$(LINKER) /system/bin 349 cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin 350 ANDROID_DATA=$(TARGET_OUT_DATA) \ 351 ANDROID_ROOT=$(TARGET_OUT) \ 352 LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \ 353 $(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS) 354endif 355 356endif # linux-x86 357 358include $(call first-makefiles-under,$(LOCAL_PATH)) 359endif # !BUILD_TINY_ANDROID 360