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 17package { 18 default_team: "trendy_team_native_tools_libraries", 19 default_applicable_licenses: ["bionic_tests_license"], 20} 21 22license { 23 name: "bionic_tests_license", 24 visibility: [":__subpackages__"], 25 license_kinds: [ 26 "SPDX-license-identifier-Apache-2.0", 27 "SPDX-license-identifier-BSD", 28 ], 29 license_text: [ 30 "NOTICE", 31 ], 32} 33 34cc_defaults { 35 name: "bionic_tests_defaults", 36 host_supported: true, 37 target: { 38 darwin: { 39 enabled: false, 40 }, 41 android: { 42 header_libs: ["bionic_libc_platform_headers"], 43 }, 44 linux_bionic: { 45 header_libs: ["bionic_libc_platform_headers"], 46 }, 47 }, 48 cflags: [ 49 "-fstack-protector-all", 50 "-g", 51 "-Wall", 52 "-Wextra", 53 "-Wunused", 54 "-Werror", 55 "-fno-builtin", 56 57 // We want to test deprecated API too. 58 "-Wno-deprecated-declarations", 59 60 // Needed to test pthread_internal_t layout. 61 "-Wno-invalid-offsetof", 62 63 // This warning does not provide any benefit to the tests. 64 "-Wno-reorder-init-list", 65 ], 66 header_libs: [ 67 "libcutils_headers", 68 "gwp_asan_headers", 69 ], 70 stl: "libc++", 71 72 // Ensure that the tests exercise shadow call stack support. 73 // We don't use `scs: true` here because that would give us a second 74 // variant of this library where we actually just want to say "this 75 // library should always be built this way". 76 arch: { 77 arm64: { 78 cflags: ["-fsanitize=shadow-call-stack"], 79 }, 80 riscv64: { 81 cflags: ["-fsanitize=shadow-call-stack"], 82 }, 83 }, 84 sanitize: { 85 address: false, 86 }, 87 88 // Use the bootstrap version of bionic because some tests call private APIs 89 // that aren't exposed by the APEX bionic stubs. 90 bootstrap: true, 91} 92 93// ----------------------------------------------------------------------------- 94// Prebuilt shared libraries for use in tests. 95// ----------------------------------------------------------------------------- 96 97filegroup { 98 name: "bionic_prebuilt_test_elf_files_arm64", 99 srcs: [ 100 "prebuilt-elf-files/arm64/*.so", 101 ], 102} 103 104cc_prebuilt_test_library_shared { 105 name: "libtest_invalid-rw_load_segment", 106 strip: { 107 none: true, 108 }, 109 check_elf_files: false, 110 relative_install_path: "bionic-loader-test-libs/prebuilt-elf-files", 111 arch: { 112 arm: { 113 srcs: ["prebuilt-elf-files/arm/libtest_invalid-rw_load_segment.so"], 114 }, 115 arm64: { 116 srcs: ["prebuilt-elf-files/arm64/libtest_invalid-rw_load_segment.so"], 117 }, 118 riscv64: { 119 srcs: ["prebuilt-elf-files/riscv64/libtest_invalid-rw_load_segment.so"], 120 }, 121 x86: { 122 srcs: ["prebuilt-elf-files/x86/libtest_invalid-rw_load_segment.so"], 123 }, 124 x86_64: { 125 srcs: ["prebuilt-elf-files/x86_64/libtest_invalid-rw_load_segment.so"], 126 }, 127 }, 128} 129 130cc_prebuilt_test_library_shared { 131 name: "libtest_invalid-unaligned_shdr_offset", 132 strip: { 133 none: true, 134 }, 135 check_elf_files: false, 136 relative_install_path: "bionic-loader-test-libs/prebuilt-elf-files", 137 arch: { 138 arm: { 139 srcs: ["prebuilt-elf-files/arm/libtest_invalid-unaligned_shdr_offset.so"], 140 }, 141 arm64: { 142 srcs: ["prebuilt-elf-files/arm64/libtest_invalid-unaligned_shdr_offset.so"], 143 }, 144 riscv64: { 145 srcs: ["prebuilt-elf-files/riscv64/libtest_invalid-unaligned_shdr_offset.so"], 146 }, 147 x86: { 148 srcs: ["prebuilt-elf-files/x86/libtest_invalid-unaligned_shdr_offset.so"], 149 }, 150 x86_64: { 151 srcs: ["prebuilt-elf-files/x86_64/libtest_invalid-unaligned_shdr_offset.so"], 152 }, 153 }, 154} 155 156cc_prebuilt_test_library_shared { 157 name: "libtest_invalid-zero_shentsize", 158 strip: { 159 none: true, 160 }, 161 check_elf_files: false, 162 relative_install_path: "bionic-loader-test-libs/prebuilt-elf-files", 163 arch: { 164 arm: { 165 srcs: ["prebuilt-elf-files/arm/libtest_invalid-zero_shentsize.so"], 166 }, 167 arm64: { 168 srcs: ["prebuilt-elf-files/arm64/libtest_invalid-zero_shentsize.so"], 169 }, 170 riscv64: { 171 srcs: ["prebuilt-elf-files/riscv64/libtest_invalid-zero_shentsize.so"], 172 }, 173 x86: { 174 srcs: ["prebuilt-elf-files/x86/libtest_invalid-zero_shentsize.so"], 175 }, 176 x86_64: { 177 srcs: ["prebuilt-elf-files/x86_64/libtest_invalid-zero_shentsize.so"], 178 }, 179 }, 180} 181 182cc_prebuilt_test_library_shared { 183 name: "libtest_invalid-zero_shstrndx", 184 strip: { 185 none: true, 186 }, 187 check_elf_files: false, 188 relative_install_path: "bionic-loader-test-libs/prebuilt-elf-files", 189 arch: { 190 arm: { 191 srcs: ["prebuilt-elf-files/arm/libtest_invalid-zero_shstrndx.so"], 192 }, 193 arm64: { 194 srcs: ["prebuilt-elf-files/arm64/libtest_invalid-zero_shstrndx.so"], 195 }, 196 riscv64: { 197 srcs: ["prebuilt-elf-files/riscv64/libtest_invalid-zero_shstrndx.so"], 198 }, 199 x86: { 200 srcs: ["prebuilt-elf-files/x86/libtest_invalid-zero_shstrndx.so"], 201 }, 202 x86_64: { 203 srcs: ["prebuilt-elf-files/x86_64/libtest_invalid-zero_shstrndx.so"], 204 }, 205 }, 206} 207 208cc_prebuilt_test_library_shared { 209 name: "libtest_invalid-empty_shdr_table", 210 strip: { 211 none: true, 212 }, 213 check_elf_files: false, 214 relative_install_path: "bionic-loader-test-libs/prebuilt-elf-files", 215 arch: { 216 arm: { 217 srcs: ["prebuilt-elf-files/arm/libtest_invalid-empty_shdr_table.so"], 218 }, 219 arm64: { 220 srcs: ["prebuilt-elf-files/arm64/libtest_invalid-empty_shdr_table.so"], 221 }, 222 riscv64: { 223 srcs: ["prebuilt-elf-files/riscv64/libtest_invalid-empty_shdr_table.so"], 224 }, 225 x86: { 226 srcs: ["prebuilt-elf-files/x86/libtest_invalid-empty_shdr_table.so"], 227 }, 228 x86_64: { 229 srcs: ["prebuilt-elf-files/x86_64/libtest_invalid-empty_shdr_table.so"], 230 }, 231 }, 232} 233 234cc_prebuilt_test_library_shared { 235 name: "libtest_invalid-zero_shdr_table_offset", 236 strip: { 237 none: true, 238 }, 239 check_elf_files: false, 240 relative_install_path: "bionic-loader-test-libs/prebuilt-elf-files", 241 arch: { 242 arm: { 243 srcs: ["prebuilt-elf-files/arm/libtest_invalid-zero_shdr_table_offset.so"], 244 }, 245 arm64: { 246 srcs: ["prebuilt-elf-files/arm64/libtest_invalid-zero_shdr_table_offset.so"], 247 }, 248 riscv64: { 249 srcs: ["prebuilt-elf-files/riscv64/libtest_invalid-zero_shdr_table_offset.so"], 250 }, 251 x86: { 252 srcs: ["prebuilt-elf-files/x86/libtest_invalid-zero_shdr_table_offset.so"], 253 }, 254 x86_64: { 255 srcs: ["prebuilt-elf-files/x86_64/libtest_invalid-zero_shdr_table_offset.so"], 256 }, 257 }, 258} 259 260cc_prebuilt_test_library_shared { 261 name: "libtest_invalid-zero_shdr_table_content", 262 strip: { 263 none: true, 264 }, 265 check_elf_files: false, 266 relative_install_path: "bionic-loader-test-libs/prebuilt-elf-files", 267 arch: { 268 arm: { 269 srcs: ["prebuilt-elf-files/arm/libtest_invalid-zero_shdr_table_content.so"], 270 }, 271 arm64: { 272 srcs: ["prebuilt-elf-files/arm64/libtest_invalid-zero_shdr_table_content.so"], 273 }, 274 riscv64: { 275 srcs: ["prebuilt-elf-files/riscv64/libtest_invalid-zero_shdr_table_content.so"], 276 }, 277 x86: { 278 srcs: ["prebuilt-elf-files/x86/libtest_invalid-zero_shdr_table_content.so"], 279 }, 280 x86_64: { 281 srcs: ["prebuilt-elf-files/x86_64/libtest_invalid-zero_shdr_table_content.so"], 282 }, 283 }, 284} 285 286cc_prebuilt_test_library_shared { 287 name: "libtest_invalid-textrels", 288 strip: { 289 none: true, 290 }, 291 check_elf_files: false, 292 relative_install_path: "bionic-loader-test-libs/prebuilt-elf-files", 293 arch: { 294 arm: { 295 srcs: ["prebuilt-elf-files/arm/libtest_invalid-textrels.so"], 296 }, 297 arm64: { 298 srcs: ["prebuilt-elf-files/arm64/libtest_invalid-textrels.so"], 299 }, 300 riscv64: { 301 srcs: ["prebuilt-elf-files/riscv64/libtest_invalid-textrels.so"], 302 }, 303 x86: { 304 srcs: ["prebuilt-elf-files/x86/libtest_invalid-textrels.so"], 305 }, 306 x86_64: { 307 srcs: ["prebuilt-elf-files/x86_64/libtest_invalid-textrels.so"], 308 }, 309 }, 310} 311 312cc_prebuilt_test_library_shared { 313 name: "libtest_invalid-textrels2", 314 strip: { 315 none: true, 316 }, 317 check_elf_files: false, 318 relative_install_path: "bionic-loader-test-libs/prebuilt-elf-files", 319 arch: { 320 arm: { 321 srcs: ["prebuilt-elf-files/arm/libtest_invalid-textrels2.so"], 322 }, 323 arm64: { 324 srcs: ["prebuilt-elf-files/arm64/libtest_invalid-textrels2.so"], 325 }, 326 riscv64: { 327 srcs: ["prebuilt-elf-files/riscv64/libtest_invalid-textrels2.so"], 328 }, 329 x86: { 330 srcs: ["prebuilt-elf-files/x86/libtest_invalid-textrels2.so"], 331 }, 332 x86_64: { 333 srcs: ["prebuilt-elf-files/x86_64/libtest_invalid-textrels2.so"], 334 }, 335 }, 336} 337 338cc_prebuilt_test_library_shared { 339 name: "libtest_invalid-local-tls", 340 strip: { 341 none: true, 342 }, 343 check_elf_files: false, 344 relative_install_path: "bionic-loader-test-libs/prebuilt-elf-files", 345 arch: { 346 arm: { 347 srcs: ["prebuilt-elf-files/arm/libtest_invalid-local-tls.so"], 348 }, 349 arm64: { 350 srcs: ["prebuilt-elf-files/arm64/libtest_invalid-local-tls.so"], 351 }, 352 x86: { 353 srcs: ["prebuilt-elf-files/x86/libtest_invalid-local-tls.so"], 354 }, 355 x86_64: { 356 srcs: ["prebuilt-elf-files/x86_64/libtest_invalid-local-tls.so"], 357 }, 358 }, 359} 360 361// ----------------------------------------------------------------------------- 362// All standard tests. 363// ----------------------------------------------------------------------------- 364 365// Test diagnostics emitted by clang. The library that results is useless; we 366// just want to run '-Xclang -verify', which will fail if the diagnostics don't 367// match up with what the source file says they should be. 368cc_test_library { 369 name: "clang_diagnostic_tests", 370 cflags: [ 371 "-Xclang -verify", 372 ], 373 srcs: ["sys_ioctl_diag_test.cpp"], 374} 375 376cc_test_library { 377 name: "libBionicStandardTests", 378 defaults: [ 379 "bionic_tests_defaults", 380 "large_system_property_node_defaults", 381 ], 382 srcs: [ 383 "__aeabi_read_tp_test.cpp", 384 "__cxa_atexit_test.cpp", 385 "__cxa_demangle_test.cpp", 386 "alloca_test.cpp", 387 "android_get_device_api_level.cpp", 388 "android_set_abort_message_test.cpp", 389 "arpa_inet_test.cpp", 390 "async_safe_test.cpp", 391 "assert_test.cpp", 392 "buffer_tests.cpp", 393 "bug_26110743_test.cpp", 394 "byteswap_test.cpp", 395 "complex_test.cpp", 396 // Disabled while investigating 397 // b/378304366, b/375525252 398 // "cpu_target_features_test.cpp", 399 "ctype_test.cpp", 400 "dirent_test.cpp", 401 "elf_test.cpp", 402 "endian_test.cpp", 403 "errno_test.cpp", 404 "error_test.cpp", 405 "eventfd_test.cpp", 406 "fcntl_test.cpp", 407 "fdsan_test.cpp", 408 "fdtrack_test.cpp", 409 "fenv_test.cpp", 410 "_FILE_OFFSET_BITS_test.cpp", 411 "float_test.cpp", 412 "fnmatch_test.cpp", 413 "fts_test.cpp", 414 "ftw_test.cpp", 415 "getauxval_test.cpp", 416 "getcwd_test.cpp", 417 "glob_test.cpp", 418 "grp_pwd_test.cpp", 419 "grp_pwd_file_test.cpp", 420 "heap_tagging_level_test.cpp", 421 "iconv_test.cpp", 422 "ifaddrs_test.cpp", 423 "ifunc_test.cpp", 424 "inttypes_test.cpp", 425 "iso646_test.c", 426 "langinfo_test.cpp", 427 "leak_test.cpp", 428 "libgen_basename_test.cpp", 429 "libgen_test.cpp", 430 "limits_test.cpp", 431 "linux_swab_test.cpp", 432 "locale_test.cpp", 433 "malloc_iterate_test.cpp", 434 "malloc_test.cpp", 435 "math_test.cpp", 436 "membarrier_test.cpp", 437 "memtag_globals_test.cpp", 438 "memtag_stack_test.cpp", 439 "mntent_test.cpp", 440 "mte_test.cpp", 441 "netdb_test.cpp", 442 "net_if_test.cpp", 443 "netinet_ether_test.cpp", 444 "netinet_igmp_test.cpp", 445 "netinet_in_test.cpp", 446 "netinet_ip_icmp_test.cpp", 447 "netinet_udp_test.cpp", 448 "nl_types_test.cpp", 449 "pidfd_test.cpp", 450 "poll_test.cpp", 451 "prio_ctor_test.cpp", 452 "pthread_test.cpp", 453 "pty_test.cpp", 454 "regex_test.cpp", 455 "resolv_test.cpp", 456 "sched_test.cpp", 457 "scs_test.cpp", 458 "scsi_sg_test.cpp", 459 "search_test.cpp", 460 "semaphore_test.cpp", 461 "setjmp_test.cpp", 462 "signal_test.cpp", 463 "spawn_test.cpp", 464 "stack_protector_test.cpp", 465 "stack_protector_test_helper.cpp", 466 "stack_unwinding_test.cpp", 467 "stdalign_test.cpp", 468 "stdarg_test.cpp", 469 "stdatomic_test.cpp", 470 "stdbool_test.c", 471 "stdint_test.cpp", 472 "stdio_nofortify_test.cpp", 473 "stdio_test.cpp", 474 "stdio_ext_test.cpp", 475 "stdlib_test.cpp", 476 "stdnoreturn_test.cpp", 477 "string_nofortify_test.cpp", 478 "string_test.cpp", 479 "string_posix_strerror_r_test.cpp", 480 "string_posix_strerror_r_wrapper.cpp", 481 "strings_nofortify_test.cpp", 482 "strings_test.cpp", 483 "struct_layout_test.cpp", 484 "sstream_test.cpp", 485 "sys_auxv_test.cpp", 486 "sys_cachectl_test.cpp", 487 "sys_epoll_test.cpp", 488 "sys_hwprobe_test.cpp", 489 "sys_io_test.cpp", 490 "sys_mman_test.cpp", 491 "sys_msg_test.cpp", 492 "sys_param_test.cpp", 493 "sys_personality_test.cpp", 494 "sys_prctl_test.cpp", 495 "sys_procfs_test.cpp", 496 "sys_ptrace_test.cpp", 497 "sys_quota_test.cpp", 498 "sys_random_test.cpp", 499 "sys_resource_test.cpp", 500 "sys_select_test.cpp", 501 "sys_sem_test.cpp", 502 "sys_sendfile_test.cpp", 503 "sys_shm_test.cpp", 504 "sys_signalfd_test.cpp", 505 "sys_socket_test.cpp", 506 "sys_stat_test.cpp", 507 "sys_statvfs_test.cpp", 508 "sys_syscall_test.cpp", 509 "sys_sysinfo_test.cpp", 510 "sys_sysmacros_test.cpp", 511 "sys_time_test.cpp", 512 "sys_timex_test.cpp", 513 "sys_ttydefaults_test.cpp", 514 "sys_types_test.cpp", 515 "sys_uio_test.cpp", 516 "sys_un_test.cpp", 517 "sys_vfs_test.cpp", 518 "sys_wait_test.cpp", 519 "sys_xattr_test.cpp", 520 "syslog_test.cpp", 521 "system_properties_test.cpp", 522 "system_properties_test2.cpp", 523 "termios_test.cpp", 524 "tgmath_test.c", 525 "threads_test.cpp", 526 "time_test.cpp", 527 "uchar_test.cpp", 528 "unistd_nofortify_test.cpp", 529 "unistd_test.cpp", 530 "utils.cpp", 531 "utmp_test.cpp", 532 "utmpx_test.cpp", 533 "wchar_test.cpp", 534 "wctype_test.cpp", 535 ], 536 537 include_dirs: [ 538 "bionic/libc", 539 ], 540 541 target: { 542 bionic: { 543 whole_static_libs: [ 544 "libasync_safe", 545 "libprocinfo", 546 "libsystemproperties", 547 ], 548 }, 549 musl: { 550 exclude_srcs: [ 551 // musl doesn't have error.h 552 "error_test.cpp", 553 554 // musl doesn't define noreturn for C++ 555 "stdnoreturn_test.cpp", 556 557 // unsupported relocation type 37 558 "ifunc_test.cpp", 559 560 // musl #defines utmp to utmpx, causing a collision with 561 // utmpx_test.cpp 562 "utmp_test.cpp", 563 ], 564 }, 565 }, 566 567 static_libs: [ 568 "libtinyxml2", 569 "liblog", 570 "libbase", 571 ], 572 shared: { 573 enabled: false, 574 }, 575 576 generated_headers: ["generated_android_ids"], 577} 578 579cc_test_library { 580 name: "libBionicElfTlsTests", 581 defaults: ["bionic_tests_defaults"], 582 srcs: [ 583 "elftls_test.cpp", 584 ], 585 include_dirs: [ 586 "bionic/libc", 587 ], 588 static_libs: [ 589 "libbase", 590 ], 591 shared: { 592 enabled: false, 593 }, 594} 595 596cc_test_library { 597 name: "libBionicElfTlsLoaderTests", 598 defaults: ["bionic_tests_defaults"], 599 srcs: [ 600 "elftls_dl_test.cpp", 601 ], 602 include_dirs: [ 603 "bionic/libc", 604 ], 605 static_libs: [ 606 "liblog", 607 "libbase", 608 ], 609 shared: { 610 enabled: false, 611 }, 612} 613 614cc_test_library { 615 name: "libBionicFramePointerTests", 616 defaults: ["bionic_tests_defaults"], 617 srcs: [ 618 "android_unsafe_frame_pointer_chase_test.cpp", 619 ], 620 include_dirs: [ 621 "bionic/libc", 622 ], 623 cflags: [ 624 "-fno-omit-frame-pointer", 625 ], 626} 627 628// ----------------------------------------------------------------------------- 629// Fortify tests. 630// ----------------------------------------------------------------------------- 631 632cc_defaults { 633 name: "bionic_clang_fortify_tests_w_flags", 634 cflags: [ 635 "-Wno-builtin-memcpy-chk-size", 636 "-Wno-format-security", 637 "-Wno-format-zero-length", 638 "-Wno-fortify-source", 639 "-Wno-memset-transposed-args", 640 "-Wno-strlcpy-strlcat-size", 641 "-Wno-strncat-size", 642 ], 643 static_libs: [ 644 "libbase", 645 ], 646} 647 648cc_defaults { 649 name: "bionic_fortify_tests_defaults", 650 cflags: [ 651 "-U_FORTIFY_SOURCE", 652 ], 653 srcs: ["fortify_test_main.cpp"], 654 static_libs: [ 655 "libbase", 656 ], 657 target: { 658 musl: { 659 // Musl doesn't have fortify 660 enabled: false, 661 }, 662 }, 663} 664 665// Ensure we don't use FORTIFY'ed functions with the clang static analyzer: 666// it can confuse these tools pretty easily. If this builds successfully, then 667// __clang_analyzer__ overrode FORTIFY. Otherwise, FORTIFY was incorrectly 668// enabled. The library that results from building this is meant to be unused. 669cc_test_library { 670 name: "fortify_disabled_for_clang_analyzer", 671 defaults: [ 672 "bionic_clang_fortify_tests_w_flags", 673 ], 674 cflags: [ 675 "-Werror", 676 "-D_FORTIFY_SOURCE=2", 677 "-D__clang_analyzer__", 678 ], 679 srcs: ["clang_fortify_tests.cpp"], 680} 681 682cc_test_library { 683 name: "libfortify1-tests-clang", 684 defaults: [ 685 "bionic_fortify_tests_defaults", 686 "bionic_tests_defaults", 687 ], 688 cflags: [ 689 "-D_FORTIFY_SOURCE=1", 690 "-DTEST_NAME=Fortify1_clang", 691 ], 692 shared: { 693 enabled: false, 694 }, 695} 696 697cc_test_library { 698 name: "libfortify2-tests-clang", 699 defaults: [ 700 "bionic_fortify_tests_defaults", 701 "bionic_tests_defaults", 702 ], 703 cflags: [ 704 "-D_FORTIFY_SOURCE=2", 705 "-DTEST_NAME=Fortify2_clang", 706 ], 707 shared: { 708 enabled: false, 709 }, 710} 711 712cc_defaults { 713 name: "bionic_new_fortify_tests_defaults", 714 defaults: [ 715 "bionic_clang_fortify_tests_w_flags", 716 ], 717 cflags: [ 718 "-U_FORTIFY_SOURCE", 719 ], 720 srcs: ["clang_fortify_tests.cpp"], 721} 722 723cc_test_library { 724 name: "libfortify1-new-tests-clang", 725 defaults: [ 726 "bionic_new_fortify_tests_defaults", 727 "bionic_tests_defaults", 728 ], 729 cflags: [ 730 "-D_FORTIFY_SOURCE=1", 731 "-DTEST_NAME=Fortify1_clang_new", 732 ], 733 shared: { 734 enabled: false, 735 }, 736} 737 738cc_test_library { 739 name: "libfortify2-new-tests-clang", 740 defaults: [ 741 "bionic_new_fortify_tests_defaults", 742 "bionic_tests_defaults", 743 ], 744 cflags: [ 745 "-D_FORTIFY_SOURCE=2", 746 "-DTEST_NAME=Fortify2_clang_new", 747 ], 748 shared: { 749 enabled: false, 750 }, 751} 752 753cc_defaults { 754 name: "bionic_fortify_c_tests_defaults", 755 defaults: [ 756 "bionic_clang_fortify_tests_w_flags", 757 "bionic_tests_defaults", 758 ], 759 cflags: [ 760 "-U_FORTIFY_SOURCE", 761 // -fbuiltin is required here to counteract -fno-builtin from 762 // `bionic_tests_defaults`. With `-fno-builtin`, Clang won't 763 // const-evaluate calls to `strlen`, which is tested for here. 764 "-fbuiltin", 765 ], 766 srcs: [ 767 "clang_fortify_c_only_tests.c", 768 ], 769 shared: { 770 enabled: false, 771 }, 772} 773 774cc_test_library { 775 name: "libfortify1-c-tests-clang", 776 defaults: ["bionic_fortify_c_tests_defaults"], 777 cflags: ["-D_FORTIFY_SOURCE=1"], 778} 779 780cc_test_library { 781 name: "libfortify2-c-tests-clang", 782 defaults: ["bionic_fortify_c_tests_defaults"], 783 cflags: ["-D_FORTIFY_SOURCE=2"], 784} 785 786// ----------------------------------------------------------------------------- 787// Library of all tests (excluding the dynamic linker tests). 788// ----------------------------------------------------------------------------- 789cc_test_library { 790 name: "libBionicTests", 791 defaults: ["bionic_tests_defaults"], 792 host_supported: false, 793 whole_static_libs: [ 794 "libBionicStandardTests", 795 "libBionicElfTlsTests", 796 "libBionicFramePointerTests", 797 "libfortify1-c-tests-clang", 798 "libfortify1-tests-clang", 799 "libfortify1-new-tests-clang", 800 "libfortify2-c-tests-clang", 801 "libfortify2-tests-clang", 802 "libfortify2-new-tests-clang", 803 ], 804 shared: { 805 enabled: false, 806 }, 807} 808 809cc_test_library { 810 name: "libBionicLoaderTests", 811 defaults: [ 812 "bionic_tests_defaults", 813 ], 814 srcs: [ 815 "atexit_test.cpp", 816 "dl_test.cpp", 817 "dlfcn_symlink_support.cpp", 818 "dlfcn_test.cpp", 819 "execinfo_test.cpp", 820 "link_test.cpp", 821 "page_size_16kib_compat_test.cpp", 822 "pthread_dlfcn_test.cpp", 823 ], 824 static_libs: [ 825 "libbase", 826 "libprocinfo", 827 ], 828 include_dirs: [ 829 "bionic/libc", 830 "bionic/tests/libs", 831 ], 832 shared: { 833 enabled: false, 834 }, 835 target: { 836 android: { 837 srcs: [ 838 "cfi_test.cpp", 839 "dlext_test.cpp", 840 "libdl_test.cpp", 841 ], 842 static_libs: [ 843 "libmeminfo", 844 "libprocinfo", 845 "libziparchive", 846 ], 847 }, 848 }, 849} 850 851// ----------------------------------------------------------------------------- 852// Library of bionic customized gtest main function, with normal gtest output format, 853// which is needed by bionic cts test. 854// ----------------------------------------------------------------------------- 855cc_test_library { 856 name: "libBionicCtsGtestMain", 857 defaults: ["bionic_tests_defaults"], 858 srcs: [ 859 "gtest_globals.cpp", 860 "gtest_main.cpp", 861 ], 862 shared: { 863 enabled: false, 864 }, 865 whole_static_libs: [ 866 "libbase", 867 "libgtest_isolated", 868 ], 869} 870 871cc_defaults { 872 name: "bionic_unit_tests_data", 873 data_bins: [ 874 "cfi_test_helper", 875 "cfi_test_helper2", 876 "elftls_align_test_helper", 877 "elftls_dlopen_ie_error_helper", 878 "elftls_dtv_resize_helper", 879 "elftls_skew_align_test_helper", 880 "exec_linker_helper", 881 "exec_linker_helper_lib", 882 "heap_tagging_async_helper", 883 "heap_tagging_disabled_helper", 884 "heap_tagging_static_async_helper", 885 "heap_tagging_static_disabled_helper", 886 "heap_tagging_static_sync_helper", 887 "heap_tagging_sync_helper", 888 "stack_tagging_helper", 889 "stack_tagging_static_helper", 890 "ld_config_test_helper", 891 "ld_config_test_helper_lib1", 892 "ld_config_test_helper_lib2", 893 "ld_config_test_helper_lib3", 894 "ld_preload_test_helper", 895 "ld_preload_test_helper_lib1", 896 "ld_preload_test_helper_lib2", 897 "memtag_globals_binary", 898 "memtag_globals_binary_static", 899 "memtag_globals_dso", 900 "mte_globals_relr_regression_test_b_314038442", 901 "mte_globals_relr_regression_test_b_314038442_mte", 902 "ns_hidden_child_helper", 903 "preinit_getauxval_test_helper", 904 "preinit_syscall_test_helper", 905 "thread_exit_cb_helper", 906 "tls_properties_helper", 907 ], 908 data_libs: [ 909 "libatest_simple_zip", 910 "libcfi-test", 911 "libcfi-test-bad", 912 "libdl_preempt_test_1", 913 "libdl_preempt_test_2", 914 "libdl_test_df_1_global", 915 "libdlext_test", 916 "libdlext_test_different_soname", 917 "libdlext_test_fd", 918 "libdlext_test_norelro", 919 "libdlext_test_recursive", 920 "libdlext_test_zip", 921 "libgnu-hash-table-library", 922 "libns_hidden_child_app", 923 "libns_hidden_child_global", 924 "libns_hidden_child_internal", 925 "libns_hidden_child_public", 926 "libnstest_dlopened", 927 "libnstest_ns_a_public1", 928 "libnstest_ns_a_public1_internal", 929 "libnstest_ns_b_public2", 930 "libnstest_ns_b_public3", 931 "libnstest_private", 932 "libnstest_private_external", 933 "libnstest_public", 934 "libnstest_public_internal", 935 "libnstest_root", 936 "libnstest_root_not_isolated", 937 "librelocations-ANDROID_REL", 938 "librelocations-ANDROID_RELR", 939 "librelocations-RELR", 940 "librelocations-fat", 941 "libsegment_gap_inner", 942 "libsegment_gap_outer", 943 "libsysv-hash-table-library", 944 "libtest_atexit", 945 "libtest_check_order_dlsym", 946 "libtest_check_order_dlsym_1_left", 947 "libtest_check_order_dlsym_2_right", 948 "libtest_check_order_dlsym_3_c", 949 "libtest_check_order_dlsym_a", 950 "libtest_check_order_dlsym_b", 951 "libtest_check_order_dlsym_d", 952 "libtest_check_order_reloc_root", 953 "libtest_check_order_reloc_root_1", 954 "libtest_check_order_reloc_root_2", 955 "libtest_check_order_reloc_siblings", 956 "libtest_check_order_reloc_siblings_1", 957 "libtest_check_order_reloc_siblings_2", 958 "libtest_check_order_reloc_siblings_3", 959 "libtest_check_order_reloc_siblings_a", 960 "libtest_check_order_reloc_siblings_b", 961 "libtest_check_order_reloc_siblings_c", 962 "libtest_check_order_reloc_siblings_c_1", 963 "libtest_check_order_reloc_siblings_c_2", 964 "libtest_check_order_reloc_siblings_d", 965 "libtest_check_order_reloc_siblings_e", 966 "libtest_check_order_reloc_siblings_f", 967 "libtest_check_rtld_next_from_library", 968 "libtest_dlopen_df_1_global", 969 "libtest_dlopen_from_ctor", 970 "libtest_dlopen_from_ctor_main", 971 "libtest_dlopen_weak_undefined_func", 972 "libtest_dlsym_df_1_global", 973 "libtest_dlsym_from_this", 974 "libtest_dlsym_from_this_child", 975 "libtest_dlsym_from_this_grandchild", 976 "libtest_dlsym_weak_func", 977 "libtest_dt_runpath_a", 978 "libtest_dt_runpath_b", 979 "libtest_dt_runpath_c", 980 "libtest_dt_runpath_d", 981 "libtest_dt_runpath_x", 982 "libtest_dt_runpath_y", 983 "libtest_elf_max_page_size_4kib", 984 "libtest_elftls_dynamic", 985 "libtest_elftls_dynamic_filler_1", 986 "libtest_elftls_dynamic_filler_2", 987 "libtest_elftls_dynamic_filler_3", 988 "libtest_elftls_dynamic_filler_4", 989 "libtest_elftls_dynamic_filler_5", 990 "libtest_elftls_shared_var", 991 "libtest_elftls_shared_var_ie", 992 "libtest_elftls_tprel", 993 "libtest_empty", 994 "libtest_ifunc", 995 "libtest_ifunc_variable", 996 "libtest_ifunc_variable_impl", 997 "libtest_indirect_thread_local_dtor", 998 "libtest_init_fini_order_child", 999 "libtest_init_fini_order_grand_child", 1000 "libtest_init_fini_order_root", 1001 "libtest_init_fini_order_root2", 1002 "libtest_invalid-empty_shdr_table", 1003 "libtest_invalid-local-tls", 1004 "libtest_invalid-rw_load_segment", 1005 "libtest_invalid-textrels", 1006 "libtest_invalid-textrels2", 1007 "libtest_invalid-unaligned_shdr_offset", 1008 "libtest_invalid-zero_shdr_table_content", 1009 "libtest_invalid-zero_shdr_table_offset", 1010 "libtest_invalid-zero_shentsize", 1011 "libtest_invalid-zero_shstrndx", 1012 "libtest_missing_symbol", 1013 "libtest_missing_symbol_child_private", 1014 "libtest_missing_symbol_child_public", 1015 "libtest_missing_symbol_root", 1016 "libtest_nodelete_1", 1017 "libtest_nodelete_2", 1018 "libtest_nodelete_dt_flags_1", 1019 "libtest_pthread_atfork", 1020 "libtest_relo_check_dt_needed_order", 1021 "libtest_relo_check_dt_needed_order_1", 1022 "libtest_relo_check_dt_needed_order_2", 1023 "libtest_simple", 1024 "libtest_thread_local_dtor", 1025 "libtest_thread_local_dtor2", 1026 "libtest_two_parents_child", 1027 "libtest_two_parents_parent1", 1028 "libtest_two_parents_parent2", 1029 "libtest_versioned_lib", 1030 "libtest_versioned_libv1", 1031 "libtest_versioned_libv2", 1032 "libtest_versioned_otherlib", 1033 "libtest_versioned_otherlib_empty", 1034 "libtest_versioned_uselibv1", 1035 "libtest_versioned_uselibv2", 1036 "libtest_versioned_uselibv2_other", 1037 "libtest_versioned_uselibv3_other", 1038 "libtest_with_dependency", 1039 "libtest_with_dependency_loop", 1040 "libtest_with_dependency_loop_a", 1041 "libtest_with_dependency_loop_b", 1042 "libtest_with_dependency_loop_c", 1043 "libtestshared", 1044 ], 1045} 1046 1047// ----------------------------------------------------------------------------- 1048// Tests for the device using bionic's .so. Run with: 1049// adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests 1050// adb shell /data/nativetest64/bionic-unit-tests/bionic-unit-tests 1051// ----------------------------------------------------------------------------- 1052cc_defaults { 1053 name: "bionic_unit_tests_defaults", 1054 host_supported: false, 1055 gtest: false, 1056 1057 defaults: [ 1058 "bionic_tests_defaults", 1059 "bionic_unit_tests_data", 1060 ], 1061 1062 whole_static_libs: [ 1063 "libBionicTests", 1064 "libBionicLoaderTests", 1065 "libBionicElfTlsLoaderTests", 1066 ], 1067 1068 static_libs: [ 1069 "libtinyxml2", 1070 "liblog", 1071 "libbase", 1072 "libgtest_isolated", 1073 ], 1074 1075 srcs: [ 1076 // TODO: Include __cxa_thread_atexit_test.cpp to glibc tests once it is upgraded (glibc 2.18+) 1077 "__cxa_thread_atexit_test.cpp", 1078 "gtest_globals.cpp", 1079 "gtest_main.cpp", 1080 "gwp_asan_test.cpp", 1081 "thread_local_test.cpp", 1082 ], 1083 1084 conlyflags: [ 1085 "-fexceptions", 1086 "-fnon-call-exceptions", 1087 ], 1088 1089 ldflags: ["-Wl,--export-dynamic"], 1090 1091 include_dirs: ["bionic/libc"], 1092 1093 stl: "libc++_static", 1094 1095 target: { 1096 android: { 1097 shared_libs: [ 1098 "ld-android", 1099 "libdl", 1100 "libdl_android", 1101 "libdl_preempt_test_1", 1102 "libdl_preempt_test_2", 1103 "libdl_test_df_1_global", 1104 "libtest_elftls_shared_var", 1105 "libtest_elftls_tprel", 1106 ], 1107 static_libs: [ 1108 // The order of these libraries matters, do not shuffle them. 1109 "libmeminfo", 1110 "libziparchive", 1111 "libz", 1112 "libutils", 1113 ], 1114 ldflags: [ 1115 "-Wl,--rpath,${ORIGIN}/bionic-loader-test-libs", 1116 "-Wl,--enable-new-dtags", 1117 ], 1118 }, 1119 }, 1120} 1121 1122cc_test { 1123 name: "bionic-unit-tests", 1124 defaults: [ 1125 "bionic_unit_tests_defaults", 1126 ], 1127 test_suites: ["general-tests"], 1128 data: [ 1129 ":libdlext_test_runpath_zip_zipaligned", 1130 ":libdlext_test_zip_zipaligned", 1131 ], 1132} 1133 1134cc_defaults { 1135 name: "hwasan_test_defaults", 1136 enabled: false, 1137 // This does not use bionic_tests_defaults because it is not supported on 1138 // host. 1139 arch: { 1140 arm64: { 1141 enabled: true, 1142 }, 1143 }, 1144 sanitize: { 1145 hwaddress: true, 1146 }, 1147 srcs: [ 1148 "hwasan_test.cpp", 1149 ], 1150 data_libs: [ 1151 "libtest_simple_hwasan", 1152 "libtest_simple_hwasan_nohwasan", 1153 ], 1154 header_libs: ["bionic_libc_platform_headers"], 1155 test_suites: ["general-tests"], 1156} 1157 1158cc_test { 1159 name: "hwasan_test", 1160 defaults: ["hwasan_test_defaults"], 1161 shared_libs: [ 1162 "libbase", 1163 ], 1164} 1165 1166cc_test { 1167 name: "hwasan_test_static", 1168 defaults: ["hwasan_test_defaults"], 1169 static_libs: [ 1170 "libbase", 1171 ], 1172 static_executable: true, 1173 cflags: ["-DHWASAN_TEST_STATIC"], 1174} 1175 1176cc_test { 1177 name: "memtag_stack_dlopen_test", 1178 enabled: false, 1179 // This does not use bionic_tests_defaults because it is not supported on 1180 // host. 1181 arch: { 1182 arm64: { 1183 enabled: true, 1184 }, 1185 }, 1186 sanitize: { 1187 memtag_heap: true, 1188 memtag_stack: false, 1189 }, 1190 srcs: [ 1191 "memtag_stack_dlopen_test.cpp", 1192 ], 1193 shared_libs: [ 1194 "libbase", 1195 ], 1196 data_libs: [ 1197 "libtest_simple_memtag_stack", 1198 "libtest_depends_on_simple_memtag_stack", 1199 ], 1200 data_bins: [ 1201 "testbinary_depends_on_simple_memtag_stack", 1202 "testbinary_depends_on_depends_on_simple_memtag_stack", 1203 "testbinary_is_stack_mte_after_dlopen", 1204 ], 1205 header_libs: ["bionic_libc_platform_headers"], 1206 test_suites: ["general-tests"], 1207} 1208 1209cc_test { 1210 name: "memtag_stack_abi_test", 1211 enabled: false, 1212 // This does not use bionic_tests_defaults because it is not supported on 1213 // host. 1214 arch: { 1215 arm64: { 1216 enabled: true, 1217 }, 1218 }, 1219 // We don't use `sanitize:` so we generate the appropriate ELF note, but 1220 // still support non-MTE devices. 1221 // TODO(fmayer): also add a test that enables stack MTE for MTE devices, 1222 // which would test for more bugs. 1223 ldflags: ["-fsanitize=memtag-stack"], 1224 // Turn off all other sanitizers from SANITIZE_TARGET. 1225 sanitize: { 1226 never: true, 1227 }, 1228 shared_libs: [ 1229 "libbase", 1230 ], 1231 srcs: [ 1232 "memtag_stack_abi_test.cpp", 1233 ], 1234 header_libs: ["bionic_libc_platform_headers"], 1235 test_suites: ["general-tests"], 1236} 1237 1238cc_test { 1239 name: "bionic-stress-tests", 1240 defaults: [ 1241 "bionic_tests_defaults", 1242 ], 1243 1244 // For now, these tests run forever, so do not use the isolation framework. 1245 isolated: false, 1246 // Running forever, do not consider unit test. 1247 test_options: { 1248 unit_test: false, 1249 }, 1250 1251 srcs: [ 1252 "malloc_stress_test.cpp", 1253 ], 1254 1255 shared_libs: [ 1256 "libbase", 1257 "liblog", 1258 ], 1259 1260 target: { 1261 android: { 1262 static_libs: [ 1263 "libmeminfo", 1264 "libprocinfo", 1265 ], 1266 }, 1267 }, 1268} 1269 1270// ----------------------------------------------------------------------------- 1271// Tests for the device linked against bionic's static library. Run with: 1272// adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static 1273// adb shell /data/nativetest64/bionic-unit-tests-static/bionic-unit-tests-static 1274// ----------------------------------------------------------------------------- 1275cc_test { 1276 name: "bionic-unit-tests-static", 1277 gtest: false, 1278 defaults: ["bionic_tests_defaults"], 1279 test_suites: ["general-tests"], 1280 host_supported: false, 1281 1282 srcs: [ 1283 "gtest_preinit_debuggerd.cpp", 1284 "gtest_globals.cpp", 1285 "gtest_main.cpp", 1286 1287 // Test internal parts of Bionic that aren't exposed via libc.so. 1288 "bionic_allocator_test.cpp", 1289 "static_tls_layout_test.cpp", 1290 ], 1291 include_dirs: [ 1292 "bionic/libc", 1293 ], 1294 whole_static_libs: [ 1295 "libBionicTests", 1296 ], 1297 1298 static_libs: [ 1299 "libm", 1300 "libc", 1301 "libdl", 1302 "libtinyxml2", 1303 "liblog", 1304 "libbase", 1305 "libdebuggerd_handler", 1306 "libgtest_isolated", 1307 "libtest_elftls_shared_var", 1308 "libtest_elftls_tprel", 1309 ], 1310 1311 static_executable: true, 1312 stl: "libc++_static", 1313 // Clang cannot build ifunc with LTO. 1314 // http://b/203737712 1315 lto: { 1316 never: true, 1317 }, 1318 data_bins: [ 1319 "elftls_align_test_helper", 1320 "elftls_skew_align_test_helper", 1321 "heap_tagging_async_helper", 1322 "heap_tagging_disabled_helper", 1323 "heap_tagging_static_async_helper", 1324 "heap_tagging_static_disabled_helper", 1325 "heap_tagging_static_sync_helper", 1326 "heap_tagging_sync_helper", 1327 "memtag_globals_binary", 1328 "memtag_globals_binary_static", 1329 "memtag_globals_dso", 1330 "mte_globals_relr_regression_test_b_314038442", 1331 "mte_globals_relr_regression_test_b_314038442_mte", 1332 "stack_tagging_helper", 1333 "stack_tagging_static_helper", 1334 ], 1335} 1336 1337// ----------------------------------------------------------------------------- 1338// Tests to run on the host and linked against glibc. Run with: 1339// cd bionic/tests; mm bionic-unit-tests-glibc-run 1340// ----------------------------------------------------------------------------- 1341 1342cc_test_host { 1343 name: "bionic-unit-tests-glibc", 1344 gtest: false, 1345 defaults: ["bionic_tests_defaults"], 1346 1347 srcs: [ 1348 "atexit_test.cpp", 1349 "dlfcn_symlink_support.cpp", 1350 "dlfcn_test.cpp", 1351 "dl_test.cpp", 1352 "execinfo_test.cpp", 1353 "gtest_globals.cpp", 1354 "gtest_main.cpp", 1355 "pthread_dlfcn_test.cpp", 1356 ], 1357 1358 shared_libs: [ 1359 "libdl_preempt_test_1", 1360 "libdl_preempt_test_2", 1361 "libdl_test_df_1_global", 1362 "libtest_elftls_shared_var", 1363 "libtest_elftls_tprel", 1364 ], 1365 1366 whole_static_libs: [ 1367 "libBionicStandardTests", 1368 "libBionicElfTlsTests", 1369 "libBionicElfTlsLoaderTests", 1370 "libfortify1-tests-clang", 1371 "libfortify2-tests-clang", 1372 ], 1373 1374 static_libs: [ 1375 "libbase", 1376 "liblog", 1377 "libcutils", 1378 "libgtest_isolated", 1379 ], 1380 1381 host_ldlibs: [ 1382 "-lresolv", 1383 "-lutil", 1384 ], 1385 1386 include_dirs: [ 1387 "bionic/libc", 1388 ], 1389 1390 ldflags: [ 1391 "-Wl,--rpath,${ORIGIN}/../bionic-loader-test-libs", 1392 "-Wl,--export-dynamic", 1393 ], 1394 1395 sanitize: { 1396 never: false, 1397 }, 1398 1399 target: { 1400 linux_bionic: { 1401 enabled: false, 1402 }, 1403 musl: { 1404 exclude_static_libs: [ 1405 // Musl doesn't have fortify 1406 "libfortify1-tests-clang", 1407 "libfortify2-tests-clang", 1408 ], 1409 }, 1410 }, 1411} 1412 1413cc_defaults { 1414 name: "bionic_compile_time_tests_defaults", 1415 enabled: true, 1416 clang_verify: true, 1417 cflags: [ 1418 "-Wall", 1419 "-Wno-error", 1420 "-fno-color-diagnostics", 1421 "-ferror-limit=10000", 1422 "-DCOMPILATION_TESTS=1", 1423 "-Wformat-nonliteral", 1424 "-U_FORTIFY_SOURCE", 1425 ], 1426 srcs: ["clang_fortify_tests.cpp"], 1427} 1428 1429cc_library_static { 1430 name: "bionic-compile-time-tests1-clang++", 1431 defaults: [ 1432 "bionic_compile_time_tests_defaults", 1433 ], 1434 cppflags: [ 1435 "-D_FORTIFY_SOURCE=1", 1436 ], 1437} 1438 1439cc_library_static { 1440 name: "bionic-compile-time-tests2-clang++", 1441 defaults: [ 1442 "bionic_compile_time_tests_defaults", 1443 ], 1444 cppflags: [ 1445 "-D_FORTIFY_SOURCE=2", 1446 ], 1447} 1448 1449cc_library_static { 1450 name: "bionic-compile-time-tests3-clang++", 1451 defaults: [ 1452 "bionic_compile_time_tests_defaults", 1453 ], 1454 cppflags: [ 1455 "-D_FORTIFY_SOURCE=3", 1456 ], 1457} 1458