diff --git a/src/bench/bench.cpp b/src/bench/bench.cpp index 745fd0966d6a6..d1b2b938ff2c2 100644 --- a/src/bench/bench.cpp +++ b/src/bench/bench.cpp @@ -16,6 +16,7 @@ #include const RegTestingSetup* g_testing_setup = nullptr; +const std::function G_TEST_LOG_FUN{}; void benchmark::ConsolePrinter::header() { diff --git a/src/qt/test/test_main.cpp b/src/qt/test/test_main.cpp index f8c0379ea86e3..aefdcd27163a9 100644 --- a/src/qt/test/test_main.cpp +++ b/src/qt/test/test_main.cpp @@ -37,6 +37,8 @@ Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin); #endif #endif +const std::function G_TEST_LOG_FUN{}; + // This is all you need to run all the tests int main(int argc, char *argv[]) { diff --git a/src/test/fuzz/fuzz.cpp b/src/test/fuzz/fuzz.cpp index da4e623e98156..a6ab620e21890 100644 --- a/src/test/fuzz/fuzz.cpp +++ b/src/test/fuzz/fuzz.cpp @@ -4,10 +4,14 @@ #include +#include + #include #include #include +const std::function G_TEST_LOG_FUN{}; + static bool read_stdin(std::vector& data) { uint8_t buffer[1024]; diff --git a/src/test/main.cpp b/src/test/main.cpp index ff3f36b56162f..e6529949e2702 100644 --- a/src/test/main.cpp +++ b/src/test/main.cpp @@ -2,6 +2,21 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +/** + * See https://www.boost.org/doc/libs/1_71_0/libs/test/doc/html/boost_test/utf_reference/link_references/link_boost_test_module_macro.html + */ #define BOOST_TEST_MODULE Bitcoin Core Test Suite #include + +#include + +/** Redirect debug log to boost log */ +const std::function G_TEST_LOG_FUN = [](const std::string& s) { + if (s.back() == '\n') { + // boost will insert the new line + BOOST_TEST_MESSAGE(s.substr(0, s.size() - 1)); + } else { + BOOST_TEST_MESSAGE(s); + } +}; diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp index 3bdf3485faa2c..ccb3064d5974a 100644 --- a/src/test/util/setup_common.cpp +++ b/src/test/util/setup_common.cpp @@ -71,6 +71,7 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName) SelectParams(chainName); SeedInsecureRand(); gArgs.ForceSetArg("-printtoconsole", "0"); + if (G_TEST_LOG_FUN) LogInstance().PushBackCallback(G_TEST_LOG_FUN); InitLogging(); LogInstance().StartLogging(); SHA256AutoDetect(); diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h index 1e2e059a561d1..6741be84804aa 100644 --- a/src/test/util/setup_common.h +++ b/src/test/util/setup_common.h @@ -18,6 +18,9 @@ #include +/** This is connected to the logger. Can be used to redirect logs to any other log */ +extern const std::function G_TEST_LOG_FUN; + // Enable BOOST_CHECK_EQUAL for enum class types template std::ostream& operator<<(typename std::enable_if::value, std::ostream>::type& stream, const T& e) diff --git a/test/sanitizer_suppressions/tsan b/test/sanitizer_suppressions/tsan index 70eea343633ae..b9c5c038d0afa 100644 --- a/test/sanitizer_suppressions/tsan +++ b/test/sanitizer_suppressions/tsan @@ -7,6 +7,14 @@ deadlock:WalletBatch # Intentional deadlock in tests deadlock:TestPotentialDeadLockDetected +# Race due to unprotected calls to thread-unsafe BOOST_TEST_MESSAGE from different threads: +# * G_TEST_LOG_FUN in the index thread +# * boost test case invoker (entering a test case) in the main thread +# TODO: get rid of BOOST_ macros, see also https://github.com/bitcoin/bitcoin/issues/8670 +race:blockfilter_index_initial_sync_invoker +race:txindex_initial_sync_invoker +race:validation_block_tests::TestSubscriber + # Wildcard for all gui tests, should be replaced with non-wildcard suppressions race:src/qt/test/* deadlock:src/qt/test/*