mirror of https://github.com/Icinga/icinga2.git
Add a test case for the stack trace formatter
This commit is contained in:
parent
b931194f59
commit
24f6283362
|
@ -16,6 +16,7 @@ set(base_test_SOURCES
|
||||||
base-object-packer.cpp
|
base-object-packer.cpp
|
||||||
base-serialize.cpp
|
base-serialize.cpp
|
||||||
base-shellescape.cpp
|
base-shellescape.cpp
|
||||||
|
base-stacktrace.cpp
|
||||||
base-stream.cpp
|
base-stream.cpp
|
||||||
base-string.cpp
|
base-string.cpp
|
||||||
base-timer.cpp
|
base-timer.cpp
|
||||||
|
@ -89,6 +90,7 @@ add_boost_test(base
|
||||||
base_serialize/object
|
base_serialize/object
|
||||||
base_shellescape/escape_basic
|
base_shellescape/escape_basic
|
||||||
base_shellescape/escape_quoted
|
base_shellescape/escape_quoted
|
||||||
|
base_stacktrace/stacktrace
|
||||||
base_stream/readline_stdio
|
base_stream/readline_stdio
|
||||||
base_string/construct
|
base_string/construct
|
||||||
base_string/equal
|
base_string/equal
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
/* Icinga 2 | (c) 2020 Icinga GmbH | GPLv2+ */
|
||||||
|
|
||||||
|
#include "base/stacktrace.hpp"
|
||||||
|
#include <BoostTestTargetConfig.h>
|
||||||
|
|
||||||
|
using namespace icinga;
|
||||||
|
|
||||||
|
|
||||||
|
#pragma GCC push_options
|
||||||
|
#pragma GCC optimize ("O0")
|
||||||
|
#pragma clang optimize off
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE(base_stacktrace)
|
||||||
|
|
||||||
|
[[gnu::noinline]]
|
||||||
|
void stack_test_func_b()
|
||||||
|
{
|
||||||
|
boost::stacktrace::stacktrace stack;
|
||||||
|
std::ostringstream obuf;
|
||||||
|
obuf << StackTraceFormatter(stack);
|
||||||
|
std::string result = obuf.str();
|
||||||
|
BOOST_CHECK_MESSAGE(!result.empty(), "stack trace must not be empty");
|
||||||
|
size_t pos_a = result.find("stack_test_func_a");
|
||||||
|
size_t pos_b = result.find("stack_test_func_b");
|
||||||
|
BOOST_CHECK_MESSAGE(pos_a != std::string::npos, "'stack_test_func_a' not found\n\n" << result);
|
||||||
|
BOOST_CHECK_MESSAGE(pos_b != std::string::npos, "'stack_test_func_b' not found\n\n" << result);
|
||||||
|
BOOST_CHECK_MESSAGE(pos_a > pos_b, "'stack_test_func_a' must appear after 'stack_test_func_b'\n\n" << result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[gnu::noinline]]
|
||||||
|
void stack_test_func_a()
|
||||||
|
{
|
||||||
|
stack_test_func_b();
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(stacktrace)
|
||||||
|
{
|
||||||
|
stack_test_func_a();
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
||||||
|
#pragma GCC pop_options
|
||||||
|
#pragma clang optimize on
|
Loading…
Reference in New Issue