From 2e29f5de28ec40fa0e1f57407ad91d574e558020 Mon Sep 17 00:00:00 2001 From: Michael Aziz Date: Thu, 23 Jan 2025 07:38:55 -0800 Subject: [PATCH 1/2] Add test cases for queue default context Signed-off-by: Michael Aziz --- tests/queue/queue_constructors.cpp | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/queue/queue_constructors.cpp b/tests/queue/queue_constructors.cpp index 95b1c34d3..36296cf92 100644 --- a/tests/queue/queue_constructors.cpp +++ b/tests/queue/queue_constructors.cpp @@ -248,4 +248,44 @@ TEST_CASE("Check exceptions thrown for mismatched context and device", } } +TEST_CASE("Check that the default context contains all devices", "[queue]") { + sycl::platform platform{}; + sycl::context defaultContext = sycl::queue{}.get_context(); + CHECK(defaultContext.get_devices() == platform.get_devices()); +} + +TEST_CASE("Check that queue constructors use the correct context", "[queue]") { + const sycl::property_list& propList = {}; + cts_async_handler asyncHandler; + const auto& deviceSelector = sycl::default_selector_v; + sycl::device syclDevice; + sycl::context syclContext; + sycl::context defaultContext = sycl::queue{}.get_context(); + + // Check that a default-constructed context is not the default context. + CHECK(syclContext != defaultContext); + + // Default context constructors + CHECK(defaultContext == sycl::queue{propList}.get_context()); + CHECK(defaultContext == sycl::queue{asyncHandler, propList}.get_context()); + CHECK(defaultContext == sycl::queue{deviceSelector, propList}.get_context()); + CHECK(defaultContext == + sycl::queue{deviceSelector, asyncHandler, propList}.get_context()); + CHECK(defaultContext == sycl::queue{syclDevice, propList}.get_context()); + CHECK(defaultContext == + sycl::queue{syclDevice, asyncHandler, propList}.get_context()); + + // Non-default context constructors + CHECK(syclContext == + sycl::queue{syclContext, deviceSelector, propList}.get_context()); + CHECK(syclContext == + sycl::queue{syclContext, deviceSelector, asyncHandler, propList} + .get_context()); + CHECK(syclContext == + sycl::queue{syclContext, syclDevice, propList}.get_context()); + CHECK(syclContext == + sycl::queue{syclContext, syclDevice, asyncHandler, propList} + .get_context()); +} + } /* namespace queue_constructors */ From 70dbd8f080af2118c11481593a8add8a567ef815 Mon Sep 17 00:00:00 2001 From: Michael Aziz Date: Thu, 23 Jan 2025 12:06:19 -0500 Subject: [PATCH 2/2] Update tests/queue/queue_constructors.cpp Co-authored-by: Tom Deakin --- tests/queue/queue_constructors.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/queue/queue_constructors.cpp b/tests/queue/queue_constructors.cpp index 36296cf92..0d529706c 100644 --- a/tests/queue/queue_constructors.cpp +++ b/tests/queue/queue_constructors.cpp @@ -263,6 +263,7 @@ TEST_CASE("Check that queue constructors use the correct context", "[queue]") { sycl::context defaultContext = sycl::queue{}.get_context(); // Check that a default-constructed context is not the default context. + // recall, explicitly created contexts should not equal the default one. CHECK(syclContext != defaultContext); // Default context constructors