From 5587670c4f4156f14ce9d94a2d503fa4c48ae177 Mon Sep 17 00:00:00 2001 From: "Milczarek, Slawomir" Date: Wed, 1 Apr 2020 21:01:39 +0200 Subject: [PATCH] Implement expect memory for AUB tests in TBX mode Related-To: NEO-4459 Change-Id: I7ab64ff124f19baabb00cbad50b1a2065379b0c6 Signed-off-by: Milczarek, Slawomir --- .../command_stream_receiver_simulated_common_hw.h | 4 ++-- ...d_stream_receiver_simulated_common_hw_base.inl | 12 ++++++------ .../tbx_command_stream_receiver_hw.h | 1 + .../tbx_command_stream_receiver_hw.inl | 15 +++++++++++++++ .../command_stream/aub_command_stream_fixture.h | 6 ++++-- .../unit_test/aub_tests/fixtures/aub_fixture.h | 6 ++++-- opencl/test/unit_test/main.cpp | 2 +- opencl/test/unit_test/mocks/mock_aub_csr.h | 8 ++++---- 8 files changed, 37 insertions(+), 17 deletions(-) diff --git a/opencl/source/command_stream/command_stream_receiver_simulated_common_hw.h b/opencl/source/command_stream/command_stream_receiver_simulated_common_hw.h index f91ef3c787..fec89d041f 100644 --- a/opencl/source/command_stream/command_stream_receiver_simulated_common_hw.h +++ b/opencl/source/command_stream/command_stream_receiver_simulated_common_hw.h @@ -48,8 +48,8 @@ class CommandStreamReceiverSimulatedCommonHw : public CommandStreamReceiverHw::getParametersForWriteMem } template -void CommandStreamReceiverSimulatedCommonHw::expectMemoryEqual(void *gfxAddress, const void *srcAddress, size_t length) { - this->expectMemory(gfxAddress, srcAddress, length, - AubMemDump::CmdServicesMemTraceMemoryCompare::CompareOperationValues::CompareEqual); +bool CommandStreamReceiverSimulatedCommonHw::expectMemoryEqual(void *gfxAddress, const void *srcAddress, size_t length) { + return this->expectMemory(gfxAddress, srcAddress, length, + AubMemDump::CmdServicesMemTraceMemoryCompare::CompareOperationValues::CompareEqual); } template -void CommandStreamReceiverSimulatedCommonHw::expectMemoryNotEqual(void *gfxAddress, const void *srcAddress, size_t length) { - this->expectMemory(gfxAddress, srcAddress, length, - AubMemDump::CmdServicesMemTraceMemoryCompare::CompareOperationValues::CompareNotEqual); +bool CommandStreamReceiverSimulatedCommonHw::expectMemoryNotEqual(void *gfxAddress, const void *srcAddress, size_t length) { + return this->expectMemory(gfxAddress, srcAddress, length, + AubMemDump::CmdServicesMemTraceMemoryCompare::CompareOperationValues::CompareNotEqual); } template diff --git a/opencl/source/command_stream/tbx_command_stream_receiver_hw.h b/opencl/source/command_stream/tbx_command_stream_receiver_hw.h index 86487468f7..28f5dca311 100644 --- a/opencl/source/command_stream/tbx_command_stream_receiver_hw.h +++ b/opencl/source/command_stream/tbx_command_stream_receiver_hw.h @@ -48,6 +48,7 @@ class TbxCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw::writeMemory(GraphicsAllocation &gfxA return true; } +template +bool TbxCommandStreamReceiverHw::expectMemory(const void *gfxAddress, const void *srcAddress, + size_t length, uint32_t compareOperation) { + if (hardwareContextController) { + auto readMemory = std::make_unique(length); + //note: memory bank should not matter assuming that we call expect on the memory that was previously allocated + hardwareContextController->readMemory((uint64_t)gfxAddress, readMemory.get(), length, this->getMemoryBankForGtt(), MemoryConstants::pageSize64k); + auto isMemoryEqual = (memcmp(readMemory.get(), srcAddress, length) == 0); + auto isEqualMemoryExpected = (compareOperation == AubMemDump::CmdServicesMemTraceMemoryCompare::CompareOperationValues::CompareEqual); + return (isMemoryEqual == isEqualMemoryExpected); + } + + return BaseClass::expectMemory(gfxAddress, srcAddress, length, compareOperation); +} + template void TbxCommandStreamReceiverHw::waitForTaskCountWithKmdNotifyFallback(uint32_t taskCountToWait, FlushStamp flushStampToWait, bool useQuickKmdSleep, bool forcePowerSavingMode) { this->flushBatchedSubmissions(); diff --git a/opencl/test/unit_test/aub_tests/command_stream/aub_command_stream_fixture.h b/opencl/test/unit_test/aub_tests/command_stream/aub_command_stream_fixture.h index 2314db254a..ee65a049b2 100644 --- a/opencl/test/unit_test/aub_tests/command_stream/aub_command_stream_fixture.h +++ b/opencl/test/unit_test/aub_tests/command_stream/aub_command_stream_fixture.h @@ -19,6 +19,8 @@ #include "opencl/test/unit_test/command_stream/command_stream_fixture.h" #include "opencl/test/unit_test/mocks/mock_allocation_properties.h" +#include "gtest/gtest.h" + #include namespace NEO { @@ -57,7 +59,7 @@ class AUBCommandStreamFixture : public CommandStreamFixture { CommandStreamReceiver *csr = pCommandStreamReceiver; if (testMode == TestMode::AubTestsWithTbx) { auto tbxCsr = static_cast *>(pCommandStreamReceiver); - tbxCsr->expectMemoryEqual(gfxAddress, srcAddress, length); + EXPECT_TRUE(tbxCsr->expectMemoryEqual(gfxAddress, srcAddress, length)); csr = static_cast> *>(pCommandStreamReceiver)->aubCSR.get(); } @@ -73,7 +75,7 @@ class AUBCommandStreamFixture : public CommandStreamFixture { CommandStreamReceiver *csr = pCommandStreamReceiver; if (testMode == TestMode::AubTestsWithTbx) { auto tbxCsr = static_cast *>(pCommandStreamReceiver); - tbxCsr->expectMemoryNotEqual(gfxAddress, srcAddress, length); + EXPECT_TRUE(tbxCsr->expectMemoryNotEqual(gfxAddress, srcAddress, length)); csr = static_cast> *>(pCommandStreamReceiver)->aubCSR.get(); } diff --git a/opencl/test/unit_test/aub_tests/fixtures/aub_fixture.h b/opencl/test/unit_test/aub_tests/fixtures/aub_fixture.h index 9c806189e1..85641a63aa 100644 --- a/opencl/test/unit_test/aub_tests/fixtures/aub_fixture.h +++ b/opencl/test/unit_test/aub_tests/fixtures/aub_fixture.h @@ -21,6 +21,8 @@ #include "opencl/test/unit_test/mocks/mock_device.h" #include "opencl/test/unit_test/mocks/mock_platform.h" +#include "gtest/gtest.h" + #include namespace NEO { @@ -69,7 +71,7 @@ class AUBFixture : public CommandQueueHwFixture { if (testMode == TestMode::AubTestsWithTbx) { auto tbxCsr = csrSimulated; - tbxCsr->expectMemoryEqual(gfxAddress, srcAddress, length); + EXPECT_TRUE(tbxCsr->expectMemoryEqual(gfxAddress, srcAddress, length)); csrSimulated = static_cast *>( static_cast> *>(csr)->aubCSR.get()); } @@ -85,7 +87,7 @@ class AUBFixture : public CommandQueueHwFixture { if (testMode == TestMode::AubTestsWithTbx) { auto tbxCsr = csrSimulated; - tbxCsr->expectMemoryNotEqual(gfxAddress, srcAddress, length); + EXPECT_TRUE(tbxCsr->expectMemoryNotEqual(gfxAddress, srcAddress, length)); csrSimulated = static_cast *>( static_cast> *>(csr)->aubCSR.get()); } diff --git a/opencl/test/unit_test/main.cpp b/opencl/test/unit_test/main.cpp index bb30729828..575965c83e 100644 --- a/opencl/test/unit_test/main.cpp +++ b/opencl/test/unit_test/main.cpp @@ -278,7 +278,7 @@ int main(int argc, char **argv) { } } else if (!strcmp("--generate_random_inputs", argv[i])) { generateRandomInput = true; - } else if (!strcmp("--read-config", argv[i]) && testMode == TestMode::AubTests) { + } else if (!strcmp("--read-config", argv[i]) && (testMode == TestMode::AubTests || testMode == TestMode::AubTestsWithTbx)) { if (DebugManager.registryReadAvailable()) { DebugManager.setReaderImpl(SettingsReader::create(oclRegPath)); DebugManager.injectSettingsFromReader(); diff --git a/opencl/test/unit_test/mocks/mock_aub_csr.h b/opencl/test/unit_test/mocks/mock_aub_csr.h index e19d6e1329..9dfd37f753 100644 --- a/opencl/test/unit_test/mocks/mock_aub_csr.h +++ b/opencl/test/unit_test/mocks/mock_aub_csr.h @@ -106,13 +106,13 @@ struct MockAubCsr : public AUBCommandStreamReceiverHw { AUBCommandStreamReceiverHw::pollForCompletion(); pollForCompletionCalled = true; } - void expectMemoryEqual(void *gfxAddress, const void *srcAddress, size_t length) override { - AUBCommandStreamReceiverHw::expectMemoryEqual(gfxAddress, srcAddress, length); + bool expectMemoryEqual(void *gfxAddress, const void *srcAddress, size_t length) override { expectMemoryEqualCalled = true; + return AUBCommandStreamReceiverHw::expectMemoryEqual(gfxAddress, srcAddress, length); } - void expectMemoryNotEqual(void *gfxAddress, const void *srcAddress, size_t length) override { - AUBCommandStreamReceiverHw::expectMemoryNotEqual(gfxAddress, srcAddress, length); + bool expectMemoryNotEqual(void *gfxAddress, const void *srcAddress, size_t length) override { expectMemoryNotEqualCalled = true; + return AUBCommandStreamReceiverHw::expectMemoryNotEqual(gfxAddress, srcAddress, length); } bool waitForCompletionWithTimeout(bool enableTimeout, int64_t timeoutMicroseconds, uint32_t taskCountToWait) override { return true;