• 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
17cc_defaults {
18    name: "bionic_tests_defaults",
19    host_supported: true,
20    cpp_std: "experimental",
21    target: {
22        darwin: {
23            enabled: false,
24        },
25    },
26    cflags: [
27        "-fstack-protector-all",
28        "-g",
29        "-Wall",
30        "-Wextra",
31        "-Wunused",
32        "-Werror",
33        "-fno-builtin",
34
35        // We want to test deprecated API too.
36        "-Wno-deprecated-declarations",
37
38        // For glibc.
39        "-D__STDC_LIMIT_MACROS",
40    ],
41    // Make the bionic tests implicitly test bionic's shadow call stack support.
42    arch: {
43        arm64: {
44           cflags: ["-fsanitize=shadow-call-stack"],
45        },
46    },
47    stl: "libc++",
48    sanitize: {
49        address: false,
50    },
51    bootstrap: true,
52}
53
54// -----------------------------------------------------------------------------
55// All standard tests.
56// -----------------------------------------------------------------------------
57
58// Test diagnostics emitted by clang. The library that results is useless; we
59// just want to run '-Xclang -verify', which will fail if the diagnostics don't
60// match up with what the source file says they should be.
61cc_test_library {
62    name: "clang_diagnostic_tests",
63    cflags: [
64      "-Xclang",
65      "-verify",
66    ],
67    srcs: ["sys_ioctl_diag_test.cpp"],
68}
69
70cc_test_library {
71    name: "libBionicStandardTests",
72    defaults: ["bionic_tests_defaults"],
73    srcs: [
74        "__aeabi_read_tp_test.cpp",
75        "alloca_test.cpp",
76        "android_get_device_api_level.cpp",
77        "arpa_inet_test.cpp",
78        "async_safe_test.cpp",
79        "assert_test.cpp",
80        "buffer_tests.cpp",
81        "bug_26110743_test.cpp",
82        "byteswap_test.cpp",
83        "complex_test.cpp",
84        "complex_force_long_double_test.cpp",
85        "ctype_test.cpp",
86        "dirent_test.cpp",
87        "elf_test.cpp",
88        "endian_test.cpp",
89        "errno_test.cpp",
90        "error_test.cpp",
91        "eventfd_test.cpp",
92        "fcntl_test.cpp",
93        "fdsan_test.cpp",
94        "fenv_test.cpp",
95        "float_test.cpp",
96        "ftw_test.cpp",
97        "getauxval_test.cpp",
98        "getcwd_test.cpp",
99        "glob_test.cpp",
100        "grp_pwd_test.cpp",
101        "grp_pwd_file_test.cpp",
102        "iconv_test.cpp",
103        "ifaddrs_test.cpp",
104        "ifunc_test.cpp",
105        "inttypes_test.cpp",
106        "iso646_test.c",
107        "langinfo_test.cpp",
108        "leak_test.cpp",
109        "libgen_basename_test.cpp",
110        "libgen_test.cpp",
111        "limits_test.cpp",
112        "linux_swab_test.cpp",
113        "locale_test.cpp",
114        "malloc_iterate_test.cpp",
115        "malloc_test.cpp",
116        "math_test.cpp",
117        "math_force_long_double_test.cpp",
118        "membarrier_test.cpp",
119        "mntent_test.cpp",
120        "netdb_test.cpp",
121        "net_if_test.cpp",
122        "netinet_ether_test.cpp",
123        "netinet_in_test.cpp",
124        "netinet_ip_icmp_test.cpp",
125        "netinet_udp_test.cpp",
126        "nl_types_test.cpp",
127        "poll_test.cpp",
128        "pthread_test.cpp",
129        "pty_test.cpp",
130        "regex_test.cpp",
131        "resolv_test.cpp",
132        "sched_test.cpp",
133        "scs_test.cpp",
134        "scsi_sg_test.cpp",
135        "search_test.cpp",
136        "semaphore_test.cpp",
137        "setjmp_test.cpp",
138        "signal_test.cpp",
139        "spawn_test.cpp",
140        "stack_protector_test.cpp",
141        "stack_protector_test_helper.cpp",
142        "stack_unwinding_test.cpp",
143        "stdalign_test.cpp",
144        "stdarg_test.cpp",
145        "stdatomic_test.cpp",
146        "stdbool_test.c",
147        "stdint_test.cpp",
148        "stdio_nofortify_test.cpp",
149        "stdio_test.cpp",
150        "stdio_ext_test.cpp",
151        "stdlib_test.cpp",
152        "stdnoreturn_test.cpp",
153        "string_nofortify_test.cpp",
154        "string_test.cpp",
155        "string_posix_strerror_r_test.cpp",
156        "strings_nofortify_test.cpp",
157        "strings_test.cpp",
158        "sstream_test.cpp",
159        "sys_epoll_test.cpp",
160        "sys_mman_test.cpp",
161        "sys_msg_test.cpp",
162        "sys_param_test.cpp",
163        "sys_personality_test.cpp",
164        "sys_prctl_test.cpp",
165        "sys_procfs_test.cpp",
166        "sys_ptrace_test.cpp",
167        "sys_quota_test.cpp",
168        "sys_random_test.cpp",
169        "sys_resource_test.cpp",
170        "sys_select_test.cpp",
171        "sys_sem_test.cpp",
172        "sys_sendfile_test.cpp",
173        "sys_shm_test.cpp",
174        "sys_signalfd_test.cpp",
175        "sys_socket_test.cpp",
176        "sys_stat_test.cpp",
177        "sys_statvfs_test.cpp",
178        "sys_syscall_test.cpp",
179        "sys_sysinfo_test.cpp",
180        "sys_sysmacros_test.cpp",
181        "sys_time_test.cpp",
182        "sys_timex_test.cpp",
183        "sys_ttydefaults_test.cpp",
184        "sys_types_test.cpp",
185        "sys_uio_test.cpp",
186        "sys_un_test.cpp",
187        "sys_vfs_test.cpp",
188        "sys_xattr_test.cpp",
189        "system_properties_test.cpp",
190        "system_properties_test2.cpp",
191        "termios_test.cpp",
192        "tgmath_test.c",
193        "time_test.cpp",
194        "uchar_test.cpp",
195        "unistd_nofortify_test.cpp",
196        "unistd_test.cpp",
197        "utmp_test.cpp",
198        "wchar_test.cpp",
199        "wctype_test.cpp",
200    ],
201
202    include_dirs: [
203        "bionic/libc",
204    ],
205
206    target: {
207        bionic: {
208            whole_static_libs: [
209                "libasync_safe",
210                "libprocinfo",
211                "libsystemproperties",
212            ],
213        },
214    },
215
216    static_libs: [
217        "libtinyxml2",
218        "liblog",
219        "libbase",
220    ],
221    shared: {
222        enabled: false,
223    },
224
225    generated_headers: ["generated_android_ids"],
226}
227
228cc_test_library {
229    name: "libBionicElfTlsTests",
230    defaults: ["bionic_tests_defaults"],
231    srcs: [
232        "elftls_test.cpp",
233    ],
234    include_dirs: [
235        "bionic/libc",
236    ],
237    shared: {
238        enabled: false,
239    },
240    cflags: [
241        "-fno-emulated-tls",
242    ],
243}
244
245cc_test_library {
246    name: "libBionicElfTlsLoaderTests",
247    defaults: ["bionic_tests_defaults"],
248    srcs: [
249        "elftls_dl_test.cpp",
250    ],
251    include_dirs: [
252        "bionic/libc",
253    ],
254    static_libs: [
255        "liblog",
256        "libbase",
257    ],
258    shared: {
259        enabled: false,
260    },
261    cflags: [
262        "-fno-emulated-tls",
263    ],
264}
265
266// -----------------------------------------------------------------------------
267// Fortify tests.
268// -----------------------------------------------------------------------------
269
270cc_defaults {
271    name: "bionic_fortify_tests_defaults",
272    cflags: [
273        "-U_FORTIFY_SOURCE",
274    ],
275    srcs: ["fortify_test_main.cpp"],
276    target: {
277        host: {
278            clang_cflags: ["-D__clang__"],
279        },
280    },
281}
282
283// If building this fails, then we have both FORTIFY and ASAN enabled, which
284// isn't desirable. (Ideally, we'd emit FORTIFY diagnostics even with ASAN
285// enabled, but that's not a reality today.) This is meant to be otherwise
286// unused.
287cc_test_library {
288    name: "fortify_disabled_for_asan",
289    cflags: [
290        "-Werror",
291        "-D_FORTIFY_SOURCE=2",
292        // "sanitize: address" doesn't work on platforms where libasan isn't
293        // enabled. Since the intent is just to build this, we can get away with
294        // passing this flag on its own.
295        "-fsanitize=address",
296    ],
297    // Ignore that we don't have ASAN symbols linked in.
298    allow_undefined_symbols: true,
299    srcs: ["fortify_filecheck_diagnostics_test.cpp"],
300}
301
302// Ensure we don't use FORTIFY'ed functions with the static analyzer/clang-tidy:
303// it can confuse these tools pretty easily. If this builds successfully, then
304// __clang_analyzer__ overrode FORTIFY. Otherwise, FORTIFY was incorrectly
305// enabled. The library that results from building this is meant to be unused.
306cc_test_library {
307    name: "fortify_disabled_for_tidy",
308    cflags: [
309        "-Werror",
310        "-D_FORTIFY_SOURCE=2",
311        "-D__clang_analyzer__",
312    ],
313    srcs: ["fortify_filecheck_diagnostics_test.cpp"],
314}
315
316cc_test_library {
317    name: "libfortify1-tests-clang",
318    defaults: [
319        "bionic_fortify_tests_defaults",
320        "bionic_tests_defaults",
321    ],
322    cflags: [
323        "-D_FORTIFY_SOURCE=1",
324        "-DTEST_NAME=Fortify1_clang",
325    ],
326    shared: {
327        enabled: false,
328    },
329}
330
331cc_test_library {
332    name: "libfortify2-tests-clang",
333    defaults: [
334        "bionic_fortify_tests_defaults",
335        "bionic_tests_defaults",
336    ],
337    cflags: [
338        "-D_FORTIFY_SOURCE=2",
339        "-DTEST_NAME=Fortify2_clang",
340    ],
341    shared: {
342        enabled: false,
343    },
344}
345
346// -----------------------------------------------------------------------------
347// Library of all tests (excluding the dynamic linker tests).
348// -----------------------------------------------------------------------------
349cc_test_library {
350    name: "libBionicTests",
351    defaults: ["bionic_tests_defaults"],
352    whole_static_libs: [
353        "libBionicStandardTests",
354        "libBionicElfTlsTests",
355        "libfortify1-tests-clang",
356        "libfortify2-tests-clang",
357    ],
358    shared: {
359        enabled: false,
360    },
361}
362
363cc_test_library {
364    name: "libBionicLoaderTests",
365    defaults: [
366        "bionic_tests_defaults",
367        "llvm-defaults",
368    ],
369    srcs: [
370        "atexit_test.cpp",
371        "dl_test.cpp",
372        "dlfcn_symlink_support.cpp",
373        "dlfcn_test.cpp",
374        "link_test.cpp",
375        "pthread_dlfcn_test.cpp",
376    ],
377    static_libs: [
378        "libbase",
379    ],
380    include_dirs: [
381        "bionic/libc",
382    ],
383    shared: {
384        enabled: false,
385    },
386    target: {
387        android: {
388            srcs: [
389                "cfi_test.cpp",
390                "dlext_test.cpp",
391                "libdl_test.cpp",
392            ],
393            static_libs: [
394                "libmeminfo",
395                "libprocinfo",
396                "libziparchive",
397                "libLLVMObject",
398                "libLLVMBitReader",
399                "libLLVMMC",
400                "libLLVMMCParser",
401                "libLLVMCore",
402                "libLLVMSupport",
403            ],
404        },
405    },
406}
407
408// -----------------------------------------------------------------------------
409// Library of bionic customized gtest main function, with normal gtest output format,
410// which is needed by bionic cts test.
411// -----------------------------------------------------------------------------
412cc_test_library {
413    name: "libBionicCtsGtestMain",
414    defaults: ["bionic_tests_defaults"],
415    srcs: [
416        "gtest_globals_cts.cpp",
417        "gtest_main.cpp",
418    ],
419    shared: {
420        enabled: false,
421    },
422    whole_static_libs: [
423        "libgtest_isolated",
424    ],
425}
426
427// -----------------------------------------------------------------------------
428// Tests for the device using bionic's .so. Run with:
429//   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests
430//   adb shell /data/nativetest64/bionic-unit-tests/bionic-unit-tests
431// -----------------------------------------------------------------------------
432cc_defaults {
433    name: "bionic_unit_tests_defaults",
434    host_supported: false,
435    gtest: false,
436
437    defaults: [
438        "bionic_tests_defaults",
439    ],
440
441    whole_static_libs: [
442        "libBionicTests",
443        "libBionicLoaderTests",
444        "libBionicElfTlsLoaderTests",
445    ],
446
447    static_libs: [
448        "libtinyxml2",
449        "liblog",
450        "libbase",
451        "libgtest_isolated",
452    ],
453
454    srcs: [
455        // TODO: Include __cxa_thread_atexit_test.cpp to glibc tests once it is upgraded (glibc 2.18+)
456        "__cxa_thread_atexit_test.cpp",
457        "gtest_globals.cpp",
458        "gtest_main.cpp",
459        "thread_local_test.cpp",
460    ],
461
462    conlyflags: [
463        "-fexceptions",
464        "-fnon-call-exceptions",
465    ],
466
467    ldflags: ["-Wl,--export-dynamic"],
468
469    include_dirs: ["bionic/libc"],
470
471    stl: "libc++_static",
472
473    target: {
474        android: {
475            shared_libs: [
476                "ld-android",
477                "libandroidicu",
478                "libdl",
479                "libdl_android",
480                "libdl_preempt_test_1",
481                "libdl_preempt_test_2",
482                "libdl_test_df_1_global",
483                "libtest_elftls_shared_var",
484                "libtest_elftls_tprel",
485            ],
486            static_libs: [
487                // The order of these libraries matters, do not shuffle them.
488                "libbase",
489                "libmeminfo",
490                "libziparchive",
491                "libz",
492                "libutils",
493                "libLLVMObject",
494                "libLLVMBitReader",
495                "libLLVMMC",
496                "libLLVMMCParser",
497                "libLLVMCore",
498                "libLLVMSupport",
499            ],
500            ldflags: [
501                "-Wl,--rpath,${ORIGIN}/../bionic-loader-test-libs",
502                "-Wl,--enable-new-dtags",
503            ],
504        },
505    },
506
507    required: [
508        "cfi_test_helper",
509        "cfi_test_helper2",
510        "elftls_dlopen_ie_error_helper",
511        "exec_linker_helper",
512        "exec_linker_helper_lib",
513        "libtest_dt_runpath_a",
514        "libtest_dt_runpath_b",
515        "libtest_dt_runpath_c",
516        "libtest_dt_runpath_x",
517        "libtest_dt_runpath_y",
518        "libatest_simple_zip",
519        "libcfi-test",
520        "libcfi-test-bad",
521        "libdlext_test_different_soname",
522        "libdlext_test_fd",
523        "libdlext_test_norelro",
524        "libdlext_test_recursive",
525        "libdlext_test_runpath_zip_zipaligned",
526        "libdlext_test",
527        "libdlext_test_zip",
528        "libdlext_test_zip_zipaligned",
529        "libdl_preempt_test_1",
530        "libdl_preempt_test_2",
531        "libdl_test_df_1_global",
532        "libgnu-hash-table-library",
533        "libsysv-hash-table-library",
534        "libtestshared",
535        "libtest_atexit",
536        "libtest_check_order_dlsym_1_left",
537        "libtest_check_order_dlsym_2_right",
538        "libtest_check_order_dlsym_3_c",
539        "libtest_check_order_dlsym_a",
540        "libtest_check_order_dlsym_b",
541        "libtest_check_order_dlsym_d",
542        "libtest_check_order_dlsym",
543        "libtest_check_order_reloc_root_1",
544        "libtest_check_order_reloc_root_2",
545        "libtest_check_order_reloc_root",
546        "libtest_check_order_reloc_siblings_1",
547        "libtest_check_order_reloc_siblings_2",
548        "libtest_check_order_reloc_siblings_3",
549        "libtest_check_order_reloc_siblings_a",
550        "libtest_check_order_reloc_siblings_b",
551        "libtest_check_order_reloc_siblings_c_1",
552        "libtest_check_order_reloc_siblings_c_2",
553        "libtest_check_order_reloc_siblings_c",
554        "libtest_check_order_reloc_siblings_d",
555        "libtest_check_order_reloc_siblings_e",
556        "libtest_check_order_reloc_siblings_f",
557        "libtest_check_order_reloc_siblings",
558        "libtest_check_rtld_next_from_library",
559        "libtest_dlopen_df_1_global",
560        "libtest_dlopen_from_ctor_main",
561        "libtest_dlopen_from_ctor",
562        "libtest_dlopen_weak_undefined_func",
563        "libtest_dlsym_df_1_global",
564        "libtest_dlsym_from_this_child",
565        "libtest_dlsym_from_this_grandchild",
566        "libtest_dlsym_from_this",
567        "libtest_dlsym_weak_func",
568        "libtest_dt_runpath_d",
569        "libtest_elftls_dynamic",
570        "libtest_elftls_dynamic_filler_1",
571        "libtest_elftls_dynamic_filler_2",
572        "libtest_elftls_dynamic_filler_3",
573        "libtest_elftls_shared_var",
574        "libtest_elftls_shared_var_ie",
575        "libtest_elftls_tprel",
576        "libtest_empty",
577        "libtest_ifunc_variable_impl",
578        "libtest_ifunc_variable",
579        "libtest_ifunc",
580        "libtest_init_fini_order_child",
581        "libtest_init_fini_order_grand_child",
582        "libtest_init_fini_order_root2",
583        "libtest_init_fini_order_root",
584        "libtest_missing_symbol_child_public",
585        "libtest_missing_symbol_child_private",
586        "libtest_missing_symbol_root",
587        "libtest_missing_symbol",
588        "libtest_nodelete_1",
589        "libtest_nodelete_2",
590        "libtest_nodelete_dt_flags_1",
591        "libtest_pthread_atfork",
592        "libtest_relo_check_dt_needed_order_1",
593        "libtest_relo_check_dt_needed_order_2",
594        "libtest_relo_check_dt_needed_order",
595        "libtest_simple",
596        "libtest_two_parents_child",
597        "libtest_two_parents_parent1",
598        "libtest_two_parents_parent2",
599        "libtest_versioned_lib",
600        "libtest_versioned_libv1",
601        "libtest_versioned_libv2",
602        "libtest_versioned_otherlib_empty",
603        "libtest_versioned_otherlib",
604        "libtest_versioned_uselibv1",
605        "libtest_versioned_uselibv2_other",
606        "libtest_versioned_uselibv2",
607        "libtest_versioned_uselibv3_other",
608        "libtest_with_dependency_loop_a",
609        "libtest_with_dependency_loop_b",
610        "libtest_with_dependency_loop_c",
611        "libtest_with_dependency_loop",
612        "libtest_with_dependency",
613        "libtest_indirect_thread_local_dtor",
614        "libtest_invalid-empty_shdr_table.so",
615        "libtest_invalid-rw_load_segment.so",
616        "libtest_invalid-unaligned_shdr_offset.so",
617        "libtest_invalid-zero_shdr_table_content.so",
618        "libtest_invalid-zero_shdr_table_offset.so",
619        "libtest_invalid-zero_shentsize.so",
620        "libtest_invalid-zero_shstrndx.so",
621        "libtest_invalid-textrels.so",
622        "libtest_invalid-textrels2.so",
623        "libtest_thread_local_dtor",
624        "libtest_thread_local_dtor2",
625        "preinit_getauxval_test_helper",
626        "preinit_syscall_test_helper",
627        "libnstest_private_external",
628        "libnstest_dlopened",
629        "libnstest_private",
630        "libnstest_root_not_isolated",
631        "libnstest_root",
632        "libnstest_public",
633        "libnstest_public_internal",
634        "libnstest_ns_a_public1",
635        "libnstest_ns_a_public1_internal",
636        "libnstest_ns_b_public2",
637        "libnstest_ns_b_public3",
638        "libsegment_gap_inner",
639        "libsegment_gap_outer",
640        "ld_preload_test_helper",
641        "ld_preload_test_helper_lib1",
642        "ld_preload_test_helper_lib2",
643        "ld_config_test_helper",
644        "ld_config_test_helper_lib1",
645        "ld_config_test_helper_lib2",
646        "ld_config_test_helper_lib3",
647    ],
648}
649
650cc_test {
651    name: "bionic-unit-tests",
652    defaults: [
653        "bionic_unit_tests_defaults",
654    ],
655}
656
657cc_test {
658    name: "bionic-unit-tests-scudo",
659    defaults: [
660        "bionic_unit_tests_defaults",
661    ],
662
663    shared_libs: [
664        "libc_scudo",
665    ],
666}
667
668// -----------------------------------------------------------------------------
669// Tests for the device linked against bionic's static library. Run with:
670//   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static
671//   adb shell /data/nativetest64/bionic-unit-tests-static/bionic-unit-tests-static
672// -----------------------------------------------------------------------------
673cc_test {
674    name: "bionic-unit-tests-static",
675    gtest: false,
676    defaults: ["bionic_tests_defaults"],
677    host_supported: false,
678
679    srcs: [
680        "gtest_preinit_debuggerd.cpp",
681        "gtest_globals.cpp",
682        "gtest_main.cpp",
683
684        // The Bionic allocator has its own C++ API. It isn't packaged into its
685        // own library, so it can only be tested when it's part of libc.a.
686        "bionic_allocator_test.cpp",
687    ],
688    include_dirs: [
689        "bionic/libc",
690    ],
691    whole_static_libs: [
692        "libBionicTests",
693    ],
694
695    static_libs: [
696        "libm",
697        "libc",
698        "libdl",
699        "libtinyxml2",
700        "liblog",
701        "libbase",
702        "libdebuggerd_handler",
703        "libgtest_isolated",
704        "libtest_elftls_shared_var",
705        "libtest_elftls_tprel",
706    ],
707
708    static_executable: true,
709    stl: "libc++_static",
710}
711
712// -----------------------------------------------------------------------------
713// Tests to run on the host and linked against glibc. Run with:
714//   cd bionic/tests; mm bionic-unit-tests-glibc-run
715// -----------------------------------------------------------------------------
716
717cc_test_host {
718    name: "bionic-unit-tests-glibc",
719    gtest: false,
720    defaults: ["bionic_tests_defaults"],
721
722    srcs: [
723        "atexit_test.cpp",
724        "dlfcn_symlink_support.cpp",
725        "dlfcn_test.cpp",
726        "dl_test.cpp",
727        "gtest_globals.cpp",
728        "gtest_main.cpp",
729        "pthread_dlfcn_test.cpp",
730    ],
731
732    shared_libs: [
733        "libdl_preempt_test_1",
734        "libdl_preempt_test_2",
735        "libdl_test_df_1_global",
736        "libtest_elftls_shared_var",
737        "libtest_elftls_tprel",
738    ],
739
740    whole_static_libs: [
741        "libBionicStandardTests",
742        "libBionicElfTlsTests",
743        "libBionicElfTlsLoaderTests",
744        "libfortify1-tests-clang",
745        "libfortify2-tests-clang",
746    ],
747
748    static_libs: [
749        "libbase",
750        "liblog",
751        "libcutils",
752        "libgtest_isolated",
753    ],
754
755    host_ldlibs: [
756        "-lresolv",
757        "-lutil",
758    ],
759
760    include_dirs: [
761        "bionic/libc",
762    ],
763
764    ldflags: [
765        "-Wl,--rpath,${ORIGIN}/../bionic-loader-test-libs",
766        "-Wl,--export-dynamic",
767    ],
768
769    sanitize: {
770        never: false,
771    },
772
773    target: {
774        linux_bionic: {
775            enabled: false,
776        },
777    },
778}
779
780subdirs = ["*"]
781