IVGCVSW-4005 Add PacketFamilyId to version resolver
authorJim Flynn <jim.flynn@arm.com>
Fri, 18 Oct 2019 12:21:43 +0000 (13:21 +0100)
committerJim Flynn <jim.flynn@arm.com>
Fri, 18 Oct 2019 12:21:43 +0000 (13:21 +0100)
Change-Id: Ief9373871438df4e1d353bbc545a3ee4f25c1fb0
Signed-off-by: Jim Flynn <jim.flynn@arm.com>
src/profiling/CommandHandler.cpp
src/profiling/PacketVersionResolver.cpp
src/profiling/PacketVersionResolver.hpp
src/profiling/ProfilingService.hpp
src/profiling/test/ProfilingTests.cpp
tests/profiling/gatordmock/GatordMockMain.cpp
tests/profiling/gatordmock/GatordMockService.cpp
tests/profiling/gatordmock/PeriodicCounterCaptureCommandHandler.hpp

index 2e22be3..d9722b3 100644 (file)
@@ -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(), 
index 66e2b4d..3737e3c 100644 (file)
@@ -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);
index 168a32c..e959ed5 100644 (file)
@@ -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
index ea11442..f2c1783 100644 (file)
@@ -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
index c255098..aba9675 100644 (file)
@@ -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);
     }
index 2423493..dd48363 100644 (file)
@@ -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);
index 2697b2f..194b097 100644 (file)
@@ -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;
index 4135a2f..05539a4 100644 (file)
@@ -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)
     {}