Commit 37ad5b38 authored by Vlad Tsyrklevich's avatar Vlad Tsyrklevich Committed by Commit Bot

GWP-ASan: Add android support to crash_handler unittests

On Android crashpad launches differently than on desktop platforms. This
requires refactoring the crash_handler unittests to support launching
via a specially built executable that we package with the unit tests
just for the Android build. This approach only works if the
enable_gwp_asan buildflag is set to true because otherwise
libchrome_crashpad_handler.so wont compile in the GWP-ASan crash handler
hook.

Bug: 973167
Change-Id: I40888e0d7a81961e22f808ab15d8b0c2a83b4494
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1730031
Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
Auto-Submit: Vlad Tsyrklevich <vtsyrklevich@chromium.org>
Reviewed-by: default avatarVitaly Buka <vitalybuka@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683010}
parent 2c740704
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import("//components/gwp_asan/buildflags/buildflags.gni")
import("//third_party/protobuf/proto_library.gni") import("//third_party/protobuf/proto_library.gni")
static_library("crash_handler") { static_library("crash_handler") {
...@@ -35,8 +36,8 @@ source_set("unit_tests") { ...@@ -35,8 +36,8 @@ source_set("unit_tests") {
testonly = true testonly = true
sources = [ sources = [
"crash_analyzer_unittest.cc", "crash_analyzer_unittest.cc",
"crash_handler_unittest.cc",
] ]
deps = [ deps = [
":crash_handler", ":crash_handler",
":crash_proto", ":crash_proto",
...@@ -46,13 +47,28 @@ source_set("unit_tests") { ...@@ -46,13 +47,28 @@ source_set("unit_tests") {
"//testing/gmock", "//testing/gmock",
"//testing/gtest", "//testing/gtest",
"//third_party/crashpad/crashpad/client", "//third_party/crashpad/crashpad/client",
"//third_party/crashpad/crashpad/handler",
"//third_party/crashpad/crashpad/minidump",
"//third_party/crashpad/crashpad/snapshot", "//third_party/crashpad/crashpad/snapshot",
"//third_party/crashpad/crashpad/snapshot:test_support", "//third_party/crashpad/crashpad/snapshot:test_support",
"//third_party/crashpad/crashpad/test", "//third_party/crashpad/crashpad/test",
"//third_party/crashpad/crashpad/tools:tool_support",
"//third_party/crashpad/crashpad/util", "//third_party/crashpad/crashpad/util",
"//third_party/protobuf:protobuf_lite", "//third_party/protobuf:protobuf_lite",
] ]
if (!is_android || enable_gwp_asan) {
sources += [ "crash_handler_unittest.cc" ]
deps += [
"//third_party/crashpad/crashpad/handler",
"//third_party/crashpad/crashpad/minidump",
"//third_party/crashpad/crashpad/tools:tool_support",
]
if (is_android) {
metadata = {
shared_libraries = [ "$root_out_dir/libchrome_crashpad_handler.so" ]
}
deps += [
"//components/crash/content/app:chrome_crashpad_handler_named_as_so",
]
}
}
} }
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "base/path_service.h"
#include "base/process/process_metrics.h" #include "base/process/process_metrics.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
#include "base/test/gtest_util.h" #include "base/test/gtest_util.h"
...@@ -42,6 +43,7 @@ constexpr size_t kAllocationSize = 902; ...@@ -42,6 +43,7 @@ constexpr size_t kAllocationSize = 902;
constexpr int kSuccess = 0; constexpr int kSuccess = 0;
constexpr size_t kTotalPages = AllocatorState::kMaxSlots; constexpr size_t kTotalPages = AllocatorState::kMaxSlots;
#if !defined(OS_ANDROID)
int HandlerMainAdaptor(int argc, char* argv[]) { int HandlerMainAdaptor(int argc, char* argv[]) {
crashpad::UserStreamDataSources user_stream_data_sources; crashpad::UserStreamDataSources user_stream_data_sources;
user_stream_data_sources.push_back( user_stream_data_sources.push_back(
...@@ -74,6 +76,7 @@ MULTIPROCESS_TEST_MAIN(CrashpadHandler) { ...@@ -74,6 +76,7 @@ MULTIPROCESS_TEST_MAIN(CrashpadHandler) {
return 0; return 0;
} }
#endif // !defined(OS_ANDROID)
// Child process that launches the crashpad handler and then crashes. // Child process that launches the crashpad handler and then crashes.
MULTIPROCESS_TEST_MAIN(CrashingProcess) { MULTIPROCESS_TEST_MAIN(CrashingProcess) {
...@@ -114,9 +117,10 @@ MULTIPROCESS_TEST_MAIN(CrashingProcess) { ...@@ -114,9 +117,10 @@ MULTIPROCESS_TEST_MAIN(CrashingProcess) {
base::FilePath metrics_dir(FILE_PATH_LITERAL("")); base::FilePath metrics_dir(FILE_PATH_LITERAL(""));
std::map<std::string, std::string> annotations; std::map<std::string, std::string> annotations;
std::vector<std::string> arguments; std::vector<std::string> arguments;
arguments.push_back("--test-child-process=CrashpadHandler");
crashpad::CrashpadClient* client = new crashpad::CrashpadClient(); crashpad::CrashpadClient* client = new crashpad::CrashpadClient();
#if !defined(OS_ANDROID)
arguments.push_back("--test-child-process=CrashpadHandler");
bool handler = client->StartHandler(/* handler */ cmd_line->GetProgram(), bool handler = client->StartHandler(/* handler */ cmd_line->GetProgram(),
/* database */ directory, /* database */ directory,
/* metrics_dir */ metrics_dir, /* metrics_dir */ metrics_dir,
...@@ -125,6 +129,27 @@ MULTIPROCESS_TEST_MAIN(CrashingProcess) { ...@@ -125,6 +129,27 @@ MULTIPROCESS_TEST_MAIN(CrashingProcess) {
/* arguments */ arguments, /* arguments */ arguments,
/* restartable */ false, /* restartable */ false,
/* asynchronous_start */ false); /* asynchronous_start */ false);
#else
// TODO: Once the minSdkVersion is >= Q define a CrashpadHandlerMain() and
// use the /system/bin/linker approach instead of using
// libchrome_crashpad_handler.so
base::FilePath modules;
if (!base::PathService::Get(base::DIR_MODULE, &modules)) {
LOG(ERROR) << "Failed to read DIR_MODULE";
return kSuccess;
}
base::FilePath executable_path =
modules.AppendASCII("libchrome_crashpad_handler.so");
std::unique_ptr<base::Environment> env(base::Environment::Create());
std::string library_path;
env->GetVar("LD_LIBRARY_PATH", &library_path);
env->SetVar("LD_LIBRARY_PATH", library_path + ":" + modules.value());
bool handler = client->StartHandlerAtCrash(
executable_path, directory, metrics_dir, "", annotations, arguments);
#endif
if (!handler) { if (!handler) {
LOG(ERROR) << "Crash handler failed to launch"; LOG(ERROR) << "Crash handler failed to launch";
return kSuccess; return kSuccess;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment