[Lldb-commits] [lldb] [lldb] add --platform-available-ports option to the dotest.py (PR #112555)

via lldb-commits lldb-commits at lists.llvm.org
Thu Mar 27 10:08:11 PDT 2025


https://github.com/dlav-sc updated https://github.com/llvm/llvm-project/pull/112555

>From a9d02c8b0c22138d9337bf33883f7e6c937bd655 Mon Sep 17 00:00:00 2001
From: Daniil Avdeev <daniil.avdeev at syntacore.com>
Date: Mon, 14 Oct 2024 14:14:30 +0000
Subject: [PATCH 1/2] [lldb] add --platform-available-ports option to the
 dotest.py

This patch adds --platform-available-ports option to the dotest.py script
to remove hardcoded gdb ports from lldb testsuite.

Currently, this option could be helpful for GdbRemoteTestCases (e.g.
TestLldbGdbServer, TestNonStop, TestGdbRemoteThreadsInStopReply,
TestGdbRemotePlatformFile, TestGdbRemote_vCont)
---
 lldb/packages/Python/lldbsuite/test/configuration.py       | 1 +
 lldb/packages/Python/lldbsuite/test/dotest.py              | 2 ++
 lldb/packages/Python/lldbsuite/test/dotest_args.py         | 7 +++++++
 lldb/packages/Python/lldbsuite/test/lldbtest.py            | 4 ++++
 .../lldbsuite/test/tools/lldb-server/gdbremote_testcase.py | 3 +++
 5 files changed, 17 insertions(+)

diff --git a/lldb/packages/Python/lldbsuite/test/configuration.py b/lldb/packages/Python/lldbsuite/test/configuration.py
index bcc179346836d..18c1566176331 100644
--- a/lldb/packages/Python/lldbsuite/test/configuration.py
+++ b/lldb/packages/Python/lldbsuite/test/configuration.py
@@ -103,6 +103,7 @@
 lldb_platform_name = None
 lldb_platform_url = None
 lldb_platform_working_dir = None
+lldb_platform_available_ports = None
 
 # Apple SDK
 apple_sdk = None
diff --git a/lldb/packages/Python/lldbsuite/test/dotest.py b/lldb/packages/Python/lldbsuite/test/dotest.py
index 681ea1638f2d6..7cc8f2985043e 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest.py
@@ -419,6 +419,8 @@ def parseOptionsAndInitTestdirs():
         configuration.lldb_platform_url = args.lldb_platform_url
     if args.lldb_platform_working_dir:
         configuration.lldb_platform_working_dir = args.lldb_platform_working_dir
+    if args.lldb_platform_available_ports:
+        configuration.lldb_platform_available_ports = args.lldb_platform_available_ports
     if platform_system == "Darwin" and args.apple_sdk:
         configuration.apple_sdk = args.apple_sdk
     if args.test_build_dir:
diff --git a/lldb/packages/Python/lldbsuite/test/dotest_args.py b/lldb/packages/Python/lldbsuite/test/dotest_args.py
index a80428ebec589..18047fdca2a92 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest_args.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest_args.py
@@ -292,6 +292,13 @@ def create_parser():
         metavar="platform-working-dir",
         help="The directory to use on the remote platform.",
     )
+    group.add_argument(
+        "--platform-available-ports",
+        dest="lldb_platform_available_ports",
+        type=lambda ports: [int(port.strip()) for port in ports.split(":")],
+        metavar="platform-available-ports",
+        help="Ports available for connection to a lldb server on the remote platform",
+    )
 
     # Test-suite behaviour
     group = parser.add_argument_group("Runtime behaviour options")
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index 570c36b5f9622..2e370564939d8 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -749,6 +749,10 @@ def getSourcePath(self, name):
         """Return absolute path to a file in the test's source directory."""
         return os.path.join(self.getSourceDir(), name)
 
+    def getPlatformAvailablePorts(self):
+        """Return ports available for connection to a lldb server on the remote platform."""
+        return configuration.lldb_platform_available_ports
+
     @classmethod
     def setUpCommands(cls):
         commands = [
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
index 3d3ecb9aa8f95..029aaf3164697 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
@@ -185,6 +185,9 @@ def setUpServerLogging(self, is_llgs):
             ]
 
     def get_next_port(self):
+        available_ports = self.getPlatformAvailablePorts()
+        if available_ports:
+            return random.choice(available_ports)
         return 12000 + random.randint(0, 7999)
 
     def reset_test_sequence(self):

>From bee43951764f20efac586c6b3cde55d8f36236da Mon Sep 17 00:00:00 2001
From: Daniil Avdeev <daniil.avdeev at syntacore.com>
Date: Thu, 27 Mar 2025 14:36:56 +0000
Subject: [PATCH 2/2] NFC

---
 lldb/packages/Python/lldbsuite/test/dotest_args.py           | 2 +-
 .../lldbsuite/test/tools/lldb-server/gdbremote_testcase.py   | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/dotest_args.py b/lldb/packages/Python/lldbsuite/test/dotest_args.py
index 18047fdca2a92..f6b389cd40d32 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest_args.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest_args.py
@@ -295,7 +295,7 @@ def create_parser():
     group.add_argument(
         "--platform-available-ports",
         dest="lldb_platform_available_ports",
-        type=lambda ports: [int(port.strip()) for port in ports.split(":")],
+        nargs="*",
         metavar="platform-available-ports",
         help="Ports available for connection to a lldb server on the remote platform",
     )
diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
index 029aaf3164697..cc62920ea871f 100644
--- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
+++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py
@@ -185,9 +185,8 @@ def setUpServerLogging(self, is_llgs):
             ]
 
     def get_next_port(self):
-        available_ports = self.getPlatformAvailablePorts()
-        if available_ports:
-            return random.choice(available_ports)
+        if available_ports := self.getPlatformAvailablePorts():
+            return int(random.choice(available_ports))
         return 12000 + random.randint(0, 7999)
 
     def reset_test_sequence(self):



More information about the lldb-commits mailing list