Skip to content

Commit 5742c05

Browse files
[lldb][unittests] Add once_flag to initialization of debugger in testing support (#8141)
* [lldb][unittest] Add call_once flag to initialize debugger (llvm#80786) I tried adding a new unit test to the core test suite (llvm#79533) but it broke the test suite on AArch64 Linux due to hitting an assertion for calling `Debugger::Initialize` more than once. When the unit test suite is invoked as a standalone binary the test suite state is shared, and `Debugger::Initialize` gets called in `DiagnosticEventTest.cpp` before being called in `ProgressReportTest.cpp`. `DiagnosticEventTest.cpp` uses a call_once flag to initialize the debugger but it's local to that test. This commit adds a once_flag to `TestUtilities` so that `Debugger::Initialize` can be called once by the tests that use it. (cherry picked from commit 3885483) * [lldb][unittest] Use shared once_flag in DiagnosticEventTest (llvm#80788) Incorporates the changes from llvm#80786 to use a once_flag from `TestUtilities` instead of a local flag in order to prevent hitting an assertion that the debugger was initialized again in another test. (cherry picked from commit 5690027)
1 parent 9a57599 commit 5742c05

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

lldb/unittests/Core/DiagnosticEventTest.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "Plugins/Platform/MacOSX/PlatformMacOSX.h"
1212
#include "Plugins/Platform/MacOSX/PlatformRemoteMacOSX.h"
1313
#include "TestingSupport/SubsystemRAII.h"
14+
#include "TestingSupport/TestUtilities.h"
1415
#include "lldb/Core/Debugger.h"
1516
#include "lldb/Core/DebuggerEvents.h"
1617
#include "lldb/Host/FileSystem.h"
@@ -26,16 +27,14 @@ using namespace lldb_private::repro;
2627
static const constexpr std::chrono::seconds TIMEOUT(0);
2728
static const constexpr size_t DEBUGGERS = 3;
2829

29-
static std::once_flag debugger_initialize_flag;
30-
3130
namespace {
3231
class DiagnosticEventTest : public ::testing::Test {
3332
public:
3433
void SetUp() override {
3534
FileSystem::Initialize();
3635
HostInfo::Initialize();
3736
PlatformMacOSX::Initialize();
38-
std::call_once(debugger_initialize_flag,
37+
std::call_once(TestUtilities::g_debugger_initialize_flag,
3938
[]() { Debugger::Initialize(nullptr); });
4039
ArchSpec arch("x86_64-apple-macosx-");
4140
Platform::SetHostPlatform(

lldb/unittests/TestingSupport/TestUtilities.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ using namespace lldb_private;
1919

2020
extern const char *TestMainArgv0;
2121

22+
std::once_flag TestUtilities::g_debugger_initialize_flag;
2223
std::string lldb_private::GetInputFilePath(const llvm::Twine &name) {
2324
llvm::SmallString<128> result = llvm::sys::path::parent_path(TestMainArgv0);
2425
llvm::sys::fs::make_absolute(result);

lldb/unittests/TestingSupport/TestUtilities.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
namespace lldb_private {
3232
std::string GetInputFilePath(const llvm::Twine &name);
3333

34+
class TestUtilities {
35+
public:
36+
static std::once_flag g_debugger_initialize_flag;
37+
};
38+
3439
class TestFile {
3540
public:
3641
static llvm::Expected<TestFile> fromYaml(llvm::StringRef Yaml);
@@ -51,6 +56,6 @@ class TestFile {
5156

5257
std::string Buffer;
5358
};
54-
}
59+
} // namespace lldb_private
5560

5661
#endif

0 commit comments

Comments
 (0)