1 /* 2 * Copyright (C) 2020-2021 Intel Corporation 3 * 4 * SPDX-License-Identifier: MIT 5 * 6 */ 7 8 #include "shared/source/execution_environment/root_device_environment.h" 9 #include "shared/source/gmm_helper/gmm_helper.h" 10 #include "shared/source/os_interface/device_factory.h" 11 #include "shared/source/os_interface/os_interface.h" 12 #include "shared/test/common/fixtures/device_fixture.h" 13 #include "shared/test/common/helpers/debug_manager_state_restore.h" 14 #include "shared/test/common/mocks/mock_wddm.h" 15 #include "shared/test/common/os_interface/windows/mock_wddm_memory_manager.h" 16 #include "shared/test/common/test_macros/test.h" 17 18 namespace NEO { 19 20 class WddmMemManagerFixture { 21 public: 22 struct FrontWindowMemManagerMock : public MockWddmMemoryManager { 23 using MemoryManager::allocate32BitGraphicsMemoryImpl; FrontWindowMemManagerMockNEO::WddmMemManagerFixture::FrontWindowMemManagerMock24 FrontWindowMemManagerMock(NEO::ExecutionEnvironment &executionEnvironment) : MockWddmMemoryManager(executionEnvironment) {} 25 }; 26 SetUp()27 void SetUp() { 28 DebugManagerStateRestore dbgRestorer; 29 DebugManager.flags.UseExternalAllocatorForSshAndDsh.set(true); 30 executionEnvironment = std::make_unique<ExecutionEnvironment>(); 31 executionEnvironment->prepareRootDeviceEnvironments(1); 32 executionEnvironment->rootDeviceEnvironments[0]->setHwInfo(defaultHwInfo.get()); 33 DeviceFactory::prepareDeviceEnvironments(*executionEnvironment); 34 auto wddm = static_cast<WddmMock *>(executionEnvironment->rootDeviceEnvironments[0]->osInterface->getDriverModel()->as<Wddm>()); 35 wddm->callBaseMapGpuVa = false; 36 memManager = std::unique_ptr<FrontWindowMemManagerMock>(new FrontWindowMemManagerMock(*executionEnvironment)); 37 } TearDown()38 void TearDown() { 39 } 40 std::unique_ptr<FrontWindowMemManagerMock> memManager; 41 std::unique_ptr<ExecutionEnvironment> executionEnvironment; 42 }; 43 44 using WddmFrontWindowPoolAllocatorTests = Test<WddmMemManagerFixture>; 45 TEST_F(WddmFrontWindowPoolAllocatorTests,givenAllocateInFrontWindowPoolFlagWhenWddmAllocate32BitGraphicsMemoryThenAllocateAtHeapBegining)46TEST_F(WddmFrontWindowPoolAllocatorTests, givenAllocateInFrontWindowPoolFlagWhenWddmAllocate32BitGraphicsMemoryThenAllocateAtHeapBegining) { 47 AllocationData allocData = {}; 48 allocData.flags.use32BitFrontWindow = true; 49 allocData.size = MemoryConstants::kiloByte; 50 auto allocation = memManager->allocate32BitGraphicsMemoryImpl(allocData, false); 51 EXPECT_EQ(allocation->getGpuBaseAddress(), GmmHelper::canonize(allocation->getGpuAddress())); 52 memManager->freeGraphicsMemory(allocation); 53 } 54 } // namespace NEO