blob: ee22c3520504d3f9467712ce2a7f8dce5e0854c6 [file] [log] [blame]
Elliott Hughescc213f82012-08-14 15:32:42 -07001#
2# Copyright (C) 2012 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
Benoit Goby5ac9eee2012-08-31 19:52:15 -070015#
16
Elliott Hughese7c59f92013-12-17 20:47:06 -080017ifneq ($(BUILD_TINY_ANDROID),true)
Elliott Hughescc213f82012-08-14 15:32:42 -070018
19LOCAL_PATH := $(call my-dir)
20
Elliott Hughes7be369d2012-11-08 15:37:43 -080021# -----------------------------------------------------------------------------
Elliott Hughes7be369d2012-11-08 15:37:43 -080022# Unit tests.
23# -----------------------------------------------------------------------------
24
Elliott Hughesad88a082012-10-24 18:37:21 -070025test_c_flags = \
Nick Kralevichdcab1b22013-01-10 17:12:29 -080026 -fstack-protector-all \
Elliott Hughesad88a082012-10-24 18:37:21 -070027 -g \
28 -Wall -Wextra \
29 -Werror \
Elliott Hughesa0ee0782013-01-30 19:06:37 -080030 -fno-builtin \
Elliott Hughesad88a082012-10-24 18:37:21 -070031
Colin Crossd1973ca2014-01-21 19:50:58 -080032ifeq ($(TARGET_ARCH),arm64)
Serban Constantinescu282e2322013-10-22 11:30:12 +010033 $(info TODO: $(LOCAL_PATH)/Android.mk -fstack-protector not yet available for the AArch64 toolchain)
34 test_c_flags += -fno-stack-protector
Colin Crossd1973ca2014-01-21 19:50:58 -080035endif # arm64
Serban Constantinescu282e2322013-10-22 11:30:12 +010036
Elliott Hughescc213f82012-08-14 15:32:42 -070037test_src_files = \
Christopher Ferrisb687ad32013-11-06 17:32:11 -080038 buffer_tests.cpp \
Elliott Hughes063cfb22012-10-25 20:55:23 -070039 dirent_test.cpp \
Kito Cheng8baa9292013-04-03 11:29:40 +080040 eventfd_test.cpp \
Elliott Hughes06209252013-11-06 16:20:54 -080041 fcntl_test.cpp \
Elliott Hughes90e10d42012-11-02 17:05:20 -070042 fenv_test.cpp \
Nick Kralevich2c5153b2013-01-11 14:43:05 -080043 getauxval_test.cpp \
Elliott Hughes04a83a42012-08-16 15:59:12 -070044 getcwd_test.cpp \
Elliott Hughes74f08332013-07-02 15:23:38 -070045 inttypes_test.cpp \
Elliott Hughes8f2a5a02013-03-15 15:30:25 -070046 libc_logging_test.cpp \
Elliott Hughes58b57542012-10-29 14:27:10 -070047 libgen_test.cpp \
Christopher Ferris885f3b92013-05-21 17:48:01 -070048 malloc_test.cpp \
Elliott Hughesa0ee0782013-01-30 19:06:37 -080049 math_test.cpp \
Elliott Hughesd3b9d112013-02-13 08:22:07 -080050 netdb_test.cpp \
Elliott Hughesbfeab1b2012-09-05 17:47:37 -070051 pthread_test.cpp \
Elliott Hughescc213f82012-08-14 15:32:42 -070052 regex_test.cpp \
Elliott Hughes53bfdae2013-10-18 19:39:09 -070053 sched_test.cpp \
Elliott Hughesda73f652012-11-30 16:40:55 -080054 signal_test.cpp \
Elliott Hughesad88a082012-10-24 18:37:21 -070055 stack_protector_test.cpp \
Sergey Melnikovc45087b2013-01-25 16:40:13 +040056 stack_unwinding_test.cpp \
Elliott Hughes06040fd2013-07-09 13:25:03 -070057 statvfs_test.cpp \
Elliott Hughes91875dc2012-09-24 17:55:15 -070058 stdio_test.cpp \
Elliott Hughes774c7f52012-10-01 13:11:03 -070059 stdlib_test.cpp \
Irina Tirdeab5f053b2012-09-08 09:17:54 +030060 string_test.cpp \
Elliott Hughes73964c52013-02-13 14:35:14 -080061 strings_test.cpp \
Kenny Root2a54e5e2012-09-13 10:52:52 -070062 stubs_test.cpp \
Elliott Hughes11952072013-10-24 15:15:14 -070063 sys_epoll_test.cpp \
Elliott Hughes431166d2014-01-27 16:28:31 -080064 sys_mman_test.cpp \
Elliott Hughes0f461e32014-01-09 10:17:03 -080065 sys_resource_test.cpp \
Elliott Hughes5b9310e2013-10-02 16:59:05 -070066 sys_select_test.cpp \
Elliott Hughesb4f76162013-09-19 16:27:24 -070067 sys_sendfile_test.cpp \
Elliott Hughesd0be7c82013-08-08 17:13:33 -070068 sys_stat_test.cpp \
Elliott Hughese61dc712013-11-13 13:14:31 -080069 sys_syscall_test.cpp \
Elliott Hughesf8fcfbc2013-10-22 13:28:46 -070070 sys_time_test.cpp \
Elliott Hughes894f8cb2014-01-03 14:49:37 -080071 sys_types_test.cpp \
Colin Crossb27e2002013-01-28 17:19:43 -080072 system_properties_test.cpp \
Elliott Hughese0175ca2013-03-14 14:38:08 -070073 time_test.cpp \
Elliott Hughesa55f6302013-01-02 14:23:43 -080074 unistd_test.cpp \
Elliott Hughescc213f82012-08-14 15:32:42 -070075
jeffhaoacf5aa72012-09-12 17:25:30 -070076test_dynamic_ldflags = -Wl,--export-dynamic -Wl,-u,DlSymTestFunction
77test_dynamic_src_files = \
Elliott Hughese66190d2012-12-18 15:57:55 -080078 dlfcn_test.cpp \
jeffhaoacf5aa72012-09-12 17:25:30 -070079
Nick Kralevich5bcf3982013-06-28 10:34:09 -070080test_fortify_static_libraries = \
81 fortify1-tests-gcc fortify2-tests-gcc fortify1-tests-clang fortify2-tests-clang
82
Sergey Melnikovc45087b2013-01-25 16:40:13 +040083include $(CLEAR_VARS)
84LOCAL_MODULE := bionic-unit-tests-unwind-test-impl
85LOCAL_CFLAGS += $(test_c_flags) -fexceptions -fnon-call-exceptions
86LOCAL_SRC_FILES := stack_unwinding_test_impl.c
87include $(BUILD_STATIC_LIBRARY)
88
89include $(CLEAR_VARS)
90LOCAL_MODULE := bionic-unit-tests-unwind-test-impl-host
91LOCAL_CFLAGS += $(test_c_flags) -fexceptions -fnon-call-exceptions
92LOCAL_SRC_FILES := stack_unwinding_test_impl.c
93include $(BUILD_HOST_STATIC_LIBRARY)
94
Elliott Hughes7be369d2012-11-08 15:37:43 -080095# Build tests for the device (with bionic's .so). Run with:
Elliott Hughescc213f82012-08-14 15:32:42 -070096# adb shell /data/nativetest/bionic-unit-tests/bionic-unit-tests
97include $(CLEAR_VARS)
Joe Onorato7b841f32012-08-15 20:27:04 -070098LOCAL_MODULE := bionic-unit-tests
Elliott Hughes2e8f4342012-09-05 14:27:17 -070099LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
Elliott Hughesad88a082012-10-24 18:37:21 -0700100LOCAL_CFLAGS += $(test_c_flags)
jeffhaoacf5aa72012-09-12 17:25:30 -0700101LOCAL_LDFLAGS += $(test_dynamic_ldflags)
102LOCAL_SHARED_LIBRARIES += libdl
103LOCAL_SRC_FILES := $(test_src_files) $(test_dynamic_src_files)
Nick Kralevich5bcf3982013-06-28 10:34:09 -0700104LOCAL_WHOLE_STATIC_LIBRARIES := $(test_fortify_static_libraries)
Sergey Melnikovc45087b2013-01-25 16:40:13 +0400105LOCAL_STATIC_LIBRARIES += bionic-unit-tests-unwind-test-impl
Elliott Hughescc213f82012-08-14 15:32:42 -0700106include $(BUILD_NATIVE_TEST)
107
Elliott Hughes7be369d2012-11-08 15:37:43 -0800108# Build tests for the device (with bionic's .a). Run with:
Elliott Hughesbfeab1b2012-09-05 17:47:37 -0700109# adb shell /data/nativetest/bionic-unit-tests-static/bionic-unit-tests-static
110include $(CLEAR_VARS)
Elliott Hughesbfeab1b2012-09-05 17:47:37 -0700111LOCAL_MODULE := bionic-unit-tests-static
112LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
jeffhaoacf5aa72012-09-12 17:25:30 -0700113LOCAL_FORCE_STATIC_EXECUTABLE := true
Christopher Ferris153d9272013-08-27 14:32:15 -0700114LOCAL_WHOLE_STATIC_LIBRARIES += libBionicTests
Christopher Ferris8240bed2013-08-29 11:37:33 -0700115LOCAL_STATIC_LIBRARIES += libstlport_static libstdc++ libm libc
Elliott Hughesbfeab1b2012-09-05 17:47:37 -0700116include $(BUILD_NATIVE_TEST)
117
Elliott Hughes7be369d2012-11-08 15:37:43 -0800118# -----------------------------------------------------------------------------
Christopher Ferris153d9272013-08-27 14:32:15 -0700119# We build the static unit tests as a library so they can be used both for
120# bionic-unit-tests-static and also as part of CTS.
121# -----------------------------------------------------------------------------
122
123include $(CLEAR_VARS)
124LOCAL_MODULE := libBionicTests
125LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
126LOCAL_CFLAGS += $(test_c_flags)
127LOCAL_SRC_FILES := $(test_src_files)
Christopher Ferris8240bed2013-08-29 11:37:33 -0700128LOCAL_CFLAGS += \
129 -DGTEST_OS_LINUX_ANDROID \
130 -DGTEST_HAS_STD_STRING \
131
132LOCAL_C_INCLUDES += \
133 bionic bionic/libstdc++/include \
134 external/gtest/include \
135 external/stlport/stlport \
136
137LOCAL_WHOLE_STATIC_LIBRARIES := \
138 $(test_fortify_static_libraries) \
139 bionic-unit-tests-unwind-test-impl \
140
Christopher Ferris153d9272013-08-27 14:32:15 -0700141include $(BUILD_STATIC_LIBRARY)
142
143# -----------------------------------------------------------------------------
Elliott Hughes7be369d2012-11-08 15:37:43 -0800144# Test library for the unit tests.
145# -----------------------------------------------------------------------------
Elliott Hughes124fae92012-10-31 14:20:03 -0700146
147# Build no-elf-hash-table-library.so to test dlopen(3) on a library that
Elliott Hughesa43e9062013-01-07 14:18:22 -0800148# only has a GNU-style hash table. MIPS doesn't support GNU hash style.
149ifneq ($(TARGET_ARCH),mips)
Elliott Hughes124fae92012-10-31 14:20:03 -0700150include $(CLEAR_VARS)
151LOCAL_MODULE := no-elf-hash-table-library
152LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
153LOCAL_SRC_FILES := empty.cpp
154LOCAL_LDFLAGS := -Wl,--hash-style=gnu
155include $(BUILD_SHARED_LIBRARY)
Elliott Hughesa43e9062013-01-07 14:18:22 -0800156endif
Elliott Hughes124fae92012-10-31 14:20:03 -0700157
Elliott Hughes7be369d2012-11-08 15:37:43 -0800158# -----------------------------------------------------------------------------
159# Unit tests built against glibc.
160# -----------------------------------------------------------------------------
Elliott Hughes124fae92012-10-31 14:20:03 -0700161
Elliott Hughes7be369d2012-11-08 15:37:43 -0800162# Build tests for the host (with glibc).
Elliott Hughescc213f82012-08-14 15:32:42 -0700163# Note that this will build against glibc, so it's not useful for testing
164# bionic's implementation, but it does let you use glibc as a reference
165# implementation for testing the tests themselves.
Elliott Hughes38bfa212012-09-13 11:01:46 -0700166ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
Elliott Hughescc213f82012-08-14 15:32:42 -0700167include $(CLEAR_VARS)
Joe Onorato7b841f32012-08-15 20:27:04 -0700168LOCAL_MODULE := bionic-unit-tests-glibc
Elliott Hughes2e8f4342012-09-05 14:27:17 -0700169LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
Elliott Hughesad88a082012-10-24 18:37:21 -0700170LOCAL_CFLAGS += $(test_c_flags)
Jeff Hao9b06cc32013-08-15 14:51:16 -0700171LOCAL_LDFLAGS += -lpthread -ldl -lrt
jeffhaoacf5aa72012-09-12 17:25:30 -0700172LOCAL_LDFLAGS += $(test_dynamic_ldflags)
173LOCAL_SRC_FILES := $(test_src_files) $(test_dynamic_src_files)
Sergey Melnikovc45087b2013-01-25 16:40:13 +0400174LOCAL_STATIC_LIBRARIES += bionic-unit-tests-unwind-test-impl-host
Elliott Hughescc213f82012-08-14 15:32:42 -0700175include $(BUILD_HOST_NATIVE_TEST)
Christopher Ferrisb38e4d52013-10-25 10:06:57 -0700176
177# gtest needs ANDROID_DATA/local/tmp for death test output.
178# Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
179# Use the current target out directory as ANDROID_DATA.
180bionic-unit-tests-glibc-run: bionic-unit-tests-glibc
181 mkdir -p $(TARGET_OUT_DATA)/local/tmp
182 ANDROID_DATA=$(TARGET_OUT_DATA) \
183 ANDROID_ROOT=$(TARGET_OUT) \
184 $(HOST_OUT_EXECUTABLES)/bionic-unit-tests-glibc
Elliott Hughes38bfa212012-09-13 11:01:46 -0700185endif
Benoit Goby5ac9eee2012-08-31 19:52:15 -0700186
Nick Kralevich16d1af12013-06-17 14:49:19 -0700187# -----------------------------------------------------------------------------
Pavel Chupinf22fb682013-09-06 18:43:27 +0400188# Run the unit tests built against x86 bionic on an x86 host.
189# -----------------------------------------------------------------------------
190
191ifeq ($(HOST_OS)-$(HOST_ARCH),linux-x86)
Pavel Chupin17558de2013-10-17 14:41:34 +0400192ifeq ($(TARGET_ARCH),$(filter $(TARGET_ARCH),x86 x86_64))
Pavel Chupinf22fb682013-09-06 18:43:27 +0400193ifeq ($(TARGET_ARCH),x86)
Pavel Chupin17558de2013-10-17 14:41:34 +0400194LINKER = linker
195else
196LINKER = linker64
197endif
Christopher Ferrisb38e4d52013-10-25 10:06:57 -0700198# gtest needs ANDROID_DATA/local/tmp for death test output.
199# Make sure to create ANDROID_DATA/local/tmp if doesn't exist.
Pavel Chupinf22fb682013-09-06 18:43:27 +0400200# bionic itself should always work relative to ANDROID_DATA or ANDROID_ROOT.
Pavel Chupin17558de2013-10-17 14:41:34 +0400201bionic-unit-tests-run-on-host: bionic-unit-tests $(TARGET_OUT_EXECUTABLES)/$(LINKER) $(TARGET_OUT_EXECUTABLES)/sh
Christopher Ferrisb38e4d52013-10-25 10:06:57 -0700202 if [ ! -d /system -o ! -d /system/bin ]; then \
203 echo "Attempting to create /system/bin"; \
204 sudo mkdir -p -m 0777 /system/bin; \
205 fi
Pavel Chupinf22fb682013-09-06 18:43:27 +0400206 mkdir -p $(TARGET_OUT_DATA)/local/tmp
Pavel Chupin17558de2013-10-17 14:41:34 +0400207 cp $(TARGET_OUT_EXECUTABLES)/$(LINKER) /system/bin
Elliott Hughese60c4f02013-09-19 11:28:20 -0700208 cp $(TARGET_OUT_EXECUTABLES)/sh /system/bin
Pavel Chupinf22fb682013-09-06 18:43:27 +0400209 ANDROID_DATA=$(TARGET_OUT_DATA) \
210 ANDROID_ROOT=$(TARGET_OUT) \
Pavel Chupinf22fb682013-09-06 18:43:27 +0400211 LD_LIBRARY_PATH=$(TARGET_OUT_SHARED_LIBRARIES) \
212 $(TARGET_OUT_DATA_NATIVE_TESTS)/bionic-unit-tests/bionic-unit-tests
213endif
214endif
215
216# -----------------------------------------------------------------------------
Nick Kralevich5bcf3982013-06-28 10:34:09 -0700217# FORTIFY_SOURCE tests
Nick Kralevich16d1af12013-06-17 14:49:19 -0700218# -----------------------------------------------------------------------------
Nick Kralevich5bcf3982013-06-28 10:34:09 -0700219
220fortify_c_includes = \
221 bionic \
222 bionic/libstdc++/include \
223 external/stlport/stlport \
224 external/gtest/include
225fortify_test_files = fortify_test.cpp
Nick Kralevich16d1af12013-06-17 14:49:19 -0700226
227# -Wno-error=unused-parameter needed as
228# external/stlport/stlport/stl/_threads.c (included from
229# external/gtest/include/gtest/gtest.h) does not compile cleanly under
230# clang. TODO: fix this.
Nick Kralevich5bcf3982013-06-28 10:34:09 -0700231fortify_c_flags = $(test_c_flags) -Wno-error=unused-parameter
Nick Kralevich16d1af12013-06-17 14:49:19 -0700232
Nick Kralevich5bcf3982013-06-28 10:34:09 -0700233include $(CLEAR_VARS)
234LOCAL_SRC_FILES := $(fortify_test_files)
235LOCAL_MODULE := fortify1-tests-gcc
236LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DTEST_NAME=Fortify1_Gcc
Nick Kralevich16d1af12013-06-17 14:49:19 -0700237LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
Nick Kralevich5bcf3982013-06-28 10:34:09 -0700238LOCAL_C_INCLUDES += $(fortify_c_includes)
239include $(BUILD_STATIC_LIBRARY)
Nick Kralevich16d1af12013-06-17 14:49:19 -0700240
Nick Kralevich5bcf3982013-06-28 10:34:09 -0700241include $(CLEAR_VARS)
242LOCAL_SRC_FILES := $(fortify_test_files)
243LOCAL_MODULE := fortify2-tests-gcc
244LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -DTEST_NAME=Fortify2_Gcc
245LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
246LOCAL_C_INCLUDES += $(fortify_c_includes)
247include $(BUILD_STATIC_LIBRARY)
248
249include $(CLEAR_VARS)
250LOCAL_SRC_FILES := $(fortify_test_files)
251LOCAL_MODULE := fortify1-tests-clang
252LOCAL_CLANG := true
253LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DTEST_NAME=Fortify1_Clang
254LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
255LOCAL_C_INCLUDES += $(fortify_c_includes)
256include $(BUILD_STATIC_LIBRARY)
257
258include $(CLEAR_VARS)
259LOCAL_SRC_FILES := $(fortify_test_files)
260LOCAL_MODULE := fortify2-tests-clang
261LOCAL_CLANG := true
262LOCAL_CFLAGS += $(fortify_c_flags) -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -DTEST_NAME=Fortify2_Clang
263LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
264LOCAL_C_INCLUDES += $(fortify_c_includes)
Nick Kralevich16d1af12013-06-17 14:49:19 -0700265include $(BUILD_STATIC_LIBRARY)
266
Benoit Goby5ac9eee2012-08-31 19:52:15 -0700267endif # !BUILD_TINY_ANDROID