]>
git.proxmox.com Git - ceph.git/blob - ceph/src/test/common/test_back_trace.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include <boost/algorithm/string.hpp>
5 // std::regex support in libstdc++ 4.8 is incomplete, so let's stick to
7 #include <boost/regex.hpp>
8 #include <gtest/gtest.h>
12 #include "common/BackTrace.h"
13 #include "common/version.h"
15 // a dummy function, so we can check "foo" in the backtrace.
16 // do not mark this function as static or put it into an anonymous namespace,
17 // otherwise it's function name will be removed in the backtrace.
20 std::ostringstream oss
;
21 oss
<< ceph::BackTrace(1);
25 // a typical backtrace looks like:
27 // ceph version Development (no_version)
28 // 1: (foo[abi:cxx11]()+0x4a) [0x5562231cf22a]
29 // 2: (BackTrace_Basic_Test::TestBody()+0x28) [0x5562231cf2fc]
30 TEST(BackTrace
, Basic
) {
31 std::string bt
= foo();
32 std::vector
<std::string
> lines
;
33 boost::split(lines
, bt
, boost::is_any_of("\n"));
34 const unsigned lineno
= 1;
35 ASSERT_GT(lines
.size(), lineno
);
36 ASSERT_EQ(lines
[0].find(pretty_version_to_str()), 1U);
37 boost::regex e
{"^ 1: "
43 "\\[0x[[:xdigit:]]+\\]$"};
45 EXPECT_TRUE(boost::regex_match(lines
[lineno
], e
));