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 | 3e9bc19 | 2022-03-23 23:01:26 +0000 | [diff] [blame] | 6 | #include <client/src/ProfilingUtils.hpp> |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 7 | |
Jim Flynn | 75c14f4 | 2022-03-10 22:05:42 +0000 | [diff] [blame] | 8 | #include <common/include/NumericCast.hpp> |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 9 | #include <common/include/SwTrace.hpp> |
Jim Flynn | 9c85b41 | 2022-03-16 00:27:43 +0000 | [diff] [blame] | 10 | #include <common/include/Threads.hpp> |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 11 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 12 | #include <doctest/doctest.h> |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 13 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 14 | using namespace arm::pipe; |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 15 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 16 | TEST_SUITE("TimelinePacketTests") |
| 17 | { |
| 18 | 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); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 28 | CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 29 | CHECK(numberOfBytesWritten == 0); |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 30 | } |
| 31 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 32 | 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); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 44 | CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 45 | CHECK(numberOfBytesWritten == 0); |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 46 | } |
| 47 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 48 | 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(), |
Jim Flynn | 75c14f4 | 2022-03-10 22:05:42 +0000 | [diff] [blame] | 58 | arm::pipe::numeric_cast<unsigned int>(buffer.size()), |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 59 | numberOfBytesWritten); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 60 | CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 61 | CHECK(numberOfBytesWritten == 0); |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 62 | } |
| 63 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 64 | 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(), |
Jim Flynn | 75c14f4 | 2022-03-10 22:05:42 +0000 | [diff] [blame] | 74 | arm::pipe::numeric_cast<unsigned int>(buffer.size()), |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 75 | numberOfBytesWritten); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 76 | CHECK(result == TimelinePacketStatus::Error); |
| 77 | CHECK(numberOfBytesWritten == 0); |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 78 | } |
| 79 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 80 | 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(), |
Jim Flynn | 75c14f4 | 2022-03-10 22:05:42 +0000 | [diff] [blame] | 90 | arm::pipe::numeric_cast<unsigned int>(buffer.size()), |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 91 | numberOfBytesWritten); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 92 | CHECK(result == TimelinePacketStatus::Ok); |
| 93 | 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); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 101 | 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); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 106 | CHECK(readProfilingGuid == profilingGuid); |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 107 | |
| 108 | // Check the SWTrace label |
| 109 | offset += uint64_t_size; |
| 110 | uint32_t swTraceLabelLength = ReadUint32(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 111 | CHECK(swTraceLabelLength == 11); // Label length including the null-terminator |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 112 | |
| 113 | offset += uint32_t_size; |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 114 | CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 115 | label.data(), // The original label |
| 116 | swTraceLabelLength - 1) == 0); // The length of the label |
| 117 | |
| 118 | offset += swTraceLabelLength * uint32_t_size; |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 119 | CHECK(buffer[offset] == '\0'); // The null-terminator at the end of the SWTrace label |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 120 | } |
| 121 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 122 | TEST_CASE("TimelineRelationshipPacketNullBufferTest") |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 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); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 138 | CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 139 | CHECK(numberOfBytesWritten == 0); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 140 | } |
| 141 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 142 | TEST_CASE("TimelineRelationshipPacketZeroBufferSizeTest") |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 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); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 160 | CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 161 | CHECK(numberOfBytesWritten == 0); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 162 | } |
| 163 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 164 | TEST_CASE("TimelineRelationshipPacketSmallBufferSizeTest") |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 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(), |
Jim Flynn | 75c14f4 | 2022-03-10 22:05:42 +0000 | [diff] [blame] | 181 | arm::pipe::numeric_cast<unsigned int>(buffer.size()), |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 182 | numberOfBytesWritten); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 183 | CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 184 | CHECK(numberOfBytesWritten == 0); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 185 | } |
| 186 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 187 | TEST_CASE("TimelineRelationshipPacketInvalidRelationTest") |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 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 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 198 | CHECK_THROWS_AS(WriteTimelineRelationshipBinary(relationshipType, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 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(), |
Jim Flynn | 75c14f4 | 2022-03-10 22:05:42 +0000 | [diff] [blame] | 204 | arm::pipe::numeric_cast<unsigned int>(buffer.size()), |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 205 | numberOfBytesWritten), |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 206 | arm::pipe::InvalidArgumentException); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 207 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 208 | CHECK(numberOfBytesWritten == 0); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 209 | } |
| 210 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 211 | 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(), |
Jim Flynn | 75c14f4 | 2022-03-10 22:05:42 +0000 | [diff] [blame] | 228 | arm::pipe::numeric_cast<unsigned int>(buffer.size()), |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 229 | numberOfBytesWritten); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 230 | CHECK(result == TimelinePacketStatus::Ok); |
| 231 | 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); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 240 | CHECK(readDeclId == 3); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 241 | |
| 242 | // Check the relationship type |
| 243 | offset += uint32_t_size; |
| 244 | uint32_t readRelationshipType = ReadUint32(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 245 | CHECK(readRelationshipType == 0); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 246 | |
| 247 | // Check the relationship GUID |
| 248 | offset += uint32_t_size; |
| 249 | uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 250 | CHECK(readRelationshipGuid == relationshipGuid); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 251 | |
| 252 | // Check the head GUID |
| 253 | offset += uint64_t_size; |
| 254 | uint64_t readHeadGuid = ReadUint64(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 255 | CHECK(readHeadGuid == headGuid); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 256 | |
| 257 | // Check the tail GUID |
| 258 | offset += uint64_t_size; |
| 259 | uint64_t readTailGuid = ReadUint64(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 260 | 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); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 265 | CHECK(readAttributeGuid == attributeGuid); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 266 | } |
| 267 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 268 | 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(), |
Jim Flynn | 75c14f4 | 2022-03-10 22:05:42 +0000 | [diff] [blame] | 285 | arm::pipe::numeric_cast<unsigned int>(buffer.size()), |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 286 | numberOfBytesWritten); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 287 | CHECK(result == TimelinePacketStatus::Ok); |
| 288 | 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); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 295 | CHECK(readDeclId == 3); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 296 | |
| 297 | // Check the relationship type |
| 298 | offset += uint32_t_size; |
| 299 | uint32_t readRelationshipType = ReadUint32(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 300 | CHECK(readRelationshipType == 1); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 301 | |
| 302 | // Check the relationship GUID |
| 303 | offset += uint32_t_size; |
| 304 | uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 305 | CHECK(readRelationshipGuid == relationshipGuid); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 306 | |
| 307 | // Check the head GUID |
| 308 | offset += uint64_t_size; |
| 309 | uint64_t readHeadGuid = ReadUint64(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 310 | CHECK(readHeadGuid == headGuid); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 311 | |
| 312 | // Check the tail GUID |
| 313 | offset += uint64_t_size; |
| 314 | uint64_t readTailGuid = ReadUint64(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 315 | 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); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 320 | CHECK(readAttributeGuid == attributeGuid); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 324 | 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(), |
Jim Flynn | 75c14f4 | 2022-03-10 22:05:42 +0000 | [diff] [blame] | 341 | arm::pipe::numeric_cast<unsigned int>(buffer.size()), |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 342 | numberOfBytesWritten); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 343 | CHECK(result == TimelinePacketStatus::Ok); |
| 344 | 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); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 351 | CHECK(readDeclId == 3); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 352 | |
| 353 | // Check the relationship type |
| 354 | offset += uint32_t_size; |
| 355 | uint32_t readRelationshipType = ReadUint32(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 356 | CHECK(readRelationshipType == 2); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 357 | |
| 358 | // Check the relationship GUID |
| 359 | offset += uint32_t_size; |
| 360 | uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 361 | CHECK(readRelationshipGuid == relationshipGuid); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 362 | |
| 363 | // Check the head GUID |
| 364 | offset += uint64_t_size; |
| 365 | uint64_t readHeadGuid = ReadUint64(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 366 | CHECK(readHeadGuid == headGuid); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 367 | |
| 368 | // Check the tail GUID |
| 369 | offset += uint64_t_size; |
| 370 | uint64_t readTailGuid = ReadUint64(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 371 | 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); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 376 | CHECK(readAttributeGuid == attributeGuid); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 380 | 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(), |
Jim Flynn | 75c14f4 | 2022-03-10 22:05:42 +0000 | [diff] [blame] | 397 | arm::pipe::numeric_cast<unsigned int>(buffer.size()), |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 398 | numberOfBytesWritten); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 399 | CHECK(result == TimelinePacketStatus::Ok); |
| 400 | 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); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 408 | CHECK(readDeclId == 3); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 409 | |
| 410 | // Check the relationship type |
| 411 | offset += uint32_t_size; |
| 412 | uint32_t readRelationshipType = ReadUint32(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 413 | CHECK(readRelationshipType == 3); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 414 | |
| 415 | // Check the relationship GUID |
| 416 | offset += uint32_t_size; |
| 417 | uint64_t readRelationshipGuid = ReadUint64(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 418 | CHECK(readRelationshipGuid == relationshipGuid); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 419 | |
| 420 | // Check the head GUID |
| 421 | offset += uint64_t_size; |
| 422 | uint64_t readHeadGuid = ReadUint64(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 423 | CHECK(readHeadGuid == headGuid); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 424 | |
| 425 | // Check the tail GUID |
| 426 | offset += uint64_t_size; |
| 427 | uint64_t readTailGuid = ReadUint64(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 428 | 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); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 433 | CHECK(readAttributeGuid == attributeGuid); |
Narumol Prangnawarat | 7e5eec7 | 2019-10-16 12:16:26 +0100 | [diff] [blame] | 434 | } |
| 435 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 436 | 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); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 442 | CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 443 | CHECK(numberOfBytesWritten == 0); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 444 | } |
| 445 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 446 | 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); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 454 | CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 455 | CHECK(numberOfBytesWritten == 0); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 456 | } |
| 457 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 458 | 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(), |
Jim Flynn | 75c14f4 | 2022-03-10 22:05:42 +0000 | [diff] [blame] | 463 | arm::pipe::numeric_cast<unsigned int>( |
| 464 | buffer.size()), |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 465 | numberOfBytesWritten); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 466 | CHECK(result == TimelinePacketStatus::Ok); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 467 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 468 | CHECK(numberOfBytesWritten == 451); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 469 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 470 | unsigned int uint8_t_size = sizeof(uint8_t); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 471 | unsigned int uint32_t_size = sizeof(uint32_t); |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 472 | unsigned int uint64_t_size = sizeof(uint64_t); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 473 | |
| 474 | // Check the packet header |
| 475 | unsigned int offset = 0; |
| 476 | uint32_t packetHeaderWord0 = ReadUint32(buffer.data(), offset); |
| 477 | uint32_t packetFamily = (packetHeaderWord0 >> 26) & 0x0000003F; |
| 478 | uint32_t packetClass = (packetHeaderWord0 >> 19) & 0x0000007F; |
| 479 | uint32_t packetType = (packetHeaderWord0 >> 16) & 0x00000007; |
| 480 | uint32_t streamId = (packetHeaderWord0 >> 0) & 0x00000007; |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 481 | CHECK(packetFamily == 1); |
| 482 | CHECK(packetClass == 0); |
| 483 | CHECK(packetType == 0); |
| 484 | CHECK(streamId == 0); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 485 | |
| 486 | offset += uint32_t_size; |
| 487 | uint32_t packetHeaderWord1 = ReadUint32(buffer.data(), offset); |
| 488 | uint32_t sequenceNumbered = (packetHeaderWord1 >> 24) & 0x00000001; |
| 489 | uint32_t dataLength = (packetHeaderWord1 >> 0) & 0x00FFFFFF; |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 490 | CHECK(sequenceNumbered == 0); |
| 491 | CHECK(dataLength == 443); |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 492 | |
| 493 | // Check the stream header |
| 494 | offset += uint32_t_size; |
| 495 | uint8_t readStreamVersion = ReadUint8(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 496 | CHECK(readStreamVersion == 4); |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 497 | offset += uint8_t_size; |
| 498 | uint8_t readPointerBytes = ReadUint8(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 499 | CHECK(readPointerBytes == uint64_t_size); |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 500 | offset += uint8_t_size; |
| 501 | uint8_t readThreadIdBytes = ReadUint8(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 502 | CHECK(readThreadIdBytes == ThreadIdSize); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 503 | |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 504 | // Check the number of declarations |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 505 | offset += uint8_t_size; |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 506 | uint32_t declCount = ReadUint32(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 507 | CHECK(declCount == 5); |
Finn Williams | e63a026 | 2019-10-22 10:30:49 +0100 | [diff] [blame] | 508 | |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 509 | // Check the decl_id |
| 510 | offset += uint32_t_size; |
| 511 | uint32_t readDeclId = ReadUint32(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 512 | CHECK(readDeclId == 0); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 513 | |
| 514 | // SWTrace "namestring" format |
| 515 | // length of the string (first 4 bytes) + string + null terminator |
| 516 | |
| 517 | // Check the decl_name |
| 518 | offset += uint32_t_size; |
| 519 | uint32_t swTraceDeclNameLength = ReadUint32(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 520 | CHECK(swTraceDeclNameLength == 13); // decl_name length including the null-terminator |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 521 | |
| 522 | std::string label = "declareLabel"; |
| 523 | offset += uint32_t_size; |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 524 | 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] | 525 | label.data(), // The original label |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 526 | swTraceDeclNameLength - 1) == 0); // The length of the label |
| 527 | |
| 528 | // Check the ui_name |
| 529 | std::vector<uint32_t> swTraceString; |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 530 | StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString); |
Jim Flynn | 75c14f4 | 2022-03-10 22:05:42 +0000 | [diff] [blame] | 531 | offset += (arm::pipe::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size; |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 532 | uint32_t swTraceUINameLength = ReadUint32(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 533 | CHECK(swTraceUINameLength == 14); // ui_name length including the null-terminator |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 534 | |
| 535 | label = "declare label"; |
| 536 | offset += uint32_t_size; |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 537 | CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 538 | label.data(), // The original label |
| 539 | swTraceUINameLength - 1) == 0); // The length of the label |
| 540 | |
| 541 | // Check arg_types |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 542 | StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString); |
Jim Flynn | 75c14f4 | 2022-03-10 22:05:42 +0000 | [diff] [blame] | 543 | offset += (arm::pipe::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size; |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 544 | uint32_t swTraceArgTypesLength = ReadUint32(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 545 | CHECK(swTraceArgTypesLength == 3); // arg_types length including the null-terminator |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 546 | |
| 547 | label = "ps"; |
| 548 | offset += uint32_t_size; |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 549 | CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 550 | label.data(), // The original label |
| 551 | swTraceArgTypesLength - 1) == 0); // The length of the label |
| 552 | |
| 553 | // Check arg_names |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 554 | StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString); |
Jim Flynn | 75c14f4 | 2022-03-10 22:05:42 +0000 | [diff] [blame] | 555 | offset += (arm::pipe::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size; |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 556 | uint32_t swTraceArgNamesLength = ReadUint32(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 557 | CHECK(swTraceArgNamesLength == 11); // arg_names length including the null-terminator |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 558 | |
| 559 | label = "guid,value"; |
| 560 | offset += uint32_t_size; |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 561 | CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 562 | label.data(), // The original label |
| 563 | swTraceArgNamesLength - 1) == 0); // The length of the label |
| 564 | |
| 565 | // Check second message decl_id |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame] | 566 | StringToSwTraceString<SwTraceCharPolicy>(label, swTraceString); |
Jim Flynn | 75c14f4 | 2022-03-10 22:05:42 +0000 | [diff] [blame] | 567 | offset += (arm::pipe::numeric_cast<unsigned int>(swTraceString.size()) - 1) * uint32_t_size; |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 568 | readDeclId = ReadUint32(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 569 | CHECK(readDeclId == 1); |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 570 | |
| 571 | // Check second decl_name |
| 572 | offset += uint32_t_size; |
| 573 | swTraceDeclNameLength = ReadUint32(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 574 | CHECK(swTraceDeclNameLength == 14); // decl_name length including the null-terminator |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 575 | |
| 576 | label = "declareEntity"; |
| 577 | offset += uint32_t_size; |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 578 | CHECK(std::memcmp(buffer.data() + offset, // Offset to the label in the buffer |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 579 | label.data(), // The original label |
| 580 | swTraceDeclNameLength - 1) == 0); // The length of the label |
| 581 | } |
| 582 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 583 | TEST_CASE("TimelineEntityPacketTestNoBuffer") |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 584 | { |
| 585 | const uint64_t profilingGuid = 123456u; |
| 586 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 587 | TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid, |
| 588 | nullptr, |
| 589 | 512u, |
| 590 | numberOfBytesWritten); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 591 | CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 592 | CHECK(numberOfBytesWritten == 0); |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 593 | } |
| 594 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 595 | TEST_CASE("TimelineEntityPacketTestBufferExhaustedWithZeroBufferSize") |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 596 | { |
| 597 | std::vector<unsigned char> buffer(512, 0); |
| 598 | |
| 599 | const uint64_t profilingGuid = 123456u; |
| 600 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 601 | TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid, |
| 602 | buffer.data(), |
| 603 | 0, |
| 604 | numberOfBytesWritten); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 605 | CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 606 | CHECK(numberOfBytesWritten == 0); |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 607 | } |
| 608 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 609 | TEST_CASE("TimelineEntityPacketTestBufferExhaustedWithFixedBufferSize") |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 610 | { |
| 611 | std::vector<unsigned char> buffer(10, 0); |
| 612 | |
| 613 | const uint64_t profilingGuid = 123456u; |
| 614 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 615 | TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid, |
| 616 | buffer.data(), |
Jim Flynn | 75c14f4 | 2022-03-10 22:05:42 +0000 | [diff] [blame] | 617 | arm::pipe::numeric_cast<unsigned int>(buffer.size()), |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 618 | numberOfBytesWritten); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 619 | CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 620 | CHECK(numberOfBytesWritten == 0); |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 621 | } |
| 622 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 623 | TEST_CASE("TimelineEntityPacketTestFullConstructionOfData") |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 624 | { |
| 625 | std::vector<unsigned char> buffer(512, 0); |
| 626 | |
| 627 | const uint64_t profilingGuid = 123456u; |
| 628 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 629 | TimelinePacketStatus result = WriteTimelineEntityBinary(profilingGuid, |
| 630 | buffer.data(), |
Jim Flynn | 75c14f4 | 2022-03-10 22:05:42 +0000 | [diff] [blame] | 631 | arm::pipe::numeric_cast<unsigned int>(buffer.size()), |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 632 | numberOfBytesWritten); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 633 | CHECK(result == TimelinePacketStatus::Ok); |
| 634 | CHECK(numberOfBytesWritten == 12); |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 635 | |
| 636 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 637 | |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 638 | unsigned int offset = 0; |
Jan Eilers | b884ea4 | 2019-10-16 09:54:15 +0100 | [diff] [blame] | 639 | // Check decl_Id |
Jan Eilers | b884ea4 | 2019-10-16 09:54:15 +0100 | [diff] [blame] | 640 | uint32_t decl_Id = ReadUint32(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 641 | CHECK(decl_Id == uint32_t(1)); |
Jan Eilers | b884ea4 | 2019-10-16 09:54:15 +0100 | [diff] [blame] | 642 | |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 643 | // Check the profiling GUID |
| 644 | offset += uint32_t_size; |
| 645 | uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 646 | CHECK(readProfilingGuid == profilingGuid); |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 647 | } |
| 648 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 649 | TEST_CASE("TimelineEventClassTestNoBuffer") |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 650 | { |
| 651 | const uint64_t profilingGuid = 123456u; |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 652 | const uint64_t profilingNameGuid = 3345u; |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 653 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 654 | TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid, |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 655 | profilingNameGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 656 | nullptr, |
| 657 | 512u, |
| 658 | numberOfBytesWritten); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 659 | CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 660 | CHECK(numberOfBytesWritten == 0); |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 661 | } |
| 662 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 663 | TEST_CASE("TimelineEventClassTestBufferExhaustionZeroValue") |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 664 | { |
| 665 | std::vector<unsigned char> buffer(512, 0); |
| 666 | |
| 667 | const uint64_t profilingGuid = 123456u; |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 668 | const uint64_t profilingNameGuid = 3345u; |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 669 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 670 | TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid, |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 671 | profilingNameGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 672 | buffer.data(), |
| 673 | 0, |
| 674 | numberOfBytesWritten); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 675 | CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 676 | CHECK(numberOfBytesWritten == 0); |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 677 | } |
| 678 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 679 | TEST_CASE("TimelineEventClassTestBufferExhaustionFixedValue") |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 680 | { |
| 681 | std::vector<unsigned char> buffer(10, 0); |
| 682 | |
| 683 | const uint64_t profilingGuid = 123456u; |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 684 | const uint64_t profilingNameGuid = 5564u; |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 685 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 686 | TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid, |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 687 | profilingNameGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 688 | buffer.data(), |
Jim Flynn | 75c14f4 | 2022-03-10 22:05:42 +0000 | [diff] [blame] | 689 | arm::pipe::numeric_cast<unsigned int>(buffer.size()), |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 690 | numberOfBytesWritten); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 691 | CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 692 | CHECK(numberOfBytesWritten == 0); |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 693 | } |
| 694 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 695 | TEST_CASE("TimelineEventClassTestFullConstructionOfData") |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 696 | { |
| 697 | std::vector<unsigned char> buffer(512, 0); |
| 698 | |
| 699 | const uint64_t profilingGuid = 123456u; |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 700 | const uint64_t profilingNameGuid = 654321u; |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 701 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 702 | TimelinePacketStatus result = WriteTimelineEventClassBinary(profilingGuid, |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 703 | profilingNameGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 704 | buffer.data(), |
Jim Flynn | 75c14f4 | 2022-03-10 22:05:42 +0000 | [diff] [blame] | 705 | arm::pipe::numeric_cast<unsigned int>(buffer.size()), |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 706 | numberOfBytesWritten); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 707 | CHECK(result == TimelinePacketStatus::Ok); |
| 708 | CHECK(numberOfBytesWritten == 20); |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 709 | |
| 710 | unsigned int uint32_t_size = sizeof(uint32_t); |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 711 | unsigned int uint64_t_size = sizeof(uint64_t); |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 712 | |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 713 | unsigned int offset = 0; |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 714 | // Check the decl_id |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 715 | uint32_t declId = ReadUint32(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 716 | CHECK(declId == uint32_t(2)); |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 717 | |
| 718 | // Check the profiling GUID |
| 719 | offset += uint32_t_size; |
| 720 | uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 721 | CHECK(readProfilingGuid == profilingGuid); |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 722 | |
| 723 | offset += uint64_t_size; |
| 724 | uint64_t readProfilingNameGuid = ReadUint64(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 725 | CHECK(readProfilingNameGuid == profilingNameGuid); |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 726 | } |
| 727 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 728 | TEST_CASE("TimelineEventPacketTestNoBuffer") |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 729 | { |
| 730 | const uint64_t timestamp = 456789u; |
Jim Flynn | 9c85b41 | 2022-03-16 00:27:43 +0000 | [diff] [blame] | 731 | const int threadId = arm::pipe::GetCurrentThreadId(); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 732 | const uint64_t profilingGuid = 123456u; |
| 733 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 734 | TimelinePacketStatus result = WriteTimelineEventBinary(timestamp, |
| 735 | threadId, |
| 736 | profilingGuid, |
| 737 | nullptr, |
| 738 | 512u, |
| 739 | numberOfBytesWritten); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 740 | CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 741 | CHECK(numberOfBytesWritten == 0); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 742 | } |
| 743 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 744 | TEST_CASE("TimelineEventPacketTestBufferExhaustionZeroValue") |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 745 | { |
| 746 | std::vector<unsigned char> buffer(512, 0); |
| 747 | |
| 748 | const uint64_t timestamp = 456789u; |
Jim Flynn | 9c85b41 | 2022-03-16 00:27:43 +0000 | [diff] [blame] | 749 | const int threadId = arm::pipe::GetCurrentThreadId(); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 750 | const uint64_t profilingGuid = 123456u; |
| 751 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 752 | TimelinePacketStatus result = WriteTimelineEventBinary(timestamp, |
| 753 | threadId, |
| 754 | profilingGuid, |
| 755 | buffer.data(), |
| 756 | 0, |
| 757 | numberOfBytesWritten); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 758 | CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 759 | CHECK(numberOfBytesWritten == 0); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 760 | } |
| 761 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 762 | TEST_CASE("TimelineEventPacketTestBufferExhaustionFixedValue") |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 763 | { |
| 764 | std::vector<unsigned char> buffer(10, 0); |
| 765 | |
| 766 | const uint64_t timestamp = 456789u; |
Jim Flynn | 9c85b41 | 2022-03-16 00:27:43 +0000 | [diff] [blame] | 767 | const int threadId = arm::pipe::GetCurrentThreadId(); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 768 | const uint64_t profilingGuid = 123456u; |
| 769 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 770 | TimelinePacketStatus result = WriteTimelineEventBinary(timestamp, |
| 771 | threadId, |
| 772 | profilingGuid, |
| 773 | buffer.data(), |
Jim Flynn | 75c14f4 | 2022-03-10 22:05:42 +0000 | [diff] [blame] | 774 | arm::pipe::numeric_cast<unsigned int>(buffer.size()), |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 775 | numberOfBytesWritten); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 776 | CHECK(result == TimelinePacketStatus::BufferExhaustion); |
| 777 | CHECK(numberOfBytesWritten == 0); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 778 | } |
| 779 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 780 | TEST_CASE("TimelineEventPacketTestFullConstructionOfData") |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 781 | { |
| 782 | std::vector<unsigned char> buffer(512, 0); |
| 783 | |
| 784 | const uint64_t timestamp = 456789u; |
Jim Flynn | 9c85b41 | 2022-03-16 00:27:43 +0000 | [diff] [blame] | 785 | const int threadId = arm::pipe::GetCurrentThreadId(); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 786 | const uint64_t profilingGuid = 123456u; |
| 787 | unsigned int numberOfBytesWritten = 789u; |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 788 | TimelinePacketStatus result = WriteTimelineEventBinary(timestamp, |
| 789 | threadId, |
| 790 | profilingGuid, |
| 791 | buffer.data(), |
Jim Flynn | 75c14f4 | 2022-03-10 22:05:42 +0000 | [diff] [blame] | 792 | arm::pipe::numeric_cast<unsigned int>(buffer.size()), |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 793 | numberOfBytesWritten); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 794 | CHECK(result == TimelinePacketStatus::Ok); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 795 | |
| 796 | unsigned int uint32_t_size = sizeof(uint32_t); |
| 797 | unsigned int uint64_t_size = sizeof(uint64_t); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 798 | CHECK(numberOfBytesWritten == 20 + ThreadIdSize); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 799 | |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 800 | unsigned int offset = 0; |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 801 | // Check the decl_id |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 802 | uint32_t readDeclId = ReadUint32(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 803 | CHECK(readDeclId == 4); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 804 | |
| 805 | // Check the timestamp |
| 806 | offset += uint32_t_size; |
| 807 | uint64_t readTimestamp = ReadUint64(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 808 | CHECK(readTimestamp == timestamp); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 809 | |
| 810 | // Check the thread id |
| 811 | offset += uint64_t_size; |
Colm Donelan | 5bb3d8a | 2020-05-12 16:36:46 +0100 | [diff] [blame] | 812 | std::vector<uint8_t> readThreadId(ThreadIdSize, 0); |
| 813 | ReadBytes(buffer.data(), offset, ThreadIdSize, readThreadId.data()); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 814 | CHECK(readThreadId == threadId); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 815 | |
| 816 | // Check the profiling GUID |
Colm Donelan | 5bb3d8a | 2020-05-12 16:36:46 +0100 | [diff] [blame] | 817 | offset += ThreadIdSize; |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 818 | uint64_t readProfilingGuid = ReadUint64(buffer.data(), offset); |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 819 | CHECK(readProfilingGuid == profilingGuid); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 820 | } |
| 821 | |
Sadik Armagan | 1625efc | 2021-06-10 18:24:34 +0100 | [diff] [blame] | 822 | } |