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

via lldb-commits lldb-commits at lists.llvm.org
Wed Oct 16 07:44:49 PDT 2024


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

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

Currently, this option could be helpful in GdbRemoteTestCases (e.g. TestLldbGdbServer, TestNonStop, TestGdbRemoteThreadsInStopReply, TestGdbRemotePlatformFile, TestGdbRemote_vCont)

>From 255731042d9bf24af661b7d5fe7f27dc191f0d29 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] [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 1bacd74a968c31..c54f8d6a3962f8 100644
--- a/lldb/packages/Python/lldbsuite/test/configuration.py
+++ b/lldb/packages/Python/lldbsuite/test/configuration.py
@@ -99,6 +99,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 681ea1638f2d6f..7cc8f2985043e6 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 a80428ebec5891..18047fdca2a921 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 8884ef5933ada8..112f139518f393 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -747,6 +747,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 8c8e4abed0b454..f7516d26d01d79 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, 3999)
 
     def reset_test_sequence(self):



More information about the lldb-commits mailing list