From 95298b0af87b4eb981345598076b8a19b1991fa2 Mon Sep 17 00:00:00 2001 From: Trevor Radcliffe Date: Wed, 20 Apr 2022 14:42:36 +0000 Subject: Changes to gmock to support isolated as default gmock bp module needed to be changed in order to support the change to using isolated as the default for cc_tests Bug: 178498003 Test: m nothing Change-Id: I44e4c85f5fb033f821c72cda37b09ac592fe0c27 --- googlemock/Android.bp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/googlemock/Android.bp b/googlemock/Android.bp index 40473d43..e3f779ca 100644 --- a/googlemock/Android.bp +++ b/googlemock/Android.bp @@ -87,6 +87,8 @@ cc_library_static { rtti: true, static_libs: ["libgtest"], vendor_available: true, + product_available: true, + native_bridge_supported: true, } cc_library_static { @@ -98,6 +100,8 @@ cc_library_static { srcs: ["src/gmock_main.cc"], static_libs: ["libgtest"], vendor_available: true, + product_available: true, + native_bridge_supported: true, } // Deprecated: use libgmock instead -- cgit v1.2.3 From 18a21d8f68731363262d007cbe88183183986d52 Mon Sep 17 00:00:00 2001 From: Florian Mayer Date: Thu, 2 Jun 2022 22:36:37 +0000 Subject: Build gmock with exception tables. Bug: 233683072 Change-Id: Ic208fc03670a8c9b4ceb7dc805d45cd25e69be8c --- googlemock/Android.bp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/googlemock/Android.bp b/googlemock/Android.bp index e3f779ca..77cf6501 100644 --- a/googlemock/Android.bp +++ b/googlemock/Android.bp @@ -34,6 +34,9 @@ cc_defaults { "-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", ], } -- cgit v1.2.3 From 68218f1fd8047664df8d2e2c54497e41bf12b537 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kosi=C5=84ski?= Date: Tue, 28 Feb 2023 06:09:31 +0000 Subject: Fix device death tests. The death message is usually reported using LOG(FATAL) or CHECK(). In device tests, these messages are reported to logd instead of standard error and cannot be seen by GTest. Add a custom test init function which adds a logger that repeats the message to stderr if we are in a death test child process. Bug: 270535879 Test: presubmit, ran the test from the bug Change-Id: Ibd23031260d3e75f634af6d434bbf010b277803b --- googletest/include/gtest/internal/custom/gtest.h | 50 ++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/googletest/include/gtest/internal/custom/gtest.h b/googletest/include/gtest/internal/custom/gtest.h index 67ce67f1..3d855613 100644 --- a/googletest/include/gtest/internal/custom/gtest.h +++ b/googletest/include/gtest/internal/custom/gtest.h @@ -35,13 +35,21 @@ #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ #if GTEST_OS_LINUX_ANDROID -# define GTEST_CUSTOM_TEMPDIR_FUNCTION_ GetAndroidTempDir -# include +#include +#include + +#define GTEST_CUSTOM_TEMPDIR_FUNCTION_ GetAndroidTempDir +#define GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(argc, argv) \ + internal::InitGoogleTestImpl(argc, argv); \ + SetAndroidTestLogger() + 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/"; + 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... @@ -54,6 +62,40 @@ static inline std::string GetAndroidTempDir() { } return result; } -#endif //GTEST_OS_LINUX_ANDROID + +static inline void SetAndroidTestLogger() { + // By default, Android log messages are only written to the log buffer, where + // GTest cannot see them. This breaks death tests, which need to check the + // crash message to ensure that the process died for the expected reason. + // To fix this, send log messages to both logd and stderr if we are in a death + // test child process. + struct LogMessage; + using LoggerFunction = void (*)(const LogMessage*); + using SetLoggerFunction = void (*)(LoggerFunction logger); + + static void* liblog = dlopen("liblog.so", RTLD_NOW); + if (liblog == nullptr) { + return; + } + + static SetLoggerFunction set_logger = reinterpret_cast( + dlsym(liblog, "__android_log_set_logger")); + static LoggerFunction logd_logger = reinterpret_cast( + dlsym(liblog, "__android_log_logd_logger")); + static LoggerFunction stderr_logger = reinterpret_cast( + dlsym(liblog, "__android_log_stderr_logger")); + if (set_logger == nullptr || logd_logger == nullptr || + stderr_logger == nullptr) { + return; + } + + set_logger([](const LogMessage* message) { + logd_logger(message); + if (::testing::internal::InDeathTestChild()) { + stderr_logger(message); + } + }); +} +#endif // GTEST_OS_LINUX_ANDROID #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ -- cgit v1.2.3 From c4ccb3b18f191b96a401465777ebfd224705b26e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kosi=C5=84ski?= Date: Fri, 3 Mar 2023 04:00:26 +0000 Subject: Revert "Fix device death tests." This reverts commit 68218f1fd8047664df8d2e2c54497e41bf12b537. Reason for revert: interferes with apexd_test Bug: 271504595 Change-Id: I6f0bbd97f790a50acee12e69af8b439f89c05ac1 --- googletest/include/gtest/internal/custom/gtest.h | 50 ++---------------------- 1 file changed, 4 insertions(+), 46 deletions(-) diff --git a/googletest/include/gtest/internal/custom/gtest.h b/googletest/include/gtest/internal/custom/gtest.h index 3d855613..67ce67f1 100644 --- a/googletest/include/gtest/internal/custom/gtest.h +++ b/googletest/include/gtest/internal/custom/gtest.h @@ -35,21 +35,13 @@ #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ #if GTEST_OS_LINUX_ANDROID -#include -#include - -#define GTEST_CUSTOM_TEMPDIR_FUNCTION_ GetAndroidTempDir -#define GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(argc, argv) \ - internal::InitGoogleTestImpl(argc, argv); \ - SetAndroidTestLogger() - +# define GTEST_CUSTOM_TEMPDIR_FUNCTION_ GetAndroidTempDir +# include 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/"; - } + 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... @@ -62,40 +54,6 @@ static inline std::string GetAndroidTempDir() { } return result; } - -static inline void SetAndroidTestLogger() { - // By default, Android log messages are only written to the log buffer, where - // GTest cannot see them. This breaks death tests, which need to check the - // crash message to ensure that the process died for the expected reason. - // To fix this, send log messages to both logd and stderr if we are in a death - // test child process. - struct LogMessage; - using LoggerFunction = void (*)(const LogMessage*); - using SetLoggerFunction = void (*)(LoggerFunction logger); - - static void* liblog = dlopen("liblog.so", RTLD_NOW); - if (liblog == nullptr) { - return; - } - - static SetLoggerFunction set_logger = reinterpret_cast( - dlsym(liblog, "__android_log_set_logger")); - static LoggerFunction logd_logger = reinterpret_cast( - dlsym(liblog, "__android_log_logd_logger")); - static LoggerFunction stderr_logger = reinterpret_cast( - dlsym(liblog, "__android_log_stderr_logger")); - if (set_logger == nullptr || logd_logger == nullptr || - stderr_logger == nullptr) { - return; - } - - set_logger([](const LogMessage* message) { - logd_logger(message); - if (::testing::internal::InDeathTestChild()) { - stderr_logger(message); - } - }); -} -#endif // GTEST_OS_LINUX_ANDROID +#endif //GTEST_OS_LINUX_ANDROID #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ -- cgit v1.2.3 From 479381ccf23eb868b4793f196ff153e00f105e39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Kosi=C5=84ski?= Date: Mon, 6 Mar 2023 22:50:36 +0000 Subject: Revert "Revert "Fix device death tests."" This reverts commit c4ccb3b18f191b96a401465777ebfd224705b26e. Reason for revert: The tests broken by this change should be fixed now. Bug: 270535879 Test: presubmit Change-Id: Icc629db4eeb7b176a3495c2b3f50c2bc96374cba --- googletest/include/gtest/internal/custom/gtest.h | 50 ++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/googletest/include/gtest/internal/custom/gtest.h b/googletest/include/gtest/internal/custom/gtest.h index 67ce67f1..3d855613 100644 --- a/googletest/include/gtest/internal/custom/gtest.h +++ b/googletest/include/gtest/internal/custom/gtest.h @@ -35,13 +35,21 @@ #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ #if GTEST_OS_LINUX_ANDROID -# define GTEST_CUSTOM_TEMPDIR_FUNCTION_ GetAndroidTempDir -# include +#include +#include + +#define GTEST_CUSTOM_TEMPDIR_FUNCTION_ GetAndroidTempDir +#define GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(argc, argv) \ + internal::InitGoogleTestImpl(argc, argv); \ + SetAndroidTestLogger() + 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/"; + 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... @@ -54,6 +62,40 @@ static inline std::string GetAndroidTempDir() { } return result; } -#endif //GTEST_OS_LINUX_ANDROID + +static inline void SetAndroidTestLogger() { + // By default, Android log messages are only written to the log buffer, where + // GTest cannot see them. This breaks death tests, which need to check the + // crash message to ensure that the process died for the expected reason. + // To fix this, send log messages to both logd and stderr if we are in a death + // test child process. + struct LogMessage; + using LoggerFunction = void (*)(const LogMessage*); + using SetLoggerFunction = void (*)(LoggerFunction logger); + + static void* liblog = dlopen("liblog.so", RTLD_NOW); + if (liblog == nullptr) { + return; + } + + static SetLoggerFunction set_logger = reinterpret_cast( + dlsym(liblog, "__android_log_set_logger")); + static LoggerFunction logd_logger = reinterpret_cast( + dlsym(liblog, "__android_log_logd_logger")); + static LoggerFunction stderr_logger = reinterpret_cast( + dlsym(liblog, "__android_log_stderr_logger")); + if (set_logger == nullptr || logd_logger == nullptr || + stderr_logger == nullptr) { + return; + } + + set_logger([](const LogMessage* message) { + logd_logger(message); + if (::testing::internal::InDeathTestChild()) { + stderr_logger(message); + } + }); +} +#endif // GTEST_OS_LINUX_ANDROID #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ -- cgit v1.2.3 From 42795cf170b92d3e9d7f9d8bbb70a24e097e11cc Mon Sep 17 00:00:00 2001 From: Diego Vela Date: Tue, 7 Mar 2023 18:12:33 +0000 Subject: Revert "Revert "Revert "Fix device death tests.""" This reverts commit 479381ccf23eb868b4793f196ff153e00f105e39. Reason for revert: Causing test failures. https://android-build.googleplex.com/builds/tests/view?invocationId=I43600010138010586&testResultId=TR77428536100414300 Bug: 272089599 Change-Id: I6822f857606fa6c82452580747cd77aa0f36da40 --- googletest/include/gtest/internal/custom/gtest.h | 50 ++---------------------- 1 file changed, 4 insertions(+), 46 deletions(-) diff --git a/googletest/include/gtest/internal/custom/gtest.h b/googletest/include/gtest/internal/custom/gtest.h index 3d855613..67ce67f1 100644 --- a/googletest/include/gtest/internal/custom/gtest.h +++ b/googletest/include/gtest/internal/custom/gtest.h @@ -35,21 +35,13 @@ #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ #if GTEST_OS_LINUX_ANDROID -#include -#include - -#define GTEST_CUSTOM_TEMPDIR_FUNCTION_ GetAndroidTempDir -#define GTEST_CUSTOM_INIT_GOOGLE_TEST_FUNCTION_(argc, argv) \ - internal::InitGoogleTestImpl(argc, argv); \ - SetAndroidTestLogger() - +# define GTEST_CUSTOM_TEMPDIR_FUNCTION_ GetAndroidTempDir +# include 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/"; - } + 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... @@ -62,40 +54,6 @@ static inline std::string GetAndroidTempDir() { } return result; } - -static inline void SetAndroidTestLogger() { - // By default, Android log messages are only written to the log buffer, where - // GTest cannot see them. This breaks death tests, which need to check the - // crash message to ensure that the process died for the expected reason. - // To fix this, send log messages to both logd and stderr if we are in a death - // test child process. - struct LogMessage; - using LoggerFunction = void (*)(const LogMessage*); - using SetLoggerFunction = void (*)(LoggerFunction logger); - - static void* liblog = dlopen("liblog.so", RTLD_NOW); - if (liblog == nullptr) { - return; - } - - static SetLoggerFunction set_logger = reinterpret_cast( - dlsym(liblog, "__android_log_set_logger")); - static LoggerFunction logd_logger = reinterpret_cast( - dlsym(liblog, "__android_log_logd_logger")); - static LoggerFunction stderr_logger = reinterpret_cast( - dlsym(liblog, "__android_log_stderr_logger")); - if (set_logger == nullptr || logd_logger == nullptr || - stderr_logger == nullptr) { - return; - } - - set_logger([](const LogMessage* message) { - logd_logger(message); - if (::testing::internal::InDeathTestChild()) { - stderr_logger(message); - } - }); -} -#endif // GTEST_OS_LINUX_ANDROID +#endif //GTEST_OS_LINUX_ANDROID #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ -- cgit v1.2.3