Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 1 | // |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 2 | // Copyright © 2019 Arm Ltd and Contributors. All rights reserved. |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Jim Flynn | 1fdeb99 | 2020-07-09 07:28:37 +0100 | [diff] [blame^] | 6 | #include <Threads.hpp> |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 7 | #include <ProfilingUtils.hpp> |
| 8 | |
| 9 | #include <boost/test/unit_test.hpp> |
| 10 | #include <boost/numeric/conversion/cast.hpp> |
| 11 | |
| 12 | using namespace armnn::profiling; |
| 13 | |
| 14 | BOOST_AUTO_TEST_SUITE(TimelinePacketTests) |
| 15 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 16 | BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestNoBuffer) |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 17 | { |
| 18 | const uint64_t profilingGuid = 123456u; |
| 19 | const std::string label = "some label"; |
| 20 | unsigned int numberOfBytesWritten = 789u; |
| 21 | TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid, |
| 22 | label, |
| 23 | nullptr, |
| 24 | 512u, |
| 25 | numberOfBytesWritten); |
| 26 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 27 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 28 | } |
| 29 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 30 | BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestBufferExhaustionZeroValue) |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 31 | { |
| 32 | std::vector<unsigned char> buffer(512, 0); |
| 33 | |
| 34 | const uint64_t profilingGuid = 123456u; |
| 35 | const std::string label = "some label"; |
| 36 | unsigned int numberOfBytesWritten = 789u; |
| 37 | TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid, |
| 38 | label, |
| 39 | buffer.data(), |
| 40 | 0, |
| 41 | numberOfBytesWritten); |
| 42 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 43 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 44 | } |
| 45 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 46 | BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestBufferExhaustionFixedValue) |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 47 | { |
| 48 | std::vector<unsigned char> buffer(10, 0); |
| 49 | |
| 50 | const uint64_t profilingGuid = 123456u; |
| 51 | const std::string label = "some label"; |
| 52 | unsigned int numberOfBytesWritten = 789u; |
| 53 | TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid, |
| 54 | label, |
| 55 | buffer.data(), |
| 56 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 57 | numberOfBytesWritten); |
| 58 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 59 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 60 | } |
| 61 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 62 | BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestInvalidLabel) |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 63 | { |
| 64 | std::vector<unsigned char> buffer(512, 0); |
| 65 | |
| 66 | const uint64_t profilingGuid = 123456u; |
| 67 | const std::string label = "s0m€ l@b€l"; |
| 68 | unsigned int numberOfBytesWritten = 789u; |
| 69 | TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid, |
| 70 | label, |
| 71 | buffer.data(), |
| 72 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 73 | numberOfBytesWritten); |
| 74 | BOOST_CHECK(result == TimelinePacketStatus::Error); |
| 75 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 76 | } |
| 77 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 78 | BOOST_AUTO_TEST_CASE(TimelineLabelPacketTestSingleConstructionOfData) |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 79 | { |
| 80 | std::vector<unsigned char> buffer(512, 0); |
| 81 | |
| 82 | const uint64_t profilingGuid = 123456u; |
| 83 | const std::string label = "some label"; |
| 84 | unsigned int numberOfBytesWritten = 789u; |
| 85 | TimelinePacketStatus result = WriteTimelineLabelBinaryPacket(profilingGuid, |
| 86 | label, |
| 87 | buffer.data(), |
| 88 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 89 | numberOfBytesWritten); |
| 90 | BOOST_CHECK(result == TimelinePacketStatus::Ok); |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 91 | BOOST_CHECK(numberOfBytesWritten == 28); |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 92 | |
| 93 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 94 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 95 | |
| 96 | // Check the packet header |
| 97 | unsigned int offset = 0; |
Jan Eilers | b884ea4 | 2019-10-16 09:54:15 +0100 | [diff] [blame] | 98 | uint32_t decl_Id = ReadUint32(buffer.data(), offset); |
| 99 | BOOST_CHECK(decl_Id == uint32_t(0)); |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 100 | |
| 101 | // Check the profiling GUID |
| 102 | offset += uint32_t_size; |
| 103 | uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset); |
| 104 | BOOST_CHECK(readProfilingGuid == profilingGuid); |
| 105 | |
| 106 | // Check the SWTrace label |
| 107 | offset += uint64_t_size; |
| 108 | uint32_t swTraceLabelLength = ReadUint32(buffer.data(), offset); |
| 109 | BOOST_CHECK(swTraceLabelLength == 11); // Label length including the null-terminator |
| 110 | |
| 111 | offset += uint32_t_size; |
| 112 | BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer |
| 113 | label.data(), // The original label |
| 114 | swTraceLabelLength - 1) == 0); // The length of the label |
| 115 | |
| 116 | offset += swTraceLabelLength * uint32_t_size; |
| 117 | BOOST_CHECK(buffer[offset] == '\0'); // The null-terminator at the end of the SWTrace label |
| 118 | } |
| 119 | |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 120 | BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketNullBufferTest) |
| 121 | { |
| 122 | ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink; |
| 123 | const uint64_t relationshipGuid = 123456u; |
| 124 | const uint64_t headGuid = 234567u; |
| 125 | const uint64_t tailGuid = 345678u; |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 126 | const uint64_t attributeGuid = 876345u; |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 127 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 128 | TimelinePacketStatus result = WriteTimelineRelationshipBinary(relationshipType, |
| 129 | relationshipGuid, |
| 130 | headGuid, |
| 131 | tailGuid, |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 132 | attributeGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 133 | nullptr, |
| 134 | 512u, |
| 135 | numberOfBytesWritten); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 136 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 137 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 138 | } |
| 139 | |
| 140 | BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketZeroBufferSizeTest) |
| 141 | { |
| 142 | std::vector<unsigned char> buffer(512, 0); |
| 143 | |
| 144 | ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink; |
| 145 | const uint64_t relationshipGuid = 123456u; |
| 146 | const uint64_t headGuid = 234567u; |
| 147 | const uint64_t tailGuid = 345678u; |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 148 | const uint64_t attributeGuid = 876345u; |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 149 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 150 | TimelinePacketStatus result = WriteTimelineRelationshipBinary(relationshipType, |
| 151 | relationshipGuid, |
| 152 | headGuid, |
| 153 | tailGuid, |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 154 | attributeGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 155 | buffer.data(), |
| 156 | 0, |
| 157 | numberOfBytesWritten); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 158 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 159 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 160 | } |
| 161 | |
| 162 | BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketSmallBufferSizeTest) |
| 163 | { |
| 164 | std::vector<unsigned char> buffer(10, 0); |
| 165 | |
| 166 | ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink; |
| 167 | const uint64_t relationshipGuid = 123456u; |
| 168 | const uint64_t headGuid = 234567u; |
| 169 | const uint64_t tailGuid = 345678u; |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 170 | const uint64_t attributeGuid = 876345u; |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 171 | unsigned int numberOfBytesWritten = 789u; |
| 172 | TimelinePacketStatus result = |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 173 | WriteTimelineRelationshipBinary(relationshipType, |
| 174 | relationshipGuid, |
| 175 | headGuid, |
| 176 | tailGuid, |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 177 | attributeGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 178 | buffer.data(), |
| 179 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 180 | numberOfBytesWritten); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 181 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 182 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 183 | } |
| 184 | |
| 185 | BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketInvalidRelationTest) |
| 186 | { |
| 187 | std::vector<unsigned char> buffer(512, 0); |
| 188 | ProfilingRelationshipType relationshipType = static_cast<ProfilingRelationshipType>(5); |
| 189 | const uint64_t relationshipGuid = 123456u; |
| 190 | const uint64_t headGuid = 234567u; |
| 191 | const uint64_t tailGuid = 345678u; |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 192 | const uint64_t attributeGuid = 876345u; |
| 193 | |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 194 | unsigned int numberOfBytesWritten = 789u; |
| 195 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 196 | BOOST_CHECK_THROW(WriteTimelineRelationshipBinary(relationshipType, |
| 197 | relationshipGuid, |
| 198 | headGuid, |
| 199 | tailGuid, |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 200 | attributeGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 201 | buffer.data(), |
| 202 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 203 | numberOfBytesWritten), |
| 204 | armnn::InvalidArgumentException); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 205 | |
| 206 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 207 | } |
| 208 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 209 | BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketTestDataConstruction) |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 210 | { |
| 211 | std::vector<unsigned char> buffer(512, 0); |
| 212 | |
| 213 | ProfilingRelationshipType relationshipType = ProfilingRelationshipType::RetentionLink; |
| 214 | const uint64_t relationshipGuid = 123456u; |
| 215 | const uint64_t headGuid = 234567u; |
| 216 | const uint64_t tailGuid = 345678u; |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 217 | const uint64_t attributeGuid = 876345u; |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 218 | unsigned int numberOfBytesWritten = 789u; |
| 219 | TimelinePacketStatus result = |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 220 | WriteTimelineRelationshipBinary(relationshipType, |
| 221 | relationshipGuid, |
| 222 | headGuid, |
| 223 | tailGuid, |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 224 | attributeGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 225 | buffer.data(), |
| 226 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 227 | numberOfBytesWritten); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 228 | BOOST_CHECK(result == TimelinePacketStatus::Ok); |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 229 | BOOST_CHECK(numberOfBytesWritten == 40); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 230 | |
| 231 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 232 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 233 | |
| 234 | // Check the packet header |
| 235 | unsigned int offset = 0; |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 236 | // Check the decl_id |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 237 | uint32_t readDeclId = ReadUint32(buffer.data(), offset); |
| 238 | BOOST_CHECK(readDeclId == 3); |
| 239 | |
| 240 | // Check the relationship type |
| 241 | offset += uint32_t_size; |
| 242 | uint32_t readRelationshipType = ReadUint32(buffer.data(), offset); |
| 243 | BOOST_CHECK(readRelationshipType == 0); |
| 244 | |
| 245 | // Check the relationship GUID |
| 246 | offset += uint32_t_size; |
| 247 | uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset); |
| 248 | BOOST_CHECK(readRelationshipGuid == relationshipGuid); |
| 249 | |
| 250 | // Check the head GUID |
| 251 | offset += uint64_t_size; |
| 252 | uint64_t readHeadGuid = ReadUint64(buffer.data(), offset); |
| 253 | BOOST_CHECK(readHeadGuid == headGuid); |
| 254 | |
| 255 | // Check the tail GUID |
| 256 | offset += uint64_t_size; |
| 257 | uint64_t readTailGuid = ReadUint64(buffer.data(), offset); |
| 258 | BOOST_CHECK(readTailGuid == tailGuid); |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 259 | |
| 260 | // Check the attribute GUID |
| 261 | offset += uint64_t_size; |
| 262 | uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset); |
| 263 | BOOST_CHECK(readAttributeGuid == attributeGuid); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 264 | } |
| 265 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 266 | BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketExecutionLinkTestDataConstruction) |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 267 | { |
| 268 | std::vector<unsigned char> buffer(512, 0); |
| 269 | |
| 270 | ProfilingRelationshipType relationshipType = ProfilingRelationshipType::ExecutionLink; |
| 271 | const uint64_t relationshipGuid = 123456u; |
| 272 | const uint64_t headGuid = 234567u; |
| 273 | const uint64_t tailGuid = 345678u; |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 274 | const uint64_t attributeGuid = 876345u; |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 275 | unsigned int numberOfBytesWritten = 789u; |
| 276 | TimelinePacketStatus result = |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 277 | WriteTimelineRelationshipBinary(relationshipType, |
| 278 | relationshipGuid, |
| 279 | headGuid, |
| 280 | tailGuid, |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 281 | attributeGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 282 | buffer.data(), |
| 283 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 284 | numberOfBytesWritten); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 285 | BOOST_CHECK(result == TimelinePacketStatus::Ok); |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 286 | BOOST_CHECK(numberOfBytesWritten == 40); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 287 | |
| 288 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 289 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 290 | |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 291 | unsigned int offset = 0; |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 292 | uint32_t readDeclId = ReadUint32(buffer.data(), offset); |
| 293 | BOOST_CHECK(readDeclId == 3); |
| 294 | |
| 295 | // Check the relationship type |
| 296 | offset += uint32_t_size; |
| 297 | uint32_t readRelationshipType = ReadUint32(buffer.data(), offset); |
| 298 | BOOST_CHECK(readRelationshipType == 1); |
| 299 | |
| 300 | // Check the relationship GUID |
| 301 | offset += uint32_t_size; |
| 302 | uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset); |
| 303 | BOOST_CHECK(readRelationshipGuid == relationshipGuid); |
| 304 | |
| 305 | // Check the head GUID |
| 306 | offset += uint64_t_size; |
| 307 | uint64_t readHeadGuid = ReadUint64(buffer.data(), offset); |
| 308 | BOOST_CHECK(readHeadGuid == headGuid); |
| 309 | |
| 310 | // Check the tail GUID |
| 311 | offset += uint64_t_size; |
| 312 | uint64_t readTailGuid = ReadUint64(buffer.data(), offset); |
| 313 | BOOST_CHECK(readTailGuid == tailGuid); |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 314 | |
| 315 | // Check the attribute GUID |
| 316 | offset += uint64_t_size; |
| 317 | uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset); |
| 318 | BOOST_CHECK(readAttributeGuid == attributeGuid); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 322 | BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketDataLinkTestDataConstruction) |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 323 | { |
| 324 | std::vector<unsigned char> buffer(512, 0); |
| 325 | |
| 326 | ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink; |
| 327 | const uint64_t relationshipGuid = 123456u; |
| 328 | const uint64_t headGuid = 234567u; |
| 329 | const uint64_t tailGuid = 345678u; |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 330 | const uint64_t attributeGuid = 876345u; |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 331 | unsigned int numberOfBytesWritten = 789u; |
| 332 | TimelinePacketStatus result = |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 333 | WriteTimelineRelationshipBinary(relationshipType, |
| 334 | relationshipGuid, |
| 335 | headGuid, |
| 336 | tailGuid, |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 337 | attributeGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 338 | buffer.data(), |
| 339 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 340 | numberOfBytesWritten); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 341 | BOOST_CHECK(result == TimelinePacketStatus::Ok); |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 342 | BOOST_CHECK(numberOfBytesWritten == 40); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 343 | |
| 344 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 345 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 346 | |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 347 | unsigned int offset = 0; |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 348 | uint32_t readDeclId = ReadUint32(buffer.data(), offset); |
| 349 | BOOST_CHECK(readDeclId == 3); |
| 350 | |
| 351 | // Check the relationship type |
| 352 | offset += uint32_t_size; |
| 353 | uint32_t readRelationshipType = ReadUint32(buffer.data(), offset); |
| 354 | BOOST_CHECK(readRelationshipType == 2); |
| 355 | |
| 356 | // Check the relationship GUID |
| 357 | offset += uint32_t_size; |
| 358 | uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset); |
| 359 | BOOST_CHECK(readRelationshipGuid == relationshipGuid); |
| 360 | |
| 361 | // Check the head GUID |
| 362 | offset += uint64_t_size; |
| 363 | uint64_t readHeadGuid = ReadUint64(buffer.data(), offset); |
| 364 | BOOST_CHECK(readHeadGuid == headGuid); |
| 365 | |
| 366 | // Check the tail GUID |
| 367 | offset += uint64_t_size; |
| 368 | uint64_t readTailGuid = ReadUint64(buffer.data(), offset); |
| 369 | BOOST_CHECK(readTailGuid == tailGuid); |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 370 | |
| 371 | // Check the attribute GUID |
| 372 | offset += uint64_t_size; |
| 373 | uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset); |
| 374 | BOOST_CHECK(readAttributeGuid == attributeGuid); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 378 | BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketLabelLinkTestDataConstruction) |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 379 | { |
| 380 | std::vector<unsigned char> buffer(512, 0); |
| 381 | |
| 382 | ProfilingRelationshipType relationshipType = ProfilingRelationshipType::LabelLink; |
| 383 | const uint64_t relationshipGuid = 123456u; |
| 384 | const uint64_t headGuid = 234567u; |
| 385 | const uint64_t tailGuid = 345678u; |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 386 | const uint64_t attributeGuid = 876345u; |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 387 | unsigned int numberOfBytesWritten = 789u; |
| 388 | TimelinePacketStatus result = |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 389 | WriteTimelineRelationshipBinary(relationshipType, |
| 390 | relationshipGuid, |
| 391 | headGuid, |
| 392 | tailGuid, |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 393 | attributeGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 394 | buffer.data(), |
| 395 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 396 | numberOfBytesWritten); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 397 | BOOST_CHECK(result == TimelinePacketStatus::Ok); |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 398 | BOOST_CHECK(numberOfBytesWritten == 40); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 399 | |
| 400 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 401 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 402 | |
| 403 | // Check the packet header |
| 404 | unsigned int offset = 0; |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 405 | uint32_t readDeclId = ReadUint32(buffer.data(), offset); |
| 406 | BOOST_CHECK(readDeclId == 3); |
| 407 | |
| 408 | // Check the relationship type |
| 409 | offset += uint32_t_size; |
| 410 | uint32_t readRelationshipType = ReadUint32(buffer.data(), offset); |
| 411 | BOOST_CHECK(readRelationshipType == 3); |
| 412 | |
| 413 | // Check the relationship GUID |
| 414 | offset += uint32_t_size; |
| 415 | uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset); |
| 416 | BOOST_CHECK(readRelationshipGuid == relationshipGuid); |
| 417 | |
| 418 | // Check the head GUID |
| 419 | offset += uint64_t_size; |
| 420 | uint64_t readHeadGuid = ReadUint64(buffer.data(), offset); |
| 421 | BOOST_CHECK(readHeadGuid == headGuid); |
| 422 | |
| 423 | // Check the tail GUID |
| 424 | offset += uint64_t_size; |
| 425 | uint64_t readTailGuid = ReadUint64(buffer.data(), offset); |
| 426 | BOOST_CHECK(readTailGuid == tailGuid); |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 427 | |
| 428 | // Check the attribute GUID |
| 429 | offset += uint64_t_size; |
| 430 | uint64_t readAttributeGuid = ReadUint64(buffer.data(), offset); |
| 431 | BOOST_CHECK(readAttributeGuid == attributeGuid); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 432 | } |
| 433 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 434 | BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTestNoBuffer) |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 435 | { |
| 436 | unsigned int numberOfBytesWritten = 789u; |
| 437 | TimelinePacketStatus result = WriteTimelineMessageDirectoryPackage(nullptr, |
| 438 | 512u, |
| 439 | numberOfBytesWritten); |
| 440 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 441 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 442 | } |
| 443 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 444 | BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTestBufferExhausted) |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 445 | { |
| 446 | std::vector<unsigned char> buffer(512, 0); |
| 447 | |
| 448 | unsigned int numberOfBytesWritten = 789u; |
| 449 | TimelinePacketStatus result = WriteTimelineMessageDirectoryPackage(buffer.data(), |
| 450 | 0, |
| 451 | numberOfBytesWritten); |
| 452 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 453 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 454 | } |
| 455 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 456 | BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTestFullConstruction) |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 457 | { |
| 458 | std::vector<unsigned char> buffer(512, 0); |
| 459 | unsigned int numberOfBytesWritten = 789u; |
| 460 | TimelinePacketStatus result = WriteTimelineMessageDirectoryPackage(buffer.data(), |
| 461 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 462 | numberOfBytesWritten); |
| 463 | BOOST_CHECK(result == TimelinePacketStatus::Ok); |
| 464 | |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 465 | BOOST_CHECK(numberOfBytesWritten == 451); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 466 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 467 | unsigned int uint8_t_size = sizeof(uint8_t); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 468 | unsigned int uint32_t_size = sizeof(uint32_t); |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 469 | unsigned int uint64_t_size = sizeof(uint64_t); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 470 | |
| 471 | // Check the packet header |
| 472 | unsigned int offset = 0; |
| 473 | uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset); |
| 474 | uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F; |
| 475 | uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F; |
| 476 | uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007; |
| 477 | uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007; |
| 478 | BOOST_CHECK(packetFamily == 1); |
| 479 | BOOST_CHECK(packetClass == 0); |
| 480 | BOOST_CHECK(packetType == 0); |
| 481 | BOOST_CHECK(streamId == 0); |
| 482 | |
| 483 | offset += uint32_t_size; |
| 484 | uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset); |
| 485 | uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001; |
| 486 | uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF; |
| 487 | BOOST_CHECK(sequenceNumbered == 0); |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 488 | BOOST_CHECK(dataLength == 443); |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 489 | |
| 490 | // Check the stream header |
| 491 | offset += uint32_t_size; |
| 492 | uint8_t readStreamVersion = ReadUint8(buffer.data(), offset); |
| 493 | BOOST_CHECK(readStreamVersion == 4); |
| 494 | offset += uint8_t_size; |
| 495 | uint8_t readPointerBytes = ReadUint8(buffer.data(), offset); |
| 496 | BOOST_CHECK(readPointerBytes == uint64_t_size); |
| 497 | offset += uint8_t_size; |
| 498 | uint8_t readThreadIdBytes = ReadUint8(buffer.data(), offset); |
Colm Donelan | 5bb3d8a | 2020-05-12 16:36:46 +0100 | [diff] [blame] | 499 | BOOST_CHECK(readThreadIdBytes == ThreadIdSize); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 500 | |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 501 | // Check the number of declarations |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 502 | offset += uint8_t_size; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 503 | uint32_t declCount = ReadUint32(buffer.data(), offset); |
| 504 | BOOST_CHECK(declCount == 5); |
| 505 | |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 506 | // Check the decl_id |
| 507 | offset += uint32_t_size; |
| 508 | uint32_t readDeclId = ReadUint32(buffer.data(), offset); |
| 509 | BOOST_CHECK(readDeclId == 0); |
| 510 | |
| 511 | // SWTrace "namestring" format |
| 512 | // length of the string (first 4 bytes) + string + null terminator |
| 513 | |
| 514 | // Check the decl_name |
| 515 | offset += uint32_t_size; |
| 516 | uint32_t swTraceDeclNameLength = ReadUint32(buffer.data(), offset); |
| 517 | BOOST_CHECK(swTraceDeclNameLength == 13); // decl_name length including the null-terminator |
| 518 | |
| 519 | std::string label = "declareLabel"; |
| 520 | offset += uint32_t_size; |
| 521 | BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 522 | label.data(), // The original label |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 523 | swTraceDeclNameLength - 1) == 0); // The length of the label |
| 524 | |
| 525 | // Check the ui_name |
| 526 | std::vector<uint32_t> swTraceString; |
| 527 | StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString); |
| 528 | offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size; |
| 529 | uint32_t swTraceUINameLength = ReadUint32(buffer.data(), offset); |
| 530 | BOOST_CHECK(swTraceUINameLength == 14); // ui_name length including the null-terminator |
| 531 | |
| 532 | label = "declare label"; |
| 533 | offset += uint32_t_size; |
| 534 | BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer |
| 535 | label.data(), // The original label |
| 536 | swTraceUINameLength - 1) == 0); // The length of the label |
| 537 | |
| 538 | // Check arg_types |
| 539 | StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString); |
| 540 | offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size; |
| 541 | uint32_t swTraceArgTypesLength = ReadUint32(buffer.data(), offset); |
| 542 | BOOST_CHECK(swTraceArgTypesLength == 3); // arg_types length including the null-terminator |
| 543 | |
| 544 | label = "ps"; |
| 545 | offset += uint32_t_size; |
| 546 | BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer |
| 547 | label.data(), // The original label |
| 548 | swTraceArgTypesLength - 1) == 0); // The length of the label |
| 549 | |
| 550 | // Check arg_names |
| 551 | StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString); |
| 552 | offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size; |
| 553 | uint32_t swTraceArgNamesLength = ReadUint32(buffer.data(), offset); |
| 554 | BOOST_CHECK(swTraceArgNamesLength == 11); // arg_names length including the null-terminator |
| 555 | |
| 556 | label = "guid,value"; |
| 557 | offset += uint32_t_size; |
| 558 | BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer |
| 559 | label.data(), // The original label |
| 560 | swTraceArgNamesLength - 1) == 0); // The length of the label |
| 561 | |
| 562 | // Check second message decl_id |
| 563 | StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString); |
| 564 | offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size; |
| 565 | readDeclId = ReadUint32(buffer.data(), offset); |
| 566 | BOOST_CHECK(readDeclId == 1); |
| 567 | |
| 568 | // Check second decl_name |
| 569 | offset += uint32_t_size; |
| 570 | swTraceDeclNameLength = ReadUint32(buffer.data(), offset); |
| 571 | BOOST_CHECK(swTraceDeclNameLength == 14); // decl_name length including the null-terminator |
| 572 | |
| 573 | label = "declareEntity"; |
| 574 | offset += uint32_t_size; |
| 575 | BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer |
| 576 | label.data(), // The original label |
| 577 | swTraceDeclNameLength - 1) == 0); // The length of the label |
| 578 | } |
| 579 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 580 | BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestNoBuffer) |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 581 | { |
| 582 | const uint64_t profilingGuid = 123456u; |
| 583 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 584 | TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid, |
| 585 | nullptr, |
| 586 | 512u, |
| 587 | numberOfBytesWritten); |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 588 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 589 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 590 | } |
| 591 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 592 | BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestBufferExhaustedWithZeroBufferSize) |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 593 | { |
| 594 | std::vector<unsigned char> buffer(512, 0); |
| 595 | |
| 596 | const uint64_t profilingGuid = 123456u; |
| 597 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 598 | TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid, |
| 599 | buffer.data(), |
| 600 | 0, |
| 601 | numberOfBytesWritten); |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 602 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 603 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 604 | } |
| 605 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 606 | BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestBufferExhaustedWithFixedBufferSize) |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 607 | { |
| 608 | std::vector<unsigned char> buffer(10, 0); |
| 609 | |
| 610 | const uint64_t profilingGuid = 123456u; |
| 611 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 612 | TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid, |
| 613 | buffer.data(), |
| 614 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 615 | numberOfBytesWritten); |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 616 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 617 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 618 | } |
| 619 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 620 | BOOST_AUTO_TEST_CASE(TimelineEntityPacketTestFullConstructionOfData) |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 621 | { |
| 622 | std::vector<unsigned char> buffer(512, 0); |
| 623 | |
| 624 | const uint64_t profilingGuid = 123456u; |
| 625 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 626 | TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid, |
| 627 | buffer.data(), |
| 628 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 629 | numberOfBytesWritten); |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 630 | BOOST_CHECK(result == TimelinePacketStatus::Ok); |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 631 | BOOST_CHECK(numberOfBytesWritten == 12); |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 632 | |
| 633 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 634 | |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 635 | unsigned int offset = 0; |
Jan Eilers | b884ea4 | 2019-10-16 09:54:15 +0100 | [diff] [blame] | 636 | // Check decl_Id |
Jan Eilers | b884ea4 | 2019-10-16 09:54:15 +0100 | [diff] [blame] | 637 | uint32_t decl_Id = ReadUint32(buffer.data(), offset); |
| 638 | BOOST_CHECK(decl_Id == uint32_t(1)); |
| 639 | |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 640 | // Check the profiling GUID |
| 641 | offset += uint32_t_size; |
| 642 | uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset); |
| 643 | BOOST_CHECK(readProfilingGuid == profilingGuid); |
| 644 | } |
| 645 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 646 | BOOST_AUTO_TEST_CASE(TimelineEventClassTestNoBuffer) |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 647 | { |
| 648 | const uint64_t profilingGuid = 123456u; |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 649 | const uint64_t profilingNameGuid = 3345u; |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 650 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 651 | TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid, |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 652 | profilingNameGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 653 | nullptr, |
| 654 | 512u, |
| 655 | numberOfBytesWritten); |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 656 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 657 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 658 | } |
| 659 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 660 | BOOST_AUTO_TEST_CASE(TimelineEventClassTestBufferExhaustionZeroValue) |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 661 | { |
| 662 | std::vector<unsigned char> buffer(512, 0); |
| 663 | |
| 664 | const uint64_t profilingGuid = 123456u; |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 665 | const uint64_t profilingNameGuid = 3345u; |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 666 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 667 | TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid, |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 668 | profilingNameGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 669 | buffer.data(), |
| 670 | 0, |
| 671 | numberOfBytesWritten); |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 672 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 673 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 674 | } |
| 675 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 676 | BOOST_AUTO_TEST_CASE(TimelineEventClassTestBufferExhaustionFixedValue) |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 677 | { |
| 678 | std::vector<unsigned char> buffer(10, 0); |
| 679 | |
| 680 | const uint64_t profilingGuid = 123456u; |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 681 | const uint64_t profilingNameGuid = 5564u; |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 682 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 683 | TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid, |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 684 | profilingNameGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 685 | buffer.data(), |
| 686 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 687 | numberOfBytesWritten); |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 688 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 689 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 690 | } |
| 691 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 692 | BOOST_AUTO_TEST_CASE(TimelineEventClassTestFullConstructionOfData) |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 693 | { |
| 694 | std::vector<unsigned char> buffer(512, 0); |
| 695 | |
| 696 | const uint64_t profilingGuid = 123456u; |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 697 | const uint64_t profilingNameGuid = 654321u; |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 698 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 699 | TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid, |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 700 | profilingNameGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 701 | buffer.data(), |
| 702 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 703 | numberOfBytesWritten); |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 704 | BOOST_CHECK(result == TimelinePacketStatus::Ok); |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 705 | BOOST_CHECK(numberOfBytesWritten == 20); |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 706 | |
| 707 | unsigned int uint32_t_size = sizeof(uint32_t); |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 708 | unsigned int uint64_t_size = sizeof(uint64_t); |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 709 | |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 710 | unsigned int offset = 0; |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 711 | // Check the decl_id |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 712 | uint32_t declId = ReadUint32(buffer.data(), offset); |
| 713 | BOOST_CHECK(declId == uint32_t(2)); |
| 714 | |
| 715 | // Check the profiling GUID |
| 716 | offset += uint32_t_size; |
| 717 | uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset); |
| 718 | BOOST_CHECK(readProfilingGuid == profilingGuid); |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 719 | |
| 720 | offset += uint64_t_size; |
| 721 | uint64_t readProfilingNameGuid = ReadUint64(buffer.data(), offset); |
| 722 | BOOST_CHECK(readProfilingNameGuid == profilingNameGuid); |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 723 | } |
| 724 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 725 | BOOST_AUTO_TEST_CASE(TimelineEventPacketTestNoBuffer) |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 726 | { |
| 727 | const uint64_t timestamp = 456789u; |
Jim Flynn | 1fdeb99 | 2020-07-09 07:28:37 +0100 | [diff] [blame^] | 728 | const int threadId = armnnUtils::Threads::GetCurrentThreadId(); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 729 | const uint64_t profilingGuid = 123456u; |
| 730 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 731 | TimelinePacketStatus result = WriteTimelineEventBinary(timestamp, |
| 732 | threadId, |
| 733 | profilingGuid, |
| 734 | nullptr, |
| 735 | 512u, |
| 736 | numberOfBytesWritten); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 737 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 738 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 739 | } |
| 740 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 741 | BOOST_AUTO_TEST_CASE(TimelineEventPacketTestBufferExhaustionZeroValue) |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 742 | { |
| 743 | std::vector<unsigned char> buffer(512, 0); |
| 744 | |
| 745 | const uint64_t timestamp = 456789u; |
Jim Flynn | 1fdeb99 | 2020-07-09 07:28:37 +0100 | [diff] [blame^] | 746 | const int threadId = armnnUtils::Threads::GetCurrentThreadId(); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 747 | const uint64_t profilingGuid = 123456u; |
| 748 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 749 | TimelinePacketStatus result = WriteTimelineEventBinary(timestamp, |
| 750 | threadId, |
| 751 | profilingGuid, |
| 752 | buffer.data(), |
| 753 | 0, |
| 754 | numberOfBytesWritten); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 755 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 756 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 757 | } |
| 758 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 759 | BOOST_AUTO_TEST_CASE(TimelineEventPacketTestBufferExhaustionFixedValue) |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 760 | { |
| 761 | std::vector<unsigned char> buffer(10, 0); |
| 762 | |
| 763 | const uint64_t timestamp = 456789u; |
Jim Flynn | 1fdeb99 | 2020-07-09 07:28:37 +0100 | [diff] [blame^] | 764 | const int threadId = armnnUtils::Threads::GetCurrentThreadId(); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 765 | const uint64_t profilingGuid = 123456u; |
| 766 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 767 | TimelinePacketStatus result = WriteTimelineEventBinary(timestamp, |
| 768 | threadId, |
| 769 | profilingGuid, |
| 770 | buffer.data(), |
| 771 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 772 | numberOfBytesWritten); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 773 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 774 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 775 | } |
| 776 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 777 | BOOST_AUTO_TEST_CASE(TimelineEventPacketTestFullConstructionOfData) |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 778 | { |
| 779 | std::vector<unsigned char> buffer(512, 0); |
| 780 | |
| 781 | const uint64_t timestamp = 456789u; |
Jim Flynn | 1fdeb99 | 2020-07-09 07:28:37 +0100 | [diff] [blame^] | 782 | const int threadId = armnnUtils::Threads::GetCurrentThreadId(); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 783 | const uint64_t profilingGuid = 123456u; |
| 784 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 785 | TimelinePacketStatus result = WriteTimelineEventBinary(timestamp, |
| 786 | threadId, |
| 787 | profilingGuid, |
| 788 | buffer.data(), |
| 789 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 790 | numberOfBytesWritten); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 791 | BOOST_CHECK(result == TimelinePacketStatus::Ok); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 792 | |
| 793 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 794 | unsigned int uint64_t_size = sizeof(uint64_t); |
Colm Donelan | 5bb3d8a | 2020-05-12 16:36:46 +0100 | [diff] [blame] | 795 | BOOST_CHECK(numberOfBytesWritten == 20 + ThreadIdSize); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 796 | |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 797 | unsigned int offset = 0; |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 798 | // Check the decl_id |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 799 | uint32_t readDeclId = ReadUint32(buffer.data(), offset); |
| 800 | BOOST_CHECK(readDeclId == 4); |
| 801 | |
| 802 | // Check the timestamp |
| 803 | offset += uint32_t_size; |
| 804 | uint64_t readTimestamp = ReadUint64(buffer.data(), offset); |
| 805 | BOOST_CHECK(readTimestamp == timestamp); |
| 806 | |
| 807 | // Check the thread id |
| 808 | offset += uint64_t_size; |
Colm Donelan | 5bb3d8a | 2020-05-12 16:36:46 +0100 | [diff] [blame] | 809 | std::vector<uint8_t> readThreadId(ThreadIdSize, 0); |
| 810 | ReadBytes(buffer.data(), offset, ThreadIdSize, readThreadId.data()); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 811 | BOOST_CHECK(readThreadId == threadId); |
| 812 | |
| 813 | // Check the profiling GUID |
Colm Donelan | 5bb3d8a | 2020-05-12 16:36:46 +0100 | [diff] [blame] | 814 | offset += ThreadIdSize; |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 815 | uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset); |
| 816 | BOOST_CHECK(readProfilingGuid == profilingGuid); |
| 817 | } |
| 818 | |
| 819 | BOOST_AUTO_TEST_SUITE_END() |