diff options
author | Raphael Isemann <teemperor@gmail.com> | 2019-12-23 10:38:12 +0100 |
---|---|---|
committer | Raphael Isemann <teemperor@gmail.com> | 2019-12-23 10:38:25 +0100 |
commit | 5dca0596a959217a1c18858a62ed35245a4c42b4 (patch) | |
tree | 768403f9a80da341579c1e1c682fc240f98033e3 /lldb/unittests/Symbol/TestLineEntry.cpp | |
parent | 70fa4c4f88609044dd0cd9671139d02d578d0df9 (diff) | |
download | bcm5719-llvm-5dca0596a959217a1c18858a62ed35245a4c42b4.tar.gz bcm5719-llvm-5dca0596a959217a1c18858a62ed35245a4c42b4.zip |
[lldb] Add a SubsystemRAII that takes care of calling Initialize and Terminate in the unit tests
Summary:
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.
Reviewers: labath, JDevlieghere, martong, espindola, shafik
Reviewed By: labath
Subscribers: mgorny, rnkovacs, emaste, MaskRay, abidh, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D71630
Diffstat (limited to 'lldb/unittests/Symbol/TestLineEntry.cpp')
-rw-r--r-- | lldb/unittests/Symbol/TestLineEntry.cpp | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/lldb/unittests/Symbol/TestLineEntry.cpp b/lldb/unittests/Symbol/TestLineEntry.cpp index b6325fa115b..cb2adba3ece 100644 --- a/lldb/unittests/Symbol/TestLineEntry.cpp +++ b/lldb/unittests/Symbol/TestLineEntry.cpp @@ -14,6 +14,7 @@ #include "Plugins/ObjectFile/Mach-O/ObjectFileMachO.h" #include "Plugins/SymbolFile/DWARF/DWARFASTParserClang.h" #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h" +#include "TestingSupport/SubsystemRAII.h" #include "TestingSupport/TestUtilities.h" #include "lldb/Symbol/ClangASTContext.h" @@ -31,17 +32,13 @@ using namespace lldb_private; using namespace lldb; class LineEntryTest : public testing::Test { + SubsystemRAII<FileSystem, HostInfo, ObjectFileMachO, SymbolFileDWARF, + ClangASTContext> + subsystem; + public: void SetUp() override; - void TearDown() override { - ClangASTContext::Terminate(); - SymbolFileDWARF::Terminate(); - ObjectFileMachO::Terminate(); - HostInfo::Terminate(); - FileSystem::Terminate(); - } - protected: llvm::Expected<LineEntry> GetLineEntryForLine(uint32_t line); llvm::Optional<TestFile> m_file; @@ -49,11 +46,6 @@ protected: }; void LineEntryTest::SetUp() { - FileSystem::Initialize(); - HostInfo::Initialize(); - ObjectFileMachO::Initialize(); - SymbolFileDWARF::Initialize(); - ClangASTContext::Initialize(); auto ExpectedFile = TestFile::fromYamlFile("inlined-functions.yaml"); ASSERT_THAT_EXPECTED(ExpectedFile, llvm::Succeeded()); m_file.emplace(std::move(*ExpectedFile)); |