/* * Copyright (C) 2018-2019 Intel Corporation * * SPDX-License-Identifier: MIT * */ #pragma once #include "runtime/aub/aub_center.h" #include "runtime/command_stream/preemption.h" #include "runtime/command_stream/tbx_command_stream_receiver_hw.h" #include "runtime/execution_environment/execution_environment.h" #include "runtime/helpers/hw_info.h" #include "gmock/gmock.h" #include namespace NEO { template class MockTbxCsrToTestWaitBeforeMakingNonResident : public TbxCommandStreamReceiverHw { public: using CommandStreamReceiver::latestFlushedTaskCount; MockTbxCsrToTestWaitBeforeMakingNonResident(ExecutionEnvironment &executionEnvironment) : TbxCommandStreamReceiverHw(executionEnvironment) {} void makeCoherent(GraphicsAllocation &gfxAllocation) override { auto tagAddress = reinterpret_cast(gfxAllocation.getUnderlyingBuffer()); *tagAddress = this->latestFlushedTaskCount; makeCoherentCalled = true; } bool makeCoherentCalled = false; }; template class MockTbxCsr : public TbxCommandStreamReceiverHw { public: using TbxCommandStreamReceiverHw::writeMemory; MockTbxCsr(ExecutionEnvironment &executionEnvironment) : TbxCommandStreamReceiverHw(executionEnvironment) {} void initializeEngine() { TbxCommandStreamReceiverHw::initializeEngine(); initializeEngineCalled = true; } void writeMemoryWithAubManager(GraphicsAllocation &graphicsAllocation) override { CommandStreamReceiverSimulatedHw::writeMemoryWithAubManager(graphicsAllocation); writeMemoryWithAubManagerCalled = true; } void writeMemory(uint64_t gpuAddress, void *cpuAddress, size_t size, uint32_t memoryBank, uint64_t entryBits) override { TbxCommandStreamReceiverHw::writeMemory(gpuAddress, cpuAddress, size, memoryBank, entryBits); writeMemoryCalled = true; } void submitBatchBuffer(uint64_t batchBufferGpuAddress, const void *batchBuffer, size_t batchBufferSize, uint32_t memoryBank, uint64_t entryBits) override { TbxCommandStreamReceiverHw::submitBatchBuffer(batchBufferGpuAddress, batchBuffer, batchBufferSize, memoryBank, entryBits); submitBatchBufferCalled = true; } void pollForCompletion() override { TbxCommandStreamReceiverHw::pollForCompletion(); pollForCompletionCalled = true; } void makeCoherent(GraphicsAllocation &gfxAllocation) override { TbxCommandStreamReceiverHw::makeCoherent(gfxAllocation); makeCoherentCalled = true; } bool initializeEngineCalled = false; bool writeMemoryWithAubManagerCalled = false; bool writeMemoryCalled = false; bool submitBatchBufferCalled = false; bool pollForCompletionCalled = false; bool expectMemoryEqualCalled = false; bool expectMemoryNotEqualCalled = false; bool makeCoherentCalled = false; }; struct TbxExecutionEnvironment { std::unique_ptr executionEnvironment; GraphicsAllocation *commandBuffer = nullptr; template CsrType *getCsr() { return static_cast(executionEnvironment->commandStreamReceivers[0][0].get()); } ~TbxExecutionEnvironment() { if (commandBuffer) { executionEnvironment->memoryManager->freeGraphicsMemory(commandBuffer); } } }; template std::unique_ptr getEnvironment(bool createTagAllocation, bool allocateCommandBuffer) { std::unique_ptr executionEnvironment(new ExecutionEnvironment); executionEnvironment->aubCenter.reset(new AubCenter()); executionEnvironment->commandStreamReceivers.resize(1); executionEnvironment->commandStreamReceivers[0].push_back(std::make_unique(*platformDevices[0], *executionEnvironment)); executionEnvironment->initializeMemoryManager(); if (createTagAllocation) { executionEnvironment->commandStreamReceivers[0][0]->initializeTagAllocation(); } auto osContext = executionEnvironment->memoryManager->createAndRegisterOsContext(executionEnvironment->commandStreamReceivers[0][0].get(), getChosenEngineType(*platformDevices[0]), 1, PreemptionHelper::getDefaultPreemptionMode(*platformDevices[0]), false); executionEnvironment->commandStreamReceivers[0][0]->setupContext(*osContext); std::unique_ptr tbxExecutionEnvironment(new TbxExecutionEnvironment); if (allocateCommandBuffer) { tbxExecutionEnvironment->commandBuffer = executionEnvironment->memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}); } tbxExecutionEnvironment->executionEnvironment = std::move(executionEnvironment); return tbxExecutionEnvironment; } } // namespace NEO