[Lldb-commits] [PATCH] D71630: [lldb] Add a SubsystemRAII that takes care of calling Initialize and Terminate in the unit tests

Raphael Isemann via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Tue Dec 17 14:10:40 PST 2019


teemperor created this revision.
teemperor added reviewers: labath, JDevlieghere.
Herald added subscribers: lldb-commits, abidh, MaskRay, emaste.
Herald added a reviewer: martong.
Herald added a reviewer: espindola.
Herald added a reviewer: shafik.
Herald added a project: LLDB.
teemperor added a comment.
Herald added a subscriber: rnkovacs.

I only converted like 40% of our tests to the new system as I first wanted to get some feedback before I do all the refactoring. Also I'm open to ideas how to name the member (currently I just use `subsystems` without the `m_` prefix as it's not really a real member with any contents).


Many of our tests need to initialize certain subsystems/plugins of LLDB such as
`FileSystem` or `HostInfo` by calling their static `Initialize` functions before the
test starts and then calling `::Terminate` after the test is done (in reverse order).
This adds a lot of error-prone boilerplate code to our testing code.

This patch adds a RAII called SubsystemRAII that ensures that we always call
::Initialize and then call ::Terminate after the test is done (and that the Terminate
calls are always in the reverse order of the ::Initialize calls). It also gets rid of
all of the boilerplate that we had for these calls.

Per-fixture initialization is still not very nice with this approach as it would
require some kind of static unique_ptr that gets manually assigned/reseted
from the gtest SetUpTestCase/TearDownTestCase functions. Because of that
I changed all per-fixture setup to now do per-test setup which can be done
by just having the SubsystemRAII as a member of the test fixture. This change doesn't
influence our normal test runtime as LIT anyway runs each test case separately
(and the Initialize/Terminate calls are anyway not very expensive). It will however
make running all tests in a single executable slightly slower.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D71630

Files:
  lldb/unittests/Core/MangledTest.cpp
  lldb/unittests/Editline/EditlineTest.cpp
  lldb/unittests/Expression/ClangParserTest.cpp
  lldb/unittests/Expression/CppModuleConfigurationTest.cpp
  lldb/unittests/Expression/DWARFExpressionTest.cpp
  lldb/unittests/Host/HostInfoTest.cpp
  lldb/unittests/Interpreter/TestCompletion.cpp
  lldb/unittests/Language/Highlighting/HighlighterTest.cpp
  lldb/unittests/ObjectFile/ELF/TestObjectFileELF.cpp
  lldb/unittests/ObjectFile/PECOFF/TestPECallFrameInfo.cpp
  lldb/unittests/Symbol/TestClangASTImporter.cpp
  lldb/unittests/Symbol/TestDWARFCallFrameInfo.cpp
  lldb/unittests/Symbol/TestLineEntry.cpp
  lldb/unittests/SymbolFile/DWARF/DWARFASTParserClangTests.cpp
  lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
  lldb/unittests/Target/ModuleCacheTest.cpp
  lldb/unittests/TestingSupport/SubsystemRAII.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71630.234381.patch
Type: text/x-patch
Size: 23581 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20191217/adcffdcf/attachment-0001.bin>


More information about the lldb-commits mailing list