From 46cfb067f88cf1890f0dd67507998a8735c69b56 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 31 May 2024 16:36:38 -0400 Subject: [PATCH] [SYCL][E2E] Remove deprecated exception warnings in Basic e2e tests (#13940) --- sycl/test-e2e/Basic/context.cpp | 7 +- sycl/test-e2e/Basic/context_platforms.cpp | 7 +- .../diagnostics/non-uniform-wk-gp-test.cpp | 7 +- sycl/test-e2e/Basic/event_async_exception.cpp | 2 +- sycl/test-e2e/Basic/get_info_aspect.cpp | 3 +- sycl/test-e2e/Basic/gpu_max_wgs_error.cpp | 3 +- sycl/test-e2e/Basic/partition_supported.cpp | 4 +- sycl/test-e2e/Basic/property_list.cpp | 2 +- sycl/test-e2e/Basic/reqd_work_group_size.cpp | 4 +- .../test-e2e/Basic/use_pinned_host_memory.cpp | 7 +- sycl/test-e2e/Basic/work_group_size_prop.cpp | 97 +++---------------- 11 files changed, 43 insertions(+), 100 deletions(-) diff --git a/sycl/test-e2e/Basic/context.cpp b/sycl/test-e2e/Basic/context.cpp index 9bbd58e52e45..c933608caafe 100644 --- a/sycl/test-e2e/Basic/context.cpp +++ b/sycl/test-e2e/Basic/context.cpp @@ -12,8 +12,11 @@ using namespace sycl; int main() { try { context c; - } catch (device_error e) { - std::cout << "Failed to create device for context" << std::endl; + } catch (exception e) { + if (e.code() == errc::invalid) + std::cout << "Failed to create device for context" << std::endl; + else + std::cout << "Failed to create context" << std::endl; } auto devices = device::get_devices(); diff --git a/sycl/test-e2e/Basic/context_platforms.cpp b/sycl/test-e2e/Basic/context_platforms.cpp index 9e81b8480e7a..e8294003a986 100644 --- a/sycl/test-e2e/Basic/context_platforms.cpp +++ b/sycl/test-e2e/Basic/context_platforms.cpp @@ -23,10 +23,11 @@ int main(int argc, char const *argv[]) { context all_context = context(all_platforms_devices); std::cerr << "Test failed: exception wasn't thrown" << std::endl; return 1; - } catch (runtime_error &E) { - if (std::string(E.what()).find( + } catch (sycl::exception &E) { + if (E.code() != sycl::errc::kernel_argument || + std::string(E.what()).find( "Can't add devices across platforms to a single context.") == - std::string::npos) { + std::string::npos) { std::cerr << "Received error is incorrect" << std::endl; return 1; } diff --git a/sycl/test-e2e/Basic/diagnostics/non-uniform-wk-gp-test.cpp b/sycl/test-e2e/Basic/diagnostics/non-uniform-wk-gp-test.cpp index f9c04853962a..8b613b787885 100644 --- a/sycl/test-e2e/Basic/diagnostics/non-uniform-wk-gp-test.cpp +++ b/sycl/test-e2e/Basic/diagnostics/non-uniform-wk-gp-test.cpp @@ -34,10 +34,11 @@ int test() { }); }); std::cout << "Test failed: no exception thrown." << std::endl; - } catch (sycl::runtime_error &E) { - if (std::string(E.what()).find( + } catch (exception &E) { + if (E.code() == errc::nd_range && + std::string(E.what()).find( "Non-uniform work-groups are not supported by the target device") != - std::string::npos) { + std::string::npos) { std::cout << E.what() << std::endl; std::cout << "Test passed: caught the expected error." << std::endl; res = 0; diff --git a/sycl/test-e2e/Basic/event_async_exception.cpp b/sycl/test-e2e/Basic/event_async_exception.cpp index 20b7d5e71bc2..ca605dac8ec0 100644 --- a/sycl/test-e2e/Basic/event_async_exception.cpp +++ b/sycl/test-e2e/Basic/event_async_exception.cpp @@ -34,7 +34,7 @@ int main() { e.wait_and_throw(); return 0; - } catch (runtime_error e) { + } catch (exception e) { return 1; } } diff --git a/sycl/test-e2e/Basic/get_info_aspect.cpp b/sycl/test-e2e/Basic/get_info_aspect.cpp index 7576e0f98d11..fbc7bd7ffa86 100644 --- a/sycl/test-e2e/Basic/get_info_aspect.cpp +++ b/sycl/test-e2e/Basic/get_info_aspect.cpp @@ -12,7 +12,8 @@ int main() { try { sycl::device d(sycl::default_selector_v); size_t mem_free = d.get_info(); - } catch (const sycl::invalid_object_error &e) { + } catch (const sycl::exception &e) { + assert(e.code() == sycl::errc::invalid); std::cout << "Expected exception encountered: " << e.what() << std::endl; failed = false; } diff --git a/sycl/test-e2e/Basic/gpu_max_wgs_error.cpp b/sycl/test-e2e/Basic/gpu_max_wgs_error.cpp index c4d0e15bd646..ed1afc98000a 100644 --- a/sycl/test-e2e/Basic/gpu_max_wgs_error.cpp +++ b/sycl/test-e2e/Basic/gpu_max_wgs_error.cpp @@ -19,9 +19,10 @@ void check(range global, range local, bool expect_fail = false) { cgh.parallel_for(nd_range(global, local), [=](nd_item item) {}); }); assert(!expect_fail && "Exception expected"); - } catch (nd_range_error e) { + } catch (exception e) { if (expect_fail) { std::string msg = e.what(); + assert(e.code() == errc::nd_range); assert(msg.rfind(expected_msg, 0) == 0 && "Unexpected error message"); } else { throw e; diff --git a/sycl/test-e2e/Basic/partition_supported.cpp b/sycl/test-e2e/Basic/partition_supported.cpp index 1dfcec0eae15..1d659e726c8e 100644 --- a/sycl/test-e2e/Basic/partition_supported.cpp +++ b/sycl/test-e2e/Basic/partition_supported.cpp @@ -104,7 +104,7 @@ int main() { "should have thrown an exception" << std::endl; return -1; - } catch (const sycl::feature_not_supported &e) { + } catch (const sycl::exception &e) { if (e.code() != sycl::errc::feature_not_supported) { std::cerr << "error code should be errc::feature_not_supported instead of " @@ -113,7 +113,7 @@ int main() { } } catch (...) { std::cerr << "device::create_sub_device(info::partition_affinity_domain) " - "should have thrown sycl::feature_not_supported" + "should have thrown sycl::exception" << std::endl; return -1; } diff --git a/sycl/test-e2e/Basic/property_list.cpp b/sycl/test-e2e/Basic/property_list.cpp index 540c542a1239..ecd2324a363a 100644 --- a/sycl/test-e2e/Basic/property_list.cpp +++ b/sycl/test-e2e/Basic/property_list.cpp @@ -52,7 +52,7 @@ int main() { Failed = true; } - } catch (sycl::invalid_object_error &Error) { + } catch (sycl::exception &Error) { Error.what(); std::cerr << "Error: exception was thrown in get_property method." << std::endl; diff --git a/sycl/test-e2e/Basic/reqd_work_group_size.cpp b/sycl/test-e2e/Basic/reqd_work_group_size.cpp index 1510461f9782..d3fbe1621c75 100644 --- a/sycl/test-e2e/Basic/reqd_work_group_size.cpp +++ b/sycl/test-e2e/Basic/reqd_work_group_size.cpp @@ -144,9 +144,9 @@ int runNegativeTest(queue &Q, range GlobalRange, Q.wait_and_throw(); std::cerr << TestCaseName << " failed: no exception has been thrown\n"; return 1; // We shouldn't be here, exception is expected - } catch (nd_range_error &E) { - return 0; } catch (sycl::exception &E) { + if (E.code() == sycl::errc::nd_range) + return 0; std::cerr << TestCaseName << " failed: unexpected sycl::exception: " << E.what() << std::endl; diff --git a/sycl/test-e2e/Basic/use_pinned_host_memory.cpp b/sycl/test-e2e/Basic/use_pinned_host_memory.cpp index 49ef9f6c10f6..75b11c681798 100644 --- a/sycl/test-e2e/Basic/use_pinned_host_memory.cpp +++ b/sycl/test-e2e/Basic/use_pinned_host_memory.cpp @@ -31,10 +31,11 @@ int main() { {sycl::ext::oneapi::property::buffer::use_pinned_host_memory()}); // Expected that exception is thrown return 1; - } catch (sycl::invalid_object_error &E) { - if (std::string(E.what()).find( + } catch (sycl::exception &E) { + if (E.code() != sycl::errc::invalid || + std::string(E.what()).find( "The use_pinned_host_memory cannot be used with host pointer") == - std::string::npos) { + std::string::npos) { return 1; } diff --git a/sycl/test-e2e/Basic/work_group_size_prop.cpp b/sycl/test-e2e/Basic/work_group_size_prop.cpp index 19a0cd2d40a3..e23f021aa25c 100644 --- a/sycl/test-e2e/Basic/work_group_size_prop.cpp +++ b/sycl/test-e2e/Basic/work_group_size_prop.cpp @@ -63,21 +63,10 @@ int test(queue &Q, PropertiesT Props, KernelType KernelFunc) { KernelFunc); }); Q.wait_and_throw(); - } catch (nd_range_error &E) { - std::cerr << "Test case ReqdWGSizePositiveA failed: unexpected " - "nd_range_error exception: " + } catch (exception &E) { + std::cerr << "Test case ReqdWGSizePositiveA failed: unexpected exception: " << E.what() << std::endl; return 1; - } catch (runtime_error &E) { - std::cerr << "Test case ReqdWGSizePositiveA failed: unexpected " - "runtime_error exception: " - << E.what() << std::endl; - return 1; - } catch (...) { - std::cerr << "Test case ReqdWGSizePositiveA failed: something unexpected " - "has been caught" - << std::endl; - return 1; } // Same as above but using the queue shortcuts. @@ -86,21 +75,11 @@ int test(queue &Q, PropertiesT Props, KernelType KernelFunc) { nd_range(repeatRange(8), range(Is...)), Props, KernelFunc); Q.wait_and_throw(); - } catch (nd_range_error &E) { - std::cerr << "Test case ReqdWGSizePositiveA shortcut failed: unexpected " - "nd_range_error exception: " - << E.what() << std::endl; - return 1; - } catch (runtime_error &E) { + } catch (exception &E) { std::cerr << "Test case ReqdWGSizePositiveA shortcut failed: unexpected " - "runtime_error exception: " + "exception: " << E.what() << std::endl; return 1; - } catch (...) { - std::cerr << "Test case ReqdWGSizePositiveA shortcut failed: something " - "unexpected has been caught" - << std::endl; - return 1; } // Kernel that has a required WG size, but no local size is specified. @@ -114,46 +93,22 @@ int test(queue &Q, PropertiesT Props, KernelType KernelFunc) { repeatRange(16), Props, KernelFunc); }); Q.wait_and_throw(); - } catch (nd_range_error &E) { + } catch (exception &E) { std::cerr << "Test case ReqdWGSizeNoLocalPositive failed: unexpected " - "nd_range_error exception: " + "exception: " << E.what() << std::endl; return 1; - } catch (runtime_error &E) { - std::cerr - << "Test case ReqdWGSizeNoLocalPositive: unexpected runtime_error " - "exception: " - << E.what() << std::endl; - return 1; - } catch (...) { - std::cerr << "Test case ReqdWGSizeNoLocalPositive failed: something " - "unexpected has been caught" - << std::endl; - return 1; } try { Q.parallel_for>( repeatRange(16), Props, KernelFunc); Q.wait_and_throw(); - } catch (nd_range_error &E) { - std::cerr - << "Test case ReqdWGSizeNoLocalPositive shortcut failed: unexpected " - "nd_range_error exception: " - << E.what() << std::endl; - return 1; - } catch (runtime_error &E) { - std::cerr << "Test case ReqdWGSizeNoLocalPositive shortcut: unexpected " - "runtime_error " - "exception: " + } catch (exception &E) { + std::cerr << "Test case ReqdWGSizeNoLocalPositive shortcut failed: " + "unexpected exception: " << E.what() << std::endl; return 1; - } catch (...) { - std::cerr - << "Test case ReqdWGSizeNoLocalPositive shortcut failed: something " - "unexpected has been caught" - << std::endl; - return 1; } } @@ -168,28 +123,18 @@ int test(queue &Q, PropertiesT Props, KernelType KernelFunc) { std::cerr << "Test case ReqdWGSizeNegativeA failed: no exception has been " "thrown\n"; return 1; // We shouldn't be here, exception is expected - } catch (nd_range_error &E) { - if (std::string(E.what()).find( + } catch (exception &E) { + if (E.code() != errc::nd_range || + std::string(E.what()).find( "The specified local size " + rangeToString(repeatRange(8)) + " doesn't match the required " + "work-group size specified in the program source " + rangeToString(range(Is...))) == std::string::npos) { std::cerr - << "Test case ReqdWGSizeNegativeA failed: unexpected nd_range_error " - "exception: " + << "Test case ReqdWGSizeNegativeA failed: unexpected exception: " << E.what() << std::endl; return 1; } - } catch (runtime_error &E) { - std::cerr << "Test case ReqdWGSizeNegativeA failed: unexpected " - "nd_range_error exception: " - << E.what() << std::endl; - return 1; - } catch (...) { - std::cerr << "Test case ReqdWGSizeNegativeA failed: something unexpected " - "has been caught" - << std::endl; - return 1; } // Same as above but using the queue shortcuts. @@ -202,28 +147,18 @@ int test(queue &Q, PropertiesT Props, KernelType KernelFunc) { "has been " "thrown\n"; return 1; // We shouldn't be here, exception is expected - } catch (nd_range_error &E) { - if (std::string(E.what()).find( + } catch (exception &E) { + if (E.code() != errc::nd_range || + std::string(E.what()).find( "The specified local size " + rangeToString(repeatRange(8)) + " doesn't match the required " + "work-group size specified in the program source " + rangeToString(range(Is...))) == std::string::npos) { std::cerr << "Test case ReqdWGSizeNegativeA shortcut failed: unexpected " - "nd_range_error " "exception: " << E.what() << std::endl; return 1; } - } catch (runtime_error &E) { - std::cerr << "Test case ReqdWGSizeNegativeA shortcut failed: unexpected " - "nd_range_error exception: " - << E.what() << std::endl; - return 1; - } catch (...) { - std::cerr << "Test case ReqdWGSizeNegativeA shortcut failed: something " - "unexpected has been caught" - << std::endl; - return 1; } return 0;