Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2019 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "SendCounterPacketTests.hpp" |
| 7 | |
| 8 | #include <BufferManager.hpp> |
Jim Flynn | 00f3aaf | 2019-10-24 11:58:06 +0100 | [diff] [blame] | 9 | #include <ProfilingService.hpp> |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 10 | #include <ProfilingUtils.hpp> |
| 11 | #include <SendTimelinePacket.hpp> |
| 12 | #include <TimelinePacketWriterFactory.hpp> |
| 13 | |
| 14 | #include <boost/test/unit_test.hpp> |
Jim Flynn | ab84575 | 2019-10-25 13:17:30 +0100 | [diff] [blame] | 15 | #include <LabelsAndEventClasses.hpp> |
| 16 | |
| 17 | #include <functional> |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 18 | |
| 19 | using namespace armnn::profiling; |
| 20 | |
| 21 | BOOST_AUTO_TEST_SUITE(SendTimelinePacketTests) |
| 22 | |
| 23 | BOOST_AUTO_TEST_CASE(SendTimelineMessageDirectoryPackageTest) |
| 24 | { |
| 25 | MockBufferManager mockBuffer(512); |
| 26 | TimelinePacketWriterFactory timelinePacketWriterFactory(mockBuffer); |
| 27 | std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket(); |
| 28 | |
| 29 | sendTimelinePacket->SendTimelineMessageDirectoryPackage(); |
| 30 | |
| 31 | // Get the readable buffer |
| 32 | auto packetBuffer = mockBuffer.GetReadableBuffer(); |
| 33 | |
| 34 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 35 | // Check the packet header |
| 36 | unsigned int offset = 0; |
| 37 | uint32_t packetHeaderWord0 = ReadUint32(packetBuffer, offset); |
| 38 | uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F; |
| 39 | uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F; |
| 40 | uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007; |
| 41 | uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007; |
| 42 | |
| 43 | BOOST_CHECK(packetFamily == 1); |
| 44 | BOOST_CHECK(packetClass == 0); |
| 45 | BOOST_CHECK(packetType == 0); |
| 46 | BOOST_CHECK(streamId == 0); |
| 47 | |
| 48 | offset += uint32_t_size; |
| 49 | uint32_t packetHeaderWord1 = ReadUint32(packetBuffer, offset); |
| 50 | uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001; |
| 51 | uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF; |
| 52 | BOOST_CHECK(sequenceNumbered == 0); |
| 53 | BOOST_CHECK(dataLength == 416); |
| 54 | |
| 55 | offset += uint32_t_size; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame^] | 56 | uint32_t DeclCount = ReadUint32(packetBuffer, offset); |
| 57 | BOOST_CHECK(DeclCount == 5); |
| 58 | |
| 59 | offset += uint32_t_size; |
| 60 | SwTraceMessage swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 61 | |
| 62 | BOOST_CHECK(swTraceMessage.id == 0); |
| 63 | BOOST_CHECK(swTraceMessage.name == "declareLabel"); |
| 64 | BOOST_CHECK(swTraceMessage.uiName == "declare label"); |
| 65 | BOOST_CHECK(swTraceMessage.argTypes.size() == 2); |
| 66 | BOOST_CHECK(swTraceMessage.argTypes[0] == 'p'); |
| 67 | BOOST_CHECK(swTraceMessage.argTypes[1] == 's'); |
| 68 | BOOST_CHECK(swTraceMessage.argNames.size() == 2); |
| 69 | BOOST_CHECK(swTraceMessage.argNames[0] == "guid"); |
| 70 | BOOST_CHECK(swTraceMessage.argNames[1] == "value"); |
| 71 | |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame^] | 72 | swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 73 | |
| 74 | BOOST_CHECK(swTraceMessage.id == 1); |
| 75 | BOOST_CHECK(swTraceMessage.name == "declareEntity"); |
| 76 | BOOST_CHECK(swTraceMessage.uiName == "declare entity"); |
| 77 | BOOST_CHECK(swTraceMessage.argTypes.size() == 1); |
| 78 | BOOST_CHECK(swTraceMessage.argTypes[0] == 'p'); |
| 79 | BOOST_CHECK(swTraceMessage.argNames.size() == 1); |
| 80 | BOOST_CHECK(swTraceMessage.argNames[0] == "guid"); |
| 81 | |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame^] | 82 | swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 83 | |
| 84 | BOOST_CHECK(swTraceMessage.id == 2); |
| 85 | BOOST_CHECK(swTraceMessage.name == "declareEventClass"); |
| 86 | BOOST_CHECK(swTraceMessage.uiName == "declare event class"); |
| 87 | BOOST_CHECK(swTraceMessage.argTypes.size() == 1); |
| 88 | BOOST_CHECK(swTraceMessage.argTypes[0] == 'p'); |
| 89 | BOOST_CHECK(swTraceMessage.argNames.size() == 1); |
| 90 | BOOST_CHECK(swTraceMessage.argNames[0] == "guid"); |
| 91 | |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame^] | 92 | swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 93 | |
| 94 | BOOST_CHECK(swTraceMessage.id == 3); |
| 95 | BOOST_CHECK(swTraceMessage.name == "declareRelationship"); |
| 96 | BOOST_CHECK(swTraceMessage.uiName == "declare relationship"); |
| 97 | BOOST_CHECK(swTraceMessage.argTypes.size() == 4); |
| 98 | BOOST_CHECK(swTraceMessage.argTypes[0] == 'I'); |
| 99 | BOOST_CHECK(swTraceMessage.argTypes[1] == 'p'); |
| 100 | BOOST_CHECK(swTraceMessage.argTypes[2] == 'p'); |
| 101 | BOOST_CHECK(swTraceMessage.argTypes[3] == 'p'); |
| 102 | BOOST_CHECK(swTraceMessage.argNames.size() == 4); |
| 103 | BOOST_CHECK(swTraceMessage.argNames[0] == "relationshipType"); |
| 104 | BOOST_CHECK(swTraceMessage.argNames[1] == "relationshipGuid"); |
| 105 | BOOST_CHECK(swTraceMessage.argNames[2] == "headGuid"); |
| 106 | BOOST_CHECK(swTraceMessage.argNames[3] == "tailGuid"); |
| 107 | |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame^] | 108 | swTraceMessage = ReadSwTraceMessage(packetBuffer->GetReadableData(), offset); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 109 | |
| 110 | BOOST_CHECK(swTraceMessage.id == 4); |
| 111 | BOOST_CHECK(swTraceMessage.name == "declareEvent"); |
| 112 | BOOST_CHECK(swTraceMessage.uiName == "declare event"); |
| 113 | BOOST_CHECK(swTraceMessage.argTypes.size() == 3); |
| 114 | BOOST_CHECK(swTraceMessage.argTypes[0] == '@'); |
| 115 | BOOST_CHECK(swTraceMessage.argTypes[1] == 't'); |
| 116 | BOOST_CHECK(swTraceMessage.argTypes[2] == 'p'); |
| 117 | BOOST_CHECK(swTraceMessage.argNames.size() == 3); |
| 118 | BOOST_CHECK(swTraceMessage.argNames[0] == "timestamp"); |
| 119 | BOOST_CHECK(swTraceMessage.argNames[1] == "threadId"); |
| 120 | BOOST_CHECK(swTraceMessage.argNames[2] == "eventGuid"); |
| 121 | } |
| 122 | |
| 123 | BOOST_AUTO_TEST_CASE(SendTimelineEntityPlusEventClassBinaryPacketTest) |
| 124 | { |
| 125 | MockBufferManager bufferManager(40); |
| 126 | TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager); |
| 127 | std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket(); |
| 128 | |
| 129 | const uint64_t entityBinaryPacketProfilingGuid = 123456u; |
| 130 | sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid); |
| 131 | |
| 132 | const uint64_t eventClassBinaryPacketProfilingGuid = 789123u; |
| 133 | sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassBinaryPacketProfilingGuid); |
| 134 | |
| 135 | // Commit the messages |
| 136 | sendTimelinePacket->Commit(); |
| 137 | |
| 138 | // Get the readable buffer |
| 139 | auto packetBuffer = bufferManager.GetReadableBuffer(); |
| 140 | |
| 141 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 142 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 143 | |
| 144 | // Check the packet header |
| 145 | unsigned int offset = 0; |
| 146 | |
| 147 | // Reading TimelineEntityClassBinaryPacket |
| 148 | uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset); |
| 149 | uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F; |
| 150 | uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F; |
| 151 | uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007; |
| 152 | uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007; |
| 153 | |
| 154 | BOOST_CHECK(entityBinaryPacketFamily == 1); |
| 155 | BOOST_CHECK(entityBinaryPacketClass == 0); |
| 156 | BOOST_CHECK(entityBinaryPacketType == 1); |
| 157 | BOOST_CHECK(entityBinaryPacketStreamId == 0); |
| 158 | |
| 159 | offset += uint32_t_size; |
| 160 | uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset); |
| 161 | uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001; |
| 162 | uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF; |
| 163 | BOOST_CHECK(entityBinaryPacketSequenceNumbered == 0); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame^] | 164 | BOOST_CHECK(entityBinaryPacketDataLength == 12); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 165 | |
| 166 | // Check the decl_id |
| 167 | offset += uint32_t_size; |
| 168 | uint32_t entitytDecId = ReadUint32(packetBuffer, offset); |
| 169 | |
| 170 | BOOST_CHECK(entitytDecId == uint32_t(1)); |
| 171 | |
| 172 | // Check the profiling GUID |
| 173 | offset += uint32_t_size; |
| 174 | uint64_t readProfilingGuid = ReadUint64(packetBuffer, offset); |
| 175 | |
| 176 | BOOST_CHECK(readProfilingGuid == entityBinaryPacketProfilingGuid); |
| 177 | |
| 178 | // Reading TimelineEventClassBinaryPacket |
| 179 | offset += uint64_t_size; |
| 180 | uint32_t eventClassBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset); |
| 181 | uint32_t eventClassBinaryPacketFamily = (eventClassBinaryPacketHeaderWord0 >> 26) & 0x0000003F; |
| 182 | uint32_t eventClassBinaryPacketClass = (eventClassBinaryPacketHeaderWord0 >> 19) & 0x0000007F; |
| 183 | uint32_t eventClassBinaryPacketType = (eventClassBinaryPacketHeaderWord0 >> 16) & 0x00000007; |
| 184 | uint32_t eventClassBinaryPacketStreamId = (eventClassBinaryPacketHeaderWord0 >> 0) & 0x00000007; |
| 185 | |
| 186 | BOOST_CHECK(eventClassBinaryPacketFamily == 1); |
| 187 | BOOST_CHECK(eventClassBinaryPacketClass == 0); |
| 188 | BOOST_CHECK(eventClassBinaryPacketType == 1); |
| 189 | BOOST_CHECK(eventClassBinaryPacketStreamId == 0); |
| 190 | |
| 191 | offset += uint32_t_size; |
| 192 | uint32_t eventClassBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset); |
| 193 | uint32_t eventClassBinaryPacketSequenceNumbered = (eventClassBinaryPacketHeaderWord1 >> 24) & 0x00000001; |
| 194 | uint32_t eventClassBinaryPacketDataLength = (eventClassBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF; |
| 195 | BOOST_CHECK(eventClassBinaryPacketSequenceNumbered == 0); |
| 196 | BOOST_CHECK(eventClassBinaryPacketDataLength == 12); |
| 197 | |
| 198 | offset += uint32_t_size; |
| 199 | uint32_t eventClassDeclId = ReadUint32(packetBuffer, offset); |
| 200 | BOOST_CHECK(eventClassDeclId == uint32_t(2)); |
| 201 | |
| 202 | // Check the profiling GUID |
| 203 | offset += uint32_t_size; |
| 204 | readProfilingGuid = ReadUint64(packetBuffer, offset); |
| 205 | BOOST_CHECK(readProfilingGuid == eventClassBinaryPacketProfilingGuid); |
| 206 | |
| 207 | bufferManager.MarkRead(packetBuffer); |
| 208 | } |
| 209 | |
| 210 | BOOST_AUTO_TEST_CASE(SendTimelinePacketTests1) |
| 211 | { |
| 212 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 213 | unsigned int uint64_t_size = sizeof(uint64_t); |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 214 | unsigned int threadId_size = sizeof(std::thread::id); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 215 | |
| 216 | MockBufferManager bufferManager(512); |
| 217 | TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager); |
| 218 | std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket(); |
| 219 | |
| 220 | // Send TimelineEntityClassBinaryPacket |
| 221 | const uint64_t entityBinaryPacketProfilingGuid = 123456u; |
| 222 | sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid); |
| 223 | |
| 224 | // Commit the buffer |
| 225 | sendTimelinePacket->Commit(); |
| 226 | |
| 227 | // Get the readable buffer |
| 228 | auto packetBuffer = bufferManager.GetReadableBuffer(); |
| 229 | |
| 230 | // Check the packet header |
| 231 | unsigned int offset = 0; |
| 232 | |
| 233 | // Reading TimelineEntityClassBinaryPacket |
| 234 | uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset); |
| 235 | uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F; |
| 236 | uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F; |
| 237 | uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007; |
| 238 | uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007; |
| 239 | |
| 240 | BOOST_CHECK(entityBinaryPacketFamily == 1); |
| 241 | BOOST_CHECK(entityBinaryPacketClass == 0); |
| 242 | BOOST_CHECK(entityBinaryPacketType == 1); |
| 243 | BOOST_CHECK(entityBinaryPacketStreamId == 0); |
| 244 | |
| 245 | offset += uint32_t_size; |
| 246 | uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset); |
| 247 | uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001; |
| 248 | uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF; |
| 249 | BOOST_CHECK(entityBinaryPacketSequenceNumbered == 0); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame^] | 250 | BOOST_CHECK(entityBinaryPacketDataLength == 12); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 251 | |
| 252 | // Check the decl_id |
| 253 | offset += uint32_t_size; |
| 254 | uint32_t entitytDecId = ReadUint32(packetBuffer, offset); |
| 255 | |
| 256 | BOOST_CHECK(entitytDecId == uint32_t(1)); |
| 257 | |
| 258 | // Check the profiling GUID |
| 259 | offset += uint32_t_size; |
| 260 | uint64_t readProfilingGuid = ReadUint64(packetBuffer, offset); |
| 261 | |
| 262 | BOOST_CHECK(readProfilingGuid == entityBinaryPacketProfilingGuid); |
| 263 | |
| 264 | bufferManager.MarkRead(packetBuffer); |
| 265 | |
| 266 | // Send TimelineEventClassBinaryPacket |
| 267 | const uint64_t eventClassBinaryPacketProfilingGuid = 789123u; |
| 268 | sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassBinaryPacketProfilingGuid); |
| 269 | |
| 270 | // Commit the buffer |
| 271 | sendTimelinePacket->Commit(); |
| 272 | |
| 273 | // Get the readable buffer |
| 274 | packetBuffer = bufferManager.GetReadableBuffer(); |
| 275 | |
| 276 | // Check the packet header |
| 277 | offset = 0; |
| 278 | |
| 279 | // Reading TimelineEventClassBinaryPacket |
| 280 | uint32_t eventClassBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset); |
| 281 | uint32_t eventClassBinaryPacketFamily = (eventClassBinaryPacketHeaderWord0 >> 26) & 0x0000003F; |
| 282 | uint32_t eventClassBinaryPacketClass = (eventClassBinaryPacketHeaderWord0 >> 19) & 0x0000007F; |
| 283 | uint32_t eventClassBinaryPacketType = (eventClassBinaryPacketHeaderWord0 >> 16) & 0x00000007; |
| 284 | uint32_t eventClassBinaryPacketStreamId = (eventClassBinaryPacketHeaderWord0 >> 0) & 0x00000007; |
| 285 | |
| 286 | BOOST_CHECK(eventClassBinaryPacketFamily == 1); |
| 287 | BOOST_CHECK(eventClassBinaryPacketClass == 0); |
| 288 | BOOST_CHECK(eventClassBinaryPacketType == 1); |
| 289 | BOOST_CHECK(eventClassBinaryPacketStreamId == 0); |
| 290 | |
| 291 | offset += uint32_t_size; |
| 292 | uint32_t eventClassBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset); |
| 293 | uint32_t eventClassBinaryPacketSequenceNumbered = (eventClassBinaryPacketHeaderWord1 >> 24) & 0x00000001; |
| 294 | uint32_t eventClassBinaryPacketDataLength = (eventClassBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF; |
| 295 | BOOST_CHECK(eventClassBinaryPacketSequenceNumbered == 0); |
| 296 | BOOST_CHECK(eventClassBinaryPacketDataLength == 12); |
| 297 | |
| 298 | offset += uint32_t_size; |
| 299 | uint32_t eventClassDeclId = ReadUint32(packetBuffer, offset); |
| 300 | BOOST_CHECK(eventClassDeclId == uint32_t(2)); |
| 301 | |
| 302 | // Check the profiling GUID |
| 303 | offset += uint32_t_size; |
| 304 | readProfilingGuid = ReadUint64(packetBuffer, offset); |
| 305 | BOOST_CHECK(readProfilingGuid == eventClassBinaryPacketProfilingGuid); |
| 306 | |
| 307 | bufferManager.MarkRead(packetBuffer); |
| 308 | |
| 309 | // Send TimelineEventBinaryPacket |
| 310 | const uint64_t timestamp = 456789u; |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 311 | const std::thread::id threadId = std::this_thread::get_id(); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 312 | const uint64_t eventProfilingGuid = 123456u; |
| 313 | sendTimelinePacket->SendTimelineEventBinaryPacket(timestamp, threadId, eventProfilingGuid); |
| 314 | |
| 315 | // Commit the buffer |
| 316 | sendTimelinePacket->Commit(); |
| 317 | |
| 318 | // Get the readable buffer |
| 319 | packetBuffer = bufferManager.GetReadableBuffer(); |
| 320 | |
| 321 | // Check the packet header |
| 322 | offset = 0; |
| 323 | |
| 324 | // Reading TimelineEventBinaryPacket |
| 325 | uint32_t eventBinaryPacketHeaderWord0 = ReadUint32(packetBuffer, offset); |
| 326 | uint32_t eventBinaryPacketFamily = (eventBinaryPacketHeaderWord0 >> 26) & 0x0000003F; |
| 327 | uint32_t eventBinaryPacketClass = (eventBinaryPacketHeaderWord0 >> 19) & 0x0000007F; |
| 328 | uint32_t eventBinaryPacketType = (eventBinaryPacketHeaderWord0 >> 16) & 0x00000007; |
| 329 | uint32_t eventBinaryPacketStreamId = (eventBinaryPacketHeaderWord0 >> 0) & 0x00000007; |
| 330 | |
| 331 | BOOST_CHECK(eventBinaryPacketFamily == 1); |
| 332 | BOOST_CHECK(eventBinaryPacketClass == 0); |
| 333 | BOOST_CHECK(eventBinaryPacketType == 1); |
| 334 | BOOST_CHECK(eventBinaryPacketStreamId == 0); |
| 335 | |
| 336 | offset += uint32_t_size; |
| 337 | uint32_t eventBinaryPacketHeaderWord1 = ReadUint32(packetBuffer, offset); |
| 338 | uint32_t eventBinaryPacketSequenceNumbered = (eventBinaryPacketHeaderWord1 >> 24) & 0x00000001; |
| 339 | uint32_t eventBinaryPacketDataLength = (eventBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF; |
| 340 | BOOST_CHECK(eventBinaryPacketSequenceNumbered == 0); |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 341 | BOOST_CHECK(eventBinaryPacketDataLength == 28); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 342 | |
| 343 | // Check the decl_id |
| 344 | offset += uint32_t_size; |
| 345 | uint32_t eventDeclId = ReadUint32(packetBuffer, offset); |
| 346 | BOOST_CHECK(eventDeclId == 4); |
| 347 | |
| 348 | // Check the timestamp |
| 349 | offset += uint32_t_size; |
| 350 | uint64_t eventTimestamp = ReadUint64(packetBuffer, offset); |
| 351 | BOOST_CHECK(eventTimestamp == timestamp); |
| 352 | |
| 353 | // Check the thread id |
| 354 | offset += uint64_t_size; |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 355 | std::vector<uint8_t> readThreadId(threadId_size, 0); |
| 356 | ReadBytes(packetBuffer, offset, threadId_size, readThreadId.data()); |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 357 | BOOST_CHECK(readThreadId == threadId); |
| 358 | |
| 359 | // Check the profiling GUID |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 360 | offset += threadId_size; |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 361 | readProfilingGuid = ReadUint64(packetBuffer, offset); |
| 362 | BOOST_CHECK(readProfilingGuid == eventProfilingGuid); |
| 363 | } |
| 364 | |
| 365 | BOOST_AUTO_TEST_CASE(SendTimelinePacketTests2) |
| 366 | { |
| 367 | MockBufferManager bufferManager(40); |
| 368 | TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager); |
| 369 | std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket(); |
| 370 | |
| 371 | BOOST_CHECK_THROW(sendTimelinePacket->SendTimelineMessageDirectoryPackage(), |
| 372 | armnn::RuntimeException); |
| 373 | } |
| 374 | |
| 375 | BOOST_AUTO_TEST_CASE(SendTimelinePacketTests3) |
| 376 | { |
| 377 | MockBufferManager bufferManager(512); |
| 378 | TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager); |
| 379 | std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = timelinePacketWriterFactory.GetSendTimelinePacket(); |
| 380 | |
| 381 | // Send TimelineEntityClassBinaryPacket |
| 382 | const uint64_t entityBinaryPacketProfilingGuid = 123456u; |
| 383 | sendTimelinePacket->SendTimelineEntityBinaryPacket(entityBinaryPacketProfilingGuid); |
| 384 | |
| 385 | // Commit the buffer |
| 386 | sendTimelinePacket->Commit(); |
| 387 | |
| 388 | // Get the readable buffer |
| 389 | auto packetBuffer = bufferManager.GetReadableBuffer(); |
| 390 | |
| 391 | // Send TimelineEventClassBinaryPacket |
| 392 | const uint64_t eventClassBinaryPacketProfilingGuid = 789123u; |
| 393 | BOOST_CHECK_THROW(sendTimelinePacket->SendTimelineEventClassBinaryPacket(eventClassBinaryPacketProfilingGuid), |
| 394 | armnn::RuntimeException); |
| 395 | } |
| 396 | |
Jim Flynn | 00f3aaf | 2019-10-24 11:58:06 +0100 | [diff] [blame] | 397 | BOOST_AUTO_TEST_CASE(GetGuidsFromProfilingService) |
| 398 | { |
| 399 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
| 400 | options.m_EnableProfiling = true; |
| 401 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 402 | profilingService.ResetExternalProfilingOptions(options, true); |
| 403 | ProfilingStaticGuid staticGuid = profilingService.GenerateStaticId("dummy"); |
Jim Flynn | ab84575 | 2019-10-25 13:17:30 +0100 | [diff] [blame] | 404 | // TODO this will change again... |
| 405 | std::hash<std::string> hasher; |
| 406 | uint64_t hash = static_cast<uint64_t>(hasher("dummy")); |
| 407 | ProfilingStaticGuid expectedStaticValue(hash); |
Jim Flynn | 00f3aaf | 2019-10-24 11:58:06 +0100 | [diff] [blame] | 408 | BOOST_CHECK(staticGuid == expectedStaticValue); |
| 409 | ProfilingDynamicGuid dynamicGuid = profilingService.NextGuid(); |
Jim Flynn | ab84575 | 2019-10-25 13:17:30 +0100 | [diff] [blame] | 410 | uint64_t dynamicGuidValue = static_cast<uint64_t>(dynamicGuid); |
| 411 | ++dynamicGuidValue; |
| 412 | ProfilingDynamicGuid expectedDynamicValue(dynamicGuidValue); |
| 413 | dynamicGuid = profilingService.NextGuid(); |
Jim Flynn | 00f3aaf | 2019-10-24 11:58:06 +0100 | [diff] [blame] | 414 | BOOST_CHECK(dynamicGuid == expectedDynamicValue); |
| 415 | } |
| 416 | |
Jim Flynn | 8b20065 | 2019-10-24 18:07:44 +0100 | [diff] [blame] | 417 | BOOST_AUTO_TEST_CASE(GetTimelinePackerWriterFromProfilingService) |
| 418 | { |
| 419 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
| 420 | options.m_EnableProfiling = true; |
| 421 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 422 | profilingService.ResetExternalProfilingOptions(options, true); |
| 423 | |
| 424 | std::unique_ptr<ISendTimelinePacket> writer = profilingService.GetSendTimelinePacket(); |
| 425 | BOOST_CHECK(writer != nullptr); |
| 426 | } |
| 427 | |
Jim Flynn | ab84575 | 2019-10-25 13:17:30 +0100 | [diff] [blame] | 428 | BOOST_AUTO_TEST_CASE(CheckStaticGuidsAndEvents) |
| 429 | { |
| 430 | BOOST_CHECK("name" == LabelsAndEventClasses::NAME_LABEL); |
| 431 | BOOST_CHECK("type" == LabelsAndEventClasses::TYPE_LABEL); |
| 432 | BOOST_CHECK("index" == LabelsAndEventClasses::INDEX_LABEL); |
| 433 | |
| 434 | std::hash<std::string> hasher; |
| 435 | |
| 436 | uint64_t hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::NAME_LABEL)); |
| 437 | ProfilingStaticGuid expectedNameGuid(hash); |
| 438 | BOOST_CHECK(LabelsAndEventClasses::NAME_GUID == expectedNameGuid); |
| 439 | |
| 440 | hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::TYPE_LABEL)); |
| 441 | ProfilingStaticGuid expectedTypeGuid(hash); |
| 442 | BOOST_CHECK(LabelsAndEventClasses::TYPE_GUID == expectedTypeGuid); |
| 443 | |
| 444 | hash = static_cast<uint64_t>(hasher(LabelsAndEventClasses::INDEX_LABEL)); |
| 445 | ProfilingStaticGuid expectedIndexGuid(hash); |
| 446 | BOOST_CHECK(LabelsAndEventClasses::INDEX_GUID == expectedIndexGuid); |
| 447 | |
| 448 | hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_SOL")); |
| 449 | ProfilingStaticGuid expectedSol(hash); |
| 450 | BOOST_CHECK(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS == expectedSol); |
| 451 | |
| 452 | hash = static_cast<uint64_t>(hasher("ARMNN_PROFILING_EOL")); |
| 453 | ProfilingStaticGuid expectedEol(hash); |
| 454 | BOOST_CHECK(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS == expectedEol); |
| 455 | } |
| 456 | |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 457 | BOOST_AUTO_TEST_SUITE_END() |