aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Android.bp44
-rw-r--r--METADATA19
-rw-r--r--OWNERS1
-rw-r--r--TEST_MAPPING28
-rw-r--r--googlemock/Android.bp127
l---------googlemock/LICENSE1
-rw-r--r--googlemock/MODULE_LICENSE_BSD_LIKE0
l---------googlemock/NOTICE1
-rw-r--r--googlemock/include/gmock/gmock-matchers.h2
-rw-r--r--googlemock/include/gmock/gmock.h2
-rw-r--r--googlemock/test/Android.bp83
-rw-r--r--googletest/Android.bp116
-rw-r--r--googletest/Android.mk168
l---------googletest/LICENSE1
-rw-r--r--googletest/MODULE_LICENSE_BSD_LIKE0
l---------googletest/NOTICE1
-rw-r--r--googletest/include/gtest/gtest-printers.h18
-rw-r--r--googletest/include/gtest/internal/custom/gtest-port.h8
-rw-r--r--googletest/include/gtest/internal/custom/gtest.h22
-rw-r--r--googletest/include/gtest/internal/gtest-port.h14
-rw-r--r--googletest/src/gtest.cc5
-rw-r--r--googletest/test/Android.bp196
-rw-r--r--googletest/test/googletest-options-test.cc12
-rwxr-xr-xrun_tests.py103
24 files changed, 967 insertions, 5 deletions
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 00000000..8ecadf4c
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,44 @@
+//
+// Copyright (C) 2021 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package {
+ default_applicable_licenses: ["external_googletest_license"],
+}
+
+// Added automatically by a large-scale-change that took the approach of
+// 'apply every license found to every target'. While this makes sure we respect
+// every license restriction, it may not be entirely correct.
+//
+// e.g. GPL in an MIT project might only apply to the contrib/ directory.
+//
+// Please consider splitting the single license below into multiple licenses,
+// taking care not to lose any license_kind information, and overriding the
+// default license using the 'licenses: [...]' property on targets as needed.
+//
+// For unused files, consider creating a 'fileGroup' with "//visibility:private"
+// to attach the license to, and including a comment whether the files may be
+// used in the current project.
+// See: http://go/android-license-faq
+license {
+ name: "external_googletest_license",
+ visibility: [":__subpackages__"],
+ license_kinds: [
+ "SPDX-license-identifier-Apache-2.0",
+ "SPDX-license-identifier-BSD",
+ ],
+ license_text: [
+ "LICENSE",
+ ],
+}
diff --git a/METADATA b/METADATA
new file mode 100644
index 00000000..e2d05ce6
--- /dev/null
+++ b/METADATA
@@ -0,0 +1,19 @@
+name: "googletest"
+description: "Google's C++ test framework!"
+third_party {
+ url {
+ type: HOMEPAGE
+ value: "https://github.com/google/googletest"
+ }
+ url {
+ type: GIT
+ value: "https://github.com/google/googletest.git"
+ }
+ version: "e47544ad31cb3ceecd04cc13e8fe556f8df9fe0b"
+ license_type: NOTICE
+ last_upgrade_date {
+ year: 2023
+ month: 9
+ day: 27
+ }
+}
diff --git a/OWNERS b/OWNERS
new file mode 100644
index 00000000..7529cb92
--- /dev/null
+++ b/OWNERS
@@ -0,0 +1 @@
+include platform/system/core:/janitors/OWNERS
diff --git a/TEST_MAPPING b/TEST_MAPPING
new file mode 100644
index 00000000..32e6a971
--- /dev/null
+++ b/TEST_MAPPING
@@ -0,0 +1,28 @@
+{
+ "presubmit": [
+ {
+ "name": "gtest_isolated_tests"
+ },
+ {
+ // Confirm GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST behavior
+ "name": "VtsHalBluetoothA2dpV1_0TargetTest"
+ },
+ {
+ // Confirm VTS test can pass
+ "name": "VtsHalPowerStatsV1_0TargetTest"
+ }
+ ],
+ "hwasan-postsubmit": [
+ {
+ "name": "gtest_isolated_tests"
+ },
+ {
+ // Confirm GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST behavior
+ "name": "VtsHalBluetoothA2dpV1_0TargetTest"
+ },
+ {
+ // Confirm VTS test can pass
+ "name": "VtsHalPowerStatsV1_0TargetTest"
+ }
+ ]
+}
diff --git a/googlemock/Android.bp b/googlemock/Android.bp
new file mode 100644
index 00000000..4cc979d2
--- /dev/null
+++ b/googlemock/Android.bp
@@ -0,0 +1,127 @@
+// Copyright (C) 2016 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package {
+ // See: http://go/android-license-faq
+ // A large-scale-change added 'default_applicable_licenses' to import
+ // all of the 'license_kinds' from "external_googletest_license"
+ // to get the below license kinds:
+ // SPDX-license-identifier-Apache-2.0
+ // SPDX-license-identifier-BSD
+ default_applicable_licenses: ["external_googletest_license"],
+}
+
+cc_defaults {
+ name: "gmock_flags",
+
+ local_include_dirs: ["include"],
+ export_include_dirs: ["include"],
+
+ cflags: [
+ "-Wall",
+ "-Werror",
+ "-Wno-missing-field-initializers",
+ "-Wno-sign-compare",
+ "-Wno-unused-parameter",
+ // We need to generate exception tables, otherwise any users of this
+ // library that use testing::Throw will trigger undefined behaviour.
+ "-fexceptions",
+ ],
+}
+
+cc_defaults {
+ name: "gmock_ndk",
+ sdk_version: "9",
+ stl: "c++_static",
+ cpp_std: "c++14",
+}
+
+cc_defaults {
+ name: "gmock_defaults",
+ host_supported: true,
+ target: {
+ linux_bionic: {
+ enabled: true,
+ },
+ windows: {
+ enabled: true,
+ },
+ },
+}
+
+cc_library_static {
+ name: "libgmock_ndk",
+ defaults: [
+ "gmock_ndk",
+ "gmock_flags",
+ ],
+ srcs: ["src/gmock-all.cc"],
+ static_libs: ["libgtest_ndk_c++"],
+}
+
+cc_library_static {
+ name: "libgmock_main_ndk",
+ defaults: [
+ "gmock_ndk",
+ "gmock_flags",
+ ],
+ srcs: ["src/gmock_main.cc"],
+ static_libs: ["libgtest_ndk_c++"],
+}
+
+cc_library_static {
+ name: "libgmock",
+ defaults: [
+ "gmock_defaults",
+ "gmock_flags",
+ ],
+ srcs: ["src/gmock-all.cc"],
+ rtti: true,
+ static_libs: ["libgtest"],
+ vendor_available: true,
+ product_available: true,
+ native_bridge_supported: true,
+}
+
+cc_library_static {
+ name: "libgmock_main",
+ defaults: [
+ "gmock_defaults",
+ "gmock_flags",
+ ],
+ srcs: ["src/gmock_main.cc"],
+ static_libs: ["libgtest"],
+ vendor_available: true,
+ product_available: true,
+ native_bridge_supported: true,
+}
+
+// Deprecated: use libgmock instead
+cc_library_host_static {
+ name: "libgmock_host",
+ defaults: [
+ "gmock_defaults",
+ "gmock_flags",
+ ],
+ whole_static_libs: ["libgmock"],
+}
+
+cc_library_host_static {
+ name: "libgmock_main_host",
+ defaults: [
+ "gmock_defaults",
+ "gmock_flags",
+ ],
+ whole_static_libs: ["libgmock_main"],
+}
diff --git a/googlemock/LICENSE b/googlemock/LICENSE
new file mode 120000
index 00000000..ea5b6064
--- /dev/null
+++ b/googlemock/LICENSE
@@ -0,0 +1 @@
+../LICENSE \ No newline at end of file
diff --git a/googlemock/MODULE_LICENSE_BSD_LIKE b/googlemock/MODULE_LICENSE_BSD_LIKE
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/googlemock/MODULE_LICENSE_BSD_LIKE
diff --git a/googlemock/NOTICE b/googlemock/NOTICE
new file mode 120000
index 00000000..ea5b6064
--- /dev/null
+++ b/googlemock/NOTICE
@@ -0,0 +1 @@
+../LICENSE \ No newline at end of file
diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h
index 0f677137..bc994bd7 100644
--- a/googlemock/include/gmock/gmock-matchers.h
+++ b/googlemock/include/gmock/gmock-matchers.h
@@ -288,6 +288,8 @@ GTEST_DISABLE_MSC_WARNINGS_PUSH_(
clients of class B */
/* Symbol involving type with internal linkage not defined */)
+#pragma GCC system_header
+
namespace testing {
// To implement a matcher Foo for type T, define:
diff --git a/googlemock/include/gmock/gmock.h b/googlemock/include/gmock/gmock.h
index 2ca4f7ac..c0c7ce64 100644
--- a/googlemock/include/gmock/gmock.h
+++ b/googlemock/include/gmock/gmock.h
@@ -34,6 +34,8 @@
#ifndef GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_H_
#define GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_H_
+#define GMOCK_INCLUDE_GMOCK_GMOCK_H_ // Android: backwards compatibility.
+
// This file implements the following syntax:
//
// ON_CALL(mock_object, Method(...))
diff --git a/googlemock/test/Android.bp b/googlemock/test/Android.bp
new file mode 100644
index 00000000..19463a36
--- /dev/null
+++ b/googlemock/test/Android.bp
@@ -0,0 +1,83 @@
+// Copyright (C) 2016 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package {
+ // See: http://go/android-license-faq
+ // A large-scale-change added 'default_applicable_licenses' to import
+ // all of the 'license_kinds' from "external_googletest_license"
+ // to get the below license kinds:
+ // SPDX-license-identifier-BSD
+ default_applicable_licenses: ["external_googletest_license"],
+}
+
+cc_defaults {
+ name: "gmock_test_defaults",
+ host_supported: true,
+ gtest: false,
+ cpp_std: "c++14",
+ cflags: [
+ "-Wall",
+ "-Werror",
+ "-Wno-sign-compare",
+ "-Wno-unused-parameter",
+ "-Wno-unused-private-field",
+ ],
+ include_dirs: [
+ "external/googletest/googlemock",
+ "external/googletest/googletest",
+ ],
+ static_libs: [
+ "libgmock_main",
+ "libgmock",
+ "libgtest",
+ ],
+}
+
+cc_test {
+ name: "gmock_tests",
+ defaults: ["gmock_test_defaults"],
+ test_per_src: true,
+ srcs: [
+ "gmock-actions_test.cc",
+ "gmock-cardinalities_test.cc",
+
+ // Test is disabled because Android doesn't build gmock with exceptions.
+ //"gmock_ex_test.cc",
+
+ "gmock-function-mocker_test.cc",
+ "gmock-internal-utils_test.cc",
+ "gmock-matchers-arithmetic_test.cc",
+ "gmock-matchers-comparisons_test.cc",
+ "gmock-matchers-containers_test.cc",
+ "gmock-matchers-misc_test.cc",
+ "gmock-more-actions_test.cc",
+ "gmock-nice-strict_test.cc",
+ "gmock-port_test.cc",
+ "gmock-pp_test.cc",
+ "gmock-pp-string_test.cc",
+ "gmock-spec-builders_test.cc",
+ "gmock_test.cc",
+ ],
+}
+
+cc_test {
+ name: "gmock_link_test",
+ defaults: ["gmock_test_defaults"],
+ relative_install_path: "gmock_tests",
+ no_named_install_directory: true,
+ srcs: [
+ "gmock_link_test.cc",
+ "gmock_link2_test.cc",
+ ],
+}
diff --git a/googletest/Android.bp b/googletest/Android.bp
new file mode 100644
index 00000000..4abe7ea5
--- /dev/null
+++ b/googletest/Android.bp
@@ -0,0 +1,116 @@
+// Copyright (C) 2016 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package {
+ // See: http://go/android-license-faq
+ // A large-scale-change added 'default_applicable_licenses' to import
+ // all of the 'license_kinds' from "external_googletest_license"
+ // to get the below license kinds:
+ // SPDX-license-identifier-BSD
+ default_applicable_licenses: ["external_googletest_license"],
+}
+
+cc_defaults {
+ name: "libgtest_defaults",
+ export_include_dirs: ["include"],
+ cflags: ["-Wall", "-Werror", "-Wno-unused-private-field"],
+}
+
+cc_defaults {
+ name: "libgtest_host_defaults",
+ target: {
+ linux_bionic: {
+ enabled: true,
+ },
+ windows: {
+ enabled: true,
+ },
+ },
+}
+
+// NDK libraries.
+// We need to build one pair of (libgtest, libgtest_main) for each of the three
+// STLs we support in the NDK since the user's app might use any of them.
+
+// libc++
+cc_library_static {
+ name: "libgtest_ndk_c++",
+ defaults: ["libgtest_defaults"],
+ sdk_version: "9",
+ stl: "c++_static",
+ srcs: ["src/gtest-all.cc"],
+}
+
+cc_library_static {
+ name: "libgtest_main_ndk_c++",
+ defaults: ["libgtest_defaults"],
+ sdk_version: "9",
+ stl: "c++_static",
+ srcs: ["src/gtest_main.cc"],
+}
+
+// Platform and host libraries.
+cc_library_static {
+ name: "libgtest",
+ defaults: ["libgtest_defaults", "libgtest_host_defaults"],
+ host_supported: true,
+ vendor_available: true,
+ product_available: true,
+ native_bridge_supported: true,
+ srcs: ["src/gtest-all.cc"],
+ rtti: true,
+}
+
+cc_library_static {
+ name: "libgtest_main",
+ defaults: ["libgtest_defaults", "libgtest_host_defaults"],
+ host_supported: true,
+ vendor_available: true,
+ product_available: true,
+ native_bridge_supported: true,
+ srcs: ["src/gtest_main.cc"],
+}
+
+// Legacy libraries for makefiles that refer to libgtest_host
+cc_library_host_static {
+ name: "libgtest_host",
+ whole_static_libs: ["libgtest"],
+ defaults: ["libgtest_host_defaults"],
+}
+
+cc_library_host_static {
+ name: "libgtest_main_host",
+ whole_static_libs: ["libgtest_main"],
+ defaults: ["libgtest_host_defaults"],
+}
+
+cc_library_headers {
+ name: "libgtest_prod_headers",
+ defaults: ["libgtest_defaults", "libgtest_host_defaults"],
+ host_supported: true,
+ native_bridge_supported: true,
+ ramdisk_available: true,
+ recovery_available: true,
+ vendor_ramdisk_available: true,
+ vendor_available: true,
+ product_available: true,
+ export_include_dirs: ["include"],
+ apex_available: [
+ "//apex_available:anyapex",
+ "//apex_available:platform",
+ ],
+ min_sdk_version: "apex_inherit",
+}
+
+// Tests are in the Android.mk. Run with external/googletest/run_tests.py.
diff --git a/googletest/Android.mk b/googletest/Android.mk
new file mode 100644
index 00000000..19060e8c
--- /dev/null
+++ b/googletest/Android.mk
@@ -0,0 +1,168 @@
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# Note that the platform modules are defined in the Android.bp. This file is
+# used for the NDK.
+
+# If we're being invoked from ndk-build, we'll have NDK_ROOT defined.
+ifdef NDK_ROOT
+
+LOCAL_PATH := $(call my-dir)
+
+# Defines a test module.
+#
+# The upstream gtest configuration builds each of these as separate executables.
+# It's a pain for how we run tests in the platform, but we can handle that with
+# a test running script.
+#
+# $(1): Test name. test/$(1).cc will automatically be added to sources.
+# $(2): Additional source files.
+# $(3): "libgtest_main" or empty.
+#
+# Use -Wno-unnamed-type-template-args because gtest_unittest.cc wants anonymous enum type.
+define gtest-unit-test
+ $(eval include $(CLEAR_VARS)) \
+ $(eval LOCAL_MODULE := $(1)) \
+ $(eval LOCAL_CPP_EXTENSION := .cc) \
+ $(eval LOCAL_SRC_FILES := test/$(strip $(1)).cc $(2)) \
+ $(eval LOCAL_C_INCLUDES := $(LOCAL_PATH)/include) \
+ $(eval LOCAL_CPP_FEATURES := rtti) \
+ $(eval LOCAL_CFLAGS := -Wall -Werror -Wno-sign-compare -Wno-unnamed-type-template-args) \
+ $(eval LOCAL_CFLAGS += -Wno-unused-private-field) \
+ $(eval LOCAL_STATIC_LIBRARIES := $(3) libgtest) \
+ $(eval include $(BUILD_EXECUTABLE))
+endef
+
+# Create modules for each test in the suite.
+#
+# The NDK variant of gtest-death-test_test is disabled because we don't have
+# pthread_atfork on android-9.
+define gtest-test-suite
+ $(eval $(call gtest-unit-test,googletest-death-test-test,,libgtest_main)) \
+ $(eval $(call gtest-unit-test,googletest-filepath-test,,libgtest_main)) \
+ $(eval $(call gtest-unit-test,googletest-listener-test,,libgtest_main)) \
+ $(eval $(call gtest-unit-test,googletest-message-test,,libgtest_main)) \
+ $(eval $(call gtest-unit-test,googletest-options-test,,libgtest_main)) \
+ $(eval $(call gtest-unit-test,googletest-param-test-test, \
+ test/googletest-param-test2-test.cc,)) \
+ $(eval $(call gtest-unit-test,googletest-port-test,,libgtest_main)) \
+ $(eval $(call gtest-unit-test,googletest-printers-test,,libgtest_main)) \
+ $(eval $(call gtest-unit-test,googletest-test-part-test,,libgtest_main)) \
+ $(eval $(call gtest-unit-test, \
+ gtest-typed-test_test,test/gtest-typed-test2_test.cc, \
+ libgtest_main)) \
+ $(eval $(call gtest-unit-test,gtest-unittest-api_test,,)) \
+ $(eval $(call gtest-unit-test,gtest_environment_test,,)) \
+ $(eval $(call gtest-unit-test,gtest_main_unittest,,libgtest_main)) \
+ $(eval $(call gtest-unit-test,gtest_no_test_unittest,,)) \
+ $(eval $(call gtest-unit-test,gtest_pred_impl_unittest,,libgtest_main)) \
+ $(eval $(call gtest-unit-test,gtest_premature_exit_test,,)) \
+ $(eval $(call gtest-unit-test,gtest_prod_test,test/production.cc, \
+ libgtest_main)) \
+ $(eval $(call gtest-unit-test,gtest_repeat_test,,)) \
+ $(eval $(call gtest-unit-test,gtest_skip_test,,libgtest_main)) \
+ $(eval $(call gtest-unit-test,gtest_sole_header_test,,libgtest_main)) \
+ $(eval $(call gtest-unit-test,gtest_stress_test,,)) \
+ $(eval $(call gtest-unit-test,gtest_unittest,,libgtest_main))
+endef
+
+# Test is disabled because Android doesn't build gtest with exceptions.
+# $(eval $(call gtest-unit-test,gtest_throw_on_failure_ex_test,,))
+# $(eval $(call gtest-unit-test,gtest_assert_by_exception_test,,))
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libgtest
+LOCAL_LICENSE_KINDS := SPDX-license-identifier-BSD
+LOCAL_LICENSE_CONDITIONS := notice
+LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../LICENSE
+LOCAL_SRC_FILES := src/gtest-all.cc
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/src $(LOCAL_PATH)/include
+LOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)/include
+LOCAL_CPP_FEATURES := rtti
+include $(BUILD_STATIC_LIBRARY)
+
+# Note: Unlike the platform, libgtest_main carries a dependency on libgtest.
+# Users don't need to manually depend on both.
+include $(CLEAR_VARS)
+LOCAL_MODULE := libgtest_main
+LOCAL_LICENSE_KINDS := SPDX-license-identifier-BSD
+LOCAL_LICENSE_CONDITIONS := notice
+LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../LICENSE
+LOCAL_SRC_FILES := src/gtest_main.cc
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/src $(LOCAL_PATH)/include
+LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
+LOCAL_CPP_FEATURES := rtti
+LOCAL_STATIC_LIBRARIES := libgtest
+include $(BUILD_STATIC_LIBRARY)
+
+# These are the old names of these libraries. They don't match the platform or
+# the upstream build, but we've been requiring that people put them in their NDK
+# makefiles for years.
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := googletest_static
+LOCAL_LICENSE_KINDS := SPDX-license-identifier-BSD
+LOCAL_LICENSE_CONDITIONS := notice
+LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../LICENSE
+LOCAL_SRC_FILES := src/gtest-all.cc
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/src $(LOCAL_PATH)/include
+LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
+LOCAL_CPP_FEATURES := rtti
+include $(BUILD_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libgoogletest_main
+LOCAL_LICENSE_KINDS := SPDX-license-identifier-BSD
+LOCAL_LICENSE_CONDITIONS := notice
+LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../LICENSE
+LOCAL_CPP_EXTENSION := .cc
+LOCAL_SRC_FILES := src/gtest_main.cc
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/src $(LOCAL_PATH)/include
+LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
+LOCAL_CPP_FEATURES := rtti
+LOCAL_STATIC_LIBRARIES := libgtest
+include $(BUILD_STATIC_LIBRARY)
+
+# The NDK used to include shared versions of these libraries, for some reason.
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := googletest_shared
+LOCAL_LICENSE_KINDS := SPDX-license-identifier-BSD
+LOCAL_LICENSE_CONDITIONS := notice
+LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../LICENSE
+LOCAL_SRC_FILES := src/gtest-all.cc
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/src $(LOCAL_PATH)/include
+LOCAL_CFLAGS := -DGTEST_CREATE_SHARED_LIBRARY
+LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
+LOCAL_CPP_FEATURES := rtti
+include $(BUILD_SHARED_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := googletest_main_shared
+LOCAL_LICENSE_KINDS := SPDX-license-identifier-BSD
+LOCAL_LICENSE_CONDITIONS := notice
+LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../LICENSE
+LOCAL_SRC_FILES := src/gtest_main.cc
+LOCAL_C_INCLUDES := $(LOCAL_PATH)/src $(LOCAL_PATH)/include
+LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/include
+LOCAL_CPP_FEATURES := rtti
+LOCAL_SHARED_LIBRARIES := googletest_shared
+include $(BUILD_STATIC_LIBRARY)
+
+# Tests for use in the NDK itself.
+$(call gtest-test-suite)
+
+endif
diff --git a/googletest/LICENSE b/googletest/LICENSE
new file mode 120000
index 00000000..ea5b6064
--- /dev/null
+++ b/googletest/LICENSE
@@ -0,0 +1 @@
+../LICENSE \ No newline at end of file
diff --git a/googletest/MODULE_LICENSE_BSD_LIKE b/googletest/MODULE_LICENSE_BSD_LIKE
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/googletest/MODULE_LICENSE_BSD_LIKE
diff --git a/googletest/NOTICE b/googletest/NOTICE
new file mode 120000
index 00000000..ea5b6064
--- /dev/null
+++ b/googletest/NOTICE
@@ -0,0 +1 @@
+../LICENSE \ No newline at end of file
diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h
index 1b12ef68..59286815 100644
--- a/googletest/include/gtest/gtest-printers.h
+++ b/googletest/include/gtest/gtest-printers.h
@@ -208,6 +208,13 @@ struct FunctionPointerPrinter {
}
};
+// Android local change: There is a non-standard hack in android-base/logging.h
+// which emits a warning when a string pointer is printed. Ignore the warning
+// in this generic printer.
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wuser-defined-warnings"
+#endif
struct PointerPrinter {
template <typename T>
static void PrintValue(T* p, ::std::ostream* os) {
@@ -221,6 +228,9 @@ struct PointerPrinter {
}
}
};
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
namespace internal_stream_operator_without_lexical_name_lookup {
@@ -552,6 +562,11 @@ int AppropriateResolution(FloatType val) {
int full = std::numeric_limits<FloatType>::max_digits10;
if (val < 0) val = -val;
+ // Android local change: do not warn about exact float comparison.
+#ifdef __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wfloat-equal"
+#endif
if (val < 1000000) {
FloatType mulfor6 = 1e10;
if (val >= 100000.0) { // 100,000 to 999,999
@@ -595,6 +610,9 @@ int AppropriateResolution(FloatType val) {
val)
return 6;
}
+#ifdef __GNUC__
+#pragma GCC diagnostic pop
+#endif
return full;
}
diff --git a/googletest/include/gtest/internal/custom/gtest-port.h b/googletest/include/gtest/internal/custom/gtest-port.h
index db02881c..66bfb48d 100644
--- a/googletest/include/gtest/internal/custom/gtest-port.h
+++ b/googletest/include/gtest/internal/custom/gtest-port.h
@@ -34,4 +34,12 @@
#ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_
#define GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_
+// TODO: b/302409123 - <iomanip> was previously included by GTest internal
+// headers, but was recently removed. Temporarily add it here to unblock
+// upgrades.
+#include <iomanip>
+
+// Suppress warnings for deprecated *_TEST_CASE_* macros.
+#define GTEST_INTERNAL_DEPRECATED(message)
+
#endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_
diff --git a/googletest/include/gtest/internal/custom/gtest.h b/googletest/include/gtest/internal/custom/gtest.h
index afaaf17b..67ce67f1 100644
--- a/googletest/include/gtest/internal/custom/gtest.h
+++ b/googletest/include/gtest/internal/custom/gtest.h
@@ -34,4 +34,26 @@
#ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
#define GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
+#if GTEST_OS_LINUX_ANDROID
+# define GTEST_CUSTOM_TEMPDIR_FUNCTION_ GetAndroidTempDir
+# include <unistd.h>
+static inline std::string GetAndroidTempDir() {
+ // Android doesn't have /tmp, and /sdcard is no longer accessible from
+ // an app context starting from Android O. On Android, /data/local/tmp
+ // is usually used as the temporary directory, so try that first...
+ if (access("/data/local/tmp", R_OK | W_OK | X_OK) == 0) return "/data/local/tmp/";
+
+ // Processes running in an app context can't write to /data/local/tmp,
+ // so fall back to the current directory...
+ std::string result = "./";
+ char* cwd = getcwd(NULL, 0);
+ if (cwd != NULL) {
+ result = cwd;
+ result += "/";
+ free(cwd);
+ }
+ return result;
+}
+#endif //GTEST_OS_LINUX_ANDROID
+
#endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h
index d061a49b..daaaa74a 100644
--- a/googletest/include/gtest/internal/gtest-port.h
+++ b/googletest/include/gtest/internal/gtest-port.h
@@ -680,7 +680,9 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
defined(GTEST_OS_DRAGONFLY) || defined(GTEST_OS_GNU_KFREEBSD) || \
defined(GTEST_OS_HAIKU) || defined(GTEST_OS_GNU_HURD))
// Death tests require a file system to work properly.
-#if GTEST_HAS_FILE_SYSTEM
+// Android local change: Trusty force-disables stream redirection, which is also
+// required for death tests.
+#if GTEST_HAS_FILE_SYSTEM && GTEST_HAS_STREAM_REDIRECTION
#define GTEST_HAS_DEATH_TEST 1
#endif // GTEST_HAS_FILE_SYSTEM
#endif
@@ -1250,6 +1252,12 @@ class GTEST_API_ AutoHandle {
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \
/* class A needs to have dll-interface to be used by clients of class B */)
+// Android local change: disable overzealous thread safety warning.
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wthread-safety-negative"
+#endif
+
// Allows a controller thread to pause execution of newly created
// threads until notified. Instances of this class must be created
// and destroyed in the controller thread.
@@ -1283,6 +1291,10 @@ class GTEST_API_ Notification {
std::condition_variable cv_;
bool notified_;
};
+
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251
#endif // GTEST_HAS_NOTIFICATION_
diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc
index 99b22ed3..d22822eb 100644
--- a/googletest/src/gtest.cc
+++ b/googletest/src/gtest.cc
@@ -5332,9 +5332,10 @@ void UnitTest::AddTestPartResult(TestPartResult::Type result_type,
if (os_stack_trace.c_str() != nullptr && !os_stack_trace.empty()) {
msg << internal::kStackTraceMarker << os_stack_trace;
- } else {
- msg << "\n";
}
+ // Android local modification: don't add a superfluous newline so that
+ // the output is unchanged from previous versions. If it changes,
+ // the golden outputs in gtest_isolated_tests need to be updated.
const TestPartResult result = TestPartResult(
result_type, file_name, line_number, msg.GetString().c_str());
diff --git a/googletest/test/Android.bp b/googletest/test/Android.bp
new file mode 100644
index 00000000..4b000128
--- /dev/null
+++ b/googletest/test/Android.bp
@@ -0,0 +1,196 @@
+// Copyright (C) 2016 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+package {
+ // See: http://go/android-license-faq
+ // A large-scale-change added 'default_applicable_licenses' to import
+ // all of the 'license_kinds' from "external_googletest_license"
+ // to get the below license kinds:
+ // SPDX-license-identifier-BSD
+ default_applicable_licenses: ["external_googletest_license"],
+}
+
+cc_defaults {
+ name: "gtest_test_defaults",
+ host_supported: true,
+ gtest: false,
+ cflags: [
+ "-Wall",
+ "-Werror",
+ "-Wno-sign-compare",
+ // because gtest_unittest.cc wants anonymous enum type.
+ "-Wno-unnamed-type-template-args",
+ "-Wno-unused-private-field",
+ ],
+ include_dirs: ["external/googletest/googletest"],
+ static_libs: ["libgtest"],
+ relative_install_path: "gtest_tests",
+ no_named_install_directory: true,
+}
+
+cc_defaults {
+ name: "gtest_ndk_test_defaults",
+ gtest: false,
+ cflags: [
+ "-Wall",
+ "-Werror",
+ "-Wno-sign-compare",
+ "-Wno-unnamed-type-template-args",
+ "-Wno-unused-private-field",
+ ],
+ include_dirs: ["external/googletest/googletest"],
+ static_libs: ["libgtest_ndk_c++"],
+ relative_install_path: "gtest_ndk_tests",
+ no_named_install_directory: true,
+ sdk_version: "9",
+ stl: "c++_static",
+}
+
+cc_test {
+ name: "gtest_tests",
+ defaults: ["gtest_test_defaults"],
+ test_per_src: true,
+ srcs: [
+ "googletest-death-test-test.cc",
+ "googletest-filepath-test.cc",
+ "googletest-listener-test.cc",
+ "googletest-message-test.cc",
+ "googletest-options-test.cc",
+ "googletest-port-test.cc",
+ "googletest-printers-test.cc",
+ "googletest-test-part-test.cc",
+ "gtest-unittest-api_test.cc",
+ "gtest_main_unittest.cc",
+ "gtest_pred_impl_unittest.cc",
+ "gtest_skip_test.cc",
+ "gtest_sole_header_test.cc",
+ "gtest_unittest.cc",
+ ],
+ static_libs: ["libgtest_main"],
+}
+
+cc_test {
+ name: "gtest_tests_no_main",
+ defaults: ["gtest_test_defaults"],
+ test_per_src: true,
+ srcs: [
+ "gtest_environment_test.cc",
+ "gtest_no_test_unittest.cc",
+ "gtest_premature_exit_test.cc",
+ "gtest_repeat_test.cc",
+ "gtest_stress_test.cc",
+
+ // Tests are disabled because Android doesn't build gtest with exceptions
+ // "gtest_throw_on_failure_ex_test.cc",
+ // "gtest_assert_by_exception_test.cc",
+ ],
+}
+
+cc_test {
+ name: "googletest-param-test-test",
+ defaults: ["gtest_test_defaults"],
+ srcs: [
+ "googletest-param-test-test.cc",
+ "googletest-param-test2-test.cc",
+ ],
+}
+
+cc_test {
+ name: "gtest-typed-test_test",
+ defaults: ["gtest_test_defaults"],
+ srcs: [
+ "gtest-typed-test_test.cc",
+ "gtest-typed-test2_test.cc",
+ ],
+ static_libs: ["libgtest_main"],
+}
+
+cc_test {
+ name: "gtest_prod_test",
+ defaults: ["gtest_test_defaults"],
+ srcs: [
+ "gtest_prod_test.cc",
+ "production.cc",
+ ],
+ static_libs: ["libgtest_main"],
+}
+
+cc_test {
+ name: "gtest_ndk_tests",
+ defaults: ["gtest_ndk_test_defaults"],
+ test_per_src: true,
+ srcs: [
+ "googletest-death-test-test.cc",
+ "googletest-filepath-test.cc",
+ "googletest-listener-test.cc",
+ "googletest-message-test.cc",
+ "googletest-options-test.cc",
+ "googletest-port-test.cc",
+ "googletest-printers-test.cc",
+ "googletest-test-part-test.cc",
+ "gtest-unittest-api_test.cc",
+ "gtest_main_unittest.cc",
+ "gtest_pred_impl_unittest.cc",
+ "gtest_skip_test.cc",
+ "gtest_sole_header_test.cc",
+ "gtest_unittest.cc",
+ ],
+ static_libs: ["libgtest_main_ndk_c++"],
+}
+
+cc_test {
+ name: "gtest_ndk_tests_no_main",
+ defaults: ["gtest_ndk_test_defaults"],
+ test_per_src: true,
+ srcs: [
+ "gtest_environment_test.cc",
+ "gtest_no_test_unittest.cc",
+ "gtest_premature_exit_test.cc",
+ "gtest_repeat_test.cc",
+ "gtest_stress_test.cc",
+
+ // Tests are disabled because Android doesn't build gtest with exceptions
+ // "gtest_throw_on_failure_ex_test.cc",
+ // "gtest_assert_by_exception_test.cc",
+ ],
+}
+
+cc_test {
+ name: "googletest-param-test-test_ndk",
+ defaults: ["gtest_ndk_test_defaults"],
+ srcs: [
+ "googletest-param-test-test.cc",
+ "googletest-param-test2-test.cc",
+ ],
+}
+
+cc_test {
+ name: "gtest-typed-test_test_ndk",
+ defaults: ["gtest_ndk_test_defaults"],
+ srcs: [
+ "gtest-typed-test_test.cc",
+ "gtest-typed-test2_test.cc",
+ ],
+ static_libs: ["libgtest_main_ndk_c++"],
+}
+
+cc_test {
+ name: "gtest_prod_test_ndk",
+ defaults: ["gtest_ndk_test_defaults"],
+ srcs: [
+ "gtest_prod_test.cc",
+ "production.cc",
+ ],
+ static_libs: ["libgtest_main_ndk_c++"],
+}
diff --git a/googletest/test/googletest-options-test.cc b/googletest/test/googletest-options-test.cc
index b712c06f..722c5b55 100644
--- a/googletest/test/googletest-options-test.cc
+++ b/googletest/test/googletest-options-test.cc
@@ -117,8 +117,16 @@ TEST(OutputFileHelpersTest, GetCurrentExecutableName) {
const bool success = exe_str == "app";
#else
const bool success =
- exe_str == "googletest-options-test" || exe_str == "gtest_all_test" ||
- exe_str == "lt-gtest_all_test" || exe_str == "gtest_dll_test";
+ exe_str == "googletest-options-test" ||
+ exe_str == "gtest_all_test" ||
+ exe_str == "lt-gtest_all_test" ||
+ exe_str == "gtest_dll_test"
+#ifdef __ANDROID__
+ || exe_str == "gtest-options_test_ndk_c++" ||
+ exe_str == "gtest-options_test_ndk_gnustl" ||
+ exe_str == "gtest-options_test_ndk_stlport"
+#endif
+ ;
#endif // GTEST_OS_WINDOWS
if (!success) FAIL() << "GetCurrentExecutableName() returns " << exe_str;
}
diff --git a/run_tests.py b/run_tests.py
new file mode 100755
index 00000000..bc6221e9
--- /dev/null
+++ b/run_tests.py
@@ -0,0 +1,103 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2016 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+"""Runs all tests for gtest/gmock."""
+import argparse
+import logging
+import os
+import sys
+
+
+# pylint: disable=design
+
+
+def logger():
+ """Return the default logger for the module."""
+ return logging.getLogger(__name__)
+
+
+def call(cmd, *args, **kwargs):
+ """Proxy for subprocess.call with logging."""
+ import subprocess
+ logger().info('call `%s`', ' '.join(cmd))
+ return subprocess.call(cmd, *args, **kwargs)
+
+
+def parse_args():
+ "Parse and return command line arguments."""
+ parser = argparse.ArgumentParser()
+ parser.add_argument('--host', action='store_true')
+ parser.add_argument('-v', '--verbose', action='store_true')
+ return parser.parse_args()
+
+
+def main():
+ "Program entry point."""
+ args = parse_args()
+ log_level = logging.INFO
+ if args.verbose:
+ log_level = logging.DEBUG
+ logging.basicConfig(level=log_level)
+
+ if args.host:
+ test_location = os.path.join(os.environ['ANDROID_HOST_OUT'], 'nativetest64')
+ else:
+ data_dir = os.path.join(os.environ['OUT'], 'data')
+ test_location = os.path.join(data_dir, 'nativetest64')
+ if not os.path.exists(test_location):
+ test_location = os.path.join(data_dir, 'nativetest')
+
+ num_tests = 0
+ failures = []
+ for test_dir in ['gtest_tests', 'gtest_ndk_tests', 'gmock_tests']:
+ test_dir = os.path.join(test_location, test_dir)
+ if not os.path.isdir(test_dir):
+ logger().debug('Skipping %s', test_dir)
+ continue
+
+ logger().debug('Scanning %s for tests', test_dir)
+ for test in os.listdir(test_dir):
+ if not test.startswith('gtest') and not test.startswith('gmock'):
+ logger().debug('Skipping %s', test)
+ continue
+ num_tests += 1
+
+ if args.host:
+ cmd = [os.path.join(test_dir, test)]
+ if call(cmd) != 0:
+ failures.append(test)
+ else:
+ device_dir = test_dir.replace(os.environ['OUT'], '')
+ cmd = ['adb', 'shell', 'cd {} && ./{}'.format(device_dir, test)]
+ if call(cmd) != 0:
+ failures.append(test)
+
+ if num_tests == 0:
+ logger().error('No tests found!')
+ sys.exit(1)
+
+ num_failures = len(failures)
+ num_passes = num_tests - num_failures
+ logger().info('%d/%d tests passed', num_passes, num_tests)
+ if len(failures) > 0:
+ logger().error('Failures:\n%s', '\n'.join(failures))
+ else:
+ logger().info('All tests passed!')
+ sys.exit(num_failures)
+
+
+if __name__ == '__main__':
+ main()