Skip to content

Commit

Permalink
[SYCL][E2E] Remove deprecated exception warnings in Basic e2e tests (i…
Browse files Browse the repository at this point in the history
  • Loading branch information
ayylol committed May 31, 2024
1 parent d5b26f1 commit 46cfb06
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 100 deletions.
7 changes: 5 additions & 2 deletions sycl/test-e2e/Basic/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 4 additions & 3 deletions sycl/test-e2e/Basic/context_platforms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 4 additions & 3 deletions sycl/test-e2e/Basic/diagnostics/non-uniform-wk-gp-test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion sycl/test-e2e/Basic/event_async_exception.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int main() {

e.wait_and_throw();
return 0;
} catch (runtime_error e) {
} catch (exception e) {
return 1;
}
}
3 changes: 2 additions & 1 deletion sycl/test-e2e/Basic/get_info_aspect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ int main() {
try {
sycl::device d(sycl::default_selector_v);
size_t mem_free = d.get_info<sycl::ext::intel::info::device::free_memory>();
} 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;
}
Expand Down
3 changes: 2 additions & 1 deletion sycl/test-e2e/Basic/gpu_max_wgs_error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ void check(range<N> global, range<N> local, bool expect_fail = false) {
cgh.parallel_for(nd_range<N>(global, local), [=](nd_item<N> 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;
Expand Down
4 changes: 2 additions & 2 deletions sycl/test-e2e/Basic/partition_supported.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 "
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion sycl/test-e2e/Basic/property_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions sycl/test-e2e/Basic/reqd_work_group_size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ int runNegativeTest(queue &Q, range<sizeof...(ReqdWGSizes)> 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;
Expand Down
7 changes: 4 additions & 3 deletions sycl/test-e2e/Basic/use_pinned_host_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
97 changes: 16 additions & 81 deletions sycl/test-e2e/Basic/work_group_size_prop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -86,21 +75,11 @@ int test(queue &Q, PropertiesT Props, KernelType KernelFunc) {
nd_range<Dims>(repeatRange<Dims>(8), range<Dims>(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.
Expand All @@ -114,46 +93,22 @@ int test(queue &Q, PropertiesT Props, KernelType KernelFunc) {
repeatRange<Dims>(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<ReqdWGSizeNoLocalPositive<KernelVariant, true, Is...>>(
repeatRange<Dims>(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;
}
}

Expand All @@ -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<Dims>(8)) +
" doesn't match the required " +
"work-group size specified in the program source " +
rangeToString(range<Dims>(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.
Expand All @@ -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<Dims>(8)) +
" doesn't match the required " +
"work-group size specified in the program source " +
rangeToString(range<Dims>(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;
Expand Down

0 comments on commit 46cfb06

Please sign in to comment.