Changeset View
Changeset View
Standalone View
Standalone View
src/test/sync_tests.cpp
Show All 22 Lines | void TestPotentialDeadLockDetected(MutexType &mutex1, MutexType &mutex2) { | ||||
} | } | ||||
BOOST_CHECK(LockStackEmpty()); | BOOST_CHECK(LockStackEmpty()); | ||||
#ifdef DEBUG_LOCKORDER | #ifdef DEBUG_LOCKORDER | ||||
BOOST_CHECK(error_thrown); | BOOST_CHECK(error_thrown); | ||||
#else | #else | ||||
BOOST_CHECK(!error_thrown); | BOOST_CHECK(!error_thrown); | ||||
#endif | #endif | ||||
} | } | ||||
template <typename MutexType> | |||||
void TestInconsistentLockOrderDetected(MutexType &mutex1, MutexType &mutex2) | |||||
NO_THREAD_SAFETY_ANALYSIS { | |||||
ENTER_CRITICAL_SECTION(mutex1); | |||||
ENTER_CRITICAL_SECTION(mutex2); | |||||
#ifdef DEBUG_LOCKORDER | |||||
BOOST_CHECK_EXCEPTION( | |||||
LEAVE_CRITICAL_SECTION(mutex1), std::logic_error, | |||||
HasReason("mutex1 was not most recent critical section locked")); | |||||
#endif // DEBUG_LOCKORDER | |||||
LEAVE_CRITICAL_SECTION(mutex2); | |||||
LEAVE_CRITICAL_SECTION(mutex1); | |||||
BOOST_CHECK(LockStackEmpty()); | |||||
} | |||||
} // namespace | } // namespace | ||||
BOOST_FIXTURE_TEST_SUITE(sync_tests, BasicTestingSetup) | BOOST_FIXTURE_TEST_SUITE(sync_tests, BasicTestingSetup) | ||||
BOOST_AUTO_TEST_CASE(potential_deadlock_detected) { | BOOST_AUTO_TEST_CASE(potential_deadlock_detected) { | ||||
#ifdef DEBUG_LOCKORDER | #ifdef DEBUG_LOCKORDER | ||||
bool prev = g_debug_lockorder_abort; | bool prev = g_debug_lockorder_abort; | ||||
g_debug_lockorder_abort = false; | g_debug_lockorder_abort = false; | ||||
Show All 11 Lines | #endif | ||||
// exception. | // exception. | ||||
TestPotentialDeadLockDetected(mutex1, mutex2); | TestPotentialDeadLockDetected(mutex1, mutex2); | ||||
#ifdef DEBUG_LOCKORDER | #ifdef DEBUG_LOCKORDER | ||||
g_debug_lockorder_abort = prev; | g_debug_lockorder_abort = prev; | ||||
#endif | #endif | ||||
} | } | ||||
BOOST_AUTO_TEST_CASE(inconsistent_lock_order_detected) { | |||||
#ifdef DEBUG_LOCKORDER | |||||
bool prev = g_debug_lockorder_abort; | |||||
g_debug_lockorder_abort = false; | |||||
#endif // DEBUG_LOCKORDER | |||||
RecursiveMutex rmutex1, rmutex2; | |||||
TestInconsistentLockOrderDetected(rmutex1, rmutex2); | |||||
// By checking lock order consistency (CheckLastCritical) before any | |||||
// unlocking (LeaveCritical) the lock tracking data must not have been | |||||
// broken by exception. | |||||
TestInconsistentLockOrderDetected(rmutex1, rmutex2); | |||||
Mutex mutex1, mutex2; | |||||
TestInconsistentLockOrderDetected(mutex1, mutex2); | |||||
// By checking lock order consistency (CheckLastCritical) before any | |||||
// unlocking (LeaveCritical) the lock tracking data must not have been | |||||
// broken by exception. | |||||
TestInconsistentLockOrderDetected(mutex1, mutex2); | |||||
#ifdef DEBUG_LOCKORDER | |||||
g_debug_lockorder_abort = prev; | |||||
#endif // DEBUG_LOCKORDER | |||||
} | |||||
BOOST_AUTO_TEST_SUITE_END() | BOOST_AUTO_TEST_SUITE_END() |