/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * vim: sw=2 ts=4 et : * 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/. */
// The code in this file is also used by // storage/test/gtest/test_deadlock_detector.cpp. The following two macros are // used to provide the necessary differentiation between this file and that // file. #ifndef MUTEX # define MUTEX mozilla::Mutex #endif #ifndef TESTNAME # define TESTNAME(name) XPCOM##name #endif
/** * Simple test fixture that makes sure the gdb sleep setup in the * ah crap handler is bypassed during the death tests.
*/ class TESTNAME(DeadlockDetectorTest) : public ::testing::Test { protected: void SetUp() final { SAVE_GDB_SLEEP_GLOBAL(mOldSleepDuration); }
void TearDown() final { RESTORE_GDB_SLEEP_GLOBAL(mOldSleepDuration); }
/** * Helper for passing state to threads in the multithread tests.
*/ struct ThreadState { /** * Locks to use during the test. This is just a reference and is owned by * the main test thread.
*/ const nsTArray<MUTEX*>& locks;
/** * Integer argument used to identify each thread.
*/ int id;
};
#if 0 // Temporarily disabled, see bug 1370644. staticvoid
TwoThreads_thread(void* arg) MOZ_NO_THREAD_SAFETY_ANALYSIS
{
ThreadState* state = static_cast<ThreadState*>(arg);
for (uint32_t k = 0; k < K; ++k) { for (int32_t i = starti; i < (int32_t)cndMs.Length(); ++i) cndMs[i]->Lock(); // comment out the next two lines for deadlocking fun! for (int32_t i = cndMs.Length() - 1; i >= starti; --i) cndMs[i]->Unlock();
for (uint32_t i = 0; i < kMutexCount; ++i)
locks.AppendElement(new MUTEX("dd.cnd.ms"));
for (int32_t i = 0; i < (int32_t)std::size(threads); ++i)
threads[i] = spawn(ContentionNoDeadlock_thread, states + i);
for (uint32_t i = 0; i < std::size(threads); ++i) PR_JoinThread(threads[i]);
for (uint32_t i = 0; i < locks.Length(); ++i) delete locks[i];
return 0;
}
TEST_F(TESTNAME(DeadlockDetectorTest), TESTNAME(ContentionNoDeadlock)) { // Just check that this test runs to completion.
ASSERT_EQ(ContentionNoDeadlock_Child(), 0);
}
¤ Dauer der Verarbeitung: 0.14 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.