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