Skip to content

Commit 2443f54

Browse files
[CI][SYCL][Test] Make check-sycl-unittests also run unit tests with ABI breaking changes. (#19687)
This PR makes `check-sycl-unittests` CMake target run both preview and non-preview version of unit tests. --------- Co-authored-by: Copilot <[email protected]>
1 parent 11df329 commit 2443f54

File tree

12 files changed

+78
-22
lines changed

12 files changed

+78
-22
lines changed

sycl/cmake/modules/AddSYCLUnitTest.cmake

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,40 @@
1-
# add_sycl_unittest(test_dirname SHARED|OBJECT file1.cpp, file2.cpp ...)
2-
#
3-
# Will compile the list of files together and link against SYCL.
4-
# Produces a binary names `basename(test_dirname)`.
5-
macro(add_sycl_unittest test_dirname link_variant)
1+
# Internal function to create SYCL unit tests with code reuse
2+
# add_sycl_unittest_internal(test_dirname SHARED|OBJECT is_preview file1.cpp, file2.cpp ...)
3+
function(add_sycl_unittest_internal test_dirname link_variant is_preview)
64
# Enable exception handling for these unit tests
75
set(LLVM_REQUIRES_EH ON)
86
set(LLVM_REQUIRES_RTTI ON)
97

108
get_target_property(SYCL_BINARY_DIR sycl-toolchain BINARY_DIR)
119

1210
string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type_lower)
11+
12+
# Select which sycl libraries and object to link based
13+
# on whether this is a preview build.
1314
if (MSVC AND build_type_lower MATCHES "debug")
14-
set(sycl_obj_target "sycld_object")
15-
set(sycl_so_target "sycld")
15+
if (${is_preview})
16+
set(sycl_obj_target "sycl-previewd_object")
17+
set(sycl_so_target "sycl-previewd")
18+
else()
19+
set(sycl_obj_target "sycld_object")
20+
set(sycl_so_target "sycld")
21+
endif()
1622
else()
17-
set(sycl_obj_target "sycl_object")
18-
set(sycl_so_target "sycl")
23+
if (${is_preview})
24+
set(sycl_obj_target "sycl-preview_object")
25+
set(sycl_so_target "sycl-preview")
26+
else()
27+
set(sycl_obj_target "sycl_object")
28+
set(sycl_so_target "sycl")
29+
endif()
30+
endif()
31+
32+
# This is done to ensure that preview tests are kept in a separate
33+
# directory, so that they do not interfere with the non-preview tests.
34+
# Chaning CMAKE_CURRENT_BINARY_DIR should not affect this variable in its
35+
# parent scope.
36+
if (${is_preview})
37+
set(CMAKE_CURRENT_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/Preview")
1938
endif()
2039

2140
if ("${link_variant}" MATCHES "SHARED")
@@ -39,6 +58,13 @@ macro(add_sycl_unittest test_dirname link_variant)
3958
)
4059
endif()
4160

61+
# Add preview-specific compile definition
62+
if (${is_preview})
63+
target_compile_definitions(${test_dirname}
64+
PRIVATE __INTEL_PREVIEW_BREAKING_CHANGES)
65+
set(sycl_cache_suffix "_preview")
66+
endif()
67+
4268
if (SYCL_ENABLE_XPTI_TRACING)
4369
target_compile_definitions(${test_dirname}
4470
PRIVATE XPTI_ENABLE_INSTRUMENTATION XPTI_STATIC_LIBRARY)
@@ -53,9 +79,10 @@ macro(add_sycl_unittest test_dirname link_variant)
5379
LLVM_PROFILE_FILE="${SYCL_COVERAGE_PATH}/${test_dirname}.profraw"
5480
SYCL_CONFIG_FILE_NAME=null.cfg
5581
SYCL_DEVICELIB_NO_FALLBACK=1
56-
SYCL_CACHE_DIR="${CMAKE_BINARY_DIR}/sycl_cache"
82+
SYCL_CACHE_DIR="${CMAKE_BINARY_DIR}/sycl_cache${sycl_cache_suffix}"
5783
"PATH=${CMAKE_BINARY_DIR}/bin;$ENV{PATH}"
5884
${CMAKE_CURRENT_BINARY_DIR}/${test_dirname}
85+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
5986
DEPENDS
6087
${test_dirname}
6188
)
@@ -65,9 +92,10 @@ macro(add_sycl_unittest test_dirname link_variant)
6592
LLVM_PROFILE_FILE="${SYCL_COVERAGE_PATH}/${test_dirname}.profraw"
6693
SYCL_CONFIG_FILE_NAME=null.cfg
6794
SYCL_DEVICELIB_NO_FALLBACK=1
68-
SYCL_CACHE_DIR="${CMAKE_BINARY_DIR}/sycl_cache"
95+
SYCL_CACHE_DIR="${CMAKE_BINARY_DIR}/sycl_cache${sycl_cache_suffix}"
6996
"LD_LIBRARY_PATH=${SYCL_BINARY_DIR}/unittests/lib:${CMAKE_BINARY_DIR}/lib:$ENV{LD_LIBRARY_PATH}"
7097
${CMAKE_CURRENT_BINARY_DIR}/${test_dirname}
98+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
7199
DEPENDS
72100
${test_dirname}
73101
)
@@ -79,6 +107,7 @@ macro(add_sycl_unittest test_dirname link_variant)
79107
# Windows doesn't support LD_LIBRARY_PATH, so instead we copy the mock OpenCL binary next to the test and ensure
80108
# that the test itself links to OpenCL (rather than through ur_adapter_opencl.dll)
81109
set(mock_ocl ${CMAKE_CURRENT_BINARY_DIR}/OpenCL.dll)
110+
82111
add_custom_command(TARGET ${test_dirname} POST_BUILD
83112
COMMAND ${CMAKE_COMMAND} -E copy $<TARGET_FILE:mockOpenCL> ${mock_ocl}
84113
DEPENDS mockOpenCL
@@ -122,4 +151,14 @@ macro(add_sycl_unittest test_dirname link_variant)
122151
endif()
123152

124153
target_compile_definitions(${test_dirname} PRIVATE SYCL_DISABLE_FSYCL_SYCLHPP_WARNING)
154+
endfunction()
155+
156+
# add_sycl_unittest(test_name_prefix SHARED|OBJECT file1.cpp, file2.cpp ...)
157+
#
158+
# Will compile the list of files together to create two builds, with and without
159+
# the SYCL preview features enabled.
160+
# Produces two binaries, named `basename(test_name_prefix_non_preview)` and `basename(test_name_prefix_preview)`
161+
macro(add_sycl_unittest test_name_prefix link_variant)
162+
add_sycl_unittest_internal(${test_name_prefix}_non_preview ${link_variant} FALSE ${ARGN})
163+
add_sycl_unittest_internal(${test_name_prefix}_preview ${link_variant} TRUE ${ARGN})
125164
endmacro()

sycl/unittests/Extensions/LaunchQueries.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ auto getKernel(const sycl::queue &Q) {
6161
return KernelBundle.get_kernel(KernelID);
6262
}
6363

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

150154
TEST(LaunchQueries, GetMaxSubGroupSize3DSuccess) {
151155
sycl::unittest::UrMock<> Mock;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_sycl_unittest(CompressionTests OBJECT
22
CompressionTests.cpp
33
)
4-
target_compile_definitions(CompressionTests PRIVATE SYCL_RT_ZSTD_AVAILABLE)
4+
target_compile_definitions(CompressionTests_non_preview PRIVATE SYCL_RT_ZSTD_AVAILABLE)
5+
target_compile_definitions(CompressionTests_preview PRIVATE SYCL_RT_ZSTD_AVAILABLE)

sycl/unittests/event/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
add_sycl_unittest(EventTests OBJECT
22
EventDestruction.cpp
3-
)
3+
)

sycl/unittests/kernel-and-program/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ add_sycl_unittest(KernelAndProgramTests OBJECT
99
OutOfResources.cpp
1010
InMemCacheEviction.cpp
1111
)
12-
target_compile_definitions(KernelAndProgramTests PRIVATE -D__SYCL_INTERNAL_API)
12+
target_compile_definitions(KernelAndProgramTests_non_preview PRIVATE -D__SYCL_INTERNAL_API)
13+
target_compile_definitions(KernelAndProgramTests_preview PRIVATE -D__SYCL_INTERNAL_API)

sycl/unittests/misc/OsUtils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ bool isSameDir(const char* LHS, const char* RHS) {
5454
class OsUtilsTest : public ::testing::Test {
5555
};
5656

57+
// This test fails with preview breaking changes enabled.
58+
// Failure tracker: https://github.com/intel/llvm/issues/19626
59+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
5760
TEST_F(OsUtilsTest, getCurrentDSODir) {
5861
std::string DSODir = sycl::detail::OSUtil::getCurrentDSODir();
5962
ASSERT_TRUE(isSameDir(DSODir.c_str(), SYCL_LIB_DIR)) <<
6063
"expected: " << SYCL_LIB_DIR << ", got: " << DSODir;
6164
}
65+
#endif

sycl/unittests/pipes/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@ add_sycl_unittest(PipeTests OBJECT
44
host_pipe_registration.cpp
55
)
66

7-
add_dependencies(PipeTests sycl)
8-
target_include_directories(PipeTests PRIVATE SYSTEM ${sycl_inc_dir})
7+
add_dependencies(PipeTests_non_preview sycl)
8+
target_include_directories(PipeTests_non_preview PRIVATE SYSTEM ${sycl_inc_dir})
9+
add_dependencies(PipeTests_preview sycl)
10+
target_include_directories(PipeTests_preview PRIVATE SYSTEM ${sycl_inc_dir})

sycl/unittests/program_manager/arg_mask/EliminatedArgMask.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ class MockHandler : public sycl::handler {
136136
using sycl::handler::impl;
137137

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

141142
std::unique_ptr<sycl::detail::CG> finalize() {
142143
auto CGH = static_cast<sycl::handler *>(this);

sycl/unittests/scheduler/InOrderQueueSyncCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class LimitedHandler {
4444

4545
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
4646
virtual sycl::detail::EventImplPtr finalize() {
47-
return std::make_shared<detail::event_impl>();
47+
return detail::event_impl::create_default_event();
4848
}
4949
#else
5050
virtual event finalize() {

sycl/unittests/scheduler/SchedulerTestUtils.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@ sycl::detail::Requirement getMockRequirement(const MemObjT &MemObj) {
221221
class MockHandler : public sycl::handler {
222222
public:
223223
MockHandler(sycl::detail::queue_impl &Queue, bool CallerNeedsEvent)
224-
: sycl::handler(Queue.shared_from_this(), CallerNeedsEvent) {}
224+
: sycl::handler(std::make_unique<sycl::detail::handler_impl>(
225+
Queue, nullptr, CallerNeedsEvent)) {}
225226
// Methods
226227
using sycl::handler::addReduction;
227228
using sycl::handler::getType;

0 commit comments

Comments
 (0)