diff options
author | Billy Donahue <billy.donahue@mongodb.com> | 2020-03-11 10:28:06 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-03-11 18:04:47 +0000 |
commit | 3a29405624aa378fe395ff2eecd9f5f03b7bf360 (patch) | |
tree | 2a730fe877c7eca8308fe9e8d63d1fe802f60369 /src/mongo/util/stacktrace_test.cpp | |
parent | 521ab081fdbd6a0ba5169f762a78e2158edba86c (diff) | |
download | mongo-3a29405624aa378fe395ff2eecd9f5f03b7bf360.tar.gz |
SERVER-46403 fix regex in stacktrace_test:StackTrace:PosixFormat
Diffstat (limited to 'src/mongo/util/stacktrace_test.cpp')
-rw-r--r-- | src/mongo/util/stacktrace_test.cpp | 37 |
1 files changed, 14 insertions, 23 deletions
diff --git a/src/mongo/util/stacktrace_test.cpp b/src/mongo/util/stacktrace_test.cpp index 0138d642999..4de985fde00 100644 --- a/src/mongo/util/stacktrace_test.cpp +++ b/src/mongo/util/stacktrace_test.cpp @@ -54,7 +54,6 @@ #include "mongo/stdx/condition_variable.h" #include "mongo/stdx/thread.h" #include "mongo/unittest/unittest.h" -#include "mongo/util/debug_util.h" #include "mongo/util/stacktrace.h" #include "mongo/util/stacktrace_json.h" @@ -159,11 +158,6 @@ TEST(StackTrace, PosixFormat) { return; } - if (kDebugBuild) { - // TODO SERVER-46403 will make the regex below work with opt=off dbg=on - return; - } - std::string trace; stack_trace_test_detail::RecursionParam param{3, [&] { StringStackTraceSink sink{trace}; @@ -175,17 +169,22 @@ TEST(StackTrace, PosixFormat) { tlog() << "trace:{" << trace << "}"; } + // Expect log to be a "BACKTRACE:" 1-line record, followed by some "Frame:" lines. + // Each "Frame:" line holds a full json object, but we only examine its "a" field here. std::string jsonLine; - std::string traceBody; - ASSERT_TRUE(pcrecpp::RE(R"re(BACKTRACE: (\{.*\})\n)re" - R"re(((?:.|\n)*))re") - .FullMatch(trace, &jsonLine, &traceBody)) - << "trace: {}"_format(trace); - - if (kSuperVerbose) { - tlog() << "jsonLine:{" << jsonLine << "}"; - tlog() << "traceBody:{" << traceBody << "}"; + std::vector<uintptr_t> humanAddrs; + pcrecpp::StringPiece in{trace}; + static const pcrecpp::RE jsonLineRE(R"re(BACKTRACE: (\{.*\})\n?)re"); + ASSERT_TRUE(jsonLineRE.Consume(&in, &jsonLine)) << "\"" << in.as_string() << "\""; + while (true) { + std::string frameLine; + static const pcrecpp::RE frameRE(R"re( Frame: (\{.*\})\n?)re"); + if (!frameRE.Consume(&in, &frameLine)) + break; + BSONObj frameObj = fromjson(frameLine); // throwy + humanAddrs.push_back(fromHex(frameObj["a"].String())); } + ASSERT_TRUE(in.empty()) << "must be consumed fully: \"" << in.as_string() << "\""; BSONObj jsonObj = fromjson(jsonLine); // throwy ASSERT_TRUE(jsonObj.hasField("backtrace")); @@ -209,14 +208,6 @@ TEST(StackTrace, PosixFormat) { } // Sanity check: make sure all BACKTRACE addrs are represented in the Frame section. - std::vector<uintptr_t> humanAddrs; - - static const pcrecpp::RE re(R"re( Frame: (?:\{"a":"(.*?)",.*\})\n?)re"); - pcrecpp::StringPiece traceBodyPiece(traceBody); - for (uintptr_t addr; re.Consume(&traceBodyPiece, pcrecpp::Hex(&addr));) { - humanAddrs.push_back(addr); - } - std::vector<uintptr_t> btAddrs; for (const auto& btElem : jsonObj["backtrace"].embeddedObject()) { btAddrs.push_back(fromHex(btElem.embeddedObject()["a"].String())); |