From 74510286a1fbb06ec584ac55a29891948d2e5257 Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Thu, 13 Dec 2018 16:24:42 +0100 Subject: [PATCH] Command Queue: Destroy timestamp packet container before releasing context Change-Id: I7ee492586ee178bc89c44d5d6663d3ff8fb2e778 Signed-off-by: Mateusz Jablonski --- runtime/command_queue/command_queue.cpp | 1 + runtime/helpers/timestamp_packet.h | 2 +- .../command_queue/command_queue_tests.cpp | 20 +++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/runtime/command_queue/command_queue.cpp b/runtime/command_queue/command_queue.cpp index b0c02e4da7..d68c207338 100644 --- a/runtime/command_queue/command_queue.cpp +++ b/runtime/command_queue/command_queue.cpp @@ -96,6 +96,7 @@ CommandQueue::~CommandQueue() { } } + timestampPacketContainer.reset(); //for normal queue, decrement ref count on context //special queue is owned by context so ref count doesn't have to be decremented if (context && !isSpecialCommandQueue) { diff --git a/runtime/helpers/timestamp_packet.h b/runtime/helpers/timestamp_packet.h index 191aee72eb..a89b859661 100644 --- a/runtime/helpers/timestamp_packet.h +++ b/runtime/helpers/timestamp_packet.h @@ -96,7 +96,7 @@ class TimestampPacketContainer : public NonCopyableOrMovableClass { public: using Node = TagNode; TimestampPacketContainer() = default; - ~TimestampPacketContainer(); + MOCKABLE_VIRTUAL ~TimestampPacketContainer(); const std::vector &peekNodes() const { return timestampPacketNodes; } void add(Node *timestampPacketNode); diff --git a/unit_tests/command_queue/command_queue_tests.cpp b/unit_tests/command_queue/command_queue_tests.cpp index 4b11a0611a..60934252a4 100644 --- a/unit_tests/command_queue/command_queue_tests.cpp +++ b/unit_tests/command_queue/command_queue_tests.cpp @@ -13,6 +13,7 @@ #include "runtime/helpers/basic_math.h" #include "runtime/helpers/kernel_commands.h" #include "runtime/helpers/options.h" +#include "runtime/helpers/timestamp_packet.h" #include "unit_tests/command_queue/command_queue_fixture.h" #include "unit_tests/command_stream/command_stream_fixture.h" @@ -949,3 +950,22 @@ HWTEST_F(CommandQueueCommandStreamTest, givenCsrWithDebugSurfaceAllocatedWhenSet RENDER_SURFACE_STATE *surfaceState = (RENDER_SURFACE_STATE *)kernel->getSurfaceStateHeap(); EXPECT_EQ(debugSurface->getGpuAddress(), surfaceState->getSurfaceBaseAddress()); } + +struct MockTimestampPacketContainer : TimestampPacketContainer { + MockTimestampPacketContainer(Context &context) : context(context) { + } + ~MockTimestampPacketContainer() override { + EXPECT_EQ(1, context.getRefInternalCount()); + } + Context &context; +}; + +TEST(CommandQueueDestructorTest, whenCommandQueueIsDestroyedThenDestroysTimestampPacketContainerBeforeReleasingContext) { + auto context = new MockContext; + EXPECT_EQ(1, context->getRefInternalCount()); + MockCommandQueue queue(context, context->getDevice(0), nullptr); + queue.timestampPacketContainer.reset(new MockTimestampPacketContainer(*context)); + EXPECT_EQ(2, context->getRefInternalCount()); + context->release(); + EXPECT_EQ(1, context->getRefInternalCount()); +}