Skip to content

Commit 3467a00

Browse files
authored
[SYCL][E2E] Substitute paths to lit tool binaries (#9041)
This change makes LIT explicitly substitute uses of tool binaries in tests with their full paths. This makes test RUN lines easier to reproduce, as it negates the effect of lit's internal environment (e.g., PATH) on which tools are run. The list of tools affected are: sycl-ls llvm-spirv, llvm-link, FileCheck and not (when used after a pipe). This also changes the behaviour of how LIT finds sycl-ls, llvm-spirv, and llvm-link. Whereas before these tools were found only on the PATH, now they will be preferably sourced first from the in-tree tools directory.
1 parent 21f68c7 commit 3467a00

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

sycl/test-e2e/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ unavailable.
181181
* **gpu-intel-dg2** - Intel GPU DG2 availability;
182182
* **gpu-intel-pvc** - Intel GPU PVC availability;
183183
* **dump_ir**: - compiler can / cannot dump IR;
184+
* **llvm-spirv** - llvm-spirv tool availability;
185+
* **llvm-link** - llvm-link tool availability;
184186

185187
## llvm-lit parameters
186188

sycl/test-e2e/lit.cfg.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import lit.util
1212

1313
from lit.llvm import llvm_config
14+
from lit.llvm.subst import ToolSubst, FindTool
1415

1516
# Configuration file for the 'lit' test runner.
1617

@@ -34,6 +35,9 @@
3435
# test_exec_root: The root path where tests should be run.
3536
config.test_exec_root = config.sycl_obj_root
3637

38+
# allow expanding substitutions that are based on other substitutions
39+
config.recursiveExpansionLimit = 10
40+
3741
# Cleanup environment variables which may affect tests
3842
possibly_dangerous_env_vars = ['COMPILER_PATH', 'RC_DEBUG_OPTIONS',
3943
'CINDEXTEST_PREAMBLE_FILE', 'LIBRARY_PATH',
@@ -390,7 +394,6 @@
390394

391395
if config.run_launcher:
392396
config.substitutions.append(('%e2e_tests_root', config.test_source_root))
393-
config.recursiveExpansionLimit = 10
394397

395398
if config.sycl_be == 'ext_oneapi_cuda' or (config.sycl_be == 'ext_oneapi_hip' and config.hip_platform == 'NVIDIA'):
396399
config.substitutions.append( ('%sycl_triple', "nvptx64-nvidia-cuda" ) )
@@ -399,9 +402,6 @@
399402
else:
400403
config.substitutions.append( ('%sycl_triple', "spir64" ) )
401404

402-
if find_executable('sycl-ls'):
403-
config.available_features.add('sycl-ls')
404-
405405
# TODO properly set XPTIFW include and runtime dirs
406406
xptifw_lib_dir = os.path.join(config.dpcpp_root_dir, 'lib')
407407
xptifw_dispatcher = ""
@@ -418,17 +418,32 @@
418418
else:
419419
config.substitutions.append(('%xptifw_lib', " -L{} -lxptifw -I{} ".format(xptifw_lib_dir, xptifw_includes)))
420420

421-
422-
llvm_tools = ["llvm-spirv", "llvm-link"]
423-
for llvm_tool in llvm_tools:
424-
llvm_tool_path = find_executable(llvm_tool)
425-
if llvm_tool_path:
426-
lit_config.note("Found " + llvm_tool)
427-
config.available_features.add(llvm_tool)
428-
config.substitutions.append( ('%' + llvm_tool.replace('-', '_'),
429-
os.path.realpath(llvm_tool_path)) )
430-
else:
431-
lit_config.warning("Can't find " + llvm_tool)
421+
# Tools for which we add a corresponding feature when available.
422+
feature_tools = [
423+
ToolSubst('llvm-spirv', unresolved='ignore'),
424+
ToolSubst('llvm-link', unresolved='ignore'),
425+
]
426+
427+
tools = [
428+
ToolSubst('FileCheck', unresolved='ignore'),
429+
# not is only substituted in certain circumstances; this is lit's default
430+
# behaviour.
431+
ToolSubst(r'\| \bnot\b', command=FindTool('not'),
432+
verbatim=True, unresolved='ignore'),
433+
ToolSubst('sycl-ls', unresolved='ignore'),
434+
] + feature_tools
435+
436+
# Try and find each of these tools in the llvm tools directory or the PATH, in
437+
# that order. If found, they will be added as substitutions with the full path
438+
# to the tool. This allows us to support both in-tree builds and standalone
439+
# builds, where the tools may be externally defined.
440+
llvm_config.add_tool_substitutions(tools, [config.llvm_tools_dir,
441+
os.environ.get('PATH', '')])
442+
for tool in feature_tools:
443+
if tool.was_resolved:
444+
config.available_features.add(tool.key)
445+
else:
446+
lit_config.warning("Can't find " + tool.key)
432447

433448
if find_executable('cmc'):
434449
config.available_features.add('cm-compiler')

0 commit comments

Comments
 (0)