1#
2# Copyright (C) 2016 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.
15#
16
17# Note that the platform modules are defined in the Android.bp. This file is
18# used for the NDK, but is also how we define the tests for the platform.
19
20LOCAL_PATH := $(call my-dir)
21
22# Defines a test module.
23#
24# The upstream gtest configuration builds each of these as separate executables.
25# It's a pain for how we run tests in the platform, but we can handle that with
26# a test running script.
27#
28# $(1): Test name. test/$(1).cc will automatically be added to sources.
29# $(2): Additional source files.
30# $(3): "libgtest_main" or empty.
31# $(4): Variant. Can be "_host", "_ndk", or empty.
32# $(5): NDK STL if $(4) is "_ndk", else empty.
33#
34# Use -Wno-unnamed-type-template-args because gtest_unittest.cc wants anonymous enum type.
35define gtest-unit-test
36    $(eval include $(CLEAR_VARS)) \
37    $(eval LOCAL_MODULE := \
38        $(1)$(if $(findstring _ndk,$(4)),$(4))$(if $(5),_$(5))) \
39    $(eval LOCAL_CPP_EXTENSION := .cc) \
40    $(eval LOCAL_SRC_FILES := test/$(strip $(1)).cc $(2)) \
41    $(eval LOCAL_C_INCLUDES := $(LOCAL_PATH)/include) \
42    $(eval LOCAL_CPP_FEATURES := rtti) \
43    $(eval LOCAL_CFLAGS := -Wno-unnamed-type-template-args) \
44    $(eval LOCAL_STATIC_LIBRARIES := \
45        $(if $(3),$(3)$(4)$(if $(5),_$(5))) libgtest$(4)$(if $(5),_$(5))) \
46    $(if $(findstring _ndk,$(4)),$(eval LOCAL_LDLIBS := -ldl)) \
47    $(if $(findstring _ndk,$(4)),$(eval LOCAL_SDK_VERSION := 9)) \
48    $(if $(findstring _ndk,$(4)),$(eval LOCAL_NDK_STL_VARIANT := $(5)_static)) \
49    $(if $(findstring _host,$(4)),,\
50        $(eval LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_NATIVE_TESTS))) \
51    $(eval $(if $(findstring _host,$(4)), \
52        include $(BUILD_HOST_EXECUTABLE), \
53        include $(BUILD_EXECUTABLE)))
54endef
55
56# Create modules for each test in the suite.
57#
58# $(1): Variant. Can be "_host", "_ndk", or empty.
59# $(2): NDK STL if $(1) is "_ndk", else empty.
60#
61# The NDK variant of gtest-death-test_test is disabled because we don't have
62# pthread_atfork on android-9.
63define gtest-test-suite
64    $(if $(findstring _ndk,$(1)),, \
65        $(eval $(call gtest-unit-test, \
66            gtest-death-test_test,,libgtest_main,$(1),$(2)))) \
67    $(eval $(call gtest-unit-test,gtest_environment_test,,,$(1),$(2))) \
68    $(eval $(call gtest-unit-test,gtest-filepath_test,, \
69        libgtest_main,$(1),$(2))) \
70    $(eval $(call gtest-unit-test,gtest-linked_ptr_test,, \
71        libgtest_main,$(1),$(2))) \
72    $(eval $(call gtest-unit-test,gtest-listener_test,, \
73        libgtest_main,$(1),$(2))) \
74    $(eval $(call gtest-unit-test,gtest_main_unittest,, \
75        libgtest_main,$(1),$(2))) \
76    $(eval $(call gtest-unit-test,gtest-message_test,, \
77        libgtest_main,$(1),$(2))) \
78    $(eval $(call gtest-unit-test,gtest_no_test_unittest,,,$(1),$(2))) \
79    $(eval $(call gtest-unit-test,gtest-options_test,, \
80        libgtest_main,$(1),$(2))) \
81    $(eval $(call gtest-unit-test,gtest-param-test_test, \
82        test/gtest-param-test2_test.cc,,$(1),$(2))) \
83    $(eval $(call gtest-unit-test,gtest-port_test,,libgtest_main,$(1),$(2))) \
84    $(eval $(call gtest-unit-test,gtest_pred_impl_unittest,, \
85        libgtest_main,$(1),$(2))) \
86    $(eval $(call gtest-unit-test,gtest_premature_exit_test,,,$(1),$(2))) \
87    $(eval $(call gtest-unit-test,gtest_prod_test,test/production.cc, \
88        libgtest_main,$(1),$(2))) \
89    $(eval $(call gtest-unit-test,gtest_repeat_test,,,$(1),$(2))) \
90    $(eval $(call gtest-unit-test,gtest_sole_header_test,, \
91        libgtest_main,$(1),$(2))) \
92    $(eval $(call gtest-unit-test,gtest_stress_test,,,$(1),$(2))) \
93    $(eval $(call gtest-unit-test,gtest-test-part_test,, \
94        libgtest_main,$(1),$(2))) \
95    $(eval $(call gtest-unit-test, \
96        gtest-typed-test_test,test/gtest-typed-test2_test.cc, \
97            libgtest_main,$(1),$(2))) \
98    $(eval $(call gtest-unit-test,gtest_unittest,,libgtest_main,$(1),$(2))) \
99    $(eval $(call gtest-unit-test,gtest-unittest-api_test,,,$(1),$(2)))
100endef
101
102# Test is disabled because Android doesn't build gtest with exceptions.
103# $(eval $(call gtest-unit-test,gtest_throw_on_failure_ex_test,,,$(1),$(2)))
104
105# Test is disabled until https://github.com/google/googletest/pull/728 lands.
106# $(eval $(call gtest-unit-test,gtest-printers_test,,libgtest_main,$(1),$(2)))
107
108# If we're being invoked from ndk-build, we'll have NDK_ROOT defined.
109ifdef NDK_ROOT
110
111include $(CLEAR_VARS)
112LOCAL_MODULE := libgtest
113LOCAL_SRC_FILES := src/gtest-all.cc
114LOCAL_C_INCLUDES := $(LOCAL_PATH)/src $(LOCAL_PATH)/include
115LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
116LOCAL_CPP_FEATURES := rtti
117include $(BUILD_STATIC_LIBRARY)
118
119# Note: Unlike the platform, libgtest_main carries a dependency on libgtest.
120# Users don't need to manually depend on both.
121include $(CLEAR_VARS)
122LOCAL_MODULE := libgtest_main
123LOCAL_SRC_FILES := src/gtest_main.cc
124LOCAL_C_INCLUDES := $(LOCAL_PATH)/src $(LOCAL_PATH)/include
125LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
126LOCAL_CPP_FEATURES := rtti
127LOCAL_STATIC_LIBRARIES := libgtest
128include $(BUILD_STATIC_LIBRARY)
129
130# These are the old names of these libraries. They don't match the platform or
131# the upstream build, but we've been requiring that people put them in their NDK
132# makefiles for years.
133
134include $(CLEAR_VARS)
135LOCAL_MODULE := googletest_static
136LOCAL_SRC_FILES := src/gtest-all.cc
137LOCAL_C_INCLUDES := $(LOCAL_PATH)/src $(LOCAL_PATH)/include
138LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
139LOCAL_CPP_FEATURES := rtti
140include $(BUILD_STATIC_LIBRARY)
141
142include $(CLEAR_VARS)
143LOCAL_MODULE := libgoogletest_main
144LOCAL_CPP_EXTENSION := .cc
145LOCAL_SRC_FILES := src/gtest_main.cc
146LOCAL_C_INCLUDES := $(LOCAL_PATH)/src $(LOCAL_PATH)/include
147LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
148LOCAL_CPP_FEATURES := rtti
149LOCAL_STATIC_LIBRARIES := libgtest
150include $(BUILD_STATIC_LIBRARY)
151
152# The NDK used to include shared versions of these libraries, for some reason.
153
154include $(CLEAR_VARS)
155LOCAL_MODULE := googletest_shared
156LOCAL_SRC_FILES := src/gtest-all.cc
157LOCAL_C_INCLUDES := $(LOCAL_PATH)/src $(LOCAL_PATH)/include
158LOCAL_CFLAGS := -DGTEST_CREATE_SHARED_LIBRARY
159LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
160LOCAL_CPP_FEATURES := rtti
161include $(BUILD_SHARED_LIBRARY)
162
163include $(CLEAR_VARS)
164LOCAL_MODULE := googletest_main_shared
165LOCAL_SRC_FILES := src/gtest_main.cc
166LOCAL_C_INCLUDES := $(LOCAL_PATH)/src $(LOCAL_PATH)/include
167LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
168LOCAL_CPP_FEATURES := rtti
169LOCAL_SHARED_LIBRARIES := googletest_shared
170include $(BUILD_STATIC_LIBRARY)
171
172else
173
174# Tests for the platform built NDK gtest.
175$(call gtest-test-suite,_ndk,stlport)
176$(call gtest-test-suite,_ndk,gnustl)
177$(call gtest-test-suite,_ndk,c++)
178
179# Tests for the host gtest.
180ifeq (,$(TARGET_BUILD_APPS))
181$(call gtest-test-suite,_host,)
182endif
183
184endif
185
186# Tests for the platform device gtest and for use in the NDK itself.
187$(call gtest-test-suite,)
188