[Lldb-commits] [lldb] [lldb] Consolidating platform support checks in tests. (PR #184656)

John Harrison via lldb-commits lldb-commits at lists.llvm.org
Tue Mar 10 10:29:44 PDT 2026


https://github.com/ashgti updated https://github.com/llvm/llvm-project/pull/184656

>From e59e581a28b67d9dfd3cfa10ae1603741ab50f72 Mon Sep 17 00:00:00 2001
From: John Harrison <harjohn at google.com>
Date: Wed, 4 Mar 2026 10:06:52 -0800
Subject: [PATCH 1/4] [lldb] Consolidating platform support checks in tests.

Moving the platform support check into `lldb/unittests/TestingSupport/TestUtilities.h` so it can be reused across tests.

Also skipping 'VariablesTest' cases that load a core dump if the platform is not supported.
---
 lldb/unittests/DAP/Handler/DisconnectTest.cpp |  4 ----
 lldb/unittests/DAP/TestBase.cpp               | 17 +----------------
 lldb/unittests/DAP/TestBase.h                 |  1 -
 lldb/unittests/DAP/VariablesTest.cpp          |  5 ++++-
 .../TestingSupport/TestUtilities.cpp          | 19 ++++++++++++++++++-
 lldb/unittests/TestingSupport/TestUtilities.h | 12 ++++++++++++
 6 files changed, 35 insertions(+), 23 deletions(-)

diff --git a/lldb/unittests/DAP/Handler/DisconnectTest.cpp b/lldb/unittests/DAP/Handler/DisconnectTest.cpp
index 212c5698feea8..1c19d35bd746d 100644
--- a/lldb/unittests/DAP/Handler/DisconnectTest.cpp
+++ b/lldb/unittests/DAP/Handler/DisconnectTest.cpp
@@ -38,10 +38,6 @@ TEST_F(DisconnectRequestHandlerTest, DisconnectTriggersTerminated) {
 #ifndef __linux__
 TEST_F(DisconnectRequestHandlerTest, DisconnectTriggersTerminateCommands) {
   CreateDebugger();
-
-  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 6073aa82a8eb7..cee90caf9ff7b 100644
--- a/lldb/unittests/DAP/TestBase.cpp
+++ b/lldb/unittests/DAP/TestBase.cpp
@@ -72,25 +72,10 @@ void DAPTestBase::SetUpTestSuite() {
 }
 void DAPTestBase::TearDownTestSuite() { SBDebugger::Terminate(); }
 
-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);
+  SKIP_UNLESS_PLATFORM_SUPPORTED(dap->debugger, "X86");
   dap->target = dap->debugger.GetDummyTarget();
 
   Expected<lldb::FileUP> dev_null = FileSystem::Instance().Open(
diff --git a/lldb/unittests/DAP/TestBase.h b/lldb/unittests/DAP/TestBase.h
index 7953e0fabfbe5..2a0febf298d63 100644
--- a/lldb/unittests/DAP/TestBase.h
+++ b/lldb/unittests/DAP/TestBase.h
@@ -112,7 +112,6 @@ class DAPTestBase : public TransportBase {
   void SetUp() override;
   void TearDown() override;
 
-  bool GetDebuggerSupportsTarget(llvm::StringRef platform);
   void CreateDebugger();
   void LoadCore();
 };
diff --git a/lldb/unittests/DAP/VariablesTest.cpp b/lldb/unittests/DAP/VariablesTest.cpp
index fe85e92a7fee2..8f590253f3b7c 100644
--- a/lldb/unittests/DAP/VariablesTest.cpp
+++ b/lldb/unittests/DAP/VariablesTest.cpp
@@ -59,7 +59,10 @@ class VariablesTest : public ::testing::Test {
   std::optional<llvm::sys::fs::TempFile> core;
   std::optional<llvm::sys::fs::TempFile> binary;
 
-  void CreateDebugger() { debugger = lldb::SBDebugger::Create(); }
+  void CreateDebugger() {
+    debugger = lldb::SBDebugger::Create();
+    SKIP_UNLESS_PLATFORM_SUPPORTED(debugger, "X86");
+  }
 
   void LoadCore() {
     ASSERT_TRUE(debugger);
diff --git a/lldb/unittests/TestingSupport/TestUtilities.cpp b/lldb/unittests/TestingSupport/TestUtilities.cpp
index d164c227afb9e..8b65087065992 100644
--- a/lldb/unittests/TestingSupport/TestUtilities.cpp
+++ b/lldb/unittests/TestingSupport/TestUtilities.cpp
@@ -7,11 +7,11 @@
 //===----------------------------------------------------------------------===//
 
 #include "TestUtilities.h"
+#include "lldb/API/SBStructuredData.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 "gtest/gtest.h"
 
@@ -61,3 +61,20 @@ llvm::Expected<llvm::sys::fs::TempFile> TestFile::writeToTemporaryFile() {
   llvm::raw_fd_ostream(Temp->FD, /*shouldClose=*/false) << Buffer;
   return std::move(*Temp);
 }
+
+bool lldb_private::DebuggerSupportsPlatform(lldb::SBDebugger &debugger,
+                                            llvm::StringRef platform) {
+  EXPECT_TRUE(debugger);
+
+  lldb::SBStructuredData data =
+      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 (llvm::StringRef(buf, size) == platform)
+      return true;
+  }
+
+  return false;
+}
diff --git a/lldb/unittests/TestingSupport/TestUtilities.h b/lldb/unittests/TestingSupport/TestUtilities.h
index 68b4dbc127a7d..e27577472f5b6 100644
--- a/lldb/unittests/TestingSupport/TestUtilities.h
+++ b/lldb/unittests/TestingSupport/TestUtilities.h
@@ -9,6 +9,7 @@
 #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"
@@ -16,6 +17,7 @@
 #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)                                                     \
@@ -65,12 +67,22 @@ class TestFile {
   std::string Buffer;
 };
 
+/// Check if the debugger supports the given platform.
+bool DebuggerSupportsPlatform(lldb::SBDebugger &debugger,
+                              llvm::StringRef platform);
+
+#define SKIP_UNLESS_PLATFORM_SUPPORTED(debugger, platform)                     \
+  if (!::lldb_private::DebuggerSupportsPlatform(debugger, 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);
 }
+
 } // namespace lldb_private
 
 #endif

>From e7e720531c718798a49428ae10c5536f5b34983f Mon Sep 17 00:00:00 2001
From: John Harrison <harjohn at google.com>
Date: Wed, 4 Mar 2026 12:45:03 -0800
Subject: [PATCH 2/4] Trying to make loading a core more explicit and moving
 the SKIP to the test case itself.

---
 lldb/unittests/DAP/Handler/DisconnectTest.cpp |  2 +
 lldb/unittests/DAP/TestBase.cpp               | 23 ++-------
 lldb/unittests/DAP/VariablesTest.cpp          | 49 +++++--------------
 .../TestingSupport/TestUtilities.cpp          | 37 ++++++++++++++
 lldb/unittests/TestingSupport/TestUtilities.h |  4 ++
 5 files changed, 57 insertions(+), 58 deletions(-)

diff --git a/lldb/unittests/DAP/Handler/DisconnectTest.cpp b/lldb/unittests/DAP/Handler/DisconnectTest.cpp
index 1c19d35bd746d..d8003f3dfa5fc 100644
--- a/lldb/unittests/DAP/Handler/DisconnectTest.cpp
+++ b/lldb/unittests/DAP/Handler/DisconnectTest.cpp
@@ -10,6 +10,7 @@
 #include "Handler/RequestHandler.h"
 #include "Protocol/ProtocolBase.h"
 #include "TestBase.h"
+#include "TestingSupport/TestUtilities.h"
 #include "lldb/API/SBDefines.h"
 #include "lldb/lldb-enumerations.h"
 #include "llvm/Testing/Support/Error.h"
@@ -38,6 +39,7 @@ TEST_F(DisconnectRequestHandlerTest, DisconnectTriggersTerminated) {
 #ifndef __linux__
 TEST_F(DisconnectRequestHandlerTest, DisconnectTriggersTerminateCommands) {
   CreateDebugger();
+  SKIP_UNLESS_PLATFORM_SUPPORTED(dap->debugger, "X86");
   LoadCore();
 
   DisconnectRequestHandler handler(*dap);
diff --git a/lldb/unittests/DAP/TestBase.cpp b/lldb/unittests/DAP/TestBase.cpp
index cee90caf9ff7b..f31930de08663 100644
--- a/lldb/unittests/DAP/TestBase.cpp
+++ b/lldb/unittests/DAP/TestBase.cpp
@@ -75,7 +75,6 @@ void DAPTestBase::TearDownTestSuite() { SBDebugger::Terminate(); }
 void DAPTestBase::CreateDebugger() {
   dap->debugger = lldb::SBDebugger::Create();
   ASSERT_TRUE(dap->debugger);
-  SKIP_UNLESS_PLATFORM_SUPPORTED(dap->debugger, "X86");
   dap->target = dap->debugger.GetDummyTarget();
 
   Expected<lldb::FileUP> dev_null = FileSystem::Instance().Open(
@@ -97,23 +96,7 @@ void DAPTestBase::CreateDebugger() {
 }
 
 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);
+  lldb::SBProcess process;
+  std::tie(dap->target, process) =
+      lldb_private::LoadCore(dap->debugger, k_linux_binary, k_linux_core);
 }
diff --git a/lldb/unittests/DAP/VariablesTest.cpp b/lldb/unittests/DAP/VariablesTest.cpp
index 8f590253f3b7c..fbf1645fd7df3 100644
--- a/lldb/unittests/DAP/VariablesTest.cpp
+++ b/lldb/unittests/DAP/VariablesTest.cpp
@@ -36,10 +36,6 @@ 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();
   }
@@ -53,40 +49,12 @@ 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;
+  static constexpr llvm::StringLiteral k_binary_x86_64 =
+      "linux-x86_64.out.yaml";
+  static constexpr llvm::StringLiteral k_core_x86_64 = "linux-x86_64.core.yaml";
 
   void CreateDebugger() {
-    debugger = lldb::SBDebugger::Create();
-    SKIP_UNLESS_PLATFORM_SUPPORTED(debugger, "X86");
-  }
-
-  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);
+    debugger = lldb::SBDebugger::Create(/*source_init_files*/ false);
   }
 
   static const protocol::Scope *
@@ -102,7 +70,9 @@ class VariablesTest : public ::testing::Test {
 
 TEST_F(VariablesTest, GetNewVariableReference_UniqueAndRanges) {
   CreateDebugger();
-  LoadCore();
+  SKIP_UNLESS_PLATFORM_SUPPORTED(debugger, "X86");
+  std::tie(target, process) =
+      lldb_private::LoadCore(debugger, k_binary_x86_64, k_core_x86_64);
   auto x15 = target.CreateValueFromExpression("x", "15");
   auto y42 = target.CreateValueFromExpression("y", "42");
   auto gzero = target.CreateValueFromExpression("$0", "42");
@@ -153,7 +123,10 @@ TEST_F(VariablesTest, Clear_RemovesTemporaryKeepsPermanent) {
 
 TEST_F(VariablesTest, VariablesStore) {
   CreateDebugger();
-  LoadCore();
+  SKIP_UNLESS_PLATFORM_SUPPORTED(debugger, "X86");
+  std::tie(target, process) =
+      lldb_private::LoadCore(debugger, k_binary_x86_64, k_core_x86_64);
+
   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 8b65087065992..7d3010d80aa8c 100644
--- a/lldb/unittests/TestingSupport/TestUtilities.cpp
+++ b/lldb/unittests/TestingSupport/TestUtilities.cpp
@@ -8,12 +8,15 @@
 
 #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/YAMLTraits.h"
+#include "llvm/Testing/Support/Error.h"
 #include "gtest/gtest.h"
+#include <utility>
 
 using namespace lldb_private;
 
@@ -78,3 +81,37 @@ bool lldb_private::DebuggerSupportsPlatform(lldb::SBDebugger &debugger,
 
   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);
+}
\ No newline at end of file
diff --git a/lldb/unittests/TestingSupport/TestUtilities.h b/lldb/unittests/TestingSupport/TestUtilities.h
index e27577472f5b6..46129cda85b80 100644
--- a/lldb/unittests/TestingSupport/TestUtilities.h
+++ b/lldb/unittests/TestingSupport/TestUtilities.h
@@ -83,6 +83,10 @@ template <typename T> static llvm::Expected<T> roundtripJSON(const T &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

>From 1429696bbf63485487fcf574acf52ac3e93edc5d Mon Sep 17 00:00:00 2001
From: John Harrison <harjohn at google.com>
Date: Wed, 4 Mar 2026 15:37:24 -0800
Subject: [PATCH 3/4] Adding a newline to the end of the file.

---
 lldb/unittests/TestingSupport/TestUtilities.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/unittests/TestingSupport/TestUtilities.cpp b/lldb/unittests/TestingSupport/TestUtilities.cpp
index 7d3010d80aa8c..a8b3cd246c35c 100644
--- a/lldb/unittests/TestingSupport/TestUtilities.cpp
+++ b/lldb/unittests/TestingSupport/TestUtilities.cpp
@@ -114,4 +114,4 @@ lldb_private::LoadCore(lldb::SBDebugger &debugger, llvm::StringRef binary_path,
   EXPECT_THAT_ERROR(core_file->discard(), llvm::Succeeded());
 
   return std::make_pair(target, process);
-}
\ No newline at end of file
+}

>From 14000f6ced30acb0c9c3a9908223749e0dc86abf Mon Sep 17 00:00:00 2001
From: John Harrison <harjohn at google.com>
Date: Tue, 10 Mar 2026 10:28:45 -0700
Subject: [PATCH 4/4] Updating `DebuggerSupportsLLVMTarget` to call
 lldb::SBDebugger::GetBuildConfiguration, which is static and renamed the skip
 macro to match the python name.

---
 lldb/unittests/DAP/DAPTest.cpp                |  3 +-
 lldb/unittests/DAP/Handler/DisconnectTest.cpp |  7 +-
 lldb/unittests/DAP/TestBase.cpp               |  8 +-
 lldb/unittests/DAP/TestBase.h                 | 55 +------------
 lldb/unittests/DAP/TestUtilities.h            | 82 +++++++++++++++++++
 lldb/unittests/DAP/VariablesTest.cpp          | 21 +++--
 .../TestingSupport/TestUtilities.cpp          | 13 ++-
 lldb/unittests/TestingSupport/TestUtilities.h |  7 +-
 8 files changed, 111 insertions(+), 85 deletions(-)
 create mode 100644 lldb/unittests/DAP/TestUtilities.h

diff --git a/lldb/unittests/DAP/DAPTest.cpp b/lldb/unittests/DAP/DAPTest.cpp
index 4fd6cd546e6fa..fcc8ff25446ff 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,6 +9,7 @@
 #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 d8003f3dfa5fc..9f53600de88a8 100644
--- a/lldb/unittests/DAP/Handler/DisconnectTest.cpp
+++ b/lldb/unittests/DAP/Handler/DisconnectTest.cpp
@@ -8,8 +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"
@@ -38,9 +38,10 @@ 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();
-  SKIP_UNLESS_PLATFORM_SUPPORTED(dap->debugger, "X86");
-  LoadCore();
+  LoadCore(k_linux_x86_64_binary, k_linux_x86_64_core);
 
   DisconnectRequestHandler handler(*dap);
 
diff --git a/lldb/unittests/DAP/TestBase.cpp b/lldb/unittests/DAP/TestBase.cpp
index f31930de08663..7a0b9ec7daf39 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,7 +13,6 @@
 #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"
@@ -95,8 +94,9 @@ void DAPTestBase::CreateDebugger() {
   dap->debugger.SetErrorFile(lldb::SBFile(*err_fd, "w", false));
 }
 
-void DAPTestBase::LoadCore() {
+void DAPTestBase::LoadCore(llvm::StringRef binary_path,
+                           llvm::StringRef core_path) {
   lldb::SBProcess process;
   std::tie(dap->target, process) =
-      lldb_private::LoadCore(dap->debugger, k_linux_binary, k_linux_core);
+      lldb_private::LoadCore(dap->debugger, binary_path, core_path);
 }
diff --git a/lldb/unittests/DAP/TestBase.h b/lldb/unittests/DAP/TestBase.h
index 2a0febf298d63..a4ca407a8a822 100644
--- a/lldb/unittests/DAP/TestBase.h
+++ b/lldb/unittests/DAP/TestBase.h
@@ -10,44 +10,18 @@
 #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>;
@@ -74,46 +48,19 @@ 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;
 
-  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 CreateDebugger();
-  void LoadCore();
+  void LoadCore(llvm::StringRef binary_path, llvm::StringRef core_path);
 };
 
 } // namespace lldb_dap_tests
diff --git a/lldb/unittests/DAP/TestUtilities.h b/lldb/unittests/DAP/TestUtilities.h
new file mode 100644
index 0000000000000..e6daf2c1b3fd9
--- /dev/null
+++ b/lldb/unittests/DAP/TestUtilities.h
@@ -0,0 +1,82 @@
+//===----------------------------------------------------------------------===//
+//
+// 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 "DAP.h"
+#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 {
+
+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 fbf1645fd7df3..be5d77715d429 100644
--- a/lldb/unittests/DAP/VariablesTest.cpp
+++ b/lldb/unittests/DAP/VariablesTest.cpp
@@ -10,6 +10,7 @@
 #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"
@@ -17,11 +18,11 @@
 #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;
 
 class VariablesTest : public ::testing::Test {
@@ -49,10 +50,6 @@ class VariablesTest : public ::testing::Test {
   lldb::SBTarget target;
   lldb::SBProcess process;
 
-  static constexpr llvm::StringLiteral k_binary_x86_64 =
-      "linux-x86_64.out.yaml";
-  static constexpr llvm::StringLiteral k_core_x86_64 = "linux-x86_64.core.yaml";
-
   void CreateDebugger() {
     debugger = lldb::SBDebugger::Create(/*source_init_files*/ false);
   }
@@ -69,10 +66,11 @@ class VariablesTest : public ::testing::Test {
 };
 
 TEST_F(VariablesTest, GetNewVariableReference_UniqueAndRanges) {
+  SKIP_IF_LLVM_TARGET_MISSING("X86");
+
   CreateDebugger();
-  SKIP_UNLESS_PLATFORM_SUPPORTED(debugger, "X86");
-  std::tie(target, process) =
-      lldb_private::LoadCore(debugger, k_binary_x86_64, k_core_x86_64);
+  std::tie(target, process) = lldb_private::LoadCore(
+      debugger, k_linux_x86_64_binary, k_linux_x86_64_core);
   auto x15 = target.CreateValueFromExpression("x", "15");
   auto y42 = target.CreateValueFromExpression("y", "42");
   auto gzero = target.CreateValueFromExpression("$0", "42");
@@ -122,10 +120,11 @@ TEST_F(VariablesTest, Clear_RemovesTemporaryKeepsPermanent) {
 }
 
 TEST_F(VariablesTest, VariablesStore) {
+  SKIP_IF_LLVM_TARGET_MISSING("X86");
+
   CreateDebugger();
-  SKIP_UNLESS_PLATFORM_SUPPORTED(debugger, "X86");
-  std::tie(target, process) =
-      lldb_private::LoadCore(debugger, k_binary_x86_64, k_core_x86_64);
+  std::tie(target, process) = lldb_private::LoadCore(
+      debugger, k_linux_x86_64_binary, k_linux_x86_64_core);
 
   lldb::SBFrame frame = process.GetSelectedThread().GetSelectedFrame();
 
diff --git a/lldb/unittests/TestingSupport/TestUtilities.cpp b/lldb/unittests/TestingSupport/TestUtilities.cpp
index a8b3cd246c35c..13092742a4347 100644
--- a/lldb/unittests/TestingSupport/TestUtilities.cpp
+++ b/lldb/unittests/TestingSupport/TestUtilities.cpp
@@ -65,17 +65,14 @@ llvm::Expected<llvm::sys::fs::TempFile> TestFile::writeToTemporaryFile() {
   return std::move(*Temp);
 }
 
-bool lldb_private::DebuggerSupportsPlatform(lldb::SBDebugger &debugger,
-                                            llvm::StringRef platform) {
-  EXPECT_TRUE(debugger);
-
-  lldb::SBStructuredData data =
-      debugger.GetBuildConfiguration().GetValueForKey("targets").GetValueForKey(
-          "value");
+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) == platform)
+    if (llvm::StringRef(buf, size) == target)
       return true;
   }
 
diff --git a/lldb/unittests/TestingSupport/TestUtilities.h b/lldb/unittests/TestingSupport/TestUtilities.h
index 46129cda85b80..01ecc15c9606d 100644
--- a/lldb/unittests/TestingSupport/TestUtilities.h
+++ b/lldb/unittests/TestingSupport/TestUtilities.h
@@ -68,11 +68,10 @@ class TestFile {
 };
 
 /// Check if the debugger supports the given platform.
-bool DebuggerSupportsPlatform(lldb::SBDebugger &debugger,
-                              llvm::StringRef platform);
+bool DebuggerSupportsLLVMTarget(llvm::StringRef target);
 
-#define SKIP_UNLESS_PLATFORM_SUPPORTED(debugger, platform)                     \
-  if (!::lldb_private::DebuggerSupportsPlatform(debugger, platform)) {         \
+#define SKIP_IF_LLVM_TARGET_MISSING(platform)                                  \
+  if (!::lldb_private::DebuggerSupportsLLVMTarget(platform)) {                 \
     GTEST_SKIP() << "Unsupported platform";                                    \
   }
 



More information about the lldb-commits mailing list