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); |
| 261 | BOOST_CHECK(entityBinaryPacketDataLength == 8); |
| 262 | |
| 263 | // Check the decl_id |
| 264 | offset += uint32_t_size; |
| 265 | uint32_t entitytDecId = ReadUint32(readableData, offset); |
| 266 | |
| 267 | BOOST_CHECK(entitytDecId == uint32_t(1)); |
| 268 | |
| 269 | // Check the profiling GUID |
| 270 | offset += uint32_t_size; |
| 271 | uint64_t readProfilingGuid = ReadUint64(readableData, offset); |
| 272 | |
| 273 | if (guid.has_value()) |
| 274 | { |
| 275 | BOOST_CHECK(readProfilingGuid == guid.value()); |
| 276 | } |
| 277 | else |
| 278 | { |
| 279 | BOOST_CHECK(readProfilingGuid != ProfilingGuid(0)); |
| 280 | } |
| 281 | |
| 282 | offset += uint64_t_size; |
| 283 | } |
| 284 | |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 285 | } // Anonymous namespace |
| 286 | |
Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +0100 | [diff] [blame] | 287 | BOOST_AUTO_TEST_SUITE(TimelineUtilityMethodsTests) |
| 288 | |
Matteo Martincigh | c040199 | 2019-10-28 15:24:34 +0000 | [diff] [blame] | 289 | BOOST_AUTO_TEST_CASE(CreateTypedLabelTest) |
| 290 | { |
| 291 | MockBufferManager mockBufferManager(1024); |
| 292 | SendTimelinePacket sendTimelinePacket(mockBufferManager); |
| 293 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 294 | |
| 295 | ProfilingGuid entityGuid(123); |
| 296 | const std::string entityName = "some entity"; |
| 297 | ProfilingStaticGuid labelTypeGuid(456); |
| 298 | |
| 299 | BOOST_CHECK_NO_THROW(timelineUtilityMethods.CreateTypedLabel(entityGuid, entityName, labelTypeGuid)); |
| 300 | |
| 301 | // Commit all packets at once |
| 302 | sendTimelinePacket.Commit(); |
| 303 | |
| 304 | // Get the readable buffer |
| 305 | auto readableBuffer = mockBufferManager.GetReadableBuffer(); |
| 306 | BOOST_CHECK(readableBuffer != nullptr); |
| 307 | unsigned int size = readableBuffer->GetSize(); |
| 308 | BOOST_CHECK(size == 116); |
| 309 | const unsigned char* readableData = readableBuffer->GetReadableData(); |
| 310 | BOOST_CHECK(readableData != nullptr); |
| 311 | |
| 312 | // Utils |
| 313 | unsigned int offset = 0; |
| 314 | |
| 315 | // First packet sent: TimelineLabelBinaryPacket |
| 316 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityName, readableData, offset); |
| 317 | |
| 318 | // Second packet sent: TimelineRelationshipBinaryPacket |
| 319 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 320 | EmptyOptional(), |
| 321 | entityGuid, |
| 322 | EmptyOptional(), |
| 323 | readableData, |
| 324 | offset); |
| 325 | |
| 326 | // Third packet sent: TimelineRelationshipBinaryPacket |
| 327 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 328 | EmptyOptional(), |
| 329 | EmptyOptional(), |
| 330 | labelTypeGuid, |
| 331 | readableData, |
| 332 | offset); |
| 333 | |
| 334 | // Mark the buffer as read |
| 335 | mockBufferManager.MarkRead(readableBuffer); |
| 336 | } |
| 337 | |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 338 | BOOST_AUTO_TEST_CASE(SendWellKnownLabelsAndEventClassesTest) |
| 339 | { |
| 340 | MockBufferManager mockBufferManager(1024); |
| 341 | SendTimelinePacket sendTimelinePacket(mockBufferManager); |
| 342 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 343 | |
| 344 | BOOST_CHECK_NO_THROW(timelineUtilityMethods.SendWellKnownLabelsAndEventClasses()); |
| 345 | |
| 346 | // Commit all packets at once |
| 347 | sendTimelinePacket.Commit(); |
| 348 | |
| 349 | // Get the readable buffer |
| 350 | auto readableBuffer = mockBufferManager.GetReadableBuffer(); |
| 351 | BOOST_CHECK(readableBuffer != nullptr); |
| 352 | unsigned int size = readableBuffer->GetSize(); |
| 353 | BOOST_CHECK(size == 136); |
| 354 | const unsigned char* readableData = readableBuffer->GetReadableData(); |
| 355 | BOOST_CHECK(readableData != nullptr); |
| 356 | |
| 357 | // Utils |
| 358 | unsigned int offset = 0; |
| 359 | |
| 360 | // First "well-known" label: NAME |
| 361 | VerifyTimelineLabelBinaryPacket(LabelsAndEventClasses::NAME_GUID, |
| 362 | LabelsAndEventClasses::NAME_LABEL, |
| 363 | readableData, |
| 364 | offset); |
| 365 | |
| 366 | // Second "well-known" label: TYPE |
| 367 | VerifyTimelineLabelBinaryPacket(LabelsAndEventClasses::TYPE_GUID, |
| 368 | LabelsAndEventClasses::TYPE_LABEL, |
| 369 | readableData, |
| 370 | offset); |
| 371 | |
| 372 | // Third "well-known" label: INDEX |
| 373 | VerifyTimelineLabelBinaryPacket(LabelsAndEventClasses::INDEX_GUID, |
| 374 | LabelsAndEventClasses::INDEX_LABEL, |
| 375 | readableData, |
| 376 | offset); |
| 377 | |
| 378 | // First "well-known" event class: START OF LIFE |
| 379 | VerifyTimelineEventClassBinaryPacket(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS, |
| 380 | readableData, |
| 381 | offset); |
| 382 | |
Narumol Prangnawarat | 94a3088 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 383 | // Second "well-known" event class: END OF LIFE |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 384 | VerifyTimelineEventClassBinaryPacket(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS, |
| 385 | readableData, |
| 386 | offset); |
| 387 | |
| 388 | // Mark the buffer as read |
| 389 | mockBufferManager.MarkRead(readableBuffer); |
| 390 | } |
| 391 | |
Narumol Prangnawarat | 94a3088 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 392 | BOOST_AUTO_TEST_CASE(CreateNamedTypedChildEntityTest) |
| 393 | { |
| 394 | MockBufferManager mockBufferManager(1024); |
| 395 | SendTimelinePacket sendTimelinePacket(mockBufferManager); |
| 396 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 397 | |
| 398 | ProfilingGuid parentEntityGuid(123); |
| 399 | const std::string entityName = "some entity"; |
| 400 | const std::string entityType = "some type"; |
| 401 | |
| 402 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid, "", entityType), |
| 403 | InvalidArgumentException); |
| 404 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid, entityName, ""), |
| 405 | InvalidArgumentException); |
| 406 | |
| 407 | ProfilingGuid childEntityGuid(0); |
| 408 | BOOST_CHECK_NO_THROW(childEntityGuid = timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid, |
| 409 | entityName, |
| 410 | entityType)); |
| 411 | BOOST_CHECK(childEntityGuid != ProfilingGuid(0)); |
| 412 | |
| 413 | // Commit all packets at once |
| 414 | sendTimelinePacket.Commit(); |
| 415 | |
| 416 | // Get the readable buffer |
| 417 | auto readableBuffer = mockBufferManager.GetReadableBuffer(); |
| 418 | BOOST_CHECK(readableBuffer != nullptr); |
| 419 | unsigned int size = readableBuffer->GetSize(); |
| 420 | BOOST_CHECK(size == 292); |
| 421 | const unsigned char* readableData = readableBuffer->GetReadableData(); |
| 422 | BOOST_CHECK(readableData != nullptr); |
| 423 | |
| 424 | // Utils |
| 425 | unsigned int offset = 0; |
| 426 | |
| 427 | // First packet sent: TimelineEntityBinaryPacket |
| 428 | VerifyTimelineEntityBinaryPacket(EmptyOptional(), readableData, offset); |
| 429 | |
| 430 | // Second packet sent: TimelineLabelBinaryPacket |
| 431 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityName, readableData, offset); |
| 432 | |
| 433 | // Third packet sent: TimelineRelationshipBinaryPacket |
| 434 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 435 | EmptyOptional(), |
| 436 | EmptyOptional(), |
| 437 | EmptyOptional(), |
| 438 | readableData, |
| 439 | offset); |
| 440 | |
| 441 | // Fourth packet sent: TimelineRelationshipBinaryPacket |
| 442 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 443 | EmptyOptional(), |
| 444 | EmptyOptional(), |
| 445 | LabelsAndEventClasses::NAME_GUID, |
| 446 | readableData, |
| 447 | offset); |
| 448 | |
| 449 | // Fifth packet sent: TimelineLabelBinaryPacket |
| 450 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityType, readableData, offset); |
| 451 | |
| 452 | // Sixth packet sent: TimelineRelationshipBinaryPacket |
| 453 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 454 | EmptyOptional(), |
| 455 | EmptyOptional(), |
| 456 | EmptyOptional(), |
| 457 | readableData, |
| 458 | offset); |
| 459 | |
| 460 | // Seventh packet sent: TimelineRelationshipBinaryPacket |
| 461 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 462 | EmptyOptional(), |
| 463 | EmptyOptional(), |
| 464 | LabelsAndEventClasses::TYPE_GUID, |
| 465 | readableData, |
| 466 | offset); |
| 467 | |
| 468 | // Eighth packet sent: TimelineRelationshipBinaryPacket |
| 469 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink, |
| 470 | EmptyOptional(), |
| 471 | parentEntityGuid, |
| 472 | EmptyOptional(), |
| 473 | readableData, |
| 474 | offset); |
| 475 | |
| 476 | // Mark the buffer as read |
| 477 | mockBufferManager.MarkRead(readableBuffer); |
| 478 | } |
| 479 | |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 480 | BOOST_AUTO_TEST_CASE(DeclareLabelTest) |
Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +0100 | [diff] [blame] | 481 | { |
| 482 | MockBufferManager mockBufferManager(1024); |
| 483 | SendTimelinePacket sendTimelinePacket(mockBufferManager); |
| 484 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 485 | |
| 486 | // Try declaring an invalid (empty) label |
| 487 | BOOST_CHECK_THROW(timelineUtilityMethods.DeclareLabel(""), InvalidArgumentException); |
| 488 | |
| 489 | // Try declaring an invalid (wrong SWTrace format) label |
| 490 | BOOST_CHECK_THROW(timelineUtilityMethods.DeclareLabel("inv@lid lab€l"), RuntimeException); |
| 491 | |
| 492 | // Declare a valid label |
| 493 | const std::string labelName = "valid label"; |
| 494 | ProfilingGuid labelGuid = 0; |
| 495 | BOOST_CHECK_NO_THROW(labelGuid = timelineUtilityMethods.DeclareLabel(labelName)); |
| 496 | // TODO when the implementation of the profiling GUID generator is done, enable the following test |
| 497 | //BOOST_CHECK(labelGuid != ProfilingGuid(0)); |
| 498 | |
| 499 | // TODO when the implementation of the profiling GUID generator is done, enable the following tests |
| 500 | // Try adding the same label as before |
| 501 | //ProfilingGuid newLabelGuid = 0; |
| 502 | //BOOST_CHECK_NO_THROW(labelGuid = timelineUtilityMethods.DeclareLabel(labelName)); |
| 503 | //BOOST_CHECK(newLabelGuid != ProfilingGuid(0)); |
| 504 | //BOOST_CHECK(newLabelGuid == labelGuid); |
| 505 | } |
| 506 | |
Narumol Prangnawarat | d034e08 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 507 | BOOST_AUTO_TEST_CASE(CreateNameTypeEntityInvalidTest) |
| 508 | { |
| 509 | MockBufferManager mockBufferManager(1024); |
| 510 | SendTimelinePacket sendTimelinePacket(mockBufferManager); |
| 511 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 512 | |
| 513 | // Invalid name |
| 514 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity("", "Type"), InvalidArgumentException); |
| 515 | |
| 516 | // Invalid type |
| 517 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity("Name", ""), InvalidArgumentException); |
| 518 | |
| 519 | } |
| 520 | |
| 521 | BOOST_AUTO_TEST_CASE(CreateNameTypeEntitylTest) |
| 522 | { |
| 523 | MockBufferManager mockBufferManager(1024); |
| 524 | SendTimelinePacket sendTimelinePacket(mockBufferManager); |
| 525 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 526 | |
| 527 | const std::string entityName = "Entity0"; |
| 528 | const std::string entityType = "Type0"; |
| 529 | |
Narumol Prangnawarat | d034e08 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 530 | ProfilingDynamicGuid guid = timelineUtilityMethods.CreateNamedTypedEntity(entityName, entityType); |
| 531 | BOOST_CHECK(guid != ProfilingGuid(0)); |
| 532 | |
| 533 | // Commit all packets at once |
| 534 | sendTimelinePacket.Commit(); |
| 535 | |
| 536 | // Get the readable buffer |
| 537 | auto readableBuffer = mockBufferManager.GetReadableBuffer(); |
| 538 | BOOST_CHECK(readableBuffer != nullptr); |
| 539 | unsigned int size = readableBuffer->GetSize(); |
| 540 | BOOST_CHECK(size == 244); |
| 541 | const unsigned char* readableData = readableBuffer->GetReadableData(); |
| 542 | BOOST_CHECK(readableData != nullptr); |
| 543 | |
| 544 | // Utils |
| 545 | unsigned int offset = 0; |
| 546 | |
| 547 | // First packet sent: TimelineEntityBinaryPacket |
Narumol Prangnawarat | 94a3088 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 548 | VerifyTimelineEntityBinaryPacket(guid, readableData, offset); |
Narumol Prangnawarat | d034e08 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 549 | |
| 550 | // Packets for Name Entity |
| 551 | // First packet sent: TimelineLabelBinaryPacket |
| 552 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityName, readableData, offset); |
| 553 | |
| 554 | // Second packet sent: TimelineRelationshipBinaryPacket |
| 555 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 556 | EmptyOptional(), |
| 557 | EmptyOptional(), |
| 558 | EmptyOptional(), |
| 559 | readableData, |
| 560 | offset); |
| 561 | |
| 562 | // Third packet sent: TimelineRelationshipBinaryPacket |
| 563 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 564 | EmptyOptional(), |
| 565 | EmptyOptional(), |
| 566 | LabelsAndEventClasses::NAME_GUID, |
| 567 | readableData, |
| 568 | offset); |
| 569 | |
| 570 | // Packets for Type Entity |
| 571 | // First packet sent: TimelineLabelBinaryPacket |
| 572 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityType, readableData, offset); |
| 573 | |
| 574 | // Second packet sent: TimelineRelationshipBinaryPacket |
| 575 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 576 | EmptyOptional(), |
| 577 | EmptyOptional(), |
| 578 | EmptyOptional(), |
| 579 | readableData, |
| 580 | offset); |
| 581 | |
| 582 | // Third packet sent: TimelineRelationshipBinaryPacket |
| 583 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 584 | EmptyOptional(), |
| 585 | EmptyOptional(), |
| 586 | LabelsAndEventClasses::TYPE_GUID, |
| 587 | readableData, |
| 588 | offset); |
| 589 | |
| 590 | // Mark the buffer as read |
| 591 | mockBufferManager.MarkRead(readableBuffer); |
| 592 | } |
| 593 | |
Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +0100 | [diff] [blame] | 594 | BOOST_AUTO_TEST_SUITE_END() |