Android.mk revision 062092543fdbd6fa2676e4f5b37a15f7bba94332
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 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_time_test.cpp \ 90 system_properties_test.cpp \ 91 time_test.cpp \ 92 unistd_test.cpp \ 93 94test_dynamic_ldflags = -Wl,--export-dynamic -Wl,-u,DlSymTestFunction 95test_dynamic_src_files = \ 96 dlfcn_test.cpp \ 97 98test_fortify_static_libraries = \ 99 fortify1-tests-gcc fortify2-tests-gcc fortify1-tests-clang fortify2-tests-clang 100 101include $(CLEAR_VARS) 102LOCAL_MODULE := bionic-unit-tests-unwind-test-impl 103LOCAL_CFLAGS += $(test_c_flags) -fexceptions -fnon-call-exceptions 104LOCAL_SRC_FILES := stack_unwinding_test_impl.c 105include $(BUILD_STATIC_LIBRARY) 106 107include $(CLEAR_VARS) 108LOCAL_MODULE := bionic-unit-tests-unwind-test-impl-host 109LOCAL_CFLAGS += $(test_c_flags) -fexceptions -fnon-call-exceptions 110LOCAL_SRC_FILES := stack_unwinding_test_impl.c 111include $(BUILD_HOST_STATIC_LIBRARY) 112 113# Build tests for the device (with bionic's .so). Run with: 114# adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests 115include $(CLEAR_VARS) 116LOCAL_MODULE := bionic-unit-tests 117LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 118LOCAL_CFLAGS += $(test_c_flags) 119LOCAL_LDFLAGS += $(test_dynamic_ldflags) 120LOCAL_SHARED_LIBRARIES += libdl 121LOCAL_SRC_FILES := $(test_src_files) $(test_dynamic_src_files) 122LOCAL_WHOLE_STATIC_LIBRARIES := $(test_fortify_static_libraries) 123LOCAL_STATIC_LIBRARIES += bionic-unit-tests-unwind-test-impl 124include $(BUILD_NATIVE_TEST) 125 126# Build tests for the device (with bionic's .a). Run with: 127# adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static 128include $(CLEAR_VARS) 129LOCAL_MODULE := bionic-unit-tests-static 130LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 131LOCAL_FORCE_STATIC_EXECUTABLE := true 132LOCAL_WHOLE_STATIC_LIBRARIES += libBionicTests 133LOCAL_STATIC_LIBRARIES += libstlport_static libstdc++ libm libc 134include $(BUILD_NATIVE_TEST) 135 136# ----------------------------------------------------------------------------- 137# We build the static unit tests as a library so they can be used both for 138# bionic-unit-tests-static and also as part of CTS. 139# ----------------------------------------------------------------------------- 140 141include $(CLEAR_VARS) 142LOCAL_MODULE := libBionicTests 143LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 144LOCAL_CFLAGS += $(test_c_flags) 145LOCAL_SRC_FILES := $(test_src_files) 146LOCAL_CFLAGS += \ 147 -DGTEST_OS_LINUX_ANDROID \ 148 -DGTEST_HAS_STD_STRING \ 149 150LOCAL_C_INCLUDES += \ 151 bionic bionic/libstdc++/include \ 152 external/gtest/include \ 153 external/stlport/stlport \ 154 155LOCAL_WHOLE_STATIC_LIBRARIES := \ 156 $(test_fortify_static_libraries) \ 157 bionic-unit-tests-unwind-test-impl \ 158 159include $(BUILD_STATIC_LIBRARY) 160 161# ----------------------------------------------------------------------------- 162# Test library for the unit tests. 163# ----------------------------------------------------------------------------- 164 165# Build no-elf-hash-table-library.so to test dlopen(3) on a library that 166# only has a GNU-style hash table. MIPS doesn't support GNU hash style. 167ifneq ($(TARGET_ARCH),mips) 168include $(CLEAR_VARS) 169LOCAL_MODULE := no-elf-hash-table-library 170LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 171LOCAL_SRC_FILES := empty.cpp 172LOCAL_LDFLAGS := -Wl,--hash-style=gnu 173include $(BUILD_SHARED_LIBRARY) 174endif 175 176# ----------------------------------------------------------------------------- 177# Unit tests built against glibc. 178# ----------------------------------------------------------------------------- 179 180# Build tests for the host (with glibc). 181# Note that this will build against glibc, so it's not useful for testing 182# bionic's implementation, but it does let you use glibc as a reference 183# implementation for testing the tests themselves. 184ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86) 185include $(CLEAR_VARS) 186LOCAL_MODULE := bionic-unit-tests-glibc 187LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 188LOCAL_CFLAGS += $(test_c_flags) 189LOCAL_LDFLAGS += -lpthread -ldl -lrt 190LOCAL_LDFLAGS += $(test_dynamic_ldflags) 191LOCAL_SRC_FILES := $(test_src_files) $(test_dynamic_src_files) 192LOCAL_STATIC_LIBRARIES += bionic-unit-tests-unwind-test-impl-host 193include $(BUILD_HOST_NATIVE_TEST) 194 195# gtest needs ANDROID_DATA/local/tmp for death test output. 196# Make sure to create ANDROID_DATA/local/tmp if doesn't exist. 197# Use the current target out directory as ANDROID_DATA. 198bionic-unit-tests-glibc-run: bionic-unit-tests-glibc 199 mkdir -p $(TARGET_OUT_DATA)/local/tmp 200 ANDROID_DATA=$(TARGET_OUT_DATA) \ 201 ANDROID_ROOT=$(TARGET_OUT) \ 202 $(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc 203endif 204 205# ----------------------------------------------------------------------------- 206# Run the unit tests built against x86 bionic on an x86 host. 207# ----------------------------------------------------------------------------- 208 209ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86) 210ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64)) 211ifeq ($(TARGET_ARCH),x86) 212LINKER = linker 213else 214LINKER = linker64 215endif 216# gtest needs ANDROID_DATA/local/tmp for death test output. 217# Make sure to create ANDROID_DATA/local/tmp if doesn't exist. 218# bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT. 219bionic-unit-tests-run-on-host: bionic-unit-tests $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh 220 if [ ! -d /system -o ! -d /system/bin ]; then \ 221 echo "Attempting to create /system/bin"; \ 222 sudo mkdir -p -m 0777 /system/bin; \ 223 fi 224 mkdir -p $(TARGET_OUT_DATA)/local/tmp 225 cp $(TARGET_OUT_EXECUTABLES)/$(LINKER) /system/bin 226 cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin 227 ANDROID_DATA=$(TARGET_OUT_DATA) \ 228 ANDROID_ROOT=$(TARGET_OUT) \ 229 LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \ 230 $(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests 231endif 232endif 233 234# ----------------------------------------------------------------------------- 235# FORTIFY_SOURCE tests 236# ----------------------------------------------------------------------------- 237 238fortify_c_includes = \ 239 bionic \ 240 bionic/libstdc++/include \ 241 external/stlport/stlport \ 242 external/gtest/include 243fortify_test_files = fortify_test.cpp 244 245# -Wno-error=unused-parameter needed as 246# external/stlport/stlport/stl/_threads.c (included from 247# external/gtest/include/gtest/gtest.h) does not compile cleanly under 248# clang. TODO: fix this. 249fortify_c_flags = $(test_c_flags) -Wno-error=unused-parameter 250 251include $(CLEAR_VARS) 252LOCAL_SRC_FILES := $(fortify_test_files) 253LOCAL_MODULE := fortify1-tests-gcc 254LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DTEST_NAME=Fortify1_Gcc 255LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 256LOCAL_C_INCLUDES += $(fortify_c_includes) 257include $(BUILD_STATIC_LIBRARY) 258 259include $(CLEAR_VARS) 260LOCAL_SRC_FILES := $(fortify_test_files) 261LOCAL_MODULE := fortify2-tests-gcc 262LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -DTEST_NAME=Fortify2_Gcc 263LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 264LOCAL_C_INCLUDES += $(fortify_c_includes) 265include $(BUILD_STATIC_LIBRARY) 266 267include $(CLEAR_VARS) 268LOCAL_SRC_FILES := $(fortify_test_files) 269LOCAL_MODULE := fortify1-tests-clang 270LOCAL_CLANG := true 271LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DTEST_NAME=Fortify1_Clang 272LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 273LOCAL_C_INCLUDES += $(fortify_c_includes) 274include $(BUILD_STATIC_LIBRARY) 275 276include $(CLEAR_VARS) 277LOCAL_SRC_FILES := $(fortify_test_files) 278LOCAL_MODULE := fortify2-tests-clang 279LOCAL_CLANG := true 280LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -DTEST_NAME=Fortify2_Clang 281LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk 282LOCAL_C_INCLUDES += $(fortify_c_includes) 283include $(BUILD_STATIC_LIBRARY) 284 285endif # !BUILD_TINY_ANDROID 286