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 17 ifneq ($(BUILD_TINY_ANDROID),true) 18 19 LOCAL_PATH := $(call my-dir) 20 21 # ----------------------------------------------------------------------------- 22 # Unit tests. 23 # ----------------------------------------------------------------------------- 24 25 ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64)) 26 build_host := true 27 else 28 build_host := false 29 endif 30 31 # ----------------------------------------------------------------------------- 32 # All standard tests. 33 # ----------------------------------------------------------------------------- 34 test_cflags = \ 35 -fstack-protector-all \ 36 -g \ 37 -Wall -Wextra -Wunused \ 38 -Werror \ 39 -fno-builtin \ 40 41 test_cflags += -D__STDC_LIMIT_MACROS # For glibc. 42 43 ifeq ($(MALLOC_IMPL),dlmalloc) 44 test_cflags += -DUSE_DLMALLOC 45 else 46 test_cflags += -DUSE_JEMALLOC 47 endif 48 49 test_cppflags = \ 50 -std=gnu++11 \ 51 52 libBionicStandardTests_src_files := \ 53 arpa_inet_test.cpp \ 54 buffer_tests.cpp \ 55 ctype_test.cpp \ 56 dirent_test.cpp \ 57 eventfd_test.cpp \ 58 fcntl_test.cpp \ 59 fenv_test.cpp \ 60 ftw_test.cpp \ 61 getauxval_test.cpp \ 62 getcwd_test.cpp \ 63 inttypes_test.cpp \ 64 libc_logging_test.cpp \ 65 libgen_test.cpp \ 66 locale_test.cpp \ 67 malloc_test.cpp \ 68 math_cos_test.cpp \ 69 math_cosf_test.cpp \ 70 math_exp_test.cpp \ 71 math_expf_test.cpp \ 72 math_log_test.cpp \ 73 math_logf_test.cpp \ 74 math_pow_test.cpp \ 75 math_powf_test.cpp \ 76 math_sin_test.cpp \ 77 math_sinf_test.cpp \ 78 math_sincos_test.cpp \ 79 math_sincosf_test.cpp \ 80 math_tan_test.cpp \ 81 math_tanf_test.cpp \ 82 math_test.cpp \ 83 mntent_test.cpp \ 84 netdb_test.cpp \ 85 pthread_test.cpp \ 86 regex_test.cpp \ 87 sched_test.cpp \ 88 search_test.cpp \ 89 signal_test.cpp \ 90 stack_protector_test.cpp \ 91 stack_unwinding_test.cpp \ 92 stdatomic_test.cpp \ 93 stdint_test.cpp \ 94 stdio_test.cpp \ 95 stdlib_test.cpp \ 96 string_test.cpp \ 97 strings_test.cpp \ 98 stubs_test.cpp \ 99 sstream_test.cpp \ 100 sys_epoll_test.cpp \ 101 sys_mman_test.cpp \ 102 sys_resource_test.cpp \ 103 sys_select_test.cpp \ 104 sys_sendfile_test.cpp \ 105 sys_socket_test.cpp \ 106 sys_stat_test.cpp \ 107 sys_statvfs_test.cpp \ 108 sys_syscall_test.cpp \ 109 sys_time_test.cpp \ 110 sys_types_test.cpp \ 111 sys_vfs_test.cpp \ 112 system_properties_test.cpp \ 113 time_test.cpp \ 114 uchar_test.cpp \ 115 unistd_test.cpp \ 116 wchar_test.cpp \ 117 118 libBionicStandardTests_cflags := \ 119 $(test_cflags) \ 120 121 ifeq ($(MALLOC_IMPL),dlmalloc) 122 libBionicStandardTests_cflags += -DUSE_DLMALLOC 123 else 124 libBionicStandardTests_cflags += -DUSE_JEMALLOC 125 endif 126 127 libBionicStandardTests_cppflags := \ 128 $(test_cppflags) \ 129 130 libBionicStandardTests_c_includes := \ 131 bionic/libc \ 132 133 libBionicStandardTests_ldlibs_host := \ 134 -lrt \ 135 136 libBionicStandardTests_whole_static_libraries := \ 137 libBionicUnwindTest \ 138 139 module := libBionicStandardTests 140 module_tag := optional 141 build_type := target 142 build_target := STATIC_TEST_LIBRARY 143 include $(LOCAL_PATH)/Android.build.mk 144 build_type := host 145 include $(LOCAL_PATH)/Android.build.mk 146 147 # ----------------------------------------------------------------------------- 148 # Special stack unwinding test library compiled with special flags. 149 # ----------------------------------------------------------------------------- 150 libBionicUnwindTest_cflags := \ 151 $(test_cflags) \ 152 -fexceptions \ 153 -fnon-call-exceptions \ 154 155 libBionicUnwindTest_src_files := \ 156 stack_unwinding_test_impl.c \ 157 158 module := libBionicUnwindTest 159 module_tag := optional 160 build_type := target 161 build_target := STATIC_TEST_LIBRARY 162 include $(LOCAL_PATH)/Android.build.mk 163 build_type := host 164 include $(LOCAL_PATH)/Android.build.mk 165 166 # ----------------------------------------------------------------------------- 167 # Fortify tests. 168 # ----------------------------------------------------------------------------- 169 $(foreach compiler,gcc clang, \ 170 $(foreach test,1 2, \ 171 $(eval fortify$(test)-tests-$(compiler)_cflags := \ 172 $(test_cflags) \ 173 -U_FORTIFY_SOURCE \ 174 -D_FORTIFY_SOURCE=$(test) \ 175 -DTEST_NAME=Fortify$(test)_$(compiler)); \ 176 $(eval fortify$(test)-tests-$(compiler)_cflags_host := \ 177 -Wno-error); \ 178 $(eval fortify$(test)-tests-$(compiler)_src_files := \ 179 fortify_test.cpp); \ 180 $(eval fortify_libs += fortify$(test)-tests-$(compiler)); \ 181 ) \ 182 ) 183 184 module := fortify1-tests-gcc 185 module_tag := optional 186 build_type := target 187 build_target := STATIC_TEST_LIBRARY 188 include $(LOCAL_PATH)/Android.build.mk 189 build_type := host 190 include $(LOCAL_PATH)/Android.build.mk 191 192 module := fortify2-tests-gcc 193 module_tag := optional 194 build_type := target 195 build_target := STATIC_TEST_LIBRARY 196 include $(LOCAL_PATH)/Android.build.mk 197 build_type := host 198 include $(LOCAL_PATH)/Android.build.mk 199 200 fortify1-tests-clang_clang_target := true 201 fortify1-tests-clang_cflags_host := -D__clang__ 202 203 module := fortify1-tests-clang 204 module_tag := optional 205 build_type := target 206 build_target := STATIC_TEST_LIBRARY 207 include $(LOCAL_PATH)/Android.build.mk 208 build_type := host 209 include $(LOCAL_PATH)/Android.build.mk 210 211 fortify2-tests-clang_clang_target := true 212 213 fortify2-tests-clang_cflags_host := -D__clang__ 214 215 module := fortify2-tests-clang 216 module_tag := optional 217 build_type := target 218 build_target := STATIC_TEST_LIBRARY 219 include $(LOCAL_PATH)/Android.build.mk 220 build_type := host 221 include $(LOCAL_PATH)/Android.build.mk 222 223 # ----------------------------------------------------------------------------- 224 # Library of all tests (excluding the dynamic linker tests). 225 # ----------------------------------------------------------------------------- 226 libBionicTests_whole_static_libraries := \ 227 libBionicStandardTests \ 228 $(fortify_libs) \ 229 230 module := libBionicTests 231 module_tag := optional 232 build_type := target 233 build_target := STATIC_TEST_LIBRARY 234 include $(LOCAL_PATH)/Android.build.mk 235 build_type := host 236 include $(LOCAL_PATH)/Android.build.mk 237 238 # ----------------------------------------------------------------------------- 239 # Tests for the device using bionic's .so. Run with: 240 # adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests32 241 # adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests64 242 # ----------------------------------------------------------------------------- 243 bionic-unit-tests_whole_static_libraries := \ 244 libBionicTests \ 245 246 bionic-unit-tests_src_files := \ 247 atexit_test.cpp \ 248 dlext_test.cpp \ 249 dlfcn_test.cpp \ 250 251 bionic-unit-tests_cflags := $(test_cflags) 252 bionic-unit-tests_cppflags := $(test_cppflags) 253 254 bionic-unit-tests_ldflags := \ 255 -Wl,--export-dynamic \ 256 -Wl,-u,DlSymTestFunction \ 257 258 bionic-unit-tests_c_includes := \ 259 $(call include-path-for, libpagemap) \ 260 261 bionic-unit-tests_shared_libraries_target := \ 262 libdl \ 263 libpagemap \ 264 265 module := bionic-unit-tests 266 module_tag := optional 267 build_type := target 268 build_target := NATIVE_TEST 269 include $(LOCAL_PATH)/Android.build.mk 270 271 # ----------------------------------------------------------------------------- 272 # Tests for the device linked against bionic's static library. Run with: 273 # adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static32 274 # adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static64 275 # ----------------------------------------------------------------------------- 276 bionic-unit-tests-static_whole_static_libraries := \ 277 libBionicTests \ 278 279 bionic-unit-tests-static_static_libraries := \ 280 libstlport_static \ 281 libm \ 282 libc \ 283 libstdc++ \ 284 285 bionic-unit-tests-static_force_static_executable := true 286 287 module := bionic-unit-tests-static 288 module_tag := optional 289 build_type := target 290 build_target := NATIVE_TEST 291 include $(LOCAL_PATH)/Android.build.mk 292 293 # ----------------------------------------------------------------------------- 294 # Tests to run on the host and linked against glibc. Run with: 295 # cd bionic/tests; mm bionic-unit-tests-glibc-run 296 # ----------------------------------------------------------------------------- 297 298 ifeq ($(HOST_OS)-$(HOST_ARCH),$(filter $(HOST_OS)-$(HOST_ARCH),linux-x86 linux-x86_64)) 299 300 bionic-unit-tests-glibc_src_files := \ 301 atexit_test.cpp \ 302 303 bionic-unit-tests-glibc_whole_static_libraries := \ 304 libBionicStandardTests \ 305 306 bionic-unit-tests-glibc_ldlibs := \ 307 -lrt -ldl \ 308 309 bionic-unit-tests-glibc_cflags := $(test_cflags) 310 bionic-unit-tests-glibc_cppflags := $(test_cppflags) 311 312 module := bionic-unit-tests-glibc 313 module_tag := optional 314 build_type := host 315 build_target := NATIVE_TEST 316 include $(LOCAL_PATH)/Android.build.mk 317 318 ifneq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),arm mips x86)) 319 LINKER = linker64 320 NATIVE_TEST_SUFFIX=64 321 else 322 LINKER = linker 323 NATIVE_TEST_SUFFIX=32 324 endif 325 326 # gtest needs ANDROID_DATA/local/tmp for death test output. 327 # Make sure to create ANDROID_DATA/local/tmp if doesn't exist. 328 # Use the current target out directory as ANDROID_DATA. 329 # BIONIC_TEST_FLAGS is either empty or it comes from the user. 330 bionic-unit-tests-glibc-run: bionic-unit-tests-glibc 331 mkdir -p $(TARGET_OUT_DATA)/local/tmp 332 ANDROID_DATA=$(TARGET_OUT_DATA) \ 333 ANDROID_ROOT=$(TARGET_OUT) \ 334 $(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS) 335 336 # ----------------------------------------------------------------------------- 337 # Run the unit tests built against x86 bionic on an x86 host. 338 # ----------------------------------------------------------------------------- 339 340 ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64)) 341 # gtest needs ANDROID_DATA/local/tmp for death test output. 342 # Make sure to create ANDROID_DATA/local/tmp if doesn't exist. 343 # bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT. 344 # BIONIC_TEST_FLAGS is either empty or it comes from the user. 345 bionic-unit-tests-run-on-host: bionic-unit-tests $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh 346 if [ ! -d /system -o ! -d /system/bin ]; then \ 347 echo "Attempting to create /system/bin"; \ 348 sudo mkdir -p -m 0777 /system/bin; \ 349 fi 350 mkdir -p $(TARGET_OUT_DATA)/local/tmp 351 cp $(TARGET_OUT_EXECUTABLES)/$(LINKER) /system/bin 352 cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin 353 ANDROID_DATA=$(TARGET_OUT_DATA) \ 354 ANDROID_ROOT=$(TARGET_OUT) \ 355 LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \ 356 $(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests$(NATIVE_TEST_SUFFIX) $(BIONIC_TEST_FLAGS) 357 endif 358 359 endif # linux-x86 360 361 include $(call first-makefiles-under,$(LOCAL_PATH)) 362 endif # !BUILD_TINY_ANDROID 363