Bug 1237447 - Disable the crashreporter when crashing intentionally in TestPLDHash. r=njn draft
authorChris Manchester <cmanchester@mozilla.com>
Wed, 06 Jan 2016 19:49:22 -0800
changeset 319541 47fb60978ebebf8af1fcddb2bef11a27fb280a32
parent 319338 1ec3a3ff68f2d1a54e6ed33e926c28fee286bdf1
child 512606 ea543a2a44f8e6d529e9712de993a55e6b659d8d
push id9046
push usercmanchester@mozilla.com
push dateThu, 07 Jan 2016 03:49:29 +0000
reviewersnjn
bugs1237447
milestone46.0a1
Bug 1237447 - Disable the crashreporter when crashing intentionally in TestPLDHash. r=njn
xpcom/tests/gtest/TestPLDHash.cpp
--- a/xpcom/tests/gtest/TestPLDHash.cpp
+++ b/xpcom/tests/gtest/TestPLDHash.cpp
@@ -14,16 +14,20 @@
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 
 // This global variable is defined in toolkit/xre/nsSigHandlers.cpp.
 extern unsigned int _gdb_sleep_duration;
 #endif
 
+#ifdef MOZ_CRASHREPORTER
+#include "nsICrashReporter.h"
+#endif
+
 // We can test that certain operations cause expected aborts by forking
 // and then checking that the child aborted in the expected way (i.e. via
 // MOZ_CRASH). We skip this for the following configurations.
 // - On Windows, because it doesn't have fork().
 // - On non-DEBUG builds, because the crashes cause the crash reporter to pop
 //   up when running this test locally, which is surprising and annoying.
 // - On ASAN builds, because ASAN alters the way a MOZ_CRASHing process
 //   terminates, which makes it harder to test if the right thing has occurred.
@@ -35,16 +39,25 @@ TestCrashyOperation(void (*aCrashyOperat
   // to be attached.
   unsigned int old_gdb_sleep_duration = _gdb_sleep_duration;
   _gdb_sleep_duration = 0;
 
   int pid = fork();
   ASSERT_NE(pid, -1);
 
   if (pid == 0) {
+    // Disable the crashreporter -- writing a crash dump in the child will
+    // prevent the parent from writing a subsequent dump. Crashes here are
+    // expected, so we don't want their stacks to show up in the log anyway.
+#ifdef MOZ_CRASHREPORTER
+    nsCOMPtr<nsICrashReporter> crashreporter =
+      do_GetService("@mozilla.org/toolkit/crash-reporter;1");
+    crashreporter->SetEnabled(false);
+#endif
+
     // Child: perform the crashy operation.
     aCrashyOperation();
     fprintf(stderr, "TestCrashyOperation: didn't crash?!\n");
     ASSERT_TRUE(false);   // shouldn't reach here
   }
 
   // Parent: check that child crashed as expected.
   int status;