Skip to content

Commit fcb2eb7

Browse files
authored
Merge pull request ceph#57260 from tchaikov/test_back_trace-with-asan
test/common/test_back_trace: skip one more frame when testing w/ ASan Reviewed-by: Radoslaw Zarzynski <[email protected]>
2 parents 84484c0 + 2f44b34 commit fcb2eb7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/test/common/test_back_trace.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,30 @@
1010
#include "common/BackTrace.h"
1111
#include "common/version.h"
1212

13+
#ifndef __has_feature
14+
#define __has_feature(x) 0
15+
#endif
16+
1317
// a dummy function, so we can check "foo" in the backtrace.
1418
// do not mark this function as static or put it into an anonymous namespace,
1519
// otherwise it's function name will be removed in the backtrace.
1620
std::string foo()
1721
{
1822
std::ostringstream oss;
23+
// but if ASan is enabled, backtrace() returns one more frame, and the
24+
// backtrace would look like:
25+
//
26+
// ceph version Development (no_version)
27+
// 1: (ceph::ClibBackTrace::ClibBackTrace(int)+0xf5) [0x555555722bf5]
28+
// 2: (foo[abi:cxx11]()+0x1fc) [0x555555721b5c]
29+
// 3: (BackTrace_Basic_Test::TestBody()+0x2db) [0x55555572208b]
30+
//
31+
// so we need to skip one more frame
32+
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
33+
oss << ceph::ClibBackTrace(2);
34+
#else
1935
oss << ceph::ClibBackTrace(1);
36+
#endif
2037
return oss.str();
2138
}
2239

0 commit comments

Comments
 (0)