Skip to content

Commit e891924

Browse files
[SYCL] Avoid referencing deprecated sycl::runtime_error in tests (intel#14489)
1 parent a14c091 commit e891924

File tree

11 files changed

+41
-48
lines changed

11 files changed

+41
-48
lines changed

sycl/test-e2e/Config/device_selector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int main() {
2020
RejectEverything Selector;
2121
try {
2222
sycl::device Device(Selector);
23-
} catch (sycl::runtime_error &E) {
23+
} catch (sycl::exception &) {
2424
return 0;
2525
}
2626
std::cerr << "Error. A device is found." << std::endl;

sycl/test-e2e/FilterSelector/select.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ int main() {
104104
try {
105105
// pick something crazy
106106
device d9(filter_selector("gpu:999"));
107-
} catch (const sycl::runtime_error &e) {
107+
} catch (const sycl::exception &e) {
108+
assert(e.code() == sycl::errc::runtime);
108109
const char *ErrorMesg =
109110
"Could not find a device that matches the specified filter(s)!";
110111
assert(std::string{e.what()}.find(ErrorMesg) == 0 &&
@@ -114,7 +115,8 @@ int main() {
114115
try {
115116
// pick something crazy
116117
device d10(filter_selector("bob:gpu"));
117-
} catch (const sycl::runtime_error &e) {
118+
} catch (const sycl::exception &e) {
119+
assert(e.code() == sycl::errc::runtime);
118120
const char *ErrorMesg = "Invalid filter string!";
119121
assert(std::string{e.what()}.find(ErrorMesg) == 0 &&
120122
"filter_selector(\"bob:gpu\") unexpectedly selected a device");
@@ -123,7 +125,8 @@ int main() {
123125
try {
124126
// pick something crazy
125127
device d11(filter_selector("opencl:bob"));
126-
} catch (const sycl::runtime_error &e) {
128+
} catch (const sycl::exception &e) {
129+
assert(e.code() == sycl::errc::runtime);
127130
const char *ErrorMesg = "Invalid filter string!";
128131
assert(std::string{e.what()}.find(ErrorMesg) == 0 &&
129132
"filter_selector(\"opencl:bob\") unexpectedly selected a device");

sycl/test-e2e/HostInteropTask/interop-task.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,13 @@ void copy(buffer<DataT, 1> &Src, buffer<DataT, 1> &Dst, queue &Q) {
4646
int RC = clEnqueueCopyBuffer(NativeQ, SrcMem[0], DstMem[0], 0, 0,
4747
sizeof(DataT) * SrcA.get_count(), 0, nullptr,
4848
&Event);
49-
if (RC != CL_SUCCESS)
50-
throw runtime_error("Can't enqueue buffer copy", RC);
49+
assert(RC == CL_SUCCESS);
5150

5251
RC = clWaitForEvents(1, &Event);
52+
assert(RC == CL_SUCCESS);
5353

54-
if (RC != CL_SUCCESS)
55-
throw runtime_error("Can't wait for event on buffer copy", RC);
56-
57-
if (Q.get_backend() != IH.get_backend())
58-
throw runtime_error(
59-
"interop_handle::get_backend() returned a wrong value",
60-
CL_INVALID_VALUE);
54+
assert(Q.get_backend() == IH.get_backend() &&
55+
"interop_handle::get_backend() returned a wrong value");
6156
};
6257
CGH.host_task(Func);
6358
});
@@ -172,8 +167,7 @@ void test3(queue &Q) {
172167
std::vector<cl_event> Ev = get_native<backend::opencl>(Event);
173168

174169
int RC = clWaitForEvents(1, Ev.data());
175-
if (RC != CL_SUCCESS)
176-
throw runtime_error("Can't wait for events", RC);
170+
assert(RC == CL_SUCCESS);
177171
};
178172
CGH.host_task(Func);
179173
});

sycl/test-e2e/OnlineCompiler/online_compiler_L0.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,14 @@ sycl::kernel getSYCLKernelWithIL(sycl::queue &Queue,
4141
ze_module_handle_t ZeModule;
4242
ze_result_t ZeResult = zeModuleCreate(ZeContext, ZeDevice, &ZeModuleDesc,
4343
&ZeModule, &ZeBuildLog);
44-
if (ZeResult != ZE_RESULT_SUCCESS)
45-
throw sycl::runtime_error();
44+
assert(ZeResult == ZE_RESULT_SUCCESS);
4645

4746
ze_kernel_handle_t ZeKernel = nullptr;
4847

4948
ze_kernel_desc_t ZeKernelDesc{ZE_STRUCTURE_TYPE_KERNEL_DESC, nullptr, 0,
5049
"my_kernel"};
5150
ZeResult = zeKernelCreate(ZeModule, &ZeKernelDesc, &ZeKernel);
52-
if (ZeResult != ZE_RESULT_SUCCESS)
53-
throw sycl::runtime_error();
51+
assert(ZeResult == ZE_RESULT_SUCCESS);
5452
sycl::kernel_bundle<sycl::bundle_state::executable> SyclKB =
5553
sycl::make_kernel_bundle<sycl::backend::ext_oneapi_level_zero,
5654
sycl::bundle_state::executable>(

sycl/test-e2e/OnlineCompiler/online_compiler_OpenCL.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,13 @@ sycl::kernel getSYCLKernelWithIL(sycl::queue &Queue,
2626
cl_program ClProgram =
2727
clCreateProgramWithIL(sycl::get_native<sycl::backend::opencl>(Context),
2828
IL.data(), IL.size(), &Err);
29-
if (Err != CL_SUCCESS)
30-
throw sycl::runtime_error("clCreateProgramWithIL() failed", Err);
29+
assert(Err == CL_SUCCESS);
3130

3231
Err = clBuildProgram(ClProgram, 0, nullptr, nullptr, nullptr, nullptr);
33-
if (Err != CL_SUCCESS)
34-
throw sycl::runtime_error("clBuildProgram() failed", Err);
32+
assert(Err == CL_SUCCESS);
3533

3634
cl_kernel ClKernel = clCreateKernel(ClProgram, "my_kernel", &Err);
37-
if (Err != CL_SUCCESS)
38-
throw sycl::runtime_error("clCreateKernel() failed", Err);
35+
assert(Err == CL_SUCCESS);
3936

4037
return sycl::make_kernel<sycl::backend::opencl>(ClKernel, Context);
4138
}

sycl/unittests/Extensions/DefaultContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ void test_default_context_disabled() {
4444
bool catchException = false;
4545
try {
4646
(void)Plt.ext_oneapi_get_default_context();
47-
} catch (const std::runtime_error &) {
47+
} catch (const std::exception &) {
4848
catchException = true;
4949
}
5050

5151
ASSERT_TRUE(catchException)
52-
<< "ext_oneapi_get_default_context did not throw and exception";
52+
<< "ext_oneapi_get_default_context did not throw an exception";
5353
}
5454

5555
TEST(DefaultContextTest, DefaultContextTest) {

sycl/unittests/SYCL2020/KernelID.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,13 @@ TEST(KernelID, GetKernelIDInvalidKernelName) {
258258

259259
try {
260260
sycl::get_kernel_id<class NotAKernel>();
261-
throw std::logic_error("sycl::runtime_error didn't throw");
262-
} catch (sycl::runtime_error const &e) {
261+
FAIL() << "Expected an exception";
262+
} catch (sycl::exception const &e) {
263+
EXPECT_TRUE(e.code() == sycl::errc::runtime);
263264
EXPECT_EQ(std::string("No kernel found with the specified name -46 "
264265
"(PI_ERROR_INVALID_KERNEL_NAME)"),
265266
e.what());
266267
} catch (...) {
267-
FAIL() << "Expected sycl::runtime_error";
268+
FAIL() << "Expected sycl::exception";
268269
}
269270
}

sycl/unittests/allowlist/ParseAllowList.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ TEST(ParseAllowListTests, CheckUnsupportedKeyNameIsHandledInSingleDeviceDesc) {
4747
try {
4848
sycl::detail::AllowListParsedT ActualValue = sycl::detail::parseAllowList(
4949
"BackendName:level_zero,SomeUnsupportedKey:gpu");
50-
throw std::logic_error("sycl::runtime_error didn't throw");
50+
FAIL() << "Expected an exception";
5151
} catch (sycl::exception const &e) {
5252
EXPECT_EQ(
5353
std::string("Unrecognized key in SYCL_DEVICE_ALLOWLIST. For "
@@ -66,7 +66,7 @@ TEST(
6666
try {
6767
sycl::detail::AllowListParsedT ActualValue = sycl::detail::parseAllowList(
6868
"DriverVersion:{{value}}|SomeUnsupportedKey:gpu");
69-
throw std::logic_error("sycl::runtime_error didn't throw");
69+
FAIL() << "Expected an exception";
7070
} catch (sycl::exception const &e) {
7171
EXPECT_EQ(
7272
std::string("Unrecognized key in SYCL_DEVICE_ALLOWLIST. For "
@@ -85,7 +85,7 @@ TEST(
8585
try {
8686
sycl::detail::AllowListParsedT ActualValue = sycl::detail::parseAllowList(
8787
"BackendName:level_zero|SomeUnsupportedKey:gpu");
88-
throw std::logic_error("sycl::runtime_error didn't throw");
88+
FAIL() << "Expected an exception";
8989
} catch (sycl::exception const &e) {
9090
EXPECT_EQ(
9191
std::string("Unrecognized key in SYCL_DEVICE_ALLOWLIST. For "
@@ -103,7 +103,7 @@ TEST(ParseAllowListTests,
103103
try {
104104
sycl::detail::AllowListParsedT ActualValue = sycl::detail::parseAllowList(
105105
"DriverVersion:{{value1}}|SomeUnsupportedKey:{{value2}}");
106-
throw std::logic_error("sycl::runtime_error didn't throw");
106+
FAIL() << "Expected an exception";
107107
} catch (sycl::exception const &e) {
108108
EXPECT_EQ(
109109
std::string("Unrecognized key in SYCL_DEVICE_ALLOWLIST. For "
@@ -131,7 +131,7 @@ TEST(ParseAllowListTests, CheckMissingOpenDoubleCurlyBracesAreHandled) {
131131
try {
132132
sycl::detail::AllowListParsedT ActualValue = sycl::detail::parseAllowList(
133133
"DeviceName:regex1}},DriverVersion:{{regex1|regex2}}");
134-
throw std::logic_error("sycl::exception didn't throw");
134+
FAIL() << "Expected an exception";
135135
} catch (sycl::exception const &e) {
136136
EXPECT_EQ(std::string("Key DeviceName of SYCL_DEVICE_ALLOWLIST "
137137
"should have value which starts with {{ -30 "
@@ -146,7 +146,7 @@ TEST(ParseAllowListTests, CheckMissingClosedDoubleCurlyBracesAreHandled) {
146146
try {
147147
sycl::detail::AllowListParsedT ActualValue = sycl::detail::parseAllowList(
148148
"DeviceName:{{regex1}},DriverVersion:{{regex1|regex2");
149-
throw std::logic_error("sycl::runtime_error didn't throw");
149+
FAIL() << "Expected an exception";
150150
} catch (sycl::exception const &e) {
151151
EXPECT_EQ(std::string("Key DriverVersion of SYCL_DEVICE_ALLOWLIST "
152152
"should have value which ends with }} -30 "
@@ -195,7 +195,7 @@ TEST(ParseAllowListTests, CheckIncorrectBackendNameValueIsHandled) {
195195
try {
196196
sycl::detail::AllowListParsedT ActualValue =
197197
sycl::detail::parseAllowList("BackendName:blablabla");
198-
throw std::logic_error("sycl::runtime_error didn't throw");
198+
FAIL() << "Expected an exception";
199199
} catch (sycl::exception const &e) {
200200
EXPECT_EQ(
201201
std::string("Value blablabla for key BackendName is not valid in "
@@ -212,7 +212,7 @@ TEST(ParseAllowListTests, CheckIncorrectDeviceTypeValueIsHandled) {
212212
try {
213213
sycl::detail::AllowListParsedT ActualValue =
214214
sycl::detail::parseAllowList("DeviceType:blablabla");
215-
throw std::logic_error("sycl::runtime_error didn't throw");
215+
FAIL() << "Expected an exception";
216216
} catch (sycl::exception const &e) {
217217
EXPECT_EQ(
218218
std::string("Value blablabla for key DeviceType is not valid in "
@@ -229,7 +229,7 @@ TEST(ParseAllowListTests, CheckIncorrectDeviceVendorIdValueIsHandled) {
229229
try {
230230
sycl::detail::AllowListParsedT ActualValue =
231231
sycl::detail::parseAllowList("DeviceVendorId:blablabla");
232-
throw std::logic_error("sycl::runtime_error didn't throw");
232+
FAIL() << "Expected an exception";
233233
} catch (sycl::exception const &e) {
234234
EXPECT_EQ(
235235
std::string("Value blablabla for key DeviceVendorId is not valid in "
@@ -261,7 +261,7 @@ TEST(ParseAllowListTests, CheckExceptionIsThrownForValueWOColonDelim) {
261261
try {
262262
sycl::detail::AllowListParsedT ActualValue =
263263
sycl::detail::parseAllowList("SomeValueWOColonDelimiter");
264-
throw std::logic_error("sycl::runtime_error didn't throw");
264+
FAIL() << "Expected an exception";
265265
} catch (sycl::exception const &e) {
266266
EXPECT_EQ(
267267
std::string("SYCL_DEVICE_ALLOWLIST has incorrect format. For "

sycl/unittests/program_manager/arg_mask/EliminatedArgMask.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ class MockHandler : public sycl::handler {
129129
break;
130130
}
131131
default:
132-
throw sycl::runtime_error("Unhandled type of command group",
133-
PI_ERROR_INVALID_OPERATION);
132+
throw sycl::exception(sycl::make_error_code(sycl::errc::runtime),
133+
"Unhandled type of command group");
134134
}
135135

136136
return CommandGroup;

sycl/unittests/scheduler/SchedulerTestUtils.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ class MockHandler : public sycl::handler {
283283
}
284284

285285
std::unique_ptr<sycl::detail::CG> finalize() {
286-
throw sycl::runtime_error("Unhandled type of command group",
287-
PI_ERROR_INVALID_OPERATION);
286+
throw sycl::exception(sycl::make_error_code(sycl::errc::runtime),
287+
"Unhandled type of command group");
288288

289289
return nullptr;
290290
}
@@ -318,8 +318,8 @@ class MockHandlerCustomFinalize : public MockHandler {
318318
break;
319319
}
320320
default:
321-
throw sycl::runtime_error("Unhandled type of command group",
322-
PI_ERROR_INVALID_OPERATION);
321+
throw sycl::exception(sycl::make_error_code(sycl::errc::runtime),
322+
"Unhandled type of command group");
323323
}
324324

325325
return CommandGroup;

sycl/unittests/scheduler/StreamInitDependencyOnHost.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ class MockHandlerStreamInit : public MockHandler {
4141
break;
4242
}
4343
default:
44-
throw sycl::runtime_error("Unhandled type of command group",
45-
PI_ERROR_INVALID_OPERATION);
44+
throw sycl::exception(sycl::make_error_code(sycl::errc::runtime),
45+
"Unhandled type of command group");
4646
}
4747

4848
return CommandGroup;

0 commit comments

Comments
 (0)