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    target: {
21        darwin: {
22            enabled: false,
23        },
24    },
25    cflags: [
26        "-fstack-protector-all",
27        "-g",
28        "-Wall",
29        "-Wextra",
30        "-Wunused",
31        "-Werror",
32        "-fno-builtin",
33
34        // We want to test deprecated API too.
35        "-Wno-deprecated-declarations",
36
37        // For glibc.
38        "-D__STDC_LIMIT_MACROS",
39    ],
40    stl: "libc++",
41    sanitize: {
42        never: true,
43    },
44}
45
46// -----------------------------------------------------------------------------
47// All standard tests.
48// -----------------------------------------------------------------------------
49
50cc_test_library {
51    name: "libBionicStandardTests",
52    defaults: ["bionic_tests_defaults"],
53    srcs: [
54        "arpa_inet_test.cpp",
55        "assert_test.cpp",
56        "buffer_tests.cpp",
57        "bug_26110743_test.cpp",
58        "complex_test.cpp",
59        "ctype_test.cpp",
60        "dirent_test.cpp",
61        "endian_test.cpp",
62        "error_test.cpp",
63        "eventfd_test.cpp",
64        "fcntl_test.cpp",
65        "fenv_test.cpp",
66        "ftw_test.cpp",
67        "getauxval_test.cpp",
68        "getcwd_test.cpp",
69        "grp_pwd_test.cpp",
70        "ifaddrs_test.cpp",
71        "inttypes_test.cpp",
72        "langinfo_test.cpp",
73        "leak_test.cpp",
74        "libc_logging_test.cpp",
75        "libgen_basename_test.cpp",
76        "libgen_test.cpp",
77        "locale_test.cpp",
78        "malloc_test.cpp",
79        "math_test.cpp",
80        "mntent_test.cpp",
81        "netdb_test.cpp",
82        "net_if_test.cpp",
83        "netinet_ether_test.cpp",
84        "netinet_in_test.cpp",
85        "netinet_udp_test.cpp",
86        "nl_types_test.cpp",
87        "pthread_test.cpp",
88        "pty_test.cpp",
89        "regex_test.cpp",
90        "resolv_test.cpp",
91        "sched_test.cpp",
92        "search_test.cpp",
93        "semaphore_test.cpp",
94        "setjmp_test.cpp",
95        "signal_test.cpp",
96        "stack_protector_test.cpp",
97        "stack_protector_test_helper.cpp",
98        "stack_unwinding_test.cpp",
99        "stdatomic_test.cpp",
100        "stdint_test.cpp",
101        "stdio_nofortify_test.cpp",
102        "stdio_test.cpp",
103        "stdio_ext_test.cpp",
104        "stdlib_test.cpp",
105        "string_nofortify_test.cpp",
106        "string_test.cpp",
107        "string_posix_strerror_r_test.cpp",
108        "strings_nofortify_test.cpp",
109        "strings_test.cpp",
110        "sstream_test.cpp",
111        "sys_epoll_test.cpp",
112        "sys_mman_test.cpp",
113        "sys_msg_test.cpp",
114        "sys_personality_test.cpp",
115        "sys_prctl_test.cpp",
116        "sys_procfs_test.cpp",
117        "sys_ptrace_test.cpp",
118        "sys_quota_test.cpp",
119        "sys_resource_test.cpp",
120        "sys_select_test.cpp",
121        "sys_sem_test.cpp",
122        "sys_sendfile_test.cpp",
123        "sys_shm_test.cpp",
124        "sys_socket_test.cpp",
125        "sys_stat_test.cpp",
126        "sys_statvfs_test.cpp",
127        "sys_syscall_test.cpp",
128        "sys_sysinfo_test.cpp",
129        "sys_sysmacros_test.cpp",
130        "sys_time_test.cpp",
131        "sys_timex_test.cpp",
132        "sys_types_test.cpp",
133        "sys_uio_test.cpp",
134        "sys_vfs_test.cpp",
135        "sys_xattr_test.cpp",
136        "system_properties_test.cpp",
137        "system_properties_test2.cpp",
138        "time_test.cpp",
139        "uchar_test.cpp",
140        "unistd_nofortify_test.cpp",
141        "unistd_test.cpp",
142        "utmp_test.cpp",
143        "wchar_test.cpp",
144        "wctype_test.cpp",
145    ],
146
147    include_dirs: [
148        "bionic/libc",
149        "external/tinyxml2",
150    ],
151
152    static_libs: [
153        "libtinyxml2",
154        "liblog",
155        "libbase",
156    ],
157    host_ldlibs: ["-lrt"],
158    shared: {
159        enabled: false,
160    },
161
162    generated_headers: ["generated_android_ids"],
163}
164
165// -----------------------------------------------------------------------------
166// Fortify tests.
167// -----------------------------------------------------------------------------
168
169cc_defaults {
170    name: "bionic_fortify_tests_defaults",
171    cflags: [
172        "-Wno-error",
173        "-U_FORTIFY_SOURCE",
174    ],
175    srcs: ["fortify_test_main.cpp"],
176    target: {
177        host: {
178            clang_cflags: ["-D__clang__"],
179        },
180    },
181}
182
183cc_test_library {
184    name: "libfortify1-tests-clang",
185    defaults: ["bionic_fortify_tests_defaults", "bionic_tests_defaults"],
186    clang: true,
187    cflags: [
188        "-D_FORTIFY_SOURCE=1",
189        "-DTEST_NAME=Fortify1_clang"
190    ],
191    shared: {
192        enabled: false,
193    },
194}
195
196cc_test_library {
197    name: "libfortify2-tests-clang",
198    defaults: ["bionic_fortify_tests_defaults", "bionic_tests_defaults"],
199    clang: true,
200    cflags: [
201        "-D_FORTIFY_SOURCE=2",
202        "-DTEST_NAME=Fortify2_clang"
203    ],
204    shared: {
205        enabled: false,
206    },
207}
208
209// -----------------------------------------------------------------------------
210// Library of all tests (excluding the dynamic linker tests).
211// -----------------------------------------------------------------------------
212cc_test_library {
213    name: "libBionicTests",
214    defaults: ["bionic_tests_defaults"],
215    whole_static_libs: [
216        "libBionicStandardTests",
217        "libfortify1-tests-clang",
218        "libfortify2-tests-clang",
219    ],
220    shared: {
221        enabled: false,
222    },
223}
224
225// -----------------------------------------------------------------------------
226// Library of bionic customized gtest main function, with simplified output format.
227// -----------------------------------------------------------------------------
228cc_test_library {
229    name: "libBionicGtestMain",
230    defaults: ["bionic_tests_defaults"],
231    srcs: [
232        "gtest_main.cpp",
233        "gtest_globals.cpp",
234    ],
235    static_libs: [
236        "libbase",
237    ],
238    include_dirs: [
239        "bionic/libc",
240    ],
241    target: {
242        darwin: {
243            enabled: true,
244        },
245    },
246    shared: {
247        enabled: false,
248    },
249}
250
251cc_test_library {
252    name: "libBionicLoaderTests",
253    defaults: ["bionic_tests_defaults", "llvm-defaults"],
254    srcs: [
255        "atexit_test.cpp",
256        "dl_test.cpp",
257        "dlfcn_symlink_support.cpp",
258        "dlfcn_test.cpp",
259        "pthread_dlfcn_test.cpp",
260    ],
261    static_libs: [
262        "libbase",
263    ],
264    include_dirs: [
265        "bionic/libc",
266    ],
267    shared: {
268        enabled: false,
269    },
270    target: {
271        android: {
272            srcs: [
273                "cfi_test.cpp",
274                "dlext_test.cpp",
275                "libdl_test.cpp",
276            ],
277            static_libs: [
278                "libpagemap",
279                "libLLVMObject",
280                "libLLVMBitReader",
281                "libLLVMMC",
282                "libLLVMMCParser",
283                "libLLVMCore",
284                "libLLVMSupport",
285            ],
286        }
287    }
288}
289
290// -----------------------------------------------------------------------------
291// Library of bionic customized gtest main function, with normal gtest output format,
292// which is needed by bionic cts test.
293// -----------------------------------------------------------------------------
294cc_test_library {
295    name: "libBionicCtsGtestMain",
296    defaults: ["bionic_tests_defaults"],
297    srcs: [
298        "gtest_main.cpp",
299        "gtest_globals_cts.cpp",
300    ],
301    cppflags: ["-DUSING_GTEST_OUTPUT_FORMAT"],
302    shared: {
303        enabled: false,
304    },
305}
306
307// -----------------------------------------------------------------------------
308// Tests for the device using bionic's .so. Run with:
309//   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests32
310//   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests64
311//   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests-gcc32
312//   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests-gcc64
313// -----------------------------------------------------------------------------
314cc_defaults {
315    name: "bionic_unit_tests_defaults",
316    host_supported: false,
317
318    whole_static_libs: [
319        "libBionicTests",
320        "libBionicLoaderTests",
321        "libBionicGtestMain",
322    ],
323
324    static_libs: [
325        "libtinyxml2",
326        "liblog",
327        "libbase",
328    ],
329
330    srcs: [
331        // TODO: Include __cxa_thread_atexit_test.cpp to glibc tests once it is upgraded (glibc 2.18+)
332        "__cxa_thread_atexit_test.cpp",
333        "thread_local_test.cpp",
334    ],
335
336    conlyflags: [
337        "-fexceptions",
338        "-fnon-call-exceptions",
339    ],
340
341    ldflags: ["-Wl,--export-dynamic"],
342
343    include_dirs: ["bionic/libc"],
344
345    stl: "libc++_static",
346
347    target: {
348        android: {
349            shared_libs: [
350                "libdl",
351                "libdl_preempt_test_1",
352                "libdl_preempt_test_2",
353                "libdl_test_df_1_global",
354            ],
355            static_libs: [
356                // The order of these libraries matters, do not shuffle them.
357                "libbase",
358                "libpagemap",
359                "libziparchive",
360                "libz",
361                "libutils",
362                "libLLVMObject",
363                "libLLVMBitReader",
364                "libLLVMMC",
365                "libLLVMMCParser",
366                "libLLVMCore",
367                "libLLVMSupport",
368            ],
369            ldflags: [
370                "-Wl,--rpath,${ORIGIN}/../bionic-loader-test-libs",
371                "-Wl,--enable-new-dtags",
372            ],
373        },
374    }
375}
376
377cc_test {
378    name: "bionic-unit-tests",
379    defaults: ["bionic_unit_tests_defaults", "bionic_tests_defaults"],
380    clang: true,
381
382    target: {
383        android: {
384            shared_libs: ["libicuuc"],
385        },
386    },
387}
388
389// -----------------------------------------------------------------------------
390// Tests for the device linked against bionic's static library. Run with:
391//   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static32
392//   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static64
393// -----------------------------------------------------------------------------
394cc_test {
395    name: "bionic-unit-tests-static",
396    defaults: ["bionic_tests_defaults"],
397    host_supported: false,
398
399    srcs: [
400        "gtest_preinit_debuggerd.cpp",
401    ],
402    whole_static_libs: [
403        "libBionicTests",
404        "libBionicGtestMain",
405    ],
406
407    static_libs: [
408        "libm",
409        "libc",
410        "libc++_static",
411        "libdl",
412        "libtinyxml2",
413        "liblog",
414        "libbase",
415        "libdebuggerd_handler",
416    ],
417
418    static_executable: true,
419    stl: "libc++_static",
420
421    // libc and libc++ both define std::nothrow. libc's is a private symbol, but this
422    // still causes issues when linking libc.a and libc++.a, since private isn't
423    // effective until it has been linked. To fix this, just allow multiple symbol
424    // definitions for the static tests.
425    ldflags: ["-Wl,--allow-multiple-definition"],
426}
427
428// -----------------------------------------------------------------------------
429// Tests to run on the host and linked against glibc. Run with:
430//   cd bionic/tests; mm bionic-unit-tests-glibc-run
431// -----------------------------------------------------------------------------
432
433cc_test_host {
434    name: "bionic-unit-tests-glibc",
435    defaults: ["bionic_tests_defaults"],
436
437    srcs: [
438        "atexit_test.cpp",
439        "dlfcn_symlink_support.cpp",
440        "dlfcn_test.cpp",
441        "dl_test.cpp",
442        "pthread_dlfcn_test.cpp",
443    ],
444
445    shared_libs: [
446        "libdl_preempt_test_1",
447        "libdl_preempt_test_2",
448
449        "libdl_test_df_1_global",
450    ],
451
452    whole_static_libs: [
453        "libBionicStandardTests",
454        "libBionicGtestMain",
455        "libfortify1-tests-clang",
456        "libfortify2-tests-clang",
457    ],
458
459    static_libs: [
460        "libbase",
461        "liblog",
462        "libcutils",
463    ],
464
465    host_ldlibs: [
466        "-lresolv",
467        "-lrt",
468        "-ldl",
469        "-lutil",
470    ],
471
472    include_dirs: ["bionic/libc"],
473
474    ldflags: [
475        "-Wl,--rpath,${ORIGIN}/../bionic-loader-test-libs",
476        "-Wl,--export-dynamic",
477    ],
478
479    sanitize: {
480        never: false,
481    },
482}
483
484subdirs = ["libs"]
485