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