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