From e6a50d060cf835bd867eb714ad7519e1ec9b7382 Mon Sep 17 00:00:00 2001 From: Martin Morrison-Grant Date: Thu, 9 Jan 2025 09:59:49 +0000 Subject: [PATCH] Move urUSMGetMemAlloc/PoolGetInfo success test from a switch to individual tests. --- .../testing/include/uur/fixtures.h | 3 + test/conformance/usm/urUSMGetMemAllocInfo.cpp | 191 ++++++++++-------- test/conformance/usm/urUSMPoolGetInfo.cpp | 53 ++--- 3 files changed, 134 insertions(+), 113 deletions(-) diff --git a/test/conformance/testing/include/uur/fixtures.h b/test/conformance/testing/include/uur/fixtures.h index 80bbff6d49..76ea7f4abf 100644 --- a/test/conformance/testing/include/uur/fixtures.h +++ b/test/conformance/testing/include/uur/fixtures.h @@ -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)); diff --git a/test/conformance/usm/urUSMGetMemAllocInfo.cpp b/test/conformance/usm/urUSMGetMemAllocInfo.cpp index 3e45443672..4a24ad6806 100644 --- a/test/conformance/usm/urUSMGetMemAllocInfo.cpp +++ b/test/conformance/usm/urUSMGetMemAllocInfo.cpp @@ -6,7 +6,7 @@ #include #include -struct urUSMGetMemAllocInfoTest +struct urUSMGetMemAllocInfoPoolTest : uur::urUSMDeviceAllocTestWithParam { void SetUp() override { // The setup for the parent fixture does a urQueueFlush, which isn't @@ -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); -static std::unordered_map 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 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(info_data.data()); - ASSERT_EQ(*returned_device, device); - break; - } - case UR_USM_ALLOC_INFO_SIZE: { - auto returned_size = reinterpret_cast(info_data.data()); - ASSERT_GE(*returned_size, allocation_size); - break; - } - case UR_USM_ALLOC_INFO_BASE_PTR: { - auto returned_ptr = reinterpret_cast(info_data.data()); - ASSERT_EQ(*returned_ptr, ptr); - break; - } - case UR_USM_ALLOC_INFO_POOL: { - auto returned_pool = - reinterpret_cast(info_data.data()); - ASSERT_EQ(*returned_pool, pool); - break; - } - case UR_USM_ALLOC_INFO_TYPE: { - auto returned_type = - reinterpret_cast(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, diff --git a/test/conformance/usm/urUSMPoolGetInfo.cpp b/test/conformance/usm/urUSMPoolGetInfo.cpp index 5cf1daa8f2..d1f616710e 100644 --- a/test/conformance/usm/urUSMPoolGetInfo.cpp +++ b/test/conformance/usm/urUSMPoolGetInfo.cpp @@ -3,41 +3,42 @@ // See LICENSE.TXT // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception #include "ur_api.h" -#include #include -std::unordered_map 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; +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); +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 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;