Android.mk revision 8b37200df5764303e2c7c2396a34a07f2a604591
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/test_cpu_set.c \
65    common/test_drand48.c \
66    common/test_executable_destructor.c \
67    common/test_getaddrinfo.c \
68    common/test_gethostbyname.c \
69    common/test_gethostname.c \
70    common/test_pthread_cleanup_push.c \
71    common/test_pthread_getcpuclockid.c \
72    common/test_pthread_join.c \
73    common/test_pthread_mutex.c \
74    common/test_pthread_rwlock.c \
75    common/test_pthread_once.c \
76    common/test_semaphore.c \
77    common/test_sem_post.c \
78    common/test_seteuid.c \
79    common/test_static_cpp_mutex.cpp \
80    common/test_strftime_2039.c \
81    common/test_strptime.c \
82    common/test_tm_zone.c \
83    common/test_udp.c \
84
85# _XOPEN_SOURCE=600 is needed to get pthread_mutexattr_settype() on GLibc
86#
87EXTRA_LDLIBS := -lpthread -lrt
88EXTRA_CFLAGS := -D_XOPEN_SOURCE=600 -DHOST
89$(call host-test, $(sources))
90$(call device-test, $(sources))
91
92# The 'test_static_executable_destructor is the same than
93# test_executable_destructor except that the generated program
94# is statically linked instead.
95include $(CLEAR_VARS)
96LOCAL_MODULE := test_static_executable_destructor
97LOCAL_SRC_FILES := common/test_executable_destructor.c
98LOCAL_MODULE_TAGS := tests
99LOCAL_STATIC_LIBRARIES := libc
100LOCAL_FORCE_STATIC_EXECUTABLE := true
101include $(BUILD_EXECUTABLE)
102
103include $(CLEAR_VARS)
104LOCAL_MODULE := test_static_executable_destructor
105LOCAL_SRC_FILES := common/test_executable_destructor.c
106LOCAL_MODULE_TAGS := tests
107LOCAL_LDFLAGS := -static
108include $(BUILD_HOST_EXECUTABLE)
109
110# The 'test_dlopen_null' tests requires specific linker flags
111#
112# The -Wl,--export-dynamic ensures that dynamic symbols are
113# exported from the executable.
114#
115# -Wl,-u,foo is used to ensure that symbol "foo" is not
116# garbage-collected by the gold linker, since the function
117# appears to be unused.
118#
119sources := common/test_dlopen_null.c \
120
121EXTRA_LDLIBS := -ldl -Wl,--export-dynamic -Wl,-u,foo
122EXTRA_CFLAGS := -DHOST
123$(call host-test, $(sources))
124
125EXTRA_LDLIBS := -ldl -Wl,--export-dynamic -Wl,-u,foo
126$(call device-test, $(sources))
127
128
129sources := \
130    common/test_libgen.c \
131
132EXTRA_CFLAGS := -DHOST
133$(call host-test, $(sources))
134$(call device-test, $(sources))
135
136# Second, the Bionic-specific tests
137
138sources :=  \
139    bionic/test_mutex.c \
140    bionic/test_cond.c \
141    bionic/test_getgrouplist.c \
142    bionic/test_netinet_icmp.c \
143    bionic/test_pthread_cond.c \
144    bionic/test_pthread_create.c \
145    bionic/test_setjmp.c \
146
147$(call device-test, $(sources))
148
149# Third, the other tests
150
151sources := \
152    other/bench_locks.c \
153    other/test_aligned.c \
154    other/test_arc4random.c \
155    other/test_atomics.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$(call device-test, $(sources))
165
166# The relocations test is a bit special, since we need
167# to build one shared object and one executable that depends
168# on it.
169
170include $(CLEAR_VARS)
171LOCAL_SRC_FILES := bionic/lib_relocs.c
172LOCAL_MODULE    := libtest_relocs
173LOCAL_PRELINK_MODULE := false
174LOCAL_MODULE_TAGS := tests
175include $(BUILD_SHARED_LIBRARY)
176
177include $(CLEAR_VARS)
178LOCAL_SRC_FILES := bionic/test_relocs.c
179LOCAL_MODULE    := test_relocs
180LOCAL_SHARED_LIBRARIES := libtest_relocs
181LOCAL_MODULE_TAGS := tests
182include $(BUILD_EXECUTABLE)
183
184# This test tries to see if the static constructors in a
185# shared library are only called once. We thus need to
186# build a shared library, then call it from another
187# program.
188#
189include $(CLEAR_VARS)
190LOCAL_SRC_FILES := bionic/lib_static_init.cpp
191LOCAL_MODULE    := libtest_static_init
192LOCAL_PRELINK_MODULE := false
193LOCAL_MODULE_TAGS := tests
194include $(BUILD_SHARED_LIBRARY)
195
196include $(CLEAR_VARS)
197LOCAL_SRC_FILES := bionic/test_static_init.cpp
198LOCAL_MODULE    := test_static_init
199LOCAL_SHARED_LIBRARIES := libtest_static_init
200LOCAL_MODULE_TAGS := tests
201include $(BUILD_EXECUTABLE)
202
203# This test tries to see if static destructors are called
204# on dlclose(). We thus need to generate a C++ shared library
205include $(CLEAR_VARS)
206LOCAL_SRC_FILES := bionic/libdlclosetest1.cpp
207LOCAL_MODULE := libdlclosetest1
208LOCAL_PRELINK_MODULE := false
209LOCAL_MODULE_TAGS := tests
210include $(BUILD_SHARED_LIBRARY)
211
212# And this one does the same with __attribute__((constructor))
213# and __attribute__((destructor))
214include $(CLEAR_VARS)
215LOCAL_SRC_FILES := bionic/libdlclosetest2.c
216LOCAL_MODULE := libdlclosetest2
217LOCAL_PRELINK_MODULE := false
218LOCAL_MODULE_TAGS := tests
219include $(BUILD_SHARED_LIBRARY)
220
221include $(CLEAR_VARS)
222LOCAL_SRC_FILES := bionic/test_dlclose_destruction.c
223LOCAL_MODULE := test_dlclose_destruction
224LOCAL_LDFLAGS := -ldl
225#LOCAL_SHARED_LIBRARIES := libdlclosetest1 libdlclosetest2
226LOCAL_MODULE_TAGS := tests
227include $(BUILD_EXECUTABLE)
228
229# Testing 'clone' is only possible on Linux systems
230include $(CLEAR_VARS)
231LOCAL_SRC_FILES := common/test_clone.c
232LOCAL_MODULE := test_clone
233LOCAL_MODULE_TAGS := tests
234include $(BUILD_EXECUTABLE)
235
236ifeq ($(HOST_OS),linux)
237include $(CLEAR_VARS)
238LOCAL_SRC_FILES := common/test_clone.c
239LOCAL_MODULE := test_clone
240LOCAL_MODULE_TAGS := tests
241include $(BUILD_HOST_EXECUTABLE)
242endif
243
244# TODO: Add a variety of GLibc test programs too...
245
246# Hello World to test libstdc++ support
247
248sources := \
249    common/hello_world.cpp \
250
251EXTRA_CFLAGS := -mandroid
252#$(call device-test, $(sources))
253
254endif  # BIONIC_TESTS
255