Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace BackTrace::print() with the operator<< where the former is used. Signed-off-by: Kefu Chai <kchai@redhat.com>
- Loading branch information
Showing
7 changed files
with
62 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- | ||
// vim: ts=8 sw=2 smarttab | ||
|
||
#include <boost/algorithm/string.hpp> | ||
// std::regex support in libstdc++ 4.8 is incomplete, so let's stick to | ||
// boost::regex now. | ||
#include <boost/regex.hpp> | ||
#include <gtest/gtest.h> | ||
#include <sstream> | ||
#include <string> | ||
|
||
#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<std::string> 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()), 1); | ||
boost::regex e{"^ 1: " | ||
"\\(foo.*\\)\\s" | ||
"\\[0x[[:xdigit:]]+\\]$"}; | ||
EXPECT_TRUE(boost::regex_match(lines[lineno], e)); | ||
} |