/* * Copyright (C) 2018-2021 Intel Corporation * * SPDX-License-Identifier: MIT * */ #pragma once #include "shared/source/command_stream/preemption.h" #include "shared/source/execution_environment/execution_environment.h" #include "shared/source/execution_environment/root_device_environment.h" #include "shared/source/helpers/hw_helper.h" #include "shared/source/os_interface/os_interface.h" #include "shared/source/os_interface/windows/gdi_interface.h" #include "shared/source/os_interface/windows/os_context_win.h" #include "shared/source/os_interface/windows/os_environment_win.h" #include "shared/source/os_interface/windows/wddm_memory_operations_handler.h" #include "shared/test/common/fixtures/device_fixture.h" #include "shared/test/common/fixtures/mock_execution_environment_gmm_fixture.h" #include "shared/test/common/helpers/default_hw_info.h" #include "shared/test/common/helpers/engine_descriptor_helper.h" #include "shared/test/common/mocks/mock_execution_environment.h" #include "shared/test/common/mocks/mock_wddm.h" #include "shared/test/common/mocks/mock_wddm_interface20.h" #include "shared/test/common/mocks/mock_wddm_residency_allocations_container.h" #include "shared/test/common/os_interface/windows/gdi_dll_fixture.h" #include "shared/test/unit_test/os_interface/windows/mock_gdi_interface.h" #include "test.h" #include "mock_gmm_memory.h" namespace NEO { struct WddmFixture : public Test { void SetUp() override { MockExecutionEnvironmentGmmFixture::SetUp(); rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[0].get(); auto osEnvironment = new OsEnvironmentWin(); gdi = new MockGdi(); osEnvironment->gdi.reset(gdi); executionEnvironment->osEnvironment.reset(osEnvironment); wddm = static_cast(Wddm::createWddm(nullptr, *rootDeviceEnvironment)); rootDeviceEnvironment->osInterface = std::make_unique(); rootDeviceEnvironment->osInterface->setDriverModel(std::unique_ptr(wddm)); rootDeviceEnvironment->memoryOperationsInterface = std::make_unique(wddm); osInterface = rootDeviceEnvironment->osInterface.get(); auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo); wddm->init(); auto hwInfo = rootDeviceEnvironment->getHardwareInfo(); auto engine = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*hwInfo)[0]; osContext = std::make_unique(*osInterface->getDriverModel()->as(), 0u, EngineDescriptorHelper::getDefaultDescriptor(engine, preemptionMode)); osContext->ensureContextInitialized(); mockTemporaryResources = static_cast(wddm->temporaryResources.get()); } WddmMock *wddm = nullptr; OSInterface *osInterface; RootDeviceEnvironment *rootDeviceEnvironment = nullptr; std::unique_ptr osContext; MockGdi *gdi = nullptr; MockWddmResidentAllocationsContainer *mockTemporaryResources; }; struct WddmFixtureWithMockGdiDll : public GdiDllFixture, public MockExecutionEnvironmentGmmFixture { void SetUp() override { MockExecutionEnvironmentGmmFixture::SetUp(); GdiDllFixture::SetUp(); rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[0].get(); wddm = static_cast(Wddm::createWddm(nullptr, *rootDeviceEnvironment)); wddmMockInterface = new WddmMockInterface20(*wddm); wddm->wddmInterface.reset(wddmMockInterface); rootDeviceEnvironment->osInterface = std::make_unique(); rootDeviceEnvironment->osInterface->setDriverModel(std::unique_ptr(wddm)); rootDeviceEnvironment->memoryOperationsInterface = std::make_unique(wddm); osInterface = rootDeviceEnvironment->osInterface.get(); } void init() { auto preemptionMode = PreemptionHelper::getDefaultPreemptionMode(*defaultHwInfo); wddmMockInterface = static_cast(wddm->wddmInterface.release()); wddm->init(); wddm->wddmInterface.reset(wddmMockInterface); auto hwInfo = rootDeviceEnvironment->getHardwareInfo(); auto engine = HwHelper::get(defaultHwInfo->platform.eRenderCoreFamily).getGpgpuEngineInstances(*hwInfo)[0]; osContext = std::make_unique(*osInterface->getDriverModel()->as(), 0u, EngineDescriptorHelper::getDefaultDescriptor(engine, preemptionMode)); osContext->ensureContextInitialized(); } void TearDown() override { GdiDllFixture::TearDown(); } WddmMock *wddm = nullptr; OSInterface *osInterface; std::unique_ptr osContext; WddmMockInterface20 *wddmMockInterface = nullptr; RootDeviceEnvironment *rootDeviceEnvironment = nullptr; }; struct WddmInstrumentationGmmFixture : DeviceFixture { void SetUp() { DeviceFixture::SetUp(); executionEnvironment = pDevice->getExecutionEnvironment(); auto rootDeviceEnvironment = executionEnvironment->rootDeviceEnvironments[0].get(); wddm = static_cast(Wddm::createWddm(nullptr, *rootDeviceEnvironment)); gmmMem = new ::testing::NiceMock(rootDeviceEnvironment->getGmmClientContext()); wddm->gmmMemory.reset(gmmMem); rootDeviceEnvironment->osInterface = std::make_unique(); rootDeviceEnvironment->osInterface->setDriverModel(std::unique_ptr(wddm)); } void TearDown() { DeviceFixture::TearDown(); } WddmMock *wddm; GmockGmmMemory *gmmMem = nullptr; ExecutionEnvironment *executionEnvironment; }; using WddmTest = WddmFixture; using WddmTestWithMockGdiDll = Test; using WddmInstrumentationTest = Test; using WddmTestSingle = ::testing::Test; } // namespace NEO