diff options
| author | Wladimir J. van der Laan <[email protected]> | 2020-01-08 14:43:55 +0100 |
|---|---|---|
| committer | Wladimir J. van der Laan <[email protected]> | 2020-01-08 14:57:32 +0100 |
| commit | 40a495a38a265a86f5a73381635870865d5aa048 (patch) | |
| tree | 7fa2565bfa6231e398277637f06a8fc2bfb2756f /src/test | |
| parent | Merge #17880: build: add -Wdate-time to Werror flags (diff) | |
| parent | test: Show debug log on unit test failure (diff) | |
| download | discoin-40a495a38a265a86f5a73381635870865d5aa048.tar.xz discoin-40a495a38a265a86f5a73381635870865d5aa048.zip | |
Merge #16975: test: Show debug log on unit test failure
fa37e0a68bea65979f9f8f2e5258fe608acf2bdf test: Show debug log on unit test failure (MarcoFalke)
Pull request description:
Often, it is hard to debug unit test failures without the debug log. Especially when the failure happens remotely (e.g. on a ci system).
Fix that by printing the log on failure.
ACKs for top commit:
jamesob:
ACK fa37e0a68bea65979f9f8f2e5258fe608acf2bdf ([`jamesob/ackr/16975.1.MarcoFalke.test_show_debug_log_on_u`](https://github.com/jamesob/bitcoin/tree/ackr/16975.1.MarcoFalke.test_show_debug_log_on_u))
Tree-SHA512: 2ca4150c4ae3d4ad47e03b5e5e70da2baffec928ddef1fdf53a3ebc061f14aee249205387cb1b12ef6d4eb55711ef0080c0b41d9d18000b5da124ca80299793b
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/fuzz/fuzz.cpp | 4 | ||||
| -rw-r--r-- | src/test/main.cpp | 15 | ||||
| -rw-r--r-- | src/test/util/setup_common.cpp | 1 | ||||
| -rw-r--r-- | src/test/util/setup_common.h | 3 |
4 files changed, 23 insertions, 0 deletions
diff --git a/src/test/fuzz/fuzz.cpp b/src/test/fuzz/fuzz.cpp index da4e623e9..a6ab620e2 100644 --- a/src/test/fuzz/fuzz.cpp +++ b/src/test/fuzz/fuzz.cpp @@ -4,10 +4,14 @@ #include <test/fuzz/fuzz.h> +#include <test/util/setup_common.h> + #include <cstdint> #include <unistd.h> #include <vector> +const std::function<void(const std::string&)> G_TEST_LOG_FUN{}; + static bool read_stdin(std::vector<uint8_t>& data) { uint8_t buffer[1024]; diff --git a/src/test/main.cpp b/src/test/main.cpp index ff3f36b56..e6529949e 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 <boost/test/unit_test.hpp> + +#include <test/util/setup_common.h> + +/** Redirect debug log to boost log */ +const std::function<void(const std::string&)> 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 3bdf3485f..ccb3064d5 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 1e2e059a5..6741be848 100644 --- a/src/test/util/setup_common.h +++ b/src/test/util/setup_common.h @@ -18,6 +18,9 @@ #include <boost/thread.hpp> +/** This is connected to the logger. Can be used to redirect logs to any other log */ +extern const std::function<void(const std::string&)> G_TEST_LOG_FUN; + // Enable BOOST_CHECK_EQUAL for enum class types template <typename T> std::ostream& operator<<(typename std::enable_if<std::is_enum<T>::value, std::ostream>::type& stream, const T& e) |