PIVX Core  5.6.99
P2P Digital Currency
sync_tests.cpp
Go to the documentation of this file.
1 // Copyright (c) 2012-2020 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include "sync.h"
6 #include "test/test_pivx.h"
7 
8 #include <boost/test/unit_test.hpp>
9 
10 namespace {
11 template <typename MutexType>
12 void TestPotentialDeadLockDetected(MutexType& mutex1, MutexType& mutex2)
13 {
14  {
15  LOCK2(mutex1, mutex2);
16  }
17  bool error_thrown = false;
18  try {
19  LOCK2(mutex2, mutex1);
20  } catch (const std::logic_error& e) {
21  BOOST_CHECK_EQUAL(e.what(), "potential deadlock detected");
22  error_thrown = true;
23  }
24  #ifdef DEBUG_LOCKORDER
25  BOOST_CHECK(error_thrown);
26  #else
27  BOOST_CHECK(!error_thrown);
28  #endif
29 }
30 } // namespace
31 
33 
34 BOOST_AUTO_TEST_CASE(potential_deadlock_detected)
35 {
36  #ifdef DEBUG_LOCKORDER
37  bool prev = g_debug_lockorder_abort;
38  g_debug_lockorder_abort = false;
39  #endif
40 
41  RecursiveMutex rmutex1, rmutex2;
42  TestPotentialDeadLockDetected(rmutex1, rmutex2);
43 
44  Mutex mutex1, mutex2;
45  TestPotentialDeadLockDetected(mutex1, mutex2);
46 
47  #ifdef DEBUG_LOCKORDER
48  g_debug_lockorder_abort = prev;
49  #endif
50 }
51 
BOOST_AUTO_TEST_SUITE_END()
#define BOOST_FIXTURE_TEST_SUITE(a, b)
Definition: object.cpp:14
#define BOOST_CHECK_EQUAL(v1, v2)
Definition: object.cpp:18
#define BOOST_CHECK(expr)
Definition: object.cpp:17
Basic testing setup.
Definition: test_pivx.h:51
#define LOCK2(cs1, cs2)
Definition: sync.h:221
BOOST_AUTO_TEST_CASE(potential_deadlock_detected)
Definition: sync_tests.cpp:34