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_arc4random.c \ 156 other/test_sysconf.c \ 157 other/test_system.c \ 158 other/test_thread_max.c \ 159 other/test_timer_create.c \ 160 other/test_timer_create2.c \ 161 other/test_timer_create3.c \ 162 other/test_vfprintf_leak.c \ 163 164 ifeq ($(TARGET_ARCH),arm) 165 sources += \ 166 other/test_atomics.c 167 endif 168 169 $(call device-test, $(sources)) 170 171 # The relocations test is a bit special, since we need 172 # to build one shared object and one executable that depends 173 # on it. 174 175 include $(CLEAR_VARS) 176 LOCAL_SRC_FILES := bionic/lib_relocs.c 177 LOCAL_MODULE := libtest_relocs 178 179 LOCAL_MODULE_TAGS := tests 180 include $(BUILD_SHARED_LIBRARY) 181 182 include $(CLEAR_VARS) 183 LOCAL_SRC_FILES := bionic/test_relocs.c 184 LOCAL_MODULE := test_relocs 185 LOCAL_SHARED_LIBRARIES := libtest_relocs 186 LOCAL_MODULE_TAGS := tests 187 include $(BUILD_EXECUTABLE) 188 189 # This test tries to see if the static constructors in a 190 # shared library are only called once. We thus need to 191 # build a shared library, then call it from another 192 # program. 193 # 194 include $(CLEAR_VARS) 195 LOCAL_SRC_FILES := bionic/lib_static_init.cpp 196 LOCAL_MODULE := libtest_static_init 197 198 LOCAL_MODULE_TAGS := tests 199 include $(BUILD_SHARED_LIBRARY) 200 201 include $(CLEAR_VARS) 202 LOCAL_SRC_FILES := bionic/test_static_init.cpp 203 LOCAL_MODULE := test_static_init 204 LOCAL_SHARED_LIBRARIES := libtest_static_init 205 LOCAL_MODULE_TAGS := tests 206 include $(BUILD_EXECUTABLE) 207 208 # This test tries to see if static destructors are called 209 # on dlclose(). We thus need to generate a C++ shared library 210 include $(CLEAR_VARS) 211 LOCAL_SRC_FILES := bionic/libdlclosetest1.cpp 212 LOCAL_MODULE := libdlclosetest1 213 214 LOCAL_MODULE_TAGS := tests 215 include $(BUILD_SHARED_LIBRARY) 216 217 # And this one does the same with __attribute__((constructor)) 218 # and __attribute__((destructor)) 219 include $(CLEAR_VARS) 220 LOCAL_SRC_FILES := bionic/libdlclosetest2.c 221 LOCAL_MODULE := libdlclosetest2 222 223 LOCAL_MODULE_TAGS := tests 224 include $(BUILD_SHARED_LIBRARY) 225 226 include $(CLEAR_VARS) 227 LOCAL_SRC_FILES := bionic/test_dlclose_destruction.c 228 LOCAL_MODULE := test_dlclose_destruction 229 LOCAL_LDFLAGS := -ldl 230 #LOCAL_SHARED_LIBRARIES := libdlclosetest1 libdlclosetest2 231 LOCAL_MODULE_TAGS := tests 232 include $(BUILD_EXECUTABLE) 233 234 # Testing 'clone' is only possible on Linux systems 235 include $(CLEAR_VARS) 236 LOCAL_SRC_FILES := common/test_clone.c 237 LOCAL_MODULE := test_clone 238 LOCAL_MODULE_TAGS := tests 239 include $(BUILD_EXECUTABLE) 240 241 ifeq ($(HOST_OS),linux) 242 include $(CLEAR_VARS) 243 LOCAL_SRC_FILES := common/test_clone.c 244 LOCAL_MODULE := test_clone 245 LOCAL_MODULE_TAGS := tests 246 include $(BUILD_HOST_EXECUTABLE) 247 endif 248 249 # TODO: Add a variety of GLibc test programs too... 250 251 # Hello World to test libstdc++ support 252 253 sources := \ 254 common/hello_world.cpp \ 255 256 EXTRA_CFLAGS := -mandroid 257 #$(call device-test, $(sources)) 258 259 # NOTE: We build both a shared and static version of bench_pthread. 260 # the shared version will use the target device's C library, while 261 # the static one will use the current build product implementation. 262 # This is ideal to quantify pthread optimizations. 263 include $(CLEAR_VARS) 264 LOCAL_SRC_FILES := common/bench_pthread.c 265 LOCAL_MODULE := bench_pthread_shared 266 LOCAL_MODULE_TAGS := tests 267 include $(BUILD_EXECUTABLE) 268 269 include $(CLEAR_VARS) 270 LOCAL_SRC_FILES := common/bench_pthread.c 271 LOCAL_MODULE := bench_pthread_static 272 LOCAL_MODULE_TAGS := tests 273 LOCAL_FORCE_STATIC_EXECUTABLE := true 274 LOCAL_STATIC_LIBRARIES := libc 275 include $(BUILD_EXECUTABLE) 276 277 ifeq ($(HOST_OS),linux) 278 include $(CLEAR_VARS) 279 LOCAL_SRC_FILES := common/bench_pthread.c 280 LOCAL_MODULE := bench_pthread 281 LOCAL_LDLIBS += -lpthread -lrt 282 LOCAL_MODULE_TAGS := tests 283 include $(BUILD_HOST_EXECUTABLE) 284 endif 285 286 endif # BIONIC_TESTS 287