Skip to content

Commit b747d2c

Browse files
committed
[lldb][test] Support remote run of Shell tests
1. This commit adds LLDB_TEST_PLATFORM_URL, LLDB_TEST_SYSROOT, LLDB_TEST_PLATFORM_WORKING_DIR, LLDB_SHELL_TESTS_DISABLE_REMOTE cmake flags to pass arguments for cross-compilation and remote running of both Shell&API tests. 2. To run Shell tests remotely, it adds 'platform select' and 'platform connect' commands to %lldb substitution. 3. 'remote-linux' feature added to lit to disable tests failing with remote execution. 4. A separate working directory is assigned to each test to avoid conflicts during parallel test execution. 5. Remote Shell testing is run only when LLDB_TEST_SYSROOT is set for building test sources. Recommended compiler for that is Clang.
1 parent 971a1ac commit b747d2c

File tree

9 files changed

+112
-24
lines changed

9 files changed

+112
-24
lines changed

lldb/docs/resources/test.rst

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -592,15 +592,17 @@ test suite, but there are two things to have in mind:
592592
multiple connections. For more information on how to setup remote debugging
593593
see the Remote debugging page.
594594
2. You must tell the test-suite how to connect to the remote system. This is
595-
achieved using the ``--platform-name``, ``--platform-url`` and
596-
``--platform-working-dir`` parameters to ``dotest.py``. These parameters
597-
correspond to the platform select and platform connect LLDB commands. You
598-
will usually also need to specify the compiler and architecture for the
599-
remote system.
600-
601-
Currently, running the remote test suite is supported only with ``dotest.py`` (or
602-
dosep.py with a single thread), but we expect this issue to be addressed in the
603-
near future.
595+
achieved using the ``LLDB_TEST_PLATFORM_URL``, ``LLDB_TEST_PLATFORM_WORKING_DIR``
596+
flags to cmake, and ``--platform-name`` parameter to ``dotest.py``.
597+
These parameters correspond to the platform select and platform connect
598+
LLDB commands. You will usually also need to specify the compiler and
599+
architecture for the remote system.
600+
3. Remote Shell tests execution is currently supported only for Linux target
601+
platform. It's triggered when ``LLDB_TEST_SYSROOT`` is provided for building
602+
test sources. It can be disabled by setting ``LLDB_SHELL_TESTS_DISABLE_REMOTE=On``.
603+
Shell tests are not guaranteed to pass against remote target if the compiler
604+
being used is other than Clang.
605+
604606

605607
Running tests in QEMU System Emulation Environment
606608
``````````````````````````````````````````````````

lldb/test/API/lit.cfg.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,13 @@ def delete_module_cache(path):
303303
# In particular, (1) is visited at the top of the file, since the script
304304
# derives other information from it.
305305

306+
if is_configured("lldb_platform_url"):
307+
dotest_cmd += ["--platform-url", config.lldb_platform_url]
308+
if is_configured("lldb_platform_working_dir"):
309+
dotest_cmd += ["--platform-working-dir", config.lldb_platform_working_dir]
310+
if is_configured("cmake_sysroot"):
311+
dotest_cmd += ["--sysroot", config.cmake_sysroot]
312+
306313
if is_configured("dotest_user_args_str"):
307314
dotest_cmd.extend(config.dotest_user_args_str.split(";"))
308315

lldb/test/API/lit.site.cfg.py.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ config.lua_executable = "@Lua_EXECUTABLE@"
2424
config.lua_test_entry = "TestLuaAPI.py"
2525
config.dotest_common_args_str = lit_config.substitute("@LLDB_TEST_COMMON_ARGS@")
2626
config.dotest_user_args_str = lit_config.substitute("@LLDB_TEST_USER_ARGS@")
27+
config.lldb_platform_url = lit_config.substitute("@LLDB_TEST_PLATFORM_URL@")
28+
config.lldb_platform_working_dir = lit_config.substitute("@LLDB_TEST_PLATFORM_WORKING_DIR@")
29+
config.cmake_sysroot = lit_config.substitute("@LLDB_TEST_SYSROOT@" or "@DEFAULT_SYSROOT@")
2730
config.lldb_enable_python = @LLDB_ENABLE_PYTHON@
2831
config.dotest_lit_args_str = None
2932
config.enabled_plugins = []

lldb/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ llvm_canonicalize_cmake_booleans(
244244
LLVM_ENABLE_ZLIB
245245
LLVM_ENABLE_SHARED_LIBS
246246
LLDB_HAS_LIBCXX
247+
LLDB_SHELL_TESTS_DISABLE_REMOTE
247248
LLDB_TOOL_LLDB_SERVER_BUILD
248249
LLDB_USE_SYSTEM_DEBUGSERVER
249250
LLDB_IS_64_BITS)

lldb/test/Shell/Settings/TestEchoCommands.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# RUN: %lldb -x -b -o 'settings set interpreter.echo-comment-commands false' -s %S/Inputs/EchoCommandsTest.in | FileCheck %S/Inputs/EchoCommandsNoComments.out
33
# RUN: %lldb -x -b -o 'settings set interpreter.echo-commands false' -s %S/Inputs/EchoCommandsTest.in | FileCheck %S/Inputs/EchoCommandsNone.out
44

5+
XFAIL: remote{{.*}}
6+
57
RUN: echo start >%t.file
68
RUN: %lldb -x -b --source-quietly -s %S/Inputs/EchoCommandsTest.in >>%t.file
79
RUN: echo done >>%t.file

lldb/test/Shell/Target/target-label.test

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
target create -l "ls" /bin/ls
66
target list
7-
# CHECK: * target #0 (ls): /bin/ls
7+
# CHECK: * target #0 (ls): [[LS_PATH:.*]]
88

99
script lldb.target.SetLabel("")
1010
target list
11-
# CHECK: * target #0: /bin/ls
11+
# CHECK: * target #0: [[LS_PATH]]
1212

1313
target create -l "cat" /bin/cat
1414
target list
15-
# CHECK: target #0: /bin/ls
16-
# CHECK-NEXT: * target #1 (cat): /bin/cat
15+
# CHECK: target #0: [[LS_PATH]]
16+
# CHECK-NEXT: * target #1 (cat): [[CAT_PATH:.*]]
1717

1818
target create -l "cat" /bin/cat
1919
# CHECK: Cannot use label 'cat' since it's set in target #1.
@@ -22,12 +22,12 @@ target create -l 42 /bin/cat
2222
# CHECK: error: Cannot use integer as target label.
2323

2424
target select 0
25-
# CHECK: * target #0: /bin/ls
26-
# CHECK-NEXT: target #1 (cat): /bin/cat
25+
# CHECK: * target #0: [[LS_PATH]]
26+
# CHECK-NEXT: target #1 (cat): [[CAT_PATH]]
2727

2828
target select cat
29-
# CHECK: target #0: /bin/ls
30-
# CHECK-NEXT: * target #1 (cat): /bin/cat
29+
# CHECK: target #0: [[LS_PATH]]
30+
# CHECK-NEXT: * target #1 (cat): [[CAT_PATH]]
3131

3232
script lldb.target.GetLabel()
3333
# CHECK: 'cat'
@@ -36,5 +36,5 @@ script lldb.debugger.GetTargetAtIndex(0).SetLabel('Not cat')
3636
# CHECK: success
3737

3838
target list
39-
# CHECK: target #0 (Not cat): /bin/ls
40-
# CHECK-NEXT: * target #1 (cat): /bin/cat
39+
# CHECK: target #0 (Not cat): [[LS_PATH]]
40+
# CHECK-NEXT: * target #1 (cat): [[CAT_PATH]]

lldb/test/Shell/helper/toolchain.py

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import os
22
import itertools
33
import platform
4+
import re
45
import subprocess
56
import sys
67

78
import lit.util
9+
from lit.formats import ShTest
810
from lit.llvm import llvm_config
911
from lit.llvm.subst import FindTool
1012
from lit.llvm.subst import ToolSubst
@@ -22,6 +24,55 @@ def _disallow(config, execName):
2224
config.substitutions.append((" {0} ".format(execName), warning.format(execName)))
2325

2426

27+
def get_lldb_args(config, suffix=None):
28+
lldb_args = []
29+
if "remote-linux" in config.available_features:
30+
lldb_args += [
31+
"-O",
32+
'"platform select remote-linux"',
33+
"-O",
34+
f'"platform connect {config.lldb_platform_url}"',
35+
]
36+
if config.lldb_platform_working_dir:
37+
dir = f"{config.lldb_platform_working_dir}/shell"
38+
if suffix:
39+
dir += f"/{suffix}"
40+
lldb_args += [
41+
"-O",
42+
f'"platform shell mkdir -p {dir}"',
43+
"-O",
44+
f'"platform settings -w {dir}"',
45+
]
46+
lldb_args += ["--no-lldbinit", "-S", _get_lldb_init_path(config)]
47+
return lldb_args
48+
49+
50+
class ShTestLldb(ShTest):
51+
def __init__(
52+
self, execute_external=False, extra_substitutions=[], preamble_commands=[]
53+
):
54+
super().__init__(execute_external, extra_substitutions, preamble_commands)
55+
56+
def execute(self, test, litConfig):
57+
for i, t in enumerate(test.config.substitutions):
58+
try:
59+
if re.match(t[0], "%lldb"):
60+
cmd = t[1]
61+
if '-O "platform settings -w ' in cmd:
62+
args_def = " ".join(get_lldb_args(test.config))
63+
args_unique = " ".join(
64+
get_lldb_args(test.config, "/".join(test.path_in_suite))
65+
)
66+
test.config.substitutions[i] = (
67+
t[0],
68+
cmd.replace(args_def, args_unique),
69+
)
70+
break
71+
except:
72+
pass
73+
return super().execute(test, litConfig)
74+
75+
2576
def use_lldb_substitutions(config):
2677
# Set up substitutions for primary tools. These tools must come from config.lldb_tools_dir
2778
# which is basically the build output directory. We do not want to find these in path or
@@ -34,7 +85,9 @@ def use_lldb_substitutions(config):
3485
build_script = os.path.join(build_script, "build.py")
3586
build_script_args = [
3687
build_script,
37-
"--compiler=any", # Default to best compiler
88+
(
89+
"--compiler=clang" if config.enable_remote else "--compiler=any"
90+
), # Default to best compiler
3891
"--arch=" + str(config.lldb_bitness),
3992
]
4093
if config.lldb_lit_tools_dir:
@@ -56,7 +109,7 @@ def use_lldb_substitutions(config):
56109
ToolSubst(
57110
"%lldb",
58111
command=FindTool("lldb"),
59-
extra_args=["--no-lldbinit", "-S", lldb_init],
112+
extra_args=get_lldb_args(config),
60113
unresolved="fatal",
61114
),
62115
ToolSubst(
@@ -138,7 +191,7 @@ def use_support_substitutions(config):
138191
# Set up substitutions for support tools. These tools can be overridden at the CMake
139192
# level (by specifying -DLLDB_LIT_TOOLS_DIR), installed, or as a last resort, we can use
140193
# the just-built version.
141-
host_flags = ["--target=" + config.host_triple]
194+
host_flags = ["--target=" + config.target_triple]
142195
if platform.system() in ["Darwin"]:
143196
try:
144197
out = subprocess.check_output(["xcrun", "--show-sdk-path"]).strip()
@@ -165,6 +218,14 @@ def use_support_substitutions(config):
165218
if config.cmake_sysroot:
166219
host_flags += ["--sysroot={}".format(config.cmake_sysroot)]
167220

221+
if config.enable_remote and config.has_libcxx:
222+
host_flags += [
223+
"-L{}".format(config.libcxx_libs_dir),
224+
"-Wl,-rpath,{}".format(config.libcxx_libs_dir),
225+
"-lc++",
226+
"-lc++abi",
227+
]
228+
168229
host_flags = " ".join(host_flags)
169230
config.substitutions.append(("%clang_host", "%clang " + host_flags))
170231
config.substitutions.append(("%clangxx_host", "%clangxx " + host_flags))

lldb/test/Shell/lit.cfg.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
config.name = "lldb-shell"
2222

2323
# testFormat: The test format to use to interpret tests.
24-
config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
24+
config.test_format = toolchain.ShTestLldb(not llvm_config.use_lit_shell)
2525

2626
# suffixes: A list of file extensions to treat as test files. This is overriden
2727
# by individual lit.local.cfg files in the test subdirectories.
@@ -68,6 +68,13 @@
6868
lit_config.note("Running Shell tests in {} mode.".format(lldb_repro_mode))
6969
toolchain.use_lldb_repro_substitutions(config, lldb_repro_mode)
7070

71+
if config.lldb_platform_url and config.cmake_sysroot and config.enable_remote:
72+
if re.match(r".*-linux.*", config.target_triple):
73+
config.available_features.add("remote-linux")
74+
else:
75+
# After this, enable_remote == True iff remote testing is going to be used.
76+
config.enable_remote = False
77+
7178
llvm_config.use_default_substitutions()
7279
toolchain.use_lldb_substitutions(config)
7380
toolchain.use_support_substitutions(config)

lldb/test/Shell/lit.site.cfg.py.in

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ config.lldb_src_root = "@LLDB_SOURCE_DIR@"
1010
config.lldb_obj_root = "@LLDB_BINARY_DIR@"
1111
config.lldb_libs_dir = lit_config.substitute("@LLDB_LIBS_DIR@")
1212
config.lldb_tools_dir = lit_config.substitute("@LLDB_TOOLS_DIR@")
13+
config.lldb_platform_url = lit_config.substitute("@LLDB_TEST_PLATFORM_URL@")
14+
config.lldb_platform_working_dir = lit_config.substitute("@LLDB_TEST_PLATFORM_WORKING_DIR@")
1315
# Since it comes from the command line, it may have backslashes which
1416
# should not need to be escaped.
1517
config.lldb_lit_tools_dir = lit_config.substitute(r"@LLDB_LIT_TOOLS_DIR@")
16-
config.cmake_sysroot = lit_config.substitute("@CMAKE_SYSROOT@")
18+
config.cmake_sysroot = lit_config.substitute("@LLDB_TEST_SYSROOT@" or "@DEFAULT_SYSROOT@")
19+
config.has_libcxx = @LLDB_HAS_LIBCXX@
20+
config.enable_remote = not @LLDB_SHELL_TESTS_DISABLE_REMOTE@
21+
config.libcxx_libs_dir = "@LIBCXX_LIBRARY_DIR@"
1722
config.target_triple = "@LLVM_TARGET_TRIPLE@"
1823
config.python_executable = "@Python3_EXECUTABLE@"
1924
config.have_zlib = @LLVM_ENABLE_ZLIB@

0 commit comments

Comments
 (0)