Merge remote-tracking branch 'aosp/upstream-master' into mymerge

Change-Id: Iac43bc8e6eeb565e731267dd96c3bba374cbd81a
diff --git a/Android.bp b/Android.bp
new file mode 100644
index 0000000..b7aa6ef
--- /dev/null
+++ b/Android.bp
@@ -0,0 +1,14 @@
+// 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.
+subdirs = ["googlemock", "googletest"]
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..41a41d0
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,17 @@
+#
+# 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.
+#
+
+include $(call all-subdir-makefiles)
diff --git a/README.version b/README.version
new file mode 100644
index 0000000..1ba0e51
--- /dev/null
+++ b/README.version
@@ -0,0 +1,4 @@
+URL: https://github.com/google/googletest
+Version: ff07a5de0e81580547f1685e101194ed1a4fcd56
+BugComponent: 119451
+Owners: danalbert, enh, android-janitors
diff --git a/googlemock/Android.bp b/googlemock/Android.bp
new file mode 100644
index 0000000..c17b733
--- /dev/null
+++ b/googlemock/Android.bp
@@ -0,0 +1,88 @@
+// 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.
+
+cc_defaults {
+    name: "gmock_flags",
+
+    local_include_dirs: ["include"],
+    export_include_dirs: ["include"],
+
+    cflags: ["-Wno-missing-field-initializers", "-Wno-unused-parameter"],
+}
+
+cc_defaults {
+    name: "gmock_ndk",
+    sdk_version: "9",
+    stl: "gnustl_static",
+    cppflags: ["-std=c++11"],
+}
+
+cc_defaults {
+    name: "gmock_defaults",
+    host_supported: true,
+    sanitize: {
+        never: true,
+    },
+    target: {
+        windows: {
+            enabled: true,
+        },
+    },
+}
+
+cc_library_static {
+    name: "libgmock_ndk",
+    defaults: ["gmock_ndk", "gmock_flags"],
+    srcs: ["src/gmock-all.cc"],
+    static_libs: ["libgtest_ndk_gnustl"],
+}
+
+cc_library_static {
+    name: "libgmock_main_ndk",
+    defaults: ["gmock_ndk", "gmock_flags"],
+    srcs: ["src/gmock_main.cc"],
+    static_libs: ["libgtest_ndk_gnustl"],
+}
+
+cc_library_static {
+    name: "libgmock",
+    defaults: ["gmock_defaults", "gmock_flags"],
+    srcs: ["src/gmock-all.cc"],
+    rtti: true,
+    static_libs: ["libgtest"],
+    vendor_available: true,
+}
+
+cc_library_static {
+    name: "libgmock_main",
+    defaults: ["gmock_defaults", "gmock_flags"],
+    srcs: ["src/gmock_main.cc"],
+    static_libs: ["libgtest"],
+    vendor_available: 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"],
+}
+
+// Tests are in the Android.mk. Run with external/googletest/run_tests.py.
diff --git a/googlemock/Android.mk b/googlemock/Android.mk
new file mode 100644
index 0000000..79969bd
--- /dev/null
+++ b/googlemock/Android.mk
@@ -0,0 +1,72 @@
+# 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.
+#
+#
+
+LOCAL_PATH := $(call my-dir)
+
+# Defines a test module.
+#
+# The upstream gmock 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): "libgmock_main" or empty.
+# $(4): Variant. Can be "_host", "_ndk", or empty.
+define gmock-unit-test
+    $(eval include $(CLEAR_VARS)) \
+    $(eval LOCAL_MODULE := $(1)$(4)) \
+    $(eval LOCAL_CPP_EXTENSION := .cc) \
+    $(eval LOCAL_SRC_FILES := test/$(strip $(1)).cc $(2)) \
+    $(eval LOCAL_C_INCLUDES := $(LOCAL_PATH)/include) \
+    $(eval LOCAL_C_INCLUDES += $(LOCAL_PATH)/../googletest) \
+    $(eval LOCAL_CPP_FEATURES := rtti) \
+    $(eval LOCAL_STATIC_LIBRARIES := $(if $(3),$(3)$(4)) libgmock$(4)) \
+    $(eval LOCAL_STATIC_LIBRARIES += libgtest$(4)) \
+    $(if $(findstring _ndk,$(4)),$(eval LOCAL_SDK_VERSION := 9)) \
+    $(eval LOCAL_NDK_STL_VARIANT := stlport_static) \
+    $(if $(findstring _host,$(4)),,\
+        $(eval LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_NATIVE_TESTS))) \
+    $(eval $(if $(findstring _host,$(4)), \
+        include $(BUILD_HOST_EXECUTABLE), \
+        include $(BUILD_EXECUTABLE)))
+endef
+
+# Create modules for each test in the suite.
+#
+# $(1): Variant. Can be "_host", "_ndk", or empty.
+define gmock-test-suite
+    $(eval $(call gmock-unit-test,gmock-actions_test,,libgmock_main,$(1))) \
+    $(eval $(call gmock-unit-test,gmock-cardinalities_test,,libgmock_main,$(1))) \
+    $(eval $(call gmock-unit-test,gmock-generated-actions_test,,libgmock_main,$(1))) \
+    $(eval $(call gmock-unit-test,gmock-generated-function-mockers_test,,libgmock_main,$(1))) \
+    $(eval $(call gmock-unit-test,gmock-generated-internal-utils_test,,libgmock_main,$(1))) \
+    $(eval $(call gmock-unit-test,gmock-generated-matchers_test,,libgmock_main,$(1))) \
+    $(eval $(call gmock-unit-test,gmock-internal-utils_test,,libgmock_main,$(1))) \
+    $(eval $(call gmock-unit-test,gmock-matchers_test,,libgmock_main,$(1))) \
+    $(eval $(call gmock-unit-test,gmock-more-actions_test,,libgmock_main,$(1))) \
+    $(eval $(call gmock-unit-test,gmock-nice-strict_test,,libgmock_main,$(1))) \
+    $(eval $(call gmock-unit-test,gmock-port_test,,libgmock_main,$(1))) \
+    $(eval $(call gmock-unit-test,gmock-spec-builders_test,,libgmock_main,$(1))) \
+    $(eval $(call gmock-unit-test,gmock_link_test,test/gmock_link2_test.cc,libgmock_main,$(1))) \
+    $(eval $(call gmock-unit-test,gmock_test,,libgmock_main,$(1)))
+endef
+
+# Test is disabled because Android doesn't build gmock with exceptions.
+# $(eval $(call gmock-unit-test,gmock_ex_test,,libgmock_main,$(1)))
+
+$(call gmock-test-suite,)
+$(call gmock-test-suite,_host)
diff --git a/googlemock/MODULE_LICENSE_BSD_LIKE b/googlemock/MODULE_LICENSE_BSD_LIKE
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/googlemock/MODULE_LICENSE_BSD_LIKE
diff --git a/googlemock/NOTICE b/googlemock/NOTICE
new file mode 120000
index 0000000..7a694c9
--- /dev/null
+++ b/googlemock/NOTICE
@@ -0,0 +1 @@
+LICENSE
\ No newline at end of file
diff --git a/googletest/Android.bp b/googletest/Android.bp
new file mode 100644
index 0000000..705c823
--- /dev/null
+++ b/googletest/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.
+
+cc_defaults {
+    name: "libgtest_defaults",
+    export_include_dirs: ["include"],
+}
+
+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.
+
+// stlport
+cc_library_static {
+    name: "libgtest_ndk_stlport",
+    defaults: ["libgtest_defaults"],
+    sdk_version: "9",
+    stl: "stlport_static",
+    srcs: ["src/gtest-all.cc"],
+}
+
+cc_library_static {
+    name: "libgtest_main_ndk_stlport",
+    defaults: ["libgtest_defaults"],
+    sdk_version: "9",
+    stl: "stlport_static",
+    srcs: ["src/gtest_main.cc"],
+}
+
+// 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"],
+}
+
+// gnustl
+cc_library_static {
+    name: "libgtest_ndk_gnustl",
+    defaults: ["libgtest_defaults"],
+    sdk_version: "9",
+    stl: "gnustl_static",
+    srcs: ["src/gtest-all.cc"],
+}
+
+cc_library_static {
+    name: "libgtest_main_ndk_gnustl",
+    defaults: ["libgtest_defaults"],
+    sdk_version: "9",
+    stl: "gnustl_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,
+    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,
+    clang: 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 {
+    name: "libgtest_prod",
+    defaults: ["libgtest_defaults", "libgtest_host_defaults"],
+    host_supported: true,
+    vendor_available: true,
+    export_include_dirs: ["include"],
+}
+
+// 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 0000000..9f4526b
--- /dev/null
+++ b/googletest/Android.mk
@@ -0,0 +1,187 @@
+#
+# 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, but is also how we define the tests for the platform.
+
+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.
+# $(4): Variant. Can be "_host", "_ndk", or empty.
+# $(5): NDK STL if $(4) is "_ndk", else 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)$(if $(findstring _ndk,$(4)),$(4))$(if $(5),_$(5))) \
+    $(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 := -Wno-unnamed-type-template-args) \
+    $(eval LOCAL_STATIC_LIBRARIES := \
+        $(if $(3),$(3)$(4)$(if $(5),_$(5))) libgtest$(4)$(if $(5),_$(5))) \
+    $(if $(findstring _ndk,$(4)),$(eval LOCAL_LDLIBS := -ldl)) \
+    $(if $(findstring _ndk,$(4)),$(eval LOCAL_SDK_VERSION := 9)) \
+    $(if $(findstring _ndk,$(4)),$(eval LOCAL_NDK_STL_VARIANT := $(5)_static)) \
+    $(if $(findstring _host,$(4)),,\
+        $(eval LOCAL_MODULE_PATH := $(TARGET_OUT_DATA_NATIVE_TESTS))) \
+    $(eval $(if $(findstring _host,$(4)), \
+        include $(BUILD_HOST_EXECUTABLE), \
+        include $(BUILD_EXECUTABLE)))
+endef
+
+# Create modules for each test in the suite.
+#
+# $(1): Variant. Can be "_host", "_ndk", or empty.
+# $(2): NDK STL if $(1) is "_ndk", else empty.
+#
+# The NDK variant of gtest-death-test_test is disabled because we don't have
+# pthread_atfork on android-9.
+define gtest-test-suite
+    $(if $(findstring _ndk,$(1)),, \
+        $(eval $(call gtest-unit-test, \
+            gtest-death-test_test,,libgtest_main,$(1),$(2)))) \
+    $(eval $(call gtest-unit-test,gtest_environment_test,,,$(1),$(2))) \
+    $(eval $(call gtest-unit-test,gtest-filepath_test,, \
+        libgtest_main,$(1),$(2))) \
+    $(eval $(call gtest-unit-test,gtest-linked_ptr_test,, \
+        libgtest_main,$(1),$(2))) \
+    $(eval $(call gtest-unit-test,gtest-listener_test,, \
+        libgtest_main,$(1),$(2))) \
+    $(eval $(call gtest-unit-test,gtest_main_unittest,, \
+        libgtest_main,$(1),$(2))) \
+    $(eval $(call gtest-unit-test,gtest-message_test,, \
+        libgtest_main,$(1),$(2))) \
+    $(eval $(call gtest-unit-test,gtest_no_test_unittest,,,$(1),$(2))) \
+    $(eval $(call gtest-unit-test,gtest-options_test,, \
+        libgtest_main,$(1),$(2))) \
+    $(eval $(call gtest-unit-test,gtest-param-test_test, \
+        test/gtest-param-test2_test.cc,,$(1),$(2))) \
+    $(eval $(call gtest-unit-test,gtest-port_test,,libgtest_main,$(1),$(2))) \
+    $(eval $(call gtest-unit-test,gtest_pred_impl_unittest,, \
+        libgtest_main,$(1),$(2))) \
+    $(eval $(call gtest-unit-test,gtest_premature_exit_test,,,$(1),$(2))) \
+    $(eval $(call gtest-unit-test,gtest_prod_test,test/production.cc, \
+        libgtest_main,$(1),$(2))) \
+    $(eval $(call gtest-unit-test,gtest_repeat_test,,,$(1),$(2))) \
+    $(eval $(call gtest-unit-test,gtest_sole_header_test,, \
+        libgtest_main,$(1),$(2))) \
+    $(eval $(call gtest-unit-test,gtest_stress_test,,,$(1),$(2))) \
+    $(eval $(call gtest-unit-test,gtest-test-part_test,, \
+        libgtest_main,$(1),$(2))) \
+    $(eval $(call gtest-unit-test, \
+        gtest-typed-test_test,test/gtest-typed-test2_test.cc, \
+            libgtest_main,$(1),$(2))) \
+    $(eval $(call gtest-unit-test,gtest_unittest,,libgtest_main,$(1),$(2))) \
+    $(eval $(call gtest-unit-test,gtest-unittest-api_test,,,$(1),$(2)))
+endef
+
+# Test is disabled because Android doesn't build gtest with exceptions.
+# $(eval $(call gtest-unit-test,gtest_throw_on_failure_ex_test,,,$(1),$(2)))
+
+# Test is disabled until https://github.com/google/googletest/pull/728 lands.
+# $(eval $(call gtest-unit-test,gtest-printers_test,,libgtest_main,$(1),$(2)))
+
+# If we're being invoked from ndk-build, we'll have NDK_ROOT defined.
+ifdef NDK_ROOT
+
+include $(CLEAR_VARS)
+LOCAL_MODULE := libgtest
+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_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_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_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_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_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)
+
+else
+
+# Tests for the platform built NDK gtest.
+$(call gtest-test-suite,_ndk,stlport)
+$(call gtest-test-suite,_ndk,gnustl)
+$(call gtest-test-suite,_ndk,c++)
+
+# Tests for the host gtest.
+ifeq (,$(TARGET_BUILD_APPS))
+$(call gtest-test-suite,_host,)
+endif
+
+endif
+
+# Tests for the platform device gtest and for use in the NDK itself.
+$(call gtest-test-suite,)
diff --git a/googletest/MODULE_LICENSE_BSD_LIKE b/googletest/MODULE_LICENSE_BSD_LIKE
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/googletest/MODULE_LICENSE_BSD_LIKE
diff --git a/googletest/NOTICE b/googletest/NOTICE
new file mode 120000
index 0000000..7a694c9
--- /dev/null
+++ b/googletest/NOTICE
@@ -0,0 +1 @@
+LICENSE
\ No newline at end of file
diff --git a/googletest/include/gtest/internal/custom/gtest.h b/googletest/include/gtest/internal/custom/gtest.h
index a7a1c0b..b2fd4ae 100644
--- a/googletest/include/gtest/internal/custom/gtest.h
+++ b/googletest/include/gtest/internal/custom/gtest.h
@@ -42,4 +42,23 @@
 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
 #define GTEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
 
+#define GTEST_CUSTOM_TEMPDIR_FUNCTION_ GetAndroidTempDir
+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_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_
diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc
index d80bd80..6f92424 100644
--- a/googletest/src/gtest-port.cc
+++ b/googletest/src/gtest-port.cc
@@ -952,24 +952,10 @@
 # else
     // There's no guarantee that a test has write access to the current
     // directory, so we create the temporary file in the /tmp directory
-    // instead. We use /tmp on most systems, and /sdcard on Android.
-    // That's because Android doesn't have /tmp.
+    // instead.
 #  if GTEST_OS_LINUX_ANDROID
-    // Note: Android applications are expected to call the framework's
-    // Context.getExternalStorageDirectory() method through JNI to get
-    // the location of the world-writable SD Card directory. However,
-    // this requires a Context handle, which cannot be retrieved
-    // globally from native code. Doing so also precludes running the
-    // code as part of a regular standalone executable, which doesn't
-    // run in a Dalvik process (e.g. when running it through 'adb shell').
-    //
-    // The location /sdcard is directly accessible from native code
-    // and is the only location (unofficially) supported by the Android
-    // team. It's generally a symlink to the real SD Card mount point
-    // which can be /mnt/sdcard, /mnt/sdcard0, /system/media/sdcard, or
-    // other OEM-customized locations. Never rely on these, and always
-    // use /sdcard.
-    char name_template[] = "/sdcard/gtest_captured_stream.XXXXXX";
+    ::std::string name_template_buf = TempDir() + "gtest_captured_stream.XXXXXX";
+    char* name_template = &name_template_buf[0];
 #  else
     char name_template[] = "/tmp/captured_stream.XXXXXX";
 #  endif  // GTEST_OS_LINUX_ANDROID
diff --git a/googletest/test/gtest-options_test.cc b/googletest/test/gtest-options_test.cc
index 5586dc3..bab4360 100644
--- a/googletest/test/gtest-options_test.cc
+++ b/googletest/test/gtest-options_test.cc
@@ -118,7 +118,13 @@
       exe_str == "gtest-options_test" ||
       exe_str == "gtest_all_test" ||
       exe_str == "lt-gtest_all_test" ||
-      exe_str == "gtest_dll_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 0000000..76f2e94
--- /dev/null
+++ b/run_tests.py
@@ -0,0 +1,97 @@
+#!/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'], 'bin')
+    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 = []
+    logger().debug('Scanning %s for tests', test_location)
+    for test in os.listdir(test_location):
+        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_location, test)]
+            if call(cmd) != 0:
+                failures.append(test)
+        else:
+            device_dir = test_location.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()