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 17LOCAL_PATH := $(call my-dir) 18 19# ----------------------------------------------------------------------------- 20# Unit tests. 21# ----------------------------------------------------------------------------- 22 23ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64)) 24build_host := true 25else 26build_host := false 27endif 28 29common_additional_dependencies := $(LOCAL_PATH)/Android.mk $(LOCAL_PATH)/Android.build.mk 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 43test_cppflags := \ 44 45libBionicStandardTests_src_files := \ 46 arpa_inet_test.cpp \ 47 buffer_tests.cpp \ 48 bug_26110743_test.cpp \ 49 complex_test.cpp \ 50 ctype_test.cpp \ 51 dirent_test.cpp \ 52 error_test.cpp \ 53 eventfd_test.cpp \ 54 fcntl_test.cpp \ 55 fenv_test.cpp \ 56 ftw_test.cpp \ 57 getauxval_test.cpp \ 58 getcwd_test.cpp \ 59 ifaddrs_test.cpp \ 60 inttypes_test.cpp \ 61 libc_logging_test.cpp \ 62 libgen_basename_test.cpp \ 63 libgen_test.cpp \ 64 locale_test.cpp \ 65 malloc_test.cpp \ 66 math_test.cpp \ 67 mntent_test.cpp \ 68 netdb_test.cpp \ 69 net_if_test.cpp \ 70 netinet_in_test.cpp \ 71 netinet_udp_test.cpp \ 72 pthread_test.cpp \ 73 pty_test.cpp \ 74 regex_test.cpp \ 75 sched_test.cpp \ 76 search_test.cpp \ 77 semaphore_test.cpp \ 78 setjmp_test.cpp \ 79 signal_test.cpp \ 80 stack_protector_test.cpp \ 81 stack_protector_test_helper.cpp \ 82 stack_unwinding_test.cpp \ 83 stdatomic_test.cpp \ 84 stdint_test.cpp \ 85 stdio_nofortify_test.cpp \ 86 stdio_test.cpp \ 87 stdio_ext_test.cpp \ 88 stdlib_test.cpp \ 89 string_nofortify_test.cpp \ 90 string_test.cpp \ 91 string_posix_strerror_r_test.cpp \ 92 strings_nofortify_test.cpp \ 93 strings_test.cpp \ 94 stubs_test.cpp \ 95 sstream_test.cpp \ 96 sys_epoll_test.cpp \ 97 sys_mman_test.cpp \ 98 sys_personality_test.cpp \ 99 sys_prctl_test.cpp \ 100 sys_procfs_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_sysinfo_test.cpp \ 109 sys_sysmacros_test.cpp \ 110 sys_time_test.cpp \ 111 sys_timex_test.cpp \ 112 sys_types_test.cpp \ 113 sys_uio_test.cpp \ 114 sys_vfs_test.cpp \ 115 sys_xattr_test.cpp \ 116 system_properties_test.cpp \ 117 time_test.cpp \ 118 uchar_test.cpp \ 119 uniqueptr_test.cpp \ 120 unistd_nofortify_test.cpp \ 121 unistd_test.cpp \ 122 utmp_test.cpp \ 123 wchar_test.cpp \ 124 125libBionicStandardTests_cflags := \ 126 $(test_cflags) \ 127 128libBionicStandardTests_cppflags := \ 129 $(test_cppflags) \ 130 131libBionicStandardTests_c_includes := \ 132 bionic/libc \ 133 external/tinyxml2 \ 134 135libBionicStandardTests_static_libraries := \ 136 libbase \ 137 138libBionicStandardTests_ldlibs_host := \ 139 -lrt \ 140 141# Clang/llvm has incompatible long double (fp128) for x86_64. 142# https://llvm.org/bugs/show_bug.cgi?id=23897 143# This affects most of math_test.cpp. 144ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86_64)) 145libBionicStandardTests_clang_target := false 146endif 147 148module := libBionicStandardTests 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 156# ----------------------------------------------------------------------------- 157# Fortify tests. 158# ----------------------------------------------------------------------------- 159$(foreach compiler,gcc clang, \ 160 $(foreach test,1 2, \ 161 $(eval fortify$(test)-tests-$(compiler)_cflags := \ 162 $(test_cflags) \ 163 -Wno-error \ 164 -U_FORTIFY_SOURCE \ 165 -D_FORTIFY_SOURCE=$(test) \ 166 -DTEST_NAME=Fortify$(test)_$(compiler)); \ 167 $(eval fortify$(test)-tests-$(compiler)_src_files := \ 168 fortify_test_main.cpp); \ 169 $(eval fortify_libs += fortify$(test)-tests-$(compiler)); \ 170 ) \ 171) 172 173fortify1-tests-gcc_clang_target := false 174module := fortify1-tests-gcc 175module_tag := optional 176build_type := target 177build_target := STATIC_TEST_LIBRARY 178include $(LOCAL_PATH)/Android.build.mk 179build_type := host 180include $(LOCAL_PATH)/Android.build.mk 181 182fortify2-tests-gcc_clang_target := false 183module := fortify2-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 191fortify1-tests-clang_clang_target := true 192fortify1-tests-clang_cflags_host := -D__clang__ 193 194module := fortify1-tests-clang 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 202fortify2-tests-clang_clang_target := true 203 204fortify2-tests-clang_cflags_host := -D__clang__ 205 206module := fortify2-tests-clang 207module_tag := optional 208build_type := target 209build_target := STATIC_TEST_LIBRARY 210include $(LOCAL_PATH)/Android.build.mk 211build_type := host 212include $(LOCAL_PATH)/Android.build.mk 213 214# ----------------------------------------------------------------------------- 215# Library of all tests (excluding the dynamic linker tests). 216# ----------------------------------------------------------------------------- 217libBionicTests_whole_static_libraries := \ 218 libBionicStandardTests \ 219 $(fortify_libs) \ 220 221module := libBionicTests 222module_tag := optional 223build_type := target 224build_target := STATIC_TEST_LIBRARY 225include $(LOCAL_PATH)/Android.build.mk 226build_type := host 227include $(LOCAL_PATH)/Android.build.mk 228 229# ----------------------------------------------------------------------------- 230# Library of bionic customized gtest main function, with simplified output format. 231# ----------------------------------------------------------------------------- 232libBionicGtestMain_src_files := gtest_main.cpp 233 234libBionicGtestMain_cflags := $(test_cflags) 235 236libBionicGtestMain_cppflags := $(test_cppflags) 237 238module := libBionicGtestMain 239module_tag := optional 240build_type := target 241build_target := STATIC_TEST_LIBRARY 242include $(LOCAL_PATH)/Android.build.mk 243build_type := host 244 245ifeq ($(HOST_OS),$(filter $(HOST_OS),linux darwin)) 246saved_build_host := $(build_host) 247build_host := true 248include $(LOCAL_PATH)/Android.build.mk 249build_host := $(saved_build_host) 250endif 251 252# ----------------------------------------------------------------------------- 253# Library of bionic customized gtest main function, with normal gtest output format, 254# which is needed by bionic cts test. 255# ----------------------------------------------------------------------------- 256libBionicCtsGtestMain_src_files := gtest_main.cpp 257 258libBionicCtsGtestMain_cflags := $(test_cflags) 259 260libBionicCtsGtestMain_cppflags := $(test_cppflags) -DUSING_GTEST_OUTPUT_FORMAT \ 261 262module := libBionicCtsGtestMain 263module_tag := optional 264build_type := target 265build_target := STATIC_TEST_LIBRARY 266include $(LOCAL_PATH)/Android.build.mk 267build_type := host 268include $(LOCAL_PATH)/Android.build.mk 269 270# ----------------------------------------------------------------------------- 271# Tests for the device using bionic's .so. Run with: 272# adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests32 273# adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests64 274# adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests-gcc32 275# adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests-gcc64 276# ----------------------------------------------------------------------------- 277common_bionic-unit-tests_whole_static_libraries := \ 278 libBionicTests \ 279 libBionicGtestMain \ 280 281common_bionic-unit-tests_static_libraries := \ 282 libtinyxml2 \ 283 liblog \ 284 libbase \ 285 286# TODO: Include __cxa_thread_atexit_test.cpp to glibc tests once it is upgraded (glibc 2.18+) 287common_bionic-unit-tests_src_files := \ 288 atexit_test.cpp \ 289 dl_test.cpp \ 290 dlext_test.cpp \ 291 __cxa_thread_atexit_test.cpp \ 292 dlfcn_test.cpp \ 293 libdl_test.cpp \ 294 pthread_dlfcn_test.cpp \ 295 thread_local_test.cpp \ 296 297common_bionic-unit-tests_cflags := $(test_cflags) 298 299common_bionic-unit-tests_conlyflags := \ 300 -fexceptions \ 301 -fnon-call-exceptions \ 302 303common_bionic-unit-tests_cppflags := $(test_cppflags) 304 305common_bionic-unit-tests_ldflags := \ 306 -Wl,--export-dynamic 307 308common_bionic-unit-tests_c_includes := \ 309 bionic/libc \ 310 311common_bionic-unit-tests_shared_libraries_target := \ 312 libdl \ 313 libpagemap \ 314 libdl_preempt_test_1 \ 315 libdl_preempt_test_2 \ 316 libdl_test_df_1_global \ 317 318# The order of these libraries matters, do not shuffle them. 319common_bionic-unit-tests_static_libraries_target := \ 320 libbase \ 321 libziparchive \ 322 libz \ 323 libutils \ 324 325module_tag := optional 326build_type := target 327build_target := NATIVE_TEST 328 329module := bionic-unit-tests 330bionic-unit-tests_clang_target := true 331bionic-unit-tests_whole_static_libraries := $(common_bionic-unit-tests_whole_static_libraries) 332bionic-unit-tests_static_libraries := $(common_bionic-unit-tests_static_libraries) 333bionic-unit-tests_src_files := $(common_bionic-unit-tests_src_files) 334bionic-unit-tests_cflags := $(common_bionic-unit-tests_cflags) 335bionic-unit-tests_conlyflags := $(common_bionic-unit-tests_conlyflags) 336bionic-unit-tests_cppflags := $(common_bionic-unit-tests_cppflags) 337bionic-unit-tests_ldflags := $(common_bionic-unit-tests_ldflags) 338bionic-unit-tests_c_includes := $(common_bionic-unit-tests_c_includes) 339bionic-unit-tests_shared_libraries_target := $(common_bionic-unit-tests_shared_libraries_target) 340bionic-unit-tests_static_libraries_target := $(common_bionic-unit-tests_static_libraries_target) 341include $(LOCAL_PATH)/Android.build.mk 342 343module := bionic-unit-tests-gcc 344bionic-unit-tests-gcc_clang_target := false 345bionic-unit-tests-gcc_whole_static_libraries := $(common_bionic-unit-tests_whole_static_libraries) 346bionic-unit-tests-gcc_static_libraries := $(common_bionic-unit-tests_static_libraries) 347bionic-unit-tests-gcc_src_files := $(common_bionic-unit-tests_src_files) 348bionic-unit-tests-gcc_cflags := $(common_bionic-unit-tests_cflags) 349bionic-unit-tests-gcc_conlyflags := $(common_bionic-unit-tests_conlyflags) 350bionic-unit-tests-gcc_cppflags := $(common_bionic-unit-tests_cppflags) 351bionic-unit-tests-gcc_ldflags := $(common_bionic-unit-tests_ldflags) 352bionic-unit-tests-gcc_c_includes := $(common_bionic-unit-tests_c_includes) 353bionic-unit-tests-gcc_shared_libraries_target := $(common_bionic-unit-tests_shared_libraries_target) 354bionic-unit-tests-gcc_static_libraries_target := $(common_bionic-unit-tests_static_libraries_target) 355include $(LOCAL_PATH)/Android.build.mk 356 357# ----------------------------------------------------------------------------- 358# Tests for the device linked against bionic's static library. Run with: 359# adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static32 360# adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static64 361# ----------------------------------------------------------------------------- 362bionic-unit-tests-static_whole_static_libraries := \ 363 libBionicTests \ 364 libBionicGtestMain \ 365 366bionic-unit-tests-static_static_libraries := \ 367 libm \ 368 libc \ 369 libc++_static \ 370 libdl \ 371 libtinyxml2 \ 372 liblog \ 373 libbase \ 374 375bionic-unit-tests-static_force_static_executable := true 376 377# libc and libc++ both define std::nothrow. libc's is a private symbol, but this 378# still causes issues when linking libc.a and libc++.a, since private isn't 379# effective until it has been linked. To fix this, just allow multiple symbol 380# definitions for the static tests. 381bionic-unit-tests-static_ldflags := -Wl,--allow-multiple-definition 382 383module := bionic-unit-tests-static 384module_tag := optional 385build_type := target 386build_target := NATIVE_TEST 387include $(LOCAL_PATH)/Android.build.mk 388 389# ----------------------------------------------------------------------------- 390# Tests to run on the host and linked against glibc. Run with: 391# cd bionic/tests; mm bionic-unit-tests-glibc-run 392# ----------------------------------------------------------------------------- 393 394ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64)) 395 396bionic-unit-tests-glibc_src_files := \ 397 atexit_test.cpp \ 398 dlfcn_test.cpp \ 399 dl_test.cpp \ 400 pthread_dlfcn_test.cpp \ 401 402bionic-unit-tests-glibc_shared_libraries := \ 403 libdl_preempt_test_1 \ 404 libdl_preempt_test_2 405 406bionic-unit-tests-glibc_shared_libraries += libdl_test_df_1_global 407 408bionic-unit-tests-glibc_whole_static_libraries := \ 409 libBionicStandardTests \ 410 libBionicGtestMain \ 411 $(fortify_libs) \ 412 413bionic-unit-tests-glibc_static_libraries := \ 414 libbase \ 415 liblog \ 416 libcutils \ 417 418bionic-unit-tests-glibc_ldlibs := \ 419 -lrt -ldl -lutil \ 420 421bionic-unit-tests-glibc_c_includes := \ 422 bionic/libc \ 423 424bionic-unit-tests-glibc_cflags := $(test_cflags) 425bionic-unit-tests-glibc_cppflags := $(test_cppflags) 426bionic-unit-tests-glibc_ldflags := -Wl,--export-dynamic 427 428bionic-unit-tests-glibc_allow_asan := true 429 430module := bionic-unit-tests-glibc 431module_tag := optional 432build_type := host 433build_target := NATIVE_TEST 434include $(LOCAL_PATH)/Android.build.mk 435 436# ----------------------------------------------------------------------------- 437# Compile time tests. 438# ----------------------------------------------------------------------------- 439 440# Some of these are intentionally using = instead of := since we need access to 441# some variables not initialtized until we're in the build system. 442 443include $(CLEAR_VARS) 444LOCAL_ADDITIONAL_DEPENDENCIES := \ 445 $(LOCAL_PATH)/Android.mk \ 446 $(LOCAL_PATH)/file-check-cxx \ 447 | $(HOST_OUT_EXECUTABLES)/FileCheck$(HOST_EXECUTABLE_SUFFIX) \ 448 449LOCAL_CXX = $(LOCAL_PATH)/file-check-cxx \ 450 $(HOST_OUT_EXECUTABLES)/FileCheck \ 451 $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_CXX) \ 452 GCC \ 453 454LOCAL_CLANG := false 455LOCAL_MODULE := bionic-compile-time-tests-g++ 456LOCAL_CPPFLAGS := -Wall 457# Disable color diagnostics so the warnings output matches the source 458LOCAL_CPPFLAGS += -fdiagnostics-color=never 459LOCAL_SRC_FILES := fortify_compilation_test.cpp 460include $(BUILD_STATIC_LIBRARY) 461 462include $(CLEAR_VARS) 463LOCAL_ADDITIONAL_DEPENDENCIES := \ 464 $(LOCAL_PATH)/Android.mk \ 465 $(LOCAL_PATH)/file-check-cxx \ 466 | $(HOST_OUT_EXECUTABLES)/FileCheck$(HOST_EXECUTABLE_SUFFIX) \ 467 468LOCAL_CXX := $(LOCAL_PATH)/file-check-cxx \ 469 $(HOST_OUT_EXECUTABLES)/FileCheck \ 470 $(LLVM_PREBUILTS_PATH)/clang++ \ 471 CLANG \ 472 473LOCAL_CLANG := true 474LOCAL_MODULE := bionic-compile-time-tests-clang++ 475LOCAL_CPPFLAGS := -Wall 476# Disable color diagnostics so the warnings output matches the source 477LOCAL_CPPFLAGS += -fno-color-diagnostics 478# FileCheck will error if there aren't any CLANG: lines in the file, but there 479# don't appear to be any cases where clang _does_ emit warnings for sn?printf :( 480LOCAL_SRC_FILES := 481include $(BUILD_STATIC_LIBRARY) 482 483# ----------------------------------------------------------------------------- 484# Host glibc tests. 485# ----------------------------------------------------------------------------- 486 487# gtest needs ANDROID_DATA/local/tmp for death test output. 488# Make sure to create ANDROID_DATA/local/tmp if doesn't exist. 489# Use the current target out directory as ANDROID_DATA. 490# BIONIC_TEST_FLAGS is either empty or it comes from the user. 491.PHONY: bionic-unit-tests-glibc-run 492bionic-unit-tests-glibc-run: bionic-unit-tests-glibc 493 mkdir -p $(TARGET_OUT_DATA)/local/tmp 494 ANDROID_DATA=$(TARGET_OUT_DATA) \ 495 ANDROID_ROOT=$(TARGET_OUT) \ 496 $(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc64 $(BIONIC_TEST_FLAGS) 497 498# ----------------------------------------------------------------------------- 499# Run the unit tests built against x86 bionic on an x86 host. 500# ----------------------------------------------------------------------------- 501 502include $(LOCAL_PATH)/../build/run-on-host.mk 503 504ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64)) 505 506TEST_TIMEOUT := 0 507 508# BIONIC_TEST_FLAGS is either empty or it comes from the user. 509.PHONY: bionic-unit-tests-run-on-host32 510bionic-unit-tests-run-on-host32: bionic-unit-tests bionic-prepare-run-on-host 511 ANDROID_DATA=$(TARGET_OUT_DATA) \ 512 ANDROID_DNS_MODE=local \ 513 ANDROID_ROOT=$(TARGET_OUT) \ 514 timeout $(TEST_TIMEOUT) \ 515 $(TARGET_OUT_DATA)/nativetest/bionic-unit-tests/bionic-unit-tests32 $(BIONIC_TEST_FLAGS) 516 517ifeq ($(TARGET_IS_64_BIT),true) 518# add target to run lp64 tests 519.PHONY: bionic-unit-tests-run-on-host64 520bionic-unit-tests-run-on-host64: bionic-unit-tests bionic-prepare-run-on-host 521 ANDROID_DATA=$(TARGET_OUT_DATA) \ 522 ANDROID_DNS_MODE=local \ 523 ANDROID_ROOT=$(TARGET_OUT) \ 524 timeout $(TEST_TIMEOUT) \ 525 $(TARGET_OUT_DATA)/nativetest64/bionic-unit-tests/bionic-unit-tests64 $(BIONIC_TEST_FLAGS) 526endif 527 528endif # x86 x86_64 529endif # linux-x86 530 531include $(call first-makefiles-under,$(LOCAL_PATH)) 532