Skip to content

Commit b6c6238

Browse files
committed
[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;..." \ ... ```
1 parent 22c572e commit b6c6238

File tree

5 files changed

+50
-2
lines changed

5 files changed

+50
-2
lines changed

lldb/packages/Python/lldbsuite/test/builders/builder.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,20 @@ def getArchCFlags(self, architecture):
3636
"""Returns the ARCH_CFLAGS for the make system."""
3737
return []
3838

39+
def getTargetOsFlag(self, target_os):
40+
if target_os is None:
41+
target_os = configuration.target_os
42+
if target_os is None:
43+
return []
44+
return ["OS=%s" % target_os]
45+
3946
def getMake(self, test_subdir, test_name):
4047
"""Returns the invocation for GNU make.
4148
The first argument is a tuple of the relative path to the testcase
4249
and its filename stem."""
43-
if platform.system() == "FreeBSD" or platform.system() == "NetBSD":
50+
if configuration.make_path is not None:
51+
make = configuration.make_path
52+
elif platform.system() == "FreeBSD" or platform.system() == "NetBSD":
4453
make = "gmake"
4554
else:
4655
make = "make"
@@ -171,6 +180,7 @@ def getBuildCommand(
171180
testdir=None,
172181
testname=None,
173182
make_targets=None,
183+
target_os=None,
174184
):
175185
debug_info_args = self._getDebugInfoArgs(debug_info)
176186
if debug_info_args is None:
@@ -182,6 +192,7 @@ def getBuildCommand(
182192
debug_info_args,
183193
make_targets,
184194
self.getArchCFlags(architecture),
195+
self.getTargetOsFlag(target_os),
185196
self.getArchSpec(architecture),
186197
self.getCCSpec(compiler),
187198
self.getExtraMakeArgs(),

lldb/packages/Python/lldbsuite/test/configuration.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@
3939
count = 1
4040

4141
# The 'arch' and 'compiler' can be specified via command line.
42+
target_os = None
4243
arch = None
4344
compiler = None
4445
dsymutil = None
4546
sdkroot = None
47+
make_path = None
4648

4749
# The overriden dwarf verison.
4850
dwarf_version = 0

lldb/packages/Python/lldbsuite/test/dotest.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,8 @@ def parseOptionsAndInitTestdirs():
266266
configuration.compiler = candidate
267267
break
268268

269+
if args.make:
270+
configuration.make_path = args.make
269271
if args.dsymutil:
270272
configuration.dsymutil = args.dsymutil
271273
elif platform_system == "Darwin":
@@ -304,14 +306,19 @@ def parseOptionsAndInitTestdirs():
304306
lldbtest_config.out_of_tree_debugserver = args.out_of_tree_debugserver
305307

306308
# Set SDKROOT if we are using an Apple SDK
307-
if platform_system == "Darwin" and args.apple_sdk:
309+
if args.sysroot is not None:
310+
configuration.sdkroot = args.sysroot
311+
elif platform_system == "Darwin" and args.apple_sdk:
308312
configuration.sdkroot = seven.get_command_output(
309313
'xcrun --sdk "%s" --show-sdk-path 2> /dev/null' % (args.apple_sdk)
310314
)
311315
if not configuration.sdkroot:
312316
logging.error("No SDK found with the name %s; aborting...", args.apple_sdk)
313317
sys.exit(-1)
314318

319+
if args.target_os:
320+
configuration.target_os = args.target_os
321+
315322
if args.arch:
316323
configuration.arch = args.arch
317324
else:

lldb/packages/Python/lldbsuite/test/dotest_args.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,15 @@ def create_parser():
3131

3232
# C and Python toolchain options
3333
group = parser.add_argument_group("Toolchain options")
34+
group.add_argument(
35+
"--target-os",
36+
metavar="target_os",
37+
dest="target_os",
38+
default="",
39+
help=textwrap.dedent(
40+
"""Specify target os for test compilation. This is useful for cross-compilation."""
41+
),
42+
)
3443
group.add_argument(
3544
"-A",
3645
"--arch",
@@ -49,6 +58,15 @@ def create_parser():
4958
"""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."""
5059
),
5160
)
61+
group.add_argument(
62+
"--sysroot",
63+
metavar="sysroot",
64+
dest="sysroot",
65+
default="",
66+
help=textwrap.dedent(
67+
"""Specify the path to sysroot. This overrides apple_sdk sysroot."""
68+
),
69+
)
5270
if sys.platform == "darwin":
5371
group.add_argument(
5472
"--apple-sdk",
@@ -87,6 +105,12 @@ def create_parser():
87105
),
88106
)
89107

108+
group.add_argument(
109+
"--make",
110+
metavar="make",
111+
dest="make",
112+
help=textwrap.dedent("Specify which make to use."),
113+
)
90114
group.add_argument(
91115
"--dsymutil",
92116
metavar="dsymutil",

lldb/packages/Python/lldbsuite/test/lldbtest.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,11 +1454,15 @@ def getDebugInfo(self):
14541454
def build(
14551455
self,
14561456
debug_info=None,
1457+
target_os=None,
14571458
architecture=None,
14581459
compiler=None,
14591460
dictionary=None,
14601461
make_targets=None,
14611462
):
1463+
if not target_os and configuration.target_os:
1464+
target_os = configuration.target_os
1465+
14621466
"""Platform specific way to build binaries."""
14631467
if not architecture and configuration.arch:
14641468
architecture = configuration.arch

0 commit comments

Comments
 (0)