llvm-project/lldb/unittests/Host
Raphael Isemann 5dca0596a9 [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
2019-12-23 10:38:25 +01:00
..
linux Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
CMakeLists.txt [Host] File::GetWaitableHandle() should call fileno() 2019-09-23 19:34:26 +00:00
ConnectionFileDescriptorTest.cpp [lldb] Add a SubsystemRAII that takes care of calling Initialize and Terminate in the unit tests 2019-12-23 10:38:25 +01:00
FileActionTest.cpp Fix headers for files added in r353047 2019-02-07 17:16:25 +00:00
FileSystemTest.cpp Convert FileSystem::Open() to return Expected<FileUP> 2019-09-26 17:54:59 +00:00
FileTest.cpp factor out an abstract base class for File 2019-10-03 04:31:46 +00:00
HostInfoTest.cpp [lldb] Add a SubsystemRAII that takes care of calling Initialize and Terminate in the unit tests 2019-12-23 10:38:25 +01:00
HostTest.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
MainLoopTest.cpp [lldb] Add a SubsystemRAII that takes care of calling Initialize and Terminate in the unit tests 2019-12-23 10:38:25 +01:00
NativeProcessProtocolTest.cpp Revert "Revert "Add ReadCStringFromMemory for faster string reads"" 2019-07-23 20:40:37 +00:00
ProcessLaunchInfoTest.cpp Fix headers for files added in r353047 2019-02-07 17:16:25 +00:00
SocketAddressTest.cpp [lldb] Add a SubsystemRAII that takes care of calling Initialize and Terminate in the unit tests 2019-12-23 10:38:25 +01:00
SocketTest.cpp [lldb] Add a SubsystemRAII that takes care of calling Initialize and Terminate in the unit tests 2019-12-23 10:38:25 +01:00
SocketTestUtilities.cpp [lldb/Host] Use cmakedefine01 for LLDB_ENABLE_POSIX 2019-12-13 10:00:59 -08:00
SocketTestUtilities.h [lldb/Host] Use cmakedefine01 for LLDB_ENABLE_POSIX 2019-12-13 10:00:59 -08:00
TaskPoolTest.cpp [lldb] A few minor fixes in TaskPool 2017-11-30 22:56:11 +00:00