test_deadlock_detector.cpp (1765B)
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- 2 * vim: sw=2 ts=4 et : 3 * This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 // Note: This file is essentially a copy of 8 // xpcom/tests/gtest/TestDeadlockDetector.cpp, but all mutexes were turned into 9 // SQLiteMutexes. We use #include and some macros to avoid actual source code 10 // duplication. 11 12 #include "mozilla/CondVar.h" 13 #include "mozilla/RecursiveMutex.h" 14 #include "mozilla/ReentrantMonitor.h" 15 #include "SQLiteMutex.h" 16 17 // We need this one so _gdb_sleep_duration is also in "storage" namespace 18 #include "mozilla/gtest/MozHelpers.h" 19 20 #include "gtest/gtest.h" 21 22 using namespace mozilla; 23 24 /** 25 * Helper class to allocate a sqlite3_mutex for our SQLiteMutex. 26 */ 27 class TestMutex : public mozilla::storage::SQLiteMutex { 28 public: 29 explicit TestMutex(const char* aName) 30 : mozilla::storage::SQLiteMutex(aName), 31 mInner(sqlite3_mutex_alloc(SQLITE_MUTEX_FAST)) { 32 NS_ASSERTION(mInner, "could not allocate a sqlite3_mutex"); 33 initWithMutex(mInner); 34 } 35 36 ~TestMutex() { sqlite3_mutex_free(mInner); } 37 38 void Lock() { lock(); } 39 40 void Unlock() { unlock(); } 41 42 private: 43 sqlite3_mutex* mInner; 44 }; 45 46 // These are the two macros that differentiate this file from the XPCOM one. 47 #define MUTEX TestMutex 48 #define TESTNAME(name) storage_##name 49 50 // Bug 1473531: the test storage_DeadlockDetectorTest.storage_Sanity5DeathTest 51 // times out on macosx ccov builds 52 #if defined(XP_MACOSX) && defined(MOZ_CODE_COVERAGE) 53 # define DISABLE_STORAGE_SANITY5_DEATH_TEST 54 #endif 55 56 #include "../../../xpcom/tests/gtest/TestDeadlockDetector.cpp"