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 urUSMGetMemAlloc/PoolGetInfo success test from a switch to indivual tests #2538

Merged
merged 1 commit into from
Jan 16, 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
3 changes: 3 additions & 0 deletions test/conformance/testing/include/uur/fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,9 @@ struct urMultiDeviceMemImageWriteTest : urMultiDeviceMemImageQueueTest {

struct urUSMDeviceAllocTest : urQueueTest {
void SetUp() override {
// urQueueFlush is not supported by native cpu.
UUR_KNOWN_FAILURE_ON(uur::NativeCPU{});

UUR_RETURN_ON_FATAL_FAILURE(uur::urQueueTest::SetUp());
ur_device_usm_access_capability_flags_t device_usm = 0;
ASSERT_SUCCESS(GetDeviceUSMDeviceSupport(device, device_usm));
Expand Down
191 changes: 104 additions & 87 deletions test/conformance/usm/urUSMGetMemAllocInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <uur/fixtures.h>
#include <uur/known_failure.h>

struct urUSMGetMemAllocInfoTest
struct urUSMGetMemAllocInfoPoolTest
: uur::urUSMDeviceAllocTestWithParam<ur_usm_alloc_info_t> {
void SetUp() override {
// The setup for the parent fixture does a urQueueFlush, which isn't
Expand All @@ -19,125 +19,142 @@ struct urUSMGetMemAllocInfoTest
}
};

UUR_DEVICE_TEST_SUITE_P(urUSMGetMemAllocInfoTest,
::testing::Values(UR_USM_ALLOC_INFO_TYPE,
UR_USM_ALLOC_INFO_BASE_PTR,
UR_USM_ALLOC_INFO_SIZE,
UR_USM_ALLOC_INFO_DEVICE,
UR_USM_ALLOC_INFO_POOL),
UUR_DEVICE_TEST_SUITE_P(urUSMGetMemAllocInfoPoolTest,
::testing::Values(UR_USM_ALLOC_INFO_POOL),
uur::deviceTestWithParamPrinter<ur_usm_alloc_info_t>);

static std::unordered_map<ur_usm_alloc_info_t, size_t> usm_info_size_map = {
{UR_USM_ALLOC_INFO_TYPE, sizeof(ur_usm_type_t)},
{UR_USM_ALLOC_INFO_BASE_PTR, sizeof(void *)},
{UR_USM_ALLOC_INFO_SIZE, sizeof(size_t)},
{UR_USM_ALLOC_INFO_DEVICE, sizeof(ur_device_handle_t)},
{UR_USM_ALLOC_INFO_POOL, sizeof(ur_usm_pool_handle_t)},
};
TEST_P(urUSMGetMemAllocInfoPoolTest, SuccessPool) {
UUR_KNOWN_FAILURE_ON(uur::OpenCL{}, uur::LevelZeroV2{});

TEST_P(urUSMGetMemAllocInfoTest, Success) {
size_t size = 0;
auto alloc_info = getParam();
size_t property_size = 0;
ur_usm_alloc_info_t property_name = UR_USM_ALLOC_INFO_POOL;

if (alloc_info == UR_USM_ALLOC_INFO_POOL) {
UUR_KNOWN_FAILURE_ON(uur::OpenCL{}, uur::LevelZeroV2{});
}
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urUSMGetMemAllocInfo(context, ptr, property_name, 0, nullptr,
&property_size),
property_name);
ASSERT_EQ(sizeof(ur_usm_pool_handle_t), property_size);

if (alloc_info == UR_USM_ALLOC_INFO_BASE_PTR) {
UUR_KNOWN_FAILURE_ON(uur::NativeCPU{});
}
ur_usm_pool_handle_t returned_pool = nullptr;
ASSERT_SUCCESS(urUSMGetMemAllocInfo(
context, ptr, property_name, property_size, &returned_pool, nullptr));

ASSERT_EQ(returned_pool, pool);
}

using urUSMGetMemAllocInfoTest = uur::urUSMDeviceAllocTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urUSMGetMemAllocInfoTest);

TEST_P(urUSMGetMemAllocInfoTest, SuccessType) {
UUR_KNOWN_FAILURE_ON(uur::NativeCPU{});

size_t property_size = 0;
ur_usm_alloc_info_t property_name = UR_USM_ALLOC_INFO_TYPE;

ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urUSMGetMemAllocInfo(context, ptr, alloc_info, 0, nullptr, &size),
alloc_info);
ASSERT_NE(size, 0);
urUSMGetMemAllocInfo(context, ptr, property_name, 0, nullptr,
&property_size),
property_name);
ASSERT_EQ(sizeof(ur_usm_type_t), property_size);

if (const auto expected_size = usm_info_size_map.find(alloc_info);
expected_size != usm_info_size_map.end()) {
ASSERT_EQ(expected_size->second, size);
}
ur_usm_type_t returned_type = UR_USM_TYPE_FORCE_UINT32;
ASSERT_SUCCESS(urUSMGetMemAllocInfo(
context, ptr, property_name, property_size, &returned_type, nullptr));

std::vector<uint8_t> info_data(size);
ASSERT_SUCCESS(urUSMGetMemAllocInfo(context, ptr, alloc_info, size,
info_data.data(), nullptr));
switch (alloc_info) {
case UR_USM_ALLOC_INFO_DEVICE: {
auto returned_device =
reinterpret_cast<ur_device_handle_t *>(info_data.data());
ASSERT_EQ(*returned_device, device);
break;
}
case UR_USM_ALLOC_INFO_SIZE: {
auto returned_size = reinterpret_cast<size_t *>(info_data.data());
ASSERT_GE(*returned_size, allocation_size);
break;
}
case UR_USM_ALLOC_INFO_BASE_PTR: {
auto returned_ptr = reinterpret_cast<void **>(info_data.data());
ASSERT_EQ(*returned_ptr, ptr);
break;
}
case UR_USM_ALLOC_INFO_POOL: {
auto returned_pool =
reinterpret_cast<ur_usm_pool_handle_t *>(info_data.data());
ASSERT_EQ(*returned_pool, pool);
break;
}
case UR_USM_ALLOC_INFO_TYPE: {
auto returned_type =
reinterpret_cast<ur_usm_type_t *>(info_data.data());
ASSERT_EQ(*returned_type, UR_USM_TYPE_DEVICE);
break;
}
default:
break;
}
ASSERT_EQ(returned_type, UR_USM_TYPE_DEVICE);
}

struct urUSMGetMemAllocInfoNegativeTest : uur::urUSMDeviceAllocTest {
void SetUp() override {
// The setup for the parent fixture does a urQueueFlush, which isn't
// supported by native cpu.
UUR_KNOWN_FAILURE_ON(uur::NativeCPU{});
UUR_RETURN_ON_FATAL_FAILURE(uur::urUSMDeviceAllocTest::SetUp());
}
};
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urUSMGetMemAllocInfoNegativeTest);
TEST_P(urUSMGetMemAllocInfoTest, SuccessBasePtr) {
UUR_KNOWN_FAILURE_ON(uur::NativeCPU{});

TEST_P(urUSMGetMemAllocInfoNegativeTest, InvalidNullHandleContext) {
size_t property_size = 0;
ur_usm_alloc_info_t property_name = UR_USM_ALLOC_INFO_BASE_PTR;

ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urUSMGetMemAllocInfo(context, ptr, property_name, 0, nullptr,
&property_size),
property_name);
ASSERT_GT(property_size, 0);

void *returned_ptr = nullptr;
ASSERT_SUCCESS(urUSMGetMemAllocInfo(context, ptr, property_name,
property_size, &returned_ptr, nullptr));

ASSERT_EQ(returned_ptr, ptr);
}

TEST_P(urUSMGetMemAllocInfoTest, SuccessSize) {
UUR_KNOWN_FAILURE_ON(uur::NativeCPU{});

ur_usm_type_t USMType;
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urUSMGetMemAllocInfo(nullptr, ptr, UR_USM_ALLOC_INFO_TYPE,
sizeof(ur_usm_type_t), &USMType,
nullptr));
size_t property_size = 0;
ur_usm_alloc_info_t property_name = UR_USM_ALLOC_INFO_SIZE;

ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urUSMGetMemAllocInfo(context, ptr, property_name, 0, nullptr,
&property_size),
property_name);
ASSERT_EQ(sizeof(size_t), property_size);

size_t returned_size = 0;
ASSERT_SUCCESS(urUSMGetMemAllocInfo(
context, ptr, property_name, property_size, &returned_size, nullptr));

ASSERT_GE(returned_size, allocation_size);
}

TEST_P(urUSMGetMemAllocInfoTest, SuccessDevice) {
UUR_KNOWN_FAILURE_ON(uur::NativeCPU{});

size_t property_size = 0;
ur_usm_alloc_info_t property_name = UR_USM_ALLOC_INFO_DEVICE;

ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urUSMGetMemAllocInfo(context, ptr, property_name, 0, nullptr,
&property_size),
property_name);
ASSERT_EQ(sizeof(ur_device_handle_t), property_size);

ur_device_handle_t returned_device = nullptr;
ASSERT_SUCCESS(urUSMGetMemAllocInfo(
context, ptr, property_name, property_size, &returned_device, nullptr));

ASSERT_EQ(returned_device, device);
}

TEST_P(urUSMGetMemAllocInfoTest, InvalidNullHandleContext) {
UUR_KNOWN_FAILURE_ON(uur::NativeCPU{});

ur_usm_type_t USMType = UR_USM_TYPE_FORCE_UINT32;
ASSERT_EQ_RESULT(
UR_RESULT_ERROR_INVALID_NULL_HANDLE,
urUSMGetMemAllocInfo(nullptr, ptr, UR_USM_ALLOC_INFO_FORCE_UINT32,
sizeof(ur_usm_type_t), &USMType, nullptr));
}

TEST_P(urUSMGetMemAllocInfoNegativeTest, InvalidNullPointerMem) {
TEST_P(urUSMGetMemAllocInfoTest, InvalidNullPointerMem) {
UUR_KNOWN_FAILURE_ON(uur::NativeCPU{});

ur_usm_type_t USMType;
ur_usm_type_t USMType = UR_USM_TYPE_FORCE_UINT32;
ASSERT_EQ_RESULT(
UR_RESULT_ERROR_INVALID_NULL_POINTER,
urUSMGetMemAllocInfo(context, nullptr, UR_USM_ALLOC_INFO_TYPE,
urUSMGetMemAllocInfo(context, nullptr, UR_USM_ALLOC_INFO_FORCE_UINT32,
sizeof(ur_usm_type_t), &USMType, nullptr));
}

TEST_P(urUSMGetMemAllocInfoNegativeTest, InvalidEnumeration) {
TEST_P(urUSMGetMemAllocInfoTest, InvalidEnumeration) {
UUR_KNOWN_FAILURE_ON(uur::NativeCPU{});

ur_usm_type_t USMType;
ur_usm_type_t USMType = UR_USM_TYPE_FORCE_UINT32;
ASSERT_EQ_RESULT(
UR_RESULT_ERROR_INVALID_ENUMERATION,
urUSMGetMemAllocInfo(context, ptr, UR_USM_ALLOC_INFO_FORCE_UINT32,
sizeof(ur_usm_type_t), &USMType, nullptr));
}

TEST_P(urUSMGetMemAllocInfoNegativeTest, InvalidValuePropSize) {
TEST_P(urUSMGetMemAllocInfoTest, InvalidValuePropSize) {
UUR_KNOWN_FAILURE_ON(uur::NativeCPU{});

ur_usm_type_t USMType;
ur_usm_type_t USMType = UR_USM_TYPE_FORCE_UINT32;
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
urUSMGetMemAllocInfo(context, ptr, UR_USM_ALLOC_INFO_TYPE,
sizeof(ur_usm_type_t) - 1, &USMType,
Expand Down
53 changes: 27 additions & 26 deletions test/conformance/usm/urUSMPoolGetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,42 @@
// See LICENSE.TXT
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "ur_api.h"
#include <map>
#include <uur/fixtures.h>

std::unordered_map<ur_usm_pool_info_t, size_t> pool_info_size_map = {
{UR_USM_POOL_INFO_CONTEXT, sizeof(ur_context_handle_t)},
{UR_USM_POOL_INFO_REFERENCE_COUNT, sizeof(uint32_t)},
};

using urUSMPoolGetInfoTestWithInfoParam =
uur::urUSMPoolTestWithParam<ur_usm_pool_info_t>;
using urUSMPoolGetInfoTest = uur::urUSMPoolTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urUSMPoolGetInfoTest);

UUR_DEVICE_TEST_SUITE_P(urUSMPoolGetInfoTestWithInfoParam,
::testing::Values(UR_USM_POOL_INFO_CONTEXT,
UR_USM_POOL_INFO_REFERENCE_COUNT),
uur::deviceTestWithParamPrinter<ur_usm_pool_info_t>);
TEST_P(urUSMPoolGetInfoTest, SuccessReferenceCount) {
size_t property_size = 0;
ur_usm_pool_info_t property_name = UR_USM_POOL_INFO_REFERENCE_COUNT;

TEST_P(urUSMPoolGetInfoTestWithInfoParam, Success) {
ur_usm_pool_info_t info_type = getParam();
size_t size = 0;
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urUSMPoolGetInfo(pool, info_type, 0, nullptr, &size), info_type);
ASSERT_NE(size, 0);
urUSMPoolGetInfo(pool, property_name, 0, nullptr, &property_size),
property_name);
ASSERT_EQ(sizeof(uint32_t), property_size);

if (const auto expected_size = pool_info_size_map.find(info_type);
expected_size != pool_info_size_map.end()) {
ASSERT_EQ(expected_size->second, size);
}
uint32_t returned_reference_count = 0;
ASSERT_SUCCESS(urUSMPoolGetInfo(pool, property_name, property_size,
&returned_reference_count, nullptr));

std::vector<uint8_t> data(size);
ASSERT_SUCCESS(
urUSMPoolGetInfo(pool, info_type, size, data.data(), nullptr));
ASSERT_GT(returned_reference_count, 0U);
}

using urUSMPoolGetInfoTest = uur::urUSMPoolTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urUSMPoolGetInfoTest);
TEST_P(urUSMPoolGetInfoTest, SuccessContext) {
size_t property_size = 0;
ur_usm_pool_info_t property_name = UR_USM_POOL_INFO_CONTEXT;

ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urUSMPoolGetInfo(pool, property_name, 0, nullptr, &property_size),
property_name);
ASSERT_EQ(sizeof(ur_context_handle_t), property_size);

ur_context_handle_t returned_context = nullptr;
ASSERT_SUCCESS(urUSMPoolGetInfo(pool, property_name, property_size,
&returned_context, nullptr));

ASSERT_EQ(context, returned_context);
}

TEST_P(urUSMPoolGetInfoTest, InvalidNullHandlePool) {
ur_context_handle_t context = nullptr;
Expand Down
Loading