Skip to content

Commit b3e2874

Browse files
[SYCL][Test E2E] Introduce %{build}/%{run} substitution/expansion (#9299)
Standard LIT's ShTest format only supports substitution that can perform replacements in a single RUN directive, but cannot create multiple commands from a single RUN line. This PR introduces a new test format specific for the SYCL end-to-end tests that has such capability. As part of this change I'm updating most of the tests to start using `%{build}` and switch the most trivial ones to benefit from `%{run}`. This change is part of a longer term goal to enable targeting multiple SYCL backends in a single llvm-lit invocations. However, I'm starting with updating tests' RUN lines before doing the functional change. As such, current RUN lines are generated using `sycle_be` and `target_devices` LIT parameters. I plan to create several dedicated PRs to update tests to switch to the new `%{build}`/`%{run}` syntax once this PR gets merged in.
1 parent 4b65529 commit b3e2874

File tree

4 files changed

+56
-10
lines changed

4 files changed

+56
-10
lines changed

sycl/test-e2e/AtomicRef/add_generic.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
2-
// RUN: %GPU_RUN_PLACEHOLDER %t.out
3-
// RUN: %CPU_RUN_PLACEHOLDER %t.out
4-
// RUN: %ACC_RUN_PLACEHOLDER %t.out
1+
// RUN: %{build} -o %t.out
2+
// RUN: %{run} %t.out
53

64
#include "add.h"
75

sycl/test-e2e/format.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import lit
2+
import lit.formats
3+
4+
class SYCLEndToEndTest(lit.formats.ShTest):
5+
def execute(self, test, litConfig):
6+
filename = test.path_in_suite[-1]
7+
tmpDir, tmpBase = lit.TestRunner.getTempPaths(test)
8+
script = lit.TestRunner.parseIntegratedTestScript(test, require_script=True)
9+
if isinstance(script, lit.Test.Result):
10+
return script
11+
12+
substitutions = lit.TestRunner.getDefaultSubstitutions(test, tmpDir, tmpBase)
13+
# -fsycl-targets is needed for CUDA/HIP, so just use it be default so
14+
# -that new tests by default would runnable there (unless they have
15+
# -other restrictions).
16+
substitutions.append(('%{build}', '%clangxx -fsycl -fsycl-targets=%sycl_triple %s'))
17+
18+
devices_for_test = ['{}:{}'.format(test.config.sycl_be, dev)
19+
for dev in test.config.target_devices.split(',')]
20+
21+
new_script = []
22+
for directive in script:
23+
if not isinstance(directive, lit.TestRunner.CommandDirective):
24+
new_script.append(directive)
25+
continue
26+
27+
if '%{run}' not in directive.command:
28+
new_script.append(directive)
29+
continue
30+
31+
for sycl_device in devices_for_test:
32+
cmd = directive.command.replace(
33+
'%{run}',
34+
'env ONEAPI_DEVICE_SELECTOR={} {}'.format(sycl_device, test.config.run_launcher))
35+
36+
new_script.append(
37+
lit.TestRunner.CommandDirective(
38+
directive.start_line_number,
39+
directive.end_line_number,
40+
directive.keyword,
41+
cmd))
42+
script = new_script
43+
44+
conditions = { feature: True for feature in test.config.available_features }
45+
script = lit.TestRunner.applySubstitutions(script, substitutions, conditions,
46+
recursion_limit=test.config.recursiveExpansionLimit)
47+
useExternalSh = False
48+
return lit.TestRunner._runShTest(test, litConfig, useExternalSh, script, tmpBase)

sycl/test-e2e/lit.cfg.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,6 @@
1818
# name: The name of this test suite.
1919
config.name = 'SYCL'
2020

21-
# testFormat: The test format to use to interpret tests.
22-
#
23-
# For now we require '&&' between commands, until they get globally killed and
24-
# the test runner updated.
25-
config.test_format = lit.formats.ShTest()
26-
2721
# suffixes: A list of file extensions to treat as test files.
2822
config.suffixes = ['.c', '.cpp']
2923

sycl/test-e2e/lit.site.cfg.py.in

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import sys
44
import platform
55

6+
import site
7+
8+
site.addsitedir("@CMAKE_CURRENT_SOURCE_DIR@")
69

710
config.dpcpp_compiler = lit_config.params.get("dpcpp_compiler", "@SYCL_CXX_COMPILER@")
811
config.dpcpp_root_dir= os.path.dirname(os.path.dirname(config.dpcpp_compiler))
@@ -40,3 +43,6 @@ import lit.llvm
4043
lit.llvm.initialize(lit_config, config)
4144

4245
lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg.py")
46+
47+
from format import SYCLEndToEndTest
48+
config.test_format = SYCLEndToEndTest()

0 commit comments

Comments
 (0)