Android.mk revision 26052616915fe2324755687c7db73d69c521b34d
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 buffer_tests.cpp \ 48 ctype_test.cpp \ 49 dirent_test.cpp \ 50 eventfd_test.cpp \ 51 fcntl_test.cpp \ 52 fenv_test.cpp \ 53 ftw_test.cpp \ 54 getauxval_test.cpp \ 55 getcwd_test.cpp \ 56 inttypes_test.cpp \ 57 libc_logging_test.cpp \ 58 libgen_test.cpp \ 59 locale_test.cpp \ 60 malloc_test.cpp \ 61 math_test.cpp \ 62 netdb_test.cpp \ 63 pthread_test.cpp \ 64 regex_test.cpp \ 65 sched_test.cpp \ 66 signal_test.cpp \ 67 stack_protector_test.cpp \ 68 stack_unwinding_test.cpp \ 69 stack_unwinding_test_impl.c \ 70 stdint_test.cpp \ 71 stdio_test.cpp \ 72 stdlib_test.cpp \ 73 string_test.cpp \ 74 strings_test.cpp \ 75 stubs_test.cpp \ 76 sstream_test.cpp \ 77 sys_epoll_test.cpp \ 78 sys_mman_test.cpp \ 79 sys_resource_test.cpp \ 80 sys_select_test.cpp \ 81 sys_sendfile_test.cpp \ 82 sys_socket_test.cpp \ 83 sys_stat_test.cpp \ 84 sys_statvfs_test.cpp \ 85 sys_syscall_test.cpp \ 86 sys_time_test.cpp \ 87 sys_types_test.cpp \ 88 sys_vfs_test.cpp \ 89 system_properties_test.cpp \ 90 time_test.cpp \ 91 unistd_test.cpp \ 92 wchar_test.cpp \ 93 94libBionicStandardTests_cflags := \ 95 $(test_cflags) \ 96 97libBionicStandardTests_cppflags := \ 98 $(test_cppflags) \ 99 100libBionicStandardTests_ldlibs_host := \ 101 -lrt \ 102 103module := libBionicStandardTests 104module_tag := optional 105build_type := target 106build_target := STATIC_TEST_LIBRARY 107include $(LOCAL_PATH)/Android.build.mk 108build_type := host 109include $(LOCAL_PATH)/Android.build.mk 110 111# ----------------------------------------------------------------------------- 112# Fortify tests. 113# ----------------------------------------------------------------------------- 114$(foreach compiler,gcc clang, \ 115 $(foreach test,1 2, \ 116 $(eval fortify$(test)-tests-$(compiler)_cflags := \ 117 $(test_cflags) \ 118 -U_FORTIFY_SOURCE \ 119 -D_FORTIFY_SOURCE=$(test) \ 120 -DTEST_NAME=Fortify$(test)_$(compiler)); \ 121 $(eval fortify$(test)-tests-$(compiler)_cflags_host := \ 122 -Wno-error); \ 123 $(eval fortify$(test)-tests-$(compiler)_src_files := \ 124 fortify_test.cpp); \ 125 $(eval fortify_libs += fortify$(test)-tests-$(compiler)); \ 126 ) \ 127) 128 129module := fortify1-tests-gcc 130module_tag := optional 131build_type := target 132build_target := STATIC_TEST_LIBRARY 133include $(LOCAL_PATH)/Android.build.mk 134build_type := host 135include $(LOCAL_PATH)/Android.build.mk 136 137module := fortify2-tests-gcc 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 145fortify1-tests-clang_clang_target := true 146fortify1-tests-clang_cflags_host := -D__clang__ 147 148module := fortify1-tests-clang 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 156fortify2-tests-clang_clang_target := true 157 158fortify2-tests-clang_cflags_host := -D__clang__ 159 160module := fortify2-tests-clang 161module_tag := optional 162build_type := target 163build_target := STATIC_TEST_LIBRARY 164include $(LOCAL_PATH)/Android.build.mk 165build_type := host 166include $(LOCAL_PATH)/Android.build.mk 167 168# ----------------------------------------------------------------------------- 169# Library of all tests (excluding the dynamic linker tests). 170# ----------------------------------------------------------------------------- 171libBionicTests_whole_static_libraries := \ 172 libBionicStandardTests \ 173 $(fortify_libs) \ 174 175module := libBionicTests 176module_tag := optional 177build_type := target 178build_target := STATIC_TEST_LIBRARY 179include $(LOCAL_PATH)/Android.build.mk 180build_type := host 181include $(LOCAL_PATH)/Android.build.mk 182 183# ----------------------------------------------------------------------------- 184# Library used by dlfcn tests. 185# ----------------------------------------------------------------------------- 186ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),mips mips64)) 187no-elf-hash-table-library_src_files := \ 188 empty.cpp \ 189 190no-elf-hash-table-library_ldflags := \ 191 -Wl,--hash-style=gnu \ 192 193module := no-elf-hash-table-library 194module_tag := optional 195build_type := target 196build_target := SHARED_LIBRARY 197include $(LOCAL_PATH)/Android.build.mk 198endif 199 200# ----------------------------------------------------------------------------- 201# Library used by dlext tests - with/without GNU RELRO program header 202# ----------------------------------------------------------------------------- 203libdlext_test_src_files := \ 204 dlext_test_library.cpp \ 205 206libdlext_test_ldflags := \ 207 -Wl,-z,relro \ 208 209module := libdlext_test 210module_tag := optional 211build_type := target 212build_target := SHARED_LIBRARY 213include $(LOCAL_PATH)/Android.build.mk 214 215libdlext_test_norelro_src_files := \ 216 dlext_test_library.cpp \ 217 218libdlext_test_norelro_ldflags := \ 219 -Wl,-z,norelro \ 220 221module := libdlext_test_norelro 222module_tag := optional 223build_type := target 224build_target := SHARED_LIBRARY 225include $(LOCAL_PATH)/Android.build.mk 226 227# ----------------------------------------------------------------------------- 228# This library used by atexit tests 229# ----------------------------------------------------------------------------- 230 231libtest_atexit_src_files := \ 232 atexit_testlib.cpp 233 234module := libtest_atexit 235build_type := target 236build_target := SHARED_LIBRARY 237include $(LOCAL_PATH)/Android.build.mk 238 239# ----------------------------------------------------------------------------- 240# Tests for the device using bionic's .so. Run with: 241# adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests 242# ----------------------------------------------------------------------------- 243bionic-unit-tests_whole_static_libraries := \ 244 libBionicTests \ 245 246bionic-unit-tests_src_files := \ 247 atexit_test.cpp \ 248 dlext_test.cpp \ 249 dlfcn_test.cpp \ 250 251bionic-unit-tests_ldflags := \ 252 -Wl,--export-dynamic \ 253 -Wl,-u,DlSymTestFunction \ 254 255bionic-unit-tests_c_includes := \ 256 $(call include-path-for, libpagemap) \ 257 258bionic-unit-tests_shared_libraries_target := \ 259 libdl \ 260 libpagemap \ 261 262module := bionic-unit-tests 263module_tag := optional 264bionic-unit-tests_multilib := both 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 286bionic-unit-tests-static_multilib := both 287build_type := target 288build_target := NATIVE_TEST 289include $(LOCAL_PATH)/Android.build.mk 290 291# ----------------------------------------------------------------------------- 292# Tests to run on the host and linked against glibc. Run with: 293# cd bionic/tests; mm bionic-unit-tests-glibc-run 294# ----------------------------------------------------------------------------- 295 296ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86) 297 298bionic-unit-tests-glibc_src_files := \ 299 atexit_test.cpp \ 300 301bionic-unit-tests-glibc_whole_static_libraries := \ 302 libBionicStandardTests \ 303 304bionic-unit-tests-glibc_ldlibs := \ 305 -lrt -ldl \ 306 307module := bionic-unit-tests-glibc 308module_tag := optional 309build_type := host 310build_target := NATIVE_TEST 311include $(LOCAL_PATH)/Android.build.mk 312 313ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm mips x86)) 314LINKER = linker64 315NATIVE_TEST_SUFFIX=64 316else 317LINKER = linker 318NATIVE_TEST_SUFFIX=32 319endif 320 321# gtest needs ANDROID_DATA/local/tmp for death test output. 322# Make sure to create ANDROID_DATA/local/tmp if doesn't exist. 323# Use the current target out directory as ANDROID_DATA. 324# BIONIC_TEST_FLAGS is either empty or it comes from the user. 325bionic-unit-tests-glibc-run: bionic-unit-tests-glibc 326 mkdir -p $(TARGET_OUT_DATA)/local/tmp 327 ANDROID_DATA=$(TARGET_OUT_DATA) \ 328 ANDROID_ROOT=$(TARGET_OUT) \ 329 $(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS) 330 331# ----------------------------------------------------------------------------- 332# Run the unit tests built against x86 bionic on an x86 host. 333# ----------------------------------------------------------------------------- 334 335ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64)) 336# gtest needs ANDROID_DATA/local/tmp for death test output. 337# Make sure to create ANDROID_DATA/local/tmp if doesn't exist. 338# bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT. 339# BIONIC_TEST_FLAGS is either empty or it comes from the user. 340bionic-unit-tests-run-on-host: bionic-unit-tests $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh 341 if [ ! -d /system -o ! -d /system/bin ]; then \ 342 echo "Attempting to create /system/bin"; \ 343 sudo mkdir -p -m 0777 /system/bin; \ 344 fi 345 mkdir -p $(TARGET_OUT_DATA)/local/tmp 346 cp $(TARGET_OUT_EXECUTABLES)/$(LINKER) /system/bin 347 cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin 348 ANDROID_DATA=$(TARGET_OUT_DATA) \ 349 ANDROID_ROOT=$(TARGET_OUT) \ 350 LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \ 351 $(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS) 352endif 353 354endif # linux-x86 355 356endif # !BUILD_TINY_ANDROID 357