Skip to content

Commit

Permalink
Improvements to align CTS and Spec for Queue:
Browse files Browse the repository at this point in the history
- Add UR_RESULT_ERROR_INVALID_NULL_HANDLE/POINTER for urQueueCreateWithNativeHandleTest
- Add tests for urQueueCreateWithNativeHandleTest for creating an owned/unowned native queue handle
- Removed urQueueGetInfoDeviceQueueTestWithInfoParam as it was redundant - already being checked with urQueueGetInfoTestWithInfoParam
- Added missing enum queries for urQueueGetInfoTestWithInfoParam
  • Loading branch information
martygrant committed Nov 18, 2024
1 parent e3247c2 commit 80c359c
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 29 deletions.
55 changes: 55 additions & 0 deletions test/conformance/queue/urQueueCreateWithNativeHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,58 @@ TEST_P(urQueueCreateWithNativeHandleTest, Success) {
ASSERT_EQ(q_context, context);
ASSERT_SUCCESS(urQueueRelease(q));
}

TEST_P(urQueueCreateWithNativeHandleTest, InvalidNullHandle) {
ur_native_handle_t native_handle = 0;
{
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
urQueueGetNativeHandle(queue, nullptr, &native_handle));
}

ur_queue_handle_t q = nullptr;
ASSERT_EQ(urQueueCreateWithNativeHandle(native_handle, nullptr, device,
nullptr, &q),
UR_RESULT_ERROR_INVALID_NULL_HANDLE);
}

TEST_P(urQueueCreateWithNativeHandleTest, InvalidNullPointer) {
ur_native_handle_t native_handle = 0;
{
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
urQueueGetNativeHandle(queue, nullptr, &native_handle));
}

ASSERT_EQ(urQueueCreateWithNativeHandle(native_handle, context, device,
nullptr, nullptr),
UR_RESULT_ERROR_INVALID_NULL_POINTER);
}

TEST_P(urQueueCreateWithNativeHandleTest, SuccessWithOwnedNativeHandle) {
ur_native_handle_t native_handle = 0;
{
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
urQueueGetNativeHandle(queue, nullptr, &native_handle));
}

ur_queue_handle_t q = nullptr;
ur_queue_native_properties_t properties{
UR_STRUCTURE_TYPE_QUEUE_NATIVE_PROPERTIES, nullptr, true};
ASSERT_SUCCESS(urQueueCreateWithNativeHandle(native_handle, context, device,
&properties, &q));
ASSERT_NE(q, nullptr);
}

TEST_P(urQueueCreateWithNativeHandleTest, SuccessWithUnOwnedNativeHandle) {
ur_native_handle_t native_handle = 0;
{
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
urQueueGetNativeHandle(queue, nullptr, &native_handle));
}

ur_queue_handle_t q = nullptr;
ur_queue_native_properties_t properties{
UR_STRUCTURE_TYPE_QUEUE_NATIVE_PROPERTIES, nullptr, false};
ASSERT_SUCCESS(urQueueCreateWithNativeHandle(native_handle, context, device,
&properties, &q));
ASSERT_NE(q, nullptr);
}
47 changes: 18 additions & 29 deletions test/conformance/queue/urQueueGetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,30 @@ TEST_P(urQueueGetInfoTestWithInfoParam, Success) {
ASSERT_EQ(*returned_device, device);
break;
}
case UR_QUEUE_INFO_DEVICE_DEFAULT: {
auto returned_default_queue =
reinterpret_cast<ur_queue_handle_t *>(data.data());
ASSERT_EQ(*returned_default_queue, queue);
break;
}
case UR_QUEUE_INFO_FLAGS: {
auto returned_flags =
reinterpret_cast<ur_queue_flags_t *>(data.data());
EXPECT_EQ(*returned_flags, *returned_flags & UR_QUEUE_FLAGS_MASK);
break;
}
case UR_QUEUE_INFO_REFERENCE_COUNT: {
auto returned_reference_count =
reinterpret_cast<uint32_t *>(data.data());
ASSERT_GT(*returned_reference_count, 0U);
break;
}
case UR_QUEUE_INFO_EMPTY: {
auto returned_empty_queue =
reinterpret_cast<ur_bool_t *>(data.data());
ASSERT_TRUE(returned_empty_queue);
break;
}
default:
break;
}
Expand Down Expand Up @@ -99,35 +117,6 @@ struct urQueueGetInfoDeviceQueueTestWithInfoParam
UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE};
};

UUR_TEST_SUITE_P(urQueueGetInfoDeviceQueueTestWithInfoParam,
::testing::Values(UR_QUEUE_INFO_CONTEXT, UR_QUEUE_INFO_DEVICE,
UR_QUEUE_INFO_DEVICE_DEFAULT,
UR_QUEUE_INFO_FLAGS,
UR_QUEUE_INFO_REFERENCE_COUNT,
UR_QUEUE_INFO_SIZE, UR_QUEUE_INFO_EMPTY),
uur::deviceTestWithParamPrinter<ur_queue_info_t>);

TEST_P(urQueueGetInfoDeviceQueueTestWithInfoParam, Success) {
ur_queue_info_t info_type = getParam();
size_t size = 0;
auto result = urQueueGetInfo(queue, info_type, 0, nullptr, &size);

if (result == UR_RESULT_SUCCESS) {
ASSERT_NE(size, 0);

if (const auto expected_size = queue_info_size_map.find(info_type);
expected_size != queue_info_size_map.end()) {
ASSERT_EQ(expected_size->second, size);
}

std::vector<uint8_t> data(size);
ASSERT_SUCCESS(
urQueueGetInfo(queue, info_type, size, data.data(), nullptr));
} else {
ASSERT_EQ_RESULT(result, UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION);
}
}

using urQueueGetInfoTest = uur::urQueueTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urQueueGetInfoTest);

Expand Down

0 comments on commit 80c359c

Please sign in to comment.