[Lldb-commits] [lldb] [lldb][test] Add flags useful for remote cross-platform testing to dotest.py (PR #93800)

Vladislav Dzhidzhoev via lldb-commits lldb-commits at lists.llvm.org
Thu May 30 03:21:59 PDT 2024


https://github.com/dzhidzhoev created https://github.com/llvm/llvm-project/pull/93800

This commit adds dotest.py flags that come in handy for setting up cross-platform remote runs of API tests.

`--make` argument allows to specify the path to the make executable used by LLDB API tests to compile test programs.

`--sysroot` and `--target-os` arguments allow to pass OS and SDKROOT variables to the make invocation. These variables are used in Makefile rules for tests.

These arguments can be passed to dotest.py from cmake command line through `LLDB_TEST_USER_ARGS` as follows:
```
cmake ... \
-DLLDB_TEST_USER_ARGS="...;--make;/mymake;--sysroot;/sysroot/path/;--target-os;Linux;..." \
...
```

>From 771344c1003b5172ff4912b5263bc2a1d3678366 Mon Sep 17 00:00:00 2001
From: Vladislav Dzhidzhoev <vdzhidzhoev at accesssoftek.com>
Date: Wed, 17 Apr 2024 05:17:07 +0000
Subject: [PATCH] [lldb][test] Add flags useful for remote cross-platform
 testing to dotest.py

This commit adds dotest.py flags that come in handy for setting up
cross-platform remote run of API tests.

`--make` argument allows to specify the path to make executable which is used by
LLDB API tests to compile test programs.

`--sysroot` and `--target-os` arguments allow to pass OS and SDKROOT
variables to the make invocation. These variables are used in Makefile rules
for tests.

These arguments can be passed to dotest.py from cmake command line through
`LLDB_TEST_USER_ARGS` as follows:
```
cmake ... \
-DLLDB_TEST_USER_ARGS="...;--make;/mymake;--sysroot;/sysroot/path/;--target-os;Linux;..." \
...
```
---
 .../Python/lldbsuite/test/builders/builder.py | 13 +++++++++-
 .../Python/lldbsuite/test/configuration.py    |  2 ++
 lldb/packages/Python/lldbsuite/test/dotest.py |  9 ++++++-
 .../Python/lldbsuite/test/dotest_args.py      | 24 +++++++++++++++++++
 .../Python/lldbsuite/test/lldbtest.py         |  4 ++++
 5 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/lldb/packages/Python/lldbsuite/test/builders/builder.py b/lldb/packages/Python/lldbsuite/test/builders/builder.py
index 823a982e67438..d63845a884d2f 100644
--- a/lldb/packages/Python/lldbsuite/test/builders/builder.py
+++ b/lldb/packages/Python/lldbsuite/test/builders/builder.py
@@ -36,11 +36,20 @@ def getArchCFlags(self, architecture):
         """Returns the ARCH_CFLAGS for the make system."""
         return []
 
+    def getTargetOsFlag(self, target_os):
+        if target_os is None:
+            target_os = configuration.target_os
+        if target_os is None:
+            return []
+        return ['OS=%s' % target_os]
+
     def getMake(self, test_subdir, test_name):
         """Returns the invocation for GNU make.
         The first argument is a tuple of the relative path to the testcase
         and its filename stem."""
-        if platform.system() == "FreeBSD" or platform.system() == "NetBSD":
+        if configuration.make_path is not None:
+            make = configuration.make_path
+        elif platform.system() == "FreeBSD" or platform.system() == "NetBSD":
             make = "gmake"
         else:
             make = "make"
@@ -168,6 +177,7 @@ def getBuildCommand(
         testdir=None,
         testname=None,
         make_targets=None,
+        target_os=None,
     ):
         debug_info_args = self._getDebugInfoArgs(debug_info)
         if debug_info_args is None:
@@ -179,6 +189,7 @@ def getBuildCommand(
             debug_info_args,
             make_targets,
             self.getArchCFlags(architecture),
+            self.getTargetOsFlag(target_os),
             self.getArchSpec(architecture),
             self.getCCSpec(compiler),
             self.getExtraMakeArgs(),
diff --git a/lldb/packages/Python/lldbsuite/test/configuration.py b/lldb/packages/Python/lldbsuite/test/configuration.py
index 685f491c85fe1..4789f04582fdd 100644
--- a/lldb/packages/Python/lldbsuite/test/configuration.py
+++ b/lldb/packages/Python/lldbsuite/test/configuration.py
@@ -39,10 +39,12 @@
 count = 1
 
 # The 'arch' and 'compiler' can be specified via command line.
+target_os = None
 arch = None
 compiler = None
 dsymutil = None
 sdkroot = None
+make_path = None
 
 # The overriden dwarf verison.
 dwarf_version = 0
diff --git a/lldb/packages/Python/lldbsuite/test/dotest.py b/lldb/packages/Python/lldbsuite/test/dotest.py
index 8c29145ecc527..9e3414a807420 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest.py
@@ -266,6 +266,8 @@ def parseOptionsAndInitTestdirs():
                     configuration.compiler = candidate
                     break
 
+    if args.make:
+        configuration.make_path = args.make
     if args.dsymutil:
         configuration.dsymutil = args.dsymutil
     elif platform_system == "Darwin":
@@ -304,7 +306,9 @@ def parseOptionsAndInitTestdirs():
         lldbtest_config.out_of_tree_debugserver = args.out_of_tree_debugserver
 
     # Set SDKROOT if we are using an Apple SDK
-    if platform_system == "Darwin" and args.apple_sdk:
+    if args.sysroot is not None:
+        configuration.sdkroot = args.sysroot
+    elif platform_system == "Darwin" and args.apple_sdk:
         configuration.sdkroot = seven.get_command_output(
             'xcrun --sdk "%s" --show-sdk-path 2> /dev/null' % (args.apple_sdk)
         )
@@ -312,6 +316,9 @@ def parseOptionsAndInitTestdirs():
             logging.error("No SDK found with the name %s; aborting...", args.apple_sdk)
             sys.exit(-1)
 
+    if args.target_os:
+        configuration.target_os = args.target_os
+
     if args.arch:
         configuration.arch = args.arch
     else:
diff --git a/lldb/packages/Python/lldbsuite/test/dotest_args.py b/lldb/packages/Python/lldbsuite/test/dotest_args.py
index e4de786ec0548..bed62cc787b4c 100644
--- a/lldb/packages/Python/lldbsuite/test/dotest_args.py
+++ b/lldb/packages/Python/lldbsuite/test/dotest_args.py
@@ -31,6 +31,15 @@ def create_parser():
 
     # C and Python toolchain options
     group = parser.add_argument_group("Toolchain options")
+    group.add_argument(
+        "--target-os",
+        metavar="target_os",
+        dest="target_os",
+        default="",
+        help=textwrap.dedent(
+            """Specify target os for test compilation. This is useful for cross-compilation."""
+        ),
+    )
     group.add_argument(
         "-A",
         "--arch",
@@ -49,6 +58,15 @@ def create_parser():
             """Specify the compiler(s) used to build the inferior executables. The compiler path can be an executable basename or a full path to a compiler executable. This option can be specified multiple times."""
         ),
     )
+    group.add_argument(
+        "--sysroot",
+        metavar="sysroot",
+        dest="sysroot",
+        default="",
+        help=textwrap.dedent(
+            """Specify the path to sysroot. This overrides apple_sdk sysroot."""
+        ),
+    )
     if sys.platform == "darwin":
         group.add_argument(
             "--apple-sdk",
@@ -87,6 +105,12 @@ def create_parser():
         ),
     )
 
+    group.add_argument(
+        "--make",
+        metavar="make",
+        dest="make",
+        help=textwrap.dedent("Specify which make to use."),
+    )
     group.add_argument(
         "--dsymutil",
         metavar="dsymutil",
diff --git a/lldb/packages/Python/lldbsuite/test/lldbtest.py b/lldb/packages/Python/lldbsuite/test/lldbtest.py
index c28a78a2c4a27..9808f9fd1c373 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -1387,11 +1387,15 @@ def getDebugInfo(self):
     def build(
         self,
         debug_info=None,
+        target_os=None,
         architecture=None,
         compiler=None,
         dictionary=None,
         make_targets=None,
     ):
+        if not target_os and configuration.target_os:
+            target_os = configuration.target_os
+
         """Platform specific way to build binaries."""
         if not architecture and configuration.arch:
             architecture = configuration.arch



More information about the lldb-commits mailing list