[libcxx-commits] [libcxx] [libc++][lit] Allow overriding the executor for tests (PR #66545)

Alexander Richardson via libcxx-commits libcxx-commits at lists.llvm.org
Fri Sep 15 13:28:35 PDT 2023


https://github.com/arichardson created https://github.com/llvm/llvm-project/pull/66545

This is useful when trying to run multiple tests with different arguments to the executor script. This is needed in my case since I do not know the correct ssh connection arguments when building libc++. The testing script I have spawns multiple QEMU instances that listen on a given port on localhost and runs lit with the `--num-shards/--run-shard` argument. In order to connect each shard to the right QEMU instances I need to customize the arguments passed to ssh.py (`--extra-ssh-args` and `--extra-scp-args`) but can't do this at configure time since the target port is only known when running the tests but not when calling CMake. This change allows me to pass `-Dexecutor=ssh.py <args>` to lit once I know the right hostname/port for running the tests.

>From 1f8b913b2c242ce75a05e204a11bde2abb34d1b5 Mon Sep 17 00:00:00 2001
From: Alex Richardson <alexrichardson at google.com>
Date: Fri, 15 Sep 2023 13:25:57 -0700
Subject: [PATCH] [libc++][lit] Allow overriding the executor for tests

This is useful when trying to run multiple tests with different
arguments to the executor script. This is needed in my case since I
do not know the correct ssh connection arguments when building libc++.
The testing script I have spawns multiple QEMU instances that listen on
a given port on localhost and runs lit with the `--num-shards/--run-shard`
argument. In order to connect each shard to the right QEMU instances I
need to customize the arguments passed to ssh.py (`--extra-ssh-args` and
`--extra-scp-args`) but can't do this at configure time since the target
port is only known when running the tests but not when calling CMake.
This change allows me to pass `-Dexecutor=ssh.py <args>` to lit once I
know the right hostname/port for running the tests.
---
 libcxx/utils/libcxx/test/dsl.py    | 23 +++++++++++++++++++++++
 libcxx/utils/libcxx/test/params.py |  9 +++++++++
 2 files changed, 32 insertions(+)

diff --git a/libcxx/utils/libcxx/test/dsl.py b/libcxx/utils/libcxx/test/dsl.py
index 847cebf5962f6aa..778c15bf881175c 100644
--- a/libcxx/utils/libcxx/test/dsl.py
+++ b/libcxx/utils/libcxx/test/dsl.py
@@ -581,6 +581,29 @@ def pretty(self, config, litParams):
         return "add substitution {} = {}".format(self._key, self._getSub(config))
 
 
+class OverrideSubstitution(AddSubstitution):
+    """
+    This action replaces the given substitution in the Lit configuration.
+
+    The substitution can be a string or a callable, in which case it is called
+    with the configuration to produce the actual substitution (as a string).
+    """
+
+    def applyTo(self, config):
+        key = self._key
+        sub = self._getSub(config)
+        for i, val in enumerate(config.substitutions):
+            if val[0] == key:
+                config.substitutions[i] = (key, sub)
+                return
+        raise ValueError(
+            "Expected substitution {} to already be defined".format(key)
+        )
+
+    def pretty(self, config, litParams):
+        return "replace substitution {} = {}".format(self._key, self._getSub(config))
+
+
 class Feature(object):
     """
     Represents a Lit available feature that is enabled whenever it is supported.
diff --git a/libcxx/utils/libcxx/test/params.py b/libcxx/utils/libcxx/test/params.py
index e05c6689964c734..dfe6fc7d11e804d 100644
--- a/libcxx/utils/libcxx/test/params.py
+++ b/libcxx/utils/libcxx/test/params.py
@@ -330,5 +330,14 @@ def getModuleFlag(cfg, enable_modules):
             AddCompileFlag("-D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES"),
         ],
     ),
+    Parameter(
+        name="executor",
+        type=str,
+        default="",
+        help="Custom executor to use instead of the configured default.",
+        actions=lambda executor: [] if not executor else [
+          OverrideSubstitution("%{executor}", executor)
+        ],
+    )
 ]
 # fmt: on



More information about the libcxx-commits mailing list