diff --git a/runtime/command_stream/aub_center.h b/runtime/command_stream/aub_center.h index 67c27a0de9..78532d9328 100644 --- a/runtime/command_stream/aub_center.h +++ b/runtime/command_stream/aub_center.h @@ -7,6 +7,7 @@ #pragma once #include "runtime/command_stream/aub_stream_provider.h" +#include "runtime/memory_manager/address_mapper.h" #include "runtime/memory_manager/physical_address_allocator.h" namespace OCLRT { @@ -14,6 +15,7 @@ namespace OCLRT { class AubCenter { public: AubCenter() { + addressMapper = std::make_unique(); streamProvider = std::make_unique(); } virtual ~AubCenter() = default; @@ -26,12 +28,17 @@ class AubCenter { return physicalAddressAllocator.get(); } + AddressMapper *getAddressMapper() const { + return addressMapper.get(); + } + AubStreamProvider *getStreamProvider() const { return streamProvider.get(); } protected: std::unique_ptr physicalAddressAllocator; + std::unique_ptr addressMapper; std::unique_ptr streamProvider; }; } // namespace OCLRT diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.h b/runtime/command_stream/aub_command_stream_receiver_hw.h index ace4c669a2..5499b704e9 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.h +++ b/runtime/command_stream/aub_command_stream_receiver_hw.h @@ -62,7 +62,7 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw::type> ppgtt; std::unique_ptr ggtt; // remap CPU VA -> GGTT VA - AddressMapper gttRemap; + AddressMapper *gttRemap; MOCKABLE_VIRTUAL bool addPatchInfoComments(); void addGUCStartMessage(uint64_t batchBufferAddress, EngineType engineType); diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.inl b/runtime/command_stream/aub_command_stream_receiver_hw.inl index 89aeaacc27..78dc147d3b 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.inl +++ b/runtime/command_stream/aub_command_stream_receiver_hw.inl @@ -46,6 +46,9 @@ AUBCommandStreamReceiverHw::AUBCommandStreamReceiverHw(const Hardware ppgtt = std::make_unique::type>(physicalAddressAllocator); ggtt = std::make_unique(physicalAddressAllocator); + gttRemap = aubCenter->getAddressMapper(); + UNRECOVERABLE_IF(nullptr == gttRemap); + auto streamProvider = aubCenter->getStreamProvider(); UNRECOVERABLE_IF(nullptr == streamProvider); @@ -143,7 +146,7 @@ void AUBCommandStreamReceiverHw::closeFile() { } template -bool AUBCommandStreamReceiverHw::isFileOpen() { +bool AUBCommandStreamReceiverHw::isFileOpen() const { return stream->isOpen(); } @@ -165,7 +168,7 @@ void AUBCommandStreamReceiverHw::initializeEngine(EngineType engineTy const size_t sizeHWSP = 0x1000; const size_t alignHWSP = 0x1000; engineInfo.pGlobalHWStatusPage = alignedMalloc(sizeHWSP, alignHWSP); - engineInfo.ggttHWSP = gttRemap.map(engineInfo.pGlobalHWStatusPage, sizeHWSP); + engineInfo.ggttHWSP = gttRemap->map(engineInfo.pGlobalHWStatusPage, sizeHWSP); auto physHWSP = ggtt->map(engineInfo.ggttHWSP, sizeHWSP, this->getGTTBits(), getMemoryBankForGtt()); @@ -197,7 +200,7 @@ void AUBCommandStreamReceiverHw::initializeEngine(EngineType engineTy { const size_t alignRingBuffer = 0x1000; engineInfo.pRingBuffer = alignedMalloc(engineInfo.sizeRingBuffer, alignRingBuffer); - engineInfo.ggttRingBuffer = gttRemap.map(engineInfo.pRingBuffer, engineInfo.sizeRingBuffer); + engineInfo.ggttRingBuffer = gttRemap->map(engineInfo.pRingBuffer, engineInfo.sizeRingBuffer); auto physRingBuffer = ggtt->map(engineInfo.ggttRingBuffer, engineInfo.sizeRingBuffer, this->getGTTBits(), getMemoryBankForGtt()); { @@ -225,7 +228,7 @@ void AUBCommandStreamReceiverHw::initializeEngine(EngineType engineTy // Write our LRCA { - engineInfo.ggttLRCA = gttRemap.map(engineInfo.pLRCA, sizeLRCA); + engineInfo.ggttLRCA = gttRemap->map(engineInfo.pLRCA, sizeLRCA); auto lrcAddressPhys = ggtt->map(engineInfo.ggttLRCA, sizeLRCA, this->getGTTBits(), getMemoryBankForGtt()); { @@ -254,15 +257,15 @@ template void AUBCommandStreamReceiverHw::freeEngineInfoTable() { for (auto &engineInfo : engineInfoTable) { alignedFree(engineInfo.pLRCA); - gttRemap.unmap(engineInfo.pLRCA); + gttRemap->unmap(engineInfo.pLRCA); engineInfo.pLRCA = nullptr; alignedFree(engineInfo.pGlobalHWStatusPage); - gttRemap.unmap(engineInfo.pGlobalHWStatusPage); + gttRemap->unmap(engineInfo.pGlobalHWStatusPage); engineInfo.pGlobalHWStatusPage = nullptr; alignedFree(engineInfo.pRingBuffer); - gttRemap.unmap(engineInfo.pRingBuffer); + gttRemap->unmap(engineInfo.pRingBuffer); engineInfo.pRingBuffer = nullptr; } } diff --git a/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp b/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp index 8d1195b484..5d0932d89d 100644 --- a/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp +++ b/unit_tests/command_stream/aub_command_stream_receiver_tests.cpp @@ -7,17 +7,16 @@ #include "runtime/aub_mem_dump/aub_mem_dump.h" #include "runtime/aub_mem_dump/page_table_entry_bits.h" -#include "runtime/command_stream/aub_command_stream_receiver_hw.h" #include "runtime/helpers/array_count.h" #include "runtime/helpers/dispatch_info.h" #include "runtime/helpers/flat_batch_buffer_helper_hw.h" -#include "runtime/helpers/hw_info.h" #include "runtime/memory_manager/memory_banks.h" #include "runtime/memory_manager/memory_manager.h" #include "runtime/os_interface/debug_settings_manager.h" #include "test.h" #include "unit_tests/fixtures/device_fixture.h" #include "unit_tests/helpers/debug_manager_state_restore.h" +#include "unit_tests/mocks/mock_aub_csr.h" #include "unit_tests/mocks/mock_aub_file_stream.h" #include "unit_tests/mocks/mock_aub_subcapture_manager.h" #include "unit_tests/mocks/mock_csr.h" @@ -28,11 +27,6 @@ #include #include -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Winconsistent-missing-override" -#endif - using namespace OCLRT; using ::testing::_; @@ -41,54 +35,6 @@ using ::testing::Return; typedef Test AubCommandStreamReceiverTests; -template -struct MockAubCsr : public AUBCommandStreamReceiverHw { - MockAubCsr(const HardwareInfo &hwInfoIn, const std::string &fileName, bool standalone, ExecutionEnvironment &executionEnvironment) - : AUBCommandStreamReceiverHw(hwInfoIn, fileName, standalone, executionEnvironment){}; - - DispatchMode peekDispatchMode() const { - return this->dispatchMode; - } - - GraphicsAllocation *getTagAllocation() const { - return this->tagAllocation; - } - - void setLatestSentTaskCount(uint32_t latestSentTaskCount) { - this->latestSentTaskCount = latestSentTaskCount; - } - - void flushBatchedSubmissions() override { - flushBatchedSubmissionsCalled = true; - } - void initProgrammingFlags() override { - initProgrammingFlagsCalled = true; - } - bool flushBatchedSubmissionsCalled = false; - bool initProgrammingFlagsCalled = false; - - void initFile(const std::string &fileName) override { - fileIsOpen = true; - openFileName = fileName; - } - void closeFile() override { - fileIsOpen = false; - openFileName = ""; - } - bool isFileOpen() override { - return fileIsOpen; - } - const std::string &getFileName() override { - return openFileName; - } - bool fileIsOpen = false; - std::string openFileName = ""; - - MOCK_METHOD0(addPatchInfoComments, bool(void)); - - using CommandStreamReceiverHw::localMemoryEnabled; -}; - template struct MockAubCsrToTestDumpAubNonWritable : public AUBCommandStreamReceiverHw { using AUBCommandStreamReceiverHw::AUBCommandStreamReceiverHw; @@ -99,42 +45,6 @@ struct MockAubCsrToTestDumpAubNonWritable : public AUBCommandStreamReceiverHw executionEnvironment; - GraphicsAllocation *commandBuffer = nullptr; - template - CsrType *getCsr() { - return static_cast(executionEnvironment->commandStreamReceivers[0u].get()); - } - ~AubExecutionEnvironment() { - if (commandBuffer) { - executionEnvironment->memoryManager->freeGraphicsMemory(commandBuffer); - } - } -}; - -template -std::unique_ptr getEnvironment(bool createTagAllocation, bool allocateCommandBuffer, bool standalone) { - std::unique_ptr executionEnvironment(new ExecutionEnvironment); - executionEnvironment->commandStreamReceivers.push_back(std::make_unique(*platformDevices[0], "", standalone, *executionEnvironment)); - executionEnvironment->memoryManager.reset(executionEnvironment->commandStreamReceivers[0u]->createMemoryManager(false, false)); - executionEnvironment->commandStreamReceivers[0u]->setMemoryManager(executionEnvironment->memoryManager.get()); - if (createTagAllocation) { - executionEnvironment->commandStreamReceivers[0u]->initializeTagAllocation(); - } - - std::unique_ptr aubExecutionEnvironment(new AubExecutionEnvironment); - if (allocateCommandBuffer) { - aubExecutionEnvironment->commandBuffer = executionEnvironment->memoryManager->allocateGraphicsMemory(4096); - } - aubExecutionEnvironment->executionEnvironment = std::move(executionEnvironment); - return aubExecutionEnvironment; -} - TEST_F(AubCommandStreamReceiverTests, givenStructureWhenMisalignedUint64ThenUseSetterGetterFunctionsToSetGetValue) { const uint64_t value = 0x0123456789ABCDEFu; AubMemDump::AubCaptureBinaryDumpHD aubCaptureBinaryDumpHD{}; @@ -225,6 +135,17 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipl EXPECT_EQ(physicalAddressAlocator1, physicalAddressAlocator2); } +HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipleInstancesAreCreatedThenTheyUseTheSameAddressMapper) { + ExecutionEnvironment executionEnvironment; + auto aubCsr1 = std::make_unique>(**platformDevices, "", true, executionEnvironment); + auto addressMapper1 = executionEnvironment.aubCenter->getAddressMapper(); + EXPECT_NE(nullptr, addressMapper1); + auto aubCsr2 = std::make_unique>(**platformDevices, "", true, executionEnvironment); + auto addressMapper2 = executionEnvironment.aubCenter->getAddressMapper(); + EXPECT_NE(nullptr, addressMapper2); + EXPECT_EQ(addressMapper1, addressMapper2); +} + HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverInSubCaptureModeWhenItIsCreatedThenFileIsNotCreated) { DebugManagerStateRestore stateRestore; DebugManager.flags.AUBDumpSubCaptureMode.set(static_cast(AubSubCaptureManager::SubCaptureMode::Filter)); @@ -256,72 +177,6 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCsrInSubCaptureModeWhenItIsCreat EXPECT_STREQ(DebugManager.flags.AUBDumpFilterKernelName.get().c_str(), aubCsr->subCaptureManager->subCaptureFilter.dumpKernelName.c_str()); } -HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenFileStreamShouldBeLocked) { - auto aubExecutionEnvironment = getEnvironment>(true, true, true); - auto aubCsr = aubExecutionEnvironment->template getCsr>(); - LinearStream cs(aubExecutionEnvironment->commandBuffer); - - std::unique_ptr mockAubFileStream(new MockAubFileStream()); - MockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); - ASSERT_NE(nullptr, mockAubFileStreamPtr); - aubCsr->stream = mockAubFileStreamPtr; - - BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - auto engineType = OCLRT::ENGINE_RCS; - ResidencyContainer allocationsForResidency = {}; - - aubCsr->flush(batchBuffer, engineType, allocationsForResidency, *pDevice->getOsContext()); - EXPECT_TRUE(mockAubFileStreamPtr->lockStreamCalled); -} - -HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenExpectMemoryIsCalledThenPageWalkIsCallingStreamsExpectMemory) { - auto aubCsr = std::make_unique>(**platformDevices, "", true, *pDevice->executionEnvironment); - - std::unique_ptr mockAubFileStream(std::make_unique()); - MockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); - ASSERT_NE(nullptr, mockAubFileStreamPtr); - aubCsr->stream = mockAubFileStreamPtr; - - uintptr_t gpuAddress = 0x30000; - void *sourceAddress = reinterpret_cast(0x50000); - auto physicalAddress = aubCsr->ppgtt->map(gpuAddress, MemoryConstants::pageSize, PageTableEntry::presentBit, MemoryBanks::MainBank); - - aubCsr->expectMemory(reinterpret_cast(gpuAddress), sourceAddress, MemoryConstants::pageSize); - - EXPECT_EQ(AubMemDump::AddressSpaceValues::TraceNonlocal, mockAubFileStreamPtr->addressSpaceCapturedFromExpectMemory); - EXPECT_EQ(reinterpret_cast(sourceAddress), mockAubFileStreamPtr->memoryCapturedFromExpectMemory); - EXPECT_EQ(physicalAddress, mockAubFileStreamPtr->physAddressCapturedFromExpectMemory); - EXPECT_EQ(MemoryConstants::pageSize, mockAubFileStreamPtr->sizeCapturedFromExpectMemory); -} - -HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenExpectMMIOIsCalledThenHeaderIsWrittenToFile) { - std::string fileName = "file_name.aub"; - auto aubCsr = std::make_unique>(**platformDevices, fileName.c_str(), true, *pDevice->executionEnvironment); - - std::remove(fileName.c_str()); - - std::unique_ptr mockAubFileStream(std::make_unique()); - MockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); - ASSERT_NE(nullptr, mockAubFileStreamPtr); - aubCsr->stream = mockAubFileStreamPtr; - aubCsr->initFile(fileName); - - aubCsr->expectMMIO(5, 10); - - aubCsr->stream->fileHandle.flush(); - - std::ifstream aubFile(fileName); - EXPECT_TRUE(aubFile.is_open()); - - if (aubFile.is_open()) { - AubMemDump::CmdServicesMemTraceRegisterCompare header; - aubFile.read(reinterpret_cast(&header), sizeof(AubMemDump::CmdServicesMemTraceRegisterCompare)); - EXPECT_EQ(5u, header.registerOffset); - EXPECT_EQ(10u, header.data[0]); - aubFile.close(); - } -} - HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWhenMakeResidentCalledMultipleTimesAffectsResidencyOnce) { std::unique_ptr memoryManager(nullptr); std::unique_ptr> aubCsr(new AUBCommandStreamReceiverHw(*platformDevices[0], "", true, *pDevice->executionEnvironment)); @@ -355,6 +210,23 @@ HWTEST_F(AubCommandStreamReceiverTests, givenGraphicsAllocationWhenMakeResidentC memoryManager->freeGraphicsMemoryImpl(gfxAllocation); } +HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenMultipleInstancesInitializeTheirEnginesThenUniqueGlobalGttAdressesAreGenerated) { + ExecutionEnvironment executionEnvironment; + auto aubCsr1 = std::make_unique>(**platformDevices, "", true, executionEnvironment); + auto aubCsr2 = std::make_unique>(**platformDevices, "", true, executionEnvironment); + auto engineType = OCLRT::ENGINE_RCS; + + aubCsr1->initializeEngine(engineType); + EXPECT_NE(0u, aubCsr1->engineInfoTable[engineType].ggttLRCA); + EXPECT_NE(0u, aubCsr1->engineInfoTable[engineType].ggttHWSP); + EXPECT_NE(0u, aubCsr1->engineInfoTable[engineType].ggttRingBuffer); + + aubCsr2->initializeEngine(engineType); + EXPECT_NE(aubCsr1->engineInfoTable[engineType].ggttLRCA, aubCsr2->engineInfoTable[engineType].ggttLRCA); + EXPECT_NE(aubCsr1->engineInfoTable[engineType].ggttHWSP, aubCsr2->engineInfoTable[engineType].ggttHWSP); + EXPECT_NE(aubCsr1->engineInfoTable[engineType].ggttRingBuffer, aubCsr2->engineInfoTable[engineType].ggttRingBuffer); +} + HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenItShouldInitializeEngineInfoTable) { auto aubExecutionEnvironment = getEnvironment>(true, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); @@ -1434,265 +1306,6 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenAddPatc aubCsr->flush(batchBuffer, engineType, allocationsForResidency, *pDevice->getOsContext()); } -HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenNoPatchInfoDataObjectsThenCommentsAreEmpty) { - auto aubExecutionEnvironment = getEnvironment>(false, true, true); - auto aubCsr = aubExecutionEnvironment->template getCsr>(); - LinearStream cs(aubExecutionEnvironment->commandBuffer); - - BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 128u, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - - std::unique_ptr mockAubFileStream(new GmockAubFileStream()); - GmockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); - ASSERT_NE(nullptr, mockAubFileStreamPtr); - aubCsr->stream = mockAubFileStreamPtr; - - std::vector comments; - - EXPECT_CALL(*mockAubFileStreamPtr, addComment(_)).Times(2).WillRepeatedly(::testing::Invoke([&](const char *str) -> bool { - comments.push_back(std::string(str)); - return true; - })); - bool result = aubCsr->addPatchInfoComments(); - EXPECT_TRUE(result); - - ASSERT_EQ(2u, comments.size()); - - EXPECT_EQ("PatchInfoData\n", comments[0]); - EXPECT_EQ("AllocationsList\n", comments[1]); -} - -HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenFileStreamShouldBeFlushed) { - auto aubExecutionEnvironment = getEnvironment>(true, true, true); - auto aubCsr = aubExecutionEnvironment->template getCsr>(); - LinearStream cs(aubExecutionEnvironment->commandBuffer); - - std::unique_ptr mockAubFileStream(new MockAubFileStream()); - MockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); - ASSERT_NE(nullptr, mockAubFileStreamPtr); - aubCsr->stream = mockAubFileStreamPtr; - - BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - auto engineType = OCLRT::ENGINE_RCS; - ResidencyContainer allocationsForResidency = {}; - - aubCsr->flush(batchBuffer, engineType, allocationsForResidency, *pDevice->getOsContext()); - EXPECT_TRUE(mockAubFileStreamPtr->flushCalled); -} - -HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenFirstAddCommentsFailsThenFunctionReturnsFalse) { - auto aubExecutionEnvironment = getEnvironment>(false, true, true); - auto aubCsr = aubExecutionEnvironment->template getCsr>(); - LinearStream cs(aubExecutionEnvironment->commandBuffer); - - BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 128u, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - - std::unique_ptr mockAubFileStream(new GmockAubFileStream()); - GmockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); - ASSERT_NE(nullptr, mockAubFileStreamPtr); - aubCsr->stream = mockAubFileStreamPtr; - - EXPECT_CALL(*mockAubFileStreamPtr, addComment(_)).Times(1).WillOnce(Return(false)); - bool result = aubCsr->addPatchInfoComments(); - EXPECT_FALSE(result); -} - -HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenSecondAddCommentsFailsThenFunctionReturnsFalse) { - auto aubExecutionEnvironment = getEnvironment>(false, true, true); - auto aubCsr = aubExecutionEnvironment->template getCsr>(); - LinearStream cs(aubExecutionEnvironment->commandBuffer); - - BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 128u, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - - std::unique_ptr mockAubFileStream(new GmockAubFileStream()); - GmockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); - ASSERT_NE(nullptr, mockAubFileStreamPtr); - aubCsr->stream = mockAubFileStreamPtr; - - EXPECT_CALL(*mockAubFileStreamPtr, addComment(_)).Times(2).WillOnce(Return(true)).WillOnce(Return(false)); - bool result = aubCsr->addPatchInfoComments(); - EXPECT_FALSE(result); -} - -HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenPatchInfoDataObjectsAddedThenCommentsAreNotEmpty) { - auto aubExecutionEnvironment = getEnvironment>(false, true, true); - auto aubCsr = aubExecutionEnvironment->template getCsr>(); - LinearStream cs(aubExecutionEnvironment->commandBuffer); - - BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 128u, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - - std::unique_ptr mockAubFileStream(new GmockAubFileStream()); - GmockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); - ASSERT_NE(nullptr, mockAubFileStreamPtr); - aubCsr->stream = mockAubFileStreamPtr; - - PatchInfoData patchInfoData[2] = {{0xAAAAAAAA, 128u, PatchInfoAllocationType::Default, 0xBBBBBBBB, 256u, PatchInfoAllocationType::Default}, - {0xBBBBBBBB, 128u, PatchInfoAllocationType::Default, 0xDDDDDDDD, 256u, PatchInfoAllocationType::Default}}; - - EXPECT_TRUE(aubCsr->getFlatBatchBufferHelper().setPatchInfoData(patchInfoData[0])); - EXPECT_TRUE(aubCsr->getFlatBatchBufferHelper().setPatchInfoData(patchInfoData[1])); - - std::vector comments; - - EXPECT_CALL(*mockAubFileStreamPtr, addComment(_)).Times(2).WillRepeatedly(::testing::Invoke([&](const char *str) -> bool { - comments.push_back(std::string(str)); - return true; - })); - bool result = aubCsr->addPatchInfoComments(); - EXPECT_TRUE(result); - - ASSERT_EQ(2u, comments.size()); - - EXPECT_EQ("PatchInfoData", comments[0].substr(0, 13)); - EXPECT_EQ("AllocationsList", comments[1].substr(0, 15)); - - std::string line; - std::istringstream input1; - input1.str(comments[0]); - - uint32_t lineNo = 0; - while (std::getline(input1, line)) { - if (line.substr(0, 13) == "PatchInfoData") { - continue; - } - std::ostringstream ss; - ss << std::hex << patchInfoData[lineNo].sourceAllocation << ";" << patchInfoData[lineNo].sourceAllocationOffset << ";" << patchInfoData[lineNo].sourceType << ";"; - ss << patchInfoData[lineNo].targetAllocation << ";" << patchInfoData[lineNo].targetAllocationOffset << ";" << patchInfoData[lineNo].targetType << ";"; - - EXPECT_EQ(ss.str(), line); - lineNo++; - } - - std::vector expectedAddresses = {"aaaaaaaa", "bbbbbbbb", "cccccccc", "dddddddd"}; - lineNo = 0; - - std::istringstream input2; - input2.str(comments[1]); - while (std::getline(input2, line)) { - if (line.substr(0, 15) == "AllocationsList") { - continue; - } - - bool foundAddr = false; - for (auto &addr : expectedAddresses) { - if (line.substr(0, 8) == addr) { - foundAddr = true; - break; - } - } - EXPECT_TRUE(foundAddr); - EXPECT_TRUE(line.size() > 9); - lineNo++; - } -} - -HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenSourceAllocationIsNullThenDoNotAddToAllocationsList) { - auto aubExecutionEnvironment = getEnvironment>(false, true, true); - auto aubCsr = aubExecutionEnvironment->template getCsr>(); - LinearStream cs(aubExecutionEnvironment->commandBuffer); - - BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 128u, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - - std::unique_ptr mockAubFileStream(new GmockAubFileStream()); - GmockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); - ASSERT_NE(nullptr, mockAubFileStreamPtr); - aubCsr->stream = mockAubFileStreamPtr; - - PatchInfoData patchInfoData = {0x0, 0u, PatchInfoAllocationType::Default, 0xBBBBBBBB, 0u, PatchInfoAllocationType::Default}; - EXPECT_TRUE(aubCsr->getFlatBatchBufferHelper().setPatchInfoData(patchInfoData)); - - std::vector comments; - - EXPECT_CALL(*mockAubFileStreamPtr, addComment(_)).Times(2).WillRepeatedly(::testing::Invoke([&](const char *str) -> bool { - comments.push_back(std::string(str)); - return true; - })); - bool result = aubCsr->addPatchInfoComments(); - EXPECT_TRUE(result); - - ASSERT_EQ(2u, comments.size()); - - ASSERT_EQ("PatchInfoData", comments[0].substr(0, 13)); - ASSERT_EQ("AllocationsList", comments[1].substr(0, 15)); - - std::string line; - std::istringstream input; - input.str(comments[1]); - - uint32_t lineNo = 0; - - std::vector expectedAddresses = {"bbbbbbbb"}; - while (std::getline(input, line)) { - if (line.substr(0, 15) == "AllocationsList") { - continue; - } - - bool foundAddr = false; - for (auto &addr : expectedAddresses) { - if (line.substr(0, 8) == addr) { - foundAddr = true; - break; - } - } - EXPECT_TRUE(foundAddr); - EXPECT_TRUE(line.size() > 9); - lineNo++; - } -} - -HWTEST_F(AubCommandStreamReceiverTests, givenAddPatchInfoCommentsCalledWhenTargetAllocationIsNullThenDoNotAddToAllocationsList) { - auto aubExecutionEnvironment = getEnvironment>(false, true, true); - auto aubCsr = aubExecutionEnvironment->template getCsr>(); - LinearStream cs(aubExecutionEnvironment->commandBuffer); - - BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 128u, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; - - std::unique_ptr mockAubFileStream(new GmockAubFileStream()); - GmockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); - ASSERT_NE(nullptr, mockAubFileStreamPtr); - aubCsr->stream = mockAubFileStreamPtr; - - PatchInfoData patchInfoData = {0xAAAAAAAA, 0u, PatchInfoAllocationType::Default, 0x0, 0u, PatchInfoAllocationType::Default}; - EXPECT_TRUE(aubCsr->getFlatBatchBufferHelper().setPatchInfoData(patchInfoData)); - - std::vector comments; - - EXPECT_CALL(*mockAubFileStreamPtr, addComment(_)).Times(2).WillRepeatedly(::testing::Invoke([&](const char *str) -> bool { - comments.push_back(std::string(str)); - return true; - })); - bool result = aubCsr->addPatchInfoComments(); - EXPECT_TRUE(result); - - ASSERT_EQ(2u, comments.size()); - - ASSERT_EQ("PatchInfoData", comments[0].substr(0, 13)); - ASSERT_EQ("AllocationsList", comments[1].substr(0, 15)); - - std::string line; - std::istringstream input; - input.str(comments[1]); - - uint32_t lineNo = 0; - - std::vector expectedAddresses = {"aaaaaaaa"}; - while (std::getline(input, line)) { - if (line.substr(0, 15) == "AllocationsList") { - continue; - } - - bool foundAddr = false; - for (auto &addr : expectedAddresses) { - if (line.substr(0, 8) == addr) { - foundAddr = true; - break; - } - } - EXPECT_TRUE(foundAddr); - EXPECT_TRUE(line.size() > 9); - lineNo++; - } -} - HWTEST_F(AubCommandStreamReceiverTests, givenAubCommandStreamReceiverWhenGetIndirectPatchCommandsIsCalledForEmptyPatchInfoListThenIndirectPatchCommandBufferIsNotCreated) { auto aubExecutionEnvironment = getEnvironment>(false, false, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); @@ -2021,7 +1634,3 @@ HWTEST_F(AubCommandStreamReceiverTests, whenAubCommandStreamReceiverIsCreatedThe physicalAddress = aubCsr->ggtt->map(address, MemoryConstants::pageSize, 0, MemoryBanks::MainBank); EXPECT_NE(0u, physicalAddress); } - -#if defined(__clang__) -#pragma clang diagnostic pop -#endif diff --git a/unit_tests/command_stream/aub_file_stream_tests.cpp b/unit_tests/command_stream/aub_file_stream_tests.cpp index 1383c39cb0..dd38293eb9 100644 --- a/unit_tests/command_stream/aub_file_stream_tests.cpp +++ b/unit_tests/command_stream/aub_file_stream_tests.cpp @@ -5,19 +5,16 @@ * */ +#include "runtime/aub_mem_dump/page_table_entry_bits.h" #include "runtime/command_stream/aub_command_stream_receiver_hw.h" #include "test.h" #include "unit_tests/fixtures/device_fixture.h" +#include "unit_tests/mocks/mock_aub_csr.h" #include "unit_tests/mocks/mock_aub_file_stream.h" #include #include -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Winconsistent-missing-override" -#endif - using namespace OCLRT; using ::testing::_; @@ -102,6 +99,327 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenReopenFileIsCalled EXPECT_TRUE(mockAubFileStreamPtr->lockStreamCalled); } -#if defined(__clang__) -#pragma clang diagnostic pop -#endif +HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenFileStreamShouldBeLocked) { + auto aubExecutionEnvironment = getEnvironment>(true, true, true); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + LinearStream cs(aubExecutionEnvironment->commandBuffer); + + std::unique_ptr mockAubFileStream(new MockAubFileStream()); + MockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); + ASSERT_NE(nullptr, mockAubFileStreamPtr); + aubCsr->stream = mockAubFileStreamPtr; + + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; + auto engineType = OCLRT::ENGINE_RCS; + ResidencyContainer allocationsForResidency = {}; + + aubCsr->flush(batchBuffer, engineType, allocationsForResidency, *pDevice->getOsContext()); + EXPECT_TRUE(mockAubFileStreamPtr->lockStreamCalled); +} + +HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenFileStreamShouldBeFlushed) { + auto aubExecutionEnvironment = getEnvironment>(true, true, true); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + LinearStream cs(aubExecutionEnvironment->commandBuffer); + + std::unique_ptr mockAubFileStream(new MockAubFileStream()); + MockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); + ASSERT_NE(nullptr, mockAubFileStreamPtr); + aubCsr->stream = mockAubFileStreamPtr; + + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; + auto engineType = OCLRT::ENGINE_RCS; + ResidencyContainer allocationsForResidency = {}; + + aubCsr->flush(batchBuffer, engineType, allocationsForResidency, *pDevice->getOsContext()); + EXPECT_TRUE(mockAubFileStreamPtr->flushCalled); +} + +HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenExpectMemoryIsCalledThenPageWalkIsCallingStreamsExpectMemory) { + auto aubCsr = std::make_unique>(**platformDevices, "", true, *pDevice->executionEnvironment); + + std::unique_ptr mockAubFileStream(std::make_unique()); + MockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); + ASSERT_NE(nullptr, mockAubFileStreamPtr); + aubCsr->stream = mockAubFileStreamPtr; + + uintptr_t gpuAddress = 0x30000; + void *sourceAddress = reinterpret_cast(0x50000); + auto physicalAddress = aubCsr->ppgtt->map(gpuAddress, MemoryConstants::pageSize, PageTableEntry::presentBit, MemoryBanks::MainBank); + + aubCsr->expectMemory(reinterpret_cast(gpuAddress), sourceAddress, MemoryConstants::pageSize); + + EXPECT_EQ(AubMemDump::AddressSpaceValues::TraceNonlocal, mockAubFileStreamPtr->addressSpaceCapturedFromExpectMemory); + EXPECT_EQ(reinterpret_cast(sourceAddress), mockAubFileStreamPtr->memoryCapturedFromExpectMemory); + EXPECT_EQ(physicalAddress, mockAubFileStreamPtr->physAddressCapturedFromExpectMemory); + EXPECT_EQ(MemoryConstants::pageSize, mockAubFileStreamPtr->sizeCapturedFromExpectMemory); +} + +HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenExpectMMIOIsCalledThenHeaderIsWrittenToFile) { + std::string fileName = "file_name.aub"; + auto aubCsr = std::make_unique>(**platformDevices, fileName.c_str(), true, *pDevice->executionEnvironment); + + std::remove(fileName.c_str()); + + std::unique_ptr mockAubFileStream(std::make_unique()); + MockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); + ASSERT_NE(nullptr, mockAubFileStreamPtr); + aubCsr->stream = mockAubFileStreamPtr; + aubCsr->initFile(fileName); + + aubCsr->expectMMIO(5, 10); + + aubCsr->stream->fileHandle.flush(); + + std::ifstream aubFile(fileName); + EXPECT_TRUE(aubFile.is_open()); + + if (aubFile.is_open()) { + AubMemDump::CmdServicesMemTraceRegisterCompare header; + aubFile.read(reinterpret_cast(&header), sizeof(AubMemDump::CmdServicesMemTraceRegisterCompare)); + EXPECT_EQ(5u, header.registerOffset); + EXPECT_EQ(10u, header.data[0]); + aubFile.close(); + } +} + +HWTEST_F(AubFileStreamTests, givenAddPatchInfoCommentsCalledWhenNoPatchInfoDataObjectsThenCommentsAreEmpty) { + auto aubExecutionEnvironment = getEnvironment>(false, true, true); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + LinearStream cs(aubExecutionEnvironment->commandBuffer); + + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 128u, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; + + std::unique_ptr mockAubFileStream(new GmockAubFileStream()); + GmockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); + ASSERT_NE(nullptr, mockAubFileStreamPtr); + aubCsr->stream = mockAubFileStreamPtr; + + std::vector comments; + + EXPECT_CALL(*mockAubFileStreamPtr, addComment(_)).Times(2).WillRepeatedly(::testing::Invoke([&](const char *str) -> bool { + comments.push_back(std::string(str)); + return true; + })); + bool result = aubCsr->addPatchInfoComments(); + EXPECT_TRUE(result); + + ASSERT_EQ(2u, comments.size()); + + EXPECT_EQ("PatchInfoData\n", comments[0]); + EXPECT_EQ("AllocationsList\n", comments[1]); +} + +HWTEST_F(AubFileStreamTests, givenAddPatchInfoCommentsCalledWhenFirstAddCommentsFailsThenFunctionReturnsFalse) { + auto aubExecutionEnvironment = getEnvironment>(false, true, true); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + LinearStream cs(aubExecutionEnvironment->commandBuffer); + + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 128u, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; + + std::unique_ptr mockAubFileStream(new GmockAubFileStream()); + GmockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); + ASSERT_NE(nullptr, mockAubFileStreamPtr); + aubCsr->stream = mockAubFileStreamPtr; + + EXPECT_CALL(*mockAubFileStreamPtr, addComment(_)).Times(1).WillOnce(Return(false)); + bool result = aubCsr->addPatchInfoComments(); + EXPECT_FALSE(result); +} + +HWTEST_F(AubFileStreamTests, givenAddPatchInfoCommentsCalledWhenSecondAddCommentsFailsThenFunctionReturnsFalse) { + auto aubExecutionEnvironment = getEnvironment>(false, true, true); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + LinearStream cs(aubExecutionEnvironment->commandBuffer); + + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 128u, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; + + std::unique_ptr mockAubFileStream(new GmockAubFileStream()); + GmockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); + ASSERT_NE(nullptr, mockAubFileStreamPtr); + aubCsr->stream = mockAubFileStreamPtr; + + EXPECT_CALL(*mockAubFileStreamPtr, addComment(_)).Times(2).WillOnce(Return(true)).WillOnce(Return(false)); + bool result = aubCsr->addPatchInfoComments(); + EXPECT_FALSE(result); +} + +HWTEST_F(AubFileStreamTests, givenAddPatchInfoCommentsCalledWhenPatchInfoDataObjectsAddedThenCommentsAreNotEmpty) { + auto aubExecutionEnvironment = getEnvironment>(false, true, true); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + LinearStream cs(aubExecutionEnvironment->commandBuffer); + + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 128u, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; + + std::unique_ptr mockAubFileStream(new GmockAubFileStream()); + GmockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); + ASSERT_NE(nullptr, mockAubFileStreamPtr); + aubCsr->stream = mockAubFileStreamPtr; + + PatchInfoData patchInfoData[2] = {{0xAAAAAAAA, 128u, PatchInfoAllocationType::Default, 0xBBBBBBBB, 256u, PatchInfoAllocationType::Default}, + {0xBBBBBBBB, 128u, PatchInfoAllocationType::Default, 0xDDDDDDDD, 256u, PatchInfoAllocationType::Default}}; + + EXPECT_TRUE(aubCsr->getFlatBatchBufferHelper().setPatchInfoData(patchInfoData[0])); + EXPECT_TRUE(aubCsr->getFlatBatchBufferHelper().setPatchInfoData(patchInfoData[1])); + + std::vector comments; + + EXPECT_CALL(*mockAubFileStreamPtr, addComment(_)).Times(2).WillRepeatedly(::testing::Invoke([&](const char *str) -> bool { + comments.push_back(std::string(str)); + return true; + })); + bool result = aubCsr->addPatchInfoComments(); + EXPECT_TRUE(result); + + ASSERT_EQ(2u, comments.size()); + + EXPECT_EQ("PatchInfoData", comments[0].substr(0, 13)); + EXPECT_EQ("AllocationsList", comments[1].substr(0, 15)); + + std::string line; + std::istringstream input1; + input1.str(comments[0]); + + uint32_t lineNo = 0; + while (std::getline(input1, line)) { + if (line.substr(0, 13) == "PatchInfoData") { + continue; + } + std::ostringstream ss; + ss << std::hex << patchInfoData[lineNo].sourceAllocation << ";" << patchInfoData[lineNo].sourceAllocationOffset << ";" << patchInfoData[lineNo].sourceType << ";"; + ss << patchInfoData[lineNo].targetAllocation << ";" << patchInfoData[lineNo].targetAllocationOffset << ";" << patchInfoData[lineNo].targetType << ";"; + + EXPECT_EQ(ss.str(), line); + lineNo++; + } + + std::vector expectedAddresses = {"aaaaaaaa", "bbbbbbbb", "cccccccc", "dddddddd"}; + lineNo = 0; + + std::istringstream input2; + input2.str(comments[1]); + while (std::getline(input2, line)) { + if (line.substr(0, 15) == "AllocationsList") { + continue; + } + + bool foundAddr = false; + for (auto &addr : expectedAddresses) { + if (line.substr(0, 8) == addr) { + foundAddr = true; + break; + } + } + EXPECT_TRUE(foundAddr); + EXPECT_TRUE(line.size() > 9); + lineNo++; + } +} + +HWTEST_F(AubFileStreamTests, givenAddPatchInfoCommentsCalledWhenSourceAllocationIsNullThenDoNotAddToAllocationsList) { + auto aubExecutionEnvironment = getEnvironment>(false, true, true); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + LinearStream cs(aubExecutionEnvironment->commandBuffer); + + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 128u, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; + + std::unique_ptr mockAubFileStream(new GmockAubFileStream()); + GmockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); + ASSERT_NE(nullptr, mockAubFileStreamPtr); + aubCsr->stream = mockAubFileStreamPtr; + + PatchInfoData patchInfoData = {0x0, 0u, PatchInfoAllocationType::Default, 0xBBBBBBBB, 0u, PatchInfoAllocationType::Default}; + EXPECT_TRUE(aubCsr->getFlatBatchBufferHelper().setPatchInfoData(patchInfoData)); + + std::vector comments; + + EXPECT_CALL(*mockAubFileStreamPtr, addComment(_)).Times(2).WillRepeatedly(::testing::Invoke([&](const char *str) -> bool { + comments.push_back(std::string(str)); + return true; + })); + bool result = aubCsr->addPatchInfoComments(); + EXPECT_TRUE(result); + + ASSERT_EQ(2u, comments.size()); + + ASSERT_EQ("PatchInfoData", comments[0].substr(0, 13)); + ASSERT_EQ("AllocationsList", comments[1].substr(0, 15)); + + std::string line; + std::istringstream input; + input.str(comments[1]); + + uint32_t lineNo = 0; + + std::vector expectedAddresses = {"bbbbbbbb"}; + while (std::getline(input, line)) { + if (line.substr(0, 15) == "AllocationsList") { + continue; + } + + bool foundAddr = false; + for (auto &addr : expectedAddresses) { + if (line.substr(0, 8) == addr) { + foundAddr = true; + break; + } + } + EXPECT_TRUE(foundAddr); + EXPECT_TRUE(line.size() > 9); + lineNo++; + } +} + +HWTEST_F(AubFileStreamTests, givenAddPatchInfoCommentsCalledWhenTargetAllocationIsNullThenDoNotAddToAllocationsList) { + auto aubExecutionEnvironment = getEnvironment>(false, true, true); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + LinearStream cs(aubExecutionEnvironment->commandBuffer); + + BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 128u, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs}; + + std::unique_ptr mockAubFileStream(new GmockAubFileStream()); + GmockAubFileStream *mockAubFileStreamPtr = static_cast(mockAubFileStream.get()); + ASSERT_NE(nullptr, mockAubFileStreamPtr); + aubCsr->stream = mockAubFileStreamPtr; + + PatchInfoData patchInfoData = {0xAAAAAAAA, 0u, PatchInfoAllocationType::Default, 0x0, 0u, PatchInfoAllocationType::Default}; + EXPECT_TRUE(aubCsr->getFlatBatchBufferHelper().setPatchInfoData(patchInfoData)); + + std::vector comments; + + EXPECT_CALL(*mockAubFileStreamPtr, addComment(_)).Times(2).WillRepeatedly(::testing::Invoke([&](const char *str) -> bool { + comments.push_back(std::string(str)); + return true; + })); + bool result = aubCsr->addPatchInfoComments(); + EXPECT_TRUE(result); + + ASSERT_EQ(2u, comments.size()); + + ASSERT_EQ("PatchInfoData", comments[0].substr(0, 13)); + ASSERT_EQ("AllocationsList", comments[1].substr(0, 15)); + + std::string line; + std::istringstream input; + input.str(comments[1]); + + uint32_t lineNo = 0; + + std::vector expectedAddresses = {"aaaaaaaa"}; + while (std::getline(input, line)) { + if (line.substr(0, 15) == "AllocationsList") { + continue; + } + + bool foundAddr = false; + for (auto &addr : expectedAddresses) { + if (line.substr(0, 8) == addr) { + foundAddr = true; + break; + } + } + EXPECT_TRUE(foundAddr); + EXPECT_TRUE(line.size() > 9); + lineNo++; + } +} diff --git a/unit_tests/mocks/CMakeLists.txt b/unit_tests/mocks/CMakeLists.txt index a0c8ec9766..f3782f023c 100644 --- a/unit_tests/mocks/CMakeLists.txt +++ b/unit_tests/mocks/CMakeLists.txt @@ -9,6 +9,8 @@ set(IGDRCL_SRCS_tests_mocks ${CMAKE_CURRENT_SOURCE_DIR}/mock_32bitAllocator.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_async_event_handler.cpp ${CMAKE_CURRENT_SOURCE_DIR}/mock_async_event_handler.h + ${CMAKE_CURRENT_SOURCE_DIR}/mock_aub_csr.h + ${CMAKE_CURRENT_SOURCE_DIR}/mock_aub_file_stream.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_aub_subcapture_manager.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_block_kernel_manager.h ${CMAKE_CURRENT_SOURCE_DIR}/mock_buffer.h diff --git a/unit_tests/mocks/mock_aub_csr.h b/unit_tests/mocks/mock_aub_csr.h new file mode 100644 index 0000000000..21ea8f37c6 --- /dev/null +++ b/unit_tests/mocks/mock_aub_csr.h @@ -0,0 +1,106 @@ +/* + * Copyright (C) 2017-2018 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "runtime/command_stream/aub_command_stream_receiver_hw.h" +#include "runtime/execution_environment/execution_environment.h" +#include "runtime/helpers/hw_info.h" +#include "gmock/gmock.h" +#include + +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Winconsistent-missing-override" +#endif + +namespace OCLRT { + +template +struct MockAubCsr : public AUBCommandStreamReceiverHw { + MockAubCsr(const HardwareInfo &hwInfoIn, const std::string &fileName, bool standalone, ExecutionEnvironment &executionEnvironment) + : AUBCommandStreamReceiverHw(hwInfoIn, fileName, standalone, executionEnvironment){}; + + DispatchMode peekDispatchMode() const { + return this->dispatchMode; + } + + GraphicsAllocation *getTagAllocation() const { + return this->tagAllocation; + } + + void setLatestSentTaskCount(uint32_t latestSentTaskCount) { + this->latestSentTaskCount = latestSentTaskCount; + } + + void flushBatchedSubmissions() override { + flushBatchedSubmissionsCalled = true; + } + void initProgrammingFlags() override { + initProgrammingFlagsCalled = true; + } + bool flushBatchedSubmissionsCalled = false; + bool initProgrammingFlagsCalled = false; + + void initFile(const std::string &fileName) override { + fileIsOpen = true; + openFileName = fileName; + } + void closeFile() override { + fileIsOpen = false; + openFileName = ""; + } + bool isFileOpen() const override { + return fileIsOpen; + } + const std::string &getFileName() override { + return openFileName; + } + bool fileIsOpen = false; + std::string openFileName = ""; + + MOCK_METHOD0(addPatchInfoComments, bool(void)); + + using CommandStreamReceiverHw::localMemoryEnabled; +}; + +struct AubExecutionEnvironment { + std::unique_ptr executionEnvironment; + GraphicsAllocation *commandBuffer = nullptr; + template + CsrType *getCsr() { + return static_cast(executionEnvironment->commandStreamReceivers[0u].get()); + } + ~AubExecutionEnvironment() { + if (commandBuffer) { + executionEnvironment->memoryManager->freeGraphicsMemory(commandBuffer); + } + } +}; + +template +std::unique_ptr getEnvironment(bool createTagAllocation, bool allocateCommandBuffer, bool standalone) { + std::unique_ptr executionEnvironment(new ExecutionEnvironment); + executionEnvironment->commandStreamReceivers.push_back(std::make_unique(*platformDevices[0], "", standalone, *executionEnvironment)); + executionEnvironment->memoryManager.reset(executionEnvironment->commandStreamReceivers[0u]->createMemoryManager(false, false)); + executionEnvironment->commandStreamReceivers[0u]->setMemoryManager(executionEnvironment->memoryManager.get()); + if (createTagAllocation) { + executionEnvironment->commandStreamReceivers[0u]->initializeTagAllocation(); + } + + std::unique_ptr aubExecutionEnvironment(new AubExecutionEnvironment); + if (allocateCommandBuffer) { + aubExecutionEnvironment->commandBuffer = executionEnvironment->memoryManager->allocateGraphicsMemory(4096); + } + aubExecutionEnvironment->executionEnvironment = std::move(executionEnvironment); + return aubExecutionEnvironment; +} +} // namespace OCLRT + +#if defined(__clang__) +#pragma clang diagnostic pop +#endif diff --git a/unit_tests/mocks/mock_aub_file_stream.h b/unit_tests/mocks/mock_aub_file_stream.h index 31b966cef5..fa7214689a 100644 --- a/unit_tests/mocks/mock_aub_file_stream.h +++ b/unit_tests/mocks/mock_aub_file_stream.h @@ -8,6 +8,12 @@ #pragma once #include "runtime/command_stream/aub_command_stream_receiver.h" +#include "gmock/gmock.h" + +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Winconsistent-missing-override" +#endif namespace OCLRT { @@ -37,4 +43,12 @@ struct MockAubFileStream : public AUBCommandStreamReceiver::AubFileStream { size_t sizeCapturedFromExpectMemory = 0; uint32_t addressSpaceCapturedFromExpectMemory = 0; }; + +struct GmockAubFileStream : public AUBCommandStreamReceiver::AubFileStream { + MOCK_METHOD1(addComment, bool(const char *message)); +}; } // namespace OCLRT + +#if defined(__clang__) +#pragma clang diagnostic pop +#endif