Skip to content

[CI][SYCL][Test] Make check-sycl-unittests also run unit tests with ABI breaking changes. #19687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Aug 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 50 additions & 11 deletions sycl/cmake/modules/AddSYCLUnitTest.cmake
Original file line number Diff line number Diff line change
@@ -1,21 +1,40 @@
# add_sycl_unittest(test_dirname SHARED|OBJECT file1.cpp, file2.cpp ...)
#
# Will compile the list of files together and link against SYCL.
# Produces a binary names `basename(test_dirname)`.
macro(add_sycl_unittest test_dirname link_variant)
# Internal function to create SYCL unit tests with code reuse
# add_sycl_unittest_internal(test_dirname SHARED|OBJECT is_preview file1.cpp, file2.cpp ...)
function(add_sycl_unittest_internal test_dirname link_variant is_preview)
# Enable exception handling for these unit tests
set(LLVM_REQUIRES_EH ON)
set(LLVM_REQUIRES_RTTI ON)

get_target_property(SYCL_BINARY_DIR sycl-toolchain BINARY_DIR)

string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type_lower)

# Select which sycl libraries and object to link based
# on whether this is a preview build.
if (MSVC AND build_type_lower MATCHES "debug")
set(sycl_obj_target "sycld_object")
set(sycl_so_target "sycld")
if (${is_preview})
set(sycl_obj_target "sycl-previewd_object")
set(sycl_so_target "sycl-previewd")
else()
set(sycl_obj_target "sycld_object")
set(sycl_so_target "sycld")
endif()
else()
set(sycl_obj_target "sycl_object")
set(sycl_so_target "sycl")
if (${is_preview})
set(sycl_obj_target "sycl-preview_object")
set(sycl_so_target "sycl-preview")
else()
set(sycl_obj_target "sycl_object")
set(sycl_so_target "sycl")
endif()
endif()

# This is done to ensure that preview tests are kept in a separate
# directory, so that they do not interfere with the non-preview tests.
# Chaning CMAKE_CURRENT_BINARY_DIR should not affect this variable in its
# parent scope.
if (${is_preview})
set(CMAKE_CURRENT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/Preview")
endif()

if ("${link_variant}" MATCHES "SHARED")
Expand All @@ -39,6 +58,13 @@ macro(add_sycl_unittest test_dirname link_variant)
)
endif()

# Add preview-specific compile definition
if (${is_preview})
target_compile_definitions(${test_dirname}
PRIVATE __INTEL_PREVIEW_BREAKING_CHANGES)
set(sycl_cache_suffix "_preview")
endif()

if (SYCL_ENABLE_XPTI_TRACING)
target_compile_definitions(${test_dirname}
PRIVATE XPTI_ENABLE_INSTRUMENTATION XPTI_STATIC_LIBRARY)
Expand All @@ -53,9 +79,10 @@ macro(add_sycl_unittest test_dirname link_variant)
LLVM_PROFILE_FILE="${SYCL_COVERAGE_PATH}/${test_dirname}.profraw"
SYCL_CONFIG_FILE_NAME=null.cfg
SYCL_DEVICELIB_NO_FALLBACK=1
SYCL_CACHE_DIR="${CMAKE_BINARY_DIR}/sycl_cache"
SYCL_CACHE_DIR="${CMAKE_BINARY_DIR}/sycl_cache${sycl_cache_suffix}"
"PATH=${CMAKE_BINARY_DIR}/bin;$ENV{PATH}"
${CMAKE_CURRENT_BINARY_DIR}/${test_dirname}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS
${test_dirname}
)
Expand All @@ -65,9 +92,10 @@ macro(add_sycl_unittest test_dirname link_variant)
LLVM_PROFILE_FILE="${SYCL_COVERAGE_PATH}/${test_dirname}.profraw"
SYCL_CONFIG_FILE_NAME=null.cfg
SYCL_DEVICELIB_NO_FALLBACK=1
SYCL_CACHE_DIR="${CMAKE_BINARY_DIR}/sycl_cache"
SYCL_CACHE_DIR="${CMAKE_BINARY_DIR}/sycl_cache${sycl_cache_suffix}"
"LD_LIBRARY_PATH=${SYCL_BINARY_DIR}/unittests/lib:${CMAKE_BINARY_DIR}/lib:$ENV{LD_LIBRARY_PATH}"
${CMAKE_CURRENT_BINARY_DIR}/${test_dirname}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS
${test_dirname}
)
Expand All @@ -79,6 +107,7 @@ macro(add_sycl_unittest test_dirname link_variant)
# Windows doesn't support LD_LIBRARY_PATH, so instead we copy the mock OpenCL binary next to the test and ensure
# that the test itself links to OpenCL (rather than through ur_adapter_opencl.dll)
Copy link
Preview

Copilot AI Aug 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] There's a spelling error in the comment. 'ur_adapter_opencl.dll' should be 'ur_adapter_opencl.dll' (no change needed, comment is actually correct).

Copilot uses AI. Check for mistakes.

set(mock_ocl ${CMAKE_CURRENT_BINARY_DIR}/OpenCL.dll)

add_custom_command(TARGET ${test_dirname} POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:mockOpenCL> ${mock_ocl}
DEPENDS mockOpenCL
Expand Down Expand Up @@ -122,4 +151,14 @@ macro(add_sycl_unittest test_dirname link_variant)
endif()

target_compile_definitions(${test_dirname} PRIVATE SYCL_DISABLE_FSYCL_SYCLHPP_WARNING)
endfunction()

# add_sycl_unittest(test_name_prefix SHARED|OBJECT file1.cpp, file2.cpp ...)
#
# Will compile the list of files together to create two builds, with and without
# the SYCL preview features enabled.
# Produces two binaries, named `basename(test_name_prefix_non_preview)` and `basename(test_name_prefix_preview)`
macro(add_sycl_unittest test_name_prefix link_variant)
add_sycl_unittest_internal(${test_name_prefix}_non_preview ${link_variant} FALSE ${ARGN})
add_sycl_unittest_internal(${test_name_prefix}_preview ${link_variant} TRUE ${ARGN})
endmacro()
4 changes: 4 additions & 0 deletions sycl/unittests/Extensions/LaunchQueries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ auto getKernel(const sycl::queue &Q) {
return KernelBundle.get_kernel(KernelID);
}

// These tests fail in preview breaking mode.
// Failure Tracker: https://github.com/intel/llvm/issues/18910
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
TEST(LaunchQueries, GetWorkGroupSizeSuccess) {
sycl::unittest::UrMock<> Mock;
mock::getCallbacks().set_replace_callback(
Expand Down Expand Up @@ -146,6 +149,7 @@ TEST(LaunchQueries, GetMaxWorkGroupItemSizesExceptionCode) {
syclex::info::kernel_queue_specific::max_work_item_sizes<3>>(Queue),
sycl::exception);
}
#endif // __INTEL_PREVIEW_BREAKING_CHANGES

TEST(LaunchQueries, GetMaxSubGroupSize3DSuccess) {
sycl::unittest::UrMock<> Mock;
Expand Down
3 changes: 2 additions & 1 deletion sycl/unittests/compression/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
add_sycl_unittest(CompressionTests OBJECT
CompressionTests.cpp
)
target_compile_definitions(CompressionTests PRIVATE SYCL_RT_ZSTD_AVAILABLE)
target_compile_definitions(CompressionTests_non_preview PRIVATE SYCL_RT_ZSTD_AVAILABLE)
target_compile_definitions(CompressionTests_preview PRIVATE SYCL_RT_ZSTD_AVAILABLE)
2 changes: 1 addition & 1 deletion sycl/unittests/event/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
add_sycl_unittest(EventTests OBJECT
EventDestruction.cpp
)
)
3 changes: 2 additions & 1 deletion sycl/unittests/kernel-and-program/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ add_sycl_unittest(KernelAndProgramTests OBJECT
OutOfResources.cpp
InMemCacheEviction.cpp
)
target_compile_definitions(KernelAndProgramTests PRIVATE -D__SYCL_INTERNAL_API)
target_compile_definitions(KernelAndProgramTests_non_preview PRIVATE -D__SYCL_INTERNAL_API)
target_compile_definitions(KernelAndProgramTests_preview PRIVATE -D__SYCL_INTERNAL_API)
4 changes: 4 additions & 0 deletions sycl/unittests/misc/OsUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,12 @@ bool isSameDir(const char* LHS, const char* RHS) {
class OsUtilsTest : public ::testing::Test {
};

// This test fails with preview breaking changes enabled.
// Failure tracker: https://github.com/intel/llvm/issues/19626
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
TEST_F(OsUtilsTest, getCurrentDSODir) {
std::string DSODir = sycl::detail::OSUtil::getCurrentDSODir();
ASSERT_TRUE(isSameDir(DSODir.c_str(), SYCL_LIB_DIR)) <<
"expected: " << SYCL_LIB_DIR << ", got: " << DSODir;
}
#endif
6 changes: 4 additions & 2 deletions sycl/unittests/pipes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ add_sycl_unittest(PipeTests OBJECT
host_pipe_registration.cpp
)

add_dependencies(PipeTests sycl)
target_include_directories(PipeTests PRIVATE SYSTEM ${sycl_inc_dir})
add_dependencies(PipeTests_non_preview sycl)
target_include_directories(PipeTests_non_preview PRIVATE SYSTEM ${sycl_inc_dir})
add_dependencies(PipeTests_preview sycl)
target_include_directories(PipeTests_preview PRIVATE SYSTEM ${sycl_inc_dir})
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ class MockHandler : public sycl::handler {
using sycl::handler::impl;

MockHandler(sycl::detail::queue_impl &Queue)
: sycl::handler(Queue.shared_from_this(), /*CallerNeedsEvent*/ true) {}
: sycl::handler(std::make_unique<sycl::detail::handler_impl>(
Queue, nullptr, /*CallerNeedsEvent*/ true)) {}

std::unique_ptr<sycl::detail::CG> finalize() {
auto CGH = static_cast<sycl::handler *>(this);
Expand Down
2 changes: 1 addition & 1 deletion sycl/unittests/scheduler/InOrderQueueSyncCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class LimitedHandler {

#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
virtual sycl::detail::EventImplPtr finalize() {
return std::make_shared<detail::event_impl>();
return detail::event_impl::create_default_event();
}
#else
virtual event finalize() {
Expand Down
3 changes: 2 additions & 1 deletion sycl/unittests/scheduler/SchedulerTestUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ sycl::detail::Requirement getMockRequirement(const MemObjT &MemObj) {
class MockHandler : public sycl::handler {
public:
MockHandler(sycl::detail::queue_impl &Queue, bool CallerNeedsEvent)
: sycl::handler(Queue.shared_from_this(), CallerNeedsEvent) {}
: sycl::handler(std::make_unique<sycl::detail::handler_impl>(
Copy link
Preview

Copilot AI Aug 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The constructor call spans multiple lines but the closing parenthesis and brace are on separate lines. Consider formatting this consistently, either keeping the entire constructor call on one line or aligning the closing elements properly.

Copilot uses AI. Check for mistakes.

Queue, nullptr, CallerNeedsEvent)) {}
// Methods
using sycl::handler::addReduction;
using sycl::handler::getType;
Expand Down
6 changes: 4 additions & 2 deletions sycl/unittests/ur/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@ add_sycl_unittest(UrTests OBJECT
UrUtility.cpp
)

add_dependencies(UrTests sycl)
target_include_directories(UrTests PRIVATE SYSTEM ${sycl_inc_dir})
add_dependencies(UrTests_non_preview sycl)
target_include_directories(UrTests_non_preview PRIVATE SYSTEM ${sycl_inc_dir})
add_dependencies(UrTests_preview sycl)
target_include_directories(UrTests_preview PRIVATE SYSTEM ${sycl_inc_dir})
3 changes: 2 additions & 1 deletion sycl/unittests/xpti_trace/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ add_sycl_unittest(XptiTraceTests OBJECT
NodeCreation.cpp
QueueIDCheck.cpp
)
target_link_libraries(XptiTraceTests PRIVATE xpti xptitest_subscriber)
target_link_libraries(XptiTraceTests_non_preview PRIVATE xpti xptitest_subscriber)
target_link_libraries(XptiTraceTests_preview PRIVATE xpti xptitest_subscriber)