Merge "bionic: move benchmarks out of tests directory"
[android-sdk/platform-bionic.git] / tests / Android.mk
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 #
17 ifneq ($(BUILD_TINY_ANDROID), true)
19 LOCAL_PATH := $(call my-dir)
21 # -----------------------------------------------------------------------------
22 # Unit tests.
23 # -----------------------------------------------------------------------------
25 test_c_flags = \
26     -fstack-protector-all \
27     -g \
28     -Wall -Wextra \
29     -Werror \
30     -fno-builtin \
32 test_src_files = \
33     buffer_tests.cpp \
34     dirent_test.cpp \
35     eventfd_test.cpp \
36     fcntl_test.cpp \
37     fenv_test.cpp \
38     getauxval_test.cpp \
39     getcwd_test.cpp \
40     inttypes_test.cpp \
41     libc_logging_test.cpp \
42     libgen_test.cpp \
43     malloc_test.cpp \
44     math_test.cpp \
45     netdb_test.cpp \
46     pthread_test.cpp \
47     regex_test.cpp \
48     sched_test.cpp \
49     signal_test.cpp \
50     stack_protector_test.cpp \
51     stack_unwinding_test.cpp \
52     statvfs_test.cpp \
53     stdio_test.cpp \
54     stdlib_test.cpp \
55     string_test.cpp \
56     strings_test.cpp \
57     stubs_test.cpp \
58     sys_epoll_test.cpp \
59     sys_select_test.cpp \
60     sys_sendfile_test.cpp \
61     sys_stat_test.cpp \
62     sys_syscall_test.cpp \
63     sys_time_test.cpp \
64     system_properties_test.cpp \
65     time_test.cpp \
66     unistd_test.cpp \
68 test_dynamic_ldflags = -Wl,--export-dynamic -Wl,-u,DlSymTestFunction
69 test_dynamic_src_files = \
70     dlfcn_test.cpp \
72 test_fortify_static_libraries = \
73     fortify1-tests-gcc fortify2-tests-gcc fortify1-tests-clang fortify2-tests-clang
75 include $(CLEAR_VARS)
76 LOCAL_MODULE := bionic-unit-tests-unwind-test-impl
77 LOCAL_CFLAGS += $(test_c_flags) -fexceptions -fnon-call-exceptions
78 LOCAL_SRC_FILES := stack_unwinding_test_impl.c
79 include $(BUILD_STATIC_LIBRARY)
81 include $(CLEAR_VARS)
82 LOCAL_MODULE := bionic-unit-tests-unwind-test-impl-host
83 LOCAL_CFLAGS += $(test_c_flags) -fexceptions -fnon-call-exceptions
84 LOCAL_SRC_FILES := stack_unwinding_test_impl.c
85 include $(BUILD_HOST_STATIC_LIBRARY)
87 # Build tests for the device (with bionic's .so). Run with:
88 #   adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests
89 include $(CLEAR_VARS)
90 LOCAL_MODULE := bionic-unit-tests
91 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
92 LOCAL_CFLAGS += $(test_c_flags)
93 LOCAL_LDFLAGS += $(test_dynamic_ldflags)
94 LOCAL_SHARED_LIBRARIES += libdl
95 LOCAL_SRC_FILES := $(test_src_files) $(test_dynamic_src_files)
96 LOCAL_WHOLE_STATIC_LIBRARIES := $(test_fortify_static_libraries)
97 LOCAL_STATIC_LIBRARIES += bionic-unit-tests-unwind-test-impl
98 include $(BUILD_NATIVE_TEST)
100 # Build tests for the device (with bionic's .a). Run with:
101 #   adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static
102 include $(CLEAR_VARS)
103 LOCAL_MODULE := bionic-unit-tests-static
104 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
105 LOCAL_FORCE_STATIC_EXECUTABLE := true
106 LOCAL_WHOLE_STATIC_LIBRARIES += libBionicTests
107 LOCAL_STATIC_LIBRARIES += libstlport_static libstdc++ libm libc
108 include $(BUILD_NATIVE_TEST)
110 # -----------------------------------------------------------------------------
111 # We build the static unit tests as a library so they can be used both for
112 # bionic-unit-tests-static and also as part of CTS.
113 # -----------------------------------------------------------------------------
115 include $(CLEAR_VARS)
116 LOCAL_MODULE := libBionicTests
117 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
118 LOCAL_CFLAGS += $(test_c_flags)
119 LOCAL_SRC_FILES := $(test_src_files)
120 LOCAL_CFLAGS += \
121     -DGTEST_OS_LINUX_ANDROID \
122     -DGTEST_HAS_STD_STRING \
124 LOCAL_C_INCLUDES += \
125     bionic bionic/libstdc++/include \
126     external/gtest/include \
127     external/stlport/stlport \
129 LOCAL_WHOLE_STATIC_LIBRARIES := \
130     $(test_fortify_static_libraries) \
131     bionic-unit-tests-unwind-test-impl \
133 include $(BUILD_STATIC_LIBRARY)
135 # -----------------------------------------------------------------------------
136 # Test library for the unit tests.
137 # -----------------------------------------------------------------------------
139 # Build no-elf-hash-table-library.so to test dlopen(3) on a library that
140 # only has a GNU-style hash table. MIPS doesn't support GNU hash style.
141 ifneq ($(TARGET_ARCH),mips)
142 include $(CLEAR_VARS)
143 LOCAL_MODULE := no-elf-hash-table-library
144 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
145 LOCAL_SRC_FILES := empty.cpp
146 LOCAL_LDFLAGS := -Wl,--hash-style=gnu
147 include $(BUILD_SHARED_LIBRARY)
148 endif
150 # -----------------------------------------------------------------------------
151 # Unit tests built against glibc.
152 # -----------------------------------------------------------------------------
154 # Build tests for the host (with glibc).
155 # Note that this will build against glibc, so it's not useful for testing
156 # bionic's implementation, but it does let you use glibc as a reference
157 # implementation for testing the tests themselves.
158 ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
159 include $(CLEAR_VARS)
160 LOCAL_MODULE := bionic-unit-tests-glibc
161 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
162 LOCAL_CFLAGS += $(test_c_flags)
163 LOCAL_LDFLAGS += -lpthread -ldl -lrt
164 LOCAL_LDFLAGS += $(test_dynamic_ldflags)
165 LOCAL_SRC_FILES := $(test_src_files) $(test_dynamic_src_files)
166 LOCAL_STATIC_LIBRARIES += bionic-unit-tests-unwind-test-impl-host
167 include $(BUILD_HOST_NATIVE_TEST)
169 # gtest needs ANDROID_DATA/local/tmp for death test output.
170 # Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
171 # Use the current target out directory as ANDROID_DATA.
172 bionic-unit-tests-glibc-run: bionic-unit-tests-glibc
173         mkdir -p $(TARGET_OUT_DATA)/local/tmp
174         ANDROID_DATA=$(TARGET_OUT_DATA) \
175         ANDROID_ROOT=$(TARGET_OUT) \
176                 $(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc
177 endif
179 # -----------------------------------------------------------------------------
180 # Run the unit tests built against x86 bionic on an x86 host.
181 # -----------------------------------------------------------------------------
183 ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
184 ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
185 ifeq ($(TARGET_ARCH),x86)
186 LINKER = linker
187 else
188 LINKER = linker64
189 endif
190 # gtest needs ANDROID_DATA/local/tmp for death test output.
191 # Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
192 # bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT.
193 bionic-unit-tests-run-on-host: bionic-unit-tests $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh
194         if [ ! -d /system -o ! -d /system/bin ]; then \
195           echo "Attempting to create /system/bin"; \
196           sudo mkdir -p -m 0777 /system/bin; \
197         fi
198         mkdir -p $(TARGET_OUT_DATA)/local/tmp
199         cp $(TARGET_OUT_EXECUTABLES)/$(LINKER) /system/bin
200         cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin
201         ANDROID_DATA=$(TARGET_OUT_DATA) \
202         ANDROID_ROOT=$(TARGET_OUT) \
203         LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \
204                 $(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests
205 endif
206 endif
208 # -----------------------------------------------------------------------------
209 # FORTIFY_SOURCE tests
210 # -----------------------------------------------------------------------------
212 fortify_c_includes = \
213     bionic \
214     bionic/libstdc++/include \
215     external/stlport/stlport \
216     external/gtest/include
217 fortify_test_files = fortify_test.cpp
219 # -Wno-error=unused-parameter needed as
220 # external/stlport/stlport/stl/_threads.c (included from
221 # external/gtest/include/gtest/gtest.h) does not compile cleanly under
222 # clang. TODO: fix this.
223 fortify_c_flags = $(test_c_flags) -Wno-error=unused-parameter
225 include $(CLEAR_VARS)
226 LOCAL_SRC_FILES := $(fortify_test_files)
227 LOCAL_MODULE := fortify1-tests-gcc
228 LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DTEST_NAME=Fortify1_Gcc
229 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
230 LOCAL_C_INCLUDES += $(fortify_c_includes)
231 include $(BUILD_STATIC_LIBRARY)
233 include $(CLEAR_VARS)
234 LOCAL_SRC_FILES := $(fortify_test_files)
235 LOCAL_MODULE := fortify2-tests-gcc
236 LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -DTEST_NAME=Fortify2_Gcc
237 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
238 LOCAL_C_INCLUDES += $(fortify_c_includes)
239 include $(BUILD_STATIC_LIBRARY)
241 include $(CLEAR_VARS)
242 LOCAL_SRC_FILES := $(fortify_test_files)
243 LOCAL_MODULE := fortify1-tests-clang
244 LOCAL_CLANG := true
245 LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DTEST_NAME=Fortify1_Clang
246 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
247 LOCAL_C_INCLUDES += $(fortify_c_includes)
248 include $(BUILD_STATIC_LIBRARY)
250 include $(CLEAR_VARS)
251 LOCAL_SRC_FILES := $(fortify_test_files)
252 LOCAL_MODULE := fortify2-tests-clang
253 LOCAL_CLANG := true
254 LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -DTEST_NAME=Fortify2_Clang
255 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
256 LOCAL_C_INCLUDES += $(fortify_c_includes)
257 include $(BUILD_STATIC_LIBRARY)
259 endif # !BUILD_TINY_ANDROID