Skip to content

Commit 0d07150

Browse files
committed
Upgrade self-contained-headers test suite
1 parent 41245b0 commit 0d07150

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

sycl/test/format.py

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,55 @@
55
import os
66
import re
77

8-
SUFFIXES = {".hpp"}
9-
10-
118
class SYCLHeadersTest(lit.formats.TestFormat):
129
def getTestsForPath(
1310
self, testSuite, path_in_suite, filepath, litConfig, localConfig
1411
):
12+
# path_in_suite is a tuple like:
13+
# ('self-contained-headers', 'path/to', 'file.hpp')
14+
test_path = testSuite.getSourcePath(path_in_suite) + ".cpp"
15+
if os.path.exists(test_path):
16+
# We have a dedicated special test for a header, let's use a file
17+
# from the suite itself
18+
19+
# None is a special value we use to distinguish those two cases
20+
filepath = None
21+
else:
22+
# We don't have a dedicated special test for a header, therefore we
23+
# fallback to a generalized version of it
24+
25+
# SYCL headers may depend on some generated files and therefore we
26+
# use headers from the build folder for testing
27+
filepath = os.path.join(localConfig.sycl_include, *path_in_suite[1:])
28+
1529
yield lit.Test.Test(testSuite, path_in_suite, localConfig, file_path=filepath)
1630

1731
def getTestsInDirectory(self, testSuite, path_in_suite, litConfig, localConfig):
18-
# We traverse build/sycl/include/sycl directory
19-
source_path = os.path.join(localConfig.sycl_include, "sycl")
32+
# To respect SYCL_LIB_DUMPS_ONLY mode
33+
if ".cpp" not in localConfig.suffixes:
34+
return
35+
36+
# As we add more files and folders into 'self-contained-headers', this
37+
# method will be recursivelly called for them by lit discovery.
38+
# However, we don't use the test folder as the source of tests but
39+
# instead we use SYCL_SOURCE_DIR/include/sycl directory.
40+
# Therefore, we exit early from here if `path_in_suite` conatins more
41+
# than one element
42+
assert path_in_suite[0] == "self-contained-headers"
43+
if len(path_in_suite) > 1:
44+
return
45+
46+
source_path = os.path.join(localConfig.sycl_include_source_dir, "sycl")
2047

2148
# Optional filter can be passed through command line options
2249
headers_filter = localConfig.sycl_headers_filter
2350
for dirpath, _, filenames in os.walk(source_path):
24-
relative_dirpath = dirpath[len(localConfig.sycl_include) + 1 :]
51+
relative_dirpath = dirpath[len(localConfig.sycl_include_source_dir) + 1 :]
2552
for filename in filenames:
2653
suffix = os.path.splitext(filename)[1]
27-
if suffix not in SUFFIXES or suffix not in litConfig.suffixes:
54+
# We only look at actual header files and not at their .inc/.def
55+
# components
56+
if suffix != ".hpp":
2857
continue
2958
filepath = os.path.join(dirpath, filename)
3059

@@ -46,6 +75,17 @@ def getTestsInDirectory(self, testSuite, path_in_suite, litConfig, localConfig):
4675
yield t
4776

4877
def execute(self, test, litConfig):
78+
if test.file_path is None:
79+
# It means that we have a special test case for a header and we need
80+
# to execute it as a regular lit sh test
81+
return lit.TestRunner.executeShTest(
82+
test, litConfig,
83+
False, # execute_external
84+
[], # extra_substitutions
85+
[], # preamble_commands
86+
)
87+
88+
# Otherwise we generate the test on the fly
4989
command = [
5090
test.config.clang,
5191
"-fsycl",

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ config.sycl_tools_dir = lit_config.params.get('SYCL_TOOLS_DIR', "@LLVM_TOOLS_DIR
99
config.sycl_include = lit_config.params.get('SYCL_INCLUDE', "@SYCL_INCLUDE@")
1010
config.sycl_obj_root = "@SYCL_BINARY_DIR@"
1111
config.sycl_source_dir = "@SYCL_SOURCE_DIR@/source"
12+
config.sycl_include_source_dir = "@SYCL_SOURCE_DIR@/include"
1213
config.sycl_libs_dir = lit_config.params.get('SYCL_LIBS_DIR', "@LLVM_LIBS_DIR@")
1314
config.target_triple = "@LLVM_TARGET_TRIPLE@"
1415
config.host_triple = "@LLVM_HOST_TRIPLE@"

0 commit comments

Comments
 (0)