[libclc][CMake] Add check-libclc umbrella test target (#186053)

This allows running the full test suite using `ninja check-libclc`.
This commit is contained in:
Wenju He 2026-03-12 19:55:18 +08:00 committed by GitHub
parent 540ea54ad7
commit d352aac32c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 112 additions and 12 deletions

View File

@ -138,8 +138,6 @@ add_custom_target( libclc ALL )
add_custom_target( libclc-opencl-builtins COMMENT "Build libclc OpenCL builtins" )
add_dependencies( libclc libclc-opencl-builtins )
enable_testing()
foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
message( STATUS "libclc target '${t}' is enabled" )
string( REPLACE "-" ";" TRIPLE ${t} )
@ -279,3 +277,5 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
PARENT_TARGET libclc-opencl-builtins
)
endforeach()
add_subdirectory(test)

View File

@ -187,14 +187,4 @@ function(add_libclc_library target_name)
DESTINATION ${LIBCLC_INSTALL_DIR}/${ARG_TRIPLE}
COMPONENT ${ARG_PARENT_TARGET}
)
# Verify there are no unresolved external functions in the library.
if(NOT ARG_ARCH MATCHES "^(nvptx|clspv)(64)?$" AND
NOT ARG_ARCH MATCHES "^spirv(64)?$")
set(builtins_file $<TARGET_PROPERTY:${target_name},TARGET_FILE>)
add_test(NAME external-funcs-${target_name}
COMMAND ./check_external_funcs.sh
${builtins_file} ${LLVM_TOOLS_BINARY_DIR}
WORKING_DIRECTORY ${LIBCLC_SOURCE_DIR})
endif()
endfunction()

View File

@ -0,0 +1,50 @@
set(LIBCLC_LIBRARY_DIR ${LIBCLC_OUTPUT_LIBRARY_DIR})
set(LLVM_TOOLS_DIR ${LLVM_TOOLS_BINARY_DIR})
set(LIBCLC_TEST_DEPS
llvm-dis
)
umbrella_lit_testsuite_begin(check-libclc)
# Testing unresolved symbols.
# check_external_funcs.sh does not work on Windows
if(NOT WIN32)
foreach(t ${LIBCLC_TARGETS_TO_BUILD})
string(REPLACE "-" ";" TRIPLE ${t})
list(GET TRIPLE 0 ARCH)
# Skip nvptx, clspv, spirv targets
if(ARCH MATCHES "^(nvptx|clspv)(64)?$" OR ARCH MATCHES "^spirv(64)?$")
continue()
endif()
# Get the output file from the target property
get_target_property(target_file libclc-${t} TARGET_FILE)
get_filename_component(output_file ${target_file} NAME)
set(LIBCLC_TARGET_TEST_DIR ${CMAKE_CURRENT_BINARY_DIR}/${t})
file(MAKE_DIRECTORY ${LIBCLC_TARGET_TEST_DIR})
file(WRITE ${LIBCLC_TARGET_TEST_DIR}/check-external-funcs.test
"// RUN: %check_external_funcs %libclc_library_dir/${t}/${output_file} %llvm_tools_dir
// This test verifies that the libclc library for ${t} has no
// unresolved external functions (except LLVM intrinsics).
")
configure_lit_site_cfg(
${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
${LIBCLC_TARGET_TEST_DIR}/lit.site.cfg.py
MAIN_CONFIG
${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
)
add_lit_testsuite(check-libclc-external-funcs-${t} "Running ${t} tests"
${LIBCLC_TARGET_TEST_DIR}
DEPENDS libclc-${t} ${LIBCLC_TEST_DEPS}
)
set_target_properties(check-libclc-external-funcs-${t} PROPERTIES FOLDER "libclc tests")
endforeach()
endif()
umbrella_lit_testsuite_end(check-libclc)

46
libclc/test/lit.cfg.py Normal file
View File

@ -0,0 +1,46 @@
"""
Lit configuration file for libclc tests.
"""
import os
import lit.formats
# Configuration file for the 'lit' test runner.
# name: The name of this test suite.
config.name = "libclc"
# testFormat: The test format to use to interpret tests.
config.test_format = lit.formats.ShTest(True)
# suffixes: A list of file extensions to treat as test files.
config.suffixes = [".test"]
# Exclude certain directories from test discovery
config.excludes = ["CMakeLists.txt"]
# test_source_root: The root path where tests are located.
# For per-target tests, this is the target's test directory.
config.test_source_root = config.libclc_obj_root
# test_exec_root: The root path where tests should be run.
config.test_exec_root = config.libclc_obj_root
# Propagate PATH from environment
if "PATH" in os.environ:
config.environment["PATH"] = os.path.pathsep.join(
[config.llvm_tools_dir, os.environ["PATH"]]
)
else:
config.environment["PATH"] = config.llvm_tools_dir
# Define substitutions for the test files
config.substitutions.append(("%libclc_library_dir", config.libclc_library_dir))
config.substitutions.append(("%llvm_tools_dir", config.llvm_tools_dir))
config.substitutions.append(
(
"%check_external_funcs",
os.path.join(config.libclc_test_root, "check_external_funcs.sh"),
)
)

View File

@ -0,0 +1,14 @@
@LIT_SITE_CFG_IN_HEADER@
import sys
config.llvm_tools_dir = "@LLVM_TOOLS_DIR@"
config.libclc_obj_root = "@LIBCLC_TARGET_TEST_DIR@"
config.libclc_test_root = "@CMAKE_CURRENT_SOURCE_DIR@"
config.libclc_library_dir = "@LIBCLC_LIBRARY_DIR@"
import lit.llvm
lit.llvm.initialize(lit_config, config)
# Let the main config do the real work.
lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg.py")