Skip to content

Commit 84fac44

Browse files
authored
[libclc] Fix data races in libclc/libspirv LIT tests (#17902)
Multiple libclc test targets were running essentially the same test suite in parallel. This could result in data races when one target writes a file another target is reading. This commit fixes the issue by creating a unique test execution directory per target. We already have a unique libclc target known as an 'arch suffix' in CMake. This suffix is used as the unique builtins file name. We pass this through to LIT via a parameter to create the execution directory. Note this use of LIT (i.e., having one suite called multiple times in different configurations) is unconventional so there aren't many similar examples in LLVM. Patch proposed by @bader.
1 parent 2eb58f8 commit 84fac44

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

libclc/test/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ set(LIBCLC_TEST_DEPS
1919
add_custom_target(check-libclc)
2020

2121
foreach( t ${LIBCLC_TARGET_TO_TEST} )
22-
foreach( d ${${t}_devices} )
22+
foreach( d ${${t}_devices} )
2323
if( ${d} STREQUAL "none" )
2424
set( mcpu )
2525
set( arch_suffix "${t}" )
@@ -29,11 +29,13 @@ foreach( t ${LIBCLC_TARGET_TO_TEST} )
2929
endif()
3030
message( " Testing : ${arch_suffix}" )
3131

32-
add_lit_testsuite(check-libclc-spirv-${arch_suffix} "Running libclc spirv-${arch_suffix} regression tests"
32+
add_lit_testsuite(check-libclc-spirv-${arch_suffix}
33+
"Running libclc spirv-${arch_suffix} regression tests"
3334
${CMAKE_CURRENT_BINARY_DIR}
3435
ARGS
3536
--verbose
36-
PARAMS "target=${t}" ${mcpu} "builtins=libspirv-${arch_suffix}.bc"
37+
PARAMS "target=${t}" ${mcpu} "libclc-arch-suffix=${arch_suffix}"
38+
"builtins=libspirv-${arch_suffix}.bc"
3739
DEPENDS
3840
${LIBCLC_TEST_DEPS}
3941
libspirv-builtins

libclc/test/lit.cfg.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,18 @@
2626
# test_source_root: The root path where tests are located.
2727
config.test_source_root = os.path.join(os.path.dirname(__file__), "binding")
2828

29-
# test_exec_root: The root path where tests should be run.
30-
config.test_exec_root = os.path.join(config.test_run_dir, "test")
31-
3229
libclc_inc = os.path.join(config.libclc_root, "libspirv", "include")
3330

3431
target = lit_config.params.get("target", "")
3532
builtins = lit_config.params.get("builtins", "")
3633
cpu = lit_config.params.get("cpu", "")
3734
cpu = [] if cpu == "" else ["-mcpu=" + cpu]
35+
libclc_arch_suffix = lit_config.params.get("libclc-arch-suffix", "")
36+
37+
# test_exec_root: The root path where tests should be run. We create a unique
38+
# test directory per libclc target to test to avoid data races when multiple
39+
# 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)
3841

3942
llvm_config.use_default_substitutions()
4043

0 commit comments

Comments
 (0)