summaryrefslogtreecommitdiffstats
path: root/src/test/common/test_back_trace.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-21 11:54:28 +0000
commite6918187568dbd01842d8d1d2c808ce16a894239 (patch)
tree64f88b554b444a49f656b6c656111a145cbbaa28 /src/test/common/test_back_trace.cc
parentInitial commit. (diff)
downloadceph-e6918187568dbd01842d8d1d2c808ce16a894239.tar.xz
ceph-e6918187568dbd01842d8d1d2c808ce16a894239.zip
Adding upstream version 18.2.2.upstream/18.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/common/test_back_trace.cc')
-rw-r--r--src/test/common/test_back_trace.cc44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/test/common/test_back_trace.cc b/src/test/common/test_back_trace.cc
new file mode 100644
index 000000000..97db32686
--- /dev/null
+++ b/src/test/common/test_back_trace.cc
@@ -0,0 +1,44 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+
+#include <boost/algorithm/string.hpp>
+#include <gtest/gtest.h>
+#include <regex>
+#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::ClibBackTrace(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()), 1U);
+ std::regex e{"^ 1: "
+#ifdef __FreeBSD__
+ "<foo.*>\\s"
+ "at\\s.*$"};
+#else
+ "\\(foo.*\\)\\s"
+ "\\[0x[[:xdigit:]]+\\]$"};
+#endif
+ EXPECT_TRUE(std::regex_match(lines[lineno], e));
+}