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