]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
test/common/test_back_trace: skip one more frame when testing w/ ASan
authorKefu Chai <tchaikov@gmail.com>
Sat, 4 May 2024 03:28:14 +0000 (11:28 +0800)
committerKefu Chai <tchaikov@gmail.com>
Sat, 4 May 2024 03:31:30 +0000 (11:31 +0800)
if ASan is enabled, backtrace() returns one more frame, so we need
to skip one more frame when testing backtrace facility. this change
addresses the following test failure:

```
[ RUN      ] BackTrace.Basic
/home/jenkins-build/build/workspace/ceph-pull-requests/src/test/common/test_back_trace.cc:43: Failure
Value of: std::regex_match(lines[lineno], e)
  Actual: false
Expected: true
[  FAILED  ] BackTrace.Basic (5 ms)
```

it only manifests itself when testing with ASan enabled.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
src/test/common/test_back_trace.cc

index 97db3268671c1aea974fd6f163fddfdf9335a9c9..33ef6afa3ca72e37326a9e5c42f8dc7ae24e7964 100644 (file)
 #include "common/BackTrace.h"
 #include "common/version.h"
 
+#ifndef __has_feature
+#define __has_feature(x) 0
+#endif
+
 // 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;
+  // but if ASan is enabled, backtrace() returns one more frame, and the
+  // backtrace would look like:
+  //
+  // ceph version Development (no_version)
+  // 1: (ceph::ClibBackTrace::ClibBackTrace(int)+0xf5) [0x555555722bf5]
+  // 2: (foo[abi:cxx11]()+0x1fc) [0x555555721b5c]
+  // 3: (BackTrace_Basic_Test::TestBody()+0x2db) [0x55555572208b]
+  //
+  // so we need to skip one more frame
+#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
+  oss << ceph::ClibBackTrace(2);
+#else
   oss << ceph::ClibBackTrace(1);
+#endif
   return oss.str();
 }