Android.mk revision 33cf0fee9523f7c796a71f42d2031a532351bb88
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/bench_stdio.c \ 65 common/test_clock.c \ 66 common/test_cpu_set.c \ 67 common/test_drand48.c \ 68 common/test_executable_destructor.c \ 69 common/test_getaddrinfo.c \ 70 common/test_gethostbyname.c \ 71 common/test_gethostname.c \ 72 common/test_pthread_cleanup_push.c \ 73 common/test_pthread_getcpuclockid.c \ 74 common/test_pthread_join.c \ 75 common/test_pthread_mutex.c \ 76 common/test_pthread_rwlock.c \ 77 common/test_pthread_once.c \ 78 common/test_semaphore.c \ 79 common/test_sem_post.c \ 80 common/test_seteuid.c \ 81 common/test_static_cpp_mutex.cpp \ 82 common/test_strftime_2039.c \ 83 common/test_strptime.c \ 84 common/test_tm_zone.c \ 85 common/test_udp.c \ 86 87# _XOPEN_SOURCE=600 is needed to get pthread_mutexattr_settype() on GLibc 88# 89EXTRA_LDLIBS := -lpthread -lrt 90EXTRA_CFLAGS := -D_XOPEN_SOURCE=600 -DHOST 91$(call host-test, $(sources)) 92$(call device-test, $(sources)) 93 94# The 'test_static_executable_destructor is the same than 95# test_executable_destructor except that the generated program 96# is statically linked instead. 97include $(CLEAR_VARS) 98LOCAL_MODULE := test_static_executable_destructor 99LOCAL_SRC_FILES := common/test_executable_destructor.c 100LOCAL_MODULE_TAGS := tests 101LOCAL_STATIC_LIBRARIES := libc 102LOCAL_FORCE_STATIC_EXECUTABLE := true 103include $(BUILD_EXECUTABLE) 104 105include $(CLEAR_VARS) 106LOCAL_MODULE := test_static_executable_destructor 107LOCAL_SRC_FILES := common/test_executable_destructor.c 108LOCAL_MODULE_TAGS := tests 109LOCAL_LDFLAGS := -static 110include $(BUILD_HOST_EXECUTABLE) 111 112# The 'test_dlopen_null' tests requires specific linker flags 113# 114# The -Wl,--export-dynamic ensures that dynamic symbols are 115# exported from the executable. 116# 117# -Wl,-u,foo is used to ensure that symbol "foo" is not 118# garbage-collected by the gold linker, since the function 119# appears to be unused. 120# 121sources := common/test_dlopen_null.c \ 122 123EXTRA_LDLIBS := -ldl -Wl,--export-dynamic -Wl,-u,foo 124EXTRA_CFLAGS := -DHOST 125$(call host-test, $(sources)) 126 127EXTRA_LDLIBS := -ldl -Wl,--export-dynamic -Wl,-u,foo 128$(call device-test, $(sources)) 129 130 131sources := \ 132 common/test_libgen.c \ 133 134EXTRA_CFLAGS := -DHOST 135$(call host-test, $(sources)) 136$(call device-test, $(sources)) 137 138# Second, the Bionic-specific tests 139 140sources := \ 141 bionic/test_mutex.c \ 142 bionic/test_cond.c \ 143 bionic/test_getgrouplist.c \ 144 bionic/test_netinet_icmp.c \ 145 bionic/test_pthread_cond.c \ 146 bionic/test_pthread_create.c \ 147 bionic/test_setjmp.c \ 148 149$(call device-test, $(sources)) 150 151# Third, the other tests 152 153sources := \ 154 other/bench_locks.c \ 155 other/test_aligned.c \ 156 other/test_arc4random.c \ 157 other/test_atomics.c \ 158 other/test_sysconf.c \ 159 other/test_system.c \ 160 other/test_thread_max.c \ 161 other/test_timer_create.c \ 162 other/test_timer_create2.c \ 163 other/test_timer_create3.c \ 164 other/test_vfprintf_leak.c \ 165 166$(call device-test, $(sources)) 167 168# The relocations test is a bit special, since we need 169# to build one shared object and one executable that depends 170# on it. 171 172include $(CLEAR_VARS) 173LOCAL_SRC_FILES := bionic/lib_relocs.c 174LOCAL_MODULE := libtest_relocs 175 176LOCAL_MODULE_TAGS := tests 177include $(BUILD_SHARED_LIBRARY) 178 179include $(CLEAR_VARS) 180LOCAL_SRC_FILES := bionic/test_relocs.c 181LOCAL_MODULE := test_relocs 182LOCAL_SHARED_LIBRARIES := libtest_relocs 183LOCAL_MODULE_TAGS := tests 184include $(BUILD_EXECUTABLE) 185 186# This test tries to see if the static constructors in a 187# shared library are only called once. We thus need to 188# build a shared library, then call it from another 189# program. 190# 191include $(CLEAR_VARS) 192LOCAL_SRC_FILES := bionic/lib_static_init.cpp 193LOCAL_MODULE := libtest_static_init 194 195LOCAL_MODULE_TAGS := tests 196include $(BUILD_SHARED_LIBRARY) 197 198include $(CLEAR_VARS) 199LOCAL_SRC_FILES := bionic/test_static_init.cpp 200LOCAL_MODULE := test_static_init 201LOCAL_SHARED_LIBRARIES := libtest_static_init 202LOCAL_MODULE_TAGS := tests 203include $(BUILD_EXECUTABLE) 204 205# This test tries to see if static destructors are called 206# on dlclose(). We thus need to generate a C++ shared library 207include $(CLEAR_VARS) 208LOCAL_SRC_FILES := bionic/libdlclosetest1.cpp 209LOCAL_MODULE := libdlclosetest1 210 211LOCAL_MODULE_TAGS := tests 212include $(BUILD_SHARED_LIBRARY) 213 214# And this one does the same with __attribute__((constructor)) 215# and __attribute__((destructor)) 216include $(CLEAR_VARS) 217LOCAL_SRC_FILES := bionic/libdlclosetest2.c 218LOCAL_MODULE := libdlclosetest2 219 220LOCAL_MODULE_TAGS := tests 221include $(BUILD_SHARED_LIBRARY) 222 223include $(CLEAR_VARS) 224LOCAL_SRC_FILES := bionic/test_dlclose_destruction.c 225LOCAL_MODULE := test_dlclose_destruction 226LOCAL_LDFLAGS := -ldl 227#LOCAL_SHARED_LIBRARIES := libdlclosetest1 libdlclosetest2 228LOCAL_MODULE_TAGS := tests 229include $(BUILD_EXECUTABLE) 230 231# Testing 'clone' is only possible on Linux systems 232include $(CLEAR_VARS) 233LOCAL_SRC_FILES := common/test_clone.c 234LOCAL_MODULE := test_clone 235LOCAL_MODULE_TAGS := tests 236include $(BUILD_EXECUTABLE) 237 238ifeq ($(HOST_OS),linux) 239include $(CLEAR_VARS) 240LOCAL_SRC_FILES := common/test_clone.c 241LOCAL_MODULE := test_clone 242LOCAL_MODULE_TAGS := tests 243include $(BUILD_HOST_EXECUTABLE) 244endif 245 246# TODO: Add a variety of GLibc test programs too... 247 248# Hello World to test libstdc++ support 249 250sources := \ 251 common/hello_world.cpp \ 252 253EXTRA_CFLAGS := -mandroid 254#$(call device-test, $(sources)) 255 256# NOTE: We build both a shared and static version of bench_pthread. 257# the shared version will use the target device's C library, while 258# the static one will use the current build product implementation. 259# This is ideal to quantify pthread optimizations. 260include $(CLEAR_VARS) 261LOCAL_SRC_FILES := common/bench_pthread.c 262LOCAL_MODULE := bench_pthread_shared 263LOCAL_MODULE_TAGS := tests 264include $(BUILD_EXECUTABLE) 265 266include $(CLEAR_VARS) 267LOCAL_SRC_FILES := common/bench_pthread.c 268LOCAL_MODULE := bench_pthread_static 269LOCAL_MODULE_TAGS := tests 270LOCAL_FORCE_STATIC_EXECUTABLE := true 271LOCAL_STATIC_LIBRARIES := libc 272include $(BUILD_EXECUTABLE) 273 274ifeq ($(HOST_OS),linux) 275include $(CLEAR_VARS) 276LOCAL_SRC_FILES := common/bench_pthread.c 277LOCAL_MODULE := bench_pthread 278LOCAL_LDLIBS += -lpthread -lrt 279LOCAL_MODULE_TAGS := tests 280include $(BUILD_HOST_EXECUTABLE) 281endif 282 283endif # BIONIC_TESTS 284