Skip to content

Commit ff5d4bd

Browse files
authored
[libclc][test] Really run libspirv tests on all targets (#19395)
Due to the way `add_lit_testsuite` works, the `check-all` target was not running the libspirv (binding) tests on all targets, instead it was running it on the last target multiple times in parallel. Besides losing the coverage for other targets, this also caused sporadic failures due to tests overwriting each other. #17902 was an attempt to fix this, and it works for running all of the `check-libclc-spirv-*` cmake targets in parallel, but it does not work for the `check-all` target, which is what we use in the CI. This patch fixes the issue by making a different `lit` test suite for each target. See the comment in `libclc/test/CMakeLists.txt` for more details.
1 parent 005c1e2 commit ff5d4bd

File tree

3 files changed

+62
-40
lines changed

3 files changed

+62
-40
lines changed

libclc/test/CMakeLists.txt

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# required by lit.site.cfg.py.in
22
set(LIBCLC_TEST_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
3+
set(LIBCLC_PERTARGET_TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/targets)
34

45
configure_lit_site_cfg(
56
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
@@ -16,40 +17,40 @@ set(LIBCLC_TEST_DEPS
1617
count
1718
)
1819

19-
add_custom_target(check-libclc)
20-
20+
umbrella_lit_testsuite_begin(check-libclc)
2121
foreach( t ${LIBCLC_TARGET_TO_TEST} )
22-
foreach( d ${${t}_devices} )
23-
if( ${d} STREQUAL "none" )
24-
set( mcpu )
25-
set( arch_suffix "${t}" )
26-
else()
27-
set( mcpu "cpu=${d}" )
28-
set( arch_suffix "${d}-${t}" )
29-
endif()
30-
message( " Testing : ${arch_suffix}" )
31-
32-
add_lit_testsuite(check-libclc-spirv-${arch_suffix}
33-
"Running libclc spirv-${arch_suffix} regression tests"
34-
${CMAKE_CURRENT_BINARY_DIR}
35-
ARGS
36-
--verbose
37-
PARAMS "target=${t}" ${mcpu} "libclc-arch-suffix=${arch_suffix}"
38-
"builtins=libspirv-${arch_suffix}.bc"
22+
# Each target gets own lit testsuite directory.
23+
# This is done because all suites passed to add_lit_testsuite
24+
# are collected into a single invocation of lit, for example:
25+
# add_lit_testsuite(check-a dir PARAMS "foo=1")
26+
# add_lit_testsuite(check-b dir PARAMS "foo=2" "bar=3")
27+
# results in a call to lit like this (for `check-all`):
28+
# llvm-lit --param=foo=1 --param=foo=2 --param=bar=3 dir dir
29+
# This means we can't reuse the same directory and rely on
30+
# different parameter values to distinguish between targets, because
31+
# parameters with the same name overwrite each other.
32+
# The solution is to create a separate directory for each target,
33+
# and copy the lit.site.cfg.py file there; the name of the
34+
# directory will be used as the target name.
35+
file(MAKE_DIRECTORY ${LIBCLC_PERTARGET_TEST_DIR}/${t})
36+
file(COPY_FILE ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg.py
37+
${LIBCLC_PERTARGET_TEST_DIR}/${t}/lit.site.cfg.py)
38+
39+
add_lit_testsuite(check-libclc-spirv-${t}
40+
"Running libclc spirv-${t} regression tests"
41+
${LIBCLC_PERTARGET_TEST_DIR}/${t}
3942
DEPENDS
4043
${LIBCLC_TEST_DEPS}
4144
libspirv-builtins
4245
)
43-
44-
add_dependencies(check-libclc check-libclc-spirv-${arch_suffix})
45-
46-
endforeach( d )
4746
endforeach( t )
4847

4948
if(LIBCLC_GENERATE_REMANGLED_VARIANTS)
50-
#Now that check-libclc is defined make sure that all remangler targets depend
49+
# Now that check-libclc is defined make sure that all remangler targets depend
5150
# on it.
5251
foreach(remangler-test ${libclc-remangler-tests})
53-
add_dependencies(check-libclc ${remangler-test})
52+
set_property(GLOBAL APPEND PROPERTY LLVM_LIBCLC_ADDITIONAL_TEST_TARGETS ${remangler-test})
53+
set_property(GLOBAL APPEND PROPERTY LLVM_ALL_ADDITIONAL_TEST_TARGETS ${remangler-test})
5454
endforeach()
5555
endif()
56+
umbrella_lit_testsuite_end(check-libclc)

libclc/test/lit.cfg.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,25 @@
99
from lit.llvm.subst import ToolSubst
1010
from lit.llvm.subst import FindTool
1111

12+
13+
def quote(s):
14+
return f"'{s}'"
15+
16+
1217
# Configuration file for the 'lit' test runner.
1318

19+
if config.libclc_target is None:
20+
lit_config.fatal("libclc_target parameter must be set when running directly")
21+
22+
if config.libclc_target not in config.libclc_targets_to_test:
23+
lit_config.fatal(
24+
f"libclc_target '{config.libclc_target}' is not built. "
25+
f"Available targets: {', '.join(quote(s) for s in config.libclc_targets_to_test)}"
26+
)
27+
1428
# name: The name of this test suite.
15-
config.name = "LIBCLC"
29+
config.name = f"LIBCLC-{config.libclc_target.upper()}"
30+
1631

1732
# testFormat: The test format to use to interpret tests.
1833
config.test_format = lit.formats.ShTest(not llvm_config.use_lit_shell)
@@ -28,16 +43,12 @@
2843

2944
libclc_inc = os.path.join(config.libclc_root, "libspirv", "include")
3045

31-
target = lit_config.params.get("target", "")
32-
builtins = lit_config.params.get("builtins", "")
33-
cpu = lit_config.params.get("cpu", "")
34-
cpu = [] if cpu == "" else ["-mcpu=" + cpu]
35-
libclc_arch_suffix = lit_config.params.get("libclc-arch-suffix", "")
36-
3746
# test_exec_root: The root path where tests should be run. We create a unique
3847
# test directory per libclc target to test to avoid data races when multiple
3948
# targets try and access the the same libclc test files.
40-
config.test_exec_root = os.path.join(config.test_run_dir, "test", libclc_arch_suffix)
49+
config.test_exec_root = os.path.join(
50+
config.libclc_pertarget_test_dir, config.libclc_target
51+
)
4152

4253
llvm_config.use_default_substitutions()
4354

@@ -46,24 +57,22 @@
4657
"-I",
4758
libclc_inc,
4859
"-target",
49-
target,
60+
config.libclc_target,
5061
"-Xclang",
5162
"-fdeclare-spirv-builtins",
5263
"-Xclang",
5364
"-mlink-builtin-bitcode",
5465
"-Xclang",
55-
os.path.join(config.llvm_libs_dir, "clc", builtins),
66+
os.path.join(config.llvm_libs_dir, "clc", f"libspirv-{config.libclc_target}.bc"),
5667
"-nogpulib",
5768
]
5869

59-
if target == "amdgcn--amdhsa":
60-
config.available_features.add("amdgcn")
61-
70+
if config.libclc_target == "amdgcn--amdhsa":
6271
# libclc for amdgcn is currently built for tahiti which doesn't support
6372
# fp16 so disable the extension for the tests
6473
clang_flags += ["-Xclang", "-cl-ext=-cl_khr_fp16"]
6574

66-
llvm_config.use_clang(additional_flags=clang_flags + cpu)
75+
llvm_config.use_clang(additional_flags=clang_flags)
6776

6877
config.substitutions.append(("%PATH%", config.environment["PATH"]))
6978

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@LIT_SITE_CFG_IN_HEADER@
22

3+
import os
34
import sys
45

56
config.llvm_src_root = "@LLVM_SOURCE_DIR@"
@@ -14,10 +15,21 @@ config.target_triple = "@LLVM_TARGET_TRIPLE@"
1415
config.host_arch = "@HOST_ARCH@"
1516
config.python_executable = "@PYTHON_EXECUTABLE@"
1617
config.libclc_root = "@LIBCLC_SOURCE_DIR@"
17-
config.test_run_dir = "@LIBCLC_BINARY_DIR@"
18+
config.libclc_binary_dir = "@LIBCLC_BINARY_DIR@"
19+
config.libclc_targets_to_test = "@LIBCLC_TARGET_TO_TEST@".split(";")
20+
config.libclc_pertarget_test_dir = "@LIBCLC_PERTARGET_TEST_DIR@"
1821

1922
import lit.llvm
2023
lit.llvm.initialize(lit_config, config)
2124

25+
config.libclc_target = lit_config.params.get("libclc_target")
26+
27+
if config.libclc_target is None:
28+
# This file is copied to per-target test directories by cmake,
29+
# use the name of the directory containing this file as the target name.
30+
dirname = os.path.dirname(__file__)
31+
if os.path.realpath(dirname) != os.path.realpath("@CMAKE_CURRENT_BINARY_DIR@"):
32+
config.libclc_target = os.path.basename(dirname)
33+
2234
# Let the main config do the real work.
2335
lit_config.load_config(config, "@LIBCLC_TEST_SOURCE_DIR@/lit.cfg.py")

0 commit comments

Comments
 (0)