• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/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#
89EXTRA_LDLIBS := -lpthread -lrt
90EXTRA_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.
97include $(CLEAR_VARS)
98LOCAL_MODULE := test_static_executable_destructor
99LOCAL_SRC_FILES := common/test_executable_destructor.c
100LOCAL_MODULE_TAGS := tests
101LOCAL_STATIC_LIBRARIES := libc
102LOCAL_FORCE_STATIC_EXECUTABLE := true
103include $(BUILD_EXECUTABLE)
104
105include $(CLEAR_VARS)
106LOCAL_MODULE := test_static_executable_destructor
107LOCAL_SRC_FILES := common/test_executable_destructor.c
108LOCAL_MODULE_TAGS := tests
109LOCAL_LDFLAGS := -static
110include $(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#
121sources := common/test_dlopen_null.c \
122
123EXTRA_LDLIBS := -ldl -Wl,--export-dynamic -Wl,-u,foo
124EXTRA_CFLAGS := -DHOST
125$(call host-test, $(sources))
126
127EXTRA_LDLIBS := -ldl -Wl,--export-dynamic -Wl,-u,foo
128$(call device-test, $(sources))
129
130
131sources := \
132    common/test_libgen.c \
133
134EXTRA_CFLAGS := -DHOST
135$(call host-test, $(sources))
136$(call device-test, $(sources))
137
138# Second, the Bionic-specific tests
139
140sources :=  \
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
153sources := \
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
164ifeq ($(TARGET_ARCH),arm)
165sources += \
166    other/test_atomics.c
167endif
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
175include $(CLEAR_VARS)
176LOCAL_SRC_FILES := bionic/lib_relocs.c
177LOCAL_MODULE    := libtest_relocs
178
179LOCAL_MODULE_TAGS := tests
180include $(BUILD_SHARED_LIBRARY)
181
182include $(CLEAR_VARS)
183LOCAL_SRC_FILES := bionic/test_relocs.c
184LOCAL_MODULE    := test_relocs
185LOCAL_SHARED_LIBRARIES := libtest_relocs
186LOCAL_MODULE_TAGS := tests
187include $(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#
194include $(CLEAR_VARS)
195LOCAL_SRC_FILES := bionic/lib_static_init.cpp
196LOCAL_MODULE    := libtest_static_init
197
198LOCAL_MODULE_TAGS := tests
199include $(BUILD_SHARED_LIBRARY)
200
201include $(CLEAR_VARS)
202LOCAL_SRC_FILES := bionic/test_static_init.cpp
203LOCAL_MODULE    := test_static_init
204LOCAL_SHARED_LIBRARIES := libtest_static_init
205LOCAL_MODULE_TAGS := tests
206include $(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
210include $(CLEAR_VARS)
211LOCAL_SRC_FILES := bionic/libdlclosetest1.cpp
212LOCAL_MODULE := libdlclosetest1
213
214LOCAL_MODULE_TAGS := tests
215include $(BUILD_SHARED_LIBRARY)
216
217# And this one does the same with __attribute__((constructor))
218# and __attribute__((destructor))
219include $(CLEAR_VARS)
220LOCAL_SRC_FILES := bionic/libdlclosetest2.c
221LOCAL_MODULE := libdlclosetest2
222
223LOCAL_MODULE_TAGS := tests
224include $(BUILD_SHARED_LIBRARY)
225
226include $(CLEAR_VARS)
227LOCAL_SRC_FILES := bionic/test_dlclose_destruction.c
228LOCAL_MODULE := test_dlclose_destruction
229LOCAL_LDFLAGS := -ldl
230#LOCAL_SHARED_LIBRARIES := libdlclosetest1 libdlclosetest2
231LOCAL_MODULE_TAGS := tests
232include $(BUILD_EXECUTABLE)
233
234# Testing 'clone' is only possible on Linux systems
235include $(CLEAR_VARS)
236LOCAL_SRC_FILES := common/test_clone.c
237LOCAL_MODULE := test_clone
238LOCAL_MODULE_TAGS := tests
239include $(BUILD_EXECUTABLE)
240
241ifeq ($(HOST_OS),linux)
242include $(CLEAR_VARS)
243LOCAL_SRC_FILES := common/test_clone.c
244LOCAL_MODULE := test_clone
245LOCAL_MODULE_TAGS := tests
246include $(BUILD_HOST_EXECUTABLE)
247endif
248
249# TODO: Add a variety of GLibc test programs too...
250
251# Hello World to test libstdc++ support
252
253sources := \
254    common/hello_world.cpp \
255
256EXTRA_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.
263include $(CLEAR_VARS)
264LOCAL_SRC_FILES := common/bench_pthread.c
265LOCAL_MODULE := bench_pthread_shared
266LOCAL_MODULE_TAGS := tests
267include $(BUILD_EXECUTABLE)
268
269include $(CLEAR_VARS)
270LOCAL_SRC_FILES := common/bench_pthread.c
271LOCAL_MODULE := bench_pthread_static
272LOCAL_MODULE_TAGS := tests
273LOCAL_FORCE_STATIC_EXECUTABLE := true
274LOCAL_STATIC_LIBRARIES := libc
275include $(BUILD_EXECUTABLE)
276
277ifeq ($(HOST_OS),linux)
278include $(CLEAR_VARS)
279LOCAL_SRC_FILES := common/bench_pthread.c
280LOCAL_MODULE := bench_pthread
281LOCAL_LDLIBS += -lpthread -lrt
282LOCAL_MODULE_TAGS := tests
283include $(BUILD_HOST_EXECUTABLE)
284endif
285
286endif  # BIONIC_TESTS
287