Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +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 <SendTimelinePacket.hpp> |
| 9 | #include <TimelineUtilityMethods.hpp> |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 10 | #include <LabelsAndEventClasses.hpp> |
Matteo Martincigh | c040199 | 2019-10-28 15:24:34 +0000 | [diff] [blame] | 11 | #include <ProfilingService.hpp> |
Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +0100 | [diff] [blame] | 12 | |
| 13 | #include <boost/test/unit_test.hpp> |
| 14 | |
| 15 | using namespace armnn; |
| 16 | using namespace armnn::profiling; |
| 17 | |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 18 | namespace |
| 19 | { |
| 20 | |
| 21 | inline unsigned int OffsetToNextWord(unsigned int numberOfBytes) |
| 22 | { |
| 23 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 24 | |
| 25 | unsigned int remainder = numberOfBytes % uint32_t_size; |
| 26 | if (remainder == 0) |
| 27 | { |
| 28 | return numberOfBytes; |
| 29 | } |
| 30 | |
| 31 | return numberOfBytes + uint32_t_size - remainder; |
| 32 | } |
| 33 | |
Matteo Martincigh | c040199 | 2019-10-28 15:24:34 +0000 | [diff] [blame] | 34 | void VerifyTimelineLabelBinaryPacket(Optional<ProfilingGuid> guid, |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 35 | const std::string& label, |
| 36 | const unsigned char* readableData, |
| 37 | unsigned int& offset) |
| 38 | { |
| 39 | BOOST_ASSERT(readableData); |
| 40 | |
| 41 | // Utils |
| 42 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 43 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 44 | unsigned int label_size = boost::numeric_cast<unsigned int>(label.size()); |
| 45 | |
| 46 | // Check the TimelineLabelBinaryPacket header |
| 47 | uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(readableData, offset); |
| 48 | uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F; |
| 49 | uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F; |
| 50 | uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007; |
| 51 | uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007; |
| 52 | BOOST_CHECK(entityBinaryPacketFamily == 1); |
| 53 | BOOST_CHECK(entityBinaryPacketClass == 0); |
| 54 | BOOST_CHECK(entityBinaryPacketType == 1); |
| 55 | BOOST_CHECK(entityBinaryPacketStreamId == 0); |
| 56 | offset += uint32_t_size; |
| 57 | uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(readableData, offset); |
| 58 | uint32_t eventBinaryPacketSequenceNumber = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001; |
| 59 | uint32_t eventBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF; |
| 60 | BOOST_CHECK(eventBinaryPacketSequenceNumber == 0); |
| 61 | BOOST_CHECK(eventBinaryPacketDataLength == 16 + OffsetToNextWord(label_size + 1)); |
| 62 | |
| 63 | // Check the decl id |
| 64 | offset += uint32_t_size; |
| 65 | uint32_t eventClassDeclId = ReadUint32(readableData, offset); |
| 66 | BOOST_CHECK(eventClassDeclId == 0); |
| 67 | |
| 68 | // Check the profiling GUID |
| 69 | offset += uint32_t_size; |
| 70 | uint64_t readProfilingGuid = ReadUint64(readableData, offset); |
Matteo Martincigh | c040199 | 2019-10-28 15:24:34 +0000 | [diff] [blame] | 71 | if (guid.has_value()) |
| 72 | { |
| 73 | BOOST_CHECK(readProfilingGuid == guid.value()); |
| 74 | } |
| 75 | else |
| 76 | { |
| 77 | BOOST_CHECK(readProfilingGuid == ProfilingService::Instance().GenerateStaticId(label)); |
| 78 | } |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 79 | |
| 80 | // Check the SWTrace label |
| 81 | offset += uint64_t_size; |
| 82 | uint32_t swTraceLabelLength = ReadUint32(readableData, offset); |
| 83 | BOOST_CHECK(swTraceLabelLength == label_size + 1); // Label length including the null-terminator |
| 84 | offset += uint32_t_size; |
| 85 | BOOST_CHECK(std::memcmp(readableData + offset, // Offset to the label in the buffer |
| 86 | label.data(), // The original label |
| 87 | swTraceLabelLength - 1) == 0); // The length of the label |
| 88 | BOOST_CHECK(readableData[offset + swTraceLabelLength] == '\0'); // The null-terminator |
| 89 | |
| 90 | // SWTrace strings are written in blocks of words, so the offset has to be updated to the next whole word |
| 91 | offset += OffsetToNextWord(swTraceLabelLength); |
| 92 | } |
| 93 | |
| 94 | void VerifyTimelineEventClassBinaryPacket(ProfilingGuid guid, |
| 95 | const unsigned char* readableData, |
| 96 | unsigned int& offset) |
| 97 | { |
| 98 | BOOST_ASSERT(readableData); |
| 99 | |
| 100 | // Utils |
| 101 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 102 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 103 | |
| 104 | // Check the TimelineEventClassBinaryPacket header |
| 105 | uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(readableData, offset); |
| 106 | uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F; |
| 107 | uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F; |
| 108 | uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007; |
| 109 | uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007; |
| 110 | BOOST_CHECK(entityBinaryPacketFamily == 1); |
| 111 | BOOST_CHECK(entityBinaryPacketClass == 0); |
| 112 | BOOST_CHECK(entityBinaryPacketType == 1); |
| 113 | BOOST_CHECK(entityBinaryPacketStreamId == 0); |
| 114 | offset += uint32_t_size; |
| 115 | uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(readableData, offset); |
| 116 | uint32_t eventBinaryPacketSequenceNumber = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001; |
| 117 | uint32_t eventBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF; |
| 118 | BOOST_CHECK(eventBinaryPacketSequenceNumber == 0); |
| 119 | BOOST_CHECK(eventBinaryPacketDataLength == 12); |
| 120 | |
| 121 | // Check the decl id |
| 122 | offset += uint32_t_size; |
| 123 | uint32_t eventClassDeclId = ReadUint32(readableData, offset); |
| 124 | BOOST_CHECK(eventClassDeclId == 2); |
| 125 | |
| 126 | // Check the profiling GUID |
| 127 | offset += uint32_t_size; |
| 128 | uint64_t readProfilingGuid = ReadUint64(readableData, offset); |
| 129 | BOOST_CHECK(readProfilingGuid == guid); |
| 130 | |
Matteo Martincigh | c040199 | 2019-10-28 15:24:34 +0000 | [diff] [blame] | 131 | // Update the offset to allow parsing to be continued after this function returns |
| 132 | offset += uint64_t_size; |
| 133 | } |
| 134 | |
| 135 | void VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType relationshipType, |
| 136 | Optional<ProfilingGuid> relationshipGuid, |
| 137 | Optional<ProfilingGuid> headGuid, |
| 138 | Optional<ProfilingGuid> tailGuid, |
| 139 | const unsigned char* readableData, |
| 140 | unsigned int& offset) |
| 141 | { |
| 142 | BOOST_ASSERT(readableData); |
| 143 | |
| 144 | uint32_t relationshipTypeUint = 0; |
| 145 | switch (relationshipType) |
| 146 | { |
| 147 | case ProfilingRelationshipType::RetentionLink: |
| 148 | relationshipTypeUint = 0; |
| 149 | break; |
| 150 | case ProfilingRelationshipType::ExecutionLink: |
| 151 | relationshipTypeUint = 1; |
| 152 | break; |
| 153 | case ProfilingRelationshipType::DataLink: |
| 154 | relationshipTypeUint = 2; |
| 155 | break; |
| 156 | case ProfilingRelationshipType::LabelLink: |
| 157 | relationshipTypeUint = 3; |
| 158 | break; |
| 159 | default: |
| 160 | BOOST_ERROR("Unknown relationship type"); |
| 161 | } |
| 162 | |
| 163 | // Utils |
| 164 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 165 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 166 | |
| 167 | // Check the TimelineLabelBinaryPacket header |
| 168 | uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(readableData, offset); |
| 169 | uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F; |
| 170 | uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F; |
| 171 | uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007; |
| 172 | uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007; |
| 173 | BOOST_CHECK(entityBinaryPacketFamily == 1); |
| 174 | BOOST_CHECK(entityBinaryPacketClass == 0); |
| 175 | BOOST_CHECK(entityBinaryPacketType == 1); |
| 176 | BOOST_CHECK(entityBinaryPacketStreamId == 0); |
| 177 | offset += uint32_t_size; |
| 178 | uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(readableData, offset); |
| 179 | uint32_t eventBinaryPacketSequenceNumber = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001; |
| 180 | uint32_t eventBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF; |
| 181 | BOOST_CHECK(eventBinaryPacketSequenceNumber == 0); |
| 182 | BOOST_CHECK(eventBinaryPacketDataLength == 32); |
| 183 | |
| 184 | // Check the decl id |
| 185 | offset += uint32_t_size; |
| 186 | uint32_t eventClassDeclId = ReadUint32(readableData, offset); |
| 187 | BOOST_CHECK(eventClassDeclId == 3); |
| 188 | |
| 189 | // Check the relationship type |
| 190 | offset += uint32_t_size; |
| 191 | uint32_t readRelationshipTypeUint = ReadUint32(readableData, offset); |
| 192 | BOOST_CHECK(readRelationshipTypeUint == relationshipTypeUint); |
| 193 | |
| 194 | // Check the relationship GUID |
| 195 | offset += uint32_t_size; |
| 196 | uint64_t readRelationshipGuid = ReadUint64(readableData, offset); |
| 197 | if (relationshipGuid.has_value()) |
| 198 | { |
| 199 | BOOST_CHECK(readRelationshipGuid == relationshipGuid.value()); |
| 200 | } |
| 201 | else |
| 202 | { |
| 203 | BOOST_CHECK(readRelationshipGuid != ProfilingGuid(0)); |
| 204 | } |
| 205 | |
| 206 | // Check the head of relationship GUID |
| 207 | offset += uint64_t_size; |
| 208 | uint64_t readHeadRelationshipGuid = ReadUint64(readableData, offset); |
| 209 | if (headGuid.has_value()) |
| 210 | { |
| 211 | BOOST_CHECK(readHeadRelationshipGuid == headGuid.value()); |
| 212 | } |
| 213 | else |
| 214 | { |
| 215 | BOOST_CHECK(readHeadRelationshipGuid != ProfilingGuid(0)); |
| 216 | } |
| 217 | |
| 218 | // Check the tail of relationship GUID |
| 219 | offset += uint64_t_size; |
| 220 | uint64_t readTailRelationshipGuid = ReadUint64(readableData, offset); |
| 221 | if (tailGuid.has_value()) |
| 222 | { |
| 223 | BOOST_CHECK(readTailRelationshipGuid == tailGuid.value()); |
| 224 | } |
| 225 | else |
| 226 | { |
| 227 | BOOST_CHECK(readTailRelationshipGuid != ProfilingGuid(0)); |
| 228 | } |
| 229 | |
| 230 | // Update the offset to allow parsing to be continued after this function returns |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 231 | offset += uint64_t_size; |
| 232 | } |
| 233 | |
Narumol Prangnawarat | 94a3088 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 234 | void VerifyTimelineEntityBinaryPacket(Optional<ProfilingGuid> guid, |
| 235 | const unsigned char* readableData, |
| 236 | unsigned int& offset) |
Narumol Prangnawarat | d034e08 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 237 | { |
| 238 | BOOST_ASSERT(readableData); |
| 239 | |
| 240 | // Utils |
| 241 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 242 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 243 | |
| 244 | // Reading TimelineEntityClassBinaryPacket |
| 245 | uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(readableData, offset); |
| 246 | uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F; |
| 247 | uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F; |
| 248 | uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007; |
| 249 | uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007; |
| 250 | |
| 251 | BOOST_CHECK(entityBinaryPacketFamily == 1); |
| 252 | BOOST_CHECK(entityBinaryPacketClass == 0); |
| 253 | BOOST_CHECK(entityBinaryPacketType == 1); |
| 254 | BOOST_CHECK(entityBinaryPacketStreamId == 0); |
| 255 | |
| 256 | offset += uint32_t_size; |
| 257 | uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(readableData, offset); |
| 258 | uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001; |
| 259 | uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF; |
| 260 | BOOST_CHECK(entityBinaryPacketSequenceNumbered == 0); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 261 | BOOST_CHECK(entityBinaryPacketDataLength == 12); |
Narumol Prangnawarat | d034e08 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 262 | |
| 263 | // Check the decl_id |
| 264 | offset += uint32_t_size; |
Matteo Martincigh | 5dc816e | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 265 | uint32_t entityDeclId = ReadUint32(readableData, offset); |
| 266 | BOOST_CHECK(entityDeclId == 1); |
Narumol Prangnawarat | d034e08 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 267 | |
| 268 | // Check the profiling GUID |
| 269 | offset += uint32_t_size; |
| 270 | uint64_t readProfilingGuid = ReadUint64(readableData, offset); |
| 271 | |
| 272 | if (guid.has_value()) |
| 273 | { |
| 274 | BOOST_CHECK(readProfilingGuid == guid.value()); |
| 275 | } |
| 276 | else |
| 277 | { |
| 278 | BOOST_CHECK(readProfilingGuid != ProfilingGuid(0)); |
| 279 | } |
| 280 | |
| 281 | offset += uint64_t_size; |
| 282 | } |
| 283 | |
Matteo Martincigh | 5dc816e | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 284 | void VerifyTimelineEventBinaryPacket(Optional<uint64_t> timestamp, |
| 285 | Optional<std::thread::id> threadId, |
| 286 | Optional<ProfilingGuid> eventGuid, |
| 287 | const unsigned char* readableData, |
| 288 | unsigned int& offset) |
| 289 | { |
| 290 | BOOST_ASSERT(readableData); |
| 291 | |
| 292 | // Utils |
| 293 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 294 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 295 | unsigned int threadId_size = sizeof(std::thread::id); |
| 296 | |
| 297 | // Reading TimelineEventBinaryPacket |
| 298 | uint32_t entityBinaryPacketHeaderWord0 = ReadUint32(readableData, offset); |
| 299 | uint32_t entityBinaryPacketFamily = (entityBinaryPacketHeaderWord0 >> 26) & 0x0000003F; |
| 300 | uint32_t entityBinaryPacketClass = (entityBinaryPacketHeaderWord0 >> 19) & 0x0000007F; |
| 301 | uint32_t entityBinaryPacketType = (entityBinaryPacketHeaderWord0 >> 16) & 0x00000007; |
| 302 | uint32_t entityBinaryPacketStreamId = (entityBinaryPacketHeaderWord0 >> 0) & 0x00000007; |
| 303 | |
| 304 | BOOST_CHECK(entityBinaryPacketFamily == 1); |
| 305 | BOOST_CHECK(entityBinaryPacketClass == 0); |
| 306 | BOOST_CHECK(entityBinaryPacketType == 1); |
| 307 | BOOST_CHECK(entityBinaryPacketStreamId == 0); |
| 308 | |
| 309 | offset += uint32_t_size; |
| 310 | uint32_t entityBinaryPacketHeaderWord1 = ReadUint32(readableData, offset); |
| 311 | uint32_t entityBinaryPacketSequenceNumbered = (entityBinaryPacketHeaderWord1 >> 24) & 0x00000001; |
| 312 | uint32_t entityBinaryPacketDataLength = (entityBinaryPacketHeaderWord1 >> 0) & 0x00FFFFFF; |
| 313 | BOOST_CHECK(entityBinaryPacketSequenceNumbered == 0); |
| 314 | BOOST_CHECK(entityBinaryPacketDataLength == 20 + threadId_size); |
| 315 | |
| 316 | // Check the decl_id |
| 317 | offset += uint32_t_size; |
| 318 | uint32_t entityDeclId = ReadUint32(readableData, offset); |
| 319 | BOOST_CHECK(entityDeclId == 4); |
| 320 | |
| 321 | // Check the timestamp |
| 322 | offset += uint32_t_size; |
| 323 | uint64_t readTimestamp = ReadUint64(readableData, offset); |
| 324 | if (timestamp.has_value()) |
| 325 | { |
| 326 | BOOST_CHECK(readTimestamp == timestamp.value()); |
| 327 | } |
| 328 | else |
| 329 | { |
| 330 | BOOST_CHECK(readTimestamp != 0); |
| 331 | } |
| 332 | |
| 333 | // Check the thread id |
| 334 | offset += uint64_t_size; |
| 335 | std::vector<uint8_t> readThreadId(threadId_size, 0); |
| 336 | ReadBytes(readableData, offset, threadId_size, readThreadId.data()); |
| 337 | if (threadId.has_value()) |
| 338 | { |
| 339 | BOOST_CHECK(readThreadId == threadId.value()); |
| 340 | } |
| 341 | else |
| 342 | { |
| 343 | BOOST_CHECK(readThreadId == std::this_thread::get_id()); |
| 344 | } |
| 345 | |
| 346 | // Check the event GUID |
| 347 | offset += threadId_size; |
| 348 | uint64_t readEventGuid = ReadUint64(readableData, offset); |
| 349 | if (eventGuid.has_value()) |
| 350 | { |
| 351 | BOOST_CHECK(readEventGuid == eventGuid.value()); |
| 352 | } |
| 353 | else |
| 354 | { |
| 355 | BOOST_CHECK(readEventGuid != ProfilingGuid(0)); |
| 356 | } |
| 357 | |
| 358 | offset += uint64_t_size; |
| 359 | } |
| 360 | |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 361 | } // Anonymous namespace |
| 362 | |
Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +0100 | [diff] [blame] | 363 | BOOST_AUTO_TEST_SUITE(TimelineUtilityMethodsTests) |
| 364 | |
Matteo Martincigh | c040199 | 2019-10-28 15:24:34 +0000 | [diff] [blame] | 365 | BOOST_AUTO_TEST_CASE(CreateTypedLabelTest) |
| 366 | { |
| 367 | MockBufferManager mockBufferManager(1024); |
| 368 | SendTimelinePacket sendTimelinePacket(mockBufferManager); |
| 369 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 370 | |
Narumol Prangnawarat | dbdd1b4 | 2019-11-15 17:38:44 +0000 | [diff] [blame] | 371 | // Generate first guid to ensure that the named typed entity guid is not 0 on local single test. |
| 372 | ProfilingService::Instance().NextGuid(); |
| 373 | |
Matteo Martincigh | c040199 | 2019-10-28 15:24:34 +0000 | [diff] [blame] | 374 | ProfilingGuid entityGuid(123); |
| 375 | const std::string entityName = "some entity"; |
| 376 | ProfilingStaticGuid labelTypeGuid(456); |
| 377 | |
| 378 | BOOST_CHECK_NO_THROW(timelineUtilityMethods.CreateTypedLabel(entityGuid, entityName, labelTypeGuid)); |
| 379 | |
| 380 | // Commit all packets at once |
| 381 | sendTimelinePacket.Commit(); |
| 382 | |
| 383 | // Get the readable buffer |
| 384 | auto readableBuffer = mockBufferManager.GetReadableBuffer(); |
| 385 | BOOST_CHECK(readableBuffer != nullptr); |
| 386 | unsigned int size = readableBuffer->GetSize(); |
| 387 | BOOST_CHECK(size == 116); |
| 388 | const unsigned char* readableData = readableBuffer->GetReadableData(); |
| 389 | BOOST_CHECK(readableData != nullptr); |
| 390 | |
| 391 | // Utils |
| 392 | unsigned int offset = 0; |
| 393 | |
| 394 | // First packet sent: TimelineLabelBinaryPacket |
| 395 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityName, readableData, offset); |
| 396 | |
| 397 | // Second packet sent: TimelineRelationshipBinaryPacket |
| 398 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 399 | EmptyOptional(), |
| 400 | entityGuid, |
| 401 | EmptyOptional(), |
| 402 | readableData, |
| 403 | offset); |
| 404 | |
| 405 | // Third packet sent: TimelineRelationshipBinaryPacket |
| 406 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 407 | EmptyOptional(), |
| 408 | EmptyOptional(), |
| 409 | labelTypeGuid, |
| 410 | readableData, |
| 411 | offset); |
| 412 | |
| 413 | // Mark the buffer as read |
| 414 | mockBufferManager.MarkRead(readableBuffer); |
| 415 | } |
| 416 | |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 417 | BOOST_AUTO_TEST_CASE(SendWellKnownLabelsAndEventClassesTest) |
| 418 | { |
| 419 | MockBufferManager mockBufferManager(1024); |
| 420 | SendTimelinePacket sendTimelinePacket(mockBufferManager); |
| 421 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 422 | |
| 423 | BOOST_CHECK_NO_THROW(timelineUtilityMethods.SendWellKnownLabelsAndEventClasses()); |
| 424 | |
| 425 | // Commit all packets at once |
| 426 | sendTimelinePacket.Commit(); |
| 427 | |
| 428 | // Get the readable buffer |
| 429 | auto readableBuffer = mockBufferManager.GetReadableBuffer(); |
| 430 | BOOST_CHECK(readableBuffer != nullptr); |
| 431 | unsigned int size = readableBuffer->GetSize(); |
| 432 | BOOST_CHECK(size == 136); |
| 433 | const unsigned char* readableData = readableBuffer->GetReadableData(); |
| 434 | BOOST_CHECK(readableData != nullptr); |
| 435 | |
| 436 | // Utils |
| 437 | unsigned int offset = 0; |
| 438 | |
| 439 | // First "well-known" label: NAME |
| 440 | VerifyTimelineLabelBinaryPacket(LabelsAndEventClasses::NAME_GUID, |
| 441 | LabelsAndEventClasses::NAME_LABEL, |
| 442 | readableData, |
| 443 | offset); |
| 444 | |
| 445 | // Second "well-known" label: TYPE |
| 446 | VerifyTimelineLabelBinaryPacket(LabelsAndEventClasses::TYPE_GUID, |
| 447 | LabelsAndEventClasses::TYPE_LABEL, |
| 448 | readableData, |
| 449 | offset); |
| 450 | |
| 451 | // Third "well-known" label: INDEX |
| 452 | VerifyTimelineLabelBinaryPacket(LabelsAndEventClasses::INDEX_GUID, |
| 453 | LabelsAndEventClasses::INDEX_LABEL, |
| 454 | readableData, |
| 455 | offset); |
| 456 | |
| 457 | // First "well-known" event class: START OF LIFE |
| 458 | VerifyTimelineEventClassBinaryPacket(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS, |
| 459 | readableData, |
| 460 | offset); |
| 461 | |
Narumol Prangnawarat | 94a3088 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 462 | // Second "well-known" event class: END OF LIFE |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 463 | VerifyTimelineEventClassBinaryPacket(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS, |
| 464 | readableData, |
| 465 | offset); |
| 466 | |
| 467 | // Mark the buffer as read |
| 468 | mockBufferManager.MarkRead(readableBuffer); |
| 469 | } |
| 470 | |
Narumol Prangnawarat | 94a3088 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 471 | BOOST_AUTO_TEST_CASE(CreateNamedTypedChildEntityTest) |
| 472 | { |
| 473 | MockBufferManager mockBufferManager(1024); |
| 474 | SendTimelinePacket sendTimelinePacket(mockBufferManager); |
| 475 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 476 | |
Narumol Prangnawarat | 234d525 | 2019-11-19 15:49:18 +0000 | [diff] [blame] | 477 | ProfilingDynamicGuid childEntityGuid(0); |
Narumol Prangnawarat | 94a3088 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 478 | ProfilingGuid parentEntityGuid(123); |
| 479 | const std::string entityName = "some entity"; |
| 480 | const std::string entityType = "some type"; |
| 481 | |
Narumol Prangnawarat | dbdd1b4 | 2019-11-15 17:38:44 +0000 | [diff] [blame] | 482 | // Generate first guid to ensure that the named typed entity guid is not 0 on local single test. |
| 483 | ProfilingService::Instance().NextGuid(); |
| 484 | |
Narumol Prangnawarat | 94a3088 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 485 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid, "", entityType), |
| 486 | InvalidArgumentException); |
| 487 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid, entityName, ""), |
| 488 | InvalidArgumentException); |
Narumol Prangnawarat | 234d525 | 2019-11-19 15:49:18 +0000 | [diff] [blame] | 489 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity( |
| 490 | childEntityGuid, parentEntityGuid, "", entityType), InvalidArgumentException); |
| 491 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity( |
| 492 | childEntityGuid, parentEntityGuid, entityName, ""), InvalidArgumentException); |
Narumol Prangnawarat | 94a3088 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 493 | |
Narumol Prangnawarat | 94a3088 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 494 | BOOST_CHECK_NO_THROW(childEntityGuid = timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid, |
| 495 | entityName, |
| 496 | entityType)); |
| 497 | BOOST_CHECK(childEntityGuid != ProfilingGuid(0)); |
| 498 | |
| 499 | // Commit all packets at once |
| 500 | sendTimelinePacket.Commit(); |
| 501 | |
| 502 | // Get the readable buffer |
| 503 | auto readableBuffer = mockBufferManager.GetReadableBuffer(); |
| 504 | BOOST_CHECK(readableBuffer != nullptr); |
| 505 | unsigned int size = readableBuffer->GetSize(); |
| 506 | BOOST_CHECK(size == 292); |
| 507 | const unsigned char* readableData = readableBuffer->GetReadableData(); |
| 508 | BOOST_CHECK(readableData != nullptr); |
| 509 | |
| 510 | // Utils |
| 511 | unsigned int offset = 0; |
| 512 | |
| 513 | // First packet sent: TimelineEntityBinaryPacket |
| 514 | VerifyTimelineEntityBinaryPacket(EmptyOptional(), readableData, offset); |
| 515 | |
| 516 | // Second packet sent: TimelineLabelBinaryPacket |
| 517 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityName, readableData, offset); |
| 518 | |
| 519 | // Third packet sent: TimelineRelationshipBinaryPacket |
| 520 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 521 | EmptyOptional(), |
| 522 | EmptyOptional(), |
| 523 | EmptyOptional(), |
| 524 | readableData, |
| 525 | offset); |
| 526 | |
| 527 | // Fourth packet sent: TimelineRelationshipBinaryPacket |
| 528 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 529 | EmptyOptional(), |
| 530 | EmptyOptional(), |
| 531 | LabelsAndEventClasses::NAME_GUID, |
| 532 | readableData, |
| 533 | offset); |
| 534 | |
| 535 | // Fifth packet sent: TimelineLabelBinaryPacket |
| 536 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityType, readableData, offset); |
| 537 | |
| 538 | // Sixth packet sent: TimelineRelationshipBinaryPacket |
| 539 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 540 | EmptyOptional(), |
| 541 | EmptyOptional(), |
| 542 | EmptyOptional(), |
| 543 | readableData, |
| 544 | offset); |
| 545 | |
| 546 | // Seventh packet sent: TimelineRelationshipBinaryPacket |
| 547 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 548 | EmptyOptional(), |
| 549 | EmptyOptional(), |
| 550 | LabelsAndEventClasses::TYPE_GUID, |
| 551 | readableData, |
| 552 | offset); |
| 553 | |
| 554 | // Eighth packet sent: TimelineRelationshipBinaryPacket |
| 555 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink, |
| 556 | EmptyOptional(), |
| 557 | parentEntityGuid, |
| 558 | EmptyOptional(), |
| 559 | readableData, |
| 560 | offset); |
| 561 | |
| 562 | // Mark the buffer as read |
| 563 | mockBufferManager.MarkRead(readableBuffer); |
| 564 | } |
| 565 | |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 566 | BOOST_AUTO_TEST_CASE(DeclareLabelTest) |
Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +0100 | [diff] [blame] | 567 | { |
| 568 | MockBufferManager mockBufferManager(1024); |
| 569 | SendTimelinePacket sendTimelinePacket(mockBufferManager); |
| 570 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 571 | |
Narumol Prangnawarat | dbdd1b4 | 2019-11-15 17:38:44 +0000 | [diff] [blame] | 572 | // Generate first guid to ensure that the named typed entity guid is not 0 on local single test. |
| 573 | ProfilingService::Instance().NextGuid(); |
| 574 | |
Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +0100 | [diff] [blame] | 575 | // Try declaring an invalid (empty) label |
| 576 | BOOST_CHECK_THROW(timelineUtilityMethods.DeclareLabel(""), InvalidArgumentException); |
| 577 | |
| 578 | // Try declaring an invalid (wrong SWTrace format) label |
| 579 | BOOST_CHECK_THROW(timelineUtilityMethods.DeclareLabel("inv@lid lab€l"), RuntimeException); |
| 580 | |
| 581 | // Declare a valid label |
| 582 | const std::string labelName = "valid label"; |
| 583 | ProfilingGuid labelGuid = 0; |
| 584 | BOOST_CHECK_NO_THROW(labelGuid = timelineUtilityMethods.DeclareLabel(labelName)); |
Narumol Prangnawarat | dbdd1b4 | 2019-11-15 17:38:44 +0000 | [diff] [blame] | 585 | BOOST_CHECK(labelGuid != ProfilingGuid(0)); |
Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +0100 | [diff] [blame] | 586 | |
Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +0100 | [diff] [blame] | 587 | // Try adding the same label as before |
Narumol Prangnawarat | dbdd1b4 | 2019-11-15 17:38:44 +0000 | [diff] [blame] | 588 | ProfilingGuid newLabelGuid = 0; |
| 589 | BOOST_CHECK_NO_THROW(newLabelGuid = timelineUtilityMethods.DeclareLabel(labelName)); |
| 590 | BOOST_CHECK(newLabelGuid != ProfilingGuid(0)); |
| 591 | BOOST_CHECK(newLabelGuid == labelGuid); |
Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +0100 | [diff] [blame] | 592 | } |
| 593 | |
Narumol Prangnawarat | d034e08 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 594 | BOOST_AUTO_TEST_CASE(CreateNameTypeEntityInvalidTest) |
| 595 | { |
| 596 | MockBufferManager mockBufferManager(1024); |
| 597 | SendTimelinePacket sendTimelinePacket(mockBufferManager); |
| 598 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 599 | |
| 600 | // Invalid name |
| 601 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity("", "Type"), InvalidArgumentException); |
| 602 | |
| 603 | // Invalid type |
| 604 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity("Name", ""), InvalidArgumentException); |
| 605 | |
Narumol Prangnawarat | 234d525 | 2019-11-19 15:49:18 +0000 | [diff] [blame] | 606 | ProfilingDynamicGuid guid = ProfilingService::Instance().NextGuid(); |
| 607 | |
| 608 | // CreatedNamedTypedEntity with Guid - Invalid name |
| 609 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity(guid, "", "Type"), |
| 610 | InvalidArgumentException); |
| 611 | |
| 612 | // CreatedNamedTypedEntity with Guid - Invalid type |
| 613 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity(guid, "Name", ""), |
| 614 | InvalidArgumentException); |
| 615 | |
Narumol Prangnawarat | d034e08 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 616 | } |
| 617 | |
Matteo Martincigh | 5dc816e | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 618 | BOOST_AUTO_TEST_CASE(CreateNameTypeEntityTest) |
Narumol Prangnawarat | d034e08 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 619 | { |
| 620 | MockBufferManager mockBufferManager(1024); |
| 621 | SendTimelinePacket sendTimelinePacket(mockBufferManager); |
| 622 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 623 | |
| 624 | const std::string entityName = "Entity0"; |
| 625 | const std::string entityType = "Type0"; |
| 626 | |
Narumol Prangnawarat | dbdd1b4 | 2019-11-15 17:38:44 +0000 | [diff] [blame] | 627 | // Generate first guid to ensure that the named typed entity guid is not 0 on local single test. |
| 628 | ProfilingService::Instance().NextGuid(); |
| 629 | |
Narumol Prangnawarat | d034e08 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 630 | ProfilingDynamicGuid guid = timelineUtilityMethods.CreateNamedTypedEntity(entityName, entityType); |
| 631 | BOOST_CHECK(guid != ProfilingGuid(0)); |
| 632 | |
| 633 | // Commit all packets at once |
| 634 | sendTimelinePacket.Commit(); |
| 635 | |
| 636 | // Get the readable buffer |
| 637 | auto readableBuffer = mockBufferManager.GetReadableBuffer(); |
| 638 | BOOST_CHECK(readableBuffer != nullptr); |
| 639 | unsigned int size = readableBuffer->GetSize(); |
| 640 | BOOST_CHECK(size == 244); |
| 641 | const unsigned char* readableData = readableBuffer->GetReadableData(); |
| 642 | BOOST_CHECK(readableData != nullptr); |
| 643 | |
| 644 | // Utils |
| 645 | unsigned int offset = 0; |
| 646 | |
| 647 | // First packet sent: TimelineEntityBinaryPacket |
Narumol Prangnawarat | 94a3088 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 648 | VerifyTimelineEntityBinaryPacket(guid, readableData, offset); |
Narumol Prangnawarat | d034e08 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 649 | |
| 650 | // Packets for Name Entity |
| 651 | // First packet sent: TimelineLabelBinaryPacket |
| 652 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityName, readableData, offset); |
| 653 | |
| 654 | // Second packet sent: TimelineRelationshipBinaryPacket |
| 655 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 656 | EmptyOptional(), |
| 657 | EmptyOptional(), |
| 658 | EmptyOptional(), |
| 659 | readableData, |
| 660 | offset); |
| 661 | |
| 662 | // Third packet sent: TimelineRelationshipBinaryPacket |
| 663 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 664 | EmptyOptional(), |
| 665 | EmptyOptional(), |
| 666 | LabelsAndEventClasses::NAME_GUID, |
| 667 | readableData, |
| 668 | offset); |
| 669 | |
| 670 | // Packets for Type Entity |
| 671 | // First packet sent: TimelineLabelBinaryPacket |
| 672 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityType, readableData, offset); |
| 673 | |
| 674 | // Second packet sent: TimelineRelationshipBinaryPacket |
| 675 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 676 | EmptyOptional(), |
| 677 | EmptyOptional(), |
| 678 | EmptyOptional(), |
| 679 | readableData, |
| 680 | offset); |
| 681 | |
| 682 | // Third packet sent: TimelineRelationshipBinaryPacket |
| 683 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 684 | EmptyOptional(), |
| 685 | EmptyOptional(), |
| 686 | LabelsAndEventClasses::TYPE_GUID, |
| 687 | readableData, |
| 688 | offset); |
| 689 | |
| 690 | // Mark the buffer as read |
| 691 | mockBufferManager.MarkRead(readableBuffer); |
| 692 | } |
| 693 | |
Matteo Martincigh | 5dc816e | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 694 | BOOST_AUTO_TEST_CASE(RecordEventTest) |
| 695 | { |
| 696 | MockBufferManager mockBufferManager(1024); |
| 697 | SendTimelinePacket sendTimelinePacket(mockBufferManager); |
| 698 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 699 | |
Narumol Prangnawarat | dbdd1b4 | 2019-11-15 17:38:44 +0000 | [diff] [blame] | 700 | // Generate first guid to ensure that the named typed entity guid is not 0 on local single test. |
| 701 | ProfilingService::Instance().NextGuid(); |
| 702 | |
Matteo Martincigh | 5dc816e | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 703 | ProfilingGuid entityGuid(123); |
| 704 | ProfilingStaticGuid eventClassGuid(456); |
| 705 | ProfilingDynamicGuid eventGuid(0); |
| 706 | BOOST_CHECK_NO_THROW(eventGuid = timelineUtilityMethods.RecordEvent(entityGuid, eventClassGuid)); |
| 707 | BOOST_CHECK(eventGuid != ProfilingGuid(0)); |
| 708 | |
| 709 | // Commit all packets at once |
| 710 | sendTimelinePacket.Commit(); |
| 711 | |
| 712 | // Get the readable buffer |
| 713 | auto readableBuffer = mockBufferManager.GetReadableBuffer(); |
| 714 | BOOST_CHECK(readableBuffer != nullptr); |
| 715 | unsigned int size = readableBuffer->GetSize(); |
| 716 | BOOST_CHECK(size == 116); |
| 717 | const unsigned char* readableData = readableBuffer->GetReadableData(); |
| 718 | BOOST_CHECK(readableData != nullptr); |
| 719 | |
| 720 | // Utils |
| 721 | unsigned int offset = 0; |
| 722 | |
| 723 | // First packet sent: TimelineEntityBinaryPacket |
| 724 | VerifyTimelineEventBinaryPacket(EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset); |
| 725 | |
| 726 | // Second packet sent: TimelineRelationshipBinaryPacket |
| 727 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::ExecutionLink, |
| 728 | EmptyOptional(), |
| 729 | entityGuid, |
| 730 | EmptyOptional(), |
| 731 | readableData, |
| 732 | offset); |
| 733 | |
| 734 | // Third packet sent: TimelineRelationshipBinaryPacket |
| 735 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::DataLink, |
| 736 | EmptyOptional(), |
| 737 | entityGuid, |
| 738 | eventClassGuid, |
| 739 | readableData, |
| 740 | offset); |
| 741 | |
| 742 | // Mark the buffer as read |
| 743 | mockBufferManager.MarkRead(readableBuffer); |
| 744 | } |
| 745 | |
Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +0100 | [diff] [blame] | 746 | BOOST_AUTO_TEST_SUITE_END() |