[llvm-branch-commits] [lldb] 26ebfac - Revert "[lldb] Consolidating platform support checks in tests. (#184656)"
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Mar 12 02:58:50 PDT 2026
Author: David Spickett
Date: 2026-03-12T09:58:47Z
New Revision: 26ebfac2ce244b5bdcf10fc48fda5ce8de827c88
URL: https://github.com/llvm/llvm-project/commit/26ebfac2ce244b5bdcf10fc48fda5ce8de827c88
DIFF: https://github.com/llvm/llvm-project/commit/26ebfac2ce244b5bdcf10fc48fda5ce8de827c88.diff
LOG: Revert "[lldb] Consolidating platform support checks in tests. (#184656)"
This reverts commit 08cef699c4bb2e5236393d73e8ce05ad08a4ccca.
Added:
Modified:
lldb/unittests/DAP/DAPTest.cpp
lldb/unittests/DAP/Handler/DisconnectTest.cpp
lldb/unittests/DAP/TestBase.cpp
lldb/unittests/DAP/TestBase.h
lldb/unittests/DAP/VariablesTest.cpp
lldb/unittests/TestingSupport/TestUtilities.cpp
lldb/unittests/TestingSupport/TestUtilities.h
Removed:
lldb/unittests/DAP/TestUtilities.h
################################################################################
diff --git a/lldb/unittests/DAP/DAPTest.cpp b/lldb/unittests/DAP/DAPTest.cpp
index fcc8ff25446ff..4fd6cd546e6fa 100644
--- a/lldb/unittests/DAP/DAPTest.cpp
+++ b/lldb/unittests/DAP/DAPTest.cpp
@@ -1,4 +1,4 @@
-//===----------------------------------------------------------------------===//
+//===-- DAPTest.cpp -------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -9,7 +9,6 @@
#include "DAP.h"
#include "Protocol/ProtocolBase.h"
#include "TestBase.h"
-#include "TestUtilities.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <optional>
diff --git a/lldb/unittests/DAP/Handler/DisconnectTest.cpp b/lldb/unittests/DAP/Handler/DisconnectTest.cpp
index 10e1b1ef7b5ab..212c5698feea8 100644
--- a/lldb/unittests/DAP/Handler/DisconnectTest.cpp
+++ b/lldb/unittests/DAP/Handler/DisconnectTest.cpp
@@ -8,9 +8,8 @@
#include "DAP.h"
#include "Handler/RequestHandler.h"
+#include "Protocol/ProtocolBase.h"
#include "TestBase.h"
-#include "TestUtilities.h"
-#include "TestingSupport/TestUtilities.h"
#include "lldb/API/SBDefines.h"
#include "lldb/lldb-enumerations.h"
#include "llvm/Testing/Support/Error.h"
@@ -38,10 +37,12 @@ TEST_F(DisconnectRequestHandlerTest, DisconnectTriggersTerminated) {
// Is flaky on Linux, see https://github.com/llvm/llvm-project/issues/154763.
#ifndef __linux__
TEST_F(DisconnectRequestHandlerTest, DisconnectTriggersTerminateCommands) {
- SKIP_IF_LLVM_TARGET_MISSING("X86");
+ CreateDebugger();
- ConfigureDebugger();
- LoadCore(k_linux_x86_64_binary, k_linux_x86_64_core);
+ if (!GetDebuggerSupportsTarget("X86"))
+ GTEST_SKIP() << "Unsupported platform";
+
+ LoadCore();
DisconnectRequestHandler handler(*dap);
diff --git a/lldb/unittests/DAP/TestBase.cpp b/lldb/unittests/DAP/TestBase.cpp
index cb9596e6f1637..6073aa82a8eb7 100644
--- a/lldb/unittests/DAP/TestBase.cpp
+++ b/lldb/unittests/DAP/TestBase.cpp
@@ -1,4 +1,4 @@
-//===----------------------------------------------------------------------===//
+//===-- TestBase.cpp ------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -13,6 +13,7 @@
#include "Handler/ResponseHandler.h"
#include "TestingSupport/TestUtilities.h"
#include "lldb/API/SBDefines.h"
+#include "lldb/API/SBStructuredData.h"
#include "lldb/Host/MainLoop.h"
#include "lldb/Host/Pipe.h"
#include "llvm/ADT/StringRef.h"
@@ -69,11 +70,26 @@ void DAPTestBase::SetUpTestSuite() {
lldb::SBError error = SBDebugger::InitializeWithErrorHandling();
EXPECT_TRUE(error.Success());
}
-
void DAPTestBase::TearDownTestSuite() { SBDebugger::Terminate(); }
-void DAPTestBase::ConfigureDebugger() {
- dap->debugger = lldb::SBDebugger::Create(/*source_init_files=*/false);
+bool DAPTestBase::GetDebuggerSupportsTarget(StringRef platform) {
+ EXPECT_TRUE(dap->debugger);
+
+ lldb::SBStructuredData data = dap->debugger.GetBuildConfiguration()
+ .GetValueForKey("targets")
+ .GetValueForKey("value");
+ for (size_t i = 0; i < data.GetSize(); i++) {
+ char buf[100] = {0};
+ size_t size = data.GetItemAtIndex(i).GetStringValue(buf, sizeof(buf));
+ if (StringRef(buf, size) == platform)
+ return true;
+ }
+
+ return false;
+}
+
+void DAPTestBase::CreateDebugger() {
+ dap->debugger = lldb::SBDebugger::Create();
ASSERT_TRUE(dap->debugger);
dap->target = dap->debugger.GetDummyTarget();
@@ -95,8 +111,24 @@ void DAPTestBase::ConfigureDebugger() {
dap->debugger.SetErrorFile(lldb::SBFile(*err_fd, "w", false));
}
-void DAPTestBase::LoadCore(llvm::StringRef binary_path,
- llvm::StringRef core_path) {
- std::tie(dap->target, process) =
- lldb_private::LoadCore(dap->debugger, binary_path, core_path);
+void DAPTestBase::LoadCore() {
+ ASSERT_TRUE(dap->debugger);
+ llvm::Expected<lldb_private::TestFile> binary_yaml =
+ lldb_private::TestFile::fromYamlFile(k_linux_binary);
+ ASSERT_THAT_EXPECTED(binary_yaml, Succeeded());
+ llvm::Expected<llvm::sys::fs::TempFile> binary_file =
+ binary_yaml->writeToTemporaryFile();
+ ASSERT_THAT_EXPECTED(binary_file, Succeeded());
+ binary = std::move(*binary_file);
+ dap->target = dap->debugger.CreateTarget(binary->TmpName.data());
+ ASSERT_TRUE(dap->target);
+ llvm::Expected<lldb_private::TestFile> core_yaml =
+ lldb_private::TestFile::fromYamlFile(k_linux_core);
+ ASSERT_THAT_EXPECTED(core_yaml, Succeeded());
+ llvm::Expected<llvm::sys::fs::TempFile> core_file =
+ core_yaml->writeToTemporaryFile();
+ ASSERT_THAT_EXPECTED(core_file, Succeeded());
+ this->core = std::move(*core_file);
+ SBProcess process = dap->target.LoadCore(this->core->TmpName.data());
+ ASSERT_TRUE(process);
}
diff --git a/lldb/unittests/DAP/TestBase.h b/lldb/unittests/DAP/TestBase.h
index ec5595bd61971..7953e0fabfbe5 100644
--- a/lldb/unittests/DAP/TestBase.h
+++ b/lldb/unittests/DAP/TestBase.h
@@ -10,18 +10,44 @@
#include "DAPLog.h"
#include "Handler/RequestHandler.h"
#include "Handler/ResponseHandler.h"
+#include "Protocol/ProtocolBase.h"
#include "TestingSupport/Host/JSONTransportTestUtilities.h"
#include "TestingSupport/SubsystemRAII.h"
#include "Transport.h"
#include "lldb/Host/FileSystem.h"
#include "lldb/Host/HostInfo.h"
#include "lldb/Host/MainLoop.h"
+#include "lldb/Host/MainLoopBase.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/JSON.h"
+#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <memory>
#include <optional>
+/// Helpers for gtest printing.
+namespace lldb_dap::protocol {
+
+inline void PrintTo(const Request &req, std::ostream *os) {
+ *os << llvm::formatv("{0}", toJSON(req)).str();
+}
+
+inline void PrintTo(const Response &resp, std::ostream *os) {
+ *os << llvm::formatv("{0}", toJSON(resp)).str();
+}
+
+inline void PrintTo(const Event &evt, std::ostream *os) {
+ *os << llvm::formatv("{0}", toJSON(evt)).str();
+}
+
+inline void PrintTo(const Message &message, std::ostream *os) {
+ return std::visit([os](auto &&message) { return PrintTo(message, os); },
+ message);
+}
+
+} // namespace lldb_dap::protocol
+
namespace lldb_dap_tests {
using TestDAPTransport = TestTransport<lldb_dap::ProtocolDescriptor>;
@@ -48,20 +74,47 @@ class TransportBase : public testing::Test {
void Run();
};
+/// A matcher for a DAP event.
+template <typename EventMatcher, typename BodyMatcher>
+inline testing::Matcher<const lldb_dap::protocol::Event &>
+IsEvent(const EventMatcher &event_matcher, const BodyMatcher &body_matcher) {
+ return testing::AllOf(
+ testing::Field(&lldb_dap::protocol::Event::event, event_matcher),
+ testing::Field(&lldb_dap::protocol::Event::body, body_matcher));
+}
+
+template <typename EventMatcher>
+inline testing::Matcher<const lldb_dap::protocol::Event &>
+IsEvent(const EventMatcher &event_matcher) {
+ return testing::AllOf(
+ testing::Field(&lldb_dap::protocol::Event::event, event_matcher),
+ testing::Field(&lldb_dap::protocol::Event::body, std::nullopt));
+}
+
+/// Matches an "output" event.
+inline auto Output(llvm::StringRef o, llvm::StringRef cat = "console") {
+ return IsEvent("output",
+ testing::Optional(llvm::json::Value(
+ llvm::json::Object{{"category", cat}, {"output", o}})));
+}
+
/// A base class for tests that interact with a `lldb_dap::DAP` instance.
class DAPTestBase : public TransportBase {
protected:
std::optional<llvm::sys::fs::TempFile> core;
std::optional<llvm::sys::fs::TempFile> binary;
- lldb::SBProcess process;
+
+ static constexpr llvm::StringLiteral k_linux_binary = "linux-x86_64.out.yaml";
+ static constexpr llvm::StringLiteral k_linux_core = "linux-x86_64.core.yaml";
static void SetUpTestSuite();
static void TearDownTestSuite();
void SetUp() override;
void TearDown() override;
- void ConfigureDebugger();
- void LoadCore(llvm::StringRef binary_path, llvm::StringRef core_path);
+ bool GetDebuggerSupportsTarget(llvm::StringRef platform);
+ void CreateDebugger();
+ void LoadCore();
};
} // namespace lldb_dap_tests
diff --git a/lldb/unittests/DAP/TestUtilities.h b/lldb/unittests/DAP/TestUtilities.h
deleted file mode 100644
index 5b652534cd091..0000000000000
--- a/lldb/unittests/DAP/TestUtilities.h
+++ /dev/null
@@ -1,69 +0,0 @@
-//===----------------------------------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-
-#include "Protocol/ProtocolBase.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/Support/JSON.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
-#include <optional>
-
-/// Helpers for gtest printing.
-namespace lldb_dap::protocol {
-
-inline void PrintTo(const Request &req, std::ostream *os) {
- *os << llvm::formatv("{0}", toJSON(req)).str();
-}
-
-inline void PrintTo(const Response &resp, std::ostream *os) {
- *os << llvm::formatv("{0}", toJSON(resp)).str();
-}
-
-inline void PrintTo(const Event &evt, std::ostream *os) {
- *os << llvm::formatv("{0}", toJSON(evt)).str();
-}
-
-inline void PrintTo(const Message &message, std::ostream *os) {
- return std::visit([os](auto &&message) { return PrintTo(message, os); },
- message);
-}
-
-} // namespace lldb_dap::protocol
-
-namespace lldb_dap_tests {
-
-static constexpr llvm::StringLiteral k_linux_x86_64_binary =
- "linux-x86_64.out.yaml";
-static constexpr llvm::StringLiteral k_linux_x86_64_core =
- "linux-x86_64.core.yaml";
-
-/// A matcher for a DAP event.
-template <typename EventMatcher, typename BodyMatcher>
-inline testing::Matcher<const lldb_dap::protocol::Event &>
-IsEvent(const EventMatcher &event_matcher, const BodyMatcher &body_matcher) {
- return testing::AllOf(
- testing::Field(&lldb_dap::protocol::Event::event, event_matcher),
- testing::Field(&lldb_dap::protocol::Event::body, body_matcher));
-}
-
-template <typename EventMatcher>
-inline testing::Matcher<const lldb_dap::protocol::Event &>
-IsEvent(const EventMatcher &event_matcher) {
- return testing::AllOf(
- testing::Field(&lldb_dap::protocol::Event::event, event_matcher),
- testing::Field(&lldb_dap::protocol::Event::body, std::nullopt));
-}
-
-/// Matches an "output" event.
-inline auto Output(llvm::StringRef o, llvm::StringRef cat = "console") {
- return IsEvent("output",
- testing::Optional(llvm::json::Value(
- llvm::json::Object{{"category", cat}, {"output", o}})));
-}
-
-} // namespace lldb_dap_tests
diff --git a/lldb/unittests/DAP/VariablesTest.cpp b/lldb/unittests/DAP/VariablesTest.cpp
index 03f5cbf9cccb5..fe85e92a7fee2 100644
--- a/lldb/unittests/DAP/VariablesTest.cpp
+++ b/lldb/unittests/DAP/VariablesTest.cpp
@@ -10,7 +10,6 @@
#include "DAPLog.h"
#include "Protocol/DAPTypes.h"
#include "Protocol/ProtocolTypes.h"
-#include "TestUtilities.h"
#include "TestingSupport/TestUtilities.h"
#include "lldb/API/SBDebugger.h"
#include "lldb/API/SBFrame.h"
@@ -18,17 +17,13 @@
#include "lldb/API/SBValue.h"
#include "llvm/Testing/Support/Error.h"
#include "gtest/gtest.h"
+#include <optional>
using namespace llvm;
using namespace lldb;
using namespace lldb_dap;
-using namespace lldb_dap_tests;
using namespace lldb_dap::protocol;
-static lldb::SBDebugger CreateDebugger() {
- return lldb::SBDebugger::Create(/*source_init_files*/ false);
-}
-
class VariablesTest : public ::testing::Test {
public:
@@ -41,6 +36,10 @@ class VariablesTest : public ::testing::Test {
static void TearDownTestSuite() { SBDebugger::Terminate(); }
void TearDown() override {
+ if (core)
+ ASSERT_THAT_ERROR(core->discard(), Succeeded());
+ if (binary)
+ ASSERT_THAT_ERROR(binary->discard(), Succeeded());
if (debugger)
debugger.Clear();
}
@@ -54,6 +53,39 @@ class VariablesTest : public ::testing::Test {
lldb::SBTarget target;
lldb::SBProcess process;
+ static constexpr llvm::StringLiteral k_binary = "linux-x86_64.out.yaml";
+ static constexpr llvm::StringLiteral k_core = "linux-x86_64.core.yaml";
+
+ std::optional<llvm::sys::fs::TempFile> core;
+ std::optional<llvm::sys::fs::TempFile> binary;
+
+ void CreateDebugger() { debugger = lldb::SBDebugger::Create(); }
+
+ void LoadCore() {
+ ASSERT_TRUE(debugger);
+
+ llvm::Expected<lldb_private::TestFile> binary_yaml =
+ lldb_private::TestFile::fromYamlFile(k_binary);
+ ASSERT_THAT_EXPECTED(binary_yaml, Succeeded());
+ llvm::Expected<llvm::sys::fs::TempFile> binary_file =
+ binary_yaml->writeToTemporaryFile();
+ ASSERT_THAT_EXPECTED(binary_file, Succeeded());
+ binary = std::move(*binary_file);
+ target = debugger.CreateTarget(binary->TmpName.data());
+ ASSERT_TRUE(target);
+ debugger.SetSelectedTarget(target);
+
+ llvm::Expected<lldb_private::TestFile> core_yaml =
+ lldb_private::TestFile::fromYamlFile(k_core);
+ ASSERT_THAT_EXPECTED(core_yaml, Succeeded());
+ llvm::Expected<llvm::sys::fs::TempFile> core_file =
+ core_yaml->writeToTemporaryFile();
+ ASSERT_THAT_EXPECTED(core_file, Succeeded());
+ this->core = std::move(*core_file);
+ process = target.LoadCore(this->core->TmpName.data());
+ ASSERT_TRUE(process);
+ }
+
static const protocol::Scope *
FindScope(const std::vector<protocol::Scope> &scopes,
const protocol::String &name) {
@@ -66,11 +98,8 @@ class VariablesTest : public ::testing::Test {
};
TEST_F(VariablesTest, GetNewVariableReference_UniqueAndRanges) {
- SKIP_IF_LLVM_TARGET_MISSING("X86");
-
- debugger = CreateDebugger();
- std::tie(target, process) = lldb_private::LoadCore(
- debugger, k_linux_x86_64_binary, k_linux_x86_64_core);
+ CreateDebugger();
+ LoadCore();
auto x15 = target.CreateValueFromExpression("x", "15");
auto y42 = target.CreateValueFromExpression("y", "42");
auto gzero = target.CreateValueFromExpression("$0", "42");
@@ -120,12 +149,8 @@ TEST_F(VariablesTest, Clear_RemovesTemporaryKeepsPermanent) {
}
TEST_F(VariablesTest, VariablesStore) {
- SKIP_IF_LLVM_TARGET_MISSING("X86");
-
- debugger = CreateDebugger();
- std::tie(target, process) = lldb_private::LoadCore(
- debugger, k_linux_x86_64_binary, k_linux_x86_64_core);
-
+ CreateDebugger();
+ LoadCore();
lldb::SBFrame frame = process.GetSelectedThread().GetSelectedFrame();
std::vector<protocol::Scope> scopes = vars.Insert(frame);
diff --git a/lldb/unittests/TestingSupport/TestUtilities.cpp b/lldb/unittests/TestingSupport/TestUtilities.cpp
index 13092742a4347..d164c227afb9e 100644
--- a/lldb/unittests/TestingSupport/TestUtilities.cpp
+++ b/lldb/unittests/TestingSupport/TestUtilities.cpp
@@ -7,16 +7,13 @@
//===----------------------------------------------------------------------===//
#include "TestUtilities.h"
-#include "lldb/API/SBStructuredData.h"
-#include "lldb/API/SBTarget.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ObjectYAML/yaml2obj.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/Program.h"
#include "llvm/Support/YAMLTraits.h"
-#include "llvm/Testing/Support/Error.h"
#include "gtest/gtest.h"
-#include <utility>
using namespace lldb_private;
@@ -64,51 +61,3 @@ llvm::Expected<llvm::sys::fs::TempFile> TestFile::writeToTemporaryFile() {
llvm::raw_fd_ostream(Temp->FD, /*shouldClose=*/false) << Buffer;
return std::move(*Temp);
}
-
-bool lldb_private::DebuggerSupportsLLVMTarget(llvm::StringRef target) {
- lldb::SBStructuredData data = lldb::SBDebugger::GetBuildConfiguration()
- .GetValueForKey("targets")
- .GetValueForKey("value");
- for (size_t i = 0; i < data.GetSize(); i++) {
- char buf[100] = {0};
- size_t size = data.GetItemAtIndex(i).GetStringValue(buf, sizeof(buf));
- if (llvm::StringRef(buf, size) == target)
- return true;
- }
-
- return false;
-}
-
-std::pair<lldb::SBTarget, lldb::SBProcess>
-lldb_private::LoadCore(lldb::SBDebugger &debugger, llvm::StringRef binary_path,
- llvm::StringRef core_path) {
- EXPECT_TRUE(debugger);
-
- llvm::Expected<lldb_private::TestFile> binary_yaml =
- lldb_private::TestFile::fromYamlFile(binary_path);
- EXPECT_THAT_EXPECTED(binary_yaml, llvm::Succeeded());
- llvm::Expected<llvm::sys::fs::TempFile> binary_file =
- binary_yaml->writeToTemporaryFile();
- EXPECT_THAT_EXPECTED(binary_file, llvm::Succeeded());
- lldb::SBError error;
- lldb::SBTarget target = debugger.CreateTarget(
- /*filename=*/binary_file->TmpName.data(), /*target_triple=*/"",
- /*platform_name=*/"", /*add_dependent_modules=*/false, /*error=*/error);
- EXPECT_TRUE(target);
- EXPECT_TRUE(error.Success()) << error.GetCString();
- debugger.SetSelectedTarget(target);
-
- llvm::Expected<lldb_private::TestFile> core_yaml =
- lldb_private::TestFile::fromYamlFile(core_path);
- EXPECT_THAT_EXPECTED(core_yaml, llvm::Succeeded());
- llvm::Expected<llvm::sys::fs::TempFile> core_file =
- core_yaml->writeToTemporaryFile();
- EXPECT_THAT_EXPECTED(core_file, llvm::Succeeded());
- lldb::SBProcess process = target.LoadCore(core_file->TmpName.data());
- EXPECT_TRUE(process);
-
- EXPECT_THAT_ERROR(binary_file->discard(), llvm::Succeeded());
- EXPECT_THAT_ERROR(core_file->discard(), llvm::Succeeded());
-
- return std::make_pair(target, process);
-}
diff --git a/lldb/unittests/TestingSupport/TestUtilities.h b/lldb/unittests/TestingSupport/TestUtilities.h
index 01ecc15c9606d..68b4dbc127a7d 100644
--- a/lldb/unittests/TestingSupport/TestUtilities.h
+++ b/lldb/unittests/TestingSupport/TestUtilities.h
@@ -9,7 +9,6 @@
#ifndef LLDB_UNITTESTS_TESTINGSUPPORT_TESTUTILITIES_H
#define LLDB_UNITTESTS_TESTINGSUPPORT_TESTUTILITIES_H
-#include "lldb/API/SBDebugger.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Utility/DataBuffer.h"
#include "llvm/ADT/Twine.h"
@@ -17,7 +16,6 @@
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/JSON.h"
#include "llvm/Support/raw_ostream.h"
-#include "gtest/gtest.h"
#include <string>
#define ASSERT_NO_ERROR(x) \
@@ -67,25 +65,12 @@ class TestFile {
std::string Buffer;
};
-/// Check if the debugger supports the given platform.
-bool DebuggerSupportsLLVMTarget(llvm::StringRef target);
-
-#define SKIP_IF_LLVM_TARGET_MISSING(platform) \
- if (!::lldb_private::DebuggerSupportsLLVMTarget(platform)) { \
- GTEST_SKIP() << "Unsupported platform"; \
- }
-
template <typename T> static llvm::Expected<T> roundtripJSON(const T &input) {
std::string encoded;
llvm::raw_string_ostream OS(encoded);
OS << toJSON(input);
return llvm::json::parse<T>(encoded);
}
-
-std::pair<lldb::SBTarget, lldb::SBProcess> LoadCore(lldb::SBDebugger &debugger,
- llvm::StringRef binary_path,
- llvm::StringRef core_path);
-
} // namespace lldb_private
#endif
More information about the llvm-branch-commits
mailing list