[Lldb-commits] [PATCH] D133628: [lldb/test][TestingSupport] Add a helper class to send all LLDB logs to stderr in unit tests.
Jordan Rupprecht via Phabricator via lldb-commits
lldb-commits at lists.llvm.org
Fri Sep 9 19:20:57 PDT 2022
rupprecht created this revision.
Herald added a subscriber: mgorny.
Herald added a project: All.
rupprecht requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.
This helper class can be useful to see what `LLDB_LOG` messages are happening when debugging the LLDB C++ unit tests. It isn't pretty, but on the other hand, it's meant for temporary debugging and not something one would want to check in anyway, so maybe that's OK.
This can be used like so:
TEST(FooTest, HasABug) {
Func1(); // LLDB_LOG statements this makes won't go anywhere
{
auto logger = TestStderrLogger::Scoped(LLDBLog::AST | LLDBLog::Breakpoints);
Func2(); // Now they'll go to stderr.
}
Func3(); // Now they go nowhere again.
}
It can be created in a way that mirrors `GetLog()` calls, i.e. deducing from the enum, or by directly using the strings that are registered.
Right now this only works for the LLDBLog enum, but it should be trivial to add more. I don't know of a good generic way to handle arbitrary enums.
I was able to use this to debug a flaky unit test that was failing ~1/100 times, so my approach was to enable logs and compare good vs bad log methods. I didn't find an easier way than this helper class.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D133628
Files:
lldb/unittests/TestingSupport/CMakeLists.txt
lldb/unittests/TestingSupport/TestStderrLogger.cpp
lldb/unittests/TestingSupport/TestStderrLogger.h
lldb/unittests/TestingSupport/tests/CMakeLists.txt
lldb/unittests/TestingSupport/tests/TestStderrLoggerTest.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133628.459244.patch
Type: text/x-patch
Size: 9277 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220910/bbffef7a/attachment-0001.bin>
More information about the lldb-commits
mailing list