From 7685c9c46a52cb267d8b1afff0d5f2049bb3d02e Mon Sep 17 00:00:00 2001 From: Mirza Halilcevic Date: Sat, 9 Dec 2023 00:57:19 +0530 Subject: [PATCH] EXSWHTEC-363 - Implement tests for Surface Management APIs (#439) Change-Id: If354846b04fb48974cd0345f3a317e52b046014f --- catch/include/hip_test_defgroups.hh | 7 ++ catch/unit/surface/CMakeLists.txt | 2 + catch/unit/surface/hipCreateSurfaceObject.cc | 85 +++++++++++++++++++ catch/unit/surface/hipDestroySurfaceObject.cc | 66 ++++++++++++++ 4 files changed, 160 insertions(+) create mode 100644 catch/unit/surface/hipCreateSurfaceObject.cc create mode 100644 catch/unit/surface/hipDestroySurfaceObject.cc diff --git a/catch/include/hip_test_defgroups.hh b/catch/include/hip_test_defgroups.hh index 4f61381817..44a0b406f5 100644 --- a/catch/include/hip_test_defgroups.hh +++ b/catch/include/hip_test_defgroups.hh @@ -186,3 +186,10 @@ THE SOFTWARE. * This section describes the various Printf use case Scenarios. * @} */ + +/** + * @defgroup SurfaceTest Surface Management + * @{ + * This section describes tests for the surface management functions of HIP runtime API. + * @} + */ diff --git a/catch/unit/surface/CMakeLists.txt b/catch/unit/surface/CMakeLists.txt index 4bc01e0794..d2afb5c702 100644 --- a/catch/unit/surface/CMakeLists.txt +++ b/catch/unit/surface/CMakeLists.txt @@ -23,6 +23,8 @@ set(TEST_SRC hipSurfaceObj1D.cc hipSurfaceObj2D.cc hipSurfaceObj3D.cc + hipCreateSurfaceObject.cc + hipDestroySurfaceObject.cc ) hip_add_exe_to_target(NAME SurfaceTest diff --git a/catch/unit/surface/hipCreateSurfaceObject.cc b/catch/unit/surface/hipCreateSurfaceObject.cc new file mode 100644 index 0000000000..7fcb341385 --- /dev/null +++ b/catch/unit/surface/hipCreateSurfaceObject.cc @@ -0,0 +1,85 @@ +/* +Copyright (c) 2023 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 + +/** + * @addtogroup hipCreateSurfaceObject hipCreateSurfaceObject + * @{ + * @ingroup SurfaceTest + */ + +/** + * Test Description + * ------------------------ + * - Negative parameters test for `hipCreateSurfaceObject`. + * Test source + * ------------------------ + * - unit/texture/hipCreateSurfaceObject.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEST_CASE("Unit_hipCreateSurfaceObject_Negative_Parameters") { + hipArray_t array; + hipChannelFormatDesc desc = hipCreateChannelDesc(); + + HIP_CHECK(hipMallocArray(&array, &desc, 64, 0, hipArraySurfaceLoadStore)); + + hipSurfaceObject_t surf; + + hipResourceDesc resc = {}; + resc.resType = hipResourceTypeArray; + resc.res.array.array = array; + + SECTION("pSurfObject is nullptr") { + HIP_CHECK_ERROR(hipCreateSurfaceObject(nullptr, &resc), hipErrorInvalidValue); + } + + SECTION("pResDesc is nullptr") { + HIP_CHECK_ERROR(hipCreateSurfaceObject(&surf, nullptr), hipErrorInvalidValue); + } + + SECTION("invalid resource type") { + resc.resType = hipResourceTypeLinear; + HIP_CHECK_ERROR(hipCreateSurfaceObject(&surf, &resc), hipErrorInvalidValue); + } + +#if HT_NVIDIA // DIsalbed due to defect EXSWHTEC-366 + SECTION("array handle is nullptr") { + resc.res.array.array = nullptr; + HIP_CHECK_ERROR(hipCreateSurfaceObject(&surf, &resc), hipErrorInvalidHandle); + } +#endif + +#if HT_NVIDIA // Disalbed due to defect EXSWHTEC-367 + SECTION("freed array handle") { + hipArray_t invalid_array; + HIP_CHECK(hipMallocArray(&invalid_array, &desc, 64, 0, hipArraySurfaceLoadStore)); + HIP_CHECK(hipFreeArray(invalid_array)); + resc.res.array.array = invalid_array; + HIP_CHECK_ERROR(hipCreateSurfaceObject(&surf, &resc), hipErrorContextIsDestroyed); + } +#endif + + HIP_CHECK(hipFreeArray(array)); +} \ No newline at end of file diff --git a/catch/unit/surface/hipDestroySurfaceObject.cc b/catch/unit/surface/hipDestroySurfaceObject.cc new file mode 100644 index 0000000000..dc67a24e2a --- /dev/null +++ b/catch/unit/surface/hipDestroySurfaceObject.cc @@ -0,0 +1,66 @@ +/* +Copyright (c) 2023 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 + +/** + * @addtogroup hipDestroySurfaceObject hipDestroySurfaceObject + * @{ + * @ingroup SurfaceTest + */ + +/** + * Test Description + * ------------------------ + * - Negative parameters test for `hipDestroySurfaceObject`. + * Test source + * ------------------------ + * - unit/texture/hipDestroySurfaceObject.cc + * Test requirements + * ------------------------ + * - HIP_VERSION >= 5.7 + */ +TEST_CASE("Unit_hipDestroySurfaceObject_Negative_Parameters") { + SECTION("surfObject is NULL") { + HIP_CHECK(hipDestroySurfaceObject(static_cast(0))); + } + + SECTION("double free") { + hipArray_t array; + hipChannelFormatDesc desc = hipCreateChannelDesc(); + + HIP_CHECK(hipMallocArray(&array, &desc, 64, 0, hipArraySurfaceLoadStore)); + + hipSurfaceObject_t surf; + + hipResourceDesc resc = {}; + resc.resType = hipResourceTypeArray; + resc.res.array.array = array; + + HIP_CHECK(hipCreateSurfaceObject(&surf, &resc)); + + HIP_CHECK(hipDestroySurfaceObject(surf)); + HIP_CHECK_ERROR(hipDestroySurfaceObject(surf), hipErrorInvalidValue); + + HIP_CHECK(hipFreeArray(array)); + } +} \ No newline at end of file