Bug 1798711 - Remove duplication of DisableCrashReporter on gtest r=ahal

Differential Revision: https://phabricator.services.mozilla.com/D162972
This commit is contained in:
Alexandre Lissy 2022-11-30 14:41:42 +00:00
parent 7c1384de1c
commit 5d0257721a
11 changed files with 124 additions and 164 deletions

View File

@ -7,11 +7,11 @@
#include "mozilla/SpinEventLoopUntil.h" #include "mozilla/SpinEventLoopUntil.h"
#include "mozilla/ipc/AsyncBlockers.h" #include "mozilla/ipc/AsyncBlockers.h"
#include "mozilla/gtest/MozHelpers.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsITimer.h" #include "nsITimer.h"
#include "nsINamed.h" #include "nsINamed.h"
#include "TestUtils.h"
using namespace mozilla; using namespace mozilla;
using namespace mozilla::ipc; using namespace mozilla::ipc;
@ -19,27 +19,19 @@ using namespace mozilla::ipc;
#define PROCESS_EVENTS_UNTIL(_done) \ #define PROCESS_EVENTS_UNTIL(_done) \
SpinEventLoopUntil("TestAsyncBlockers"_ns, [&]() { return _done; }); SpinEventLoopUntil("TestAsyncBlockers"_ns, [&]() { return _done; });
#if defined(XP_UNIX)
// This global variable is defined in toolkit/xre/nsSigHandlers.cpp.
extern unsigned int _gdb_sleep_duration;
#endif // defined(XP_UNIX)
class TestAsyncBlockers : public ::testing::Test { class TestAsyncBlockers : public ::testing::Test {
protected: protected:
void SetUp() override { void SetUp() override {
#if defined(XP_UNIX) SAVE_GDB_SLEEP(mOldSleepDuration);
mOldSleepDuration = ::_gdb_sleep_duration;
::_gdb_sleep_duration = 0;
#endif // defined(XP_UNIX)
return; return;
} }
#if defined(XP_UNIX) void TearDown() final { RESTORE_GDB_SLEEP(mOldSleepDuration); }
void TearDown() final { ::_gdb_sleep_duration = mOldSleepDuration; }
private: private:
#if defined(HAS_GDB_SLEEP_DURATION)
unsigned int mOldSleepDuration = 0; unsigned int mOldSleepDuration = 0;
#endif // defined(XP_UNIX) #endif // defined(HAS_GDB_SLEEP_DURATION)
}; };
class Blocker {}; class Blocker {};
@ -158,7 +150,7 @@ TEST_F(TestAsyncBlockers, Register_WaitUntilClear_0s) {
#if defined(MOZ_DIAGNOSTIC_ASSERT_ENABLED) && !defined(ANDROID) && \ #if defined(MOZ_DIAGNOSTIC_ASSERT_ENABLED) && !defined(ANDROID) && \
!(defined(XP_DARWIN) && !defined(MOZ_DEBUG)) !(defined(XP_DARWIN) && !defined(MOZ_DEBUG))
static void DeregisterEmpty_Test() { static void DeregisterEmpty_Test() {
DisableCrashReporter(); mozilla::gtest::DisableCrashReporter();
AsyncBlockers blockers; AsyncBlockers blockers;
Blocker* blocker = new Blocker(); Blocker* blocker = new Blocker();

View File

@ -14,7 +14,7 @@
#endif // defined(MOZ_WIDGET_ANDROID) || defined(XP_MACOSX) #endif // defined(MOZ_WIDGET_ANDROID) || defined(XP_MACOSX)
#if defined(XP_WIN) #if defined(XP_WIN)
# include "TestUtils.h" # include "mozilla/gtest/MozHelpers.h"
# include "mozilla/ipc/UtilityProcessImpl.h" # include "mozilla/ipc/UtilityProcessImpl.h"
#endif // defined(XP_WIN) #endif // defined(XP_WIN)
@ -141,7 +141,7 @@ TEST_F(UtilityProcess, DestroyProcess) {
#if defined(XP_WIN) #if defined(XP_WIN)
static void LoadLibraryCrash_Test() { static void LoadLibraryCrash_Test() {
DisableCrashReporter(); mozilla::gtest::DisableCrashReporter();
// Just a uuidgen name to have something random // Just a uuidgen name to have something random
UtilityProcessImpl::LoadLibraryOrCrash( UtilityProcessImpl::LoadLibraryOrCrash(
L"2b49036e-6ba3-400c-a297-38fa1f6c5255.dll"); L"2b49036e-6ba3-400c-a297-38fa1f6c5255.dll");

View File

@ -1,24 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#ifndef GTEST_UTILITY_TEST_UTILS_H
#define GTEST_UTILITY_TEST_UTILS_H
#include "nsServiceManagerUtils.h"
#include "nsICrashReporter.h"
#if (defined(MOZ_DIAGNOSTIC_ASSERT_ENABLED) || defined(XP_WIN)) && \
!defined(ANDROID) && !(defined(XP_DARWIN) && !defined(MOZ_DEBUG))
static void DisableCrashReporter() {
nsCOMPtr<nsICrashReporter> crashreporter =
do_GetService("@mozilla.org/toolkit/crash-reporter;1");
if (crashreporter) {
crashreporter->SetEnabled(false);
}
}
#endif // defined(MOZ_DIAGNOSTIC_ASSERT_ENABLED) && !defined(ANDROID) &&
// !(defined(XP_DARWIN) && !defined(MOZ_DEBUG))
#endif // GTEST_UTILITY_TEST_UTILS_H

View File

@ -8,10 +8,9 @@
#include "mozilla/UniquePtr.h" #include "mozilla/UniquePtr.h"
#include "mozilla/Unused.h" #include "mozilla/Unused.h"
#include "mozilla/Vector.h" #include "mozilla/Vector.h"
#include "mozilla/gtest/MozHelpers.h"
#include "mozmemory.h" #include "mozmemory.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsICrashReporter.h"
#include "nsServiceManagerUtils.h"
#include "Utils.h" #include "Utils.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
@ -20,35 +19,6 @@
# include "replace_malloc_bridge.h" # include "replace_malloc_bridge.h"
#endif #endif
#if defined(DEBUG) && !defined(XP_WIN) && !defined(ANDROID)
# define HAS_GDB_SLEEP_DURATION 1
extern unsigned int _gdb_sleep_duration;
#endif
// Death tests are too slow on OSX because of the system crash reporter.
#ifndef XP_DARWIN
static void DisableCrashReporter() {
nsCOMPtr<nsICrashReporter> crashreporter =
do_GetService("@mozilla.org/toolkit/crash-reporter;1");
if (crashreporter) {
crashreporter->SetEnabled(false);
}
}
// Wrap ASSERT_DEATH_IF_SUPPORTED to disable the crash reporter
// when entering the subprocess, so that the expected crashes don't
// create a minidump that the gtest harness will interpret as an error.
# define ASSERT_DEATH_WRAP(a, b) \
ASSERT_DEATH_IF_SUPPORTED( \
{ \
DisableCrashReporter(); \
a; \
}, \
b)
#else
# define ASSERT_DEATH_WRAP(a, b)
#endif
using namespace mozilla; using namespace mozilla;
class AutoDisablePHCOnCurrentThread { class AutoDisablePHCOnCurrentThread {
@ -295,11 +265,8 @@ TEST(Jemalloc, Arenas)
free(ptr); free(ptr);
moz_dispose_arena(arena); moz_dispose_arena(arena);
#ifdef HAS_GDB_SLEEP_DURATION
// Avoid death tests adding some unnecessary (long) delays. // Avoid death tests adding some unnecessary (long) delays.
unsigned int old_gdb_sleep_duration = _gdb_sleep_duration; SAVE_GDB_SLEEP_LOCAL();
_gdb_sleep_duration = 0;
#endif
// Can't use an arena after it's disposed. // Can't use an arena after it's disposed.
// ASSERT_DEATH_WRAP(moz_arena_malloc(arena, 80), ""); // ASSERT_DEATH_WRAP(moz_arena_malloc(arena, 80), "");
@ -333,9 +300,7 @@ TEST(Jemalloc, Arenas)
moz_dispose_arena(arena2); moz_dispose_arena(arena2);
moz_dispose_arena(arena); moz_dispose_arena(arena);
#ifdef HAS_GDB_SLEEP_DURATION RESTORE_GDB_SLEEP_LOCAL();
_gdb_sleep_duration = old_gdb_sleep_duration;
#endif
} }
// Check that a buffer aPtr is entirely filled with a given character from // Check that a buffer aPtr is entirely filled with a given character from
@ -464,11 +429,8 @@ TEST(Jemalloc, JunkPoison)
jemalloc_stats_t stats; jemalloc_stats_t stats;
jemalloc_stats(&stats); jemalloc_stats(&stats);
# ifdef HAS_GDB_SLEEP_DURATION
// Avoid death tests adding some unnecessary (long) delays. // Avoid death tests adding some unnecessary (long) delays.
unsigned int old_gdb_sleep_duration = _gdb_sleep_duration; SAVE_GDB_SLEEP_LOCAL();
_gdb_sleep_duration = 0;
# endif
// Create buffers in a separate arena, for faster comparisons with // Create buffers in a separate arena, for faster comparisons with
// bulk_compare. // bulk_compare.
@ -654,9 +616,7 @@ TEST(Jemalloc, JunkPoison)
moz_arena_free(buf_arena, fill_buf); moz_arena_free(buf_arena, fill_buf);
moz_dispose_arena(buf_arena); moz_dispose_arena(buf_arena);
# ifdef HAS_GDB_SLEEP_DURATION RESTORE_GDB_SLEEP_LOCAL();
_gdb_sleep_duration = old_gdb_sleep_duration;
# endif
} }
#endif // !defined(XP_WIN) || !defined(MOZ_CODE_COVERAGE) #endif // !defined(XP_WIN) || !defined(MOZ_CODE_COVERAGE)
@ -669,11 +629,8 @@ TEST(Jemalloc, TrailingGuard)
jemalloc_stats_t stats; jemalloc_stats_t stats;
jemalloc_stats(&stats); jemalloc_stats(&stats);
#ifdef HAS_GDB_SLEEP_DURATION
// Avoid death tests adding some unnecessary (long) delays. // Avoid death tests adding some unnecessary (long) delays.
unsigned int old_gdb_sleep_duration = _gdb_sleep_duration; SAVE_GDB_SLEEP_LOCAL();
_gdb_sleep_duration = 0;
#endif
arena_id_t arena = moz_create_arena(); arena_id_t arena = moz_create_arena();
ASSERT_TRUE(arena != 0); ASSERT_TRUE(arena != 0);
@ -705,9 +662,7 @@ TEST(Jemalloc, TrailingGuard)
moz_dispose_arena(arena); moz_dispose_arena(arena);
#ifdef HAS_GDB_SLEEP_DURATION RESTORE_GDB_SLEEP_LOCAL();
_gdb_sleep_duration = old_gdb_sleep_duration;
#endif
} }
TEST(Jemalloc, LeadingGuard) TEST(Jemalloc, LeadingGuard)
@ -719,11 +674,8 @@ TEST(Jemalloc, LeadingGuard)
jemalloc_stats_t stats; jemalloc_stats_t stats;
jemalloc_stats(&stats); jemalloc_stats(&stats);
#ifdef HAS_GDB_SLEEP_DURATION
// Avoid death tests adding some unnecessary (long) delays. // Avoid death tests adding some unnecessary (long) delays.
unsigned int old_gdb_sleep_duration = _gdb_sleep_duration; SAVE_GDB_SLEEP_LOCAL();
_gdb_sleep_duration = 0;
#endif
arena_id_t arena = moz_create_arena(); arena_id_t arena = moz_create_arena();
ASSERT_TRUE(arena != 0); ASSERT_TRUE(arena != 0);
@ -755,9 +707,7 @@ TEST(Jemalloc, LeadingGuard)
moz_arena_free(arena, ptr); moz_arena_free(arena, ptr);
moz_dispose_arena(arena); moz_dispose_arena(arena);
#ifdef HAS_GDB_SLEEP_DURATION RESTORE_GDB_SLEEP_LOCAL();
_gdb_sleep_duration = old_gdb_sleep_duration;
#endif
} }
TEST(Jemalloc, DisposeArena) TEST(Jemalloc, DisposeArena)
@ -765,11 +715,8 @@ TEST(Jemalloc, DisposeArena)
jemalloc_stats_t stats; jemalloc_stats_t stats;
jemalloc_stats(&stats); jemalloc_stats(&stats);
#ifdef HAS_GDB_SLEEP_DURATION
// Avoid death tests adding some unnecessary (long) delays. // Avoid death tests adding some unnecessary (long) delays.
unsigned int old_gdb_sleep_duration = _gdb_sleep_duration; SAVE_GDB_SLEEP_LOCAL();
_gdb_sleep_duration = 0;
#endif
arena_id_t arena = moz_create_arena(); arena_id_t arena = moz_create_arena();
void* ptr = moz_arena_malloc(arena, 42); void* ptr = moz_arena_malloc(arena, 42);
@ -805,7 +752,5 @@ TEST(Jemalloc, DisposeArena)
// Using the arena after it's been disposed of is MOZ_CRASH-worthy. // Using the arena after it's been disposed of is MOZ_CRASH-worthy.
ASSERT_DEATH_WRAP(moz_arena_malloc(arena, 42), ""); ASSERT_DEATH_WRAP(moz_arena_malloc(arena, 42), "");
#ifdef HAS_GDB_SLEEP_DURATION RESTORE_GDB_SLEEP_LOCAL();
_gdb_sleep_duration = old_gdb_sleep_duration;
#endif
} }

View File

@ -14,6 +14,9 @@
#include "mozilla/ReentrantMonitor.h" #include "mozilla/ReentrantMonitor.h"
#include "SQLiteMutex.h" #include "SQLiteMutex.h"
// We need this one so _gdb_sleep_duration is also in "storage" namespace
#include "mozilla/gtest/MozHelpers.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
using namespace mozilla; using namespace mozilla;
@ -40,11 +43,6 @@ class TestMutex : public mozilla::storage::SQLiteMutex {
sqlite3_mutex* mInner; sqlite3_mutex* mInner;
}; };
// This global variable is defined in toolkit/xre/nsSigHandlers.cpp.
// It's declared in xpcom/tests/gtest/TestDeadlockDetector.cpp, but we #include
// that within the |storage| namespace, so we need to declare it again here.
extern unsigned int _gdb_sleep_duration;
// These are the two macros that differentiate this file from the XPCOM one. // These are the two macros that differentiate this file from the XPCOM one.
#define MUTEX TestMutex #define MUTEX TestMutex
#define TESTNAME(name) storage_##name #define TESTNAME(name) storage_##name

View File

@ -0,0 +1,13 @@
#include "MozHelpers.h"
namespace mozilla::gtest {
void DisableCrashReporter() {
nsCOMPtr<nsICrashReporter> crashreporter =
do_GetService("@mozilla.org/toolkit/crash-reporter;1");
if (crashreporter) {
crashreporter->SetEnabled(false);
}
}
} // namespace mozilla::gtest

View File

@ -0,0 +1,68 @@
#ifndef TESTING_GTEST_MOZILLA_HELPERS_H_
#define TESTING_GTEST_MOZILLA_HELPERS_H_
#include "gtest/gtest.h"
#include "nsCOMPtr.h"
#include "nsServiceManagerUtils.h"
#include "nsICrashReporter.h"
#if defined(DEBUG) && !defined(XP_WIN) && !defined(ANDROID)
# define HAS_GDB_SLEEP_DURATION 1
extern unsigned int _gdb_sleep_duration;
#endif
namespace mozilla::gtest {
#if defined(HAS_GDB_SLEEP_DURATION)
# define ZERO_GDB_SLEEP() _gdb_sleep_duration = 0;
# define SAVE_GDB_SLEEP(v) \
v = _gdb_sleep_duration; \
ZERO_GDB_SLEEP();
# define RESTORE_GDB_SLEEP(v) _gdb_sleep_duration = v;
// Some use needs to be in the global namespace
# define SAVE_GDB_SLEEP_GLOBAL(v) \
v = ::_gdb_sleep_duration; \
ZERO_GDB_SLEEP();
# define RESTORE_GDB_SLEEP_GLOBAL(v) ::_gdb_sleep_duration = v;
# define SAVE_GDB_SLEEP_LOCAL() \
unsigned int _old_gdb_sleep_duration; \
SAVE_GDB_SLEEP(_old_gdb_sleep_duration);
# define RESTORE_GDB_SLEEP_LOCAL() RESTORE_GDB_SLEEP(_old_gdb_sleep_duration);
#else // defined(HAS_GDB_SLEEP_DURATION)
# define ZERO_GDB_SLEEP() ;
# define SAVE_GDB_SLEEP(v)
# define SAVE_GDB_SLEEP_GLOBAL(v)
# define SAVE_GDB_SLEEP_LOCAL()
# define RESTORE_GDB_SLEEP(v)
# define RESTORE_GDB_SLEEP_GLOBAL(v)
# define RESTORE_GDB_SLEEP_LOCAL()
#endif // defined(HAS_GDB_SLEEP_DURATION)
// Death tests are too slow on OSX because of the system crash reporter.
#if !defined(XP_DARWIN)
// Wrap ASSERT_DEATH_IF_SUPPORTED to disable the crash reporter
// when entering the subprocess, so that the expected crashes don't
// create a minidump that the gtest harness will interpret as an error.
# define ASSERT_DEATH_WRAP(a, b) \
ASSERT_DEATH_IF_SUPPORTED( \
{ \
mozilla::gtest::DisableCrashReporter(); \
a; \
}, \
b)
#else
# define ASSERT_DEATH_WRAP(a, b)
#endif
void DisableCrashReporter();
} // namespace mozilla::gtest
#endif // TESTING_GTEST_MOZILLA_HELPERS_H_

View File

@ -19,12 +19,14 @@ if CONFIG["ENABLE_TESTS"]:
EXPORTS.mozilla.gtest += [ EXPORTS.mozilla.gtest += [
"MozAssertions.h", "MozAssertions.h",
"MozHelpers.h",
] ]
SOURCES += [ SOURCES += [
"GTestRunner.cpp", "GTestRunner.cpp",
"MozAssertions.cpp", "MozAssertions.cpp",
"MozGTestBench.cpp", "MozGTestBench.cpp",
"MozHelpers.cpp",
"SanityTest.cpp", "SanityTest.cpp",
] ]

View File

@ -9,8 +9,6 @@
#include "prthread.h" #include "prthread.h"
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsICrashReporter.h"
#include "nsServiceManagerUtils.h"
#include "nsTArray.h" #include "nsTArray.h"
#include "mozilla/CondVar.h" #include "mozilla/CondVar.h"
@ -18,6 +16,8 @@
#include "mozilla/ReentrantMonitor.h" #include "mozilla/ReentrantMonitor.h"
#include "mozilla/Mutex.h" #include "mozilla/Mutex.h"
#include "mozilla/gtest/MozHelpers.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
using namespace mozilla; using namespace mozilla;
@ -38,40 +38,28 @@ static PRThread* spawn(void (*run)(void*), void* arg) {
PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0); PR_GLOBAL_THREAD, PR_JOINABLE_THREAD, 0);
} }
// This global variable is defined in toolkit/xre/nsSigHandlers.cpp.
extern unsigned int _gdb_sleep_duration;
/** /**
* Simple test fixture that makes sure the gdb sleep setup in the * Simple test fixture that makes sure the gdb sleep setup in the
* ah crap handler is bypassed during the death tests. * ah crap handler is bypassed during the death tests.
*/ */
class TESTNAME(DeadlockDetectorTest) : public ::testing::Test { class TESTNAME(DeadlockDetectorTest) : public ::testing::Test {
protected: protected:
void SetUp() final { void SetUp() final { SAVE_GDB_SLEEP_GLOBAL(mOldSleepDuration); }
mOldSleepDuration = ::_gdb_sleep_duration;
::_gdb_sleep_duration = 0;
}
void TearDown() final { ::_gdb_sleep_duration = mOldSleepDuration; } void TearDown() final { RESTORE_GDB_SLEEP_GLOBAL(mOldSleepDuration); }
private: private:
#if defined(HAS_GDB_SLEEP_DURATION)
unsigned int mOldSleepDuration; unsigned int mOldSleepDuration;
#endif // defined(HAS_GDB_SLEEP_DURATION)
}; };
static void DisableCrashReporter() {
nsCOMPtr<nsICrashReporter> crashreporter =
do_GetService("@mozilla.org/toolkit/crash-reporter;1");
if (crashreporter) {
crashreporter->SetEnabled(false);
}
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Single-threaded sanity tests // Single-threaded sanity tests
// Stupidest possible deadlock. // Stupidest possible deadlock.
static int Sanity_Child() MOZ_NO_THREAD_SAFETY_ANALYSIS { static int Sanity_Child() MOZ_NO_THREAD_SAFETY_ANALYSIS {
DisableCrashReporter(); mozilla::gtest::DisableCrashReporter();
MUTEX m1("dd.sanity.m1"); MUTEX m1("dd.sanity.m1");
m1.Lock(); m1.Lock();
@ -92,7 +80,7 @@ TEST_F(TESTNAME(DeadlockDetectorTest), TESTNAME(SanityDeathTest)) {
// Slightly less stupid deadlock. // Slightly less stupid deadlock.
static int Sanity2_Child() MOZ_NO_THREAD_SAFETY_ANALYSIS { static int Sanity2_Child() MOZ_NO_THREAD_SAFETY_ANALYSIS {
DisableCrashReporter(); mozilla::gtest::DisableCrashReporter();
MUTEX m1("dd.sanity2.m1"); MUTEX m1("dd.sanity2.m1");
MUTEX m2("dd.sanity2.m2"); MUTEX m2("dd.sanity2.m2");
@ -119,7 +107,7 @@ TEST_F(TESTNAME(DeadlockDetectorTest), TESTNAME(Sanity2DeathTest)) {
int int
Sanity3_Child() MOZ_NO_THREAD_SAFETY_ANALYSIS Sanity3_Child() MOZ_NO_THREAD_SAFETY_ANALYSIS
{ {
DisableCrashReporter(); mozilla::gtest::DisableCrashReporter();
MUTEX m1("dd.sanity3.m1"); MUTEX m1("dd.sanity3.m1");
MUTEX m2("dd.sanity3.m2"); MUTEX m2("dd.sanity3.m2");
@ -156,7 +144,7 @@ TEST_F(TESTNAME(DeadlockDetectorTest), TESTNAME(Sanity3DeathTest))
#endif #endif
static int Sanity4_Child() MOZ_NO_THREAD_SAFETY_ANALYSIS { static int Sanity4_Child() MOZ_NO_THREAD_SAFETY_ANALYSIS {
DisableCrashReporter(); mozilla::gtest::DisableCrashReporter();
mozilla::ReentrantMonitor m1 MOZ_UNANNOTATED("dd.sanity4.m1"); mozilla::ReentrantMonitor m1 MOZ_UNANNOTATED("dd.sanity4.m1");
MUTEX m2("dd.sanity4.m2"); MUTEX m2("dd.sanity4.m2");
@ -179,7 +167,7 @@ TEST_F(TESTNAME(DeadlockDetectorTest), TESTNAME(Sanity4DeathTest)) {
} }
static int Sanity5_Child() MOZ_NO_THREAD_SAFETY_ANALYSIS { static int Sanity5_Child() MOZ_NO_THREAD_SAFETY_ANALYSIS {
DisableCrashReporter(); mozilla::gtest::DisableCrashReporter();
mozilla::RecursiveMutex m1 MOZ_UNANNOTATED("dd.sanity4.m1"); mozilla::RecursiveMutex m1 MOZ_UNANNOTATED("dd.sanity4.m1");
MUTEX m2("dd.sanity4.m2"); MUTEX m2("dd.sanity4.m2");
@ -248,7 +236,7 @@ TwoThreads_thread(void* arg) MOZ_NO_THREAD_SAFETY_ANALYSIS
int int
TwoThreads_Child() MOZ_NO_THREAD_SAFETY_ANALYSIS TwoThreads_Child() MOZ_NO_THREAD_SAFETY_ANALYSIS
{ {
DisableCrashReporter(); mozilla::gtest::DisableCrashReporter();
nsTArray<MUTEX*> locks = { nsTArray<MUTEX*> locks = {
new MUTEX("dd.twothreads.m1"), new MUTEX("dd.twothreads.m1"),

View File

@ -5,10 +5,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "PLDHashTable.h" #include "PLDHashTable.h"
#include "nsCOMPtr.h"
#include "nsICrashReporter.h"
#include "nsServiceManagerUtils.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "mozilla/gtest/MozHelpers.h"
// This test mostly focuses on edge cases. But more coverage of normal // This test mostly focuses on edge cases. But more coverage of normal
// operations wouldn't be a bad thing. // operations wouldn't be a bad thing.
@ -17,9 +15,6 @@
# include <unistd.h> # include <unistd.h>
# include <sys/types.h> # include <sys/types.h>
# include <sys/wait.h> # include <sys/wait.h>
// This global variable is defined in toolkit/xre/nsSigHandlers.cpp.
extern unsigned int _gdb_sleep_duration;
#endif #endif
// We can test that certain operations cause expected aborts by forking // We can test that certain operations cause expected aborts by forking
@ -34,8 +29,7 @@ static void TestCrashyOperation(const char* label, void (*aCrashyOperation)()) {
#if defined(XP_UNIX) && defined(DEBUG) && !defined(MOZ_ASAN) #if defined(XP_UNIX) && defined(DEBUG) && !defined(MOZ_ASAN)
// We're about to trigger a crash. When it happens don't pause to allow GDB // We're about to trigger a crash. When it happens don't pause to allow GDB
// to be attached. // to be attached.
unsigned int old_gdb_sleep_duration = _gdb_sleep_duration; SAVE_GDB_SLEEP_LOCAL();
_gdb_sleep_duration = 0;
int pid = fork(); int pid = fork();
ASSERT_NE(pid, -1); ASSERT_NE(pid, -1);
@ -44,11 +38,7 @@ static void TestCrashyOperation(const char* label, void (*aCrashyOperation)()) {
// Disable the crashreporter -- writing a crash dump in the child will // Disable the crashreporter -- writing a crash dump in the child will
// prevent the parent from writing a subsequent dump. Crashes here are // 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. // expected, so we don't want their stacks to show up in the log anyway.
nsCOMPtr<nsICrashReporter> crashreporter = mozilla::gtest::DisableCrashReporter();
do_GetService("@mozilla.org/toolkit/crash-reporter;1");
if (crashreporter) {
crashreporter->SetEnabled(false);
}
// Child: perform the crashy operation. // Child: perform the crashy operation.
FILE* stderr_dup = fdopen(dup(fileno(stderr)), "w"); FILE* stderr_dup = fdopen(dup(fileno(stderr)), "w");
@ -86,7 +76,7 @@ static void TestCrashyOperation(const char* label, void (*aCrashyOperation)()) {
} }
} }
_gdb_sleep_duration = old_gdb_sleep_duration; RESTORE_GDB_SLEEP_LOCAL();
#endif #endif
} }

View File

@ -10,10 +10,6 @@
# error "failed to wrap <vector>" # error "failed to wrap <vector>"
#endif #endif
#include "nsCOMPtr.h"
#include "nsICrashReporter.h"
#include "nsServiceManagerUtils.h"
// gcc errors out if we |try ... catch| with -fno-exceptions, but we // gcc errors out if we |try ... catch| with -fno-exceptions, but we
// can still test on windows // can still test on windows
#ifdef _MSC_VER #ifdef _MSC_VER
@ -29,20 +25,12 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
#if defined(XP_UNIX) #include "mozilla/gtest/MozHelpers.h"
extern unsigned int _gdb_sleep_duration;
#endif
void ShouldAbort() { void ShouldAbort() {
#if defined(XP_UNIX) ZERO_GDB_SLEEP();
_gdb_sleep_duration = 0;
#endif
nsCOMPtr<nsICrashReporter> crashreporter = mozilla::gtest::DisableCrashReporter();
do_GetService("@mozilla.org/toolkit/crash-reporter;1");
if (crashreporter) {
crashreporter->SetEnabled(false);
}
std::vector<int> v; std::vector<int> v;