IVGCVSW-5076 Correct Profiling Stream Metadata packet revision table

Change-Id: Ic3f8637642d3f3a5925f5b82e3729b3b654a7f3e
Signed-off-by: Jim Flynn <jim.flynn@arm.com>
diff --git a/src/profiling/ProfilingUtils.cpp b/src/profiling/ProfilingUtils.cpp
index 3f6e563..d86adbc 100644
--- a/src/profiling/ProfilingUtils.cpp
+++ b/src/profiling/ProfilingUtils.cpp
@@ -99,7 +99,14 @@
                          uint32_t packetId)
 {
     return (( packetFamily & 0x0000003F ) << 26 )|
-           (( packetId & 0x000003FF )     << 16 );
+           (( packetId     & 0x000003FF ) << 16 );
+}
+
+uint32_t ConstructHeader(uint32_t packetFamily, uint32_t packetClass, uint32_t packetType)
+{
+    return ((packetFamily & 0x0000003F) << 26) |
+           ((packetClass  & 0x0000007F) << 19) |
+           ((packetType   & 0x00000007) << 16);
 }
 
 void WriteUint64(const std::unique_ptr<IPacketBuffer>& packetBuffer, unsigned int offset, uint64_t value)
diff --git a/src/profiling/ProfilingUtils.hpp b/src/profiling/ProfilingUtils.hpp
index 2ead316..985c49e 100644
--- a/src/profiling/ProfilingUtils.hpp
+++ b/src/profiling/ProfilingUtils.hpp
@@ -150,6 +150,8 @@
 
 uint32_t ConstructHeader(uint32_t packetFamily, uint32_t packetId);
 
+uint32_t ConstructHeader(uint32_t packetFamily, uint32_t packetClass, uint32_t packetType);
+
 void WriteUint64(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint64_t value);
 
 void WriteUint32(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint32_t value);
diff --git a/src/profiling/SendCounterPacket.cpp b/src/profiling/SendCounterPacket.cpp
index 21f3116..2182ce6 100644
--- a/src/profiling/SendCounterPacket.cpp
+++ b/src/profiling/SendCounterPacket.cpp
@@ -1,5 +1,5 @@
 //
-// Copyright © 2017 Arm Ltd. All rights reserved.
+// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
 // SPDX-License-Identifier: MIT
 //
 
@@ -44,17 +44,41 @@
     const uint32_t packetVersionCountSize = sizeUint32;
 
     // Supported Packets
-    // Stream metadata packet            (packet family=0; packet id=0)
-    // Connection Acknowledged packet    (packet family=0, packet id=1)
-    // Counter Directory packet          (packet family=0; packet id=2)
-    // Request Counter Directory packet  (packet family=0, packet id=3)
-    // Periodic Counter Selection packet (packet family=0, packet id=4)
-    // Periodic Counter Capture packet   (packet family=1, packet class=0, type=0)
-    const uint32_t packetVersionEntries = 6;
+    // Packet Encoding version 1.0.0
+    // Control packet family
+    //   Stream metadata packet (packet family=0; packet id=0)
+    //   Connection Acknowledged packet ( packet family=0, packet id=1) Version 1.0.0
+    //   Counter Directory packet (packet family=0; packet id=2) Version 1.0.0
+    //   Request Counter Directory packet ( packet family=0, packet id=3) Version 1.0.0
+    //   Periodic Counter Selection packet ( packet family=0, packet id=4) Version 1.0.0
+    //   Per Job Counter Selection packet ( packet family=0, packet id=5) Version 1.0.0
+    //   Activate Timeline Reporting (packet family = 0, packet id = 6) Version 1.0.0
+    //   Deactivate Timeline Reporting (packet family = 0, packet id = 7) Version 1.0.0
+    // Counter Packet Family
+    //   Periodic Counter Capture (packet_family = 3, packet_class = 0, packet_type = 0) Version 1.0.0
+    //   Per-Job Counter Capture (packet_family = 3, packet_class = 1, packet_type = 0,1) Version  1.0.0
+    // Timeline Packet Family
+    //   Timeline Message Directory (packet_family = 1, packet_class = 0, packet_type = 0) Version 1.0.0
+    //   Timeline Message (packet_family = 1, packet_class = 0, packet_type = 1) Version 1.0.0
+    std::vector<std::pair<uint32_t, uint32_t>> packetVersions;
+    packetVersions.push_back(std::make_pair(ConstructHeader(0, 0), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(0, 1), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(0, 2), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(0, 3), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(0, 4), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(0, 5), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(0, 6), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(0, 7), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(3, 0, 0), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(3, 1, 0), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(3, 1, 1), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(1, 0, 0), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(1, 0, 1), EncodeVersion(1, 0, 0)));
+    uint32_t numberOfVersions = numeric_cast<uint32_t>(packetVersions.size());
+    uint32_t packetVersionSize = numeric_cast<uint32_t>(numberOfVersions * 2 * sizeUint32);
 
     const uint32_t payloadSize = numeric_cast<uint32_t>(infoSize + hardwareVersionSize + softwareVersionSize +
-                                                  processNameSize + packetVersionCountSize +
-                                                  (packetVersionEntries * 2 * sizeUint32));
+                                                  processNameSize + packetVersionCountSize + packetVersionSize);
 
     const uint32_t totalSize = headerSize + bodySize + payloadSize;
     uint32_t offset = 0;
@@ -122,30 +146,20 @@
         memcpy(&writeBuffer->GetWritableData()[offset], processName.c_str(), processNameSize);
         offset += processNameSize;
 
-        if (packetVersionEntries)
+        if (!packetVersions.empty())
         {
             // Packet Version Count
-            WriteUint32(writeBuffer, offset, packetVersionEntries << 16);
+            WriteUint32(writeBuffer, offset, numberOfVersions << 16);
+            offset += sizeUint32;
 
             // Packet Version Entries
-            uint32_t packetFamily = 0;
-            uint32_t packetId = 0;
-
-            offset += sizeUint32;
-            for (uint32_t i = 0; i < packetVersionEntries - 1; ++i)
+            for (std::pair<uint32_t, uint32_t>& packetVersion : packetVersions)
             {
-                WriteUint32(writeBuffer, offset, ((packetFamily & 0x3F) << 26) | ((packetId++ & 0x3FF) << 16));
+                WriteUint32(writeBuffer, offset, packetVersion.first);
                 offset += sizeUint32;
-                WriteUint32(writeBuffer, offset, EncodeVersion(1, 0, 0));
+                WriteUint32(writeBuffer, offset, packetVersion.second);
                 offset += sizeUint32;
             }
-
-            packetFamily = 1;
-            packetId = 0;
-
-            WriteUint32(writeBuffer, offset, ((packetFamily & 0x3F) << 26) | ((packetId & 0x3FF) << 16));
-            offset += sizeUint32;
-            WriteUint32(writeBuffer, offset, EncodeVersion(1, 0, 0));
         }
     }
     catch(...)
diff --git a/src/profiling/SendCounterPacket.hpp b/src/profiling/SendCounterPacket.hpp
index 4262c93..ddf8b24 100644
--- a/src/profiling/SendCounterPacket.hpp
+++ b/src/profiling/SendCounterPacket.hpp
@@ -1,5 +1,5 @@
 //
-// Copyright © 2017 Arm Ltd. All rights reserved.
+// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
 // SPDX-License-Identifier: MIT
 //
 
diff --git a/src/profiling/test/ProfilingTestUtils.cpp b/src/profiling/test/ProfilingTestUtils.cpp
index 526f3f9..2dae5cf 100644
--- a/src/profiling/test/ProfilingTestUtils.cpp
+++ b/src/profiling/test/ProfilingTestUtils.cpp
@@ -25,7 +25,7 @@
     payloadSize += boost::numeric_cast<uint32_t>(GetProcessName().size()) + 1;
 
     // Add packetVersionEntries
-    payloadSize += 6 * 2 * sizeUint32;
+    payloadSize += 13 * 2 * sizeUint32;
     // Add packetVersionCountSize
     payloadSize += sizeUint32;
 
diff --git a/src/profiling/test/SendCounterPacketTests.cpp b/src/profiling/test/SendCounterPacketTests.cpp
index dc9671b..c5f9177 100644
--- a/src/profiling/test/SendCounterPacketTests.cpp
+++ b/src/profiling/test/SendCounterPacketTests.cpp
@@ -1,5 +1,5 @@
 //
-// Copyright © 2019 Arm Ltd. All rights reserved.
+// Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
 // SPDX-License-Identifier: MIT
 //
 
@@ -307,7 +307,39 @@
     uint32_t softwareVersionSize = numeric_cast<uint32_t>(GetSoftwareVersion().size()) + 1;
     uint32_t processNameSize =     numeric_cast<uint32_t>(processName.size()) + 1;
 
-    uint32_t packetEntries = 6;
+    // Supported Packets
+    // Packet Encoding version 1.0.0
+    // Control packet family
+    //   Stream metadata packet (packet family=0; packet id=0)
+    //   Connection Acknowledged packet ( packet family=0, packet id=1) Version 1.0.0
+    //   Counter Directory packet (packet family=0; packet id=2) Version 1.0.0
+    //   Request Counter Directory packet ( packet family=0, packet id=3) Version 1.0.0
+    //   Periodic Counter Selection packet ( packet family=0, packet id=4) Version 1.0.0
+    //   Per Job Counter Selection packet ( packet family=0, packet id=5) Version 1.0.0
+    //   Activate Timeline Reporting (packet family = 0, packet id = 6) Version 1.0.0
+    //   Deactivate Timeline Reporting (packet family = 0, packet id = 7) Version 1.0.0
+    // Counter Packet Family
+    //   Periodic Counter Capture (packet_family = 3, packet_class = 0, packet_type = 0) Version 1.0.0
+    //   Per-Job Counter Capture (packet_family = 3, packet_class = 1, packet_type = 0,1) Version  1.0.0
+    // Timeline Packet Family
+    //   Timeline Message Directory (packet_family = 1, packet_class = 0, packet_type = 0) Version 1.0.0
+    //   Timeline Message (packet_family = 1, packet_class = 0, packet_type = 1) Version 1.0.0
+    std::vector<std::pair<uint32_t, uint32_t>> packetVersions;
+    packetVersions.push_back(std::make_pair(ConstructHeader(0, 0), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(0, 1), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(0, 2), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(0, 3), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(0, 4), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(0, 5), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(0, 6), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(0, 7), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(3, 0, 0), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(3, 1, 0), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(3, 1, 1), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(1, 0, 0), EncodeVersion(1, 0, 0)));
+    packetVersions.push_back(std::make_pair(ConstructHeader(1, 0, 1), EncodeVersion(1, 0, 0)));
+
+    uint32_t packetEntries = static_cast<uint32_t>(packetVersions.size());
 
     MockBufferManager mockBuffer2(512);
     SendCounterPacket sendPacket2(mockBuffer2);
@@ -382,22 +414,18 @@
 
     if (packetEntries)
     {
-        BOOST_TEST((ReadUint32(readBuffer2, offset) >> 16) == packetEntries);
+        uint32_t numberOfEntries = ReadUint32(readBuffer2, offset);
+        BOOST_TEST((numberOfEntries >> 16) == packetEntries);
         offset += sizeUint32;
-        for (uint32_t i = 0; i < packetEntries - 1; ++i)
+        for (std::pair<uint32_t, uint32_t>& packetVersion : packetVersions)
         {
-            BOOST_TEST(((ReadUint32(readBuffer2, offset) >> 26) & 0x3F) == 0);
-            BOOST_TEST(((ReadUint32(readBuffer2, offset) >> 16) & 0x3FF) == i);
+            uint32_t readPacketId = ReadUint32(readBuffer2, offset);
+            BOOST_TEST(packetVersion.first == readPacketId);
             offset += sizeUint32;
-            BOOST_TEST(ReadUint32(readBuffer2, offset) == EncodeVersion(1, 0, 0));
+            uint32_t readVersion = ReadUint32(readBuffer2, offset);
+            BOOST_TEST(packetVersion.second == readVersion);
             offset += sizeUint32;
         }
-
-        BOOST_TEST(((ReadUint32(readBuffer2, offset) >> 26) & 0x3F) == 1);
-        BOOST_TEST(((ReadUint32(readBuffer2, offset) >> 16) & 0x3FF) == 0);
-        offset += sizeUint32;
-        BOOST_TEST(ReadUint32(readBuffer2, offset) == EncodeVersion(1, 0, 0));
-        offset += sizeUint32;
     }
 
     BOOST_TEST(offset == totalLength);
diff --git a/src/profiling/test/SendCounterPacketTests.hpp b/src/profiling/test/SendCounterPacketTests.hpp
index 84c88ad..ef8f63d 100644
--- a/src/profiling/test/SendCounterPacketTests.hpp
+++ b/src/profiling/test/SendCounterPacketTests.hpp
@@ -1,5 +1,5 @@
 //
-// Copyright © 2019 Arm Ltd. All rights reserved.
+// Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
 // SPDX-License-Identifier: MIT
 //