From 1bf98c7f800d71b9dbefe944cfd1672a817bdf40 Mon Sep 17 00:00:00 2001 From: "Milczarek, Slawomir" Date: Tue, 4 Dec 2018 12:03:36 -0800 Subject: [PATCH] Added support for expectMemory call from aub stream Change-Id: I8acf27eff8b2f38dcb8d9873e03c35bfab6f3298 --- .../aub_command_stream_receiver_hw.inl | 5 ++ .../aub_stream/headers/hardware_context.h | 1 + .../command_stream/aub_file_stream_tests.cpp | 48 +++++++++++++++++++ unit_tests/mocks/mock_aub_csr.h | 10 ++++ unit_tests/mocks/mock_aub_manager.h | 2 + 5 files changed, 66 insertions(+) diff --git a/runtime/command_stream/aub_command_stream_receiver_hw.inl b/runtime/command_stream/aub_command_stream_receiver_hw.inl index f4bfaedc31..a722418a80 100644 --- a/runtime/command_stream/aub_command_stream_receiver_hw.inl +++ b/runtime/command_stream/aub_command_stream_receiver_hw.inl @@ -726,6 +726,11 @@ void AUBCommandStreamReceiverHw::expectMemoryNotEqual(void *gfxAddres template void AUBCommandStreamReceiverHw::expectMemory(void *gfxAddress, const void *srcAddress, size_t length, uint32_t compareOperation) { + if (hardwareContext) { + hardwareContext->expectMemory(reinterpret_cast(gfxAddress), srcAddress, length, compareOperation); + return; + } + PageWalker walker = [&](uint64_t physAddress, size_t size, size_t offset, uint64_t entryBits) { UNRECOVERABLE_IF(offset > length); diff --git a/third_party/aub_stream/headers/hardware_context.h b/third_party/aub_stream/headers/hardware_context.h index 2c1bd7c70d..f5ccbe7759 100644 --- a/third_party/aub_stream/headers/hardware_context.h +++ b/third_party/aub_stream/headers/hardware_context.h @@ -17,6 +17,7 @@ struct HardwareContext { virtual void submit(uint64_t gfxAddress, const void *batchBuffer, size_t size, uint32_t memoryBank) = 0; virtual void writeMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t memoryBanks, int hint, size_t pageSize = 4096) = 0; virtual void freeMemory(uint64_t gfxAddress, size_t size) = 0; + virtual void expectMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t compareOperation) = 0; virtual ~HardwareContext() = default; }; diff --git a/unit_tests/command_stream/aub_file_stream_tests.cpp b/unit_tests/command_stream/aub_file_stream_tests.cpp index 7fcbb28719..84cf5d16b2 100644 --- a/unit_tests/command_stream/aub_file_stream_tests.cpp +++ b/unit_tests/command_stream/aub_file_stream_tests.cpp @@ -146,6 +146,26 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenMakeResidentIsCall EXPECT_TRUE(aubCsr->writeMemoryCalled); } +HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenExpectMemoryEqualIsCalledThenItShouldCallTheExpectedFunctions) { + auto aubExecutionEnvironment = getEnvironment>(true, true, true); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + + MockGraphicsAllocation allocation(reinterpret_cast(0x1000), 0x1000); + aubCsr->expectMemoryEqual(reinterpret_cast(0x1000), reinterpret_cast(0x1000), 0x1000); + + EXPECT_TRUE(aubCsr->expectMemoryEqualCalled); +} + +HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenExpectMemoryNotEqualIsCalledThenItShouldCallTheExpectedFunctions) { + auto aubExecutionEnvironment = getEnvironment>(true, true, true); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + + MockGraphicsAllocation allocation(reinterpret_cast(0x1000), 0x1000); + aubCsr->expectMemoryNotEqual(reinterpret_cast(0x1000), reinterpret_cast(0x1000), 0x1000); + + EXPECT_TRUE(aubCsr->expectMemoryNotEqualCalled); +} + HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenItShouldCallTheExpectedHwContextFunctions) { auto mockManager = std::make_unique(); auto mockHardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); @@ -181,6 +201,34 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenMakeResidentIsCall EXPECT_TRUE(mockHardwareContext->writeMemoryCalled); } +HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenExpectMemoryEqualIsCalledThenItShouldCallTheExpectedHwContextFunctions) { + auto mockManager = std::make_unique(); + auto mockHardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); + + auto aubExecutionEnvironment = getEnvironment>(true, true, true); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + aubCsr->hardwareContext = std::unique_ptr(mockHardwareContext); + + MockGraphicsAllocation allocation(reinterpret_cast(0x1000), 0x1000); + aubCsr->expectMemoryEqual(reinterpret_cast(0x1000), reinterpret_cast(0x1000), 0x1000); + + EXPECT_TRUE(mockHardwareContext->expectMemoryCalled); +} + +HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenExpectMemoryNotEqualIsCalledThenItShouldCallTheExpectedHwContextFunctions) { + auto mockManager = std::make_unique(); + auto mockHardwareContext = static_cast(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS)); + + auto aubExecutionEnvironment = getEnvironment>(true, true, true); + auto aubCsr = aubExecutionEnvironment->template getCsr>(); + aubCsr->hardwareContext = std::unique_ptr(mockHardwareContext); + + MockGraphicsAllocation allocation(reinterpret_cast(0x1000), 0x1000); + aubCsr->expectMemoryNotEqual(reinterpret_cast(0x1000), reinterpret_cast(0x1000), 0x1000); + + EXPECT_TRUE(mockHardwareContext->expectMemoryCalled); +} + HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenFileStreamShouldBeFlushed) { auto aubExecutionEnvironment = getEnvironment>(true, true, true); auto aubCsr = aubExecutionEnvironment->template getCsr>(); diff --git a/unit_tests/mocks/mock_aub_csr.h b/unit_tests/mocks/mock_aub_csr.h index 67002fa016..b2b7f2a597 100644 --- a/unit_tests/mocks/mock_aub_csr.h +++ b/unit_tests/mocks/mock_aub_csr.h @@ -87,12 +87,22 @@ struct MockAubCsr : public AUBCommandStreamReceiverHw { AUBCommandStreamReceiverHw::pollForCompletion(engineInstance); pollForCompletionCalled = true; } + void expectMemoryEqual(void *gfxAddress, const void *srcAddress, size_t length) { + AUBCommandStreamReceiverHw::expectMemoryEqual(gfxAddress, srcAddress, length); + expectMemoryEqualCalled = true; + } + void expectMemoryNotEqual(void *gfxAddress, const void *srcAddress, size_t length) { + AUBCommandStreamReceiverHw::expectMemoryNotEqual(gfxAddress, srcAddress, length); + expectMemoryNotEqualCalled = true; + } bool flushBatchedSubmissionsCalled = false; bool initProgrammingFlagsCalled = false; bool initializeEngineCalled = false; bool writeMemoryCalled = false; bool submitBatchBufferCalled = false; bool pollForCompletionCalled = false; + bool expectMemoryEqualCalled = false; + bool expectMemoryNotEqualCalled = false; void initFile(const std::string &fileName) override { fileIsOpen = true; diff --git a/unit_tests/mocks/mock_aub_manager.h b/unit_tests/mocks/mock_aub_manager.h index d0eab22109..8f3342ea3a 100644 --- a/unit_tests/mocks/mock_aub_manager.h +++ b/unit_tests/mocks/mock_aub_manager.h @@ -19,12 +19,14 @@ struct MockHardwareContext : public HardwareContext { void submit(uint64_t gfxAddress, const void *batchBuffer, size_t size, uint32_t memoryBank) override { submitCalled = true; } void writeMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t memoryBanks, int hint, size_t pageSize = 4096) override { writeMemoryCalled = true; } void freeMemory(uint64_t gfxAddress, size_t size) override { freeMemoryCalled = true; } + void expectMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t compareOperation) override { expectMemoryCalled = true; } bool initializeCalled = false; bool pollForCompletionCalled = false; bool submitCalled = false; bool writeMemoryCalled = false; bool freeMemoryCalled = false; + bool expectMemoryCalled = false; }; class MockAubManager : public AubManager {