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" |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 7 | #include "ProfilingTestUtils.hpp" |
Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +0100 | [diff] [blame] | 8 | |
| 9 | #include <SendTimelinePacket.hpp> |
| 10 | #include <TimelineUtilityMethods.hpp> |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 11 | #include <LabelsAndEventClasses.hpp> |
Matteo Martincigh | c040199 | 2019-10-28 15:24:34 +0000 | [diff] [blame] | 12 | #include <ProfilingService.hpp> |
Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +0100 | [diff] [blame] | 13 | |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 14 | #include <memory> |
| 15 | |
Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +0100 | [diff] [blame] | 16 | #include <boost/test/unit_test.hpp> |
| 17 | |
| 18 | using namespace armnn; |
| 19 | using namespace armnn::profiling; |
| 20 | |
| 21 | BOOST_AUTO_TEST_SUITE(TimelineUtilityMethodsTests) |
| 22 | |
Matteo Martincigh | c040199 | 2019-10-28 15:24:34 +0000 | [diff] [blame] | 23 | BOOST_AUTO_TEST_CASE(CreateTypedLabelTest) |
| 24 | { |
| 25 | MockBufferManager mockBufferManager(1024); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 26 | std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager); |
Matteo Martincigh | c040199 | 2019-10-28 15:24:34 +0000 | [diff] [blame] | 27 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 28 | |
Narumol Prangnawarat | dbdd1b4 | 2019-11-15 17:38:44 +0000 | [diff] [blame] | 29 | // Generate first guid to ensure that the named typed entity guid is not 0 on local single test. |
| 30 | ProfilingService::Instance().NextGuid(); |
| 31 | |
Matteo Martincigh | c040199 | 2019-10-28 15:24:34 +0000 | [diff] [blame] | 32 | ProfilingGuid entityGuid(123); |
| 33 | const std::string entityName = "some entity"; |
| 34 | ProfilingStaticGuid labelTypeGuid(456); |
| 35 | |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 36 | BOOST_CHECK_NO_THROW(timelineUtilityMethods.MarkEntityWithLabel(entityGuid, entityName, labelTypeGuid)); |
Matteo Martincigh | c040199 | 2019-10-28 15:24:34 +0000 | [diff] [blame] | 37 | |
| 38 | // Commit all packets at once |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 39 | timelineUtilityMethods.Commit(); |
Matteo Martincigh | c040199 | 2019-10-28 15:24:34 +0000 | [diff] [blame] | 40 | |
| 41 | // Get the readable buffer |
| 42 | auto readableBuffer = mockBufferManager.GetReadableBuffer(); |
| 43 | BOOST_CHECK(readableBuffer != nullptr); |
| 44 | unsigned int size = readableBuffer->GetSize(); |
| 45 | BOOST_CHECK(size == 116); |
| 46 | const unsigned char* readableData = readableBuffer->GetReadableData(); |
| 47 | BOOST_CHECK(readableData != nullptr); |
| 48 | |
| 49 | // Utils |
| 50 | unsigned int offset = 0; |
| 51 | |
| 52 | // First packet sent: TimelineLabelBinaryPacket |
| 53 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityName, readableData, offset); |
| 54 | |
| 55 | // Second packet sent: TimelineRelationshipBinaryPacket |
| 56 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 57 | EmptyOptional(), |
| 58 | entityGuid, |
| 59 | EmptyOptional(), |
| 60 | readableData, |
| 61 | offset); |
| 62 | |
| 63 | // Third packet sent: TimelineRelationshipBinaryPacket |
| 64 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 65 | EmptyOptional(), |
| 66 | EmptyOptional(), |
| 67 | labelTypeGuid, |
| 68 | readableData, |
| 69 | offset); |
| 70 | |
| 71 | // Mark the buffer as read |
| 72 | mockBufferManager.MarkRead(readableBuffer); |
| 73 | } |
| 74 | |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 75 | BOOST_AUTO_TEST_CASE(SendWellKnownLabelsAndEventClassesTest) |
| 76 | { |
| 77 | MockBufferManager mockBufferManager(1024); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 78 | std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager); |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 79 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 80 | |
| 81 | BOOST_CHECK_NO_THROW(timelineUtilityMethods.SendWellKnownLabelsAndEventClasses()); |
| 82 | |
| 83 | // Commit all packets at once |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 84 | timelineUtilityMethods.Commit(); |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 85 | |
| 86 | // Get the readable buffer |
| 87 | auto readableBuffer = mockBufferManager.GetReadableBuffer(); |
| 88 | BOOST_CHECK(readableBuffer != nullptr); |
| 89 | unsigned int size = readableBuffer->GetSize(); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 90 | BOOST_TEST(size == 388); |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 91 | const unsigned char* readableData = readableBuffer->GetReadableData(); |
| 92 | BOOST_CHECK(readableData != nullptr); |
| 93 | |
| 94 | // Utils |
| 95 | unsigned int offset = 0; |
| 96 | |
| 97 | // First "well-known" label: NAME |
| 98 | VerifyTimelineLabelBinaryPacket(LabelsAndEventClasses::NAME_GUID, |
| 99 | LabelsAndEventClasses::NAME_LABEL, |
| 100 | readableData, |
| 101 | offset); |
| 102 | |
| 103 | // Second "well-known" label: TYPE |
| 104 | VerifyTimelineLabelBinaryPacket(LabelsAndEventClasses::TYPE_GUID, |
| 105 | LabelsAndEventClasses::TYPE_LABEL, |
| 106 | readableData, |
| 107 | offset); |
| 108 | |
| 109 | // Third "well-known" label: INDEX |
| 110 | VerifyTimelineLabelBinaryPacket(LabelsAndEventClasses::INDEX_GUID, |
| 111 | LabelsAndEventClasses::INDEX_LABEL, |
| 112 | readableData, |
| 113 | offset); |
| 114 | |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 115 | // Forth "well-known" label: BACKENDID |
| 116 | VerifyTimelineLabelBinaryPacket(LabelsAndEventClasses::BACKENDID_GUID, |
| 117 | LabelsAndEventClasses::BACKENDID_LABEL, |
| 118 | readableData, |
| 119 | offset); |
| 120 | |
| 121 | // Well-known types |
| 122 | // Layer |
| 123 | VerifyTimelineLabelBinaryPacket(LabelsAndEventClasses::LAYER_GUID, |
| 124 | LabelsAndEventClasses::LAYER, |
| 125 | readableData, |
| 126 | offset); |
| 127 | |
| 128 | // Workload |
| 129 | VerifyTimelineLabelBinaryPacket(LabelsAndEventClasses::WORKLOAD_GUID, |
| 130 | LabelsAndEventClasses::WORKLOAD, |
| 131 | readableData, |
| 132 | offset); |
| 133 | |
| 134 | // Network |
| 135 | VerifyTimelineLabelBinaryPacket(LabelsAndEventClasses::NETWORK_GUID, |
| 136 | LabelsAndEventClasses::NETWORK, |
| 137 | readableData, |
| 138 | offset); |
| 139 | |
| 140 | // Connection |
| 141 | VerifyTimelineLabelBinaryPacket(LabelsAndEventClasses::CONNECTION_GUID, |
| 142 | LabelsAndEventClasses::CONNECTION, |
| 143 | readableData, |
| 144 | offset); |
David Monahan | 6198fe0 | 2019-12-02 08:35:43 +0000 | [diff] [blame] | 145 | // Inference |
| 146 | VerifyTimelineLabelBinaryPacket(LabelsAndEventClasses::INFERENCE_GUID, |
| 147 | LabelsAndEventClasses::INFERENCE, |
| 148 | readableData, |
| 149 | offset); |
| 150 | // Workload Execution |
| 151 | VerifyTimelineLabelBinaryPacket(LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID, |
| 152 | LabelsAndEventClasses::WORKLOAD_EXECUTION, |
| 153 | readableData, |
| 154 | offset); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 155 | |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 156 | // First "well-known" event class: START OF LIFE |
| 157 | VerifyTimelineEventClassBinaryPacket(LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS, |
| 158 | readableData, |
| 159 | offset); |
| 160 | |
Narumol Prangnawarat | 94a3088 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 161 | // Second "well-known" event class: END OF LIFE |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 162 | VerifyTimelineEventClassBinaryPacket(LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS, |
| 163 | readableData, |
| 164 | offset); |
| 165 | |
| 166 | // Mark the buffer as read |
| 167 | mockBufferManager.MarkRead(readableBuffer); |
| 168 | } |
| 169 | |
Narumol Prangnawarat | 94a3088 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 170 | BOOST_AUTO_TEST_CASE(CreateNamedTypedChildEntityTest) |
| 171 | { |
| 172 | MockBufferManager mockBufferManager(1024); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 173 | std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager); |
Narumol Prangnawarat | 94a3088 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 174 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 175 | |
Narumol Prangnawarat | 234d525 | 2019-11-19 15:49:18 +0000 | [diff] [blame] | 176 | ProfilingDynamicGuid childEntityGuid(0); |
Narumol Prangnawarat | 94a3088 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 177 | ProfilingGuid parentEntityGuid(123); |
| 178 | const std::string entityName = "some entity"; |
| 179 | const std::string entityType = "some type"; |
| 180 | |
Narumol Prangnawarat | dbdd1b4 | 2019-11-15 17:38:44 +0000 | [diff] [blame] | 181 | // Generate first guid to ensure that the named typed entity guid is not 0 on local single test. |
| 182 | ProfilingService::Instance().NextGuid(); |
| 183 | |
Narumol Prangnawarat | 94a3088 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 184 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid, "", entityType), |
| 185 | InvalidArgumentException); |
| 186 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid, entityName, ""), |
| 187 | InvalidArgumentException); |
Narumol Prangnawarat | 234d525 | 2019-11-19 15:49:18 +0000 | [diff] [blame] | 188 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity( |
| 189 | childEntityGuid, parentEntityGuid, "", entityType), InvalidArgumentException); |
| 190 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedChildEntity( |
| 191 | childEntityGuid, parentEntityGuid, entityName, ""), InvalidArgumentException); |
Narumol Prangnawarat | 94a3088 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 192 | |
Narumol Prangnawarat | 94a3088 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 193 | BOOST_CHECK_NO_THROW(childEntityGuid = timelineUtilityMethods.CreateNamedTypedChildEntity(parentEntityGuid, |
| 194 | entityName, |
| 195 | entityType)); |
| 196 | BOOST_CHECK(childEntityGuid != ProfilingGuid(0)); |
| 197 | |
| 198 | // Commit all packets at once |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 199 | timelineUtilityMethods.Commit(); |
Narumol Prangnawarat | 94a3088 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 200 | |
| 201 | // Get the readable buffer |
| 202 | auto readableBuffer = mockBufferManager.GetReadableBuffer(); |
| 203 | BOOST_CHECK(readableBuffer != nullptr); |
| 204 | unsigned int size = readableBuffer->GetSize(); |
| 205 | BOOST_CHECK(size == 292); |
| 206 | const unsigned char* readableData = readableBuffer->GetReadableData(); |
| 207 | BOOST_CHECK(readableData != nullptr); |
| 208 | |
| 209 | // Utils |
| 210 | unsigned int offset = 0; |
| 211 | |
| 212 | // First packet sent: TimelineEntityBinaryPacket |
| 213 | VerifyTimelineEntityBinaryPacket(EmptyOptional(), readableData, offset); |
| 214 | |
| 215 | // Second packet sent: TimelineLabelBinaryPacket |
| 216 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityName, readableData, offset); |
| 217 | |
| 218 | // Third packet sent: TimelineRelationshipBinaryPacket |
| 219 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 220 | EmptyOptional(), |
| 221 | EmptyOptional(), |
| 222 | EmptyOptional(), |
| 223 | readableData, |
| 224 | offset); |
| 225 | |
| 226 | // Fourth packet sent: TimelineRelationshipBinaryPacket |
| 227 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 228 | EmptyOptional(), |
| 229 | EmptyOptional(), |
| 230 | LabelsAndEventClasses::NAME_GUID, |
| 231 | readableData, |
| 232 | offset); |
| 233 | |
| 234 | // Fifth packet sent: TimelineLabelBinaryPacket |
| 235 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityType, readableData, offset); |
| 236 | |
| 237 | // Sixth packet sent: TimelineRelationshipBinaryPacket |
| 238 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 239 | EmptyOptional(), |
| 240 | EmptyOptional(), |
| 241 | EmptyOptional(), |
| 242 | readableData, |
| 243 | offset); |
| 244 | |
| 245 | // Seventh packet sent: TimelineRelationshipBinaryPacket |
| 246 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 247 | EmptyOptional(), |
| 248 | EmptyOptional(), |
| 249 | LabelsAndEventClasses::TYPE_GUID, |
| 250 | readableData, |
| 251 | offset); |
| 252 | |
| 253 | // Eighth packet sent: TimelineRelationshipBinaryPacket |
| 254 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::RetentionLink, |
| 255 | EmptyOptional(), |
| 256 | parentEntityGuid, |
| 257 | EmptyOptional(), |
| 258 | readableData, |
| 259 | offset); |
| 260 | |
| 261 | // Mark the buffer as read |
| 262 | mockBufferManager.MarkRead(readableBuffer); |
| 263 | } |
| 264 | |
Matteo Martincigh | 102cdbd | 2019-10-28 11:42:50 +0000 | [diff] [blame] | 265 | BOOST_AUTO_TEST_CASE(DeclareLabelTest) |
Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +0100 | [diff] [blame] | 266 | { |
| 267 | MockBufferManager mockBufferManager(1024); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 268 | std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager); |
Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +0100 | [diff] [blame] | 269 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 270 | |
Narumol Prangnawarat | dbdd1b4 | 2019-11-15 17:38:44 +0000 | [diff] [blame] | 271 | // Generate first guid to ensure that the named typed entity guid is not 0 on local single test. |
| 272 | ProfilingService::Instance().NextGuid(); |
| 273 | |
Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +0100 | [diff] [blame] | 274 | // Try declaring an invalid (empty) label |
| 275 | BOOST_CHECK_THROW(timelineUtilityMethods.DeclareLabel(""), InvalidArgumentException); |
| 276 | |
| 277 | // Try declaring an invalid (wrong SWTrace format) label |
| 278 | BOOST_CHECK_THROW(timelineUtilityMethods.DeclareLabel("inv@lid lab€l"), RuntimeException); |
| 279 | |
| 280 | // Declare a valid label |
| 281 | const std::string labelName = "valid label"; |
| 282 | ProfilingGuid labelGuid = 0; |
| 283 | BOOST_CHECK_NO_THROW(labelGuid = timelineUtilityMethods.DeclareLabel(labelName)); |
Narumol Prangnawarat | dbdd1b4 | 2019-11-15 17:38:44 +0000 | [diff] [blame] | 284 | BOOST_CHECK(labelGuid != ProfilingGuid(0)); |
Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +0100 | [diff] [blame] | 285 | |
Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +0100 | [diff] [blame] | 286 | // Try adding the same label as before |
Narumol Prangnawarat | dbdd1b4 | 2019-11-15 17:38:44 +0000 | [diff] [blame] | 287 | ProfilingGuid newLabelGuid = 0; |
| 288 | BOOST_CHECK_NO_THROW(newLabelGuid = timelineUtilityMethods.DeclareLabel(labelName)); |
| 289 | BOOST_CHECK(newLabelGuid != ProfilingGuid(0)); |
| 290 | BOOST_CHECK(newLabelGuid == labelGuid); |
Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +0100 | [diff] [blame] | 291 | } |
| 292 | |
Narumol Prangnawarat | d034e08 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 293 | BOOST_AUTO_TEST_CASE(CreateNameTypeEntityInvalidTest) |
| 294 | { |
| 295 | MockBufferManager mockBufferManager(1024); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 296 | std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager); |
Narumol Prangnawarat | d034e08 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 297 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 298 | |
| 299 | // Invalid name |
| 300 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity("", "Type"), InvalidArgumentException); |
| 301 | |
| 302 | // Invalid type |
| 303 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity("Name", ""), InvalidArgumentException); |
| 304 | |
Narumol Prangnawarat | 234d525 | 2019-11-19 15:49:18 +0000 | [diff] [blame] | 305 | ProfilingDynamicGuid guid = ProfilingService::Instance().NextGuid(); |
| 306 | |
| 307 | // CreatedNamedTypedEntity with Guid - Invalid name |
| 308 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity(guid, "", "Type"), |
| 309 | InvalidArgumentException); |
| 310 | |
| 311 | // CreatedNamedTypedEntity with Guid - Invalid type |
| 312 | BOOST_CHECK_THROW(timelineUtilityMethods.CreateNamedTypedEntity(guid, "Name", ""), |
| 313 | InvalidArgumentException); |
| 314 | |
Narumol Prangnawarat | d034e08 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 315 | } |
| 316 | |
Matteo Martincigh | 5dc816e | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 317 | BOOST_AUTO_TEST_CASE(CreateNameTypeEntityTest) |
Narumol Prangnawarat | d034e08 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 318 | { |
| 319 | MockBufferManager mockBufferManager(1024); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 320 | std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager); |
Narumol Prangnawarat | d034e08 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 321 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
| 322 | |
| 323 | const std::string entityName = "Entity0"; |
| 324 | const std::string entityType = "Type0"; |
| 325 | |
Narumol Prangnawarat | dbdd1b4 | 2019-11-15 17:38:44 +0000 | [diff] [blame] | 326 | // Generate first guid to ensure that the named typed entity guid is not 0 on local single test. |
| 327 | ProfilingService::Instance().NextGuid(); |
| 328 | |
Narumol Prangnawarat | d034e08 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 329 | ProfilingDynamicGuid guid = timelineUtilityMethods.CreateNamedTypedEntity(entityName, entityType); |
| 330 | BOOST_CHECK(guid != ProfilingGuid(0)); |
| 331 | |
| 332 | // Commit all packets at once |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 333 | timelineUtilityMethods.Commit(); |
Narumol Prangnawarat | d034e08 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 334 | |
| 335 | // Get the readable buffer |
| 336 | auto readableBuffer = mockBufferManager.GetReadableBuffer(); |
| 337 | BOOST_CHECK(readableBuffer != nullptr); |
| 338 | unsigned int size = readableBuffer->GetSize(); |
| 339 | BOOST_CHECK(size == 244); |
| 340 | const unsigned char* readableData = readableBuffer->GetReadableData(); |
| 341 | BOOST_CHECK(readableData != nullptr); |
| 342 | |
| 343 | // Utils |
| 344 | unsigned int offset = 0; |
| 345 | |
| 346 | // First packet sent: TimelineEntityBinaryPacket |
Narumol Prangnawarat | 94a3088 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 347 | VerifyTimelineEntityBinaryPacket(guid, readableData, offset); |
Narumol Prangnawarat | d034e08 | 2019-10-30 12:48:31 +0000 | [diff] [blame] | 348 | |
| 349 | // Packets for Name Entity |
| 350 | // First packet sent: TimelineLabelBinaryPacket |
| 351 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityName, readableData, offset); |
| 352 | |
| 353 | // Second packet sent: TimelineRelationshipBinaryPacket |
| 354 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 355 | EmptyOptional(), |
| 356 | EmptyOptional(), |
| 357 | EmptyOptional(), |
| 358 | readableData, |
| 359 | offset); |
| 360 | |
| 361 | // Third packet sent: TimelineRelationshipBinaryPacket |
| 362 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 363 | EmptyOptional(), |
| 364 | EmptyOptional(), |
| 365 | LabelsAndEventClasses::NAME_GUID, |
| 366 | readableData, |
| 367 | offset); |
| 368 | |
| 369 | // Packets for Type Entity |
| 370 | // First packet sent: TimelineLabelBinaryPacket |
| 371 | VerifyTimelineLabelBinaryPacket(EmptyOptional(), entityType, readableData, offset); |
| 372 | |
| 373 | // Second packet sent: TimelineRelationshipBinaryPacket |
| 374 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 375 | EmptyOptional(), |
| 376 | EmptyOptional(), |
| 377 | EmptyOptional(), |
| 378 | readableData, |
| 379 | offset); |
| 380 | |
| 381 | // Third packet sent: TimelineRelationshipBinaryPacket |
| 382 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::LabelLink, |
| 383 | EmptyOptional(), |
| 384 | EmptyOptional(), |
| 385 | LabelsAndEventClasses::TYPE_GUID, |
| 386 | readableData, |
| 387 | offset); |
| 388 | |
| 389 | // Mark the buffer as read |
| 390 | mockBufferManager.MarkRead(readableBuffer); |
| 391 | } |
| 392 | |
Matteo Martincigh | 5dc816e | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 393 | BOOST_AUTO_TEST_CASE(RecordEventTest) |
| 394 | { |
| 395 | MockBufferManager mockBufferManager(1024); |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 396 | std::unique_ptr<ISendTimelinePacket> sendTimelinePacket = std::make_unique<SendTimelinePacket>(mockBufferManager); |
Matteo Martincigh | 5dc816e | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 397 | TimelineUtilityMethods timelineUtilityMethods(sendTimelinePacket); |
Narumol Prangnawarat | dbdd1b4 | 2019-11-15 17:38:44 +0000 | [diff] [blame] | 398 | // Generate first guid to ensure that the named typed entity guid is not 0 on local single test. |
| 399 | ProfilingService::Instance().NextGuid(); |
| 400 | |
Matteo Martincigh | 5dc816e | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 401 | ProfilingGuid entityGuid(123); |
| 402 | ProfilingStaticGuid eventClassGuid(456); |
| 403 | ProfilingDynamicGuid eventGuid(0); |
| 404 | BOOST_CHECK_NO_THROW(eventGuid = timelineUtilityMethods.RecordEvent(entityGuid, eventClassGuid)); |
| 405 | BOOST_CHECK(eventGuid != ProfilingGuid(0)); |
| 406 | |
| 407 | // Commit all packets at once |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 408 | timelineUtilityMethods.Commit(); |
Matteo Martincigh | 5dc816e | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 409 | |
| 410 | // Get the readable buffer |
| 411 | auto readableBuffer = mockBufferManager.GetReadableBuffer(); |
| 412 | BOOST_CHECK(readableBuffer != nullptr); |
| 413 | unsigned int size = readableBuffer->GetSize(); |
| 414 | BOOST_CHECK(size == 116); |
| 415 | const unsigned char* readableData = readableBuffer->GetReadableData(); |
| 416 | BOOST_CHECK(readableData != nullptr); |
| 417 | |
| 418 | // Utils |
| 419 | unsigned int offset = 0; |
| 420 | |
| 421 | // First packet sent: TimelineEntityBinaryPacket |
| 422 | VerifyTimelineEventBinaryPacket(EmptyOptional(), EmptyOptional(), EmptyOptional(), readableData, offset); |
| 423 | |
| 424 | // Second packet sent: TimelineRelationshipBinaryPacket |
| 425 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::ExecutionLink, |
| 426 | EmptyOptional(), |
| 427 | entityGuid, |
| 428 | EmptyOptional(), |
| 429 | readableData, |
| 430 | offset); |
| 431 | |
| 432 | // Third packet sent: TimelineRelationshipBinaryPacket |
| 433 | VerifyTimelineRelationshipBinaryPacket(ProfilingRelationshipType::DataLink, |
| 434 | EmptyOptional(), |
Narumol Prangnawarat | df31cfe | 2019-11-22 11:26:06 +0000 | [diff] [blame] | 435 | eventGuid, |
Matteo Martincigh | 5dc816e | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 436 | eventClassGuid, |
| 437 | readableData, |
| 438 | offset); |
| 439 | |
| 440 | // Mark the buffer as read |
| 441 | mockBufferManager.MarkRead(readableBuffer); |
| 442 | } |
| 443 | |
Matteo Martincigh | 830101c | 2019-10-22 11:07:45 +0100 | [diff] [blame] | 444 | BOOST_AUTO_TEST_SUITE_END() |