From: Kefu Chai Date: Sat, 4 May 2024 03:28:14 +0000 (+0800) Subject: test/common/test_back_trace: skip one more frame when testing w/ ASan X-Git-Tag: testing/wip-pdonnell-testing-20240517.012301-debug~2^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=2f44b3468b21000a4c57458abe9cb639e6581bcc;p=ceph-ci.git test/common/test_back_trace: skip one more frame when testing w/ ASan 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 --- diff --git a/src/test/common/test_back_trace.cc b/src/test/common/test_back_trace.cc index 97db3268671..33ef6afa3ca 100644 --- a/src/test/common/test_back_trace.cc +++ b/src/test/common/test_back_trace.cc @@ -10,13 +10,30 @@ #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(); }