From d9bf1886c25e91f488d31690229b62f730ba7185 Mon Sep 17 00:00:00 2001 From: Fabian Zwolinski Date: Thu, 13 Jan 2022 13:03:40 +0000 Subject: [PATCH] Remove GMock from GMockMemoryManagerFailFirstAllocation, GMockMemoryManager... Removed GMock from - GMockMemoryManagerFailFirstAllocation - GMockMemoryManager - TestEventCsr - MockKmdNotifyCsr - MockMemoryOperationsHandlerTests - GmockGmmMemory - MockMemoryManagerCommandQueueSBA - TestCmdQueueCsr Renamed: - GMockMemoryManagerFailFirstAllocation -> MockMemoryManagerFailFirstAllocation Moved class body: - GMockMemoryManager to MockMemoryManager - GmockGmmMemory to MockGmmMemoryBase Related-To: NEO-4914 Signed-off-by: Fabian Zwolinski --- .../core/source/cmdqueue/cmdqueue_hw_base.inl | 9 +- .../sources/cmdqueue/test_cmdqueue_1.cpp | 64 +++++---- .../sources/cmdqueue/test_cmdqueue_2.cpp | 10 +- .../sources/context/test_context.cpp | 48 +++---- .../driver/host_pointer_manager_tests.cpp | 13 +- opencl/test/unit_test/event/event_tests.cpp | 37 +++-- .../execution_environment_tests.cpp | 7 +- .../gen12lp/windows/wddm_tests_gen12lp.cpp | 19 +-- .../unit_test/helpers/kmd_notify_tests.cpp | 129 +++++++++++++----- .../test/unit_test/mem_obj/buffer_tests.cpp | 44 ++---- .../create_image_in_local_memory_tests.cpp | 18 +-- opencl/test/unit_test/mem_obj/image_tests.cpp | 11 +- .../os_interface/windows/wddm20_tests.cpp | 56 +++----- .../test/common/mocks/mock_memory_manager.cpp | 7 +- .../test/common/mocks/mock_memory_manager.h | 73 +++++++--- .../mocks/mock_memory_operations_handler.h | 18 +-- .../mocks/windows/mock_gmm_memory_base.h | 61 ++++----- .../os_interface/windows/wddm_fixture.h | 4 +- .../command_stream_receiver_tests.cpp | 60 +++++--- 19 files changed, 378 insertions(+), 310 deletions(-) diff --git a/level_zero/core/source/cmdqueue/cmdqueue_hw_base.inl b/level_zero/core/source/cmdqueue/cmdqueue_hw_base.inl index a546b62517..8c9d0133c7 100644 --- a/level_zero/core/source/cmdqueue/cmdqueue_hw_base.inl +++ b/level_zero/core/source/cmdqueue/cmdqueue_hw_base.inl @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -53,6 +53,9 @@ void CommandQueueHw::programStateBaseAddress(uint64_t gsba, bool globalHeapsBase = neoDevice->getBindlessHeapsHelper()->getGlobalHeapsBase(); } + auto indirectObjectHeapBaseAddress = neoDevice->getMemoryManager()->getInternalHeapBaseAddress(device->getRootDeviceIndex(), useLocalMemoryForIndirectHeap); + auto instructionHeapBaseAddress = neoDevice->getMemoryManager()->getInternalHeapBaseAddress(device->getRootDeviceIndex(), neoDevice->getMemoryManager()->isLocalMemoryUsedForIsa(neoDevice->getRootDeviceIndex())); + NEO::StateBaseAddressHelper::programStateBaseAddress(&sbaCmd, nullptr, nullptr, @@ -60,8 +63,8 @@ void CommandQueueHw::programStateBaseAddress(uint64_t gsba, bool gsba, true, (device->getMOCS(cachedMOCSAllowed, false) >> 1), - neoDevice->getMemoryManager()->getInternalHeapBaseAddress(device->getRootDeviceIndex(), useLocalMemoryForIndirectHeap), - neoDevice->getMemoryManager()->getInternalHeapBaseAddress(device->getRootDeviceIndex(), neoDevice->getMemoryManager()->isLocalMemoryUsedForIsa(neoDevice->getRootDeviceIndex())), + indirectObjectHeapBaseAddress, + instructionHeapBaseAddress, globalHeapsBase, true, useGlobalSshAndDsh, diff --git a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_1.cpp b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_1.cpp index b858b27d8c..c2e7507c90 100644 --- a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_1.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_1.cpp @@ -386,7 +386,21 @@ using CommandQueueSBASupport = IsWithinProducts struct MockMemoryManagerCommandQueueSBA : public MemoryManagerMock { MockMemoryManagerCommandQueueSBA(NEO::ExecutionEnvironment &executionEnvironment) : MemoryManagerMock(const_cast(executionEnvironment)) {} - MOCK_METHOD2(getInternalHeapBaseAddress, uint64_t(uint32_t rootDeviceIndex, bool useLocalMemory)); + + uint64_t getInternalHeapBaseAddress(uint32_t rootDeviceIndex, bool useLocalMemory) override { + getInternalHeapBaseAddressCalled++; + getInternalHeapBaseAddressParamsPassed.push_back({rootDeviceIndex, useLocalMemory}); + return getInternalHeapBaseAddressResult; + } + + struct GetInternalHeapBaseAddressParams { + uint32_t rootDeviceIndex{}; + bool useLocalMemory{}; + }; + + uint32_t getInternalHeapBaseAddressCalled = 0u; + uint64_t getInternalHeapBaseAddressResult = 0u; + StackVec getInternalHeapBaseAddressParamsPassed{}; }; struct CommandQueueProgramSBATest : public ::testing::Test { @@ -397,7 +411,7 @@ struct CommandQueueProgramSBATest : public ::testing::Test { executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(NEO::defaultHwInfo.get()); } - memoryManager = new ::testing::NiceMock(*executionEnvironment); + memoryManager = new MockMemoryManagerCommandQueueSBA(*executionEnvironment); executionEnvironment->memoryManager.reset(memoryManager); neoDevice = NEO::MockDevice::create(executionEnvironment, rootDeviceIndex); @@ -432,40 +446,36 @@ HWTEST2_F(CommandQueueProgramSBATest, whenCreatingCommandQueueThenItIsInitialize NEO::LinearStream child(commandQueue->commandStream->getSpace(alignedSize), alignedSize); auto &hwHelper = HwHelper::get(neoDevice->getHardwareInfo().platform.eRenderCoreFamily); - bool isaInLocalMemory = !hwHelper.useSystemMemoryPlacementForISA(neoDevice->getHardwareInfo()); - - if (isaInLocalMemory) { - EXPECT_CALL(*memoryManager, getInternalHeapBaseAddress(rootDeviceIndex, true)) - .Times(2); - - EXPECT_CALL(*memoryManager, getInternalHeapBaseAddress(rootDeviceIndex, false)) - .Times(0); - } else { - EXPECT_CALL(*memoryManager, getInternalHeapBaseAddress(rootDeviceIndex, true)) - .Times(1); // IOH - - EXPECT_CALL(*memoryManager, getInternalHeapBaseAddress(rootDeviceIndex, false)) - .Times(1); // instruction heap - } + const bool isaInLocalMemory = !hwHelper.useSystemMemoryPlacementForISA(neoDevice->getHardwareInfo()); commandQueue->programStateBaseAddress(0u, true, child, true); + EXPECT_EQ(2u, memoryManager->getInternalHeapBaseAddressCalled); + EXPECT_EQ(rootDeviceIndex, memoryManager->getInternalHeapBaseAddressParamsPassed[0].rootDeviceIndex); + EXPECT_EQ(rootDeviceIndex, memoryManager->getInternalHeapBaseAddressParamsPassed[1].rootDeviceIndex); + if (isaInLocalMemory) { - EXPECT_CALL(*memoryManager, getInternalHeapBaseAddress(rootDeviceIndex, false)) - .Times(1); // IOH - - EXPECT_CALL(*memoryManager, getInternalHeapBaseAddress(rootDeviceIndex, true)) - .Times(1); // instruction heap + EXPECT_TRUE(memoryManager->getInternalHeapBaseAddressParamsPassed[0].useLocalMemory); + EXPECT_TRUE(memoryManager->getInternalHeapBaseAddressParamsPassed[1].useLocalMemory); } else { - EXPECT_CALL(*memoryManager, getInternalHeapBaseAddress(rootDeviceIndex, true)) - .Times(0); - - EXPECT_CALL(*memoryManager, getInternalHeapBaseAddress(rootDeviceIndex, false)) - .Times(2); + EXPECT_TRUE(memoryManager->getInternalHeapBaseAddressParamsPassed[0].useLocalMemory); + EXPECT_FALSE(memoryManager->getInternalHeapBaseAddressParamsPassed[1].useLocalMemory); } commandQueue->programStateBaseAddress(0u, false, child, true); + EXPECT_EQ(4u, memoryManager->getInternalHeapBaseAddressCalled); + EXPECT_EQ(rootDeviceIndex, memoryManager->getInternalHeapBaseAddressParamsPassed[2].rootDeviceIndex); + EXPECT_EQ(rootDeviceIndex, memoryManager->getInternalHeapBaseAddressParamsPassed[3].rootDeviceIndex); + + if (isaInLocalMemory) { + EXPECT_TRUE(memoryManager->getInternalHeapBaseAddressParamsPassed[2].useLocalMemory); + EXPECT_FALSE(memoryManager->getInternalHeapBaseAddressParamsPassed[3].useLocalMemory); + } else { + EXPECT_FALSE(memoryManager->getInternalHeapBaseAddressParamsPassed[2].useLocalMemory); + EXPECT_FALSE(memoryManager->getInternalHeapBaseAddressParamsPassed[3].useLocalMemory); + } + commandQueue->destroy(); } diff --git a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_2.cpp b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_2.cpp index e3f178c91a..3a3d40bc1a 100644 --- a/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_2.cpp +++ b/level_zero/core/test/unit_tests/sources/cmdqueue/test_cmdqueue_2.cpp @@ -12,6 +12,7 @@ #include "shared/test/common/mocks/mock_memory_manager.h" #include "shared/test/common/mocks/mock_memory_operations_handler.h" #include "shared/test/common/mocks/ult_device_factory.h" +#include "shared/test/common/test_macros/mock_method_macros.h" #include "shared/test/common/test_macros/test.h" #include "level_zero/core/test/unit_tests/fixtures/aub_csr_fixture.h" @@ -348,7 +349,7 @@ struct TestCmdQueueCsr : public NEO::UltCommandStreamReceiver { TestCmdQueueCsr(const NEO::ExecutionEnvironment &executionEnvironment, const DeviceBitfield deviceBitfield) : NEO::UltCommandStreamReceiver(const_cast(executionEnvironment), 0, deviceBitfield) { } - MOCK_METHOD3(waitForCompletionWithTimeout, bool(bool enableTimeout, int64_t timeoutMs, uint32_t taskCountToWait)); + ADDMETHOD_NOBASE(waitForCompletionWithTimeout, bool, false, (bool enableTimeout, int64_t timeoutMs, uint32_t taskCountToWait)); }; HWTEST_F(CommandQueueSynchronizeTest, givenSinglePartitionCountWhenWaitFunctionFailsThenReturnNotReady) { @@ -368,17 +369,12 @@ HWTEST_F(CommandQueueSynchronizeTest, givenSinglePartitionCountWhenWaitFunctionF EXPECT_EQ(returnValue, ZE_RESULT_SUCCESS); ASSERT_NE(nullptr, commandQueue); - EXPECT_CALL(*csr, waitForCompletionWithTimeout(::testing::_, - ::testing::_, - ::testing::_)) - .Times(1) - .WillOnce(::testing::Return(false)); - uint64_t timeout = std::numeric_limits::max(); returnValue = commandQueue->synchronize(timeout); EXPECT_EQ(returnValue, ZE_RESULT_NOT_READY); commandQueue->destroy(); + EXPECT_EQ(1u, csr->waitForCompletionWithTimeoutCalled); } using CommandQueuePowerHintTest = Test; diff --git a/level_zero/core/test/unit_tests/sources/context/test_context.cpp b/level_zero/core/test/unit_tests/sources/context/test_context.cpp index 47bcb367f7..4c1f55c149 100644 --- a/level_zero/core/test/unit_tests/sources/context/test_context.cpp +++ b/level_zero/core/test/unit_tests/sources/context/test_context.cpp @@ -351,13 +351,12 @@ TEST_F(ContextMakeMemoryResidentTests, &ptr); EXPECT_EQ(ZE_RESULT_SUCCESS, res); - EXPECT_CALL(*mockMemoryInterface, makeResident) - .WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS)); + mockMemoryInterface->makeResidentResult = NEO::MemoryOperationsStatus::SUCCESS; + res = context->makeMemoryResident(device, ptr, size); EXPECT_EQ(ZE_RESULT_SUCCESS, res); - EXPECT_CALL(*mockMemoryInterface, evict) - .WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS)); + mockMemoryInterface->evictResult = NEO::MemoryOperationsStatus::SUCCESS; res = context->evictMemory(device, ptr, size); EXPECT_EQ(ZE_RESULT_SUCCESS, res); @@ -381,16 +380,14 @@ TEST_F(ContextMakeMemoryResidentTests, DriverHandleImp *driverHandleImp = static_cast(hostDriverHandle.get()); size_t previousSize = driverHandleImp->sharedMakeResidentAllocations.size(); - EXPECT_CALL(*mockMemoryInterface, makeResident) - .WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS)); + mockMemoryInterface->makeResidentResult = NEO::MemoryOperationsStatus::SUCCESS; res = context->makeMemoryResident(device, ptr, size); EXPECT_EQ(ZE_RESULT_SUCCESS, res); size_t currentSize = driverHandleImp->sharedMakeResidentAllocations.size(); EXPECT_EQ(previousSize + 1, currentSize); - EXPECT_CALL(*mockMemoryInterface, evict) - .WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS)); + mockMemoryInterface->evictResult = NEO::MemoryOperationsStatus::SUCCESS; res = context->evictMemory(device, ptr, size); EXPECT_EQ(ZE_RESULT_SUCCESS, res); @@ -415,16 +412,14 @@ TEST_F(ContextMakeMemoryResidentTests, DriverHandleImp *driverHandleImp = static_cast(hostDriverHandle.get()); size_t previousSize = driverHandleImp->sharedMakeResidentAllocations.size(); - EXPECT_CALL(*mockMemoryInterface, makeResident) - .WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS)); + mockMemoryInterface->makeResidentResult = NEO::MemoryOperationsStatus::SUCCESS; res = context->makeMemoryResident(device, ptr, size); EXPECT_EQ(ZE_RESULT_SUCCESS, res); size_t currentSize = driverHandleImp->sharedMakeResidentAllocations.size(); EXPECT_EQ(previousSize, currentSize); - EXPECT_CALL(*mockMemoryInterface, evict) - .WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS)); + mockMemoryInterface->evictResult = NEO::MemoryOperationsStatus::SUCCESS; res = context->evictMemory(device, ptr, size); EXPECT_EQ(ZE_RESULT_SUCCESS, res); @@ -448,8 +443,8 @@ TEST_F(ContextMakeMemoryResidentTests, DriverHandleImp *driverHandleImp = static_cast(hostDriverHandle.get()); size_t previousSize = driverHandleImp->sharedMakeResidentAllocations.size(); - EXPECT_CALL(*mockMemoryInterface, makeResident) - .WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::FAILED)); + mockMemoryInterface->makeResidentResult = NEO::MemoryOperationsStatus::FAILED; + res = context->makeMemoryResident(device, ptr, size); EXPECT_EQ(ZE_RESULT_ERROR_DEVICE_LOST, res); @@ -509,8 +504,8 @@ HWTEST_F(ContextMakeMemoryResidentAndMigrationTests, DriverHandleImp *driverHandleImp = static_cast(hostDriverHandle.get()); size_t previousSize = driverHandleImp->sharedMakeResidentAllocations.size(); - EXPECT_CALL(*mockMemoryInterface, makeResident) - .WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS)); + mockMemoryInterface->makeResidentResult = NEO::MemoryOperationsStatus::SUCCESS; + ze_result_t res = context->makeMemoryResident(device, ptr, size); EXPECT_EQ(ZE_RESULT_SUCCESS, res); @@ -546,8 +541,7 @@ HWTEST_F(ContextMakeMemoryResidentAndMigrationTests, EXPECT_EQ(mockPageFaultManager->moveAllocationToGpuDomainCalledTimes, 1u); EXPECT_EQ(mockPageFaultManager->migratedAddress, ptr); - EXPECT_CALL(*mockMemoryInterface, evict) - .WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS)); + mockMemoryInterface->evictResult = NEO::MemoryOperationsStatus::SUCCESS; res = context->evictMemory(device, ptr, size); EXPECT_EQ(ZE_RESULT_SUCCESS, res); @@ -560,8 +554,8 @@ HWTEST_F(ContextMakeMemoryResidentAndMigrationTests, DriverHandleImp *driverHandleImp = static_cast(hostDriverHandle.get()); size_t previousSize = driverHandleImp->sharedMakeResidentAllocations.size(); - EXPECT_CALL(*mockMemoryInterface, makeResident) - .WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS)); + mockMemoryInterface->makeResidentResult = NEO::MemoryOperationsStatus::SUCCESS; + ze_result_t res = context->makeMemoryResident(device, ptr, size); EXPECT_EQ(ZE_RESULT_SUCCESS, res); @@ -597,8 +591,7 @@ HWTEST_F(ContextMakeMemoryResidentAndMigrationTests, EXPECT_EQ(mockPageFaultManager->moveAllocationToGpuDomainCalledTimes, 0u); EXPECT_EQ(mockPageFaultManager->migratedAddress, nullptr); - EXPECT_CALL(*mockMemoryInterface, evict) - .WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS)); + mockMemoryInterface->evictResult = NEO::MemoryOperationsStatus::SUCCESS; res = context->evictMemory(device, ptr, size); EXPECT_EQ(ZE_RESULT_SUCCESS, res); @@ -611,8 +604,8 @@ HWTEST_F(ContextMakeMemoryResidentAndMigrationTests, DriverHandleImp *driverHandleImp = static_cast(hostDriverHandle.get()); size_t previousSize = driverHandleImp->sharedMakeResidentAllocations.size(); - EXPECT_CALL(*mockMemoryInterface, makeResident) - .WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS)); + mockMemoryInterface->makeResidentResult = NEO::MemoryOperationsStatus::SUCCESS; + ze_result_t res = context->makeMemoryResident(device, ptr, size); EXPECT_EQ(ZE_RESULT_SUCCESS, res); @@ -651,8 +644,7 @@ HWTEST_F(ContextMakeMemoryResidentAndMigrationTests, EXPECT_EQ(mockPageFaultManager->moveAllocationToGpuDomainCalledTimes, 1u); EXPECT_EQ(mockPageFaultManager->migratedAddress, ptr); - EXPECT_CALL(*mockMemoryInterface, evict) - .WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS)); + mockMemoryInterface->evictResult = NEO::MemoryOperationsStatus::SUCCESS; res = context->evictMemory(device, ptr, size); EXPECT_EQ(ZE_RESULT_SUCCESS, res); @@ -665,8 +657,8 @@ HWTEST_F(ContextMakeMemoryResidentAndMigrationTests, DriverHandleImp *driverHandleImp = static_cast(hostDriverHandle.get()); size_t previousSize = driverHandleImp->sharedMakeResidentAllocations.size(); - EXPECT_CALL(*mockMemoryInterface, makeResident) - .WillRepeatedly(testing::Return(NEO::MemoryOperationsStatus::SUCCESS)); + mockMemoryInterface->makeResidentResult = NEO::MemoryOperationsStatus::SUCCESS; + ze_result_t res = context->makeMemoryResident(device, ptr, size); EXPECT_EQ(ZE_RESULT_SUCCESS, res); diff --git a/level_zero/core/test/unit_tests/sources/driver/host_pointer_manager_tests.cpp b/level_zero/core/test/unit_tests/sources/driver/host_pointer_manager_tests.cpp index f229ac6634..4f9799eae3 100644 --- a/level_zero/core/test/unit_tests/sources/driver/host_pointer_manager_tests.cpp +++ b/level_zero/core/test/unit_tests/sources/driver/host_pointer_manager_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -390,12 +390,8 @@ TEST_F(HostPointerManagerTest, givenNoPointerRegisteredWhenAllocationCreationFai TEST_F(HostPointerManagerTest, givenHostAllocationImportedWhenMakingResidentAddressThenAllocationMadeResident) { void *testPtr = heapPointer; - EXPECT_CALL(*mockMemoryInterface, makeResident(_, _)) - .Times(1) - .WillRepeatedly(::testing::Return(NEO::MemoryOperationsStatus::SUCCESS)); - EXPECT_CALL(*mockMemoryInterface, evict(_, _)) - .Times(1) - .WillRepeatedly(::testing::Return(NEO::MemoryOperationsStatus::SUCCESS)); + mockMemoryInterface->makeResidentResult = NEO::MemoryOperationsStatus::SUCCESS; + mockMemoryInterface->evictResult = NEO::MemoryOperationsStatus::SUCCESS; auto result = context->makeMemoryResident(device, testPtr, MemoryConstants::pageSize); EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result); @@ -414,6 +410,9 @@ TEST_F(HostPointerManagerTest, givenHostAllocationImportedWhenMakingResidentAddr result = context->evictMemory(device, testPtr, MemoryConstants::pageSize); EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, result); + + EXPECT_EQ(1u, mockMemoryInterface->makeResidentCalled); + EXPECT_EQ(1u, mockMemoryInterface->evictCalled); } TEST_F(HostPointerManagerTest, givenMisalignedPointerRegisteredWhenGettingRelativeOffsetAddressThenRetrieveMisalignedPointerAsBaseAddress) { diff --git a/opencl/test/unit_test/event/event_tests.cpp b/opencl/test/unit_test/event/event_tests.cpp index 887213e7b6..f6100c93df 100644 --- a/opencl/test/unit_test/event/event_tests.cpp +++ b/opencl/test/unit_test/event/event_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2018-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -1486,7 +1486,22 @@ template struct TestEventCsr : public UltCommandStreamReceiver { TestEventCsr(const ExecutionEnvironment &executionEnvironment, const DeviceBitfield deviceBitfield) : UltCommandStreamReceiver(const_cast(executionEnvironment), 0, deviceBitfield) {} - MOCK_METHOD3(waitForCompletionWithTimeout, bool(bool enableTimeout, int64_t timeoutMs, uint32_t taskCountToWait)); + + bool waitForCompletionWithTimeout(bool enableTimeout, int64_t timeoutMs, uint32_t taskCountToWait) override { + waitForCompletionWithTimeoutCalled++; + waitForCompletionWithTimeoutParamsPassed.push_back({enableTimeout, timeoutMs, taskCountToWait}); + return waitForCompletionWithTimeoutResult; + } + + struct WaitForCompletionWithTimeoutParams { + bool enableTimeout = false; + int64_t timeoutMs{}; + uint32_t taskCountToWait{}; + }; + + uint32_t waitForCompletionWithTimeoutCalled = 0u; + bool waitForCompletionWithTimeoutResult = true; + StackVec waitForCompletionWithTimeoutParamsPassed{}; }; HWTEST_F(EventTest, givenQuickKmdSleepRequestWhenWaitIsCalledThenPassRequestToWaitingFunction) { @@ -1498,18 +1513,15 @@ HWTEST_F(EventTest, givenQuickKmdSleepRequestWhenWaitIsCalledThenPassRequestToWa pDevice->executionEnvironment->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->setHwInfo(&localHwInfo); - auto csr = new ::testing::NiceMock>(*pDevice->executionEnvironment, pDevice->getDeviceBitfield()); + auto csr = new TestEventCsr(*pDevice->executionEnvironment, pDevice->getDeviceBitfield()); pDevice->resetCommandStreamReceiver(csr); Event event(pCmdQ, CL_COMMAND_NDRANGE_KERNEL, 0, 0); event.updateCompletionStamp(1u, 0, 1u, 1u); - EXPECT_CALL(*csr, waitForCompletionWithTimeout(::testing::_, - localHwInfo.capabilityTable.kmdNotifyProperties.delayQuickKmdSleepMicroseconds, ::testing::_)) - .Times(1) - .WillOnce(::testing::Return(true)); - event.wait(true, true); + EXPECT_EQ(1u, csr->waitForCompletionWithTimeoutCalled); + EXPECT_EQ(localHwInfo.capabilityTable.kmdNotifyProperties.delayQuickKmdSleepMicroseconds, csr->waitForCompletionWithTimeoutParamsPassed[0].timeoutMs); } HWTEST_F(EventTest, givenNonQuickKmdSleepRequestWhenWaitIsCalledThenPassRequestToWaitingFunction) { @@ -1522,18 +1534,15 @@ HWTEST_F(EventTest, givenNonQuickKmdSleepRequestWhenWaitIsCalledThenPassRequestT pDevice->executionEnvironment->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]->setHwInfo(&localHwInfo); - auto csr = new ::testing::NiceMock>(*pDevice->executionEnvironment, pDevice->getDeviceBitfield()); + auto csr = new TestEventCsr(*pDevice->executionEnvironment, pDevice->getDeviceBitfield()); pDevice->resetCommandStreamReceiver(csr); Event event(pCmdQ, CL_COMMAND_NDRANGE_KERNEL, 0, 0); event.updateCompletionStamp(1u, 0, 1u, 1u); - EXPECT_CALL(*csr, waitForCompletionWithTimeout(::testing::_, - localHwInfo.capabilityTable.kmdNotifyProperties.delayKmdNotifyMicroseconds, ::testing::_)) - .Times(1) - .WillOnce(::testing::Return(true)); - event.wait(true, false); + EXPECT_EQ(1u, csr->waitForCompletionWithTimeoutCalled); + EXPECT_EQ(localHwInfo.capabilityTable.kmdNotifyProperties.delayKmdNotifyMicroseconds, csr->waitForCompletionWithTimeoutParamsPassed[0].timeoutMs); } HWTEST_F(InternalsEventTest, givenCommandWhenSubmitCalledThenUpdateFlushStamp) { diff --git a/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp b/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp index 27f1663829..e83051d6ad 100644 --- a/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp +++ b/opencl/test/unit_test/execution_environment/execution_environment_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2018-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -198,7 +198,10 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe uint32_t destructorId = 0u; struct MemoryMangerMock : public DestructorCounted { - MemoryMangerMock(uint32_t &destructorId, ExecutionEnvironment &executionEnvironment) : DestructorCounted(destructorId, executionEnvironment) {} + MemoryMangerMock(uint32_t &destructorId, ExecutionEnvironment &executionEnvironment) : DestructorCounted(destructorId, executionEnvironment) { + callBaseAllocateGraphicsMemoryForNonSvmHostPtr = false; + callBasePopulateOsHandles = false; + } }; struct DirectSubmissionControllerMock : public DestructorCounted { DirectSubmissionControllerMock(uint32_t &destructorId) : DestructorCounted(destructorId) {} diff --git a/opencl/test/unit_test/gen12lp/windows/wddm_tests_gen12lp.cpp b/opencl/test/unit_test/gen12lp/windows/wddm_tests_gen12lp.cpp index 4042f241c0..fc363f3dca 100644 --- a/opencl/test/unit_test/gen12lp/windows/wddm_tests_gen12lp.cpp +++ b/opencl/test/unit_test/gen12lp/windows/wddm_tests_gen12lp.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 Intel Corporation + * Copyright (C) 2020-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -25,7 +25,7 @@ struct Gen12LpWddmTest : public GdiDllFixture, ::testing::Test { rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[0].get(); rootDeviceEnvironment->initGmm(); wddm = static_cast(Wddm::createWddm(nullptr, *rootDeviceEnvironment)); - gmmMemory = new ::testing::NiceMock(rootDeviceEnvironment->getGmmClientContext()); + gmmMemory = new MockGmmMemoryBase(rootDeviceEnvironment->getGmmClientContext()); wddm->gmmMemory.reset(gmmMemory); } @@ -36,29 +36,20 @@ struct Gen12LpWddmTest : public GdiDllFixture, ::testing::Test { std::unique_ptr executionEnvironment; RootDeviceEnvironment *rootDeviceEnvironment = nullptr; WddmMock *wddm = nullptr; - GmockGmmMemory *gmmMemory = nullptr; + MockGmmMemoryBase *gmmMemory = nullptr; }; GEN12LPTEST_F(Gen12LpWddmTest, whenConfigureDeviceAddressSpaceThenObtainMinAddress) { - ON_CALL(*gmmMemory, configureDeviceAddressSpace(::testing::_, - ::testing::_, - ::testing::_, - ::testing::_, - ::testing::_)) - .WillByDefault(::testing::Return(true)); - uintptr_t minAddress = 0x12345u; EXPECT_NE(NEO::windowsMinAddress, minAddress); - EXPECT_CALL(*gmmMemory, - getInternalGpuVaRangeLimit()) - .Times(1) - .WillRepeatedly(::testing::Return(minAddress)); + gmmMemory->getInternalGpuVaRangeLimitResult = minAddress; wddm->init(); EXPECT_EQ(minAddress, wddm->getWddmMinAddress()); + EXPECT_EQ(1u, gmmMemory->getInternalGpuVaRangeLimitCalled); } using Gen12LpWddmHwInfoTest = ::testing::Test; diff --git a/opencl/test/unit_test/helpers/kmd_notify_tests.cpp b/opencl/test/unit_test/helpers/kmd_notify_tests.cpp index e85e44ace5..98b4765234 100644 --- a/opencl/test/unit_test/helpers/kmd_notify_tests.cpp +++ b/opencl/test/unit_test/helpers/kmd_notify_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2018-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -73,13 +73,41 @@ struct KmdNotifyTests : public ::testing::Test { public: MockKmdNotifyCsr(const ExecutionEnvironment &executionEnvironment, const DeviceBitfield deviceBitfield) : UltCommandStreamReceiver(const_cast(executionEnvironment), 0, deviceBitfield) {} - MOCK_METHOD1(waitForFlushStamp, bool(FlushStamp &flushStampToWait)); - MOCK_METHOD3(waitForCompletionWithTimeout, bool(bool enableTimeout, int64_t timeoutMs, uint32_t taskCountToWait)); + + bool waitForFlushStamp(FlushStamp &flushStampToWait) override { + waitForFlushStampCalled++; + waitForFlushStampParamsPassed.push_back({flushStampToWait}); + return waitForFlushStampResult; + } + + struct WaitForFlushStampParams { + FlushStamp flushStampToWait{}; + }; + + uint32_t waitForFlushStampCalled = 0u; + bool waitForFlushStampResult = true; + StackVec waitForFlushStampParamsPassed{}; + + bool waitForCompletionWithTimeout(bool enableTimeout, int64_t timeoutMs, uint32_t taskCountToWait) override { + waitForCompletionWithTimeoutCalled++; + waitForCompletionWithTimeoutParamsPassed.push_back({enableTimeout, timeoutMs, taskCountToWait}); + return waitForCompletionWithTimeoutResult; + } + + struct WaitForCompletionWithTimeoutParams { + bool enableTimeout{}; + int64_t timeoutMs{}; + uint32_t taskCountToWait{}; + }; + + uint32_t waitForCompletionWithTimeoutCalled = 0u; + bool waitForCompletionWithTimeoutResult = true; + StackVec waitForCompletionWithTimeoutParamsPassed{}; }; template MockKmdNotifyCsr *createMockCsr() { - auto csr = new ::testing::NiceMock>(*device->executionEnvironment, device->getDeviceBitfield()); + auto csr = new MockKmdNotifyCsr(*device->executionEnvironment, device->getDeviceBitfield()); device->resetCommandStreamReceiver(csr); mockKmdNotifyHelper = new MockKmdNotifyHelper(&device->getHardwareInfo().capabilityTable.kmdNotifyProperties); @@ -100,19 +128,23 @@ struct KmdNotifyTests : public ::testing::Test { HWTEST_F(KmdNotifyTests, givenTaskCountWhenWaitUntilCompletionCalledThenAlwaysTryCpuPolling) { auto csr = createMockCsr(); - EXPECT_CALL(*csr, waitForCompletionWithTimeout(true, 2, taskCountToWait)).Times(1).WillOnce(::testing::Return(true)); - cmdQ->waitUntilComplete(taskCountToWait, {}, flushStampToWait, false); + EXPECT_EQ(1u, csr->waitForCompletionWithTimeoutCalled); + EXPECT_EQ(true, csr->waitForCompletionWithTimeoutParamsPassed[0].enableTimeout); + EXPECT_EQ(2, csr->waitForCompletionWithTimeoutParamsPassed[0].timeoutMs); + EXPECT_EQ(taskCountToWait, csr->waitForCompletionWithTimeoutParamsPassed[0].taskCountToWait); } HWTEST_F(KmdNotifyTests, givenTaskCountAndKmdNotifyDisabledWhenWaitUntilCompletionCalledThenTryCpuPollingWithoutTimeout) { overrideKmdNotifyParams(false, 0, false, 0, false, 0, false, 0); auto csr = createMockCsr(); - EXPECT_CALL(*csr, waitForCompletionWithTimeout(false, 0, taskCountToWait)).Times(1).WillOnce(::testing::Return(true)); - EXPECT_CALL(*csr, waitForFlushStamp(::testing::_)).Times(0); - cmdQ->waitUntilComplete(taskCountToWait, {}, flushStampToWait, false); + EXPECT_EQ(0u, csr->waitForFlushStampCalled); + EXPECT_EQ(1u, csr->waitForCompletionWithTimeoutCalled); + EXPECT_EQ(false, csr->waitForCompletionWithTimeoutParamsPassed[0].enableTimeout); + EXPECT_EQ(0, csr->waitForCompletionWithTimeoutParamsPassed[0].timeoutMs); + EXPECT_EQ(taskCountToWait, csr->waitForCompletionWithTimeoutParamsPassed[0].taskCountToWait); } HWTEST_F(KmdNotifyTests, givenNotReadyTaskCountWhenWaitUntilCompletionCalledThenTryCpuPollingAndKmdWait) { @@ -120,40 +152,57 @@ HWTEST_F(KmdNotifyTests, givenNotReadyTaskCountWhenWaitUntilCompletionCalledThen *csr->getTagAddress() = taskCountToWait - 1; ::testing::InSequence is; - EXPECT_CALL(*csr, waitForCompletionWithTimeout(true, 2, taskCountToWait)).Times(1).WillOnce(::testing::Return(false)); - EXPECT_CALL(*csr, waitForFlushStamp(flushStampToWait)).Times(1).WillOnce(::testing::Return(true)); - EXPECT_CALL(*csr, waitForCompletionWithTimeout(false, 0, taskCountToWait)).Times(1).WillOnce(::testing::Return(false)); + csr->waitForCompletionWithTimeoutResult = false; //we have unrecoverable for this case, this will throw. EXPECT_THROW(cmdQ->waitUntilComplete(taskCountToWait, {}, flushStampToWait, false), std::exception); + EXPECT_EQ(1u, csr->waitForFlushStampCalled); + EXPECT_EQ(flushStampToWait, csr->waitForFlushStampParamsPassed[0].flushStampToWait); + + EXPECT_EQ(2u, csr->waitForCompletionWithTimeoutCalled); + + EXPECT_EQ(true, csr->waitForCompletionWithTimeoutParamsPassed[0].enableTimeout); + EXPECT_EQ(2, csr->waitForCompletionWithTimeoutParamsPassed[0].timeoutMs); + EXPECT_EQ(taskCountToWait, csr->waitForCompletionWithTimeoutParamsPassed[0].taskCountToWait); + + EXPECT_EQ(false, csr->waitForCompletionWithTimeoutParamsPassed[1].enableTimeout); + EXPECT_EQ(0, csr->waitForCompletionWithTimeoutParamsPassed[1].timeoutMs); + EXPECT_EQ(taskCountToWait, csr->waitForCompletionWithTimeoutParamsPassed[1].taskCountToWait); } HWTEST_F(KmdNotifyTests, givenReadyTaskCountWhenWaitUntilCompletionCalledThenTryCpuPollingAndDontCallKmdWait) { auto csr = createMockCsr(); ::testing::InSequence is; - EXPECT_CALL(*csr, waitForCompletionWithTimeout(true, 2, taskCountToWait)).Times(1).WillOnce(::testing::Return(true)); - EXPECT_CALL(*csr, waitForFlushStamp(::testing::_)).Times(0); cmdQ->waitUntilComplete(taskCountToWait, {}, flushStampToWait, false); + EXPECT_EQ(0u, csr->waitForFlushStampCalled); + EXPECT_EQ(1u, csr->waitForCompletionWithTimeoutCalled); + EXPECT_EQ(true, csr->waitForCompletionWithTimeoutParamsPassed[0].enableTimeout); + EXPECT_EQ(2, csr->waitForCompletionWithTimeoutParamsPassed[0].timeoutMs); + EXPECT_EQ(taskCountToWait, csr->waitForCompletionWithTimeoutParamsPassed[0].taskCountToWait); } HWTEST_F(KmdNotifyTests, givenDefaultArgumentWhenWaitUntilCompleteIsCalledThenDisableQuickKmdSleep) { auto csr = createMockCsr(); auto expectedTimeout = device->getHardwareInfo().capabilityTable.kmdNotifyProperties.delayKmdNotifyMicroseconds; - EXPECT_CALL(*csr, waitForCompletionWithTimeout(true, expectedTimeout, taskCountToWait)).Times(1).WillOnce(::testing::Return(true)); - cmdQ->waitUntilComplete(taskCountToWait, {}, flushStampToWait, false); + EXPECT_EQ(1u, csr->waitForCompletionWithTimeoutCalled); + EXPECT_EQ(true, csr->waitForCompletionWithTimeoutParamsPassed[0].enableTimeout); + EXPECT_EQ(expectedTimeout, csr->waitForCompletionWithTimeoutParamsPassed[0].timeoutMs); + EXPECT_EQ(taskCountToWait, csr->waitForCompletionWithTimeoutParamsPassed[0].taskCountToWait); } HWTEST_F(KmdNotifyTests, givenEnabledQuickSleepWhenWaitUntilCompleteIsCalledThenChangeDelayValue) { auto csr = createMockCsr(); auto expectedTimeout = device->getHardwareInfo().capabilityTable.kmdNotifyProperties.delayQuickKmdSleepMicroseconds; - EXPECT_CALL(*csr, waitForCompletionWithTimeout(true, expectedTimeout, taskCountToWait)).Times(1).WillOnce(::testing::Return(true)); - cmdQ->waitUntilComplete(taskCountToWait, {}, flushStampToWait, true); + EXPECT_EQ(1u, csr->waitForCompletionWithTimeoutCalled); + EXPECT_EQ(true, csr->waitForCompletionWithTimeoutParamsPassed[0].enableTimeout); + EXPECT_EQ(expectedTimeout, csr->waitForCompletionWithTimeoutParamsPassed[0].timeoutMs); + EXPECT_EQ(taskCountToWait, csr->waitForCompletionWithTimeoutParamsPassed[0].taskCountToWait); } HWTEST_F(KmdNotifyTests, givenDisabledQuickSleepWhenWaitUntilCompleteWithQuickSleepRequestIsCalledThenUseBaseDelayValue) { @@ -161,9 +210,11 @@ HWTEST_F(KmdNotifyTests, givenDisabledQuickSleepWhenWaitUntilCompleteWithQuickSl auto csr = createMockCsr(); auto expectedTimeout = device->getHardwareInfo().capabilityTable.kmdNotifyProperties.delayKmdNotifyMicroseconds; - EXPECT_CALL(*csr, waitForCompletionWithTimeout(true, expectedTimeout, taskCountToWait)).Times(1).WillOnce(::testing::Return(true)); - cmdQ->waitUntilComplete(taskCountToWait, {}, flushStampToWait, true); + EXPECT_EQ(1u, csr->waitForCompletionWithTimeoutCalled); + EXPECT_EQ(true, csr->waitForCompletionWithTimeoutParamsPassed[0].enableTimeout); + EXPECT_EQ(expectedTimeout, csr->waitForCompletionWithTimeoutParamsPassed[0].timeoutMs); + EXPECT_EQ(taskCountToWait, csr->waitForCompletionWithTimeoutParamsPassed[0].taskCountToWait); } HWTEST_F(KmdNotifyTests, givenNotReadyTaskCountWhenPollForCompletionCalledThenTimeout) { @@ -176,10 +227,12 @@ HWTEST_F(KmdNotifyTests, givenZeroFlushStampWhenWaitIsCalledThenDisableTimeout) auto csr = createMockCsr(); EXPECT_TRUE(device->getHardwareInfo().capabilityTable.kmdNotifyProperties.enableKmdNotify); - EXPECT_CALL(*csr, waitForCompletionWithTimeout(false, ::testing::_, taskCountToWait)).Times(1).WillOnce(::testing::Return(true)); - EXPECT_CALL(*csr, waitForFlushStamp(::testing::_)).Times(0); csr->waitForTaskCountWithKmdNotifyFallback(taskCountToWait, 0, false, false); + EXPECT_EQ(0u, csr->waitForFlushStampCalled); + EXPECT_EQ(1u, csr->waitForCompletionWithTimeoutCalled); + EXPECT_EQ(false, csr->waitForCompletionWithTimeoutParamsPassed[0].enableTimeout); + EXPECT_EQ(taskCountToWait, csr->waitForCompletionWithTimeoutParamsPassed[0].taskCountToWait); } HWTEST_F(KmdNotifyTests, givenNonQuickSleepRequestWhenItsSporadicWaitThenOverrideQuickSleepRequest) { @@ -187,12 +240,13 @@ HWTEST_F(KmdNotifyTests, givenNonQuickSleepRequestWhenItsSporadicWaitThenOverrid auto csr = createMockCsr(); auto expectedDelay = device->getHardwareInfo().capabilityTable.kmdNotifyProperties.delayQuickKmdSleepMicroseconds; - EXPECT_CALL(*csr, waitForCompletionWithTimeout(::testing::_, expectedDelay, ::testing::_)).Times(1).WillOnce(::testing::Return(true)); int64_t timeSinceLastWait = mockKmdNotifyHelper->properties->delayQuickKmdSleepForSporadicWaitsMicroseconds + 1; mockKmdNotifyHelper->lastWaitForCompletionTimestampUs = mockKmdNotifyHelper->getMicrosecondsSinceEpoch() - timeSinceLastWait; csr->waitForTaskCountWithKmdNotifyFallback(taskCountToWait, 1, false, false); + EXPECT_EQ(1u, csr->waitForCompletionWithTimeoutCalled); + EXPECT_EQ(expectedDelay, csr->waitForCompletionWithTimeoutParamsPassed[0].timeoutMs); } HWTEST_F(KmdNotifyTests, givenNonQuickSleepRequestWhenItsNotSporadicWaitThenOverrideQuickSleepRequest) { @@ -200,33 +254,41 @@ HWTEST_F(KmdNotifyTests, givenNonQuickSleepRequestWhenItsNotSporadicWaitThenOver auto csr = createMockCsr(); auto expectedDelay = device->getHardwareInfo().capabilityTable.kmdNotifyProperties.delayKmdNotifyMicroseconds; - EXPECT_CALL(*csr, waitForCompletionWithTimeout(::testing::_, expectedDelay, ::testing::_)).Times(1).WillOnce(::testing::Return(true)); csr->waitForTaskCountWithKmdNotifyFallback(taskCountToWait, 1, false, false); + EXPECT_EQ(1u, csr->waitForCompletionWithTimeoutCalled); + EXPECT_EQ(expectedDelay, csr->waitForCompletionWithTimeoutParamsPassed[0].timeoutMs); } HWTEST_F(KmdNotifyTests, givenKmdNotifyDisabledWhenPowerSavingModeIsRequestedThenTimeoutIsEnabled) { overrideKmdNotifyParams(false, 3, false, 2, false, 9999999, false, 0); auto csr = createMockCsr(); - EXPECT_CALL(*csr, waitForCompletionWithTimeout(true, 1, ::testing::_)).Times(1).WillOnce(::testing::Return(true)); csr->waitForTaskCountWithKmdNotifyFallback(taskCountToWait, 1, false, true); + EXPECT_EQ(1u, csr->waitForCompletionWithTimeoutCalled); + EXPECT_EQ(true, csr->waitForCompletionWithTimeoutParamsPassed[0].enableTimeout); + EXPECT_EQ(1, csr->waitForCompletionWithTimeoutParamsPassed[0].timeoutMs); } HWTEST_F(KmdNotifyTests, givenKmdNotifyDisabledWhenQueueHasPowerSavingModeAndCallWaitThenTimeoutIsEnabled) { overrideKmdNotifyParams(false, 3, false, 2, false, 9999999, false, 0); auto csr = createMockCsr(); - EXPECT_CALL(*csr, waitForCompletionWithTimeout(true, 1, ::testing::_)).Times(1).WillOnce(::testing::Return(true)); + cmdQ->throttle = QueueThrottle::LOW; cmdQ->waitUntilComplete(1, {}, 1, false); + EXPECT_EQ(1u, csr->waitForCompletionWithTimeoutCalled); + EXPECT_EQ(true, csr->waitForCompletionWithTimeoutParamsPassed[0].enableTimeout); + EXPECT_EQ(1, csr->waitForCompletionWithTimeoutParamsPassed[0].timeoutMs); } HWTEST_F(KmdNotifyTests, givenKmdNotifyDisabledWhenQueueHasPowerSavingModButThereIsNoFlushStampeAndCallWaitThenTimeoutIsDisabled) { overrideKmdNotifyParams(false, 3, false, 2, false, 9999999, false, 0); auto csr = createMockCsr(); - EXPECT_CALL(*csr, waitForCompletionWithTimeout(false, 0, ::testing::_)).Times(1).WillOnce(::testing::Return(true)); cmdQ->throttle = QueueThrottle::LOW; cmdQ->waitUntilComplete(1, {}, 0, false); + EXPECT_EQ(1u, csr->waitForCompletionWithTimeoutCalled); + EXPECT_EQ(false, csr->waitForCompletionWithTimeoutParamsPassed[0].enableTimeout); + EXPECT_EQ(0, csr->waitForCompletionWithTimeoutParamsPassed[0].timeoutMs); } HWTEST_F(KmdNotifyTests, givenQuickSleepRequestWhenItsSporadicWaitOptimizationIsDisabledThenDontOverrideQuickSleepRequest) { @@ -234,9 +296,10 @@ HWTEST_F(KmdNotifyTests, givenQuickSleepRequestWhenItsSporadicWaitOptimizationIs auto csr = createMockCsr(); auto expectedDelay = device->getHardwareInfo().capabilityTable.kmdNotifyProperties.delayQuickKmdSleepMicroseconds; - EXPECT_CALL(*csr, waitForCompletionWithTimeout(::testing::_, expectedDelay, ::testing::_)).Times(1).WillOnce(::testing::Return(true)); csr->waitForTaskCountWithKmdNotifyFallback(taskCountToWait, 1, true, false); + EXPECT_EQ(1u, csr->waitForCompletionWithTimeoutCalled); + EXPECT_EQ(expectedDelay, csr->waitForCompletionWithTimeoutParamsPassed[0].timeoutMs); } HWTEST_F(KmdNotifyTests, givenTaskCountEqualToHwTagWhenWaitCalledThenDontMultiplyTimeout) { @@ -245,9 +308,10 @@ HWTEST_F(KmdNotifyTests, givenTaskCountEqualToHwTagWhenWaitCalledThenDontMultipl auto expectedTimeout = device->getHardwareInfo().capabilityTable.kmdNotifyProperties.delayKmdNotifyMicroseconds; - EXPECT_CALL(*csr, waitForCompletionWithTimeout(true, expectedTimeout, ::testing::_)).Times(1).WillOnce(::testing::Return(true)); - csr->waitForTaskCountWithKmdNotifyFallback(taskCountToWait, 1, false, false); + EXPECT_EQ(1u, csr->waitForCompletionWithTimeoutCalled); + EXPECT_EQ(true, csr->waitForCompletionWithTimeoutParamsPassed[0].enableTimeout); + EXPECT_EQ(expectedTimeout, csr->waitForCompletionWithTimeoutParamsPassed[0].timeoutMs); } HWTEST_F(KmdNotifyTests, givenTaskCountLowerThanHwTagWhenWaitCalledThenDontMultiplyTimeout) { @@ -256,9 +320,10 @@ HWTEST_F(KmdNotifyTests, givenTaskCountLowerThanHwTagWhenWaitCalledThenDontMulti auto expectedTimeout = device->getHardwareInfo().capabilityTable.kmdNotifyProperties.delayKmdNotifyMicroseconds; - EXPECT_CALL(*csr, waitForCompletionWithTimeout(true, expectedTimeout, ::testing::_)).Times(1).WillOnce(::testing::Return(true)); - csr->waitForTaskCountWithKmdNotifyFallback(taskCountToWait, 1, false, false); + EXPECT_EQ(1u, csr->waitForCompletionWithTimeoutCalled); + EXPECT_EQ(true, csr->waitForCompletionWithTimeoutParamsPassed[0].enableTimeout); + EXPECT_EQ(expectedTimeout, csr->waitForCompletionWithTimeoutParamsPassed[0].timeoutMs); } HWTEST_F(KmdNotifyTests, givenDefaultCommandStreamReceiverWhenWaitCalledThenUpdateWaitTimestamp) { diff --git a/opencl/test/unit_test/mem_obj/buffer_tests.cpp b/opencl/test/unit_test/mem_obj/buffer_tests.cpp index 13ccd6bad8..5ff4abe937 100644 --- a/opencl/test/unit_test/mem_obj/buffer_tests.cpp +++ b/opencl/test/unit_test/mem_obj/buffer_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2018-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -225,11 +225,9 @@ TEST(Buffer, givenReadOnlyHostPtrMemoryWhenBufferIsCreatedWithReadOnlyFlagsThenB MockContext ctx(device.get()); // First fail simulates error for read only memory allocation - auto memoryManager = std::make_unique<::testing::NiceMock>(*device->getExecutionEnvironment()); - EXPECT_CALL(*memoryManager, allocateGraphicsMemoryInDevicePool(::testing::_, ::testing::_)) - .WillOnce(::testing::Return(nullptr)) - .WillRepeatedly(::testing::Invoke(memoryManager.get(), &GMockMemoryManagerFailFirstAllocation::baseAllocateGraphicsMemoryInDevicePool)); - + auto memoryManager = std::make_unique(*device->getExecutionEnvironment()); + memoryManager->returnNullptr = true; + memoryManager->returnBaseAllocateGraphicsMemoryInDevicePool = true; cl_int retVal; cl_mem_flags flags = CL_MEM_HOST_READ_ONLY | CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR; @@ -256,9 +254,7 @@ TEST(Buffer, givenReadOnlyHostPtrMemoryWhenBufferIsCreatedWithReadOnlyFlagsAndSe // First fail simulates error for read only memory allocation // Second fail returns nullptr - auto memoryManager = std::make_unique<::testing::NiceMock>(*device->getExecutionEnvironment()); - EXPECT_CALL(*memoryManager, allocateGraphicsMemoryInDevicePool(::testing::_, ::testing::_)) - .WillRepeatedly(::testing::Return(nullptr)); + auto memoryManager = std::make_unique(*device->getExecutionEnvironment()); cl_int retVal; cl_mem_flags flags = CL_MEM_HOST_READ_ONLY | CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR; @@ -281,9 +277,7 @@ TEST(Buffer, givenReadOnlyHostPtrMemoryWhenBufferIsCreatedWithKernelWriteFlagThe MockContext ctx(device.get()); // First fail simulates error for read only memory allocation - auto memoryManager = std::make_unique<::testing::NiceMock>(*device->getExecutionEnvironment()); - EXPECT_CALL(*memoryManager, allocateGraphicsMemoryInDevicePool(::testing::_, ::testing::_)) - .WillOnce(::testing::Return(nullptr)); + auto memoryManager = std::make_unique(*device->getExecutionEnvironment()); cl_int retVal; cl_mem_flags flags = CL_MEM_HOST_READ_ONLY | CL_MEM_WRITE_ONLY | CL_MEM_USE_HOST_PTR; @@ -301,9 +295,7 @@ TEST(Buffer, givenNullPtrWhenBufferIsCreatedWithKernelReadOnlyFlagsThenBufferAll MockContext ctx(device.get()); // First fail simulates error for read only memory allocation - auto memoryManager = std::make_unique<::testing::NiceMock>(*device->getExecutionEnvironment()); - EXPECT_CALL(*memoryManager, allocateGraphicsMemoryInDevicePool(::testing::_, ::testing::_)) - .WillOnce(::testing::Return(nullptr)); + auto memoryManager = std::make_unique(*device->getExecutionEnvironment()); cl_int retVal; cl_mem_flags flags = CL_MEM_HOST_READ_ONLY | CL_MEM_WRITE_ONLY; @@ -319,10 +311,8 @@ TEST(Buffer, givenNullptrPassedToBufferCreateWhenAllocationIsNotSystemMemoryPool auto device = std::make_unique(MockDevice::createWithNewExecutionEnvironment(nullptr)); MockContext ctx(device.get()); - auto memoryManager = std::make_unique<::testing::NiceMock>(*device->getExecutionEnvironment()); - EXPECT_CALL(*memoryManager, allocateGraphicsMemoryInDevicePool(::testing::_, ::testing::_)) - .WillOnce(::testing::Invoke(memoryManager.get(), &GMockMemoryManagerFailFirstAllocation::allocateNonSystemGraphicsMemoryInDevicePool)); - + auto memoryManager = std::make_unique(*device->getExecutionEnvironment()); + memoryManager->returnAllocateNonSystemGraphicsMemoryInDevicePool = true; cl_int retVal = 0; cl_mem_flags flags = CL_MEM_READ_WRITE; @@ -338,10 +328,8 @@ TEST(Buffer, givenNullptrPassedToBufferCreateWhenAllocationIsNotSystemMemoryPool auto device = std::make_unique(MockDevice::createWithNewExecutionEnvironment(nullptr)); MockContext ctx(device.get()); - auto memoryManager = std::make_unique<::testing::NiceMock>(*device->getExecutionEnvironment()); - EXPECT_CALL(*memoryManager, allocateGraphicsMemoryInDevicePool(::testing::_, ::testing::_)) - .WillOnce(::testing::Invoke(memoryManager.get(), &GMockMemoryManagerFailFirstAllocation::allocateNonSystemGraphicsMemoryInDevicePool)); - + auto memoryManager = std::make_unique(*device->getExecutionEnvironment()); + memoryManager->returnAllocateNonSystemGraphicsMemoryInDevicePool = true; cl_int retVal = 0; cl_mem_flags flags = CL_MEM_READ_WRITE; @@ -601,23 +589,19 @@ TEST(Buffer, givenZeroFlagsNoSharedContextAndCompressedBuffersDisabledWhenAlloca TEST(Buffer, givenClMemCopyHostPointerPassedToBufferCreateWhenAllocationIsNotInSystemMemoryPoolThenAllocationIsWrittenByEnqueueWriteBuffer) { ExecutionEnvironment *executionEnvironment = MockClDevice::prepareExecutionEnvironment(defaultHwInfo.get(), 0u); - auto *memoryManager = new ::testing::NiceMock(*executionEnvironment); + auto *memoryManager = new MockMemoryManagerFailFirstAllocation(*executionEnvironment); executionEnvironment->memoryManager.reset(memoryManager); - EXPECT_CALL(*memoryManager, allocateGraphicsMemoryInDevicePool(::testing::_, ::testing::_)) - .WillRepeatedly(::testing::Invoke(memoryManager, &GMockMemoryManagerFailFirstAllocation::baseAllocateGraphicsMemoryInDevicePool)); - + memoryManager->returnBaseAllocateGraphicsMemoryInDevicePool = true; auto device = std::make_unique(MockDevice::create(executionEnvironment, 0)); MockContext ctx(device.get()); - EXPECT_CALL(*memoryManager, allocateGraphicsMemoryInDevicePool(::testing::_, ::testing::_)) - .WillOnce(::testing::Invoke(memoryManager, &GMockMemoryManagerFailFirstAllocation::allocateNonSystemGraphicsMemoryInDevicePool)) - .WillRepeatedly(::testing::Invoke(memoryManager, &GMockMemoryManagerFailFirstAllocation::baseAllocateGraphicsMemoryInDevicePool)); cl_int retVal = 0; cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR; char memory[] = {1, 2, 3, 4, 5, 6, 7, 8}; auto taskCount = device->getGpgpuCommandStreamReceiver().peekLatestFlushedTaskCount(); + memoryManager->returnAllocateNonSystemGraphicsMemoryInDevicePool = true; std::unique_ptr buffer(Buffer::create(&ctx, flags, sizeof(memory), memory, retVal)); ASSERT_NE(nullptr, buffer.get()); auto taskCountSent = device->getGpgpuCommandStreamReceiver().peekLatestFlushedTaskCount(); diff --git a/opencl/test/unit_test/mem_obj/create_image_in_local_memory_tests.cpp b/opencl/test/unit_test/mem_obj/create_image_in_local_memory_tests.cpp index 36855cb86c..4e93037c3c 100644 --- a/opencl/test/unit_test/mem_obj/create_image_in_local_memory_tests.cpp +++ b/opencl/test/unit_test/mem_obj/create_image_in_local_memory_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021 Intel Corporation + * Copyright (C) 2021-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -36,11 +36,10 @@ class ImageInLocalMemoryTest : public testing::Test { executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(&inputPlatformDevice); executionEnvironment->rootDeviceEnvironments[0]->initGmm(); - gmockMemoryManager = new ::testing::NiceMock(true, *executionEnvironment); - executionEnvironment->memoryManager.reset(gmockMemoryManager); + mockMemoryManager = new MockMemoryManagerFailFirstAllocation(true, *executionEnvironment); + executionEnvironment->memoryManager.reset(mockMemoryManager); - ON_CALL(*gmockMemoryManager, allocateGraphicsMemoryInDevicePool(::testing::_, ::testing::_)) - .WillByDefault(::testing::Invoke(gmockMemoryManager, &GMockMemoryManagerFailFirstAllocation::baseAllocateGraphicsMemoryInDevicePool)); + mockMemoryManager->returnBaseAllocateGraphicsMemoryInDevicePool = true; device = std::make_unique(MockDevice::create(executionEnvironment, 0)); context = std::make_unique(device.get()); @@ -56,7 +55,7 @@ class ImageInLocalMemoryTest : public testing::Test { void TearDown() override {} - ::testing::NiceMock *gmockMemoryManager = nullptr; + MockMemoryManagerFailFirstAllocation *mockMemoryManager = nullptr; cl_image_desc imageDesc{}; cl_image_format imageFormat = {}; std::unique_ptr device; @@ -71,9 +70,6 @@ TEST_F(ImageInLocalMemoryTest, givenImageWithoutHostPtrWhenLocalMemoryIsEnabledT auto surfaceFormat = Image::getSurfaceFormatFromTable(flags, &imageFormat, context->getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); - EXPECT_CALL(*gmockMemoryManager, allocateGraphicsMemoryInDevicePool(::testing::_, ::testing::_)) - .WillRepeatedly(::testing::Invoke(gmockMemoryManager, &GMockMemoryManagerFailFirstAllocation::baseAllocateGraphicsMemoryInDevicePool)); - std::unique_ptr image(Image::create( context.get(), ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context->getDevice(0)->getDevice()), flags, 0, surfaceFormat, &imageDesc, memory, retVal)); @@ -85,7 +81,7 @@ TEST_F(ImageInLocalMemoryTest, givenImageWithoutHostPtrWhenLocalMemoryIsEnabledT EXPECT_LE(imageDesc.image_width * surfaceFormat->surfaceFormat.ImageElementSizeInBytes, imgGfxAlloc->getUnderlyingBufferSize()); EXPECT_EQ(GraphicsAllocation::AllocationType::IMAGE, imgGfxAlloc->getAllocationType()); EXPECT_FALSE(imgGfxAlloc->getDefaultGmm()->useSystemMemoryPool); - EXPECT_LT(GmmHelper::canonize(gmockMemoryManager->getGfxPartition(imgGfxAlloc->getRootDeviceIndex())->getHeapBase(HeapIndex::HEAP_STANDARD64KB)), imgGfxAlloc->getGpuAddress()); - EXPECT_GT(GmmHelper::canonize(gmockMemoryManager->getGfxPartition(imgGfxAlloc->getRootDeviceIndex())->getHeapLimit(HeapIndex::HEAP_STANDARD64KB)), imgGfxAlloc->getGpuAddress()); + EXPECT_LT(GmmHelper::canonize(mockMemoryManager->getGfxPartition(imgGfxAlloc->getRootDeviceIndex())->getHeapBase(HeapIndex::HEAP_STANDARD64KB)), imgGfxAlloc->getGpuAddress()); + EXPECT_GT(GmmHelper::canonize(mockMemoryManager->getGfxPartition(imgGfxAlloc->getRootDeviceIndex())->getHeapLimit(HeapIndex::HEAP_STANDARD64KB)), imgGfxAlloc->getGpuAddress()); EXPECT_EQ(0llu, imgGfxAlloc->getGpuBaseAddress()); } diff --git a/opencl/test/unit_test/mem_obj/image_tests.cpp b/opencl/test/unit_test/mem_obj/image_tests.cpp index 24a19aa8c5..6f861de557 100644 --- a/opencl/test/unit_test/mem_obj/image_tests.cpp +++ b/opencl/test/unit_test/mem_obj/image_tests.cpp @@ -1472,17 +1472,12 @@ TEST(ImageTest, givenClMemForceLinearStorageSetWhenCreateImageThenDisallowTiling TEST(ImageTest, givenClMemCopyHostPointerPassedToImageCreateWhenAllocationIsNotInSystemMemoryPoolThenAllocationIsWrittenByEnqueueWriteImage) { REQUIRE_IMAGES_OR_SKIP(defaultHwInfo); ExecutionEnvironment *executionEnvironment = platform()->peekExecutionEnvironment(); - auto *memoryManager = new ::testing::NiceMock(*executionEnvironment); + auto *memoryManager = new MockMemoryManagerFailFirstAllocation(*executionEnvironment); executionEnvironment->memoryManager.reset(memoryManager); - EXPECT_CALL(*memoryManager, allocateGraphicsMemoryInDevicePool(::testing::_, ::testing::_)) - .WillRepeatedly(::testing::Invoke(memoryManager, &GMockMemoryManagerFailFirstAllocation::baseAllocateGraphicsMemoryInDevicePool)); - + memoryManager->returnBaseAllocateGraphicsMemoryInDevicePool = true; auto device = std::make_unique(MockDevice::create(executionEnvironment, 0)); MockContext ctx(device.get()); - EXPECT_CALL(*memoryManager, allocateGraphicsMemoryInDevicePool(::testing::_, ::testing::_)) - .WillOnce(::testing::Invoke(memoryManager, &GMockMemoryManagerFailFirstAllocation::allocateNonSystemGraphicsMemoryInDevicePool)) - .WillRepeatedly(::testing::Invoke(memoryManager, &GMockMemoryManagerFailFirstAllocation::baseAllocateGraphicsMemoryInDevicePool)); char memory[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; auto taskCount = device->getGpgpuCommandStreamReceiver().peekLatestFlushedTaskCount(); @@ -1502,7 +1497,7 @@ TEST(ImageTest, givenClMemCopyHostPointerPassedToImageCreateWhenAllocationIsNotI MockContext context; auto surfaceFormat = Image::getSurfaceFormatFromTable( flags, &imageFormat, context.getDevice(0)->getHardwareInfo().capabilityTable.supportsOcl21Features); - + memoryManager->returnAllocateNonSystemGraphicsMemoryInDevicePool = true; std::unique_ptr image( Image::create(&ctx, ClMemoryPropertiesHelper::createMemoryProperties(flags, 0, 0, &context.getDevice(0)->getDevice()), flags, 0, surfaceFormat, &imageDesc, memory, retVal)); 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 c9368d1ab9..861d742e60 100644 --- a/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp +++ b/opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp @@ -571,45 +571,42 @@ HWTEST_F(Wddm20InstrumentationTest, WhenConfiguringDeviceAddressSpaceThenTrueIsR uintptr_t maxAddr = hwInfo.capabilityTable.gpuAddressSpace >= MemoryConstants::max64BitAppAddress ? reinterpret_cast(sysInfo.lpMaximumApplicationAddress) + 1 : 0; - EXPECT_CALL(*gmmMem, configureDeviceAddressSpace(adapterHandle, - deviceHandle, - wddm->getGdi()->escape.mFunc, - maxAddr, - FtrL3IACoherency)) - .Times(1) - .WillRepeatedly(::testing::Return(true)); + wddm->init(); + EXPECT_EQ(1u, gmmMem->configureDeviceAddressSpaceCalled); + EXPECT_EQ(adapterHandle, gmmMem->configureDeviceAddressSpaceParamsPassed[0].hAdapter); + EXPECT_EQ(deviceHandle, gmmMem->configureDeviceAddressSpaceParamsPassed[0].hDevice); + EXPECT_EQ(wddm->getGdi()->escape.mFunc, gmmMem->configureDeviceAddressSpaceParamsPassed[0].pfnEscape); + EXPECT_EQ(maxAddr, gmmMem->configureDeviceAddressSpaceParamsPassed[0].svmSize); + EXPECT_EQ(FtrL3IACoherency, gmmMem->configureDeviceAddressSpaceParamsPassed[0].bdwL3Coherency); } TEST_F(Wddm20InstrumentationTest, GivenNoAdapterWhenConfiguringDeviceAddressSpaceThenFalseIsReturned) { auto gdi = std::make_unique(); wddm->resetGdi(gdi.release()); - EXPECT_CALL(*gmmMem, - configureDeviceAddressSpace(static_cast(0), ::testing::_, ::testing::_, ::testing::_, ::testing::_)) - .Times(0); + auto ret = wddm->configureDeviceAddressSpace(); EXPECT_FALSE(ret); + EXPECT_EQ(0u, gmmMem->configureDeviceAddressSpaceCalled); } TEST_F(Wddm20InstrumentationTest, GivenNoDeviceWhenConfiguringDeviceAddressSpaceThenFalseIsReturned) { wddm->device = static_cast(0); - EXPECT_CALL(*gmmMem, - configureDeviceAddressSpace(::testing::_, static_cast(0), ::testing::_, ::testing::_, ::testing::_)) - .Times(0); + auto ret = wddm->configureDeviceAddressSpace(); EXPECT_FALSE(ret); + EXPECT_EQ(0u, gmmMem->configureDeviceAddressSpaceCalled); } TEST_F(Wddm20InstrumentationTest, GivenNoEscFuncWhenConfiguringDeviceAddressSpaceThenFalseIsReturned) { wddm->getGdi()->escape = static_cast(nullptr); - EXPECT_CALL(*gmmMem, configureDeviceAddressSpace(::testing::_, ::testing::_, static_cast(nullptr), ::testing::_, - ::testing::_)) - .Times(0); + auto ret = wddm->configureDeviceAddressSpace(); EXPECT_FALSE(ret); + EXPECT_EQ(0u, gmmMem->configureDeviceAddressSpaceCalled); } TEST_F(Wddm20Tests, WhenGettingMaxApplicationAddressThen32Or64BitIsCorrectlyReturned) { @@ -1337,41 +1334,26 @@ TEST_F(Wddm20WithMockGdiDllTests, whenSetDeviceInfoSucceedsThenDeviceCallbacksAr TEST_F(Wddm20WithMockGdiDllTests, whenSetDeviceInfoFailsThenDeviceIsNotConfigured) { - auto gmockGmmMemory = new ::testing::NiceMock(getGmmClientContext()); - ON_CALL(*gmockGmmMemory, setDeviceInfo(::testing::_)) - .WillByDefault(::testing::Return(false)); - EXPECT_CALL(*gmockGmmMemory, configureDeviceAddressSpace(::testing::_, - ::testing::_, - ::testing::_, - ::testing::_, - ::testing::_)) - .Times(0); + auto mockGmmMemory = new MockGmmMemoryBase(getGmmClientContext()); + mockGmmMemory->setDeviceInfoResult = false; - wddm->gmmMemory.reset(gmockGmmMemory); + wddm->gmmMemory.reset(mockGmmMemory); wddm->init(); + EXPECT_EQ(0u, mockGmmMemory->configureDeviceAddressSpaceCalled); } HWTEST_F(Wddm20WithMockGdiDllTests, givenNonGen12LPPlatformWhenConfigureDeviceAddressSpaceThenDontObtainMinAddress) { if (defaultHwInfo->platform.eRenderCoreFamily == IGFX_GEN12LP_CORE) { GTEST_SKIP(); } - auto gmmMemory = new ::testing::NiceMock(getGmmClientContext()); + auto gmmMemory = new MockGmmMemoryBase(getGmmClientContext()); wddm->gmmMemory.reset(gmmMemory); - ON_CALL(*gmmMemory, configureDeviceAddressSpace(::testing::_, - ::testing::_, - ::testing::_, - ::testing::_, - ::testing::_)) - .WillByDefault(::testing::Return(true)); - - EXPECT_CALL(*gmmMemory, - getInternalGpuVaRangeLimit()) - .Times(0); wddm->init(); EXPECT_EQ(NEO::windowsMinAddress, wddm->getWddmMinAddress()); + EXPECT_EQ(0u, gmmMemory->getInternalGpuVaRangeLimitCalled); } struct GdiWithMockedCloseFunc : public MockGdi { diff --git a/shared/test/common/mocks/mock_memory_manager.cpp b/shared/test/common/mocks/mock_memory_manager.cpp index 98ccad6947..c377d9c3a6 100644 --- a/shared/test/common/mocks/mock_memory_manager.cpp +++ b/shared/test/common/mocks/mock_memory_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2018-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -137,11 +137,6 @@ GraphicsAllocation *MockMemoryManager::allocate32BitGraphicsMemory(uint32_t root return allocate32BitGraphicsMemoryImpl(allocationData, useLocalMemory); } -GraphicsAllocation *MockMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(const AllocationData &allocationData) { - allocateGraphicsMemoryForNonSvmHostPtrCalled = true; - return OsAgnosticMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(allocationData); -} - GraphicsAllocation *MockMemoryManager::allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData, bool useLocalMemory) { allocate32BitGraphicsMemoryImplCalled = true; if (failAllocate32Bit) { diff --git a/shared/test/common/mocks/mock_memory_manager.h b/shared/test/common/mocks/mock_memory_manager.h index a1e00ff8be..104f639a5d 100644 --- a/shared/test/common/mocks/mock_memory_manager.h +++ b/shared/test/common/mocks/mock_memory_manager.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2018-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -11,6 +11,7 @@ #include "shared/test/common/helpers/default_hw_info.h" #include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/mocks/mock_host_ptr_manager.h" +#include "shared/test/common/test_macros/mock_method_macros.h" #include "gmock/gmock.h" @@ -134,7 +135,6 @@ class MockMemoryManager : public MemoryManagerCreate { GraphicsAllocation *allocate32BitGraphicsMemory(uint32_t rootDeviceIndex, size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType); GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData, bool useLocalMemory) override; - GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const AllocationData &allocationData) override; bool isLimitedGPU(uint32_t rootDeviceIndex) override { return limitedGPU; @@ -160,7 +160,33 @@ class MockMemoryManager : public MemoryManagerCreate { StackVec copyMemoryToAllocationBanksParamsPassed{}; bool copyMemoryToAllocationBanks(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy, DeviceBitfield handleMask) override; + MemoryManager::AllocationStatus populateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override { + populateOsHandlesCalled++; + populateOsHandlesParamsPassed.push_back({handleStorage, rootDeviceIndex}); + if (callBasePopulateOsHandles) { + populateOsHandlesResult = OsAgnosticMemoryManager::populateOsHandles(handleStorage, rootDeviceIndex); + } + return populateOsHandlesResult; + } + + struct PopulateOsHandlesParams { + OsHandleStorage handleStorage{}; + uint32_t rootDeviceIndex{}; + }; + + StackVec populateOsHandlesParamsPassed{}; + + GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const AllocationData &allocationData) override { + allocateGraphicsMemoryForNonSvmHostPtrCalled++; + if (callBaseAllocateGraphicsMemoryForNonSvmHostPtr) { + allocateGraphicsMemoryForNonSvmHostPtrResult = OsAgnosticMemoryManager::allocateGraphicsMemoryForNonSvmHostPtr(allocationData); + } + return allocateGraphicsMemoryForNonSvmHostPtrResult; + } + uint32_t copyMemoryToAllocationBanksCalled = 0u; + uint32_t populateOsHandlesCalled = 0u; + uint32_t allocateGraphicsMemoryForNonSvmHostPtrCalled = 0u; uint32_t freeGraphicsMemoryCalled = 0u; uint32_t unlockResourceCalled = 0u; uint32_t lockResourceCalled = 0u; @@ -182,7 +208,6 @@ class MockMemoryManager : public MemoryManagerCreate { bool preferCompressedFlagPassed = false; bool allocateForImageCalled = false; bool allocate32BitGraphicsMemoryImplCalled = false; - bool allocateGraphicsMemoryForNonSvmHostPtrCalled = false; bool allocateForShareableCalled = false; bool failReserveAddress = false; bool failAllocateSystemMemory = false; @@ -196,19 +221,14 @@ class MockMemoryManager : public MemoryManagerCreate { bool isMockEventPoolCreateMemoryManager = false; bool limitedGPU = false; bool returnFakeAllocation = false; + bool callBasePopulateOsHandles = true; + bool callBaseAllocateGraphicsMemoryForNonSvmHostPtr = true; std::unique_ptr mockExecutionEnvironment; DeviceBitfield recentlyPassedDeviceBitfield{}; std::unique_ptr waitAllocations = nullptr; MemAdviseFlags memAdviseFlags{}; -}; - -class GMockMemoryManager : public MockMemoryManager { - public: - GMockMemoryManager(const ExecutionEnvironment &executionEnvironment) : MockMemoryManager(const_cast(executionEnvironment)){}; - MOCK_METHOD2(populateOsHandles, MemoryManager::AllocationStatus(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex)); - MOCK_METHOD1(allocateGraphicsMemoryForNonSvmHostPtr, GraphicsAllocation *(const AllocationData &)); - - MemoryManager::AllocationStatus MemoryManagerPopulateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) { return OsAgnosticMemoryManager::populateOsHandles(handleStorage, rootDeviceIndex); } + MemoryManager::AllocationStatus populateOsHandlesResult = MemoryManager::AllocationStatus::Success; + GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtrResult = nullptr; }; class MockAllocSysMemAgnosticMemoryManager : public OsAgnosticMemoryManager { @@ -290,12 +310,33 @@ class FailMemoryManager : public MockMemoryManager { int32_t failedAllocationsCount = 0; }; -class GMockMemoryManagerFailFirstAllocation : public MockMemoryManager { +class MockMemoryManagerFailFirstAllocation : public MockMemoryManager { public: - GMockMemoryManagerFailFirstAllocation(bool enableLocalMemory, const ExecutionEnvironment &executionEnvironment) : MockMemoryManager(enableLocalMemory, const_cast(executionEnvironment)){}; - GMockMemoryManagerFailFirstAllocation(const ExecutionEnvironment &executionEnvironment) : GMockMemoryManagerFailFirstAllocation(false, executionEnvironment){}; + MockMemoryManagerFailFirstAllocation(bool enableLocalMemory, const ExecutionEnvironment &executionEnvironment) : MockMemoryManager(enableLocalMemory, const_cast(executionEnvironment)){}; + MockMemoryManagerFailFirstAllocation(const ExecutionEnvironment &executionEnvironment) : MockMemoryManagerFailFirstAllocation(false, executionEnvironment){}; + + GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override { + allocateGraphicsMemoryInDevicePoolCalled++; + if (returnNullptr) { + returnNullptr = false; + return nullptr; + } + if (returnAllocateNonSystemGraphicsMemoryInDevicePool) { + returnAllocateNonSystemGraphicsMemoryInDevicePool = false; + return allocateNonSystemGraphicsMemoryInDevicePool(allocationData, status); + } + if (returnBaseAllocateGraphicsMemoryInDevicePool) { + return baseAllocateGraphicsMemoryInDevicePool(allocationData, status); + } + return allocateGraphicsMemoryInDevicePoolResult; + } + + uint32_t allocateGraphicsMemoryInDevicePoolCalled = 0u; + GraphicsAllocation *allocateGraphicsMemoryInDevicePoolResult = nullptr; + bool returnNullptr = false; + bool returnBaseAllocateGraphicsMemoryInDevicePool = false; + bool returnAllocateNonSystemGraphicsMemoryInDevicePool = false; - MOCK_METHOD2(allocateGraphicsMemoryInDevicePool, GraphicsAllocation *(const AllocationData &, AllocationStatus &)); GraphicsAllocation *baseAllocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) { return OsAgnosticMemoryManager::allocateGraphicsMemoryInDevicePool(allocationData, status); } diff --git a/shared/test/common/mocks/mock_memory_operations_handler.h b/shared/test/common/mocks/mock_memory_operations_handler.h index bf70561c86..7551fd48df 100644 --- a/shared/test/common/mocks/mock_memory_operations_handler.h +++ b/shared/test/common/mocks/mock_memory_operations_handler.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2021 Intel Corporation + * Copyright (C) 2019-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -8,6 +8,7 @@ #pragma once #include "shared/source/memory_manager/memory_operations_handler.h" #include "shared/source/os_interface/os_context.h" +#include "shared/test/common/test_macros/mock_method_macros.h" #include "gmock/gmock.h" @@ -28,16 +29,11 @@ class MockMemoryOperationsHandler : public MemoryOperationsHandler { class MockMemoryOperationsHandlerTests : public MemoryOperationsHandler { public: MockMemoryOperationsHandlerTests() {} - MOCK_METHOD(MemoryOperationsStatus, makeResident, - (Device * device, ArrayRef gfxAllocations), (override)); - MOCK_METHOD(MemoryOperationsStatus, evict, - (Device * device, GraphicsAllocation &gfxAllocation), (override)); - MOCK_METHOD(MemoryOperationsStatus, isResident, - (Device * device, GraphicsAllocation &gfxAllocation), (override)); - MOCK_METHOD(MemoryOperationsStatus, makeResidentWithinOsContext, - (OsContext * osContext, ArrayRef gfxAllocations, bool evictable), (override)); - MOCK_METHOD(MemoryOperationsStatus, evictWithinOsContext, - (OsContext * osContext, GraphicsAllocation &gfxAllocation), (override)); + ADDMETHOD_NOBASE(makeResident, MemoryOperationsStatus, MemoryOperationsStatus::UNSUPPORTED, (Device * device, ArrayRef gfxAllocations)); + ADDMETHOD_NOBASE(evict, MemoryOperationsStatus, MemoryOperationsStatus::UNSUPPORTED, (Device * device, GraphicsAllocation &gfxAllocation)); + ADDMETHOD_NOBASE(isResident, MemoryOperationsStatus, MemoryOperationsStatus::UNSUPPORTED, (Device * device, GraphicsAllocation &gfxAllocation)); + ADDMETHOD_NOBASE(makeResidentWithinOsContext, MemoryOperationsStatus, MemoryOperationsStatus::UNSUPPORTED, (OsContext * osContext, ArrayRef gfxAllocations, bool evictable)); + ADDMETHOD_NOBASE(evictWithinOsContext, MemoryOperationsStatus, MemoryOperationsStatus::UNSUPPORTED, (OsContext * osContext, GraphicsAllocation &gfxAllocation)); }; class MockMemoryOperations : public MemoryOperationsHandler { diff --git a/shared/test/common/mocks/windows/mock_gmm_memory_base.h b/shared/test/common/mocks/windows/mock_gmm_memory_base.h index c8cf2c44dd..26752a0b65 100644 --- a/shared/test/common/mocks/windows/mock_gmm_memory_base.h +++ b/shared/test/common/mocks/windows/mock_gmm_memory_base.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2021 Intel Corporation + * Copyright (C) 2018-2022 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,6 +7,8 @@ #pragma once #include "shared/source/os_interface/windows/windows_defs.h" +#include "shared/source/utilities/stackvec.h" +#include "shared/test/common/test_macros/mock_method_macros.h" #include "gmm_memory.h" #include "gmock/gmock.h" @@ -24,50 +26,43 @@ class MockGmmMemoryBase : public GmmMemory { GMM_ESCAPE_FUNC_TYPE pfnEscape, GMM_GFX_SIZE_T svmSize, BOOLEAN bdwL3Coherency) override { - return true; + configureDeviceAddressSpaceCalled++; + configureDeviceAddressSpaceParamsPassed.push_back({hAdapter, + hDevice, + pfnEscape, + svmSize, + bdwL3Coherency}); + return configureDeviceAddressSpaceResult; } + struct ConfigureDeviceAddressSpaceParams { + GMM_ESCAPE_HANDLE hAdapter{}; + GMM_ESCAPE_HANDLE hDevice{}; + GMM_ESCAPE_FUNC_TYPE pfnEscape{}; + GMM_GFX_SIZE_T svmSize{}; + BOOLEAN bdwL3Coherency{}; + }; + + uint32_t configureDeviceAddressSpaceCalled = 0u; + bool configureDeviceAddressSpaceResult = true; + StackVec configureDeviceAddressSpaceParamsPassed{}; + void overrideInternalGpuVaRangeLimit(uintptr_t value) { - this->internalGpuVaRangeLimit = value; + this->getInternalGpuVaRangeLimitResult = value; } - uintptr_t getInternalGpuVaRangeLimit() override { - return internalGpuVaRangeLimit; - } + ADDMETHOD_NOBASE(getInternalGpuVaRangeLimit, uintptr_t, NEO::windowsMinAddress, ()); bool setDeviceInfo(GMM_DEVICE_INFO *deviceInfo) override { + setDeviceInfoCalled++; partition = deviceInfo->pGfxPartition; deviceCallbacks = *deviceInfo->pDeviceCb; - return setDeviceInfoValue; + return setDeviceInfoResult; } + uint32_t setDeviceInfoCalled = 0u; + bool setDeviceInfoResult = true; GMM_GFX_PARTITIONING *partition = nullptr; - bool setDeviceInfoValue = true; - uintptr_t internalGpuVaRangeLimit = NEO::windowsMinAddress; GMM_DEVICE_CALLBACKS_INT deviceCallbacks{}; }; - -class GmockGmmMemory : public GmmMemory { - public: - ~GmockGmmMemory() = default; - - GmockGmmMemory(GmmClientContext *gmmClientContext) : GmmMemory(gmmClientContext) { - ON_CALL(*this, getInternalGpuVaRangeLimit()) - .WillByDefault(::testing::Return(NEO::windowsMinAddress)); - - ON_CALL(*this, setDeviceInfo(::testing::_)) - .WillByDefault(::testing::Return(true)); - } - - MOCK_METHOD0(getInternalGpuVaRangeLimit, uintptr_t()); - - MOCK_METHOD1(setDeviceInfo, bool(GMM_DEVICE_INFO *)); - - MOCK_METHOD5(configureDeviceAddressSpace, - bool(GMM_ESCAPE_HANDLE hAdapter, - GMM_ESCAPE_HANDLE hDevice, - GMM_ESCAPE_FUNC_TYPE pfnEscape, - GMM_GFX_SIZE_T svmSize, - BOOLEAN bdwL3Coherency)); -}; } // namespace NEO diff --git a/shared/test/common/os_interface/windows/wddm_fixture.h b/shared/test/common/os_interface/windows/wddm_fixture.h index 232827d952..0b88acf3c5 100644 --- a/shared/test/common/os_interface/windows/wddm_fixture.h +++ b/shared/test/common/os_interface/windows/wddm_fixture.h @@ -147,7 +147,7 @@ struct WddmInstrumentationGmmFixture : DeviceFixture { executionEnvironment = pDevice->getExecutionEnvironment(); auto rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[0].get(); wddm = static_cast(Wddm::createWddm(nullptr, *rootDeviceEnvironment)); - gmmMem = new ::testing::NiceMock(rootDeviceEnvironment->getGmmClientContext()); + gmmMem = new MockGmmMemoryBase(rootDeviceEnvironment->getGmmClientContext()); wddm->gmmMemory.reset(gmmMem); rootDeviceEnvironment->osInterface = std::make_unique(); rootDeviceEnvironment->osInterface->setDriverModel(std::unique_ptr(wddm)); @@ -157,7 +157,7 @@ struct WddmInstrumentationGmmFixture : DeviceFixture { } WddmMock *wddm; - GmockGmmMemory *gmmMem = nullptr; + MockGmmMemoryBase *gmmMem = nullptr; ExecutionEnvironment *executionEnvironment; }; diff --git a/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp b/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp index 078ac95ac1..0314a75e33 100644 --- a/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp +++ b/shared/test/unit_test/command_stream/command_stream_receiver_tests.cpp @@ -1227,14 +1227,14 @@ TEST(CommandStreamReceiverMultiContextTests, givenMultipleCsrsWhenSameResourcesA struct CreateAllocationForHostSurfaceTest : public ::testing::Test { void SetUp() override { executionEnvironment.incRefInternal(); - gmockMemoryManager = new ::testing::NiceMock(executionEnvironment); - executionEnvironment.memoryManager.reset(gmockMemoryManager); + mockMemoryManager = new MockMemoryManager(executionEnvironment); + executionEnvironment.memoryManager.reset(mockMemoryManager); device.reset(MockDevice::createWithExecutionEnvironment(&hwInfo, &executionEnvironment, 0u)); commandStreamReceiver = &device->getGpgpuCommandStreamReceiver(); } MockExecutionEnvironment executionEnvironment; HardwareInfo hwInfo = *defaultHwInfo; - GMockMemoryManager *gmockMemoryManager = nullptr; + MockMemoryManager *mockMemoryManager = nullptr; std::unique_ptr device; CommandStreamReceiver *commandStreamReceiver = nullptr; }; @@ -1276,15 +1276,16 @@ TEST_F(CreateAllocationForHostSurfaceTest, givenReadOnlyHostPointerWhenAllocatio const char memory[8] = {1, 2, 3, 4, 5, 6, 7, 8}; size_t size = sizeof(memory); HostPtrSurface surface(const_cast(memory), size, true); + mockMemoryManager->callBasePopulateOsHandles = false; + mockMemoryManager->callBaseAllocateGraphicsMemoryForNonSvmHostPtr = false; + bool runPopulateOsHandlesExpects = false; + bool runAllocateGraphicsMemoryForNonSvmHostPtrExpects = false; - if (!gmockMemoryManager->useNonSvmHostPtrAlloc(GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR, device->getRootDeviceIndex())) { - EXPECT_CALL(*gmockMemoryManager, populateOsHandles(::testing::_, device->getRootDeviceIndex())) - .Times(1) - .WillOnce(::testing::Return(MemoryManager::AllocationStatus::InvalidHostPointer)); + if (!mockMemoryManager->useNonSvmHostPtrAlloc(GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR, device->getRootDeviceIndex())) { + runPopulateOsHandlesExpects = true; + mockMemoryManager->populateOsHandlesResult = MemoryManager::AllocationStatus::InvalidHostPointer; } else { - EXPECT_CALL(*gmockMemoryManager, allocateGraphicsMemoryForNonSvmHostPtr(::testing::_)) - .Times(1) - .WillOnce(::testing::Return(nullptr)); + runAllocateGraphicsMemoryForNonSvmHostPtrExpects = true; } bool result = commandStreamReceiver->createAllocationForHostSurface(surface, false); @@ -1297,21 +1298,30 @@ TEST_F(CreateAllocationForHostSurfaceTest, givenReadOnlyHostPointerWhenAllocatio EXPECT_THAT(allocation->getUnderlyingBuffer(), MemCompare(memory, size)); allocation->updateTaskCount(commandStreamReceiver->peekLatestFlushedTaskCount(), commandStreamReceiver->getOsContext().getContextId()); + + if (runPopulateOsHandlesExpects) { + EXPECT_EQ(1u, mockMemoryManager->populateOsHandlesCalled); + EXPECT_EQ(device->getRootDeviceIndex(), mockMemoryManager->populateOsHandlesParamsPassed[0].rootDeviceIndex); + } + if (runAllocateGraphicsMemoryForNonSvmHostPtrExpects) { + EXPECT_EQ(1u, mockMemoryManager->allocateGraphicsMemoryForNonSvmHostPtrCalled); + } } TEST_F(CreateAllocationForHostSurfaceTest, givenReadOnlyHostPointerWhenAllocationForHostSurfaceWithPtrCopyNotAllowedIsCreatedThenCopyAllocationIsNotCreated) { const char memory[8] = {1, 2, 3, 4, 5, 6, 7, 8}; size_t size = sizeof(memory); HostPtrSurface surface(const_cast(memory), size, false); + mockMemoryManager->callBasePopulateOsHandles = false; + mockMemoryManager->callBaseAllocateGraphicsMemoryForNonSvmHostPtr = false; + bool runPopulateOsHandlesExpects = false; + bool runAllocateGraphicsMemoryForNonSvmHostPtrExpects = false; - if (!gmockMemoryManager->useNonSvmHostPtrAlloc(GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR, device->getRootDeviceIndex())) { - EXPECT_CALL(*gmockMemoryManager, populateOsHandles(::testing::_, device->getRootDeviceIndex())) - .Times(1) - .WillOnce(::testing::Return(MemoryManager::AllocationStatus::InvalidHostPointer)); + if (!mockMemoryManager->useNonSvmHostPtrAlloc(GraphicsAllocation::AllocationType::EXTERNAL_HOST_PTR, device->getRootDeviceIndex())) { + runPopulateOsHandlesExpects = true; + mockMemoryManager->populateOsHandlesResult = MemoryManager::AllocationStatus::InvalidHostPointer; } else { - EXPECT_CALL(*gmockMemoryManager, allocateGraphicsMemoryForNonSvmHostPtr(::testing::_)) - .Times(1) - .WillOnce(::testing::Return(nullptr)); + runAllocateGraphicsMemoryForNonSvmHostPtrExpects = true; } bool result = commandStreamReceiver->createAllocationForHostSurface(surface, false); @@ -1319,6 +1329,14 @@ TEST_F(CreateAllocationForHostSurfaceTest, givenReadOnlyHostPointerWhenAllocatio auto allocation = surface.getAllocation(); EXPECT_EQ(nullptr, allocation); + + if (runPopulateOsHandlesExpects) { + EXPECT_EQ(1u, mockMemoryManager->populateOsHandlesCalled); + EXPECT_EQ(device->getRootDeviceIndex(), mockMemoryManager->populateOsHandlesParamsPassed[0].rootDeviceIndex); + } + if (runAllocateGraphicsMemoryForNonSvmHostPtrExpects) { + EXPECT_EQ(1u, mockMemoryManager->allocateGraphicsMemoryForNonSvmHostPtrCalled); + } } struct ReducedAddrSpaceCommandStreamReceiverTest : public CreateAllocationForHostSurfaceTest { @@ -1333,16 +1351,14 @@ TEST_F(ReducedAddrSpaceCommandStreamReceiverTest, if (is32bit) { GTEST_SKIP(); } + mockMemoryManager->callBaseAllocateGraphicsMemoryForNonSvmHostPtr = false; + mockMemoryManager->callBasePopulateOsHandles = false; char memory[8] = {}; HostPtrSurface surface(memory, sizeof(memory), false); - - EXPECT_CALL(*gmockMemoryManager, allocateGraphicsMemoryForNonSvmHostPtr(::testing::_)) - .Times(1) - .WillOnce(::testing::Return(nullptr)); - bool result = commandStreamReceiver->createAllocationForHostSurface(surface, false); EXPECT_FALSE(result); + EXPECT_EQ(1u, mockMemoryManager->allocateGraphicsMemoryForNonSvmHostPtrCalled); } TEST_F(CommandStreamReceiverTest, givenMinimumSizeDoesNotExceedCurrentWhenCallingEnsureCommandBufferAllocationThenDoNotReallocate) {