aboutsummaryrefslogtreecommitdiff
path: root/src/test/sync_tests.cpp
diff options
context:
space:
mode:
authorRussell Yanofsky <russ@yanofsky.org>2017-11-08 15:28:35 -0500
committerRussell Yanofsky <russ@yanofsky.org>2018-08-03 07:11:37 -0500
commit41b88e93375d57db12da923f45f87b9a2db8e730 (patch)
treeca184f2dbeea04b7deea7f7f3dc5a73d66d51795 /src/test/sync_tests.cpp
parent2b67354aa584c4aabae049a67767ac7b70e2d01a (diff)
downloadbitcoin-41b88e93375d57db12da923f45f87b9a2db8e730.tar.xz
Add unit test for DEBUG_LOCKORDER code
Diffstat (limited to 'src/test/sync_tests.cpp')
-rw-r--r--src/test/sync_tests.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/test/sync_tests.cpp b/src/test/sync_tests.cpp
new file mode 100644
index 0000000000..2e0951c3a9
--- /dev/null
+++ b/src/test/sync_tests.cpp
@@ -0,0 +1,41 @@
+// Copyright (c) 2012-2017 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include <sync.h>
+#include <test/test_bitcoin.h>
+
+#include <boost/test/unit_test.hpp>
+
+BOOST_FIXTURE_TEST_SUITE(sync_tests, BasicTestingSetup)
+
+BOOST_AUTO_TEST_CASE(potential_deadlock_detected)
+{
+ #ifdef DEBUG_LOCKORDER
+ bool prev = g_debug_lockorder_abort;
+ g_debug_lockorder_abort = false;
+ #endif
+
+ CCriticalSection mutex1, mutex2;
+ {
+ LOCK2(mutex1, mutex2);
+ }
+ bool error_thrown = false;
+ try {
+ LOCK2(mutex2, mutex1);
+ } catch (const std::logic_error& e) {
+ BOOST_CHECK_EQUAL(e.what(), "potential deadlock detected");
+ error_thrown = true;
+ }
+ #ifdef DEBUG_LOCKORDER
+ BOOST_CHECK(error_thrown);
+ #else
+ BOOST_CHECK(!error_thrown);
+ #endif
+
+ #ifdef DEBUG_LOCKORDER
+ g_debug_lockorder_abort = prev;
+ #endif
+}
+
+BOOST_AUTO_TEST_SUITE_END()