Skip to content

Commit 1bf98c7

Browse files
committed
Added support for expectMemory call from aub stream
Change-Id: I8acf27eff8b2f38dcb8d9873e03c35bfab6f3298
1 parent 835aa09 commit 1bf98c7

File tree

5 files changed

+66
-0
lines changed

5 files changed

+66
-0
lines changed

runtime/command_stream/aub_command_stream_receiver_hw.inl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,11 @@ void AUBCommandStreamReceiverHw<GfxFamily>::expectMemoryNotEqual(void *gfxAddres
726726
template <typename GfxFamily>
727727
void AUBCommandStreamReceiverHw<GfxFamily>::expectMemory(void *gfxAddress, const void *srcAddress,
728728
size_t length, uint32_t compareOperation) {
729+
if (hardwareContext) {
730+
hardwareContext->expectMemory(reinterpret_cast<uint64_t>(gfxAddress), srcAddress, length, compareOperation);
731+
return;
732+
}
733+
729734
PageWalker walker = [&](uint64_t physAddress, size_t size, size_t offset, uint64_t entryBits) {
730735
UNRECOVERABLE_IF(offset > length);
731736

third_party/aub_stream/headers/hardware_context.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct HardwareContext {
1717
virtual void submit(uint64_t gfxAddress, const void *batchBuffer, size_t size, uint32_t memoryBank) = 0;
1818
virtual void writeMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t memoryBanks, int hint, size_t pageSize = 4096) = 0;
1919
virtual void freeMemory(uint64_t gfxAddress, size_t size) = 0;
20+
virtual void expectMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t compareOperation) = 0;
2021
virtual ~HardwareContext() = default;
2122
};
2223

unit_tests/command_stream/aub_file_stream_tests.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,26 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenMakeResidentIsCall
146146
EXPECT_TRUE(aubCsr->writeMemoryCalled);
147147
}
148148

149+
HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenExpectMemoryEqualIsCalledThenItShouldCallTheExpectedFunctions) {
150+
auto aubExecutionEnvironment = getEnvironment<MockAubCsr<FamilyType>>(true, true, true);
151+
auto aubCsr = aubExecutionEnvironment->template getCsr<MockAubCsr<FamilyType>>();
152+
153+
MockGraphicsAllocation allocation(reinterpret_cast<void *>(0x1000), 0x1000);
154+
aubCsr->expectMemoryEqual(reinterpret_cast<void *>(0x1000), reinterpret_cast<void *>(0x1000), 0x1000);
155+
156+
EXPECT_TRUE(aubCsr->expectMemoryEqualCalled);
157+
}
158+
159+
HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenExpectMemoryNotEqualIsCalledThenItShouldCallTheExpectedFunctions) {
160+
auto aubExecutionEnvironment = getEnvironment<MockAubCsr<FamilyType>>(true, true, true);
161+
auto aubCsr = aubExecutionEnvironment->template getCsr<MockAubCsr<FamilyType>>();
162+
163+
MockGraphicsAllocation allocation(reinterpret_cast<void *>(0x1000), 0x1000);
164+
aubCsr->expectMemoryNotEqual(reinterpret_cast<void *>(0x1000), reinterpret_cast<void *>(0x1000), 0x1000);
165+
166+
EXPECT_TRUE(aubCsr->expectMemoryNotEqualCalled);
167+
}
168+
149169
HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenItShouldCallTheExpectedHwContextFunctions) {
150170
auto mockManager = std::make_unique<MockAubManager>();
151171
auto mockHardwareContext = static_cast<MockHardwareContext *>(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS));
@@ -181,6 +201,34 @@ HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenMakeResidentIsCall
181201
EXPECT_TRUE(mockHardwareContext->writeMemoryCalled);
182202
}
183203

204+
HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenExpectMemoryEqualIsCalledThenItShouldCallTheExpectedHwContextFunctions) {
205+
auto mockManager = std::make_unique<MockAubManager>();
206+
auto mockHardwareContext = static_cast<MockHardwareContext *>(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS));
207+
208+
auto aubExecutionEnvironment = getEnvironment<MockAubCsr<FamilyType>>(true, true, true);
209+
auto aubCsr = aubExecutionEnvironment->template getCsr<MockAubCsr<FamilyType>>();
210+
aubCsr->hardwareContext = std::unique_ptr<MockHardwareContext>(mockHardwareContext);
211+
212+
MockGraphicsAllocation allocation(reinterpret_cast<void *>(0x1000), 0x1000);
213+
aubCsr->expectMemoryEqual(reinterpret_cast<void *>(0x1000), reinterpret_cast<void *>(0x1000), 0x1000);
214+
215+
EXPECT_TRUE(mockHardwareContext->expectMemoryCalled);
216+
}
217+
218+
HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenExpectMemoryNotEqualIsCalledThenItShouldCallTheExpectedHwContextFunctions) {
219+
auto mockManager = std::make_unique<MockAubManager>();
220+
auto mockHardwareContext = static_cast<MockHardwareContext *>(mockManager->createHardwareContext(0, EngineType::ENGINE_RCS));
221+
222+
auto aubExecutionEnvironment = getEnvironment<MockAubCsr<FamilyType>>(true, true, true);
223+
auto aubCsr = aubExecutionEnvironment->template getCsr<MockAubCsr<FamilyType>>();
224+
aubCsr->hardwareContext = std::unique_ptr<MockHardwareContext>(mockHardwareContext);
225+
226+
MockGraphicsAllocation allocation(reinterpret_cast<void *>(0x1000), 0x1000);
227+
aubCsr->expectMemoryNotEqual(reinterpret_cast<void *>(0x1000), reinterpret_cast<void *>(0x1000), 0x1000);
228+
229+
EXPECT_TRUE(mockHardwareContext->expectMemoryCalled);
230+
}
231+
184232
HWTEST_F(AubFileStreamTests, givenAubCommandStreamReceiverWhenFlushIsCalledThenFileStreamShouldBeFlushed) {
185233
auto aubExecutionEnvironment = getEnvironment<AUBCommandStreamReceiverHw<FamilyType>>(true, true, true);
186234
auto aubCsr = aubExecutionEnvironment->template getCsr<AUBCommandStreamReceiverHw<FamilyType>>();

unit_tests/mocks/mock_aub_csr.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,22 @@ struct MockAubCsr : public AUBCommandStreamReceiverHw<GfxFamily> {
8787
AUBCommandStreamReceiverHw<GfxFamily>::pollForCompletion(engineInstance);
8888
pollForCompletionCalled = true;
8989
}
90+
void expectMemoryEqual(void *gfxAddress, const void *srcAddress, size_t length) {
91+
AUBCommandStreamReceiverHw<GfxFamily>::expectMemoryEqual(gfxAddress, srcAddress, length);
92+
expectMemoryEqualCalled = true;
93+
}
94+
void expectMemoryNotEqual(void *gfxAddress, const void *srcAddress, size_t length) {
95+
AUBCommandStreamReceiverHw<GfxFamily>::expectMemoryNotEqual(gfxAddress, srcAddress, length);
96+
expectMemoryNotEqualCalled = true;
97+
}
9098
bool flushBatchedSubmissionsCalled = false;
9199
bool initProgrammingFlagsCalled = false;
92100
bool initializeEngineCalled = false;
93101
bool writeMemoryCalled = false;
94102
bool submitBatchBufferCalled = false;
95103
bool pollForCompletionCalled = false;
104+
bool expectMemoryEqualCalled = false;
105+
bool expectMemoryNotEqualCalled = false;
96106

97107
void initFile(const std::string &fileName) override {
98108
fileIsOpen = true;

unit_tests/mocks/mock_aub_manager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ struct MockHardwareContext : public HardwareContext {
1919
void submit(uint64_t gfxAddress, const void *batchBuffer, size_t size, uint32_t memoryBank) override { submitCalled = true; }
2020
void writeMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t memoryBanks, int hint, size_t pageSize = 4096) override { writeMemoryCalled = true; }
2121
void freeMemory(uint64_t gfxAddress, size_t size) override { freeMemoryCalled = true; }
22+
void expectMemory(uint64_t gfxAddress, const void *memory, size_t size, uint32_t compareOperation) override { expectMemoryCalled = true; }
2223

2324
bool initializeCalled = false;
2425
bool pollForCompletionCalled = false;
2526
bool submitCalled = false;
2627
bool writeMemoryCalled = false;
2728
bool freeMemoryCalled = false;
29+
bool expectMemoryCalled = false;
2830
};
2931

3032
class MockAubManager : public AubManager {

0 commit comments

Comments
 (0)