bug 816963 - Enable crash reporting in places C++ unit tests. r=mak
authorTed Mielczarek <ted@mielczarek.org>
Fri, 30 Nov 2012 14:26:19 -0500
changeset 114641 8fc14285206061da179a6201cb21d008f7005929
parent 114640 04ebcfd56e6eb3290798382afc8da680a2984988
child 114642 b4f18037333507cf44c5bdbe1b77ff45f8d4a6bf
push id23926
push userryanvm@gmail.com
push dateSat, 01 Dec 2012 15:27:30 +0000
treeherdermozilla-central@ecdf0e332f17 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmak
bugs816963
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 816963 - Enable crash reporting in places C++ unit tests. r=mak
toolkit/components/places/tests/cpp/places_test_harness_tail.h
--- a/toolkit/components/places/tests/cpp/places_test_harness_tail.h
+++ b/toolkit/components/places/tests/cpp/places_test_harness_tail.h
@@ -1,16 +1,19 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsWidgetsCID.h"
 #include "nsIComponentRegistrar.h"
+#ifdef MOZ_CRASHREPORTER
+#include "nsICrashReporter.h"
+#endif
 
 #ifndef TEST_NAME
 #error "Must #define TEST_NAME before including places_test_harness_tail.h"
 #endif
 
 #ifndef TEST_FILE
 #error "Must #define TEST_FILE before include places_test_harness_tail.h"
 #endif
@@ -86,16 +89,42 @@ main(int aArgc,
     return -1;
   // Initialize a profile folder to ensure a clean shutdown.
   nsCOMPtr<nsIFile> profile = xpcom.GetProfileDirectory();
   if (!profile) {
     fail("Couldn't get the profile directory.");
     return -1;
   }
 
+#ifdef MOZ_CRASHREPORTER
+    char* enabled = PR_GetEnv("MOZ_CRASHREPORTER");
+    if (enabled && !strcmp(enabled, "1")) {
+      // bug 787458: move this to an even-more-common location to use in all
+      // C++ unittests
+      nsCOMPtr<nsICrashReporter> crashreporter =
+        do_GetService("@mozilla.org/toolkit/crash-reporter;1");
+      if (crashreporter) {
+        fprintf(stderr, "Setting up crash reporting\n");
+
+        nsCOMPtr<nsIProperties> dirsvc =
+          do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID);
+        if (!dirsvc)
+          NS_RUNTIMEABORT("Couldn't get directory service");
+        nsCOMPtr<nsIFile> cwd;
+        nsresult rv = dirsvc->Get(NS_OS_CURRENT_WORKING_DIR,
+                                  NS_GET_IID(nsIFile),
+                                  getter_AddRefs(cwd));
+        if (NS_FAILED(rv))
+          NS_RUNTIMEABORT("Couldn't get CWD");
+        crashreporter->SetEnabled(true);
+        crashreporter->SetMinidumpPath(cwd);
+      }
+    }
+#endif
+
   nsRefPtr<WaitForConnectionClosed> spinClose = new WaitForConnectionClosed();
 
   // Tinderboxes are constantly on idle.  Since idle tasks can interact with
   // tests, causing random failures, disable the idle service.
   disable_idle_service();
 
   do_test_pending();
   run_next_test();