Android.mk revision 9fea4090f1160ad8ca77e7b2a9a1a81dc4376329
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
17ifneq ($(BUILD_TINY_ANDROID),true)
18
19LOCAL_PATH := $(call my-dir)
20
21# -----------------------------------------------------------------------------
22# Unit tests.
23# -----------------------------------------------------------------------------
24
25ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
26build_host := true
27else
28build_host := false
29endif
30
31common_additional_dependencies := $(LOCAL_PATH)/Android.mk $(LOCAL_PATH)/Android.build.mk
32
33# -----------------------------------------------------------------------------
34# All standard tests.
35# -----------------------------------------------------------------------------
36test_cflags = \
37    -fstack-protector-all \
38    -g \
39    -Wall -Wextra -Wunused \
40    -Werror \
41    -fno-builtin \
42
43test_cflags += -D__STDC_LIMIT_MACROS  # For glibc.
44
45ifeq ($(MALLOC_IMPL),dlmalloc)
46test_cflags += -DUSE_DLMALLOC
47else
48test_cflags += -DUSE_JEMALLOC
49endif
50
51test_cppflags = \
52    -std=gnu++11 \
53
54libBionicStandardTests_src_files := \
55    arpa_inet_test.cpp \
56    buffer_tests.cpp \
57    complex_test.cpp \
58    ctype_test.cpp \
59    dirent_test.cpp \
60    eventfd_test.cpp \
61    fcntl_test.cpp \
62    fenv_test.cpp \
63    ftw_test.cpp \
64    getauxval_test.cpp \
65    getcwd_test.cpp \
66    inttypes_test.cpp \
67    libc_logging_test.cpp \
68    libgen_test.cpp \
69    locale_test.cpp \
70    malloc_test.cpp \
71    math_test.cpp \
72    mntent_test.cpp \
73    netdb_test.cpp \
74    pthread_test.cpp \
75    regex_test.cpp \
76    sched_test.cpp \
77    search_test.cpp \
78    semaphore_test.cpp \
79    setjmp_test.cpp \
80    signal_test.cpp \
81    stack_protector_test.cpp \
82    stack_unwinding_test.cpp \
83    stdatomic_test.cpp \
84    stdint_test.cpp \
85    stdio_test.cpp \
86    stdio_ext_test.cpp \
87    stdlib_test.cpp \
88    string_test.cpp \
89    string_posix_strerror_r_test.cpp \
90    strings_test.cpp \
91    stubs_test.cpp \
92    sstream_test.cpp \
93    sys_epoll_test.cpp \
94    sys_mman_test.cpp \
95    sys_resource_test.cpp \
96    sys_select_test.cpp \
97    sys_sendfile_test.cpp \
98    sys_socket_test.cpp \
99    sys_stat_test.cpp \
100    sys_statvfs_test.cpp \
101    sys_syscall_test.cpp \
102    sys_sysinfo_test.cpp \
103    sys_time_test.cpp \
104    sys_types_test.cpp \
105    sys_vfs_test.cpp \
106    system_properties_test.cpp \
107    time_test.cpp \
108    uchar_test.cpp \
109    uniqueptr_test.cpp \
110    unistd_test.cpp \
111    wchar_test.cpp \
112
113libBionicStandardTests_cflags := \
114    $(test_cflags) \
115
116ifeq ($(MALLOC_IMPL),dlmalloc)
117  libBionicStandardTests_cflags += -DUSE_DLMALLOC
118else
119  libBionicStandardTests_cflags += -DUSE_JEMALLOC
120endif
121
122libBionicStandardTests_cppflags := \
123    $(test_cppflags) \
124
125libBionicStandardTests_c_includes := \
126    bionic/libc \
127    external/tinyxml2 \
128
129libBionicStandardTests_ldlibs_host := \
130    -lrt \
131
132module := libBionicStandardTests
133module_tag := optional
134build_type := target
135build_target := STATIC_TEST_LIBRARY
136include $(LOCAL_PATH)/Android.build.mk
137build_type := host
138include $(LOCAL_PATH)/Android.build.mk
139
140# -----------------------------------------------------------------------------
141# Fortify tests.
142# -----------------------------------------------------------------------------
143$(foreach compiler,gcc clang, \
144  $(foreach test,1 2, \
145    $(eval fortify$(test)-tests-$(compiler)_cflags := \
146      $(test_cflags) \
147      -Wno-error \
148      -U_FORTIFY_SOURCE \
149      -D_FORTIFY_SOURCE=$(test) \
150      -DTEST_NAME=Fortify$(test)_$(compiler)); \
151    $(eval fortify$(test)-tests-$(compiler)_src_files := \
152      fortify_test.cpp); \
153    $(eval fortify_libs += fortify$(test)-tests-$(compiler)); \
154  ) \
155)
156
157module := fortify1-tests-gcc
158module_tag := optional
159build_type := target
160build_target := STATIC_TEST_LIBRARY
161include $(LOCAL_PATH)/Android.build.mk
162build_type := host
163include $(LOCAL_PATH)/Android.build.mk
164
165module := fortify2-tests-gcc
166module_tag := optional
167build_type := target
168build_target := STATIC_TEST_LIBRARY
169include $(LOCAL_PATH)/Android.build.mk
170build_type := host
171include $(LOCAL_PATH)/Android.build.mk
172
173fortify1-tests-clang_clang_target := true
174fortify1-tests-clang_cflags_host := -D__clang__
175
176module := fortify1-tests-clang
177module_tag := optional
178build_type := target
179build_target := STATIC_TEST_LIBRARY
180include $(LOCAL_PATH)/Android.build.mk
181build_type := host
182include $(LOCAL_PATH)/Android.build.mk
183
184fortify2-tests-clang_clang_target := true
185
186fortify2-tests-clang_cflags_host := -D__clang__
187
188module := fortify2-tests-clang
189module_tag := optional
190build_type := target
191build_target := STATIC_TEST_LIBRARY
192include $(LOCAL_PATH)/Android.build.mk
193build_type := host
194include $(LOCAL_PATH)/Android.build.mk
195
196# -----------------------------------------------------------------------------
197# Library of all tests (excluding the dynamic linker tests).
198# -----------------------------------------------------------------------------
199libBionicTests_whole_static_libraries := \
200    libBionicStandardTests \
201    $(fortify_libs) \
202
203module := libBionicTests
204module_tag := optional
205build_type := target
206build_target := STATIC_TEST_LIBRARY
207include $(LOCAL_PATH)/Android.build.mk
208build_type := host
209include $(LOCAL_PATH)/Android.build.mk
210
211# -----------------------------------------------------------------------------
212# Tests for the device using bionic's .so. Run with:
213#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests32
214#   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests64
215# -----------------------------------------------------------------------------
216bionic-unit-tests_whole_static_libraries := \
217    libBionicTests \
218
219bionic-unit-tests_static_libraries := \
220    libtinyxml2 \
221    liblog \
222
223bionic-unit-tests_src_files := \
224    atexit_test.cpp \
225    dl_test.cpp \
226    dlext_test.cpp \
227    dlfcn_test.cpp \
228
229bionic-unit-tests_cflags := $(test_cflags)
230
231bionic-unit-tests_conlyflags := \
232    -fexceptions \
233    -fnon-call-exceptions \
234
235bionic-unit-tests_cppflags := $(test_cppflags)
236
237bionic-unit-tests_ldflags := \
238    -Wl,--export-dynamic
239
240bionic-unit-tests_c_includes := \
241    bionic/libc \
242    $(call include-path-for, libpagemap) \
243
244bionic-unit-tests_shared_libraries_target := \
245    libdl \
246    libpagemap \
247    libdl_preempt_test_1 \
248    libdl_preempt_test_2
249
250ifneq ($(filter $(TARGET_ARCH),arm arm64),$(TARGET_ARCH))
251bionic-unit-tests_shared_libraries_target += libdl_test_df_1_global
252endif
253
254module := bionic-unit-tests
255module_tag := optional
256build_type := target
257build_target := NATIVE_TEST
258include $(LOCAL_PATH)/Android.build.mk
259
260# -----------------------------------------------------------------------------
261# Tests for the device linked against bionic's static library. Run with:
262#   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static32
263#   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static64
264# -----------------------------------------------------------------------------
265bionic-unit-tests-static_whole_static_libraries := \
266    libBionicTests \
267
268bionic-unit-tests-static_static_libraries := \
269    libm \
270    libc \
271    libc++_static \
272    libdl \
273    libtinyxml2 \
274    liblog \
275
276bionic-unit-tests-static_force_static_executable := true
277
278# libc and libc++ both define std::nothrow. libc's is a private symbol, but this
279# still causes issues when linking libc.a and libc++.a, since private isn't
280# effective until it has been linked. To fix this, just allow multiple symbol
281# definitions for the static tests.
282bionic-unit-tests-static_ldflags := -Wl,--allow-multiple-definition
283
284module := bionic-unit-tests-static
285module_tag := optional
286build_type := target
287build_target := NATIVE_TEST
288include $(LOCAL_PATH)/Android.build.mk
289
290# -----------------------------------------------------------------------------
291# Tests to run on the host and linked against glibc. Run with:
292#   cd bionic/tests; mm bionic-unit-tests-glibc-run
293# -----------------------------------------------------------------------------
294
295ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64))
296
297bionic-unit-tests-glibc_src_files := \
298    atexit_test.cpp \
299    dlfcn_test.cpp \
300    dl_test.cpp \
301
302bionic-unit-tests-glibc_shared_libraries := \
303    libdl_preempt_test_1 \
304    libdl_preempt_test_2
305
306bionic-unit-tests-glibc_shared_libraries += libdl_test_df_1_global
307
308bionic-unit-tests-glibc_whole_static_libraries := \
309    libBionicStandardTests \
310
311bionic-unit-tests-glibc_ldlibs := \
312    -lrt -ldl \
313
314bionic-unit-tests-glibc_c_includes := \
315    bionic/libc \
316
317bionic-unit-tests-glibc_cflags := $(test_cflags)
318bionic-unit-tests-glibc_cppflags := $(test_cppflags)
319bionic-unit-tests-glibc_ldflags := -Wl,--export-dynamic
320
321bionic-unit-tests-glibc_allow_asan := true
322
323module := bionic-unit-tests-glibc
324module_tag := optional
325build_type := host
326build_target := NATIVE_TEST
327include $(LOCAL_PATH)/Android.build.mk
328
329# -----------------------------------------------------------------------------
330# Compile time tests.
331# -----------------------------------------------------------------------------
332
333# Some of these are intentionally using = instead of := since we need access to
334# some variables not initialtized until we're in the build system.
335
336include $(CLEAR_VARS)
337LOCAL_ADDITIONAL_DEPENDENCIES := \
338    $(LOCAL_PATH)/Android.mk \
339    $(LOCAL_PATH)/file-check-cxx \
340    | $(HOST_OUT_EXECUTABLES)/FileCheck$(HOST_EXECUTABLE_SUFFIX) \
341
342LOCAL_CXX = $(LOCAL_PATH)/file-check-cxx \
343    $(HOST_OUT_EXECUTABLES)/FileCheck \
344    $($(LOCAL_2ND_ARCH_VAR_PREFIX)CXX_BARE) \
345    GCC \
346
347LOCAL_CLANG := false
348LOCAL_MODULE := bionic-compile-time-tests-g++
349LOCAL_CXXFLAGS := -Wall
350LOCAL_SRC_FILES := fortify_sprintf_warnings.cpp
351include $(BUILD_STATIC_LIBRARY)
352
353include $(CLEAR_VARS)
354LOCAL_ADDITIONAL_DEPENDENCIES := \
355    $(LOCAL_PATH)/Android.mk \
356    $(LOCAL_PATH)/file-check-cxx \
357    | $(HOST_OUT_EXECUTABLES)/FileCheck$(HOST_EXECUTABLE_SUFFIX) \
358
359LOCAL_CXX := $(LOCAL_PATH)/file-check-cxx \
360    $(HOST_OUT_EXECUTABLES)/FileCheck \
361    $(LLVM_PREBUILTS_PATH)/clang++ \
362    CLANG \
363
364LOCAL_CLANG := true
365LOCAL_MODULE := bionic-compile-time-tests-clang++
366LOCAL_CXXFLAGS := -Wall
367# FileCheck will error if there aren't any CLANG: lines in the file, but there
368# don't appear to be any cases where clang _does_ emit warnings for sn?printf :(
369LOCAL_SRC_FILES :=
370include $(BUILD_STATIC_LIBRARY)
371
372# -----------------------------------------------------------------------------
373# Host glibc tests.
374# -----------------------------------------------------------------------------
375
376ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm mips x86))
377LINKER = linker64
378NATIVE_TEST_SUFFIX=64
379else
380LINKER = linker
381NATIVE_TEST_SUFFIX=32
382endif
383
384# gtest needs ANDROID_DATA/local/tmp for death test output.
385# Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
386# Use the current target out directory as ANDROID_DATA.
387# BIONIC_TEST_FLAGS is either empty or it comes from the user.
388bionic-unit-tests-glibc-run: bionic-unit-tests-glibc
389	mkdir -p $(TARGET_OUT_DATA)/local/tmp
390	ANDROID_DATA=$(TARGET_OUT_DATA) \
391	ANDROID_ROOT=$(TARGET_OUT) \
392		$(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS)
393
394# -----------------------------------------------------------------------------
395# Run the unit tests built against x86 bionic on an x86 host.
396# -----------------------------------------------------------------------------
397
398ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
399# gtest needs ANDROID_DATA/local/tmp for death test output.
400# Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
401# bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT.
402# BIONIC_TEST_FLAGS is either empty or it comes from the user.
403bionic-unit-tests-run-on-host-prepare: $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT)/etc/hosts $(TARGET_OUT_EXECUTABLES)/sh
404	if [ ! -d /system ]; then \
405	  echo "Attempting to create /system"; \
406	  sudo mkdir -p -m 0777 /system; \
407	fi
408	mkdir -p $(TARGET_OUT_DATA)/local/tmp
409	ln -fs `realpath $(TARGET_OUT)/bin` /system/
410	ln -fs `realpath $(TARGET_OUT)/etc` /system/
411
412bionic-unit-tests-run-on-host: bionic-unit-tests bionic-unit-tests-run-on-host-prepare
413	ANDROID_DATA=$(TARGET_OUT_DATA) \
414	ANDROID_DNS_MODE=local \
415	ANDROID_ROOT=$(TARGET_OUT) \
416	LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \
417		$(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS)
418endif
419
420ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86_64))
421# add target to run lp32 tests
422bionic-unit-tests-run-on-host32: bionic-unit-tests_32 bionic-unit-tests-run-on-host-prepare
423	ANDROID_DATA=$(TARGET_OUT_DATA) \
424	ANDROID_DNS_MODE=local \
425	ANDROID_ROOT=$(TARGET_OUT) \
426	LD_LIBRARY_PATH=$(2ND_TARGET_OUT_SHARED_LIBRARIES) \
427		$(2ND_TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests32 $(BIONIC_TEST_FLAGS)
428endif
429
430endif # linux-x86
431
432include $(call first-makefiles-under,$(LOCAL_PATH))
433endif # !BUILD_TINY_ANDROID
434