From 3328f87ec0261d65c2f6fcacf3df915b68c79a5a Mon Sep 17 00:00:00 2001 From: Callum Fare Date: Fri, 23 Jun 2023 14:10:44 +0100 Subject: [PATCH] [UR][CTS] Add urMemImageGetInfo tests and add missing return values to spec --- include/ur_api.h | 11 +++ scripts/core/memory.yml | 12 +++ source/loader/layers/validation/ur_valddi.cpp | 12 +++ source/loader/ur_libapi.cpp | 11 +++ source/ur_api.cpp | 11 +++ test/conformance/memory/urMemImageGetInfo.cpp | 82 +++++++++++++++++++ .../testing/include/uur/fixtures.h | 30 +++++++ 7 files changed, 169 insertions(+) diff --git a/include/ur_api.h b/include/ur_api.h index a719fce5ee..bc8f1fb82f 100644 --- a/include/ur_api.h +++ b/include/ur_api.h @@ -2289,6 +2289,17 @@ urMemGetInfo( /// + `NULL == hMemory` /// - ::UR_RESULT_ERROR_INVALID_ENUMERATION /// + `::UR_IMAGE_INFO_DEPTH < propName` +/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION +/// + If `propName` is not supported by the adapter. +/// - ::UR_RESULT_ERROR_INVALID_SIZE +/// + `propSize == 0 && pPropValue != NULL` +/// + If `propSize` is less than the real number of bytes needed to return the info. +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `propSize != 0 && pPropValue == NULL` +/// + `pPropValue == NULL && pPropSizeRet == NULL` +/// - ::UR_RESULT_ERROR_INVALID_MEM_OBJECT +/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES +/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY UR_APIEXPORT ur_result_t UR_APICALL urMemImageGetInfo( ur_mem_handle_t hMemory, ///< [in] handle to the image object being queried. diff --git a/scripts/core/memory.yml b/scripts/core/memory.yml index b9c3ef1792..e8b190143c 100644 --- a/scripts/core/memory.yml +++ b/scripts/core/memory.yml @@ -577,3 +577,15 @@ params: name: pPropSizeRet desc: | [out][optional] pointer to the actual size in bytes of the queried propName. +returns: + - $X_RESULT_ERROR_UNSUPPORTED_ENUMERATION: + - "If `propName` is not supported by the adapter." + - $X_RESULT_ERROR_INVALID_SIZE: + - "`propSize == 0 && pPropValue != NULL`" + - "If `propSize` is less than the real number of bytes needed to return the info." + - $X_RESULT_ERROR_INVALID_NULL_POINTER: + - "`propSize != 0 && pPropValue == NULL`" + - "`pPropValue == NULL && pPropSizeRet == NULL`" + - $X_RESULT_ERROR_INVALID_MEM_OBJECT + - $X_RESULT_ERROR_OUT_OF_RESOURCES + - $X_RESULT_ERROR_OUT_OF_HOST_MEMORY diff --git a/source/loader/layers/validation/ur_valddi.cpp b/source/loader/layers/validation/ur_valddi.cpp index 6084954b58..c811674e50 100644 --- a/source/loader/layers/validation/ur_valddi.cpp +++ b/source/loader/layers/validation/ur_valddi.cpp @@ -1273,9 +1273,21 @@ __urdlllocal ur_result_t UR_APICALL urMemImageGetInfo( return UR_RESULT_ERROR_INVALID_NULL_HANDLE; } + if (propSize != 0 && pPropValue == NULL) { + return UR_RESULT_ERROR_INVALID_NULL_POINTER; + } + + if (pPropValue == NULL && pPropSizeRet == NULL) { + return UR_RESULT_ERROR_INVALID_NULL_POINTER; + } + if (UR_IMAGE_INFO_DEPTH < propName) { return UR_RESULT_ERROR_INVALID_ENUMERATION; } + + if (propSize == 0 && pPropValue != NULL) { + return UR_RESULT_ERROR_INVALID_SIZE; + } } ur_result_t result = diff --git a/source/loader/ur_libapi.cpp b/source/loader/ur_libapi.cpp index 43a81e4a47..a3c87d8a01 100644 --- a/source/loader/ur_libapi.cpp +++ b/source/loader/ur_libapi.cpp @@ -1488,6 +1488,17 @@ ur_result_t UR_APICALL urMemGetInfo( /// + `NULL == hMemory` /// - ::UR_RESULT_ERROR_INVALID_ENUMERATION /// + `::UR_IMAGE_INFO_DEPTH < propName` +/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION +/// + If `propName` is not supported by the adapter. +/// - ::UR_RESULT_ERROR_INVALID_SIZE +/// + `propSize == 0 && pPropValue != NULL` +/// + If `propSize` is less than the real number of bytes needed to return the info. +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `propSize != 0 && pPropValue == NULL` +/// + `pPropValue == NULL && pPropSizeRet == NULL` +/// - ::UR_RESULT_ERROR_INVALID_MEM_OBJECT +/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES +/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY ur_result_t UR_APICALL urMemImageGetInfo( ur_mem_handle_t hMemory, ///< [in] handle to the image object being queried. ur_image_info_t propName, ///< [in] type of image info to retrieve. diff --git a/source/ur_api.cpp b/source/ur_api.cpp index 3843c20dca..ecd6555a96 100644 --- a/source/ur_api.cpp +++ b/source/ur_api.cpp @@ -1252,6 +1252,17 @@ ur_result_t UR_APICALL urMemGetInfo( /// + `NULL == hMemory` /// - ::UR_RESULT_ERROR_INVALID_ENUMERATION /// + `::UR_IMAGE_INFO_DEPTH < propName` +/// - ::UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION +/// + If `propName` is not supported by the adapter. +/// - ::UR_RESULT_ERROR_INVALID_SIZE +/// + `propSize == 0 && pPropValue != NULL` +/// + If `propSize` is less than the real number of bytes needed to return the info. +/// - ::UR_RESULT_ERROR_INVALID_NULL_POINTER +/// + `propSize != 0 && pPropValue == NULL` +/// + `pPropValue == NULL && pPropSizeRet == NULL` +/// - ::UR_RESULT_ERROR_INVALID_MEM_OBJECT +/// - ::UR_RESULT_ERROR_OUT_OF_RESOURCES +/// - ::UR_RESULT_ERROR_OUT_OF_HOST_MEMORY ur_result_t UR_APICALL urMemImageGetInfo( ur_mem_handle_t hMemory, ///< [in] handle to the image object being queried. ur_image_info_t propName, ///< [in] type of image info to retrieve. diff --git a/test/conformance/memory/urMemImageGetInfo.cpp b/test/conformance/memory/urMemImageGetInfo.cpp index 281aa8badb..48e6d6274f 100644 --- a/test/conformance/memory/urMemImageGetInfo.cpp +++ b/test/conformance/memory/urMemImageGetInfo.cpp @@ -2,3 +2,85 @@ // Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. // See LICENSE.TXT // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +#include + +using urMemImageGetInfoTest = uur::urMemImageTestWithParam; + +static std::unordered_map image_info_size_map = { + {UR_IMAGE_INFO_FORMAT, sizeof(ur_image_format_t)}, + {UR_IMAGE_INFO_ELEMENT_SIZE, sizeof(size_t)}, + {UR_IMAGE_INFO_ROW_PITCH, sizeof(size_t)}, + {UR_IMAGE_INFO_SLICE_PITCH, sizeof(size_t)}, + {UR_IMAGE_INFO_WIDTH, sizeof(size_t)}, + {UR_IMAGE_INFO_HEIGHT, sizeof(size_t)}, + {UR_IMAGE_INFO_DEPTH, sizeof(size_t)}, +}; + +UUR_TEST_SUITE_P(urMemImageGetInfoTest, + ::testing::Values(UR_IMAGE_INFO_FORMAT, + UR_IMAGE_INFO_ELEMENT_SIZE, + UR_IMAGE_INFO_ROW_PITCH, + UR_IMAGE_INFO_SLICE_PITCH, + UR_IMAGE_INFO_WIDTH, UR_IMAGE_INFO_HEIGHT, + UR_IMAGE_INFO_DEPTH), + uur::deviceTestWithParamPrinter); + +TEST_P(urMemImageGetInfoTest, Success) { + ur_image_info_t info = getParam(); + size_t size; + ASSERT_SUCCESS(urMemImageGetInfo(image, info, 0, nullptr, &size)); + ASSERT_NE(size, 0); + + if (const auto expected_size = image_info_size_map.find(info); + expected_size != image_info_size_map.end()) { + ASSERT_EQ(expected_size->second, size); + } else { + FAIL() << "Missing info value in image info size map"; + } + + std::vector info_data(size); + ASSERT_SUCCESS( + urMemImageGetInfo(image, info, size, info_data.data(), nullptr)); +} + +TEST_P(urMemImageGetInfoTest, InvalidNullHandleImage) { + size_t info_size = 0; + ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_NULL_HANDLE, + urMemImageGetInfo(nullptr, UR_IMAGE_INFO_FORMAT, + sizeof(size_t), &info_size, nullptr)); +} + +TEST_P(urMemImageGetInfoTest, InvalidEnumerationImageInfoType) { + size_t info_size = 0; + ASSERT_EQ_RESULT(UR_RESULT_ERROR_INVALID_ENUMERATION, + urMemImageGetInfo(image, UR_IMAGE_INFO_FORCE_UINT32, + sizeof(size_t), &info_size, nullptr)); +} + +TEST_P(urMemImageGetInfoTest, InvalidSizeZero) { + size_t info_size = 0; + ASSERT_EQ_RESULT( + urMemImageGetInfo(image, UR_IMAGE_INFO_FORMAT, 0, &info_size, nullptr), + UR_RESULT_ERROR_INVALID_SIZE); +} + +TEST_P(urMemImageGetInfoTest, InvalidSizeSmall) { + int info_size = 0; + ASSERT_EQ_RESULT(urMemImageGetInfo(image, UR_IMAGE_INFO_FORMAT, + sizeof(info_size) - 1, &info_size, + nullptr), + UR_RESULT_ERROR_INVALID_SIZE); +} + +TEST_P(urMemImageGetInfoTest, InvalidNullPointerParamValue) { + size_t info_size = 0; + ASSERT_EQ_RESULT(urMemImageGetInfo(image, UR_IMAGE_INFO_FORMAT, + sizeof(info_size), nullptr, nullptr), + UR_RESULT_ERROR_INVALID_NULL_POINTER); +} + +TEST_P(urMemImageGetInfoTest, InvalidNullPointerPropSizeRet) { + ASSERT_EQ_RESULT( + urMemImageGetInfo(image, UR_IMAGE_INFO_FORMAT, 0, nullptr, nullptr), + UR_RESULT_ERROR_INVALID_NULL_POINTER); +} diff --git a/test/conformance/testing/include/uur/fixtures.h b/test/conformance/testing/include/uur/fixtures.h index 8c7adcd2e9..f2a9719537 100644 --- a/test/conformance/testing/include/uur/fixtures.h +++ b/test/conformance/testing/include/uur/fixtures.h @@ -244,6 +244,36 @@ template struct urMemBufferTestWithParam : urContextTestWithParam { ur_mem_handle_t buffer = nullptr; }; +template struct urMemImageTestWithParam : urContextTestWithParam { + void SetUp() override { + UUR_RETURN_ON_FATAL_FAILURE(urContextTestWithParam::SetUp()); + ASSERT_SUCCESS(urMemImageCreate(this->context, UR_MEM_FLAG_READ_WRITE, + &format, &desc, nullptr, &image)); + ASSERT_NE(nullptr, image); + } + + void TearDown() override { + if (image) { + EXPECT_SUCCESS(urMemRelease(image)); + } + UUR_RETURN_ON_FATAL_FAILURE(urContextTestWithParam::TearDown()); + } + ur_mem_handle_t image = nullptr; + ur_image_format_t format = {UR_IMAGE_CHANNEL_ORDER_RGBA, + UR_IMAGE_CHANNEL_TYPE_FLOAT}; + ur_image_desc_t desc = {UR_STRUCTURE_TYPE_IMAGE_DESC, // stype + nullptr, // pNext + UR_MEM_TYPE_IMAGE1D, // mem object type + 1024, // image width + 1, // image height + 1, // image depth + 1, // array size + 0, // row pitch + 0, // slice pitch + 0, // mip levels + 0}; // num samples +}; + struct urQueueTest : urContextTest { void SetUp() override { UUR_RETURN_ON_FATAL_FAILURE(urContextTest::SetUp());