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