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