X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Ftest%2Fcommon%2Ftest_back_trace.cc;fp=src%2Fceph%2Fsrc%2Ftest%2Fcommon%2Ftest_back_trace.cc;h=ff626f5a4c4fd9d218d848b04713b43075edd501;hb=812ff6ca9fcd3e629e49d4328905f33eee8ca3f5;hp=0000000000000000000000000000000000000000;hpb=15280273faafb77777eab341909a3f495cf248d9;p=stor4nfv.git diff --git a/src/ceph/src/test/common/test_back_trace.cc b/src/ceph/src/test/common/test_back_trace.cc new file mode 100644 index 0000000..ff626f5 --- /dev/null +++ b/src/ceph/src/test/common/test_back_trace.cc @@ -0,0 +1,46 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#include +// std::regex support in libstdc++ 4.8 is incomplete, so let's stick to +// boost::regex now. +#include +#include +#include +#include + +#include "common/BackTrace.h" +#include "common/version.h" + +// a dummy function, so we can check "foo" in the backtrace. +// do not mark this function as static or put it into an anonymous namespace, +// otherwise it's function name will be removed in the backtrace. +std::string foo() +{ + std::ostringstream oss; + oss << ceph::BackTrace(1); + return oss.str(); +} + +// a typical backtrace looks like: +// +// ceph version Development (no_version) +// 1: (foo[abi:cxx11]()+0x4a) [0x5562231cf22a] +// 2: (BackTrace_Basic_Test::TestBody()+0x28) [0x5562231cf2fc] +TEST(BackTrace, Basic) { + std::string bt = foo(); + std::vector lines; + boost::split(lines, bt, boost::is_any_of("\n")); + const unsigned lineno = 1; + ASSERT_GT(lines.size(), lineno); + ASSERT_EQ(lines[0].find(pretty_version_to_str()), 1U); + boost::regex e{"^ 1: " +#ifdef __FreeBSD__ + "\\s" + "at\\s.*$"}; +#else + "\\(foo.*\\)\\s" + "\\[0x[[:xdigit:]]+\\]$"}; +#endif + EXPECT_TRUE(boost::regex_match(lines[lineno], e)); +}