• 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
17LOCAL_PATH := $(call my-dir)
18
19# -----------------------------------------------------------------------------
20# Unit tests.
21# -----------------------------------------------------------------------------
22
23ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
24build_host := true
25else
26build_host := false
27endif
28
29common_additional_dependencies := $(LOCAL_PATH)/Android.mk $(LOCAL_PATH)/Android.build.mk
30
31# -----------------------------------------------------------------------------
32# All standard tests.
33# -----------------------------------------------------------------------------
34test_cflags = \
35    -fstack-protector-all \
36    -g \
37    -Wall -Wextra -Wunused \
38    -Werror \
39    -fno-builtin \
40
41test_cflags += -D__STDC_LIMIT_MACROS  # For glibc.
42
43test_cppflags := \
44
45libBionicStandardTests_src_files := \
46    arpa_inet_test.cpp \
47    buffer_tests.cpp \
48    bug_26110743_test.cpp \
49    complex_test.cpp \
50    ctype_test.cpp \
51    dirent_test.cpp \
52    error_test.cpp \
53    eventfd_test.cpp \
54    fcntl_test.cpp \
55    fenv_test.cpp \
56    ftw_test.cpp \
57    getauxval_test.cpp \
58    getcwd_test.cpp \
59    ifaddrs_test.cpp \
60    inttypes_test.cpp \
61    libc_logging_test.cpp \
62    libgen_basename_test.cpp \
63    libgen_test.cpp \
64    locale_test.cpp \
65    malloc_test.cpp \
66    math_test.cpp \
67    mntent_test.cpp \
68    netdb_test.cpp \
69    net_if_test.cpp \
70    netinet_in_test.cpp \
71    netinet_udp_test.cpp \
72    pthread_test.cpp \
73    pty_test.cpp \
74    regex_test.cpp \
75    sched_test.cpp \
76    search_test.cpp \
77    semaphore_test.cpp \
78    setjmp_test.cpp \
79    signal_test.cpp \
80    stack_protector_test.cpp \
81    stack_protector_test_helper.cpp \
82    stack_unwinding_test.cpp \
83    stdatomic_test.cpp \
84    stdint_test.cpp \
85    stdio_nofortify_test.cpp \
86    stdio_test.cpp \
87    stdio_ext_test.cpp \
88    stdlib_test.cpp \
89    string_nofortify_test.cpp \
90    string_test.cpp \
91    string_posix_strerror_r_test.cpp \
92    strings_nofortify_test.cpp \
93    strings_test.cpp \
94    stubs_test.cpp \
95    sstream_test.cpp \
96    sys_epoll_test.cpp \
97    sys_mman_test.cpp \
98    sys_personality_test.cpp \
99    sys_prctl_test.cpp \
100    sys_procfs_test.cpp \
101    sys_resource_test.cpp \
102    sys_select_test.cpp \
103    sys_sendfile_test.cpp \
104    sys_socket_test.cpp \
105    sys_stat_test.cpp \
106    sys_statvfs_test.cpp \
107    sys_syscall_test.cpp \
108    sys_sysinfo_test.cpp \
109    sys_sysmacros_test.cpp \
110    sys_time_test.cpp \
111    sys_timex_test.cpp \
112    sys_types_test.cpp \
113    sys_uio_test.cpp \
114    sys_vfs_test.cpp \
115    sys_xattr_test.cpp \
116    system_properties_test.cpp \
117    time_test.cpp \
118    uchar_test.cpp \
119    uniqueptr_test.cpp \
120    unistd_nofortify_test.cpp \
121    unistd_test.cpp \
122    utmp_test.cpp \
123    wchar_test.cpp \
124
125libBionicStandardTests_cflags := \
126    $(test_cflags) \
127
128libBionicStandardTests_cppflags := \
129    $(test_cppflags) \
130
131libBionicStandardTests_c_includes := \
132    bionic/libc \
133    external/tinyxml2 \
134
135libBionicStandardTests_static_libraries := \
136    libbase \
137
138libBionicStandardTests_ldlibs_host := \
139    -lrt \
140
141# Clang/llvm has incompatible long double (fp128) for x86_64.
142# https://llvm.org/bugs/show_bug.cgi?id=23897
143# This affects most of math_test.cpp.
144ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86_64))
145libBionicStandardTests_clang_target := false
146endif
147
148module := libBionicStandardTests
149module_tag := optional
150build_type := target
151build_target := STATIC_TEST_LIBRARY
152include $(LOCAL_PATH)/Android.build.mk
153build_type := host
154include $(LOCAL_PATH)/Android.build.mk
155
156# -----------------------------------------------------------------------------
157# Fortify tests.
158# -----------------------------------------------------------------------------
159$(foreach compiler,gcc clang, \
160  $(foreach test,1 2, \
161    $(eval fortify$(test)-tests-$(compiler)_cflags := \
162      $(test_cflags) \
163      -Wno-error \
164      -U_FORTIFY_SOURCE \
165      -D_FORTIFY_SOURCE=$(test) \
166      -DTEST_NAME=Fortify$(test)_$(compiler)); \
167    $(eval fortify$(test)-tests-$(compiler)_src_files := \
168      fortify_test_main.cpp); \
169    $(eval fortify_libs += fortify$(test)-tests-$(compiler)); \
170  ) \
171)
172
173fortify1-tests-gcc_clang_target := false
174module := fortify1-tests-gcc
175module_tag := optional
176build_type := target
177build_target := STATIC_TEST_LIBRARY
178include $(LOCAL_PATH)/Android.build.mk
179build_type := host
180include $(LOCAL_PATH)/Android.build.mk
181
182fortify2-tests-gcc_clang_target := false
183module := fortify2-tests-gcc
184module_tag := optional
185build_type := target
186build_target := STATIC_TEST_LIBRARY
187include $(LOCAL_PATH)/Android.build.mk
188build_type := host
189include $(LOCAL_PATH)/Android.build.mk
190
191fortify1-tests-clang_clang_target := true
192fortify1-tests-clang_cflags_host := -D__clang__
193
194module := fortify1-tests-clang
195module_tag := optional
196build_type := target
197build_target := STATIC_TEST_LIBRARY
198include $(LOCAL_PATH)/Android.build.mk
199build_type := host
200include $(LOCAL_PATH)/Android.build.mk
201
202fortify2-tests-clang_clang_target := true
203
204fortify2-tests-clang_cflags_host := -D__clang__
205
206module := fortify2-tests-clang
207module_tag := optional
208build_type := target
209build_target := STATIC_TEST_LIBRARY
210include $(LOCAL_PATH)/Android.build.mk
211build_type := host
212include $(LOCAL_PATH)/Android.build.mk
213
214# -----------------------------------------------------------------------------
215# Library of all tests (excluding the dynamic linker tests).
216# -----------------------------------------------------------------------------
217libBionicTests_whole_static_libraries := \
218    libBionicStandardTests \
219    $(fortify_libs) \
220
221module := libBionicTests
222module_tag := optional
223build_type := target
224build_target := STATIC_TEST_LIBRARY
225include $(LOCAL_PATH)/Android.build.mk
226build_type := host
227include $(LOCAL_PATH)/Android.build.mk
228
229# -----------------------------------------------------------------------------
230# Library of bionic customized gtest main function, with simplified output format.
231# -----------------------------------------------------------------------------
232libBionicGtestMain_src_files := gtest_main.cpp
233
234libBionicGtestMain_cflags := $(test_cflags)
235
236libBionicGtestMain_cppflags := $(test_cppflags)
237
238module := libBionicGtestMain
239module_tag := optional
240build_type := target
241build_target := STATIC_TEST_LIBRARY
242include $(LOCAL_PATH)/Android.build.mk
243build_type := host
244
245ifeq ($(HOST_OS),$(filter $(HOST_OS),linux darwin))
246saved_build_host := $(build_host)
247build_host := true
248include $(LOCAL_PATH)/Android.build.mk
249build_host := $(saved_build_host)
250endif
251
252# -----------------------------------------------------------------------------
253# Library of bionic customized gtest main function, with normal gtest output format,
254# which is needed by bionic cts test.
255# -----------------------------------------------------------------------------
256libBionicCtsGtestMain_src_files := gtest_main.cpp
257
258libBionicCtsGtestMain_cflags := $(test_cflags)
259
260libBionicCtsGtestMain_cppflags := $(test_cppflags) -DUSING_GTEST_OUTPUT_FORMAT \
261
262module := libBionicCtsGtestMain
263module_tag := optional
264build_type := target
265build_target := STATIC_TEST_LIBRARY
266include $(LOCAL_PATH)/Android.build.mk
267build_type := host
268include $(LOCAL_PATH)/Android.build.mk
269
270# -----------------------------------------------------------------------------
271# Tests for the device using bionic's .so. Run with:
272#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests32
273#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests64
274#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests-gcc32
275#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests-gcc64
276# -----------------------------------------------------------------------------
277common_bionic-unit-tests_whole_static_libraries := \
278    libBionicTests \
279    libBionicGtestMain \
280
281common_bionic-unit-tests_static_libraries := \
282    libtinyxml2 \
283    liblog \
284    libbase \
285
286# TODO: Include __cxa_thread_atexit_test.cpp to glibc tests once it is upgraded (glibc 2.18+)
287common_bionic-unit-tests_src_files := \
288    atexit_test.cpp \
289    dl_test.cpp \
290    dlext_test.cpp \
291    __cxa_thread_atexit_test.cpp \
292    dlfcn_test.cpp \
293    libdl_test.cpp \
294    pthread_dlfcn_test.cpp \
295    thread_local_test.cpp \
296
297common_bionic-unit-tests_cflags := $(test_cflags)
298
299common_bionic-unit-tests_conlyflags := \
300    -fexceptions \
301    -fnon-call-exceptions \
302
303common_bionic-unit-tests_cppflags := $(test_cppflags)
304
305common_bionic-unit-tests_ldflags := \
306    -Wl,--export-dynamic
307
308common_bionic-unit-tests_c_includes := \
309    bionic/libc \
310
311common_bionic-unit-tests_shared_libraries_target := \
312    libdl \
313    libpagemap \
314    libdl_preempt_test_1 \
315    libdl_preempt_test_2 \
316    libdl_test_df_1_global \
317
318# The order of these libraries matters, do not shuffle them.
319common_bionic-unit-tests_static_libraries_target := \
320    libbase \
321    libziparchive \
322    liblog \
323    libz \
324    libutils \
325
326module_tag := optional
327build_type := target
328build_target := NATIVE_TEST
329
330module := bionic-unit-tests
331bionic-unit-tests_clang_target := true
332bionic-unit-tests_whole_static_libraries := $(common_bionic-unit-tests_whole_static_libraries)
333bionic-unit-tests_static_libraries := $(common_bionic-unit-tests_static_libraries)
334bionic-unit-tests_src_files := $(common_bionic-unit-tests_src_files)
335bionic-unit-tests_cflags := $(common_bionic-unit-tests_cflags)
336bionic-unit-tests_conlyflags := $(common_bionic-unit-tests_conlyflags)
337bionic-unit-tests_cppflags := $(common_bionic-unit-tests_cppflags)
338bionic-unit-tests_ldflags := $(common_bionic-unit-tests_ldflags)
339bionic-unit-tests_c_includes := $(common_bionic-unit-tests_c_includes)
340bionic-unit-tests_shared_libraries_target := $(common_bionic-unit-tests_shared_libraries_target)
341bionic-unit-tests_static_libraries_target := $(common_bionic-unit-tests_static_libraries_target)
342include $(LOCAL_PATH)/Android.build.mk
343
344module := bionic-unit-tests-gcc
345bionic-unit-tests-gcc_clang_target := false
346bionic-unit-tests-gcc_whole_static_libraries := $(common_bionic-unit-tests_whole_static_libraries)
347bionic-unit-tests-gcc_static_libraries := $(common_bionic-unit-tests_static_libraries)
348bionic-unit-tests-gcc_src_files := $(common_bionic-unit-tests_src_files)
349bionic-unit-tests-gcc_cflags := $(common_bionic-unit-tests_cflags)
350bionic-unit-tests-gcc_conlyflags := $(common_bionic-unit-tests_conlyflags)
351bionic-unit-tests-gcc_cppflags := $(common_bionic-unit-tests_cppflags)
352bionic-unit-tests-gcc_ldflags := $(common_bionic-unit-tests_ldflags)
353bionic-unit-tests-gcc_c_includes := $(common_bionic-unit-tests_c_includes)
354bionic-unit-tests-gcc_shared_libraries_target := $(common_bionic-unit-tests_shared_libraries_target)
355bionic-unit-tests-gcc_static_libraries_target := $(common_bionic-unit-tests_static_libraries_target)
356include $(LOCAL_PATH)/Android.build.mk
357
358# -----------------------------------------------------------------------------
359# Tests for the device linked against bionic's static library. Run with:
360#   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static32
361#   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static64
362# -----------------------------------------------------------------------------
363bionic-unit-tests-static_whole_static_libraries := \
364    libBionicTests \
365    libBionicGtestMain \
366
367bionic-unit-tests-static_static_libraries := \
368    libm \
369    libc \
370    libc++_static \
371    libdl \
372    libtinyxml2 \
373    liblog \
374    libbase \
375
376bionic-unit-tests-static_force_static_executable := true
377
378# libc and libc++ both define std::nothrow. libc's is a private symbol, but this
379# still causes issues when linking libc.a and libc++.a, since private isn't
380# effective until it has been linked. To fix this, just allow multiple symbol
381# definitions for the static tests.
382bionic-unit-tests-static_ldflags := -Wl,--allow-multiple-definition
383
384module := bionic-unit-tests-static
385module_tag := optional
386build_type := target
387build_target := NATIVE_TEST
388include $(LOCAL_PATH)/Android.build.mk
389
390# -----------------------------------------------------------------------------
391# Tests to run on the host and linked against glibc. Run with:
392#   cd bionic/tests; mm bionic-unit-tests-glibc-run
393# -----------------------------------------------------------------------------
394
395ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
396
397bionic-unit-tests-glibc_src_files := \
398    atexit_test.cpp \
399    dlfcn_test.cpp \
400    dl_test.cpp \
401    pthread_dlfcn_test.cpp \
402
403bionic-unit-tests-glibc_shared_libraries := \
404    libdl_preempt_test_1 \
405    libdl_preempt_test_2
406
407bionic-unit-tests-glibc_shared_libraries += libdl_test_df_1_global
408
409bionic-unit-tests-glibc_whole_static_libraries := \
410    libBionicStandardTests \
411    libBionicGtestMain \
412    $(fortify_libs) \
413
414bionic-unit-tests-glibc_static_libraries := \
415    libbase \
416    liblog \
417    libcutils \
418
419bionic-unit-tests-glibc_ldlibs := \
420    -lrt -ldl -lutil \
421
422bionic-unit-tests-glibc_c_includes := \
423    bionic/libc \
424
425bionic-unit-tests-glibc_cflags := $(test_cflags)
426bionic-unit-tests-glibc_cppflags := $(test_cppflags)
427bionic-unit-tests-glibc_ldflags := -Wl,--export-dynamic
428
429bionic-unit-tests-glibc_allow_asan := true
430
431module := bionic-unit-tests-glibc
432module_tag := optional
433build_type := host
434build_target := NATIVE_TEST
435include $(LOCAL_PATH)/Android.build.mk
436
437# -----------------------------------------------------------------------------
438# Compile time tests.
439# -----------------------------------------------------------------------------
440
441# Some of these are intentionally using = instead of := since we need access to
442# some variables not initialtized until we're in the build system.
443
444include $(CLEAR_VARS)
445LOCAL_ADDITIONAL_DEPENDENCIES := \
446    $(LOCAL_PATH)/Android.mk \
447    $(LOCAL_PATH)/file-check-cxx \
448    | $(HOST_OUT_EXECUTABLES)/FileCheck$(HOST_EXECUTABLE_SUFFIX) \
449
450LOCAL_CXX = $(LOCAL_PATH)/file-check-cxx \
451    $(HOST_OUT_EXECUTABLES)/FileCheck \
452    $($(LOCAL_2ND_ARCH_VAR_PREFIX)TARGET_CXX) \
453    GCC \
454
455LOCAL_CLANG := false
456LOCAL_MODULE := bionic-compile-time-tests-g++
457LOCAL_CPPFLAGS := -Wall
458# Disable color diagnostics so the warnings output matches the source
459LOCAL_CPPFLAGS +=  -fdiagnostics-color=never
460LOCAL_SRC_FILES := fortify_compilation_test.cpp
461include $(BUILD_STATIC_LIBRARY)
462
463include $(CLEAR_VARS)
464LOCAL_ADDITIONAL_DEPENDENCIES := \
465    $(LOCAL_PATH)/Android.mk \
466    $(LOCAL_PATH)/file-check-cxx \
467    | $(HOST_OUT_EXECUTABLES)/FileCheck$(HOST_EXECUTABLE_SUFFIX) \
468
469LOCAL_CXX := $(LOCAL_PATH)/file-check-cxx \
470    $(HOST_OUT_EXECUTABLES)/FileCheck \
471    $(LLVM_PREBUILTS_PATH)/clang++ \
472    CLANG \
473
474LOCAL_CLANG := true
475LOCAL_MODULE := bionic-compile-time-tests-clang++
476LOCAL_CPPFLAGS := -Wall
477# Disable color diagnostics so the warnings output matches the source
478LOCAL_CPPFLAGS += -fno-color-diagnostics
479# FileCheck will error if there aren't any CLANG: lines in the file, but there
480# don't appear to be any cases where clang _does_ emit warnings for sn?printf :(
481LOCAL_SRC_FILES :=
482include $(BUILD_STATIC_LIBRARY)
483
484# -----------------------------------------------------------------------------
485# Host glibc tests.
486# -----------------------------------------------------------------------------
487
488# gtest needs ANDROID_DATA/local/tmp for death test output.
489# Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
490# Use the current target out directory as ANDROID_DATA.
491# BIONIC_TEST_FLAGS is either empty or it comes from the user.
492.PHONY: bionic-unit-tests-glibc-run
493bionic-unit-tests-glibc-run: bionic-unit-tests-glibc
494	mkdir -p $(TARGET_OUT_DATA)/local/tmp
495	ANDROID_DATA=$(TARGET_OUT_DATA) \
496	ANDROID_ROOT=$(TARGET_OUT) \
497		$(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc64 $(BIONIC_TEST_FLAGS)
498
499# -----------------------------------------------------------------------------
500# Run the unit tests built against x86 bionic on an x86 host.
501# -----------------------------------------------------------------------------
502
503include $(LOCAL_PATH)/../build/run-on-host.mk
504
505ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
506
507TEST_TIMEOUT := 0
508
509# BIONIC_TEST_FLAGS is either empty or it comes from the user.
510.PHONY: bionic-unit-tests-run-on-host32
511bionic-unit-tests-run-on-host32: bionic-unit-tests bionic-prepare-run-on-host
512	ANDROID_DATA=$(TARGET_OUT_DATA) \
513	ANDROID_DNS_MODE=local \
514	ANDROID_ROOT=$(TARGET_OUT) \
515		timeout $(TEST_TIMEOUT) \
516		$(TARGET_OUT_DATA)/nativetest/bionic-unit-tests/bionic-unit-tests32 $(BIONIC_TEST_FLAGS)
517
518ifeq ($(TARGET_IS_64_BIT),true)
519# add target to run lp64 tests
520.PHONY: bionic-unit-tests-run-on-host64
521bionic-unit-tests-run-on-host64: bionic-unit-tests bionic-prepare-run-on-host
522	ANDROID_DATA=$(TARGET_OUT_DATA) \
523	ANDROID_DNS_MODE=local \
524	ANDROID_ROOT=$(TARGET_OUT) \
525		timeout $(TEST_TIMEOUT) \
526		$(TARGET_OUT_DATA)/nativetest64/bionic-unit-tests/bionic-unit-tests64 $(BIONIC_TEST_FLAGS)
527endif
528
529endif # x86 x86_64
530endif # linux-x86
531
532include $(call first-makefiles-under,$(LOCAL_PATH))
533