2018-04-09 13:06:02 +00:00
|
|
|
#include <boost/test/unit_test.hpp>
|
|
|
|
|
|
2018-10-09 14:17:34 +00:00
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
|
|
2018-04-09 13:06:02 +00:00
|
|
|
#include <signal.h>
|
2018-10-09 14:17:34 +00:00
|
|
|
|
2018-04-09 13:06:02 +00:00
|
|
|
#include <fc/stacktrace.hpp>
|
2018-10-09 14:17:34 +00:00
|
|
|
#include <fc/static_variant.hpp>
|
2018-04-09 13:06:02 +00:00
|
|
|
#include <fc/thread/thread.hpp>
|
|
|
|
|
|
2018-10-09 14:17:34 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
|
2018-04-09 13:06:02 +00:00
|
|
|
BOOST_AUTO_TEST_SUITE(fc_stacktrace)
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(stacktrace_test)
|
|
|
|
|
{
|
|
|
|
|
// print the stack trace
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
fc::print_stacktrace(ss);
|
|
|
|
|
std::string results = ss.str();
|
2018-11-13 21:06:59 +00:00
|
|
|
#if BOOST_VERSION / 100 >= 1065 && !defined(__APPLE__)
|
2018-04-09 13:06:02 +00:00
|
|
|
BOOST_CHECK(!results.empty());
|
|
|
|
|
BOOST_CHECK(results.find("fc::print_stacktrace") != std::string::npos);
|
|
|
|
|
#else
|
|
|
|
|
BOOST_CHECK(results.empty());
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(threaded_stacktrace_test)
|
|
|
|
|
{
|
|
|
|
|
fc::thread test_thread("a_thread");
|
|
|
|
|
std::string results = test_thread.async(
|
|
|
|
|
[] ()->std::string {
|
|
|
|
|
// cause a pause
|
|
|
|
|
for(int i = 0; i < 10000; i++);
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
fc::print_stacktrace(ss);
|
|
|
|
|
return ss.str();
|
|
|
|
|
}
|
|
|
|
|
).wait();
|
2018-11-13 21:06:59 +00:00
|
|
|
#if BOOST_VERSION / 100 >= 1065 && !defined(__APPLE__)
|
2018-04-09 13:06:02 +00:00
|
|
|
BOOST_CHECK(!results.empty());
|
|
|
|
|
BOOST_CHECK(results.find("fc::print_stacktrace") != std::string::npos);
|
|
|
|
|
#else
|
|
|
|
|
BOOST_CHECK(results.empty());
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-13 21:06:59 +00:00
|
|
|
#if BOOST_VERSION / 100 >= 1065 && !defined(__APPLE__)
|
2018-10-09 14:17:34 +00:00
|
|
|
class _svdt_visitor
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
typedef std::string result_type;
|
|
|
|
|
std::string operator()( int64_t i )const
|
|
|
|
|
{
|
|
|
|
|
std::stringstream ss;
|
|
|
|
|
fc::print_stacktrace(ss);
|
|
|
|
|
return ss.str();
|
|
|
|
|
}
|
|
|
|
|
template<typename T>
|
|
|
|
|
std::string operator()( T i )const { return "Unexpected!"; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
BOOST_AUTO_TEST_CASE(static_variant_depth_test)
|
|
|
|
|
{
|
|
|
|
|
int64_t i = 1;
|
|
|
|
|
fc::static_variant<uint8_t,uint16_t,uint32_t,uint64_t,int8_t,int16_t,int32_t,int64_t> test(i);
|
|
|
|
|
|
|
|
|
|
std::string stacktrace = test.visit( _svdt_visitor() );
|
|
|
|
|
//std::cerr << stacktrace << "\n";
|
|
|
|
|
std::vector<std::string> lines;
|
|
|
|
|
boost::split( lines, stacktrace, boost::is_any_of("\n") );
|
|
|
|
|
int count = 0;
|
|
|
|
|
for( const auto& line : lines )
|
|
|
|
|
if( line.find("_svdt_visitor") != std::string::npos ) count++;
|
2018-12-28 19:49:17 +00:00
|
|
|
BOOST_CHECK_LT( 2, count ); // test.visit(), static_variant::visit, function object, visitor
|
2018-10-09 14:17:34 +00:00
|
|
|
BOOST_CHECK_GT( 8, count ); // some is implementation-dependent
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-04-09 13:06:02 +00:00
|
|
|
/* this test causes a segfault on purpose to test the event handler
|
|
|
|
|
BOOST_AUTO_TEST_CASE(cause_segfault)
|
|
|
|
|
{
|
|
|
|
|
fc::print_stacktrace_on_segfault();
|
|
|
|
|
::raise(SIGSEGV);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
BOOST_AUTO_TEST_SUITE_END()
|