Skip to content

Commit

Permalink
Merge pull request #2282 from martygrant/martin/queue-cts-spec-gap
Browse files Browse the repository at this point in the history
Improvements to align CTS and Spec for Queue
  • Loading branch information
martygrant authored Nov 20, 2024
2 parents 83c02a3 + 30d91b4 commit 5b57041
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 115 deletions.
12 changes: 6 additions & 6 deletions test/conformance/queue/queue_adapter_native_cpu.match
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ urQueueCreateTest.CheckContext/*
urQueueCreateWithParamTest.SuccessWithProperties/*
urQueueCreateWithParamTest.MatchingDeviceHandles/*
urQueueFlushTest.Success/*
urQueueGetInfoTestWithInfoParam.Success/*__UR_QUEUE_INFO_CONTEXT
urQueueGetInfoTestWithInfoParam.Success/*__UR_QUEUE_INFO_DEVICE
urQueueGetInfoTestWithInfoParam.Success/*__UR_QUEUE_INFO_FLAGS
urQueueGetInfoTestWithInfoParam.Success/*__UR_QUEUE_INFO_REFERENCE_COUNT
urQueueGetInfoTestWithInfoParam.Success/*__UR_QUEUE_INFO_EMPTY
urQueueGetInfoDeviceQueueTestWithInfoParam.Success/*
urQueueGetInfoTest.Context/*
urQueueGetInfoTest.Device/*
urQueueGetInfoTest.Flags/*
urQueueGetInfoTest.ReferenceCount/*
urQueueGetInfoTest.InvalidSizeSmall/*
urQueueGetInfoDeviceQueueTestWithInfoParam.DeviceDefault/*
urQueueGetInfoDeviceQueueTestWithInfoParam.Size/*
urQueueRetainTest.Success/*
urQueueReleaseTest.Success/*
21 changes: 21 additions & 0 deletions test/conformance/queue/urQueueCreateWithNativeHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,24 @@ 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);
}
228 changes: 119 additions & 109 deletions test/conformance/queue/urQueueGetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,131 +5,80 @@
#include <map>
#include <uur/fixtures.h>

std::unordered_map<ur_queue_info_t, size_t> queue_info_size_map = {
{UR_QUEUE_INFO_CONTEXT, sizeof(ur_context_handle_t)},
{UR_QUEUE_INFO_DEVICE, sizeof(ur_device_handle_t)},
{UR_QUEUE_INFO_DEVICE_DEFAULT, sizeof(ur_queue_handle_t)},
{UR_QUEUE_INFO_FLAGS, sizeof(ur_queue_flags_t)},
{UR_QUEUE_INFO_REFERENCE_COUNT, sizeof(uint32_t)},
{UR_QUEUE_INFO_SIZE, sizeof(uint32_t)},
{UR_QUEUE_INFO_EMPTY, sizeof(ur_bool_t)},
};
using urQueueGetInfoTest = uur::urQueueTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urQueueGetInfoTest);

using urQueueGetInfoTestWithInfoParam =
uur::urQueueTestWithParam<ur_queue_info_t>;
TEST_P(urQueueGetInfoTest, Context) {
size_t size = 0;
auto infoType = UR_QUEUE_INFO_CONTEXT;
ASSERT_SUCCESS(urQueueGetInfo(queue, infoType, 0, nullptr, &size));
ASSERT_NE(size, 0);
ASSERT_EQ(sizeof(ur_context_handle_t), size);

UUR_TEST_SUITE_P(urQueueGetInfoTestWithInfoParam,
::testing::Values(UR_QUEUE_INFO_CONTEXT, UR_QUEUE_INFO_DEVICE,
UR_QUEUE_INFO_FLAGS,
UR_QUEUE_INFO_REFERENCE_COUNT,
UR_QUEUE_INFO_EMPTY),
uur::deviceTestWithParamPrinter<ur_queue_info_t>);
std::vector<uint8_t> data(size);
ASSERT_SUCCESS(urQueueGetInfo(queue, infoType, size, data.data(), nullptr));

TEST_P(urQueueGetInfoTestWithInfoParam, Success) {
ur_queue_info_t info_type = getParam();
size_t size = 0;
auto result = urQueueGetInfo(queue, info_type, 0, nullptr, &size);
auto returned_context =
reinterpret_cast<ur_context_handle_t *>(data.data());
ASSERT_EQ(context, *returned_context);
}

if (result == UR_RESULT_SUCCESS) {
ASSERT_NE(size, 0);
TEST_P(urQueueGetInfoTest, Device) {
size_t size = 0;
auto infoType = UR_QUEUE_INFO_DEVICE;
ASSERT_SUCCESS(urQueueGetInfo(queue, infoType, 0, nullptr, &size));
ASSERT_NE(size, 0);
ASSERT_EQ(sizeof(ur_device_handle_t), size);

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, infoType, size, data.data(), nullptr));

std::vector<uint8_t> data(size);
ASSERT_SUCCESS(
urQueueGetInfo(queue, info_type, size, data.data(), nullptr));

switch (info_type) {
case UR_QUEUE_INFO_CONTEXT: {
auto returned_context =
reinterpret_cast<ur_context_handle_t *>(data.data());
ASSERT_EQ(context, *returned_context);
break;
}
case UR_QUEUE_INFO_DEVICE: {
auto returned_device =
reinterpret_cast<ur_device_handle_t *>(data.data());
ASSERT_EQ(*returned_device, device);
break;
}
case UR_QUEUE_INFO_REFERENCE_COUNT: {
auto returned_reference_count =
reinterpret_cast<uint32_t *>(data.data());
ASSERT_GT(*returned_reference_count, 0U);
break;
}
default:
break;
}
} else {
ASSERT_EQ_RESULT(result, UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION);
}
auto returned_device = reinterpret_cast<ur_device_handle_t *>(data.data());
ASSERT_EQ(device, *returned_device);
}

struct urQueueGetInfoDeviceQueueTestWithInfoParam
: public uur::urContextTestWithParam<ur_queue_info_t> {
void SetUp() {
urContextTestWithParam<ur_queue_info_t>::SetUp();
ur_queue_flags_t deviceQueueCapabilities;
ASSERT_SUCCESS(
urDeviceGetInfo(device, UR_DEVICE_INFO_QUEUE_ON_DEVICE_PROPERTIES,
sizeof(deviceQueueCapabilities),
&deviceQueueCapabilities, nullptr));
if (!deviceQueueCapabilities) {
GTEST_SKIP() << "Queue on device is not supported.";
}
ASSERT_SUCCESS(
urQueueCreate(context, device, &queueProperties, &queue));
}

void TearDown() {
if (queue) {
ASSERT_SUCCESS(urQueueRelease(queue));
}
urContextTestWithParam<ur_queue_info_t>::TearDown();
}
TEST_P(urQueueGetInfoTest, Flags) {
size_t size = 0;
auto infoType = UR_QUEUE_INFO_FLAGS;
ASSERT_SUCCESS(urQueueGetInfo(queue, infoType, 0, nullptr, &size));
ASSERT_NE(size, 0);
ASSERT_EQ(sizeof(ur_queue_flags_t), size);

ur_queue_handle_t queue = nullptr;
ur_queue_properties_t queueProperties = {
UR_STRUCTURE_TYPE_QUEUE_PROPERTIES, nullptr,
UR_QUEUE_FLAG_ON_DEVICE | UR_QUEUE_FLAG_ON_DEVICE_DEFAULT |
UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE};
};
std::vector<uint8_t> data(size);
ASSERT_SUCCESS(urQueueGetInfo(queue, infoType, size, data.data(), nullptr));

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>);
auto returned_flags = reinterpret_cast<ur_queue_flags_t *>(data.data());
EXPECT_EQ(*returned_flags, queue_properties.flags);
}

TEST_P(urQueueGetInfoDeviceQueueTestWithInfoParam, Success) {
ur_queue_info_t info_type = getParam();
TEST_P(urQueueGetInfoTest, ReferenceCount) {
size_t size = 0;
auto result = urQueueGetInfo(queue, info_type, 0, nullptr, &size);
auto infoType = UR_QUEUE_INFO_REFERENCE_COUNT;
ASSERT_SUCCESS(urQueueGetInfo(queue, infoType, 0, nullptr, &size));
ASSERT_NE(size, 0);
ASSERT_EQ(sizeof(uint32_t), size);

if (result == UR_RESULT_SUCCESS) {
ASSERT_NE(size, 0);
std::vector<uint8_t> data(size);
ASSERT_SUCCESS(urQueueGetInfo(queue, infoType, size, data.data(), nullptr));

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);
}
auto returned_reference_count = reinterpret_cast<uint32_t *>(data.data());
ASSERT_GT(*returned_reference_count, 0U);
}

using urQueueGetInfoTest = uur::urQueueTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urQueueGetInfoTest);
TEST_P(urQueueGetInfoTest, EmptyQueue) {
size_t size = 0;
auto infoType = UR_QUEUE_INFO_EMPTY;
UUR_ASSERT_SUCCESS_OR_UNSUPPORTED(
urQueueGetInfo(queue, infoType, 0, nullptr, &size));
ASSERT_NE(size, 0);
ASSERT_EQ(sizeof(ur_bool_t), size);

std::vector<uint8_t> data(size);
ASSERT_SUCCESS(urQueueGetInfo(queue, infoType, size, data.data(), nullptr));

auto returned_empty_queue = reinterpret_cast<ur_bool_t *>(data.data());
ASSERT_TRUE(returned_empty_queue);
}

TEST_P(urQueueGetInfoTest, InvalidNullHandleQueue) {
ur_context_handle_t context = nullptr;
Expand Down Expand Up @@ -174,3 +123,64 @@ TEST_P(urQueueGetInfoTest, InvalidNullPointerPropSizeRet) {
UR_RESULT_ERROR_INVALID_NULL_POINTER,
urQueueGetInfo(queue, UR_QUEUE_INFO_CONTEXT, 0, nullptr, nullptr));
}

struct urQueueGetInfoDeviceQueueTestWithInfoParam : public uur::urQueueTest {
void SetUp() {
urQueueGetInfoTest::SetUp();
ur_queue_flags_t deviceQueueCapabilities;
ASSERT_SUCCESS(
urDeviceGetInfo(device, UR_DEVICE_INFO_QUEUE_ON_DEVICE_PROPERTIES,
sizeof(deviceQueueCapabilities),
&deviceQueueCapabilities, nullptr));
if (!deviceQueueCapabilities) {
GTEST_SKIP() << "Queue on device is not supported.";
}
ASSERT_SUCCESS(
urQueueCreate(context, device, &queueProperties, &queue));
}

void TearDown() {
if (queue) {
ASSERT_SUCCESS(urQueueRelease(queue));
}
urQueueGetInfoTest::TearDown();
}

ur_queue_handle_t queue = nullptr;
ur_queue_properties_t queueProperties = {
UR_STRUCTURE_TYPE_QUEUE_PROPERTIES, nullptr,
UR_QUEUE_FLAG_ON_DEVICE | UR_QUEUE_FLAG_ON_DEVICE_DEFAULT |
UR_QUEUE_FLAG_OUT_OF_ORDER_EXEC_MODE_ENABLE};
};

UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urQueueGetInfoDeviceQueueTestWithInfoParam);

TEST_P(urQueueGetInfoDeviceQueueTestWithInfoParam, DeviceDefault) {

size_t size = 0;
auto infoType = UR_QUEUE_INFO_DEVICE_DEFAULT;
ASSERT_SUCCESS(urQueueGetInfo(queue, infoType, 0, nullptr, &size));
ASSERT_NE(size, 0);
ASSERT_EQ(sizeof(ur_queue_handle_t), size);

std::vector<uint8_t> data(size);
ASSERT_SUCCESS(urQueueGetInfo(queue, infoType, size, data.data(), nullptr));

auto returned_queue = reinterpret_cast<ur_queue_handle_t *>(data.data());
ASSERT_EQ(queue, *returned_queue);
}

TEST_P(urQueueGetInfoDeviceQueueTestWithInfoParam, Size) {

size_t size = 0;
auto infoType = UR_QUEUE_INFO_SIZE;
ASSERT_SUCCESS(urQueueGetInfo(queue, infoType, 0, nullptr, &size));
ASSERT_NE(size, 0);
ASSERT_EQ(sizeof(uint32_t), size);

std::vector<uint8_t> data(size);
ASSERT_SUCCESS(urQueueGetInfo(queue, infoType, size, data.data(), nullptr));

auto returned_size = reinterpret_cast<uint32_t *>(data.data());
ASSERT_GT(*returned_size, 0);
}

0 comments on commit 5b57041

Please sign in to comment.