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