Line data Source code
1 : #include "artdaq-core/Utilities/ExceptionStackTrace.hh"
2 :
3 : #define BOOST_TEST_MODULE ExceptionStackTrace_t
4 : #include "cetlib/quiet_unit_test.hpp"
5 :
6 : #define TRACE_NAME "ExceptionStackTrace_t"
7 : #include "TRACE/tracemf.h"
8 :
9 : BOOST_AUTO_TEST_SUITE(ExceptionStackTrace_test)
10 :
11 : /**
12 : * @brief Print the Exception Stack Trace
13 : */
14 1 : void PrintExceptionStackTrace()
15 : {
16 1 : auto message = artdaq::debug::getStackTraceCollector().print_stacktrace();
17 :
18 1 : std::string::size_type pos = 0;
19 1 : std::string::size_type prev = 0;
20 :
21 18 : while ((pos = message.find('\n', prev)) != std::string::npos)
22 : {
23 51 : TLOG(TLVL_DEBUG) << message.substr(prev, pos - prev);
24 17 : prev = pos + 1;
25 : }
26 :
27 3 : TLOG(TLVL_DEBUG) << message.substr(prev);
28 1 : }
29 :
30 2 : BOOST_AUTO_TEST_CASE(PrintStackTrace)
31 : {
32 : try
33 : {
34 1 : throw int(5);
35 : }
36 1 : catch (int)
37 : {
38 1 : PrintExceptionStackTrace();
39 1 : }
40 1 : }
41 :
42 : BOOST_AUTO_TEST_SUITE_END()
|