Skip to content

Commit

Permalink
Move urUSMGetMemAlloc/PoolGetInfo success test from a switch to indiv…
Browse files Browse the repository at this point in the history
…idual tests.
  • Loading branch information
martygrant committed Jan 9, 2025
1 parent 1918293 commit 71d0628
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 104 deletions.
140 changes: 74 additions & 66 deletions test/conformance/usm/urUSMGetMemAllocInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <uur/fixtures.h>

struct urUSMGetMemAllocInfoTest
struct urUSMGetMemAllocInfoPoolTest
: uur::urUSMDeviceAllocTestWithParam<ur_usm_alloc_info_t> {
void SetUp() override {
use_pool = getParam() == UR_USM_ALLOC_INFO_POOL;
Expand All @@ -14,100 +14,108 @@ struct urUSMGetMemAllocInfoTest
}
};

UUR_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_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) {
size_t size = 0;
auto info_type = UR_USM_ALLOC_INFO_POOL;
ASSERT_SUCCESS(
urUSMGetMemAllocInfo(context, ptr, info_type, 0, nullptr, &size));
ASSERT_EQ(sizeof(ur_usm_pool_handle_t), size);

TEST_P(urUSMGetMemAllocInfoTest, Success) {
ur_usm_pool_handle_t returned_pool = nullptr;
ASSERT_SUCCESS(urUSMGetMemAllocInfo(context, ptr, info_type, size,
&returned_pool, nullptr));

ASSERT_EQ(returned_pool, pool);
}

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

TEST_P(urUSMGetMemAllocInfoTest, SuccessType) {
size_t size = 0;
auto alloc_info = getParam();
ASSERT_SUCCESS_OR_OPTIONAL_QUERY(
urUSMGetMemAllocInfo(context, ptr, alloc_info, 0, nullptr, &size),
alloc_info);
ASSERT_NE(size, 0);

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);
}
auto info_type = UR_USM_ALLOC_INFO_TYPE;
ASSERT_SUCCESS(
urUSMGetMemAllocInfo(context, ptr, info_type, 0, nullptr, &size));
ASSERT_EQ(sizeof(ur_usm_type_t), size);

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;
}
ur_usm_type_t returned_type = UR_USM_TYPE_FORCE_UINT32;
ASSERT_SUCCESS(urUSMGetMemAllocInfo(context, ptr, info_type, size,
&returned_type, nullptr));

ASSERT_EQ(returned_type, UR_USM_TYPE_DEVICE);
}

using urUSMGetMemAllocInfoNegativeTest = uur::urUSMDeviceAllocTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urUSMGetMemAllocInfoNegativeTest);
TEST_P(urUSMGetMemAllocInfoTest, SuccessBasePtr) {
size_t size = 0;
auto info_type = UR_USM_ALLOC_INFO_BASE_PTR;
ASSERT_SUCCESS(
urUSMGetMemAllocInfo(context, ptr, info_type, 0, nullptr, &size));
ASSERT_GT(size, 0);

void *returned_ptr = nullptr;
ASSERT_SUCCESS(urUSMGetMemAllocInfo(context, ptr, info_type, size,
&returned_ptr, nullptr));

ASSERT_EQ(returned_ptr, ptr);
}

TEST_P(urUSMGetMemAllocInfoTest, SuccessSize) {
size_t size = 0;
auto info_type = UR_USM_ALLOC_INFO_SIZE;
ASSERT_SUCCESS(
urUSMGetMemAllocInfo(context, ptr, info_type, 0, nullptr, &size));
ASSERT_EQ(sizeof(size_t), size);

size_t returned_size = 0;
ASSERT_SUCCESS(urUSMGetMemAllocInfo(context, ptr, info_type, size,
&returned_size, nullptr));

ASSERT_GE(returned_size, allocation_size);
}

TEST_P(urUSMGetMemAllocInfoTest, SuccessDevice) {
size_t size = 0;
auto info_type = UR_USM_ALLOC_INFO_DEVICE;
ASSERT_SUCCESS(
urUSMGetMemAllocInfo(context, ptr, info_type, 0, nullptr, &size));
ASSERT_EQ(sizeof(ur_device_handle_t), size);

ur_device_handle_t returned_device = nullptr;
ASSERT_SUCCESS(urUSMGetMemAllocInfo(context, ptr, info_type, size,
&returned_device, nullptr));

ASSERT_EQ(returned_device, device);
}

TEST_P(urUSMGetMemAllocInfoNegativeTest, InvalidNullHandleContext) {
TEST_P(urUSMGetMemAllocInfoTest, InvalidNullHandleContext) {
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));
}

TEST_P(urUSMGetMemAllocInfoNegativeTest, InvalidNullPointerMem) {
TEST_P(urUSMGetMemAllocInfoTest, InvalidNullPointerMem) {
ur_usm_type_t USMType;
ASSERT_EQ_RESULT(
UR_RESULT_ERROR_INVALID_NULL_POINTER,
urUSMGetMemAllocInfo(context, nullptr, UR_USM_ALLOC_INFO_TYPE,
sizeof(ur_usm_type_t), &USMType, nullptr));
}

TEST_P(urUSMGetMemAllocInfoNegativeTest, InvalidEnumeration) {
TEST_P(urUSMGetMemAllocInfoTest, InvalidEnumeration) {
ur_usm_type_t USMType;
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) {
ur_usm_type_t USMType;
ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_SIZE,
urUSMGetMemAllocInfo(context, ptr, UR_USM_ALLOC_INFO_TYPE,
Expand Down
47 changes: 21 additions & 26 deletions test/conformance/usm/urUSMPoolGetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,36 @@
// 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 urUSMPoolGetInfoTest = uur::urUSMPoolTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urUSMPoolGetInfoTest);

using urUSMPoolGetInfoTestWithInfoParam =
uur::urUSMPoolTestWithParam<ur_usm_pool_info_t>;
TEST_P(urUSMPoolGetInfoTest, SuccessReferenceCount) {
size_t size = 0;
auto infoType = UR_USM_POOL_INFO_REFERENCE_COUNT;
ASSERT_SUCCESS(urUSMPoolGetInfo(pool, infoType, 0, nullptr, &size));
ASSERT_EQ(sizeof(uint32_t), size);

UUR_TEST_SUITE_P(urUSMPoolGetInfoTestWithInfoParam,
::testing::Values(UR_USM_POOL_INFO_CONTEXT,
UR_USM_POOL_INFO_REFERENCE_COUNT),
uur::deviceTestWithParamPrinter<ur_usm_pool_info_t>);
uint32_t returned_reference_count = 0;
ASSERT_SUCCESS(urUSMPoolGetInfo(pool, infoType, size,
&returned_reference_count, nullptr));

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);
ASSERT_GT(returned_reference_count, 0U);
}

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);
}
TEST_P(urUSMPoolGetInfoTest, SuccessContext) {
size_t size = 0;
auto infoType = UR_USM_POOL_INFO_CONTEXT;
ASSERT_SUCCESS(urUSMPoolGetInfo(pool, infoType, 0, nullptr, &size));
ASSERT_EQ(sizeof(ur_context_handle_t), size);

std::vector<uint8_t> data(size);
ur_context_handle_t returned_context = nullptr;
ASSERT_SUCCESS(
urUSMPoolGetInfo(pool, info_type, size, data.data(), nullptr));
}
urUSMPoolGetInfo(pool, infoType, size, &returned_context, nullptr));

using urUSMPoolGetInfoTest = uur::urUSMPoolTest;
UUR_INSTANTIATE_DEVICE_TEST_SUITE_P(urUSMPoolGetInfoTest);
ASSERT_EQ(context, returned_context);
}

TEST_P(urUSMPoolGetInfoTest, InvalidNullHandlePool) {
ur_context_handle_t context = nullptr;
Expand Down
6 changes: 3 additions & 3 deletions test/conformance/usm/usm_adapter_hip.match
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/*__UsePoolEnabled_32_204
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/*__UsePoolEnabled_64_8
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/*__UsePoolEnabled_64_512
urUSMDeviceAllocAlignmentTest.SuccessAlignedAllocations/*__UsePoolEnabled_64_2048
urUSMGetMemAllocInfoTest.Success/*__UR_USM_ALLOC_INFO_POOL
urUSMGetMemAllocInfoPoolTest.SuccessPool/*
urUSMHostAllocTest.Success/*__UsePoolEnabled
urUSMHostAllocTest.SuccessWithDescriptors/*__UsePoolEnabled
urUSMHostAllocTest.InvalidNullHandleContext/*__UsePoolEnabled
Expand All @@ -46,8 +46,8 @@ urUSMHostAllocAlignmentTest.SuccessAlignedAllocations/*__UsePoolEnabled_64_512
urUSMHostAllocAlignmentTest.SuccessAlignedAllocations/*__UsePoolEnabled_64_2048
urUSMPoolCreateTest.Success/*
urUSMPoolCreateTest.SuccessWithFlag/*
urUSMPoolGetInfoTestWithInfoParam.Success/*__UR_USM_POOL_INFO_CONTEXT
urUSMPoolGetInfoTestWithInfoParam.Success/*__UR_USM_POOL_INFO_REFERENCE_COUNT
urUSMPoolGetInfoTest.SuccessContext/*
urUSMPoolGetInfoTest.SuccessReferenceCount/*
urUSMPoolGetInfoTest.InvalidNullHandlePool/*
urUSMPoolGetInfoTest.InvalidEnumerationProperty/*
urUSMPoolGetInfoTest.InvalidSizeZero/*
Expand Down
2 changes: 1 addition & 1 deletion test/conformance/usm/usm_adapter_level_zero_v2.match
Original file line number Diff line number Diff line change
@@ -1 +1 @@
urUSMGetMemAllocInfoTest.Success/*___UR_USM_ALLOC_INFO_POOL
urUSMGetMemAllocInfoPoolTest.SuccessPool/*
16 changes: 8 additions & 8 deletions test/conformance/usm/usm_adapter_native_cpu.match
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ urUSMFreeTest.SuccessDeviceAlloc/*
urUSMFreeTest.SuccessHostAlloc/*
urUSMFreeTest.SuccessSharedAlloc/*
urUSMFreeDuringExecutionTest.*
urUSMGetMemAllocInfoTest.Success/*__UR_USM_ALLOC_INFO_TYPE
urUSMGetMemAllocInfoTest.Success/*__UR_USM_ALLOC_INFO_BASE_PTR
urUSMGetMemAllocInfoTest.Success/*__UR_USM_ALLOC_INFO_SIZE
urUSMGetMemAllocInfoTest.Success/*__UR_USM_ALLOC_INFO_DEVICE
urUSMGetMemAllocInfoNegativeTest.InvalidNullHandleContext/*
urUSMGetMemAllocInfoNegativeTest.InvalidNullPointerMem/*
urUSMGetMemAllocInfoNegativeTest.InvalidEnumeration/*
urUSMGetMemAllocInfoNegativeTest.InvalidValuePropSize/*
urUSMGetMemAllocInfoTest.SuccessType/*
urUSMGetMemAllocInfoTest.SuccessBasePtr/*
urUSMGetMemAllocInfoTest.SuccessSize/*
urUSMGetMemAllocInfoTest.SuccessDevice/*
urUSMGetMemAllocInfoTest.InvalidNullHandleContext/*
urUSMGetMemAllocInfoTest.InvalidNullPointerMem/*
urUSMGetMemAllocInfoTest.InvalidEnumeration/*
urUSMGetMemAllocInfoTest.InvalidValuePropSize/*
urUSMHostAllocTest.Success/*__UsePoolDisabled
urUSMHostAllocTest.InvalidUSMSize/*__UsePoolDisabled
urUSMSharedAllocTest.InvalidUSMSize/*__UsePoolDisabled

0 comments on commit 71d0628

Please sign in to comment.