From d48e130a8c510f4b792ea8a62f2ba032a60fc828 Mon Sep 17 00:00:00 2001 From: "Larsen, Steffen" Date: Wed, 3 Dec 2025 03:56:43 -0800 Subject: [PATCH] [SYCL][E2E] Add negative testing for SYCLBIN linking This commit adds additional cases for exceptions in SYCLBIN linking. Signed-off-by: Larsen, Steffen --- sycl/test-e2e/SYCLBIN/Inputs/link.hpp | 59 +++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/sycl/test-e2e/SYCLBIN/Inputs/link.hpp b/sycl/test-e2e/SYCLBIN/Inputs/link.hpp index 729171b43df25..b356f6bbdbfdb 100644 --- a/sycl/test-e2e/SYCLBIN/Inputs/link.hpp +++ b/sycl/test-e2e/SYCLBIN/Inputs/link.hpp @@ -29,16 +29,75 @@ int main(int argc, char *argv[]) { // Compile the bundles. auto KBObj1 = sycl::compile(KBInput1); + auto KBObj1Extra = sycl::compile(KBInput1); auto KBObj2 = sycl::compile(KBInput2); + auto KBObj2Extra = sycl::compile(KBInput2); #elif defined(SYCLBIN_OBJECT_STATE) auto KBObj1 = syclex::get_kernel_bundle( Q.get_context(), {Q.get_device()}, std::string{argv[1]}); + auto KBObj1Extra = syclex::get_kernel_bundle( + Q.get_context(), {Q.get_device()}, std::string{argv[1]}); auto KBObj2 = syclex::get_kernel_bundle( Q.get_context(), {Q.get_device()}, std::string{argv[2]}); + auto KBObj2Extra = syclex::get_kernel_bundle( + Q.get_context(), {Q.get_device()}, std::string{argv[2]}); #else // defined(SYCLBIN_EXECUTABLE_STATE) #error "Test does not work with executable state." #endif + // Check that linking without all symbols resolved will result in an + // exception. + try { + auto KBExeFail = syclexp::link( + {KBObj2}, syclexp::properties{syclexp::fast_link{USE_FAST_LINK}}); + std::cout << "No exception thrown for only KBObj2" << std::endl; + ++Failed; + } catch (sycl::exception &E) { + if (E.code() != sycl::make_error_code(sycl::errc::invalid)) { + std::cout << "Unexpected exception code for only KBObj2" << std::endl; + ++Failed; + } + } catch (...) { + std::cout << "Caught unexpected exception for only KBObj2" << std::endl; + ++Failed; + } + + // Check that linking bundles with conflicting kernels will result in an + // exception. + try { + auto KBExeFail = + syclexp::link({KBObj1, KBObj1Extra, KBObj2}, + syclexp::properties{syclexp::fast_link{USE_FAST_LINK}}); + std::cout << "No exception thrown for double KBObj1" << std::endl; + ++Failed; + } catch (sycl::exception &E) { + if (E.code() != sycl::make_error_code(sycl::errc::invalid)) { + std::cout << "Unexpected exception code for double KBObj1" << std::endl; + ++Failed; + } + } catch (...) { + std::cout << "Caught unexpected exception for double KBObj1" << std::endl; + ++Failed; + } + + // Check that linking bundles with conflicting exported symbols will result in + // an exception. + try { + auto KBExeFail = + syclexp::link({KBObj1, KBObj2, KBObj2Extra}, + syclexp::properties{syclexp::fast_link{USE_FAST_LINK}}); + std::cout << "No exception thrown for double KBObj2" << std::endl; + ++Failed; + } catch (sycl::exception &E) { + if (E.code() != sycl::make_error_code(sycl::errc::invalid)) { + std::cout << "Unexpected exception code for double KBObj2" << std::endl; + ++Failed; + } + } catch (...) { + std::cout << "Caught unexpected exception for double KBObj2" << std::endl; + ++Failed; + } + // Link the bundles. auto KBExe = syclexp::link( {KBObj1, KBObj2}, syclexp::properties{syclexp::fast_link{USE_FAST_LINK}});