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