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