[Lldb-commits] [lldb] [lldb][unittest] Add call_once flag to initialize debugger (PR #80786)
Chelsea Cassanova via lldb-commits
lldb-commits at lists.llvm.org
Mon Feb 5 18:47:15 PST 2024
https://github.com/chelcassanova created https://github.com/llvm/llvm-project/pull/80786
I tried adding a new unit test to the core test
suite (https://github.com/llvm/llvm-project/pull/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.
>From 2fa99391c097def91369c164195ad2a4a1cd98ed Mon Sep 17 00:00:00 2001
From: Chelsea Cassanova <chelsea_cassanova at apple.com>
Date: Mon, 5 Feb 2024 18:41:14 -0800
Subject: [PATCH] [lldb][unittest] Add call_once flag to initialize debugger
I tried adding a new unit test to the core test
suite (https://github.com/llvm/llvm-project/pull/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.
---
lldb/unittests/TestingSupport/TestUtilities.cpp | 1 +
lldb/unittests/TestingSupport/TestUtilities.h | 7 ++++++-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/lldb/unittests/TestingSupport/TestUtilities.cpp b/lldb/unittests/TestingSupport/TestUtilities.cpp
index 9e5523e4875479..507241404c08d8 100644
--- a/lldb/unittests/TestingSupport/TestUtilities.cpp
+++ b/lldb/unittests/TestingSupport/TestUtilities.cpp
@@ -19,6 +19,7 @@ using namespace lldb_private;
extern const char *TestMainArgv0;
+std::once_flag TestUtilities::debugger_initialize_flag;
std::string lldb_private::GetInputFilePath(const llvm::Twine &name) {
llvm::SmallString<128> result = llvm::sys::path::parent_path(TestMainArgv0);
llvm::sys::fs::make_absolute(result);
diff --git a/lldb/unittests/TestingSupport/TestUtilities.h b/lldb/unittests/TestingSupport/TestUtilities.h
index 811c4c1521269b..99e569bfa52507 100644
--- a/lldb/unittests/TestingSupport/TestUtilities.h
+++ b/lldb/unittests/TestingSupport/TestUtilities.h
@@ -31,6 +31,11 @@
namespace lldb_private {
std::string GetInputFilePath(const llvm::Twine &name);
+class TestUtilities {
+ public:
+ static std::once_flag debugger_initialize_flag;
+};
+
class TestFile {
public:
static llvm::Expected<TestFile> fromYaml(llvm::StringRef Yaml);
@@ -51,6 +56,6 @@ class TestFile {
std::string Buffer;
};
-}
+} // namespace lldb_private
#endif
More information about the lldb-commits
mailing list