From 169712d8a86659f6722aa8c4c32f3af14f281f2c Mon Sep 17 00:00:00 2001 From: Andrei Elovikov Date: Mon, 8 Jul 2024 15:28:17 -0700 Subject: [PATCH] [SYCL] Avoid referencing deprecated `sycl::runtime_error` in tests --- sycl/test-e2e/Config/device_selector.cpp | 2 +- sycl/test-e2e/FilterSelector/select.cpp | 9 ++++++--- .../test-e2e/HostInteropTask/interop-task.cpp | 16 +++++---------- .../OnlineCompiler/online_compiler_L0.cpp | 6 ++---- .../OnlineCompiler/online_compiler_OpenCL.cpp | 9 +++------ sycl/unittests/Extensions/DefaultContext.cpp | 4 ++-- sycl/unittests/SYCL2020/KernelID.cpp | 7 ++++--- sycl/unittests/allowlist/ParseAllowList.cpp | 20 +++++++++---------- .../arg_mask/EliminatedArgMask.cpp | 4 ++-- .../scheduler/SchedulerTestUtils.hpp | 8 ++++---- .../scheduler/StreamInitDependencyOnHost.cpp | 4 ++-- 11 files changed, 41 insertions(+), 48 deletions(-) diff --git a/sycl/test-e2e/Config/device_selector.cpp b/sycl/test-e2e/Config/device_selector.cpp index 6ae5213b5810f..ac46777fd493d 100644 --- a/sycl/test-e2e/Config/device_selector.cpp +++ b/sycl/test-e2e/Config/device_selector.cpp @@ -20,7 +20,7 @@ int main() { RejectEverything Selector; try { sycl::device Device(Selector); - } catch (sycl::runtime_error &E) { + } catch (sycl::exception &) { return 0; } std::cerr << "Error. A device is found." << std::endl; diff --git a/sycl/test-e2e/FilterSelector/select.cpp b/sycl/test-e2e/FilterSelector/select.cpp index 3717d08249a99..106b587afc000 100644 --- a/sycl/test-e2e/FilterSelector/select.cpp +++ b/sycl/test-e2e/FilterSelector/select.cpp @@ -104,7 +104,8 @@ int main() { try { // pick something crazy device d9(filter_selector("gpu:999")); - } catch (const sycl::runtime_error &e) { + } catch (const sycl::exception &e) { + assert(e.code() == sycl::errc::runtime); const char *ErrorMesg = "Could not find a device that matches the specified filter(s)!"; assert(std::string{e.what()}.find(ErrorMesg) == 0 && @@ -114,7 +115,8 @@ int main() { try { // pick something crazy device d10(filter_selector("bob:gpu")); - } catch (const sycl::runtime_error &e) { + } catch (const sycl::exception &e) { + assert(e.code() == sycl::errc::runtime); const char *ErrorMesg = "Invalid filter string!"; assert(std::string{e.what()}.find(ErrorMesg) == 0 && "filter_selector(\"bob:gpu\") unexpectedly selected a device"); @@ -123,7 +125,8 @@ int main() { try { // pick something crazy device d11(filter_selector("opencl:bob")); - } catch (const sycl::runtime_error &e) { + } catch (const sycl::exception &e) { + assert(e.code() == sycl::errc::runtime); const char *ErrorMesg = "Invalid filter string!"; assert(std::string{e.what()}.find(ErrorMesg) == 0 && "filter_selector(\"opencl:bob\") unexpectedly selected a device"); diff --git a/sycl/test-e2e/HostInteropTask/interop-task.cpp b/sycl/test-e2e/HostInteropTask/interop-task.cpp index 6047a74ec90e9..aa6606c1cc2f8 100644 --- a/sycl/test-e2e/HostInteropTask/interop-task.cpp +++ b/sycl/test-e2e/HostInteropTask/interop-task.cpp @@ -46,18 +46,13 @@ void copy(buffer &Src, buffer &Dst, queue &Q) { int RC = clEnqueueCopyBuffer(NativeQ, SrcMem[0], DstMem[0], 0, 0, sizeof(DataT) * SrcA.get_count(), 0, nullptr, &Event); - if (RC != CL_SUCCESS) - throw runtime_error("Can't enqueue buffer copy", RC); + assert(RC == CL_SUCCESS); RC = clWaitForEvents(1, &Event); + assert(RC == CL_SUCCESS); - if (RC != CL_SUCCESS) - throw runtime_error("Can't wait for event on buffer copy", RC); - - if (Q.get_backend() != IH.get_backend()) - throw runtime_error( - "interop_handle::get_backend() returned a wrong value", - CL_INVALID_VALUE); + assert(Q.get_backend() == IH.get_backend() && + "interop_handle::get_backend() returned a wrong value"); }; CGH.host_task(Func); }); @@ -172,8 +167,7 @@ void test3(queue &Q) { std::vector Ev = get_native(Event); int RC = clWaitForEvents(1, Ev.data()); - if (RC != CL_SUCCESS) - throw runtime_error("Can't wait for events", RC); + assert(RC == CL_SUCCESS); }; CGH.host_task(Func); }); diff --git a/sycl/test-e2e/OnlineCompiler/online_compiler_L0.cpp b/sycl/test-e2e/OnlineCompiler/online_compiler_L0.cpp index ad2fe4ce2371a..58fe10e30ea69 100644 --- a/sycl/test-e2e/OnlineCompiler/online_compiler_L0.cpp +++ b/sycl/test-e2e/OnlineCompiler/online_compiler_L0.cpp @@ -41,16 +41,14 @@ sycl::kernel getSYCLKernelWithIL(sycl::queue &Queue, ze_module_handle_t ZeModule; ze_result_t ZeResult = zeModuleCreate(ZeContext, ZeDevice, &ZeModuleDesc, &ZeModule, &ZeBuildLog); - if (ZeResult != ZE_RESULT_SUCCESS) - throw sycl::runtime_error(); + assert(ZeResult == ZE_RESULT_SUCCESS); ze_kernel_handle_t ZeKernel = nullptr; ze_kernel_desc_t ZeKernelDesc{ZE_STRUCTURE_TYPE_KERNEL_DESC, nullptr, 0, "my_kernel"}; ZeResult = zeKernelCreate(ZeModule, &ZeKernelDesc, &ZeKernel); - if (ZeResult != ZE_RESULT_SUCCESS) - throw sycl::runtime_error(); + assert(ZeResult == ZE_RESULT_SUCCESS); sycl::kernel_bundle SyclKB = sycl::make_kernel_bundle( diff --git a/sycl/test-e2e/OnlineCompiler/online_compiler_OpenCL.cpp b/sycl/test-e2e/OnlineCompiler/online_compiler_OpenCL.cpp index a083302a0f6a2..57cd957d3a1df 100644 --- a/sycl/test-e2e/OnlineCompiler/online_compiler_OpenCL.cpp +++ b/sycl/test-e2e/OnlineCompiler/online_compiler_OpenCL.cpp @@ -26,16 +26,13 @@ sycl::kernel getSYCLKernelWithIL(sycl::queue &Queue, cl_program ClProgram = clCreateProgramWithIL(sycl::get_native(Context), IL.data(), IL.size(), &Err); - if (Err != CL_SUCCESS) - throw sycl::runtime_error("clCreateProgramWithIL() failed", Err); + assert(Err == CL_SUCCESS); Err = clBuildProgram(ClProgram, 0, nullptr, nullptr, nullptr, nullptr); - if (Err != CL_SUCCESS) - throw sycl::runtime_error("clBuildProgram() failed", Err); + assert(Err == CL_SUCCESS); cl_kernel ClKernel = clCreateKernel(ClProgram, "my_kernel", &Err); - if (Err != CL_SUCCESS) - throw sycl::runtime_error("clCreateKernel() failed", Err); + assert(Err == CL_SUCCESS); return sycl::make_kernel(ClKernel, Context); } diff --git a/sycl/unittests/Extensions/DefaultContext.cpp b/sycl/unittests/Extensions/DefaultContext.cpp index a2d4e08ab68e6..945cd627e711b 100644 --- a/sycl/unittests/Extensions/DefaultContext.cpp +++ b/sycl/unittests/Extensions/DefaultContext.cpp @@ -44,12 +44,12 @@ void test_default_context_disabled() { bool catchException = false; try { (void)Plt.ext_oneapi_get_default_context(); - } catch (const std::runtime_error &) { + } catch (const std::exception &) { catchException = true; } ASSERT_TRUE(catchException) - << "ext_oneapi_get_default_context did not throw and exception"; + << "ext_oneapi_get_default_context did not throw an exception"; } TEST(DefaultContextTest, DefaultContextTest) { diff --git a/sycl/unittests/SYCL2020/KernelID.cpp b/sycl/unittests/SYCL2020/KernelID.cpp index 0f27e4eaed63e..1791205234c28 100644 --- a/sycl/unittests/SYCL2020/KernelID.cpp +++ b/sycl/unittests/SYCL2020/KernelID.cpp @@ -258,12 +258,13 @@ TEST(KernelID, GetKernelIDInvalidKernelName) { try { sycl::get_kernel_id(); - throw std::logic_error("sycl::runtime_error didn't throw"); - } catch (sycl::runtime_error const &e) { + FAIL() << "Expected an exception"; + } catch (sycl::exception const &e) { + EXPECT_TRUE(e.code() == sycl::errc::runtime); EXPECT_EQ(std::string("No kernel found with the specified name -46 " "(PI_ERROR_INVALID_KERNEL_NAME)"), e.what()); } catch (...) { - FAIL() << "Expected sycl::runtime_error"; + FAIL() << "Expected sycl::exception"; } } diff --git a/sycl/unittests/allowlist/ParseAllowList.cpp b/sycl/unittests/allowlist/ParseAllowList.cpp index f38dbe4495b81..144ab1a546c0e 100644 --- a/sycl/unittests/allowlist/ParseAllowList.cpp +++ b/sycl/unittests/allowlist/ParseAllowList.cpp @@ -47,7 +47,7 @@ TEST(ParseAllowListTests, CheckUnsupportedKeyNameIsHandledInSingleDeviceDesc) { try { sycl::detail::AllowListParsedT ActualValue = sycl::detail::parseAllowList( "BackendName:level_zero,SomeUnsupportedKey:gpu"); - throw std::logic_error("sycl::runtime_error didn't throw"); + FAIL() << "Expected an exception"; } catch (sycl::exception const &e) { EXPECT_EQ( std::string("Unrecognized key in SYCL_DEVICE_ALLOWLIST. For " @@ -66,7 +66,7 @@ TEST( try { sycl::detail::AllowListParsedT ActualValue = sycl::detail::parseAllowList( "DriverVersion:{{value}}|SomeUnsupportedKey:gpu"); - throw std::logic_error("sycl::runtime_error didn't throw"); + FAIL() << "Expected an exception"; } catch (sycl::exception const &e) { EXPECT_EQ( std::string("Unrecognized key in SYCL_DEVICE_ALLOWLIST. For " @@ -85,7 +85,7 @@ TEST( try { sycl::detail::AllowListParsedT ActualValue = sycl::detail::parseAllowList( "BackendName:level_zero|SomeUnsupportedKey:gpu"); - throw std::logic_error("sycl::runtime_error didn't throw"); + FAIL() << "Expected an exception"; } catch (sycl::exception const &e) { EXPECT_EQ( std::string("Unrecognized key in SYCL_DEVICE_ALLOWLIST. For " @@ -103,7 +103,7 @@ TEST(ParseAllowListTests, try { sycl::detail::AllowListParsedT ActualValue = sycl::detail::parseAllowList( "DriverVersion:{{value1}}|SomeUnsupportedKey:{{value2}}"); - throw std::logic_error("sycl::runtime_error didn't throw"); + FAIL() << "Expected an exception"; } catch (sycl::exception const &e) { EXPECT_EQ( std::string("Unrecognized key in SYCL_DEVICE_ALLOWLIST. For " @@ -131,7 +131,7 @@ TEST(ParseAllowListTests, CheckMissingOpenDoubleCurlyBracesAreHandled) { try { sycl::detail::AllowListParsedT ActualValue = sycl::detail::parseAllowList( "DeviceName:regex1}},DriverVersion:{{regex1|regex2}}"); - throw std::logic_error("sycl::exception didn't throw"); + FAIL() << "Expected an exception"; } catch (sycl::exception const &e) { EXPECT_EQ(std::string("Key DeviceName of SYCL_DEVICE_ALLOWLIST " "should have value which starts with {{ -30 " @@ -146,7 +146,7 @@ TEST(ParseAllowListTests, CheckMissingClosedDoubleCurlyBracesAreHandled) { try { sycl::detail::AllowListParsedT ActualValue = sycl::detail::parseAllowList( "DeviceName:{{regex1}},DriverVersion:{{regex1|regex2"); - throw std::logic_error("sycl::runtime_error didn't throw"); + FAIL() << "Expected an exception"; } catch (sycl::exception const &e) { EXPECT_EQ(std::string("Key DriverVersion of SYCL_DEVICE_ALLOWLIST " "should have value which ends with }} -30 " @@ -195,7 +195,7 @@ TEST(ParseAllowListTests, CheckIncorrectBackendNameValueIsHandled) { try { sycl::detail::AllowListParsedT ActualValue = sycl::detail::parseAllowList("BackendName:blablabla"); - throw std::logic_error("sycl::runtime_error didn't throw"); + FAIL() << "Expected an exception"; } catch (sycl::exception const &e) { EXPECT_EQ( std::string("Value blablabla for key BackendName is not valid in " @@ -212,7 +212,7 @@ TEST(ParseAllowListTests, CheckIncorrectDeviceTypeValueIsHandled) { try { sycl::detail::AllowListParsedT ActualValue = sycl::detail::parseAllowList("DeviceType:blablabla"); - throw std::logic_error("sycl::runtime_error didn't throw"); + FAIL() << "Expected an exception"; } catch (sycl::exception const &e) { EXPECT_EQ( std::string("Value blablabla for key DeviceType is not valid in " @@ -229,7 +229,7 @@ TEST(ParseAllowListTests, CheckIncorrectDeviceVendorIdValueIsHandled) { try { sycl::detail::AllowListParsedT ActualValue = sycl::detail::parseAllowList("DeviceVendorId:blablabla"); - throw std::logic_error("sycl::runtime_error didn't throw"); + FAIL() << "Expected an exception"; } catch (sycl::exception const &e) { EXPECT_EQ( std::string("Value blablabla for key DeviceVendorId is not valid in " @@ -261,7 +261,7 @@ TEST(ParseAllowListTests, CheckExceptionIsThrownForValueWOColonDelim) { try { sycl::detail::AllowListParsedT ActualValue = sycl::detail::parseAllowList("SomeValueWOColonDelimiter"); - throw std::logic_error("sycl::runtime_error didn't throw"); + FAIL() << "Expected an exception"; } catch (sycl::exception const &e) { EXPECT_EQ( std::string("SYCL_DEVICE_ALLOWLIST has incorrect format. For " diff --git a/sycl/unittests/program_manager/arg_mask/EliminatedArgMask.cpp b/sycl/unittests/program_manager/arg_mask/EliminatedArgMask.cpp index 27708bb2efba5..c2d53e3d8e6dd 100644 --- a/sycl/unittests/program_manager/arg_mask/EliminatedArgMask.cpp +++ b/sycl/unittests/program_manager/arg_mask/EliminatedArgMask.cpp @@ -129,8 +129,8 @@ class MockHandler : public sycl::handler { break; } default: - throw sycl::runtime_error("Unhandled type of command group", - PI_ERROR_INVALID_OPERATION); + throw sycl::exception(sycl::make_error_code(sycl::errc::runtime), + "Unhandled type of command group"); } return CommandGroup; diff --git a/sycl/unittests/scheduler/SchedulerTestUtils.hpp b/sycl/unittests/scheduler/SchedulerTestUtils.hpp index ab20050f250a6..b98aff0e040d0 100644 --- a/sycl/unittests/scheduler/SchedulerTestUtils.hpp +++ b/sycl/unittests/scheduler/SchedulerTestUtils.hpp @@ -283,8 +283,8 @@ class MockHandler : public sycl::handler { } std::unique_ptr finalize() { - throw sycl::runtime_error("Unhandled type of command group", - PI_ERROR_INVALID_OPERATION); + throw sycl::exception(sycl::make_error_code(sycl::errc::runtime), + "Unhandled type of command group"); return nullptr; } @@ -318,8 +318,8 @@ class MockHandlerCustomFinalize : public MockHandler { break; } default: - throw sycl::runtime_error("Unhandled type of command group", - PI_ERROR_INVALID_OPERATION); + throw sycl::exception(sycl::make_error_code(sycl::errc::runtime), + "Unhandled type of command group"); } return CommandGroup; diff --git a/sycl/unittests/scheduler/StreamInitDependencyOnHost.cpp b/sycl/unittests/scheduler/StreamInitDependencyOnHost.cpp index 29b54fc31dad2..c8aac819e1c32 100644 --- a/sycl/unittests/scheduler/StreamInitDependencyOnHost.cpp +++ b/sycl/unittests/scheduler/StreamInitDependencyOnHost.cpp @@ -41,8 +41,8 @@ class MockHandlerStreamInit : public MockHandler { break; } default: - throw sycl::runtime_error("Unhandled type of command group", - PI_ERROR_INVALID_OPERATION); + throw sycl::exception(sycl::make_error_code(sycl::errc::runtime), + "Unhandled type of command group"); } return CommandGroup;