8 #include <boost/test/unit_test.hpp>
14 template <
typename MutexType>
15 void TestPotentialDeadLockDetected(MutexType& mutex1, MutexType& mutex2)
18 LOCK2(mutex1, mutex2);
21 bool error_thrown =
false;
23 LOCK2(mutex2, mutex1);
24 }
catch (
const std::logic_error& e) {
25 BOOST_CHECK_EQUAL(e.what(),
"potential deadlock detected: mutex1 -> mutex2 -> mutex1");
29 #ifdef DEBUG_LOCKORDER
36 #ifdef DEBUG_LOCKORDER
37 template <
typename MutexType>
38 void TestDoubleLock2(MutexType& m)
44 template <
typename MutexType>
45 void TestDoubleLock(
bool should_throw)
47 const bool prev = g_debug_lockorder_abort;
48 g_debug_lockorder_abort =
false;
53 BOOST_CHECK_EXCEPTION(TestDoubleLock2(m), std::logic_error,
62 g_debug_lockorder_abort = prev;
66 template <
typename MutexType>
71 #ifdef DEBUG_LOCKORDER
84 #ifdef DEBUG_LOCKORDER
85 bool prev = g_debug_lockorder_abort;
86 g_debug_lockorder_abort =
false;
90 TestPotentialDeadLockDetected(rmutex1, rmutex2);
92 TestPotentialDeadLockDetected(rmutex1, rmutex2);
95 TestPotentialDeadLockDetected(mutex1, mutex2);
97 TestPotentialDeadLockDetected(mutex1, mutex2);
99 #ifdef DEBUG_LOCKORDER
100 g_debug_lockorder_abort = prev;
107 #ifdef DEBUG_LOCKORDER
110 TestDoubleLock<Mutex>(
true);
115 TestDoubleLock<RecursiveMutex>(
false);
121 #ifdef DEBUG_LOCKORDER
122 bool prev = g_debug_lockorder_abort;
123 g_debug_lockorder_abort =
false;
127 TestInconsistentLockOrderDetected(rmutex1, rmutex2);
130 TestInconsistentLockOrderDetected(rmutex1, rmutex2);
132 Mutex mutex1, mutex2;
133 TestInconsistentLockOrderDetected(mutex1, mutex2);
136 TestInconsistentLockOrderDetected(mutex1, mutex2);
138 #ifdef DEBUG_LOCKORDER
139 g_debug_lockorder_abort = prev;
BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
BOOST_AUTO_TEST_SUITE(cuckoocache_tests)
Test Suite for CuckooCache.
BOOST_AUTO_TEST_SUITE_END()
#define BOOST_CHECK_EQUAL(v1, v2)
#define BOOST_CHECK_NO_THROW(stmt)
#define BOOST_CHECK(expr)
#define ENTER_CRITICAL_SECTION(cs)
#define LEAVE_CRITICAL_SECTION(cs)
BOOST_AUTO_TEST_CASE(potential_deadlock_detected)
#define NO_THREAD_SAFETY_ANALYSIS