From e1900c240ea43a558c0976f57b3f693c06fe1971 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Wed, 7 Dec 2022 17:16:31 +0000 Subject: [PATCH] Dont return success when peeking internal handle and no handle is returned Signed-off-by: Mateusz Jablonski --- .../os_interface/windows/wddm20_tests.cpp | 17 ---------------- .../os_interface/windows/wddm_allocation.h | 2 +- .../os_interface/windows/wddm_tests.cpp | 20 +++++++++++++++++++ 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp b/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp index e190940c49..7c46772d38 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp @@ -466,23 +466,6 @@ TEST_F(WddmTestWithMockGdiDll, givenShareableAllocationWhenCreateThenSharedHandl EXPECT_NE(0u, handle); } -TEST(WddmAllocationTest, whenAllocationIsShareableThenSharedHandleToModifyIsSharedHandleOfAllocation) { - WddmAllocation allocation(0, AllocationType::UNKNOWN, nullptr, 0, MemoryConstants::pageSize, nullptr, MemoryPool::MemoryNull, true, 1u); - auto sharedHandleToModify = allocation.getSharedHandleToModify(); - EXPECT_NE(nullptr, sharedHandleToModify); - *sharedHandleToModify = 1234u; - uint64_t handle = 0; - int ret = allocation.peekInternalHandle(nullptr, handle); - EXPECT_EQ(ret, 0); - EXPECT_EQ(*sharedHandleToModify, handle); -} - -TEST(WddmAllocationTest, whenAllocationIsNotShareableThenItDoesntReturnSharedHandleToModify) { - WddmAllocation allocation(0, AllocationType::UNKNOWN, nullptr, 0, MemoryConstants::pageSize, nullptr, MemoryPool::MemoryNull, false, 1u); - auto sharedHandleToModify = allocation.getSharedHandleToModify(); - EXPECT_EQ(nullptr, sharedHandleToModify); -} - TEST_F(Wddm20Tests, WhenMakingResidentAndEvictingThenReturnIsCorrect) { OsAgnosticMemoryManager mm(*executionEnvironment); auto gmmHelper = getGmmHelper(); diff --git a/shared/source/os_interface/windows/wddm_allocation.h b/shared/source/os_interface/windows/wddm_allocation.h index a57054e866..3f569cb271 100644 --- a/shared/source/os_interface/windows/wddm_allocation.h +++ b/shared/source/os_interface/windows/wddm_allocation.h @@ -74,7 +74,7 @@ class WddmAllocation : public GraphicsAllocation { int peekInternalHandle(MemoryManager *memoryManager, uint64_t &handle) override { handle = ntSecureHandle; - return 0; + return handle == 0; } uint64_t *getSharedHandleToModify() { diff --git a/shared/test/unit_test/os_interface/windows/wddm_tests.cpp b/shared/test/unit_test/os_interface/windows/wddm_tests.cpp index 6c07ff6615..d23f6f4926 100644 --- a/shared/test/unit_test/os_interface/windows/wddm_tests.cpp +++ b/shared/test/unit_test/os_interface/windows/wddm_tests.cpp @@ -7,6 +7,7 @@ #include "shared/source/gmm_helper/gmm.h" #include "shared/source/helpers/string.h" +#include "shared/source/os_interface/windows/wddm_allocation.h" #include "shared/test/common/helpers/debug_manager_state_restore.h" #include "shared/test/common/os_interface/windows/wddm_fixture.h" #include "shared/test/common/test_macros/hw_test.h" @@ -494,4 +495,23 @@ TEST_F(WddmSkipResourceCleanupFixtureTests, givenWaitForSynchronizationObjectFro EXPECT_EQ(0u, waitForSynchronizationObjectFromCpuCounter); } +TEST(WddmAllocationTest, whenAllocationIsShareableThenSharedHandleToModifyIsSharedHandleOfAllocation) { + WddmAllocation allocation(0, AllocationType::UNKNOWN, nullptr, 0, MemoryConstants::pageSize, nullptr, MemoryPool::MemoryNull, true, 1u); + auto sharedHandleToModify = allocation.getSharedHandleToModify(); + EXPECT_NE(nullptr, sharedHandleToModify); + *sharedHandleToModify = 1234u; + uint64_t handle = 0; + int ret = allocation.peekInternalHandle(nullptr, handle); + EXPECT_EQ(ret, 0); + EXPECT_EQ(*sharedHandleToModify, handle); +} + +TEST(WddmAllocationTest, whenAllocationIsNotShareableThenItDoesntReturnSharedHandleToModifyAndCantPeekInternalHandle) { + WddmAllocation allocation(0, AllocationType::UNKNOWN, nullptr, 0, MemoryConstants::pageSize, nullptr, MemoryPool::MemoryNull, false, 1u); + auto sharedHandleToModify = allocation.getSharedHandleToModify(); + EXPECT_EQ(nullptr, sharedHandleToModify); + uint64_t handle = 0; + int ret = allocation.peekInternalHandle(nullptr, handle); + EXPECT_NE(ret, 0); +} } // namespace NEO