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