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/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 # 88 EXTRA_LDLIBS := -lpthread -lrt 89 EXTRA_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. 96 include $(CLEAR_VARS) 97 LOCAL_MODULE := test_static_executable_destructor 98 LOCAL_SRC_FILES := common/test_executable_destructor.c 99 LOCAL_MODULE_TAGS := tests 100 LOCAL_STATIC_LIBRARIES := libc 101 LOCAL_FORCE_STATIC_EXECUTABLE := true 102 include $(BUILD_EXECUTABLE) 103 104 include $(CLEAR_VARS) 105 LOCAL_MODULE := test_static_executable_destructor 106 LOCAL_SRC_FILES := common/test_executable_destructor.c 107 LOCAL_MODULE_TAGS := tests 108 LOCAL_LDFLAGS := -static 109 include $(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 # 120 sources := common/test_dlopen_null.c \ 121 122 EXTRA_LDLIBS := -ldl -Wl,--export-dynamic -Wl,-u,foo 123 EXTRA_CFLAGS := -DHOST 124 $(call host-test, $(sources)) 125 126 EXTRA_LDLIBS := -ldl -Wl,--export-dynamic -Wl,-u,foo 127 $(call device-test, $(sources)) 128 129 130 sources := \ 131 common/test_libgen.c \ 132 133 EXTRA_CFLAGS := -DHOST 134 $(call host-test, $(sources)) 135 $(call device-test, $(sources)) 136 137 # Second, the Bionic-specific tests 138 139 sources := \ 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 152 sources := \ 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 171 include $(CLEAR_VARS) 172 LOCAL_SRC_FILES := bionic/lib_relocs.c 173 LOCAL_MODULE := libtest_relocs 174 175 LOCAL_MODULE_TAGS := tests 176 include $(BUILD_SHARED_LIBRARY) 177 178 include $(CLEAR_VARS) 179 LOCAL_SRC_FILES := bionic/test_relocs.c 180 LOCAL_MODULE := test_relocs 181 LOCAL_SHARED_LIBRARIES := libtest_relocs 182 LOCAL_MODULE_TAGS := tests 183 include $(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 # 190 include $(CLEAR_VARS) 191 LOCAL_SRC_FILES := bionic/lib_static_init.cpp 192 LOCAL_MODULE := libtest_static_init 193 194 LOCAL_MODULE_TAGS := tests 195 include $(BUILD_SHARED_LIBRARY) 196 197 include $(CLEAR_VARS) 198 LOCAL_SRC_FILES := bionic/test_static_init.cpp 199 LOCAL_MODULE := test_static_init 200 LOCAL_SHARED_LIBRARIES := libtest_static_init 201 LOCAL_MODULE_TAGS := tests 202 include $(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 206 include $(CLEAR_VARS) 207 LOCAL_SRC_FILES := bionic/libdlclosetest1.cpp 208 LOCAL_MODULE := libdlclosetest1 209 210 LOCAL_MODULE_TAGS := tests 211 include $(BUILD_SHARED_LIBRARY) 212 213 # And this one does the same with __attribute__((constructor)) 214 # and __attribute__((destructor)) 215 include $(CLEAR_VARS) 216 LOCAL_SRC_FILES := bionic/libdlclosetest2.c 217 LOCAL_MODULE := libdlclosetest2 218 219 LOCAL_MODULE_TAGS := tests 220 include $(BUILD_SHARED_LIBRARY) 221 222 include $(CLEAR_VARS) 223 LOCAL_SRC_FILES := bionic/test_dlclose_destruction.c 224 LOCAL_MODULE := test_dlclose_destruction 225 LOCAL_LDFLAGS := -ldl 226 #LOCAL_SHARED_LIBRARIES := libdlclosetest1 libdlclosetest2 227 LOCAL_MODULE_TAGS := tests 228 include $(BUILD_EXECUTABLE) 229 230 # Testing 'clone' is only possible on Linux systems 231 include $(CLEAR_VARS) 232 LOCAL_SRC_FILES := common/test_clone.c 233 LOCAL_MODULE := test_clone 234 LOCAL_MODULE_TAGS := tests 235 include $(BUILD_EXECUTABLE) 236 237 ifeq ($(HOST_OS),linux) 238 include $(CLEAR_VARS) 239 LOCAL_SRC_FILES := common/test_clone.c 240 LOCAL_MODULE := test_clone 241 LOCAL_MODULE_TAGS := tests 242 include $(BUILD_HOST_EXECUTABLE) 243 endif 244 245 # TODO: Add a variety of GLibc test programs too... 246 247 # Hello World to test libstdc++ support 248 249 sources := \ 250 common/hello_world.cpp \ 251 252 EXTRA_CFLAGS := -mandroid 253 #$(call device-test, $(sources)) 254 255 endif # BIONIC_TESTS 256