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