From bd3931a9fb1730c54a388061aa4c315011ddd6d7 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Thu, 19 Mar 2020 13:48:13 +0100 Subject: [PATCH] Change signature of CommandStreamReceiver::expectMemory return bool value Change-Id: Ia3471199c5fc4449ce13f92705080a4db96f88dd Signed-off-by: Mateusz Jablonski --- opencl/source/api/api.cpp | 4 ++-- .../aub_command_stream_receiver_hw.h | 2 +- .../aub_command_stream_receiver_hw_base.inl | 7 +++---- .../unit_test/api/cl_enqueue_verify_memory.inl | 11 ++++++++--- .../aub_command_stream_receiver_2_tests.cpp | 5 ++--- .../command_stream_receiver_tests.cpp | 16 ++++++++-------- .../command_stream/command_stream_receiver.cpp | 6 +++--- .../command_stream/command_stream_receiver.h | 2 +- 8 files changed, 28 insertions(+), 25 deletions(-) diff --git a/opencl/source/api/api.cpp b/opencl/source/api/api.cpp index 5c495cf0e1..af0373e5ba 100644 --- a/opencl/source/api/api.cpp +++ b/opencl/source/api/api.cpp @@ -5183,8 +5183,8 @@ CL_API_ENTRY cl_int CL_API_CALL clEnqueueVerifyMemoryINTEL(cl_command_queue comm } auto &csr = pCommandQueue->getGpgpuCommandStreamReceiver(); - retVal = csr.expectMemory(allocationPtr, expectedData, sizeOfComparison, comparisonMode); - return retVal; + auto status = csr.expectMemory(allocationPtr, expectedData, sizeOfComparison, comparisonMode); + return status ? CL_SUCCESS : CL_INVALID_VALUE; } cl_int CL_API_CALL clAddCommentINTEL(cl_device_id device, const char *comment) { diff --git a/opencl/source/command_stream/aub_command_stream_receiver_hw.h b/opencl/source/command_stream/aub_command_stream_receiver_hw.h index a166ef6964..75a40df891 100644 --- a/opencl/source/command_stream/aub_command_stream_receiver_hw.h +++ b/opencl/source/command_stream/aub_command_stream_receiver_hw.h @@ -54,7 +54,7 @@ class AUBCommandStreamReceiverHw : public CommandStreamReceiverSimulatedHw::expectMMIO(uint32_t mmioRegister, ui } template -int32_t AUBCommandStreamReceiverHw::expectMemory(const void *gfxAddress, const void *srcAddress, - size_t length, uint32_t compareOperation) { +bool AUBCommandStreamReceiverHw::expectMemory(const void *gfxAddress, const void *srcAddress, + size_t length, uint32_t compareOperation) { pollForCompletion(); auto streamLocked = getAubStream()->lockStream(); @@ -696,8 +696,7 @@ int32_t AUBCommandStreamReceiverHw::expectMemory(const void *gfxAddre }; this->ppgtt->pageWalk(reinterpret_cast(gfxAddress), length, 0, PageTableEntry::nonValidBits, walker, MemoryBanks::BankNotSpecified); - - return CL_SUCCESS; + return true; } template diff --git a/opencl/test/unit_test/api/cl_enqueue_verify_memory.inl b/opencl/test/unit_test/api/cl_enqueue_verify_memory.inl index e29dfda233..9dd5c670f9 100644 --- a/opencl/test/unit_test/api/cl_enqueue_verify_memory.inl +++ b/opencl/test/unit_test/api/cl_enqueue_verify_memory.inl @@ -22,8 +22,7 @@ struct clEnqueueVerifyMemoryINTELSettings { const cl_uint comparisonMode = CL_MEM_COMPARE_EQUAL; const size_t bufferSize = 1; static constexpr size_t expectedSize = 1; - int expected[expectedSize]; - // Use any valid pointer as gpu address because non aub tests will not actually validate the memory + int expected[expectedSize]{}; void *gpuAddress = expected; }; @@ -51,7 +50,13 @@ TEST_F(clEnqueueVerifyMemoryINTELTests, givenInvalidCommandQueueWhenCallingVerif EXPECT_EQ(CL_INVALID_COMMAND_QUEUE, retval); } -TEST_F(clEnqueueVerifyMemoryINTELTests, givenCommandQueueWithoutAubCsrWhenCallingVerifyMemoryThenSuccessIsReturned) { +TEST_F(clEnqueueVerifyMemoryINTELTests, givenEqualMemoryWhenCallingVerifyMemoryThenSuccessIsReturned) { cl_int retval = clEnqueueVerifyMemoryINTEL(pCommandQueue, gpuAddress, expected, expectedSize, comparisonMode); EXPECT_EQ(CL_SUCCESS, retval); } + +TEST_F(clEnqueueVerifyMemoryINTELTests, givenNotEqualMemoryWhenCallingVerifyMemoryThenInvalidValueErrorIsReturned) { + int differentMemory = expected[0] + 1; + cl_int retval = clEnqueueVerifyMemoryINTEL(pCommandQueue, gpuAddress, &differentMemory, sizeof(differentMemory), comparisonMode); + EXPECT_EQ(CL_INVALID_VALUE, retval); +} diff --git a/opencl/test/unit_test/command_stream/aub_command_stream_receiver_2_tests.cpp b/opencl/test/unit_test/command_stream/aub_command_stream_receiver_2_tests.cpp index 8889bd8e63..bd9915e8c3 100644 --- a/opencl/test/unit_test/command_stream/aub_command_stream_receiver_2_tests.cpp +++ b/opencl/test/unit_test/command_stream/aub_command_stream_receiver_2_tests.cpp @@ -833,10 +833,9 @@ HWTEST_F(AubCommandStreamReceiverTests, givenAubCsrWhenAskedForMemoryExpectation public: using AUBCommandStreamReceiverHw::AUBCommandStreamReceiverHw; - cl_int expectMemory(const void *gfxAddress, const void *srcAddress, size_t length, uint32_t compareOperation) override { + bool expectMemory(const void *gfxAddress, const void *srcAddress, size_t length, uint32_t compareOperation) override { inputCompareOperation = compareOperation; - AUBCommandStreamReceiverHw::expectMemory(gfxAddress, srcAddress, length, compareOperation); - return CL_SUCCESS; + return AUBCommandStreamReceiverHw::expectMemory(gfxAddress, srcAddress, length, compareOperation); } uint32_t inputCompareOperation = 0; }; diff --git a/opencl/test/unit_test/command_stream/command_stream_receiver_tests.cpp b/opencl/test/unit_test/command_stream/command_stream_receiver_tests.cpp index f203990a95..c6330e945e 100644 --- a/opencl/test/unit_test/command_stream/command_stream_receiver_tests.cpp +++ b/opencl/test/unit_test/command_stream/command_stream_receiver_tests.cpp @@ -430,15 +430,15 @@ TEST(CommandStreamReceiverSimpleTest, givenVariousDataSetsWhenVerifyingMemoryThe constexpr auto compareEqual = AubMemDump::CmdServicesMemTraceMemoryCompare::CompareOperationValues::CompareEqual; constexpr auto compareNotEqual = AubMemDump::CmdServicesMemTraceMemoryCompare::CompareOperationValues::CompareNotEqual; - EXPECT_EQ(CL_SUCCESS, csr.expectMemory(setA1, setA2, setSize, compareEqual)); - EXPECT_EQ(CL_SUCCESS, csr.expectMemory(setB1, setB2, setSize, compareEqual)); - EXPECT_EQ(CL_INVALID_VALUE, csr.expectMemory(setA1, setA2, setSize, compareNotEqual)); - EXPECT_EQ(CL_INVALID_VALUE, csr.expectMemory(setB1, setB2, setSize, compareNotEqual)); + EXPECT_TRUE(csr.expectMemory(setA1, setA2, setSize, compareEqual)); + EXPECT_TRUE(csr.expectMemory(setB1, setB2, setSize, compareEqual)); + EXPECT_FALSE(csr.expectMemory(setA1, setA2, setSize, compareNotEqual)); + EXPECT_FALSE(csr.expectMemory(setB1, setB2, setSize, compareNotEqual)); - EXPECT_EQ(CL_INVALID_VALUE, csr.expectMemory(setA1, setB1, setSize, compareEqual)); - EXPECT_EQ(CL_INVALID_VALUE, csr.expectMemory(setA2, setB2, setSize, compareEqual)); - EXPECT_EQ(CL_SUCCESS, csr.expectMemory(setA1, setB1, setSize, compareNotEqual)); - EXPECT_EQ(CL_SUCCESS, csr.expectMemory(setA2, setB2, setSize, compareNotEqual)); + EXPECT_FALSE(csr.expectMemory(setA1, setB1, setSize, compareEqual)); + EXPECT_FALSE(csr.expectMemory(setA2, setB2, setSize, compareEqual)); + EXPECT_TRUE(csr.expectMemory(setA1, setB1, setSize, compareNotEqual)); + EXPECT_TRUE(csr.expectMemory(setA2, setB2, setSize, compareNotEqual)); } TEST(CommandStreamReceiverMultiContextTests, givenMultipleCsrsWhenSameResourcesAreUsedThenResidencyIsProperlyHandled) { diff --git a/shared/source/command_stream/command_stream_receiver.cpp b/shared/source/command_stream/command_stream_receiver.cpp index 408713a952..a8c8f63831 100644 --- a/shared/source/command_stream/command_stream_receiver.cpp +++ b/shared/source/command_stream/command_stream_receiver.cpp @@ -476,12 +476,12 @@ size_t CommandStreamReceiver::getPreferredTagPoolSize() const { return 512; } -int32_t CommandStreamReceiver::expectMemory(const void *gfxAddress, const void *srcAddress, - size_t length, uint32_t compareOperation) { +bool CommandStreamReceiver::expectMemory(const void *gfxAddress, const void *srcAddress, + size_t length, uint32_t compareOperation) { auto isMemoryEqual = (memcmp(gfxAddress, srcAddress, length) == 0); auto isEqualMemoryExpected = (compareOperation == AubMemDump::CmdServicesMemTraceMemoryCompare::CompareOperationValues::CompareEqual); - return (isMemoryEqual == isEqualMemoryExpected) ? CL_SUCCESS : CL_INVALID_VALUE; + return (isMemoryEqual == isEqualMemoryExpected); } bool CommandStreamReceiver::needsPageTableManager(aub_stream::EngineType engineType) const { diff --git a/shared/source/command_stream/command_stream_receiver.h b/shared/source/command_stream/command_stream_receiver.h index 6e570c2550..92ca9dc187 100644 --- a/shared/source/command_stream/command_stream_receiver.h +++ b/shared/source/command_stream/command_stream_receiver.h @@ -171,7 +171,7 @@ class CommandStreamReceiver { TagAllocator *getEventPerfCountAllocator(const uint32_t tagSize); TagAllocator *getTimestampPacketAllocator(); - virtual int32_t expectMemory(const void *gfxAddress, const void *srcAddress, size_t length, uint32_t compareOperation); + virtual bool expectMemory(const void *gfxAddress, const void *srcAddress, size_t length, uint32_t compareOperation); virtual bool isMultiOsContextCapable() const = 0;