From a6180a64798119f22e7349cedb80ddf38ce94844 Mon Sep 17 00:00:00 2001 From: Geoff Brown Date: Thu, 11 Apr 2019 01:25:02 +0000 Subject: [PATCH] Bug 1318091 - Support env override of gtest minidump location; r=Ehsan Desktop gtest creates minidumps in the current working directory. That is problematic on Android, since the test app's cwd may not be writable, or may not be readable by the test harness. This patch allows the test harness to specify an alternate minidump path with environment variable MOZ_GTEST_MINIDUMPS_PATH. Differential Revision: https://phabricator.services.mozilla.com/D26833 --HG-- extra : moz-landing-system : lando --- testing/gtest/mozilla/GTestRunner.cpp | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/testing/gtest/mozilla/GTestRunner.cpp b/testing/gtest/mozilla/GTestRunner.cpp index 45b92e313ae9..51a6d3877fc8 100644 --- a/testing/gtest/mozilla/GTestRunner.cpp +++ b/testing/gtest/mozilla/GTestRunner.cpp @@ -121,16 +121,25 @@ int RunGTestFunc(int* argc, char** argv) { // C++ unittests crashreporter = do_GetService("@mozilla.org/toolkit/crash-reporter;1"); if (crashreporter) { - std::cerr << "Setting up crash reporting" << std::endl; - - nsCOMPtr dirsvc = - do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID); - nsCOMPtr cwd; - nsresult rv = dirsvc->Get(NS_OS_CURRENT_WORKING_DIR, NS_GET_IID(nsIFile), - getter_AddRefs(cwd)); - MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv)); + printf_stderr("Setting up crash reporting\n"); + char* path = PR_GetEnv("MOZ_GTEST_MINIDUMPS_PATH"); + nsCOMPtr file; + if (path) { + nsresult rv = NS_NewLocalFile(NS_ConvertUTF8toUTF16(path), true, + getter_AddRefs(file)); + if (NS_FAILED(rv)) { + printf_stderr("Ignoring invalid MOZ_GTEST_MINIDUMPS_PATH\n"); + } + } + if (!file) { + nsCOMPtr dirsvc = + do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID); + nsresult rv = dirsvc->Get(NS_OS_CURRENT_WORKING_DIR, NS_GET_IID(nsIFile), + getter_AddRefs(file)); + MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv)); + } crashreporter->SetEnabled(true); - crashreporter->SetMinidumpPath(cwd); + crashreporter->SetMinidumpPath(file); } }