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