From 77b6cb94f5959e06d92c07469579f18fc6d29849 Mon Sep 17 00:00:00 2001 From: music-dino <111048524+music-dino@users.noreply.github.com> Date: Wed, 1 Feb 2023 16:45:05 +0100 Subject: [PATCH] EXSWHTEC-148 - Implement tests for hipImportExternalSemaphore and hipDestroyExternalSemaphore for the Vulkan API (#29) - Basic positive test - Negative parameter tests [ROCm/hip-tests commit: 06726393d4396bea6464090b4f2352a261a65e95] --- .../catch/unit/vulkan_interop/CMakeLists.txt | 2 + .../hipDestroyExternalSemaphore.cc | 40 +++++++++++++ .../hipImportExternalSemaphore.cc | 56 +++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 projects/hip-tests/catch/unit/vulkan_interop/hipDestroyExternalSemaphore.cc create mode 100644 projects/hip-tests/catch/unit/vulkan_interop/hipImportExternalSemaphore.cc diff --git a/projects/hip-tests/catch/unit/vulkan_interop/CMakeLists.txt b/projects/hip-tests/catch/unit/vulkan_interop/CMakeLists.txt index 8ee4556f23..4803737598 100644 --- a/projects/hip-tests/catch/unit/vulkan_interop/CMakeLists.txt +++ b/projects/hip-tests/catch/unit/vulkan_interop/CMakeLists.txt @@ -5,6 +5,8 @@ set(TEST_SRC hipDestroyExternalMemory.cc hipWaitExternalSemaphoresAsync.cc hipSignalExternalSemaphoresAsync.cc + hipImportExternalSemaphore.cc + hipDestroyExternalSemaphore.cc ) find_package(Vulkan) diff --git a/projects/hip-tests/catch/unit/vulkan_interop/hipDestroyExternalSemaphore.cc b/projects/hip-tests/catch/unit/vulkan_interop/hipDestroyExternalSemaphore.cc new file mode 100644 index 0000000000..dcef2d7fad --- /dev/null +++ b/projects/hip-tests/catch/unit/vulkan_interop/hipDestroyExternalSemaphore.cc @@ -0,0 +1,40 @@ +/* +Copyright (c) 2022 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 "vulkan_test.hh" + +constexpr bool enable_validation = false; + +TEST_CASE("Unit_hipDestroyExternalSemaphore_Vulkan_Negative_Parameters") { + SECTION("extSem == nullptr") { + HIP_CHECK_ERROR(hipDestroyExternalSemaphore(nullptr), hipErrorInvalidValue); + } + +// Segfaults in CUDA +#if HT_AMD + SECTION("Double free") { + VulkanTest vkt(enable_validation); + const auto ext_semaphore = ImportBinarySemaphore(vkt); + HIP_CHECK(hipDestroyExternalSemaphore(ext_semaphore)); + HIP_CHECK_ERROR(hipDestroyExternalSemaphore(ext_semaphore), hipErrorInvalidValue); + } +#endif +} \ No newline at end of file diff --git a/projects/hip-tests/catch/unit/vulkan_interop/hipImportExternalSemaphore.cc b/projects/hip-tests/catch/unit/vulkan_interop/hipImportExternalSemaphore.cc new file mode 100644 index 0000000000..2920645459 --- /dev/null +++ b/projects/hip-tests/catch/unit/vulkan_interop/hipImportExternalSemaphore.cc @@ -0,0 +1,56 @@ +/* +Copyright (c) 2022 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 "vulkan_test.hh" + +constexpr bool enable_validation = false; + +TEST_CASE("Unit_hipImportExternalSemaphore_Vulkan_Negative_Parameters") { + VulkanTest vkt(enable_validation); + const auto semaphore = vkt.CreateExternalSemaphore(VK_SEMAPHORE_TYPE_BINARY); + auto handle_desc = vkt.BuildSemaphoreDescriptor(semaphore, VK_SEMAPHORE_TYPE_BINARY); + hipExternalSemaphore_t ext_semaphore; + + SECTION("extSem_out == nullptr") { + HIP_CHECK_ERROR(hipImportExternalSemaphore(nullptr, &handle_desc), hipErrorInvalidValue); + } + + SECTION("semHandleDesc == nullptr") { + HIP_CHECK_ERROR(hipImportExternalSemaphore(&ext_semaphore, nullptr), hipErrorInvalidValue); + } + + SECTION("semHandleDesc.flags != 0") { + handle_desc.flags = 1; + HIP_CHECK_ERROR(hipImportExternalSemaphore(&ext_semaphore, &handle_desc), hipErrorInvalidValue); + } + + SECTION("Invalid semHandleDesc.type") { + handle_desc.type = static_cast(-1); + HIP_CHECK_ERROR(hipImportExternalSemaphore(&ext_semaphore, &handle_desc), hipErrorInvalidValue); + } + +#ifdef _WIN32 + SECTION("semHandleDesc.handle == NULL") { + handle_desc.handle.win32.handle = NULL; + HIP_CHECK_ERROR(hipImportExternalSemaphore(&ext_semaphore, &handle_desc), hipErrorInvalidValue); + } +#endif +} \ No newline at end of file