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