Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move urMemoryGetInfo success test from a switch to individual tests #2521

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 24 additions & 31 deletions test/conformance/adapter/urAdapterGetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,24 @@ using urAdapterGetInfoTest = uur::urAdapterTest;

UUR_INSTANTIATE_ADAPTER_TEST_SUITE_P(urAdapterGetInfoTest);

TEST_P(urAdapterGetInfoTest, Backend) {
TEST_P(urAdapterGetInfoTest, SuccessBackend) {
auto info_type = UR_ADAPTER_INFO_BACKEND;
size_t size = 0;
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urAdapterGetInfo(adapter, info_type, 0, nullptr, &size), info_type);
ASSERT_NE(size, 0);

ASSERT_SUCCESS(urAdapterGetInfo(adapter, info_type, 0, nullptr, &size));
ASSERT_EQ(size, sizeof(ur_adapter_backend_t));

std::vector<char> info_data(size);
ur_adapter_backend_t backend = UR_ADAPTER_BACKEND_UNKNOWN;
ASSERT_SUCCESS(
urAdapterGetInfo(adapter, info_type, size, info_data.data(), nullptr));
urAdapterGetInfo(adapter, info_type, size, &backend, nullptr));

ASSERT_TRUE(backend >= UR_ADAPTER_BACKEND_LEVEL_ZERO &&
backend <= UR_ADAPTER_BACKEND_NATIVE_CPU);
}

TEST_P(urAdapterGetInfoTest, ReferenceCount) {
TEST_P(urAdapterGetInfoTest, SuccessReferenceCount) {
auto info_type = UR_ADAPTER_INFO_REFERENCE_COUNT;
size_t size = 0;
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urAdapterGetInfo(adapter, info_type, 0, nullptr, &size), info_type);
ASSERT_SUCCESS(urAdapterGetInfo(adapter, info_type, 0, nullptr, &size));
ASSERT_EQ(size, sizeof(uint32_t));

uint32_t reference_count = 0;
Expand All @@ -38,6 +37,18 @@ TEST_P(urAdapterGetInfoTest, ReferenceCount) {
ASSERT_GE(reference_count, 0);
}

TEST_P(urAdapterGetInfoTest, SuccessVersion) {
auto info_type = UR_ADAPTER_INFO_VERSION;
size_t size = 0;
ASSERT_SUCCESS(urAdapterGetInfo(adapter, info_type, 0, nullptr, &size));
ASSERT_EQ(size, sizeof(uint32_t));
RossBrunton marked this conversation as resolved.
Show resolved Hide resolved

uint32_t returned_version = 46;
ASSERT_SUCCESS(
urAdapterGetInfo(adapter, info_type, size, &returned_version, nullptr));
ASSERT_NE(42, returned_version);
}

TEST_P(urAdapterGetInfoTest, InvalidNullHandleAdapter) {
size_t size = 0;
ASSERT_EQ_RESULT(
Expand All @@ -53,21 +64,21 @@ TEST_P(urAdapterGetInfoTest, InvalidEnumerationAdapterInfoType) {
}

TEST_P(urAdapterGetInfoTest, InvalidSizeZero) {
ur_adapter_backend_t backend;
ur_adapter_backend_t backend = UR_ADAPTER_BACKEND_UNKNOWN;
ASSERT_EQ_RESULT(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND, 0,
&backend, nullptr),
UR_RESULT_ERROR_INVALID_SIZE);
}

TEST_P(urAdapterGetInfoTest, InvalidSizeSmall) {
ur_adapter_backend_t backend;
ur_adapter_backend_t backend = UR_ADAPTER_BACKEND_UNKNOWN;
ASSERT_EQ_RESULT(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND,
sizeof(backend) - 1, &backend, nullptr),
UR_RESULT_ERROR_INVALID_SIZE);
}

TEST_P(urAdapterGetInfoTest, InvalidNullPointerPropValue) {
ur_adapter_backend_t backend;
ur_adapter_backend_t backend = UR_ADAPTER_BACKEND_UNKNOWN;
ASSERT_EQ_RESULT(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND,
sizeof(backend), nullptr, nullptr),
UR_RESULT_ERROR_INVALID_NULL_POINTER);
Expand All @@ -78,21 +89,3 @@ TEST_P(urAdapterGetInfoTest, InvalidNullPointerPropSizeRet) {
urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND, 0, nullptr, nullptr),
UR_RESULT_ERROR_INVALID_NULL_POINTER);
}

TEST_P(urAdapterGetInfoTest, ReferenceCountNotZero) {
uint32_t referenceCount = 0;

ASSERT_SUCCESS(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_REFERENCE_COUNT,
sizeof(referenceCount), &referenceCount,
nullptr));
ASSERT_GT(referenceCount, 0);
}

TEST_P(urAdapterGetInfoTest, ValidAdapterBackend) {
ur_adapter_backend_t backend;
ASSERT_SUCCESS(urAdapterGetInfo(adapter, UR_ADAPTER_INFO_BACKEND,
sizeof(backend), &backend, nullptr));

ASSERT_TRUE(backend >= UR_ADAPTER_BACKEND_LEVEL_ZERO &&
backend <= UR_ADAPTER_BACKEND_NATIVE_CPU);
}
16 changes: 8 additions & 8 deletions test/conformance/event/urEventGetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TEST_P(urEventGetInfoTest, SuccessCommandQueue) {
ASSERT_SUCCESS(urEventGetInfo(event, info_type, 0, nullptr, &size));
ASSERT_EQ(size, sizeof(ur_queue_handle_t));

ur_queue_handle_t returned_queue;
ur_queue_handle_t returned_queue = nullptr;
ASSERT_SUCCESS(
urEventGetInfo(event, info_type, size, &returned_queue, nullptr));

Expand All @@ -28,7 +28,7 @@ TEST_P(urEventGetInfoTest, SuccessContext) {
ASSERT_SUCCESS(urEventGetInfo(event, info_type, 0, nullptr, &size));
ASSERT_EQ(size, sizeof(ur_context_handle_t));

ur_context_handle_t returned_context;
ur_context_handle_t returned_context = nullptr;
ASSERT_SUCCESS(
urEventGetInfo(event, info_type, size, &returned_context, nullptr));

Expand All @@ -42,7 +42,7 @@ TEST_P(urEventGetInfoTest, SuccessCommandType) {
ASSERT_SUCCESS(urEventGetInfo(event, info_type, 0, nullptr, &size));
ASSERT_EQ(size, sizeof(ur_command_t));

ur_command_t returned_command_type;
ur_command_t returned_command_type = UR_COMMAND_FORCE_UINT32;
ASSERT_SUCCESS(urEventGetInfo(event, info_type, size,
&returned_command_type, nullptr));

Expand All @@ -56,7 +56,7 @@ TEST_P(urEventGetInfoTest, SuccessCommandExecutionStatus) {
ASSERT_SUCCESS(urEventGetInfo(event, info_type, 0, nullptr, &size));
ASSERT_EQ(size, sizeof(ur_event_status_t));

ur_event_status_t returned_status;
ur_event_status_t returned_status = UR_EVENT_STATUS_FORCE_UINT32;
ASSERT_SUCCESS(
urEventGetInfo(event, info_type, size, &returned_status, nullptr));

Expand All @@ -70,7 +70,7 @@ TEST_P(urEventGetInfoTest, SuccessReferenceCount) {
ASSERT_SUCCESS(urEventGetInfo(event, info_type, 0, nullptr, &size));
ASSERT_EQ(size, sizeof(uint32_t));

uint32_t returned_reference_count;
uint32_t returned_reference_count = 0;
ASSERT_SUCCESS(urEventGetInfo(event, info_type, size,
&returned_reference_count, nullptr));

Expand All @@ -91,7 +91,7 @@ TEST_P(urEventGetInfoTest, InvalidNullHandle) {
}

TEST_P(urEventGetInfoTest, InvalidEnumeration) {
size_t size;
size_t size = 0;
ASSERT_EQ_RESULT(
urEventGetInfo(event, UR_EVENT_INFO_FORCE_UINT32, 0, nullptr, &size),
UR_RESULT_ERROR_INVALID_ENUMERATION);
Expand All @@ -111,9 +111,9 @@ TEST_P(urEventGetInfoTest, InvalidSizePropSize) {
}

TEST_P(urEventGetInfoTest, InvalidSizePropSizeSmall) {
ur_queue_handle_t q;
ur_queue_handle_t queue = nullptr;
ASSERT_EQ_RESULT(urEventGetInfo(event, UR_EVENT_INFO_COMMAND_QUEUE,
sizeof(q) - 1, &q, nullptr),
sizeof(queue) - 1, &queue, nullptr),
UR_RESULT_ERROR_INVALID_SIZE);
}

Expand Down
2 changes: 1 addition & 1 deletion test/conformance/memory/memory_adapter_level_zero.match
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ urMemBufferPartitionWithFlagsTest.Success/*__UR_MEM_FLAG_READ_ONLY
urMemBufferPartitionTest.InvalidValueCreateType/*
urMemBufferPartitionTest.InvalidValueBufferCreateInfoOutOfBounds/*
{{OPT}}urMemImageCreateWithNativeHandleTest.Success/*
{{OPT}}urMemGetInfoImageTest.Success/*__UR_MEM_INFO_SIZE
{{OPT}}urMemGetInfoImageTest.SuccessSize/*
{{OPT}}urMemImageCreateTestWithImageFormatParam.Success/*__UR_IMAGE_CHANNEL_ORDER_RGBA__*

# These tests fail in the "Multi device testing" job, but pass in the hardware specific test
Expand Down
4 changes: 3 additions & 1 deletion test/conformance/memory/memory_adapter_native_cpu.match
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ urMemBufferPartitionWithFlagsTest.Success/*__UR_MEM_FLAG_WRITE_ONLY
urMemBufferPartitionWithFlagsTest.Success/*__UR_MEM_FLAG_READ_ONLY
urMemBufferPartitionTest.InvalidValueCreateType/*
urMemBufferPartitionTest.InvalidValueBufferCreateInfoOutOfBounds/*
urMemGetInfoTestWithParam.Success/*
urMemGetInfoTest.SuccessSize/*
urMemGetInfoTest.SuccessContext/*
urMemGetInfoTest.SuccessReferenceCount/*
urMemGetInfoTest.InvalidSizeSmall/*
urMemReleaseTest.Success/*
urMemReleaseTest.CheckReferenceCount/*
Expand Down
186 changes: 90 additions & 96 deletions test/conformance/memory/urMemGetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,61 +6,51 @@
#include <map>
#include <uur/fixtures.h>

using urMemGetInfoTestWithParam = uur::urMemBufferTestWithParam<ur_mem_info_t>;

static constexpr std::array<ur_mem_info_t, 3> mem_info_values{
UR_MEM_INFO_SIZE, UR_MEM_INFO_CONTEXT, UR_MEM_INFO_REFERENCE_COUNT};
static std::unordered_map<ur_mem_info_t, size_t> mem_info_size_map = {
{UR_MEM_INFO_SIZE, sizeof(size_t)},
{UR_MEM_INFO_CONTEXT, sizeof(ur_context_handle_t)},
{UR_MEM_INFO_REFERENCE_COUNT, sizeof(uint32_t)},
};

UUR_TEST_SUITE_P(urMemGetInfoTestWithParam,
::testing::ValuesIn(mem_info_values),
uur::deviceTestWithParamPrinter<ur_mem_info_t>);

TEST_P(urMemGetInfoTestWithParam, Success) {
ur_mem_info_t info = getParam();
size_t size;
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urMemGetInfo(buffer, info, 0, nullptr, &size), info);
ASSERT_NE(size, 0);

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

std::vector<uint8_t> info_data(size);
ASSERT_SUCCESS(urMemGetInfo(buffer, info, size, info_data.data(), nullptr));

switch (info) {
case UR_MEM_INFO_CONTEXT: {
auto returned_context =
reinterpret_cast<ur_context_handle_t *>(info_data.data());
ASSERT_EQ(context, *returned_context);
break;
}
case UR_MEM_INFO_SIZE: {
auto returned_size = reinterpret_cast<size_t *>(info_data.data());
ASSERT_GE(*returned_size, allocation_size);
break;
}
case UR_MEM_INFO_REFERENCE_COUNT: {
const size_t ReferenceCount =
*reinterpret_cast<const uint32_t *>(info_data.data());
ASSERT_GT(ReferenceCount, 0);
break;
}
default:
break;
}
}

using urMemGetInfoTest = uur::urMemBufferTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urMemGetInfoTest);

TEST_P(urMemGetInfoTest, SuccessSize) {
ur_mem_info_t info_type = UR_MEM_INFO_SIZE;
size_t size = 0;

ASSERT_SUCCESS(urMemGetInfo(buffer, info_type, 0, nullptr, &size));
ASSERT_EQ(size, sizeof(size_t));

size_t returned_size = 0;
ASSERT_SUCCESS(
urMemGetInfo(buffer, info_type, size, &returned_size, nullptr));

ASSERT_GE(returned_size, allocation_size);
}

TEST_P(urMemGetInfoTest, SuccessContext) {
ur_mem_info_t info_type = UR_MEM_INFO_CONTEXT;
size_t size = 0;

ASSERT_SUCCESS(urMemGetInfo(buffer, info_type, 0, nullptr, &size));
ASSERT_EQ(size, sizeof(ur_context_handle_t));

ur_context_handle_t returned_context = nullptr;
ASSERT_SUCCESS(
urMemGetInfo(buffer, info_type, size, &returned_context, nullptr));

ASSERT_EQ(context, returned_context);
}

TEST_P(urMemGetInfoTest, SuccessReferenceCount) {
ur_mem_info_t info_type = UR_MEM_INFO_REFERENCE_COUNT;
size_t size = 0;

ASSERT_SUCCESS(urMemGetInfo(buffer, info_type, 0, nullptr, &size));
ASSERT_EQ(size, sizeof(uint32_t));

uint32_t returned_reference_count = 0;
ASSERT_SUCCESS(urMemGetInfo(buffer, info_type, size,
&returned_reference_count, nullptr));

ASSERT_GT(returned_reference_count, 0);
}

TEST_P(urMemGetInfoTest, InvalidNullHandleMemory) {
size_t mem_size = 0;
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
Expand Down Expand Up @@ -102,48 +92,52 @@ TEST_P(urMemGetInfoTest, InvalidNullPointerPropSizeRet) {
UR_RESULT_ERROR_INVALID_NULL_POINTER);
}

using urMemGetInfoImageTest = uur::urMemImageTestWithParam<ur_mem_info_t>;
UUR_TEST_SUITE_P(urMemGetInfoImageTest, ::testing::ValuesIn(mem_info_values),
uur::deviceTestWithParamPrinter<ur_mem_info_t>);

TEST_P(urMemGetInfoImageTest, Success) {
ur_mem_info_t info = getParam();
size_t size;
ASSERT_SUCCESS(urMemGetInfo(image, info, 0, nullptr, &size));
ASSERT_NE(size, 0);

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

std::vector<uint8_t> info_data(size);
ASSERT_SUCCESS(urMemGetInfo(image, info, size, info_data.data(), nullptr));

switch (info) {
case UR_MEM_INFO_SIZE: {
const size_t ExpectedPixelSize = sizeof(float) * 4 /*NumChannels*/;
const size_t ExpectedImageSize = ExpectedPixelSize * desc.arraySize *
desc.width * desc.height * desc.depth;
const size_t ImageSizeBytes =
*reinterpret_cast<const size_t *>(info_data.data());
ASSERT_EQ(ImageSizeBytes, ExpectedImageSize);
break;
}
case UR_MEM_INFO_CONTEXT: {
ur_context_handle_t InfoContext =
*reinterpret_cast<ur_context_handle_t *>(info_data.data());
ASSERT_EQ(InfoContext, context);
break;
}
case UR_MEM_INFO_REFERENCE_COUNT: {
const size_t ReferenceCount =
*reinterpret_cast<const uint32_t *>(info_data.data());
ASSERT_GT(ReferenceCount, 0);
break;
}

default:
break;
}
using urMemGetInfoImageTest = uur::urMemImageTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urMemGetInfoImageTest);

TEST_P(urMemGetInfoImageTest, SuccessSize) {
ur_mem_info_t info_type = UR_MEM_INFO_SIZE;
size_t size = 0;

ASSERT_SUCCESS(urMemGetInfo(image, info_type, 0, nullptr, &size));
ASSERT_EQ(size, sizeof(size_t));

size_t image_size_bytes = 0;
ASSERT_SUCCESS(
urMemGetInfo(image, info_type, size, &image_size_bytes, nullptr));

const size_t expected_pixel_size = sizeof(uint8_t) * 4;
const size_t expected_image_size = expected_pixel_size *
image_desc.arraySize * image_desc.width *
image_desc.height * image_desc.depth;

ASSERT_EQ(image_size_bytes, expected_image_size);
}

TEST_P(urMemGetInfoImageTest, SuccessContext) {
ur_mem_info_t info_type = UR_MEM_INFO_CONTEXT;
size_t size = 0;

ASSERT_SUCCESS(urMemGetInfo(image, info_type, 0, nullptr, &size));
ASSERT_EQ(size, sizeof(ur_context_handle_t));

ur_context_handle_t returned_context = nullptr;
ASSERT_SUCCESS(
urMemGetInfo(image, info_type, size, &returned_context, nullptr));

ASSERT_EQ(context, returned_context);
}

TEST_P(urMemGetInfoImageTest, SuccessReferenceCount) {
ur_mem_info_t info_type = UR_MEM_INFO_REFERENCE_COUNT;
size_t size = 0;

ASSERT_SUCCESS(urMemGetInfo(image, info_type, 0, nullptr, &size));
ASSERT_EQ(size, sizeof(uint32_t));

uint32_t returned_reference_count = 0;
ASSERT_SUCCESS(urMemGetInfo(image, info_type, size,
&returned_reference_count, nullptr));

ASSERT_GT(returned_reference_count, 0);
}
Loading
Loading