From d9162f9abe2ea30e50902406b39c82447b0facca Mon Sep 17 00:00:00 2001 From: Marko Arandjelovic Date: Wed, 24 Jul 2024 11:43:26 +0200 Subject: [PATCH] SWDEV-475382 - Add unit test for hipGetTextureAlignmentOffset Change-Id: I6ec65522038ffc3761970542df4570cead3026fe --- catch/unit/texture/CMakeLists.txt | 1 + .../texture/hipGetTextureAlignmentOffset.cc | 94 +++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 catch/unit/texture/hipGetTextureAlignmentOffset.cc diff --git a/catch/unit/texture/CMakeLists.txt b/catch/unit/texture/CMakeLists.txt index 3d46891494..718e563fc6 100644 --- a/catch/unit/texture/CMakeLists.txt +++ b/catch/unit/texture/CMakeLists.txt @@ -35,6 +35,7 @@ set(TEST_SRC hipBindTex2DPitch.cc hipTex1DFetchCheckModes.cc hipGetChanDesc.cc + hipGetTextureAlignmentOffset.cc hipTexObjPitch.cc hipTexRefSetArray.cc hipTexRefGetArray.cc diff --git a/catch/unit/texture/hipGetTextureAlignmentOffset.cc b/catch/unit/texture/hipGetTextureAlignmentOffset.cc new file mode 100644 index 0000000000..fc13816e7f --- /dev/null +++ b/catch/unit/texture/hipGetTextureAlignmentOffset.cc @@ -0,0 +1,94 @@ +/* +Copyright (c) 2024 Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + +#include + +#if defined(__HIP_PLATFORM_AMD__) || CUDA_VERSION < CUDA_12000 + +texture tex; + +/** + * Test Description + * ------------------------ + * - Positive test for hipGetTextureAlignmentOffset + * - Offset should always be 0 + * Test source + * ------------------------ + * - unit/texture/hipGetTextureAlignmentOffset.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEST_CASE("Unit_hipGetTextureAlignmentOffset_Positive") { + CHECK_IMAGE_SUPPORT + + size_t offset = 0; + size_t *tex_buf; + hipChannelFormatDesc chanDesc = hipCreateChannelDesc(32, 0, 0, 0, hipChannelFormatKindFloat); + + HIP_CHECK(hipMalloc(&tex_buf, 32)); + HIP_CHECK(hipBindTexture(&offset, tex, reinterpret_cast(tex_buf), chanDesc, 32)); + HIP_CHECK(hipGetTextureAlignmentOffset(&offset, &tex)); + REQUIRE(offset == 0); + + HIP_CHECK(hipFree(tex_buf)); + HIP_CHECK(hipUnbindTexture(tex)); +} + +/** + * Test Description + * ------------------------ + * - Negative test for hipGetTextureAlignmentOffset + * - Test should give invalid error if one of params is NULL + * Test source + * ------------------------ + * - unit/texture/hipGetTextureAlignmentOffset.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEST_CASE("Unit_hipGetTextureAlignmentOffset_Negative") { + CHECK_IMAGE_SUPPORT + size_t offset = 0; + size_t *tex_buf; + hipChannelFormatDesc chanDesc = hipCreateChannelDesc(32, 0, 0, 0, hipChannelFormatKindFloat); + + HIP_CHECK(hipMalloc(&tex_buf, 32)); + HIP_CHECK(hipBindTexture(&offset, tex, reinterpret_cast(tex_buf), chanDesc, 32)); + + SECTION("offset is nullptr") { + HIP_CHECK_ERROR(hipGetTextureAlignmentOffset(nullptr, &tex), hipErrorInvalidValue); + } + + SECTION("texture is nullptr") { +#if HT_AMD + HIP_CHECK_ERROR(hipGetTextureAlignmentOffset(&offset, nullptr), hipErrorInvalidValue); +#else + HIP_CHECK_ERROR(hipGetTextureAlignmentOffset(&offset, nullptr), hipErrorInvalidTexture); +#endif + } + + HIP_CHECK(hipFree(tex_buf)); + HIP_CHECK(hipUnbindTexture(tex)); +} + +#endif