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 # 18 ifdef BIONIC_TESTS 19 20 LOCAL_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 # 28 define 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 :=) 41 endef 42 43 # same as 'device-test' but builds a host executable instead 44 # you can use EXTRA_LDLIBS to indicate additional linker flags 45 # 46 define 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 :=) 59 endef 60 61 # First, the tests in 'common' 62 63 sources := \ 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 # 89 EXTRA_LDLIBS := -lpthread -lrt 90 EXTRA_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. 97 include $(CLEAR_VARS) 98 LOCAL_MODULE := test_static_executable_destructor 99 LOCAL_SRC_FILES := common/test_executable_destructor.c 100 LOCAL_MODULE_TAGS := tests 101 LOCAL_STATIC_LIBRARIES := libc 102 LOCAL_FORCE_STATIC_EXECUTABLE := true 103 include $(BUILD_EXECUTABLE) 104 105 include $(CLEAR_VARS) 106 LOCAL_MODULE := test_static_executable_destructor 107 LOCAL_SRC_FILES := common/test_executable_destructor.c 108 LOCAL_MODULE_TAGS := tests 109 LOCAL_LDFLAGS := -static 110 include $(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 # 121 sources := common/test_dlopen_null.c \ 122 123 EXTRA_LDLIBS := -ldl -Wl,--export-dynamic -Wl,-u,foo 124 EXTRA_CFLAGS := -DHOST 125 $(call host-test, $(sources)) 126 127 EXTRA_LDLIBS := -ldl -Wl,--export-dynamic -Wl,-u,foo 128 $(call device-test, $(sources)) 129 130 131 sources := \ 132 common/test_libgen.c \ 133 134 EXTRA_CFLAGS := -DHOST 135 $(call host-test, $(sources)) 136 $(call device-test, $(sources)) 137 138 # Second, the Bionic-specific tests 139 140 sources := \ 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 153 sources := \ 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 172 include $(CLEAR_VARS) 173 LOCAL_SRC_FILES := bionic/lib_relocs.c 174 LOCAL_MODULE := libtest_relocs 175 176 LOCAL_MODULE_TAGS := tests 177 include $(BUILD_SHARED_LIBRARY) 178 179 include $(CLEAR_VARS) 180 LOCAL_SRC_FILES := bionic/test_relocs.c 181 LOCAL_MODULE := test_relocs 182 LOCAL_SHARED_LIBRARIES := libtest_relocs 183 LOCAL_MODULE_TAGS := tests 184 include $(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 # 191 include $(CLEAR_VARS) 192 LOCAL_SRC_FILES := bionic/lib_static_init.cpp 193 LOCAL_MODULE := libtest_static_init 194 195 LOCAL_MODULE_TAGS := tests 196 include $(BUILD_SHARED_LIBRARY) 197 198 include $(CLEAR_VARS) 199 LOCAL_SRC_FILES := bionic/test_static_init.cpp 200 LOCAL_MODULE := test_static_init 201 LOCAL_SHARED_LIBRARIES := libtest_static_init 202 LOCAL_MODULE_TAGS := tests 203 include $(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 207 include $(CLEAR_VARS) 208 LOCAL_SRC_FILES := bionic/libdlclosetest1.cpp 209 LOCAL_MODULE := libdlclosetest1 210 211 LOCAL_MODULE_TAGS := tests 212 include $(BUILD_SHARED_LIBRARY) 213 214 # And this one does the same with __attribute__((constructor)) 215 # and __attribute__((destructor)) 216 include $(CLEAR_VARS) 217 LOCAL_SRC_FILES := bionic/libdlclosetest2.c 218 LOCAL_MODULE := libdlclosetest2 219 220 LOCAL_MODULE_TAGS := tests 221 include $(BUILD_SHARED_LIBRARY) 222 223 include $(CLEAR_VARS) 224 LOCAL_SRC_FILES := bionic/test_dlclose_destruction.c 225 LOCAL_MODULE := test_dlclose_destruction 226 LOCAL_LDFLAGS := -ldl 227 #LOCAL_SHARED_LIBRARIES := libdlclosetest1 libdlclosetest2 228 LOCAL_MODULE_TAGS := tests 229 include $(BUILD_EXECUTABLE) 230 231 # Testing 'clone' is only possible on Linux systems 232 include $(CLEAR_VARS) 233 LOCAL_SRC_FILES := common/test_clone.c 234 LOCAL_MODULE := test_clone 235 LOCAL_MODULE_TAGS := tests 236 include $(BUILD_EXECUTABLE) 237 238 ifeq ($(HOST_OS),linux) 239 include $(CLEAR_VARS) 240 LOCAL_SRC_FILES := common/test_clone.c 241 LOCAL_MODULE := test_clone 242 LOCAL_MODULE_TAGS := tests 243 include $(BUILD_HOST_EXECUTABLE) 244 endif 245 246 # TODO: Add a variety of GLibc test programs too... 247 248 # Hello World to test libstdc++ support 249 250 sources := \ 251 common/hello_world.cpp \ 252 253 EXTRA_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. 260 include $(CLEAR_VARS) 261 LOCAL_SRC_FILES := common/bench_pthread.c 262 LOCAL_MODULE := bench_pthread_shared 263 LOCAL_MODULE_TAGS := tests 264 include $(BUILD_EXECUTABLE) 265 266 include $(CLEAR_VARS) 267 LOCAL_SRC_FILES := common/bench_pthread.c 268 LOCAL_MODULE := bench_pthread_static 269 LOCAL_MODULE_TAGS := tests 270 LOCAL_FORCE_STATIC_EXECUTABLE := true 271 LOCAL_STATIC_LIBRARIES := libc 272 include $(BUILD_EXECUTABLE) 273 274 ifeq ($(HOST_OS),linux) 275 include $(CLEAR_VARS) 276 LOCAL_SRC_FILES := common/bench_pthread.c 277 LOCAL_MODULE := bench_pthread 278 LOCAL_LDLIBS += -lpthread -lrt 279 LOCAL_MODULE_TAGS := tests 280 include $(BUILD_HOST_EXECUTABLE) 281 endif 282 283 endif # BIONIC_TESTS 284