diff options
author | James O'Beirne <james.obeirne@gmail.com> | 2019-09-19 13:59:49 -0400 |
---|---|---|
committer | James O'Beirne <james.obeirne@gmail.com> | 2019-11-04 14:13:52 -0500 |
commit | 41edaf227a69bc4846d5996675e8763fdfe0f367 (patch) | |
tree | c32c58d79efd20e311b454c9b360f5d084bc1087 /src/test/logging_tests.cpp | |
parent | 0d86f4d3dacab38f3cd5371d0c920585c178302c (diff) |
logs: add BCLog::Timer and related macros
Makes logging timing information about a block of code easier.
Diffstat (limited to 'src/test/logging_tests.cpp')
-rw-r--r-- | src/test/logging_tests.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/test/logging_tests.cpp b/src/test/logging_tests.cpp new file mode 100644 index 0000000000..eb1826ae8d --- /dev/null +++ b/src/test/logging_tests.cpp @@ -0,0 +1,36 @@ +// Copyright (c) 2019 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 <logging.h> +#include <logging/timer.h> +#include <test/setup_common.h> + +#include <chrono> + +#include <boost/test/unit_test.hpp> + +BOOST_FIXTURE_TEST_SUITE(logging_tests, BasicTestingSetup) + +BOOST_AUTO_TEST_CASE(logging_timer) +{ + + SetMockTime(1); + auto sec_timer = BCLog::Timer<std::chrono::seconds>("tests", "end_msg"); + SetMockTime(2); + BOOST_CHECK_EQUAL(sec_timer.LogMsg("test secs"), "tests: test secs (1.00s)"); + + SetMockTime(1); + auto ms_timer = BCLog::Timer<std::chrono::milliseconds>("tests", "end_msg"); + SetMockTime(2); + BOOST_CHECK_EQUAL(ms_timer.LogMsg("test ms"), "tests: test ms (1000.00ms)"); + + SetMockTime(1); + auto micro_timer = BCLog::Timer<std::chrono::microseconds>("tests", "end_msg"); + SetMockTime(2); + BOOST_CHECK_EQUAL(micro_timer.LogMsg("test micros"), "tests: test micros (1000000.00μs)"); + + SetMockTime(0); +} + +BOOST_AUTO_TEST_SUITE_END() |