From ed25e0e8932895686ffb5166966beb88ddcbd410 Mon Sep 17 00:00:00 2001 From: Jim Flynn Date: Fri, 18 Oct 2019 13:21:43 +0100 Subject: [PATCH] IVGCVSW-4005 Add PacketFamilyId to version resolver Change-Id: Ief9373871438df4e1d353bbc545a3ee4f25c1fb0 Signed-off-by: Jim Flynn --- src/profiling/CommandHandler.cpp | 3 +- src/profiling/PacketVersionResolver.cpp | 41 +++++++++++++++++++++- src/profiling/PacketVersionResolver.hpp | 22 +++++++++++- src/profiling/ProfilingService.hpp | 8 ++--- src/profiling/test/ProfilingTests.cpp | 28 ++++++++++++++- tests/profiling/gatordmock/GatordMockMain.cpp | 4 +-- tests/profiling/gatordmock/GatordMockService.cpp | 3 +- .../PeriodicCounterCaptureCommandHandler.hpp | 2 +- 8 files changed, 99 insertions(+), 12 deletions(-) diff --git a/src/profiling/CommandHandler.cpp b/src/profiling/CommandHandler.cpp index 2e22be3..d9722b3 100644 --- a/src/profiling/CommandHandler.cpp +++ b/src/profiling/CommandHandler.cpp @@ -55,7 +55,8 @@ void CommandHandler::HandleCommands(IProfilingConnection& profilingConnection) continue; } - Version version = m_PacketVersionResolver.ResolvePacketVersion(packet.GetPacketId()); + Version version = m_PacketVersionResolver.ResolvePacketVersion(packet.GetPacketFamily(), + packet.GetPacketId()); CommandHandlerFunctor* commandHandlerFunctor = m_CommandHandlerRegistry.GetFunctor(packet.GetPacketFamily(), diff --git a/src/profiling/PacketVersionResolver.cpp b/src/profiling/PacketVersionResolver.cpp index 66e2b4d..3737e3c 100644 --- a/src/profiling/PacketVersionResolver.cpp +++ b/src/profiling/PacketVersionResolver.cpp @@ -11,7 +11,46 @@ namespace armnn namespace profiling { -Version PacketVersionResolver::ResolvePacketVersion(uint32_t packetId) const +bool PacketKey::operator<(const PacketKey& rhs) const +{ + bool result = true; + if (m_FamilyId == rhs.m_FamilyId) + { + result = m_PacketId < rhs.m_PacketId; + } + else if (m_FamilyId > rhs.m_FamilyId) + { + result = false; + } + return result; +} + +bool PacketKey::operator>(const PacketKey& rhs) const +{ + return rhs < *this; +} + +bool PacketKey::operator<=(const PacketKey& rhs) const +{ + return !(*this > rhs); +} + +bool PacketKey::operator>=(const PacketKey& rhs) const +{ + return !(*this < rhs); +} + +bool PacketKey::operator==(const PacketKey& rhs) const +{ + return m_FamilyId == rhs.m_FamilyId && m_PacketId == rhs.m_PacketId; +} + +bool PacketKey::operator!=(const PacketKey& rhs) const +{ + return !(*this == rhs); +} + +Version PacketVersionResolver::ResolvePacketVersion(uint32_t familyId, uint32_t packetId) const { // NOTE: For now every packet specification is at version 1.0.0 return Version(1, 0, 0); diff --git a/src/profiling/PacketVersionResolver.hpp b/src/profiling/PacketVersionResolver.hpp index 168a32c..e959ed5 100644 --- a/src/profiling/PacketVersionResolver.hpp +++ b/src/profiling/PacketVersionResolver.hpp @@ -13,13 +13,33 @@ namespace armnn namespace profiling { +class PacketKey final +{ +public: + PacketKey(uint32_t familyId, uint32_t packetId) : m_FamilyId(familyId), m_PacketId(packetId) {} + + uint32_t GetFamilyId() { return m_FamilyId; } + uint32_t GetPacketId() { return m_PacketId; } + + bool operator< (const PacketKey& rhs) const; + bool operator> (const PacketKey& rhs) const; + bool operator<=(const PacketKey& rhs) const; + bool operator>=(const PacketKey& rhs) const; + bool operator==(const PacketKey& rhs) const; + bool operator!=(const PacketKey& rhs) const; + +private: + uint32_t m_FamilyId; + uint32_t m_PacketId; +}; + class PacketVersionResolver final { public: PacketVersionResolver() = default; ~PacketVersionResolver() = default; - Version ResolvePacketVersion(uint32_t packetId) const; + Version ResolvePacketVersion(uint32_t familyId, uint32_t packetId) const; }; } // namespace profiling diff --git a/src/profiling/ProfilingService.hpp b/src/profiling/ProfilingService.hpp index ea11442..f2c1783 100644 --- a/src/profiling/ProfilingService.hpp +++ b/src/profiling/ProfilingService.hpp @@ -123,17 +123,17 @@ protected: , m_PeriodicCounterCapture(m_Holder, m_SendCounterPacket, *this) , m_ConnectionAcknowledgedCommandHandler(0, 1, - m_PacketVersionResolver.ResolvePacketVersion(1).GetEncodedValue(), + m_PacketVersionResolver.ResolvePacketVersion(0, 1).GetEncodedValue(), m_StateMachine) , m_RequestCounterDirectoryCommandHandler(0, 3, - m_PacketVersionResolver.ResolvePacketVersion(3).GetEncodedValue(), + m_PacketVersionResolver.ResolvePacketVersion(0, 3).GetEncodedValue(), m_CounterDirectory, m_SendCounterPacket, m_StateMachine) , m_PeriodicCounterSelectionCommandHandler(0, 4, - m_PacketVersionResolver.ResolvePacketVersion(4).GetEncodedValue(), + m_PacketVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue(), m_Holder, m_PeriodicCounterCapture, *this, @@ -141,7 +141,7 @@ protected: m_StateMachine) , m_PerJobCounterSelectionCommandHandler(0, 5, - m_PacketVersionResolver.ResolvePacketVersion(4).GetEncodedValue(), + m_PacketVersionResolver.ResolvePacketVersion(0, 5).GetEncodedValue(), m_StateMachine) { // Register the "Connection Acknowledged" command handler diff --git a/src/profiling/test/ProfilingTests.cpp b/src/profiling/test/ProfilingTests.cpp index c255098..aba9675 100644 --- a/src/profiling/test/ProfilingTests.cpp +++ b/src/profiling/test/ProfilingTests.cpp @@ -96,6 +96,31 @@ BOOST_AUTO_TEST_CASE(CheckCommandHandlerKeyComparisons) BOOST_CHECK(vect == expectedVect); } +BOOST_AUTO_TEST_CASE(CheckPacketKeyComparisons) +{ + PacketKey key0(0,0); + PacketKey key1(0,0); + PacketKey key2(0,1); + PacketKey key3(0,2); + PacketKey key4(1,0); + PacketKey key5(1,0); + PacketKey key6(1,1); + + BOOST_CHECK(!(key0 < key1)); + BOOST_CHECK(!(key0 > key1)); + BOOST_CHECK(key0 <= key1); + BOOST_CHECK(key0 >= key1); + BOOST_CHECK(key0 == key1); + BOOST_CHECK(key0 < key2); + BOOST_CHECK(key2 < key3); + BOOST_CHECK(key3 > key0); + BOOST_CHECK(key4 == key5); + BOOST_CHECK(key4 > key0); + BOOST_CHECK(key5 < key6); + BOOST_CHECK(key5 <= key6); + BOOST_CHECK(key5 != key6); +} + BOOST_AUTO_TEST_CASE(CheckCommandHandler) { PacketVersionResolver packetVersionResolver; @@ -363,8 +388,9 @@ BOOST_AUTO_TEST_CASE(CheckPacketVersionResolver) for (unsigned int i = 0u; i < numTests; ++i) { + const uint32_t familyId = distribution(generator); const uint32_t packetId = distribution(generator); - Version resolvedVersion = packetVersionResolver.ResolvePacketVersion(packetId); + Version resolvedVersion = packetVersionResolver.ResolvePacketVersion(familyId, packetId); BOOST_TEST(resolvedVersion == expectedVersion); } diff --git a/tests/profiling/gatordmock/GatordMockMain.cpp b/tests/profiling/gatordmock/GatordMockMain.cpp index 2423493..dd48363 100644 --- a/tests/profiling/gatordmock/GatordMockMain.cpp +++ b/tests/profiling/gatordmock/GatordMockMain.cpp @@ -29,10 +29,10 @@ int main(int argc, char* argv[]) // This functor will receive back the selection response packet. armnn::gatordmock::PeriodicCounterSelectionResponseHandler periodicCounterSelectionResponseHandler( - 0, 4, packetVersionResolver.ResolvePacketVersion(4).GetEncodedValue()); + 0, 4, packetVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue()); // This functor will receive the counter data. armnn::gatordmock::PeriodicCounterCaptureCommandHandler counterCaptureCommandHandler( - 1, 0, packetVersionResolver.ResolvePacketVersion(0).GetEncodedValue()); + 1, 0, packetVersionResolver.ResolvePacketVersion(1, 0).GetEncodedValue()); // Register different derived functors registry.RegisterFunctor(&periodicCounterSelectionResponseHandler); diff --git a/tests/profiling/gatordmock/GatordMockService.cpp b/tests/profiling/gatordmock/GatordMockService.cpp index 2697b2f..194b097 100644 --- a/tests/profiling/gatordmock/GatordMockService.cpp +++ b/tests/profiling/gatordmock/GatordMockService.cpp @@ -326,7 +326,8 @@ armnn::profiling::Packet GatordMockService::ReceivePacket() m_HandlerRegistry .GetFunctor(packetRx.GetPacketFamily(), packetRx.GetPacketId(), - packetVersionResolver.ResolvePacketVersion(packetRx.GetPacketId()).GetEncodedValue()) + packetVersionResolver.ResolvePacketVersion(packetRx.GetPacketFamily(), + packetRx.GetPacketId()).GetEncodedValue()) ->operator()(packetRx); return packetRx; diff --git a/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.hpp b/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.hpp index 4135a2f..05539a4 100644 --- a/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.hpp +++ b/tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.hpp @@ -37,7 +37,7 @@ public: PeriodicCounterCaptureCommandHandler(uint32_t familyId, uint32_t packetId, uint32_t version, - bool quietOperation = false) + bool quietOperation = true) : CommandHandlerFunctor(familyId, packetId, version) , m_QuietOperation(quietOperation) {} -- 2.7.4