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