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