Android.mk revision f06bff7831256c708e9e5f06837bef3afc000e87
1# Copyright (C) 2008 The Android Open Source Project 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# 15# Build control file for Bionic's test programs 16# define the BIONIC_TESTS environment variable to build the test programs 17# 18ifdef BIONIC_TESTS 19 20LOCAL_PATH:= $(call my-dir) 21 22# used to define a simple test program and build it as a standalone 23# device executable. 24# 25# you can use EXTRA_CFLAGS to indicate additional CFLAGS to use 26# in the build. the variable will be cleaned on exit 27# 28define device-test 29 $(foreach file,$(1), \ 30 $(eval include $(CLEAR_VARS)) \ 31 $(eval LOCAL_SRC_FILES := $(file)) \ 32 $(eval LOCAL_MODULE := $(notdir $(file:%.c=%))) \ 33 $(eval LOCAL_MODULE := $(LOCAL_MODULE:%.cpp=%)) \ 34 $(eval LOCAL_CFLAGS += $(EXTRA_CFLAGS)) \ 35 $(eval LOCAL_LDFLAGS += $(EXTRA_LDLIBS)) \ 36 $(eval LOCAL_MODULE_TAGS := tests) \ 37 $(eval include $(BUILD_EXECUTABLE)) \ 38 ) \ 39 $(eval EXTRA_CFLAGS :=) \ 40 $(eval EXTRA_LDLIBS :=) 41endef 42 43# same as 'device-test' but builds a host executable instead 44# you can use EXTRA_LDLIBS to indicate additional linker flags 45# 46define host-test 47 $(foreach file,$(1), \ 48 $(eval include $(CLEAR_VARS)) \ 49 $(eval LOCAL_SRC_FILES := $(file)) \ 50 $(eval LOCAL_MODULE := $(notdir $(file:%.c=%))) \ 51 $(eval LOCAL_MODULE := $(LOCAL_MODULE:%.cpp=%)) \ 52 $(eval LOCAL_CFLAGS += $(EXTRA_CFLAGS)) \ 53 $(eval LOCAL_LDLIBS += $(EXTRA_LDLIBS)) \ 54 $(eval LOCAL_MODULE_TAGS := tests) \ 55 $(eval include $(BUILD_HOST_EXECUTABLE)) \ 56 ) \ 57 $(eval EXTRA_CFLAGS :=) \ 58 $(eval EXTRA_LDLIBS :=) 59endef 60 61# First, the tests in 'common' 62 63sources := \ 64 common/test_clock.c \ 65 common/test_cpu_set.c \ 66 common/test_drand48.c \ 67 common/test_executable_destructor.c \ 68 common/test_getaddrinfo.c \ 69 common/test_gethostbyname.c \ 70 common/test_gethostname.c \ 71 common/test_pthread_cleanup_push.c \ 72 common/test_pthread_getcpuclockid.c \ 73 common/test_pthread_join.c \ 74 common/test_pthread_mutex.c \ 75 common/test_pthread_rwlock.c \ 76 common/test_pthread_once.c \ 77 common/test_semaphore.c \ 78 common/test_sem_post.c \ 79 common/test_seteuid.c \ 80 common/test_static_cpp_mutex.cpp \ 81 common/test_strftime_2039.c \ 82 common/test_strptime.c \ 83 common/test_tm_zone.c \ 84 common/test_udp.c \ 85 86# _XOPEN_SOURCE=600 is needed to get pthread_mutexattr_settype() on GLibc 87# 88EXTRA_LDLIBS := -lpthread -lrt 89EXTRA_CFLAGS := -D_XOPEN_SOURCE=600 -DHOST 90$(call host-test, $(sources)) 91$(call device-test, $(sources)) 92 93# The 'test_static_executable_destructor is the same than 94# test_executable_destructor except that the generated program 95# is statically linked instead. 96include $(CLEAR_VARS) 97LOCAL_MODULE := test_static_executable_destructor 98LOCAL_SRC_FILES := common/test_executable_destructor.c 99LOCAL_MODULE_TAGS := tests 100LOCAL_STATIC_LIBRARIES := libc 101LOCAL_FORCE_STATIC_EXECUTABLE := true 102include $(BUILD_EXECUTABLE) 103 104include $(CLEAR_VARS) 105LOCAL_MODULE := test_static_executable_destructor 106LOCAL_SRC_FILES := common/test_executable_destructor.c 107LOCAL_MODULE_TAGS := tests 108LOCAL_LDFLAGS := -static 109include $(BUILD_HOST_EXECUTABLE) 110 111# The 'test_dlopen_null' tests requires specific linker flags 112# 113# The -Wl,--export-dynamic ensures that dynamic symbols are 114# exported from the executable. 115# 116# -Wl,-u,foo is used to ensure that symbol "foo" is not 117# garbage-collected by the gold linker, since the function 118# appears to be unused. 119# 120sources := common/test_dlopen_null.c \ 121 122EXTRA_LDLIBS := -ldl -Wl,--export-dynamic -Wl,-u,foo 123EXTRA_CFLAGS := -DHOST 124$(call host-test, $(sources)) 125 126EXTRA_LDLIBS := -ldl -Wl,--export-dynamic -Wl,-u,foo 127$(call device-test, $(sources)) 128 129 130sources := \ 131 common/test_libgen.c \ 132 133EXTRA_CFLAGS := -DHOST 134$(call host-test, $(sources)) 135$(call device-test, $(sources)) 136 137# Second, the Bionic-specific tests 138 139sources := \ 140 bionic/test_mutex.c \ 141 bionic/test_cond.c \ 142 bionic/test_getgrouplist.c \ 143 bionic/test_netinet_icmp.c \ 144 bionic/test_pthread_cond.c \ 145 bionic/test_pthread_create.c \ 146 bionic/test_setjmp.c \ 147 148$(call device-test, $(sources)) 149 150# Third, the other tests 151 152sources := \ 153 other/bench_locks.c \ 154 other/test_aligned.c \ 155 other/test_arc4random.c \ 156 other/test_atomics.c \ 157 other/test_sysconf.c \ 158 other/test_system.c \ 159 other/test_thread_max.c \ 160 other/test_timer_create.c \ 161 other/test_timer_create2.c \ 162 other/test_timer_create3.c \ 163 other/test_vfprintf_leak.c \ 164 165$(call device-test, $(sources)) 166 167# The relocations test is a bit special, since we need 168# to build one shared object and one executable that depends 169# on it. 170 171include $(CLEAR_VARS) 172LOCAL_SRC_FILES := bionic/lib_relocs.c 173LOCAL_MODULE := libtest_relocs 174LOCAL_PRELINK_MODULE := false 175LOCAL_MODULE_TAGS := tests 176include $(BUILD_SHARED_LIBRARY) 177 178include $(CLEAR_VARS) 179LOCAL_SRC_FILES := bionic/test_relocs.c 180LOCAL_MODULE := test_relocs 181LOCAL_SHARED_LIBRARIES := libtest_relocs 182LOCAL_MODULE_TAGS := tests 183include $(BUILD_EXECUTABLE) 184 185# This test tries to see if the static constructors in a 186# shared library are only called once. We thus need to 187# build a shared library, then call it from another 188# program. 189# 190include $(CLEAR_VARS) 191LOCAL_SRC_FILES := bionic/lib_static_init.cpp 192LOCAL_MODULE := libtest_static_init 193LOCAL_PRELINK_MODULE := false 194LOCAL_MODULE_TAGS := tests 195include $(BUILD_SHARED_LIBRARY) 196 197include $(CLEAR_VARS) 198LOCAL_SRC_FILES := bionic/test_static_init.cpp 199LOCAL_MODULE := test_static_init 200LOCAL_SHARED_LIBRARIES := libtest_static_init 201LOCAL_MODULE_TAGS := tests 202include $(BUILD_EXECUTABLE) 203 204# This test tries to see if static destructors are called 205# on dlclose(). We thus need to generate a C++ shared library 206include $(CLEAR_VARS) 207LOCAL_SRC_FILES := bionic/libdlclosetest1.cpp 208LOCAL_MODULE := libdlclosetest1 209LOCAL_PRELINK_MODULE := false 210LOCAL_MODULE_TAGS := tests 211include $(BUILD_SHARED_LIBRARY) 212 213# And this one does the same with __attribute__((constructor)) 214# and __attribute__((destructor)) 215include $(CLEAR_VARS) 216LOCAL_SRC_FILES := bionic/libdlclosetest2.c 217LOCAL_MODULE := libdlclosetest2 218LOCAL_PRELINK_MODULE := false 219LOCAL_MODULE_TAGS := tests 220include $(BUILD_SHARED_LIBRARY) 221 222include $(CLEAR_VARS) 223LOCAL_SRC_FILES := bionic/test_dlclose_destruction.c 224LOCAL_MODULE := test_dlclose_destruction 225LOCAL_LDFLAGS := -ldl 226#LOCAL_SHARED_LIBRARIES := libdlclosetest1 libdlclosetest2 227LOCAL_MODULE_TAGS := tests 228include $(BUILD_EXECUTABLE) 229 230# Testing 'clone' is only possible on Linux systems 231include $(CLEAR_VARS) 232LOCAL_SRC_FILES := common/test_clone.c 233LOCAL_MODULE := test_clone 234LOCAL_MODULE_TAGS := tests 235include $(BUILD_EXECUTABLE) 236 237ifeq ($(HOST_OS),linux) 238include $(CLEAR_VARS) 239LOCAL_SRC_FILES := common/test_clone.c 240LOCAL_MODULE := test_clone 241LOCAL_MODULE_TAGS := tests 242include $(BUILD_HOST_EXECUTABLE) 243endif 244 245# TODO: Add a variety of GLibc test programs too... 246 247# Hello World to test libstdc++ support 248 249sources := \ 250 common/hello_world.cpp \ 251 252EXTRA_CFLAGS := -mandroid 253#$(call device-test, $(sources)) 254 255endif # BIONIC_TESTS 256