diff options
Diffstat (limited to 'tests/test_backtrace.cpp')
-rw-r--r-- | tests/test_backtrace.cpp | 97 |
1 files changed, 46 insertions, 51 deletions
diff --git a/tests/test_backtrace.cpp b/tests/test_backtrace.cpp index 4c6f123f..98257684 100644 --- a/tests/test_backtrace.cpp +++ b/tests/test_backtrace.cpp @@ -2,69 +2,64 @@ #include "test_sink.h" #include "spdlog/async.h" - - - TEST_CASE("bactrace1", "[bactrace]") { - using spdlog::sinks::test_sink_st; - auto test_sink = std::make_shared<test_sink_st>(); - int backtrace_size = 5; + using spdlog::sinks::test_sink_st; + auto test_sink = std::make_shared<test_sink_st>(); + int backtrace_size = 5; - spdlog::logger logger("test-backtrace", test_sink); - logger.set_pattern("%v"); - logger.enable_backtrace(backtrace_size); + spdlog::logger logger("test-backtrace", test_sink); + logger.set_pattern("%v"); + logger.enable_backtrace(backtrace_size); - logger.info("info message"); - for(int i = 0; i < 100; i++) - logger.debug("debug message {}", i); - - REQUIRE(test_sink->lines().size() == 1); - REQUIRE(test_sink->lines()[0] == "info message"); + logger.info("info message"); + for (int i = 0; i < 100; i++) + logger.debug("debug message {}", i); - logger.dump_backtrace(); - REQUIRE(test_sink->lines().size() == backtrace_size +3); - REQUIRE(test_sink->lines()[1] == "****************** Backtrace Start ******************"); - REQUIRE(test_sink->lines()[2] == "debug message 95"); - REQUIRE(test_sink->lines()[3] == "debug message 96"); - REQUIRE(test_sink->lines()[4] == "debug message 97"); - REQUIRE(test_sink->lines()[5] == "debug message 98"); - REQUIRE(test_sink->lines()[6] == "debug message 99"); - REQUIRE(test_sink->lines()[7] == "****************** Backtrace End ********************"); -} + REQUIRE(test_sink->lines().size() == 1); + REQUIRE(test_sink->lines()[0] == "info message"); + logger.dump_backtrace(); + REQUIRE(test_sink->lines().size() == backtrace_size + 3); + REQUIRE(test_sink->lines()[1] == "****************** Backtrace Start ******************"); + REQUIRE(test_sink->lines()[2] == "debug message 95"); + REQUIRE(test_sink->lines()[3] == "debug message 96"); + REQUIRE(test_sink->lines()[4] == "debug message 97"); + REQUIRE(test_sink->lines()[5] == "debug message 98"); + REQUIRE(test_sink->lines()[6] == "debug message 99"); + REQUIRE(test_sink->lines()[7] == "****************** Backtrace End ********************"); +} TEST_CASE("bactrace-async", "[bactrace]") { - using spdlog::sinks::test_sink_mt; - auto test_sink = std::make_shared<test_sink_mt>(); - using spdlog::details::os::sleep_for_millis; + using spdlog::sinks::test_sink_mt; + auto test_sink = std::make_shared<test_sink_mt>(); + using spdlog::details::os::sleep_for_millis; - int backtrace_size = 5; + int backtrace_size = 5; - spdlog::init_thread_pool(120, 1); - auto logger = std::make_shared<spdlog::async_logger>("test-bactrace-async", test_sink, spdlog::thread_pool()); - logger->set_pattern("%v"); - logger->enable_backtrace(backtrace_size); + spdlog::init_thread_pool(120, 1); + auto logger = std::make_shared<spdlog::async_logger>("test-bactrace-async", test_sink, spdlog::thread_pool()); + logger->set_pattern("%v"); + logger->enable_backtrace(backtrace_size); - logger->info("info message"); - for(int i = 0; i < 100; i++) - logger->debug("debug message {}", i); - - sleep_for_millis(10); - REQUIRE(test_sink->lines().size() == 1); - REQUIRE(test_sink->lines()[0] == "info message"); + logger->info("info message"); + for (int i = 0; i < 100; i++) + logger->debug("debug message {}", i); - logger->dump_backtrace(); - sleep_for_millis(100); // give time for the async dump to complete - REQUIRE(test_sink->lines().size() == backtrace_size +3); - REQUIRE(test_sink->lines()[1] == "****************** Backtrace Start ******************"); - REQUIRE(test_sink->lines()[2] == "debug message 95"); - REQUIRE(test_sink->lines()[3] == "debug message 96"); - REQUIRE(test_sink->lines()[4] == "debug message 97"); - REQUIRE(test_sink->lines()[5] == "debug message 98"); - REQUIRE(test_sink->lines()[6] == "debug message 99"); - REQUIRE(test_sink->lines()[7] == "****************** Backtrace End ********************"); -} + sleep_for_millis(10); + REQUIRE(test_sink->lines().size() == 1); + REQUIRE(test_sink->lines()[0] == "info message"); + logger->dump_backtrace(); + sleep_for_millis(100); // give time for the async dump to complete + REQUIRE(test_sink->lines().size() == backtrace_size + 3); + REQUIRE(test_sink->lines()[1] == "****************** Backtrace Start ******************"); + REQUIRE(test_sink->lines()[2] == "debug message 95"); + REQUIRE(test_sink->lines()[3] == "debug message 96"); + REQUIRE(test_sink->lines()[4] == "debug message 97"); + REQUIRE(test_sink->lines()[5] == "debug message 98"); + REQUIRE(test_sink->lines()[6] == "debug message 99"); + REQUIRE(test_sink->lines()[7] == "****************** Backtrace End ********************"); +} |