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 | |
| 371 | ProfilingGuid entityGuid(123); |
| 372 | const std::string entityName = "some entity"; |
| 373 | ProfilingStaticGuid labelTypeGuid(456); |
| 374 | |
| 375 | BOOST_CHECK_NO_THROW(timelineUtilityMethods.CreateTypedLabel(entityGuid, entityName, labelTypeGuid)); |
| 376 | |
| 377 | // Commit all packets at once |
| 378 | sendTimelinePacket.Commit(); |
| 379 | |
| 380 | // Get the readable buffer |
| 381 | auto readableBuffer = mockBufferManager.GetReadableBuffer(); |
| 382 | BOOST_CHECK(readableBuffer != nullptr); |
| 383 | unsigned int size = readableBuffer->GetSize(); |
| 384 | BOOST_CHECK(size == 116); |
| 385 | const unsigned char* readableData = readableBuffer->GetReadableData(); |
| 386 | BOOST_CHECK(readableData != nullptr); |
| 387 | |
| 388 | // Utils |
| 389 | unsigned int offset = 0; |
| 390 | |
| 391 | // First packet sent: TimelineLabelBinaryPacket |
| 392 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityName, readableData, offset); |
| 393 | |
| 394 | // Second packet sent: TimelineRelationshipBinaryPacket |
| 395 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 396 | EmptyOptional(), |
| 397 | entityGuid, |
| 398 | EmptyOptional(), |
| 399 | readableData, |
| 400 | offset); |
| 401 | |
| 402 | // Third packet sent: TimelineRelationshipBinaryPacket |
| 403 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 404 | EmptyOptional(), |
| 405 | EmptyOptional(), |
| 406 | labelTypeGuid, |
| 407 | readableData, |
| 408 | offset); |
| 409 | |
| 410 | // Mark the buffer as read |
| 411 | mockBufferManager.MarkRead(readableBuffer); |
| 412 | } |
| 413 | |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 414 | BOOST_AUTO_TEST_CASE(SendWellKnownLabelsAndEventClassesTest) |
| 415 | { |
| 416 | MockBufferManager mockBufferManager(1024); |
| 417 | SendTimelinePacket sendTimelinePacket(mockBufferManager); |
| 418 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 419 | |
| 420 | BOOST_CHECK_NO_THROW(timelineUtilityMethods.SendWellKnownLabelsAndEventClasses()); |
| 421 | |
| 422 | // Commit all packets at once |
| 423 | sendTimelinePacket.Commit(); |
| 424 | |
| 425 | // Get the readable buffer |
| 426 | auto readableBuffer = mockBufferManager.GetReadableBuffer(); |
| 427 | BOOST_CHECK(readableBuffer != nullptr); |
| 428 | unsigned int size = readableBuffer->GetSize(); |
| 429 | BOOST_CHECK(size == 136); |
| 430 | const unsigned char* readableData = readableBuffer->GetReadableData(); |
| 431 | BOOST_CHECK(readableData != nullptr); |
| 432 | |
| 433 | // Utils |
| 434 | unsigned int offset = 0; |
| 435 | |
| 436 | // First "well-known" label: NAME |
| 437 | VerifyTimelineLabelBinaryPacket(LabelsAndEventClasses::NAME_GUID, |
| 438 | LabelsAndEventClasses::NAME_LABEL, |
| 439 | readableData, |
| 440 | offset); |
| 441 | |
| 442 | // Second "well-known" label: TYPE |
| 443 | VerifyTimelineLabelBinaryPacket(LabelsAndEventClasses::TYPE_GUID, |
| 444 | LabelsAndEventClasses::TYPE_LABEL, |
| 445 | readableData, |
| 446 | offset); |
| 447 | |
| 448 | // Third "well-known" label: INDEX |
| 449 | VerifyTimelineLabelBinaryPacket(LabelsAndEventClasses::INDEX_GUID, |
| 450 | LabelsAndEventClasses::INDEX_LABEL, |
| 451 | readableData, |
| 452 | offset); |
| 453 | |
| 454 | // First "well-known" event class: START OF LIFE |
| 455 | VerifyTimelineEventClassBinaryPacket(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS, |
| 456 | readableData, |
| 457 | offset); |
| 458 | |
Narumol Prangnawarat | 94a3088 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 459 | // Second "well-known" event class: END OF LIFE |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 460 | VerifyTimelineEventClassBinaryPacket(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS, |
| 461 | readableData, |
| 462 | offset); |
| 463 | |
| 464 | // Mark the buffer as read |
| 465 | mockBufferManager.MarkRead(readableBuffer); |
| 466 | } |
| 467 | |
Narumol Prangnawarat | 94a3088 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 468 | BOOST_AUTO_TEST_CASE(CreateNamedTypedChildEntityTest) |
| 469 | { |
| 470 | MockBufferManager mockBufferManager(1024); |
| 471 | SendTimelinePacket sendTimelinePacket(mockBufferManager); |
| 472 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 473 | |
| 474 | ProfilingGuid parentEntityGuid(123); |
| 475 | const std::string entityName = "some entity"; |
| 476 | const std::string entityType = "some type"; |
| 477 | |
| 478 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid, "", entityType), |
| 479 | InvalidArgumentException); |
| 480 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid, entityName, ""), |
| 481 | InvalidArgumentException); |
| 482 | |
| 483 | ProfilingGuid childEntityGuid(0); |
| 484 | BOOST_CHECK_NO_THROW(childEntityGuid = timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid, |
| 485 | entityName, |
| 486 | entityType)); |
| 487 | BOOST_CHECK(childEntityGuid != ProfilingGuid(0)); |
| 488 | |
| 489 | // Commit all packets at once |
| 490 | sendTimelinePacket.Commit(); |
| 491 | |
| 492 | // Get the readable buffer |
| 493 | auto readableBuffer = mockBufferManager.GetReadableBuffer(); |
| 494 | BOOST_CHECK(readableBuffer != nullptr); |
| 495 | unsigned int size = readableBuffer->GetSize(); |
| 496 | BOOST_CHECK(size == 292); |
| 497 | const unsigned char* readableData = readableBuffer->GetReadableData(); |
| 498 | BOOST_CHECK(readableData != nullptr); |
| 499 | |
| 500 | // Utils |
| 501 | unsigned int offset = 0; |
| 502 | |
| 503 | // First packet sent: TimelineEntityBinaryPacket |
| 504 | VerifyTimelineEntityBinaryPacket(EmptyOptional(), readableData, offset); |
| 505 | |
| 506 | // Second packet sent: TimelineLabelBinaryPacket |
| 507 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityName, readableData, offset); |
| 508 | |
| 509 | // Third packet sent: TimelineRelationshipBinaryPacket |
| 510 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 511 | EmptyOptional(), |
| 512 | EmptyOptional(), |
| 513 | EmptyOptional(), |
| 514 | readableData, |
| 515 | offset); |
| 516 | |
| 517 | // Fourth packet sent: TimelineRelationshipBinaryPacket |
| 518 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 519 | EmptyOptional(), |
| 520 | EmptyOptional(), |
| 521 | LabelsAndEventClasses::NAME_GUID, |
| 522 | readableData, |
| 523 | offset); |
| 524 | |
| 525 | // Fifth packet sent: TimelineLabelBinaryPacket |
| 526 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityType, readableData, offset); |
| 527 | |
| 528 | // Sixth packet sent: TimelineRelationshipBinaryPacket |
| 529 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 530 | EmptyOptional(), |
| 531 | EmptyOptional(), |
| 532 | EmptyOptional(), |
| 533 | readableData, |
| 534 | offset); |
| 535 | |
| 536 | // Seventh packet sent: TimelineRelationshipBinaryPacket |
| 537 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 538 | EmptyOptional(), |
| 539 | EmptyOptional(), |
| 540 | LabelsAndEventClasses::TYPE_GUID, |
| 541 | readableData, |
| 542 | offset); |
| 543 | |
| 544 | // Eighth packet sent: TimelineRelationshipBinaryPacket |
| 545 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink, |
| 546 | EmptyOptional(), |
| 547 | parentEntityGuid, |
| 548 | EmptyOptional(), |
| 549 | readableData, |
| 550 | offset); |
| 551 | |
| 552 | // Mark the buffer as read |
| 553 | mockBufferManager.MarkRead(readableBuffer); |
| 554 | } |
| 555 | |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 556 | BOOST_AUTO_TEST_CASE(DeclareLabelTest) |
Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +0100 | [diff] [blame] | 557 | { |
| 558 | MockBufferManager mockBufferManager(1024); |
| 559 | SendTimelinePacket sendTimelinePacket(mockBufferManager); |
| 560 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 561 | |
| 562 | // Try declaring an invalid (empty) label |
| 563 | BOOST_CHECK_THROW(timelineUtilityMethods.DeclareLabel(""), InvalidArgumentException); |
| 564 | |
| 565 | // Try declaring an invalid (wrong SWTrace format) label |
| 566 | BOOST_CHECK_THROW(timelineUtilityMethods.DeclareLabel("inv@lid lab€l"), RuntimeException); |
| 567 | |
| 568 | // Declare a valid label |
| 569 | const std::string labelName = "valid label"; |
| 570 | ProfilingGuid labelGuid = 0; |
| 571 | BOOST_CHECK_NO_THROW(labelGuid = timelineUtilityMethods.DeclareLabel(labelName)); |
| 572 | // TODO when the implementation of the profiling GUID generator is done, enable the following test |
| 573 | //BOOST_CHECK(labelGuid != ProfilingGuid(0)); |
| 574 | |
| 575 | // TODO when the implementation of the profiling GUID generator is done, enable the following tests |
| 576 | // Try adding the same label as before |
| 577 | //ProfilingGuid newLabelGuid = 0; |
| 578 | //BOOST_CHECK_NO_THROW(labelGuid = timelineUtilityMethods.DeclareLabel(labelName)); |
| 579 | //BOOST_CHECK(newLabelGuid != ProfilingGuid(0)); |
| 580 | //BOOST_CHECK(newLabelGuid == labelGuid); |
| 581 | } |
| 582 | |
Narumol Prangnawarat | d034e08 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 583 | BOOST_AUTO_TEST_CASE(CreateNameTypeEntityInvalidTest) |
| 584 | { |
| 585 | MockBufferManager mockBufferManager(1024); |
| 586 | SendTimelinePacket sendTimelinePacket(mockBufferManager); |
| 587 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 588 | |
| 589 | // Invalid name |
| 590 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity("", "Type"), InvalidArgumentException); |
| 591 | |
| 592 | // Invalid type |
| 593 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity("Name", ""), InvalidArgumentException); |
| 594 | |
| 595 | } |
| 596 | |
Matteo Martincigh | 5dc816e | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 597 | BOOST_AUTO_TEST_CASE(CreateNameTypeEntityTest) |
Narumol Prangnawarat | d034e08 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 598 | { |
| 599 | MockBufferManager mockBufferManager(1024); |
| 600 | SendTimelinePacket sendTimelinePacket(mockBufferManager); |
| 601 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 602 | |
| 603 | const std::string entityName = "Entity0"; |
| 604 | const std::string entityType = "Type0"; |
| 605 | |
Narumol Prangnawarat | d034e08 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 606 | ProfilingDynamicGuid guid = timelineUtilityMethods.CreateNamedTypedEntity(entityName, entityType); |
| 607 | BOOST_CHECK(guid != ProfilingGuid(0)); |
| 608 | |
| 609 | // Commit all packets at once |
| 610 | sendTimelinePacket.Commit(); |
| 611 | |
| 612 | // Get the readable buffer |
| 613 | auto readableBuffer = mockBufferManager.GetReadableBuffer(); |
| 614 | BOOST_CHECK(readableBuffer != nullptr); |
| 615 | unsigned int size = readableBuffer->GetSize(); |
| 616 | BOOST_CHECK(size == 244); |
| 617 | const unsigned char* readableData = readableBuffer->GetReadableData(); |
| 618 | BOOST_CHECK(readableData != nullptr); |
| 619 | |
| 620 | // Utils |
| 621 | unsigned int offset = 0; |
| 622 | |
| 623 | // First packet sent: TimelineEntityBinaryPacket |
Narumol Prangnawarat | 94a3088 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 624 | VerifyTimelineEntityBinaryPacket(guid, readableData, offset); |
Narumol Prangnawarat | d034e08 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 625 | |
| 626 | // Packets for Name Entity |
| 627 | // First packet sent: TimelineLabelBinaryPacket |
| 628 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityName, readableData, offset); |
| 629 | |
| 630 | // Second packet sent: TimelineRelationshipBinaryPacket |
| 631 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 632 | EmptyOptional(), |
| 633 | EmptyOptional(), |
| 634 | EmptyOptional(), |
| 635 | readableData, |
| 636 | offset); |
| 637 | |
| 638 | // Third packet sent: TimelineRelationshipBinaryPacket |
| 639 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 640 | EmptyOptional(), |
| 641 | EmptyOptional(), |
| 642 | LabelsAndEventClasses::NAME_GUID, |
| 643 | readableData, |
| 644 | offset); |
| 645 | |
| 646 | // Packets for Type Entity |
| 647 | // First packet sent: TimelineLabelBinaryPacket |
| 648 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityType, readableData, offset); |
| 649 | |
| 650 | // Second packet sent: TimelineRelationshipBinaryPacket |
| 651 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 652 | EmptyOptional(), |
| 653 | EmptyOptional(), |
| 654 | EmptyOptional(), |
| 655 | readableData, |
| 656 | offset); |
| 657 | |
| 658 | // Third packet sent: TimelineRelationshipBinaryPacket |
| 659 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 660 | EmptyOptional(), |
| 661 | EmptyOptional(), |
| 662 | LabelsAndEventClasses::TYPE_GUID, |
| 663 | readableData, |
| 664 | offset); |
| 665 | |
| 666 | // Mark the buffer as read |
| 667 | mockBufferManager.MarkRead(readableBuffer); |
| 668 | } |
| 669 | |
Matteo Martincigh | 5dc816e | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 670 | BOOST_AUTO_TEST_CASE(RecordEventTest) |
| 671 | { |
| 672 | MockBufferManager mockBufferManager(1024); |
| 673 | SendTimelinePacket sendTimelinePacket(mockBufferManager); |
| 674 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 675 | |
| 676 | ProfilingGuid entityGuid(123); |
| 677 | ProfilingStaticGuid eventClassGuid(456); |
| 678 | ProfilingDynamicGuid eventGuid(0); |
| 679 | BOOST_CHECK_NO_THROW(eventGuid = timelineUtilityMethods.RecordEvent(entityGuid, eventClassGuid)); |
| 680 | BOOST_CHECK(eventGuid != ProfilingGuid(0)); |
| 681 | |
| 682 | // Commit all packets at once |
| 683 | sendTimelinePacket.Commit(); |
| 684 | |
| 685 | // Get the readable buffer |
| 686 | auto readableBuffer = mockBufferManager.GetReadableBuffer(); |
| 687 | BOOST_CHECK(readableBuffer != nullptr); |
| 688 | unsigned int size = readableBuffer->GetSize(); |
| 689 | BOOST_CHECK(size == 116); |
| 690 | const unsigned char* readableData = readableBuffer->GetReadableData(); |
| 691 | BOOST_CHECK(readableData != nullptr); |
| 692 | |
| 693 | // Utils |
| 694 | unsigned int offset = 0; |
| 695 | |
| 696 | // First packet sent: TimelineEntityBinaryPacket |
| 697 | VerifyTimelineEventBinaryPacket(EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset); |
| 698 | |
| 699 | // Second packet sent: TimelineRelationshipBinaryPacket |
| 700 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::ExecutionLink, |
| 701 | EmptyOptional(), |
| 702 | entityGuid, |
| 703 | EmptyOptional(), |
| 704 | readableData, |
| 705 | offset); |
| 706 | |
| 707 | // Third packet sent: TimelineRelationshipBinaryPacket |
| 708 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::DataLink, |
| 709 | EmptyOptional(), |
| 710 | entityGuid, |
| 711 | eventClassGuid, |
| 712 | readableData, |
| 713 | offset); |
| 714 | |
| 715 | // Mark the buffer as read |
| 716 | mockBufferManager.MarkRead(readableBuffer); |
| 717 | } |
| 718 | |
Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +0100 | [diff] [blame] | 719 | BOOST_AUTO_TEST_SUITE_END() |