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 | |
| 15 | BOOST_AUTO_TEST_CASE(TimelineLabelPacketTest1) |
| 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 | |
| 29 | BOOST_AUTO_TEST_CASE(TimelineLabelPacketTest2) |
| 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 | |
| 45 | BOOST_AUTO_TEST_CASE(TimelineLabelPacketTest3) |
| 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 | |
| 61 | BOOST_AUTO_TEST_CASE(TimelineLabelPacketTest4) |
| 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 | |
| 77 | BOOST_AUTO_TEST_CASE(TimelineLabelPacketTest5) |
| 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); |
Jan Eilers | b884ea4 | 2019-10-16 09:54:15 +0100 | [diff] [blame] | 90 | BOOST_CHECK(numberOfBytesWritten == 36); |
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; |
| 97 | uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset); |
| 98 | uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F; |
| 99 | uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F; |
| 100 | uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007; |
| 101 | uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007; |
| 102 | BOOST_CHECK(packetFamily == 1); |
| 103 | BOOST_CHECK(packetClass == 0); |
| 104 | BOOST_CHECK(packetType == 1); |
| 105 | BOOST_CHECK(streamId == 0); |
| 106 | |
| 107 | offset += uint32_t_size; |
| 108 | uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset); |
| 109 | uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001; |
| 110 | uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF; |
| 111 | BOOST_CHECK(sequenceNumbered == 0); |
Jan Eilers | b884ea4 | 2019-10-16 09:54:15 +0100 | [diff] [blame] | 112 | BOOST_CHECK(dataLength == 28); |
| 113 | |
| 114 | // Check decl_Id |
| 115 | offset += uint32_t_size; |
| 116 | uint32_t decl_Id = ReadUint32(buffer.data(), offset); |
| 117 | BOOST_CHECK(decl_Id == uint32_t(0)); |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 118 | |
| 119 | // Check the profiling GUID |
| 120 | offset += uint32_t_size; |
| 121 | uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset); |
| 122 | BOOST_CHECK(readProfilingGuid == profilingGuid); |
| 123 | |
| 124 | // Check the SWTrace label |
| 125 | offset += uint64_t_size; |
| 126 | uint32_t swTraceLabelLength = ReadUint32(buffer.data(), offset); |
| 127 | BOOST_CHECK(swTraceLabelLength == 11); // Label length including the null-terminator |
| 128 | |
| 129 | offset += uint32_t_size; |
| 130 | BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer |
| 131 | label.data(), // The original label |
| 132 | swTraceLabelLength - 1) == 0); // The length of the label |
| 133 | |
| 134 | offset += swTraceLabelLength * uint32_t_size; |
| 135 | BOOST_CHECK(buffer[offset] == '\0'); // The null-terminator at the end of the SWTrace label |
| 136 | } |
| 137 | |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 138 | BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketNullBufferTest) |
| 139 | { |
| 140 | ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink; |
| 141 | const uint64_t relationshipGuid = 123456u; |
| 142 | const uint64_t headGuid = 234567u; |
| 143 | const uint64_t tailGuid = 345678u; |
| 144 | unsigned int numberOfBytesWritten = 789u; |
| 145 | TimelinePacketStatus result = WriteTimelineRelationshipBinaryPacket(relationshipType, |
| 146 | relationshipGuid, |
| 147 | headGuid, |
| 148 | tailGuid, |
| 149 | nullptr, |
| 150 | 512u, |
| 151 | numberOfBytesWritten); |
| 152 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 153 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 154 | } |
| 155 | |
| 156 | BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketZeroBufferSizeTest) |
| 157 | { |
| 158 | std::vector<unsigned char> buffer(512, 0); |
| 159 | |
| 160 | ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink; |
| 161 | const uint64_t relationshipGuid = 123456u; |
| 162 | const uint64_t headGuid = 234567u; |
| 163 | const uint64_t tailGuid = 345678u; |
| 164 | unsigned int numberOfBytesWritten = 789u; |
| 165 | TimelinePacketStatus result = WriteTimelineRelationshipBinaryPacket(relationshipType, |
| 166 | relationshipGuid, |
| 167 | headGuid, |
| 168 | tailGuid, |
| 169 | buffer.data(), |
| 170 | 0, |
| 171 | numberOfBytesWritten); |
| 172 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 173 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 174 | } |
| 175 | |
| 176 | BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketSmallBufferSizeTest) |
| 177 | { |
| 178 | std::vector<unsigned char> buffer(10, 0); |
| 179 | |
| 180 | ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink; |
| 181 | const uint64_t relationshipGuid = 123456u; |
| 182 | const uint64_t headGuid = 234567u; |
| 183 | const uint64_t tailGuid = 345678u; |
| 184 | unsigned int numberOfBytesWritten = 789u; |
| 185 | TimelinePacketStatus result = |
| 186 | WriteTimelineRelationshipBinaryPacket(relationshipType, |
| 187 | relationshipGuid, |
| 188 | headGuid, |
| 189 | tailGuid, |
| 190 | buffer.data(), |
| 191 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 192 | numberOfBytesWritten); |
| 193 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 194 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 195 | } |
| 196 | |
| 197 | BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketInvalidRelationTest) |
| 198 | { |
| 199 | std::vector<unsigned char> buffer(512, 0); |
| 200 | ProfilingRelationshipType relationshipType = static_cast<ProfilingRelationshipType>(5); |
| 201 | const uint64_t relationshipGuid = 123456u; |
| 202 | const uint64_t headGuid = 234567u; |
| 203 | const uint64_t tailGuid = 345678u; |
| 204 | unsigned int numberOfBytesWritten = 789u; |
| 205 | |
| 206 | BOOST_CHECK_THROW(WriteTimelineRelationshipBinaryPacket(relationshipType, |
| 207 | relationshipGuid, |
| 208 | headGuid, |
| 209 | tailGuid, |
| 210 | buffer.data(), |
| 211 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 212 | numberOfBytesWritten), |
| 213 | armnn::InvalidArgumentException); |
| 214 | |
| 215 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 216 | } |
| 217 | |
| 218 | BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketTest) |
| 219 | { |
| 220 | std::vector<unsigned char> buffer(512, 0); |
| 221 | |
| 222 | ProfilingRelationshipType relationshipType = ProfilingRelationshipType::RetentionLink; |
| 223 | const uint64_t relationshipGuid = 123456u; |
| 224 | const uint64_t headGuid = 234567u; |
| 225 | const uint64_t tailGuid = 345678u; |
| 226 | unsigned int numberOfBytesWritten = 789u; |
| 227 | TimelinePacketStatus result = |
| 228 | WriteTimelineRelationshipBinaryPacket(relationshipType, |
| 229 | relationshipGuid, |
| 230 | headGuid, |
| 231 | tailGuid, |
| 232 | buffer.data(), |
| 233 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 234 | numberOfBytesWritten); |
| 235 | BOOST_CHECK(result == TimelinePacketStatus::Ok); |
| 236 | BOOST_CHECK(numberOfBytesWritten == 40); |
| 237 | |
| 238 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 239 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 240 | |
| 241 | // Check the packet header |
| 242 | unsigned int offset = 0; |
| 243 | uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset); |
| 244 | uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F; |
| 245 | uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F; |
| 246 | uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007; |
| 247 | uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007; |
| 248 | BOOST_CHECK(packetFamily == 1); |
| 249 | BOOST_CHECK(packetClass == 0); |
| 250 | BOOST_CHECK(packetType == 1); |
| 251 | BOOST_CHECK(streamId == 0); |
| 252 | |
| 253 | offset += uint32_t_size; |
| 254 | uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset); |
| 255 | uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001; |
| 256 | uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF; |
| 257 | BOOST_CHECK(sequenceNumbered == 0); |
| 258 | BOOST_CHECK(dataLength == 32); |
| 259 | |
| 260 | // Check the decl_id |
| 261 | offset += uint32_t_size; |
| 262 | uint32_t readDeclId = ReadUint32(buffer.data(), offset); |
| 263 | BOOST_CHECK(readDeclId == 3); |
| 264 | |
| 265 | // Check the relationship type |
| 266 | offset += uint32_t_size; |
| 267 | uint32_t readRelationshipType = ReadUint32(buffer.data(), offset); |
| 268 | BOOST_CHECK(readRelationshipType == 0); |
| 269 | |
| 270 | // Check the relationship GUID |
| 271 | offset += uint32_t_size; |
| 272 | uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset); |
| 273 | BOOST_CHECK(readRelationshipGuid == relationshipGuid); |
| 274 | |
| 275 | // Check the head GUID |
| 276 | offset += uint64_t_size; |
| 277 | uint64_t readHeadGuid = ReadUint64(buffer.data(), offset); |
| 278 | BOOST_CHECK(readHeadGuid == headGuid); |
| 279 | |
| 280 | // Check the tail GUID |
| 281 | offset += uint64_t_size; |
| 282 | uint64_t readTailGuid = ReadUint64(buffer.data(), offset); |
| 283 | BOOST_CHECK(readTailGuid == tailGuid); |
| 284 | } |
| 285 | |
| 286 | BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketExecutionLinkTest) |
| 287 | { |
| 288 | std::vector<unsigned char> buffer(512, 0); |
| 289 | |
| 290 | ProfilingRelationshipType relationshipType = ProfilingRelationshipType::ExecutionLink; |
| 291 | const uint64_t relationshipGuid = 123456u; |
| 292 | const uint64_t headGuid = 234567u; |
| 293 | const uint64_t tailGuid = 345678u; |
| 294 | unsigned int numberOfBytesWritten = 789u; |
| 295 | TimelinePacketStatus result = |
| 296 | WriteTimelineRelationshipBinaryPacket(relationshipType, |
| 297 | relationshipGuid, |
| 298 | headGuid, |
| 299 | tailGuid, |
| 300 | buffer.data(), |
| 301 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 302 | numberOfBytesWritten); |
| 303 | BOOST_CHECK(result == TimelinePacketStatus::Ok); |
| 304 | BOOST_CHECK(numberOfBytesWritten == 40); |
| 305 | |
| 306 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 307 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 308 | |
| 309 | // Check the packet header |
| 310 | unsigned int offset = 0; |
| 311 | uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset); |
| 312 | uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F; |
| 313 | uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F; |
| 314 | uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007; |
| 315 | uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007; |
| 316 | BOOST_CHECK(packetFamily == 1); |
| 317 | BOOST_CHECK(packetClass == 0); |
| 318 | BOOST_CHECK(packetType == 1); |
| 319 | BOOST_CHECK(streamId == 0); |
| 320 | |
| 321 | offset += uint32_t_size; |
| 322 | uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset); |
| 323 | uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001; |
| 324 | uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF; |
| 325 | BOOST_CHECK(sequenceNumbered == 0); |
| 326 | BOOST_CHECK(dataLength == 32); |
| 327 | |
| 328 | // Check the decl_id |
| 329 | offset += uint32_t_size; |
| 330 | uint32_t readDeclId = ReadUint32(buffer.data(), offset); |
| 331 | BOOST_CHECK(readDeclId == 3); |
| 332 | |
| 333 | // Check the relationship type |
| 334 | offset += uint32_t_size; |
| 335 | uint32_t readRelationshipType = ReadUint32(buffer.data(), offset); |
| 336 | BOOST_CHECK(readRelationshipType == 1); |
| 337 | |
| 338 | // Check the relationship GUID |
| 339 | offset += uint32_t_size; |
| 340 | uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset); |
| 341 | BOOST_CHECK(readRelationshipGuid == relationshipGuid); |
| 342 | |
| 343 | // Check the head GUID |
| 344 | offset += uint64_t_size; |
| 345 | uint64_t readHeadGuid = ReadUint64(buffer.data(), offset); |
| 346 | BOOST_CHECK(readHeadGuid == headGuid); |
| 347 | |
| 348 | // Check the tail GUID |
| 349 | offset += uint64_t_size; |
| 350 | uint64_t readTailGuid = ReadUint64(buffer.data(), offset); |
| 351 | BOOST_CHECK(readTailGuid == tailGuid); |
| 352 | } |
| 353 | |
| 354 | |
| 355 | BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketDataLinkTest) |
| 356 | { |
| 357 | std::vector<unsigned char> buffer(512, 0); |
| 358 | |
| 359 | ProfilingRelationshipType relationshipType = ProfilingRelationshipType::DataLink; |
| 360 | const uint64_t relationshipGuid = 123456u; |
| 361 | const uint64_t headGuid = 234567u; |
| 362 | const uint64_t tailGuid = 345678u; |
| 363 | unsigned int numberOfBytesWritten = 789u; |
| 364 | TimelinePacketStatus result = |
| 365 | WriteTimelineRelationshipBinaryPacket(relationshipType, |
| 366 | relationshipGuid, |
| 367 | headGuid, |
| 368 | tailGuid, |
| 369 | buffer.data(), |
| 370 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 371 | numberOfBytesWritten); |
| 372 | BOOST_CHECK(result == TimelinePacketStatus::Ok); |
| 373 | BOOST_CHECK(numberOfBytesWritten == 40); |
| 374 | |
| 375 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 376 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 377 | |
| 378 | // Check the packet header |
| 379 | unsigned int offset = 0; |
| 380 | uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset); |
| 381 | uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F; |
| 382 | uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F; |
| 383 | uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007; |
| 384 | uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007; |
| 385 | BOOST_CHECK(packetFamily == 1); |
| 386 | BOOST_CHECK(packetClass == 0); |
| 387 | BOOST_CHECK(packetType == 1); |
| 388 | BOOST_CHECK(streamId == 0); |
| 389 | |
| 390 | offset += uint32_t_size; |
| 391 | uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset); |
| 392 | uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001; |
| 393 | uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF; |
| 394 | BOOST_CHECK(sequenceNumbered == 0); |
| 395 | BOOST_CHECK(dataLength == 32); |
| 396 | |
| 397 | // Check the decl_id |
| 398 | offset += uint32_t_size; |
| 399 | uint32_t readDeclId = ReadUint32(buffer.data(), offset); |
| 400 | BOOST_CHECK(readDeclId == 3); |
| 401 | |
| 402 | // Check the relationship type |
| 403 | offset += uint32_t_size; |
| 404 | uint32_t readRelationshipType = ReadUint32(buffer.data(), offset); |
| 405 | BOOST_CHECK(readRelationshipType == 2); |
| 406 | |
| 407 | // Check the relationship GUID |
| 408 | offset += uint32_t_size; |
| 409 | uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset); |
| 410 | BOOST_CHECK(readRelationshipGuid == relationshipGuid); |
| 411 | |
| 412 | // Check the head GUID |
| 413 | offset += uint64_t_size; |
| 414 | uint64_t readHeadGuid = ReadUint64(buffer.data(), offset); |
| 415 | BOOST_CHECK(readHeadGuid == headGuid); |
| 416 | |
| 417 | // Check the tail GUID |
| 418 | offset += uint64_t_size; |
| 419 | uint64_t readTailGuid = ReadUint64(buffer.data(), offset); |
| 420 | BOOST_CHECK(readTailGuid == tailGuid); |
| 421 | } |
| 422 | |
| 423 | |
| 424 | BOOST_AUTO_TEST_CASE(TimelineRelationshipPacketLabelLinkTest) |
| 425 | { |
| 426 | std::vector<unsigned char> buffer(512, 0); |
| 427 | |
| 428 | ProfilingRelationshipType relationshipType = ProfilingRelationshipType::LabelLink; |
| 429 | const uint64_t relationshipGuid = 123456u; |
| 430 | const uint64_t headGuid = 234567u; |
| 431 | const uint64_t tailGuid = 345678u; |
| 432 | unsigned int numberOfBytesWritten = 789u; |
| 433 | TimelinePacketStatus result = |
| 434 | WriteTimelineRelationshipBinaryPacket(relationshipType, |
| 435 | relationshipGuid, |
| 436 | headGuid, |
| 437 | tailGuid, |
| 438 | buffer.data(), |
| 439 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 440 | numberOfBytesWritten); |
| 441 | BOOST_CHECK(result == TimelinePacketStatus::Ok); |
| 442 | BOOST_CHECK(numberOfBytesWritten == 40); |
| 443 | |
| 444 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 445 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 446 | |
| 447 | // Check the packet header |
| 448 | unsigned int offset = 0; |
| 449 | uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset); |
| 450 | uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F; |
| 451 | uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F; |
| 452 | uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007; |
| 453 | uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007; |
| 454 | BOOST_CHECK(packetFamily == 1); |
| 455 | BOOST_CHECK(packetClass == 0); |
| 456 | BOOST_CHECK(packetType == 1); |
| 457 | BOOST_CHECK(streamId == 0); |
| 458 | |
| 459 | offset += uint32_t_size; |
| 460 | uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset); |
| 461 | uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001; |
| 462 | uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF; |
| 463 | BOOST_CHECK(sequenceNumbered == 0); |
| 464 | BOOST_CHECK(dataLength == 32); |
| 465 | |
| 466 | // Check the decl_id |
| 467 | offset += uint32_t_size; |
| 468 | uint32_t readDeclId = ReadUint32(buffer.data(), offset); |
| 469 | BOOST_CHECK(readDeclId == 3); |
| 470 | |
| 471 | // Check the relationship type |
| 472 | offset += uint32_t_size; |
| 473 | uint32_t readRelationshipType = ReadUint32(buffer.data(), offset); |
| 474 | BOOST_CHECK(readRelationshipType == 3); |
| 475 | |
| 476 | // Check the relationship GUID |
| 477 | offset += uint32_t_size; |
| 478 | uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset); |
| 479 | BOOST_CHECK(readRelationshipGuid == relationshipGuid); |
| 480 | |
| 481 | // Check the head GUID |
| 482 | offset += uint64_t_size; |
| 483 | uint64_t readHeadGuid = ReadUint64(buffer.data(), offset); |
| 484 | BOOST_CHECK(readHeadGuid == headGuid); |
| 485 | |
| 486 | // Check the tail GUID |
| 487 | offset += uint64_t_size; |
| 488 | uint64_t readTailGuid = ReadUint64(buffer.data(), offset); |
| 489 | BOOST_CHECK(readTailGuid == tailGuid); |
| 490 | } |
| 491 | |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 492 | BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTest1) |
| 493 | { |
| 494 | unsigned int numberOfBytesWritten = 789u; |
| 495 | TimelinePacketStatus result = WriteTimelineMessageDirectoryPackage(nullptr, |
| 496 | 512u, |
| 497 | numberOfBytesWritten); |
| 498 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 499 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 500 | } |
| 501 | |
| 502 | BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTest2) |
| 503 | { |
| 504 | std::vector<unsigned char> buffer(512, 0); |
| 505 | |
| 506 | unsigned int numberOfBytesWritten = 789u; |
| 507 | TimelinePacketStatus result = WriteTimelineMessageDirectoryPackage(buffer.data(), |
| 508 | 0, |
| 509 | numberOfBytesWritten); |
| 510 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 511 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 512 | } |
| 513 | |
| 514 | BOOST_AUTO_TEST_CASE(TimelineMessageDirectoryPacketTest3) |
| 515 | { |
| 516 | std::vector<unsigned char> buffer(512, 0); |
| 517 | unsigned int numberOfBytesWritten = 789u; |
| 518 | TimelinePacketStatus result = WriteTimelineMessageDirectoryPackage(buffer.data(), |
| 519 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 520 | numberOfBytesWritten); |
| 521 | BOOST_CHECK(result == TimelinePacketStatus::Ok); |
| 522 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 523 | BOOST_CHECK(numberOfBytesWritten == 427); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 524 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 525 | unsigned int uint8_t_size = sizeof(uint8_t); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 526 | unsigned int uint32_t_size = sizeof(uint32_t); |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 527 | unsigned int uint64_t_size = sizeof(uint64_t); |
| 528 | unsigned int threadId_size = sizeof(std::thread::id); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 529 | |
| 530 | // Check the packet header |
| 531 | unsigned int offset = 0; |
| 532 | uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset); |
| 533 | uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F; |
| 534 | uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F; |
| 535 | uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007; |
| 536 | uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007; |
| 537 | BOOST_CHECK(packetFamily == 1); |
| 538 | BOOST_CHECK(packetClass == 0); |
| 539 | BOOST_CHECK(packetType == 0); |
| 540 | BOOST_CHECK(streamId == 0); |
| 541 | |
| 542 | offset += uint32_t_size; |
| 543 | uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset); |
| 544 | uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001; |
| 545 | uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF; |
| 546 | BOOST_CHECK(sequenceNumbered == 0); |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 547 | BOOST_CHECK(dataLength == 419); |
| 548 | |
| 549 | // Check the stream header |
| 550 | offset += uint32_t_size; |
| 551 | uint8_t readStreamVersion = ReadUint8(buffer.data(), offset); |
| 552 | BOOST_CHECK(readStreamVersion == 4); |
| 553 | offset += uint8_t_size; |
| 554 | uint8_t readPointerBytes = ReadUint8(buffer.data(), offset); |
| 555 | BOOST_CHECK(readPointerBytes == uint64_t_size); |
| 556 | offset += uint8_t_size; |
| 557 | uint8_t readThreadIdBytes = ReadUint8(buffer.data(), offset); |
| 558 | BOOST_CHECK(readThreadIdBytes == threadId_size); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 559 | |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 560 | // Check the number of declarations |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 561 | offset += uint8_t_size; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 562 | uint32_t declCount = ReadUint32(buffer.data(), offset); |
| 563 | BOOST_CHECK(declCount == 5); |
| 564 | |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 565 | // Check the decl_id |
| 566 | offset += uint32_t_size; |
| 567 | uint32_t readDeclId = ReadUint32(buffer.data(), offset); |
| 568 | BOOST_CHECK(readDeclId == 0); |
| 569 | |
| 570 | // SWTrace "namestring" format |
| 571 | // length of the string (first 4 bytes) + string + null terminator |
| 572 | |
| 573 | // Check the decl_name |
| 574 | offset += uint32_t_size; |
| 575 | uint32_t swTraceDeclNameLength = ReadUint32(buffer.data(), offset); |
| 576 | BOOST_CHECK(swTraceDeclNameLength == 13); // decl_name length including the null-terminator |
| 577 | |
| 578 | std::string label = "declareLabel"; |
| 579 | offset += uint32_t_size; |
| 580 | 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] | 581 | label.data(), // The original label |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 582 | swTraceDeclNameLength - 1) == 0); // The length of the label |
| 583 | |
| 584 | // Check the ui_name |
| 585 | std::vector<uint32_t> swTraceString; |
| 586 | StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString); |
| 587 | offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size; |
| 588 | uint32_t swTraceUINameLength = ReadUint32(buffer.data(), offset); |
| 589 | BOOST_CHECK(swTraceUINameLength == 14); // ui_name length including the null-terminator |
| 590 | |
| 591 | label = "declare label"; |
| 592 | offset += uint32_t_size; |
| 593 | BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer |
| 594 | label.data(), // The original label |
| 595 | swTraceUINameLength - 1) == 0); // The length of the label |
| 596 | |
| 597 | // Check arg_types |
| 598 | StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString); |
| 599 | offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size; |
| 600 | uint32_t swTraceArgTypesLength = ReadUint32(buffer.data(), offset); |
| 601 | BOOST_CHECK(swTraceArgTypesLength == 3); // arg_types length including the null-terminator |
| 602 | |
| 603 | label = "ps"; |
| 604 | offset += uint32_t_size; |
| 605 | BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer |
| 606 | label.data(), // The original label |
| 607 | swTraceArgTypesLength - 1) == 0); // The length of the label |
| 608 | |
| 609 | // Check arg_names |
| 610 | StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString); |
| 611 | offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size; |
| 612 | uint32_t swTraceArgNamesLength = ReadUint32(buffer.data(), offset); |
| 613 | BOOST_CHECK(swTraceArgNamesLength == 11); // arg_names length including the null-terminator |
| 614 | |
| 615 | label = "guid,value"; |
| 616 | offset += uint32_t_size; |
| 617 | BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer |
| 618 | label.data(), // The original label |
| 619 | swTraceArgNamesLength - 1) == 0); // The length of the label |
| 620 | |
| 621 | // Check second message decl_id |
| 622 | StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString); |
| 623 | offset += (boost::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size; |
| 624 | readDeclId = ReadUint32(buffer.data(), offset); |
| 625 | BOOST_CHECK(readDeclId == 1); |
| 626 | |
| 627 | // Check second decl_name |
| 628 | offset += uint32_t_size; |
| 629 | swTraceDeclNameLength = ReadUint32(buffer.data(), offset); |
| 630 | BOOST_CHECK(swTraceDeclNameLength == 14); // decl_name length including the null-terminator |
| 631 | |
| 632 | label = "declareEntity"; |
| 633 | offset += uint32_t_size; |
| 634 | BOOST_CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer |
| 635 | label.data(), // The original label |
| 636 | swTraceDeclNameLength - 1) == 0); // The length of the label |
| 637 | } |
| 638 | |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 639 | BOOST_AUTO_TEST_CASE(TimelineEntityPacketTest1) |
| 640 | { |
| 641 | const uint64_t profilingGuid = 123456u; |
| 642 | unsigned int numberOfBytesWritten = 789u; |
| 643 | TimelinePacketStatus result = WriteTimelineEntityBinaryPacket(profilingGuid, |
| 644 | nullptr, |
| 645 | 512u, |
| 646 | numberOfBytesWritten); |
| 647 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 648 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 649 | } |
| 650 | |
| 651 | BOOST_AUTO_TEST_CASE(TimelineEntityPacketTest2) |
| 652 | { |
| 653 | std::vector<unsigned char> buffer(512, 0); |
| 654 | |
| 655 | const uint64_t profilingGuid = 123456u; |
| 656 | unsigned int numberOfBytesWritten = 789u; |
| 657 | TimelinePacketStatus result = WriteTimelineEntityBinaryPacket(profilingGuid, |
| 658 | buffer.data(), |
| 659 | 0, |
| 660 | numberOfBytesWritten); |
| 661 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 662 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 663 | } |
| 664 | |
| 665 | BOOST_AUTO_TEST_CASE(TimelineEntityPacketTest3) |
| 666 | { |
| 667 | std::vector<unsigned char> buffer(10, 0); |
| 668 | |
| 669 | const uint64_t profilingGuid = 123456u; |
| 670 | unsigned int numberOfBytesWritten = 789u; |
| 671 | TimelinePacketStatus result = WriteTimelineEntityBinaryPacket(profilingGuid, |
| 672 | buffer.data(), |
| 673 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 674 | numberOfBytesWritten); |
| 675 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 676 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 677 | } |
| 678 | |
| 679 | BOOST_AUTO_TEST_CASE(TimelineEntityPacketTest4) |
| 680 | { |
| 681 | std::vector<unsigned char> buffer(512, 0); |
| 682 | |
| 683 | const uint64_t profilingGuid = 123456u; |
| 684 | unsigned int numberOfBytesWritten = 789u; |
| 685 | TimelinePacketStatus result = WriteTimelineEntityBinaryPacket(profilingGuid, |
| 686 | buffer.data(), |
| 687 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 688 | numberOfBytesWritten); |
| 689 | BOOST_CHECK(result == TimelinePacketStatus::Ok); |
Jan Eilers | b884ea4 | 2019-10-16 09:54:15 +0100 | [diff] [blame] | 690 | BOOST_CHECK(numberOfBytesWritten == 20); |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 691 | |
| 692 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 693 | |
| 694 | // Check the packet header |
| 695 | unsigned int offset = 0; |
| 696 | uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset); |
| 697 | uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F; |
| 698 | uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F; |
| 699 | uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007; |
| 700 | uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007; |
| 701 | BOOST_CHECK(packetFamily == 1); |
| 702 | BOOST_CHECK(packetClass == 0); |
| 703 | BOOST_CHECK(packetType == 1); |
| 704 | BOOST_CHECK(streamId == 0); |
| 705 | |
| 706 | offset += uint32_t_size; |
| 707 | uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset); |
| 708 | uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001; |
| 709 | uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF; |
| 710 | BOOST_CHECK(sequenceNumbered == 0); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 711 | BOOST_CHECK(dataLength == 12); |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 712 | |
Jan Eilers | b884ea4 | 2019-10-16 09:54:15 +0100 | [diff] [blame] | 713 | // Check decl_Id |
| 714 | offset += uint32_t_size; |
| 715 | uint32_t decl_Id = ReadUint32(buffer.data(), offset); |
| 716 | BOOST_CHECK(decl_Id == uint32_t(1)); |
| 717 | |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 718 | // Check the profiling GUID |
| 719 | offset += uint32_t_size; |
| 720 | uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset); |
| 721 | BOOST_CHECK(readProfilingGuid == profilingGuid); |
| 722 | } |
| 723 | |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 724 | BOOST_AUTO_TEST_CASE(TimelineEventClassTest1) |
| 725 | { |
| 726 | const uint64_t profilingGuid = 123456u; |
| 727 | unsigned int numberOfBytesWritten = 789u; |
| 728 | TimelinePacketStatus result = WriteTimelineEventClassBinaryPacket(profilingGuid, |
| 729 | nullptr, |
| 730 | 512u, |
| 731 | numberOfBytesWritten); |
| 732 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 733 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 734 | } |
| 735 | |
| 736 | BOOST_AUTO_TEST_CASE(TimelineEventClassTest2) |
| 737 | { |
| 738 | std::vector<unsigned char> buffer(512, 0); |
| 739 | |
| 740 | const uint64_t profilingGuid = 123456u; |
| 741 | unsigned int numberOfBytesWritten = 789u; |
| 742 | TimelinePacketStatus result = WriteTimelineEventClassBinaryPacket(profilingGuid, |
| 743 | buffer.data(), |
| 744 | 0, |
| 745 | numberOfBytesWritten); |
| 746 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 747 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 748 | } |
| 749 | |
| 750 | BOOST_AUTO_TEST_CASE(TimelineEventClassTest3) |
| 751 | { |
| 752 | std::vector<unsigned char> buffer(10, 0); |
| 753 | |
| 754 | const uint64_t profilingGuid = 123456u; |
| 755 | unsigned int numberOfBytesWritten = 789u; |
| 756 | TimelinePacketStatus result = WriteTimelineEventClassBinaryPacket(profilingGuid, |
| 757 | buffer.data(), |
| 758 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 759 | numberOfBytesWritten); |
| 760 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 761 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 762 | } |
| 763 | |
| 764 | BOOST_AUTO_TEST_CASE(TimelineEventClassTest4) |
| 765 | { |
| 766 | std::vector<unsigned char> buffer(512, 0); |
| 767 | |
| 768 | const uint64_t profilingGuid = 123456u; |
| 769 | unsigned int numberOfBytesWritten = 789u; |
| 770 | TimelinePacketStatus result = WriteTimelineEventClassBinaryPacket(profilingGuid, |
| 771 | buffer.data(), |
| 772 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 773 | numberOfBytesWritten); |
| 774 | BOOST_CHECK(result == TimelinePacketStatus::Ok); |
| 775 | BOOST_CHECK(numberOfBytesWritten == 20); |
| 776 | |
| 777 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 778 | |
| 779 | // Check the packet header |
| 780 | unsigned int offset = 0; |
| 781 | uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset); |
| 782 | uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F; |
| 783 | uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F; |
| 784 | uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007; |
| 785 | uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007; |
| 786 | BOOST_CHECK(packetFamily == 1); |
| 787 | BOOST_CHECK(packetClass == 0); |
| 788 | BOOST_CHECK(packetType == 1); |
| 789 | BOOST_CHECK(streamId == 0); |
| 790 | |
| 791 | offset += uint32_t_size; |
| 792 | uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset); |
| 793 | uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001; |
| 794 | uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF; |
| 795 | BOOST_CHECK(sequenceNumbered == 0); |
| 796 | BOOST_CHECK(dataLength == 12); |
| 797 | |
| 798 | // Check the decl_id |
| 799 | offset += uint32_t_size; |
| 800 | uint32_t declId = ReadUint32(buffer.data(), offset); |
| 801 | BOOST_CHECK(declId == uint32_t(2)); |
| 802 | |
| 803 | // Check the profiling GUID |
| 804 | offset += uint32_t_size; |
| 805 | uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset); |
| 806 | BOOST_CHECK(readProfilingGuid == profilingGuid); |
| 807 | } |
| 808 | |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 809 | BOOST_AUTO_TEST_CASE(TimelineEventPacketTest1) |
| 810 | { |
| 811 | const uint64_t timestamp = 456789u; |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 812 | const std::thread::id threadId = std::this_thread::get_id(); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 813 | const uint64_t profilingGuid = 123456u; |
| 814 | unsigned int numberOfBytesWritten = 789u; |
| 815 | TimelinePacketStatus result = WriteTimelineEventBinaryPacket(timestamp, |
| 816 | threadId, |
| 817 | profilingGuid, |
| 818 | nullptr, |
| 819 | 512u, |
| 820 | numberOfBytesWritten); |
| 821 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 822 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 823 | } |
| 824 | |
| 825 | BOOST_AUTO_TEST_CASE(TimelineEventPacketTest2) |
| 826 | { |
| 827 | std::vector<unsigned char> buffer(512, 0); |
| 828 | |
| 829 | const uint64_t timestamp = 456789u; |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 830 | const std::thread::id threadId = std::this_thread::get_id(); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 831 | const uint64_t profilingGuid = 123456u; |
| 832 | unsigned int numberOfBytesWritten = 789u; |
| 833 | TimelinePacketStatus result = WriteTimelineEventBinaryPacket(timestamp, |
| 834 | threadId, |
| 835 | profilingGuid, |
| 836 | buffer.data(), |
| 837 | 0, |
| 838 | numberOfBytesWritten); |
| 839 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 840 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 841 | } |
| 842 | |
| 843 | BOOST_AUTO_TEST_CASE(TimelineEventPacketTest3) |
| 844 | { |
| 845 | std::vector<unsigned char> buffer(10, 0); |
| 846 | |
| 847 | const uint64_t timestamp = 456789u; |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 848 | const std::thread::id threadId = std::this_thread::get_id(); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 849 | const uint64_t profilingGuid = 123456u; |
| 850 | unsigned int numberOfBytesWritten = 789u; |
| 851 | TimelinePacketStatus result = WriteTimelineEventBinaryPacket(timestamp, |
| 852 | threadId, |
| 853 | profilingGuid, |
| 854 | buffer.data(), |
| 855 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 856 | numberOfBytesWritten); |
| 857 | BOOST_CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 858 | BOOST_CHECK(numberOfBytesWritten == 0); |
| 859 | } |
| 860 | |
| 861 | BOOST_AUTO_TEST_CASE(TimelineEventPacketTest4) |
| 862 | { |
| 863 | std::vector<unsigned char> buffer(512, 0); |
| 864 | |
| 865 | const uint64_t timestamp = 456789u; |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 866 | const std::thread::id threadId = std::this_thread::get_id(); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 867 | const uint64_t profilingGuid = 123456u; |
| 868 | unsigned int numberOfBytesWritten = 789u; |
| 869 | TimelinePacketStatus result = WriteTimelineEventBinaryPacket(timestamp, |
| 870 | threadId, |
| 871 | profilingGuid, |
| 872 | buffer.data(), |
| 873 | boost::numeric_cast<unsigned int>(buffer.size()), |
| 874 | numberOfBytesWritten); |
| 875 | BOOST_CHECK(result == TimelinePacketStatus::Ok); |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 876 | BOOST_CHECK(numberOfBytesWritten == 36); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 877 | |
| 878 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 879 | unsigned int uint64_t_size = sizeof(uint64_t); |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 880 | unsigned int threadId_size = sizeof(std::thread::id); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 881 | |
| 882 | // Check the packet header |
| 883 | unsigned int offset = 0; |
| 884 | uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset); |
| 885 | uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F; |
| 886 | uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F; |
| 887 | uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007; |
| 888 | uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007; |
| 889 | BOOST_CHECK(packetFamily == 1); |
| 890 | BOOST_CHECK(packetClass == 0); |
| 891 | BOOST_CHECK(packetType == 1); |
| 892 | BOOST_CHECK(streamId == 0); |
| 893 | |
| 894 | offset += uint32_t_size; |
| 895 | uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset); |
| 896 | uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001; |
| 897 | uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF; |
| 898 | BOOST_CHECK(sequenceNumbered == 0); |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 899 | BOOST_CHECK(dataLength == 28); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 900 | |
| 901 | // Check the decl_id |
| 902 | offset += uint32_t_size; |
| 903 | uint32_t readDeclId = ReadUint32(buffer.data(), offset); |
| 904 | BOOST_CHECK(readDeclId == 4); |
| 905 | |
| 906 | // Check the timestamp |
| 907 | offset += uint32_t_size; |
| 908 | uint64_t readTimestamp = ReadUint64(buffer.data(), offset); |
| 909 | BOOST_CHECK(readTimestamp == timestamp); |
| 910 | |
| 911 | // Check the thread id |
| 912 | offset += uint64_t_size; |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 913 | std::vector<uint8_t> readThreadId(threadId_size, 0); |
| 914 | ReadBytes(buffer.data(), offset, threadId_size, readThreadId.data()); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 915 | BOOST_CHECK(readThreadId == threadId); |
| 916 | |
| 917 | // Check the profiling GUID |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 918 | offset += threadId_size; |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 919 | uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset); |
| 920 | BOOST_CHECK(readProfilingGuid == profilingGuid); |
| 921 | } |
| 922 | |
| 923 | BOOST_AUTO_TEST_SUITE_END() |