Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 1 | // |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 2 | // Copyright © 2019 Arm Ltd. All rights reserved. |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Jim Flynn | 6406355 | 2020-02-14 10:18:08 +0000 | [diff] [blame] | 6 | #include "ProfilingMocks.hpp" |
Finn Williams | a0de056 | 2020-04-22 12:27:37 +0100 | [diff] [blame] | 7 | #include "ProfilingTestUtils.hpp" |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 8 | #include "SendCounterPacketTests.hpp" |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 9 | |
Narumol Prangnawarat | 0ec068f | 2019-09-30 16:20:20 +0100 | [diff] [blame] | 10 | #include <BufferManager.hpp> |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 11 | #include <CounterDirectory.hpp> |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 12 | #include <EncodeVersion.hpp> |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 13 | #include <ProfilingUtils.hpp> |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 14 | #include <SendCounterPacket.hpp> |
Rob Hughes | bdee426 | 2020-01-07 17:05:24 +0000 | [diff] [blame] | 15 | #include <Processes.hpp> |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 16 | |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 17 | #include <armnn/Exceptions.hpp> |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 18 | #include <armnn/Conversion.hpp> |
Rob Hughes | 122f325 | 2020-01-09 12:46:21 +0000 | [diff] [blame] | 19 | #include <armnn/Utils.hpp> |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 20 | |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 21 | #include <boost/test/unit_test.hpp> |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 22 | #include <boost/numeric/conversion/cast.hpp> |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 23 | |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 24 | #include <chrono> |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 25 | |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 26 | using namespace armnn::profiling; |
| 27 | |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 28 | namespace |
| 29 | { |
| 30 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 31 | // A short delay to wait for the thread to process a packet. |
Finn Williams | 09ad6f9 | 2019-12-19 17:05:18 +0000 | [diff] [blame] | 32 | uint16_t constexpr WAIT_UNTIL_READABLE_MS = 20; |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 33 | |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 34 | void SetNotConnectedProfilingState(ProfilingStateMachine& profilingStateMachine) |
| 35 | { |
| 36 | ProfilingState currentState = profilingStateMachine.GetCurrentState(); |
| 37 | switch (currentState) |
| 38 | { |
| 39 | case ProfilingState::WaitingForAck: |
| 40 | profilingStateMachine.TransitionToState(ProfilingState::Active); |
Rob Hughes | 122f325 | 2020-01-09 12:46:21 +0000 | [diff] [blame] | 41 | ARMNN_FALLTHROUGH; |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 42 | case ProfilingState::Uninitialised: |
Rob Hughes | 122f325 | 2020-01-09 12:46:21 +0000 | [diff] [blame] | 43 | ARMNN_FALLTHROUGH; |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 44 | case ProfilingState::Active: |
| 45 | profilingStateMachine.TransitionToState(ProfilingState::NotConnected); |
Rob Hughes | 122f325 | 2020-01-09 12:46:21 +0000 | [diff] [blame] | 46 | ARMNN_FALLTHROUGH; |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 47 | case ProfilingState::NotConnected: |
| 48 | return; |
| 49 | default: |
| 50 | BOOST_CHECK_MESSAGE(false, "Invalid profiling state"); |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | void SetWaitingForAckProfilingState(ProfilingStateMachine& profilingStateMachine) |
| 55 | { |
| 56 | ProfilingState currentState = profilingStateMachine.GetCurrentState(); |
| 57 | switch (currentState) |
| 58 | { |
| 59 | case ProfilingState::Uninitialised: |
Rob Hughes | 122f325 | 2020-01-09 12:46:21 +0000 | [diff] [blame] | 60 | ARMNN_FALLTHROUGH; |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 61 | case ProfilingState::Active: |
| 62 | profilingStateMachine.TransitionToState(ProfilingState::NotConnected); |
Rob Hughes | 122f325 | 2020-01-09 12:46:21 +0000 | [diff] [blame] | 63 | ARMNN_FALLTHROUGH; |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 64 | case ProfilingState::NotConnected: |
| 65 | profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck); |
Rob Hughes | 122f325 | 2020-01-09 12:46:21 +0000 | [diff] [blame] | 66 | ARMNN_FALLTHROUGH; |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 67 | case ProfilingState::WaitingForAck: |
| 68 | return; |
| 69 | default: |
| 70 | BOOST_CHECK_MESSAGE(false, "Invalid profiling state"); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | void SetActiveProfilingState(ProfilingStateMachine& profilingStateMachine) |
| 75 | { |
| 76 | ProfilingState currentState = profilingStateMachine.GetCurrentState(); |
| 77 | switch (currentState) |
| 78 | { |
| 79 | case ProfilingState::Uninitialised: |
| 80 | profilingStateMachine.TransitionToState(ProfilingState::NotConnected); |
Rob Hughes | 122f325 | 2020-01-09 12:46:21 +0000 | [diff] [blame] | 81 | ARMNN_FALLTHROUGH; |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 82 | case ProfilingState::NotConnected: |
| 83 | profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck); |
Rob Hughes | 122f325 | 2020-01-09 12:46:21 +0000 | [diff] [blame] | 84 | ARMNN_FALLTHROUGH; |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 85 | case ProfilingState::WaitingForAck: |
| 86 | profilingStateMachine.TransitionToState(ProfilingState::Active); |
Rob Hughes | 122f325 | 2020-01-09 12:46:21 +0000 | [diff] [blame] | 87 | ARMNN_FALLTHROUGH; |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 88 | case ProfilingState::Active: |
| 89 | return; |
| 90 | default: |
| 91 | BOOST_CHECK_MESSAGE(false, "Invalid profiling state"); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | } // Anonymous namespace |
| 96 | |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 97 | BOOST_AUTO_TEST_SUITE(SendCounterPacketTests) |
| 98 | |
Finn Williams | 09ad6f9 | 2019-12-19 17:05:18 +0000 | [diff] [blame] | 99 | using PacketType = MockProfilingConnection::PacketType; |
| 100 | |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 101 | BOOST_AUTO_TEST_CASE(MockSendCounterPacketTest) |
| 102 | { |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 103 | MockBufferManager mockBuffer(512); |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 104 | MockSendCounterPacket mockSendCounterPacket(mockBuffer); |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 105 | |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 106 | mockSendCounterPacket.SendStreamMetaDataPacket(); |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 107 | |
| 108 | auto packetBuffer = mockBuffer.GetReadableBuffer(); |
| 109 | const char* buffer = reinterpret_cast<const char*>(packetBuffer->GetReadableData()); |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 110 | |
| 111 | BOOST_TEST(strcmp(buffer, "SendStreamMetaDataPacket") == 0); |
| 112 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 113 | mockBuffer.MarkRead(packetBuffer); |
| 114 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 115 | CounterDirectory counterDirectory; |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 116 | mockSendCounterPacket.SendCounterDirectoryPacket(counterDirectory); |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 117 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 118 | packetBuffer = mockBuffer.GetReadableBuffer(); |
| 119 | buffer = reinterpret_cast<const char*>(packetBuffer->GetReadableData()); |
| 120 | |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 121 | BOOST_TEST(strcmp(buffer, "SendCounterDirectoryPacket") == 0); |
| 122 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 123 | mockBuffer.MarkRead(packetBuffer); |
| 124 | |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 125 | uint64_t timestamp = 0; |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 126 | std::vector<CounterValue> indexValuePairs; |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 127 | |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 128 | mockSendCounterPacket.SendPeriodicCounterCapturePacket(timestamp, indexValuePairs); |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 129 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 130 | packetBuffer = mockBuffer.GetReadableBuffer(); |
| 131 | buffer = reinterpret_cast<const char*>(packetBuffer->GetReadableData()); |
| 132 | |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 133 | BOOST_TEST(strcmp(buffer, "SendPeriodicCounterCapturePacket") == 0); |
| 134 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 135 | mockBuffer.MarkRead(packetBuffer); |
| 136 | |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 137 | uint32_t capturePeriod = 0; |
| 138 | std::vector<uint16_t> selectedCounterIds; |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 139 | mockSendCounterPacket.SendPeriodicCounterSelectionPacket(capturePeriod, selectedCounterIds); |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 140 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 141 | packetBuffer = mockBuffer.GetReadableBuffer(); |
| 142 | buffer = reinterpret_cast<const char*>(packetBuffer->GetReadableData()); |
| 143 | |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 144 | BOOST_TEST(strcmp(buffer, "SendPeriodicCounterSelectionPacket") == 0); |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 145 | |
| 146 | mockBuffer.MarkRead(packetBuffer); |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 147 | } |
| 148 | |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 149 | BOOST_AUTO_TEST_CASE(SendPeriodicCounterSelectionPacketTest) |
| 150 | { |
| 151 | // Error no space left in buffer |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 152 | MockBufferManager mockBuffer1(10); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 153 | SendCounterPacket sendPacket1(mockBuffer1); |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 154 | |
| 155 | uint32_t capturePeriod = 1000; |
| 156 | std::vector<uint16_t> selectedCounterIds; |
| 157 | BOOST_CHECK_THROW(sendPacket1.SendPeriodicCounterSelectionPacket(capturePeriod, selectedCounterIds), |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 158 | BufferExhaustion); |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 159 | |
| 160 | // Packet without any counters |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 161 | MockBufferManager mockBuffer2(512); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 162 | SendCounterPacket sendPacket2(mockBuffer2); |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 163 | |
| 164 | sendPacket2.SendPeriodicCounterSelectionPacket(capturePeriod, selectedCounterIds); |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 165 | auto readBuffer2 = mockBuffer2.GetReadableBuffer(); |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 166 | |
| 167 | uint32_t headerWord0 = ReadUint32(readBuffer2, 0); |
| 168 | uint32_t headerWord1 = ReadUint32(readBuffer2, 4); |
| 169 | uint32_t period = ReadUint32(readBuffer2, 8); |
| 170 | |
| 171 | BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0); // packet family |
| 172 | BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 4); // packet id |
| 173 | BOOST_TEST(headerWord1 == 4); // data lenght |
| 174 | BOOST_TEST(period == 1000); // capture period |
| 175 | |
| 176 | // Full packet message |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 177 | MockBufferManager mockBuffer3(512); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 178 | SendCounterPacket sendPacket3(mockBuffer3); |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 179 | |
| 180 | selectedCounterIds.reserve(5); |
| 181 | selectedCounterIds.emplace_back(100); |
| 182 | selectedCounterIds.emplace_back(200); |
| 183 | selectedCounterIds.emplace_back(300); |
| 184 | selectedCounterIds.emplace_back(400); |
| 185 | selectedCounterIds.emplace_back(500); |
| 186 | sendPacket3.SendPeriodicCounterSelectionPacket(capturePeriod, selectedCounterIds); |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 187 | auto readBuffer3 = mockBuffer3.GetReadableBuffer(); |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 188 | |
| 189 | headerWord0 = ReadUint32(readBuffer3, 0); |
| 190 | headerWord1 = ReadUint32(readBuffer3, 4); |
| 191 | period = ReadUint32(readBuffer3, 8); |
| 192 | |
| 193 | BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0); // packet family |
| 194 | BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 4); // packet id |
| 195 | BOOST_TEST(headerWord1 == 14); // data lenght |
| 196 | BOOST_TEST(period == 1000); // capture period |
| 197 | |
| 198 | uint16_t counterId = 0; |
| 199 | uint32_t offset = 12; |
| 200 | |
| 201 | // Counter Ids |
| 202 | for(const uint16_t& id : selectedCounterIds) |
| 203 | { |
| 204 | counterId = ReadUint16(readBuffer3, offset); |
| 205 | BOOST_TEST(counterId == id); |
| 206 | offset += 2; |
| 207 | } |
| 208 | } |
| 209 | |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 210 | BOOST_AUTO_TEST_CASE(SendPeriodicCounterCapturePacketTest) |
| 211 | { |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 212 | ProfilingStateMachine profilingStateMachine; |
| 213 | |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 214 | // Error no space left in buffer |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 215 | MockBufferManager mockBuffer1(10); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 216 | SendCounterPacket sendPacket1(mockBuffer1); |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 217 | |
| 218 | auto captureTimestamp = std::chrono::steady_clock::now(); |
| 219 | uint64_t time = static_cast<uint64_t >(captureTimestamp.time_since_epoch().count()); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 220 | std::vector<CounterValue> indexValuePairs; |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 221 | |
| 222 | BOOST_CHECK_THROW(sendPacket1.SendPeriodicCounterCapturePacket(time, indexValuePairs), |
| 223 | BufferExhaustion); |
| 224 | |
| 225 | // Packet without any counters |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 226 | MockBufferManager mockBuffer2(512); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 227 | SendCounterPacket sendPacket2(mockBuffer2); |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 228 | |
| 229 | sendPacket2.SendPeriodicCounterCapturePacket(time, indexValuePairs); |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 230 | auto readBuffer2 = mockBuffer2.GetReadableBuffer(); |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 231 | |
| 232 | uint32_t headerWord0 = ReadUint32(readBuffer2, 0); |
| 233 | uint32_t headerWord1 = ReadUint32(readBuffer2, 4); |
| 234 | uint64_t readTimestamp = ReadUint64(readBuffer2, 8); |
| 235 | |
Jim Flynn | fc36562 | 2019-12-04 10:07:20 +0000 | [diff] [blame] | 236 | BOOST_TEST(((headerWord0 >> 26) & 0x0000003F) == 3); // packet family |
Matteo Martincigh | 8d9590e | 2019-10-15 09:35:29 +0100 | [diff] [blame] | 237 | BOOST_TEST(((headerWord0 >> 19) & 0x0000007F) == 0); // packet class |
| 238 | BOOST_TEST(((headerWord0 >> 16) & 0x00000007) == 0); // packet type |
| 239 | BOOST_TEST(headerWord1 == 8); // data length |
| 240 | BOOST_TEST(time == readTimestamp); // capture period |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 241 | |
| 242 | // Full packet message |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 243 | MockBufferManager mockBuffer3(512); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 244 | SendCounterPacket sendPacket3(mockBuffer3); |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 245 | |
| 246 | indexValuePairs.reserve(5); |
Finn Williams | 032bc74 | 2020-02-12 11:02:34 +0000 | [diff] [blame] | 247 | indexValuePairs.emplace_back(CounterValue{0, 100}); |
| 248 | indexValuePairs.emplace_back(CounterValue{1, 200}); |
| 249 | indexValuePairs.emplace_back(CounterValue{2, 300}); |
| 250 | indexValuePairs.emplace_back(CounterValue{3, 400}); |
| 251 | indexValuePairs.emplace_back(CounterValue{4, 500}); |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 252 | sendPacket3.SendPeriodicCounterCapturePacket(time, indexValuePairs); |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 253 | auto readBuffer3 = mockBuffer3.GetReadableBuffer(); |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 254 | |
| 255 | headerWord0 = ReadUint32(readBuffer3, 0); |
| 256 | headerWord1 = ReadUint32(readBuffer3, 4); |
| 257 | uint64_t readTimestamp2 = ReadUint64(readBuffer3, 8); |
| 258 | |
Jim Flynn | fc36562 | 2019-12-04 10:07:20 +0000 | [diff] [blame] | 259 | BOOST_TEST(((headerWord0 >> 26) & 0x0000003F) == 3); // packet family |
Matteo Martincigh | 8d9590e | 2019-10-15 09:35:29 +0100 | [diff] [blame] | 260 | BOOST_TEST(((headerWord0 >> 19) & 0x0000007F) == 0); // packet class |
| 261 | BOOST_TEST(((headerWord0 >> 16) & 0x00000007) == 0); // packet type |
| 262 | BOOST_TEST(headerWord1 == 38); // data length |
| 263 | BOOST_TEST(time == readTimestamp2); // capture period |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 264 | |
| 265 | uint16_t counterIndex = 0; |
| 266 | uint32_t counterValue = 100; |
| 267 | uint32_t offset = 16; |
| 268 | |
| 269 | // Counter Ids |
| 270 | for (auto it = indexValuePairs.begin(), end = indexValuePairs.end(); it != end; ++it) |
| 271 | { |
| 272 | // Check Counter Index |
| 273 | uint16_t readIndex = ReadUint16(readBuffer3, offset); |
| 274 | BOOST_TEST(counterIndex == readIndex); |
| 275 | counterIndex++; |
| 276 | offset += 2; |
| 277 | |
| 278 | // Check Counter Value |
| 279 | uint32_t readValue = ReadUint32(readBuffer3, offset); |
| 280 | BOOST_TEST(counterValue == readValue); |
| 281 | counterValue += 100; |
| 282 | offset += 4; |
| 283 | } |
| 284 | |
| 285 | } |
| 286 | |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 287 | BOOST_AUTO_TEST_CASE(SendStreamMetaDataPacketTest) |
| 288 | { |
| 289 | using boost::numeric_cast; |
| 290 | |
| 291 | uint32_t sizeUint32 = numeric_cast<uint32_t>(sizeof(uint32_t)); |
| 292 | |
| 293 | // Error no space left in buffer |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 294 | MockBufferManager mockBuffer1(10); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 295 | SendCounterPacket sendPacket1(mockBuffer1); |
Matteo Martincigh | 149528e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 296 | BOOST_CHECK_THROW(sendPacket1.SendStreamMetaDataPacket(), armnn::profiling::BufferExhaustion); |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 297 | |
| 298 | // Full metadata packet |
| 299 | |
| 300 | std::string processName = GetProcessName().substr(0, 60); |
| 301 | |
Finn Williams | a0de056 | 2020-04-22 12:27:37 +0100 | [diff] [blame] | 302 | uint32_t infoSize = numeric_cast<uint32_t>(GetSoftwareInfo().size()) + 1; |
| 303 | uint32_t hardwareVersionSize = numeric_cast<uint32_t>(GetHardwareVersion().size()) + 1; |
| 304 | uint32_t softwareVersionSize = numeric_cast<uint32_t>(GetSoftwareVersion().size()) + 1; |
| 305 | uint32_t processNameSize = numeric_cast<uint32_t>(processName.size()) + 1; |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 306 | |
Ferran Balaguer | 5bf1d32 | 2019-09-13 13:31:40 +0100 | [diff] [blame] | 307 | uint32_t packetEntries = 6; |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 308 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 309 | MockBufferManager mockBuffer2(512); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 310 | SendCounterPacket sendPacket2(mockBuffer2); |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 311 | sendPacket2.SendStreamMetaDataPacket(); |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 312 | auto readBuffer2 = mockBuffer2.GetReadableBuffer(); |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 313 | |
| 314 | uint32_t headerWord0 = ReadUint32(readBuffer2, 0); |
| 315 | uint32_t headerWord1 = ReadUint32(readBuffer2, sizeUint32); |
| 316 | |
| 317 | BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0); // packet family |
| 318 | BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 0); // packet id |
| 319 | |
| 320 | uint32_t totalLength = numeric_cast<uint32_t>(2 * sizeUint32 + 10 * sizeUint32 + infoSize + hardwareVersionSize + |
| 321 | softwareVersionSize + processNameSize + sizeUint32 + |
| 322 | 2 * packetEntries * sizeUint32); |
| 323 | |
| 324 | BOOST_TEST(headerWord1 == totalLength - (2 * sizeUint32)); // data length |
| 325 | |
| 326 | uint32_t offset = sizeUint32 * 2; |
| 327 | BOOST_TEST(ReadUint32(readBuffer2, offset) == SendCounterPacket::PIPE_MAGIC); // pipe_magic |
| 328 | offset += sizeUint32; |
| 329 | BOOST_TEST(ReadUint32(readBuffer2, offset) == EncodeVersion(1, 0, 0)); // stream_metadata_version |
| 330 | offset += sizeUint32; |
Sadik Armagan | 7bbdf9d | 2019-10-24 10:26:05 +0100 | [diff] [blame] | 331 | BOOST_TEST(ReadUint32(readBuffer2, offset) == MAX_METADATA_PACKET_LENGTH); // max_data_len |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 332 | offset += sizeUint32; |
Rob Hughes | bdee426 | 2020-01-07 17:05:24 +0000 | [diff] [blame] | 333 | int pid = armnnUtils::Processes::GetCurrentId(); |
| 334 | BOOST_TEST(ReadUint32(readBuffer2, offset) == numeric_cast<uint32_t>(pid)); |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 335 | offset += sizeUint32; |
| 336 | uint32_t poolOffset = 10 * sizeUint32; |
Finn Williams | a0de056 | 2020-04-22 12:27:37 +0100 | [diff] [blame] | 337 | BOOST_TEST(ReadUint32(readBuffer2, offset) == poolOffset); // offset_info |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 338 | offset += sizeUint32; |
| 339 | poolOffset += infoSize; |
Finn Williams | a0de056 | 2020-04-22 12:27:37 +0100 | [diff] [blame] | 340 | BOOST_TEST(ReadUint32(readBuffer2, offset) == poolOffset); // offset_hw_version |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 341 | offset += sizeUint32; |
| 342 | poolOffset += hardwareVersionSize; |
Finn Williams | a0de056 | 2020-04-22 12:27:37 +0100 | [diff] [blame] | 343 | BOOST_TEST(ReadUint32(readBuffer2, offset) == poolOffset); // offset_sw_version |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 344 | offset += sizeUint32; |
| 345 | poolOffset += softwareVersionSize; |
Finn Williams | a0de056 | 2020-04-22 12:27:37 +0100 | [diff] [blame] | 346 | BOOST_TEST(ReadUint32(readBuffer2, offset) == poolOffset); // offset_process_name |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 347 | offset += sizeUint32; |
| 348 | poolOffset += processNameSize; |
Finn Williams | a0de056 | 2020-04-22 12:27:37 +0100 | [diff] [blame] | 349 | BOOST_TEST(ReadUint32(readBuffer2, offset) == poolOffset); // offset_packet_version_table |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 350 | offset += sizeUint32; |
| 351 | BOOST_TEST(ReadUint32(readBuffer2, offset) == 0); // reserved |
| 352 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 353 | const unsigned char* readData2 = readBuffer2->GetReadableData(); |
| 354 | |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 355 | offset += sizeUint32; |
| 356 | if (infoSize) |
| 357 | { |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 358 | BOOST_TEST(strcmp(reinterpret_cast<const char *>(&readData2[offset]), GetSoftwareInfo().c_str()) == 0); |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 359 | offset += infoSize; |
| 360 | } |
| 361 | |
| 362 | if (hardwareVersionSize) |
| 363 | { |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 364 | BOOST_TEST(strcmp(reinterpret_cast<const char *>(&readData2[offset]), GetHardwareVersion().c_str()) == 0); |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 365 | offset += hardwareVersionSize; |
| 366 | } |
| 367 | |
| 368 | if (softwareVersionSize) |
| 369 | { |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 370 | BOOST_TEST(strcmp(reinterpret_cast<const char *>(&readData2[offset]), GetSoftwareVersion().c_str()) == 0); |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 371 | offset += softwareVersionSize; |
| 372 | } |
| 373 | |
| 374 | if (processNameSize) |
| 375 | { |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 376 | BOOST_TEST(strcmp(reinterpret_cast<const char *>(&readData2[offset]), GetProcessName().c_str()) == 0); |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 377 | offset += processNameSize; |
| 378 | } |
| 379 | |
| 380 | if (packetEntries) |
| 381 | { |
| 382 | BOOST_TEST((ReadUint32(readBuffer2, offset) >> 16) == packetEntries); |
| 383 | offset += sizeUint32; |
Ferran Balaguer | 5bf1d32 | 2019-09-13 13:31:40 +0100 | [diff] [blame] | 384 | for (uint32_t i = 0; i < packetEntries - 1; ++i) |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 385 | { |
| 386 | BOOST_TEST(((ReadUint32(readBuffer2, offset) >> 26) & 0x3F) == 0); |
| 387 | BOOST_TEST(((ReadUint32(readBuffer2, offset) >> 16) & 0x3FF) == i); |
| 388 | offset += sizeUint32; |
| 389 | BOOST_TEST(ReadUint32(readBuffer2, offset) == EncodeVersion(1, 0, 0)); |
| 390 | offset += sizeUint32; |
| 391 | } |
Ferran Balaguer | 5bf1d32 | 2019-09-13 13:31:40 +0100 | [diff] [blame] | 392 | |
| 393 | BOOST_TEST(((ReadUint32(readBuffer2, offset) >> 26) & 0x3F) == 1); |
| 394 | BOOST_TEST(((ReadUint32(readBuffer2, offset) >> 16) & 0x3FF) == 0); |
| 395 | offset += sizeUint32; |
| 396 | BOOST_TEST(ReadUint32(readBuffer2, offset) == EncodeVersion(1, 0, 0)); |
| 397 | offset += sizeUint32; |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 398 | } |
| 399 | |
| 400 | BOOST_TEST(offset == totalLength); |
| 401 | } |
| 402 | |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 403 | BOOST_AUTO_TEST_CASE(CreateDeviceRecordTest) |
| 404 | { |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 405 | MockBufferManager mockBuffer(0); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 406 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 407 | |
| 408 | // Create a device for testing |
| 409 | uint16_t deviceUid = 27; |
| 410 | const std::string deviceName = "some_device"; |
| 411 | uint16_t deviceCores = 3; |
| 412 | const DevicePtr device = std::make_unique<Device>(deviceUid, deviceName, deviceCores); |
| 413 | |
| 414 | // Create a device record |
| 415 | SendCounterPacket::DeviceRecord deviceRecord; |
| 416 | std::string errorMessage; |
| 417 | bool result = sendCounterPacketTest.CreateDeviceRecordTest(device, deviceRecord, errorMessage); |
| 418 | |
| 419 | BOOST_CHECK(result); |
| 420 | BOOST_CHECK(errorMessage.empty()); |
| 421 | BOOST_CHECK(deviceRecord.size() == 6); // Size in words: header [2] + device name [4] |
| 422 | |
| 423 | uint16_t deviceRecordWord0[] |
| 424 | { |
| 425 | static_cast<uint16_t>(deviceRecord[0] >> 16), |
| 426 | static_cast<uint16_t>(deviceRecord[0]) |
| 427 | }; |
| 428 | BOOST_CHECK(deviceRecordWord0[0] == deviceUid); // uid |
| 429 | BOOST_CHECK(deviceRecordWord0[1] == deviceCores); // cores |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 430 | BOOST_CHECK(deviceRecord[1] == 2); // name_offset |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 431 | BOOST_CHECK(deviceRecord[2] == deviceName.size() + 1); // The length of the SWTrace string (name) |
| 432 | BOOST_CHECK(std::memcmp(deviceRecord.data() + 3, deviceName.data(), deviceName.size()) == 0); // name |
| 433 | } |
| 434 | |
| 435 | BOOST_AUTO_TEST_CASE(CreateInvalidDeviceRecordTest) |
| 436 | { |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 437 | MockBufferManager mockBuffer(0); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 438 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 439 | |
| 440 | // Create a device for testing |
| 441 | uint16_t deviceUid = 27; |
| 442 | const std::string deviceName = "some€£invalid‡device"; |
| 443 | uint16_t deviceCores = 3; |
| 444 | const DevicePtr device = std::make_unique<Device>(deviceUid, deviceName, deviceCores); |
| 445 | |
| 446 | // Create a device record |
| 447 | SendCounterPacket::DeviceRecord deviceRecord; |
| 448 | std::string errorMessage; |
| 449 | bool result = sendCounterPacketTest.CreateDeviceRecordTest(device, deviceRecord, errorMessage); |
| 450 | |
| 451 | BOOST_CHECK(!result); |
| 452 | BOOST_CHECK(!errorMessage.empty()); |
| 453 | BOOST_CHECK(deviceRecord.empty()); |
| 454 | } |
| 455 | |
| 456 | BOOST_AUTO_TEST_CASE(CreateCounterSetRecordTest) |
| 457 | { |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 458 | MockBufferManager mockBuffer(0); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 459 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 460 | |
| 461 | // Create a counter set for testing |
| 462 | uint16_t counterSetUid = 27; |
| 463 | const std::string counterSetName = "some_counter_set"; |
| 464 | uint16_t counterSetCount = 3421; |
| 465 | const CounterSetPtr counterSet = std::make_unique<CounterSet>(counterSetUid, counterSetName, counterSetCount); |
| 466 | |
| 467 | // Create a counter set record |
| 468 | SendCounterPacket::CounterSetRecord counterSetRecord; |
| 469 | std::string errorMessage; |
| 470 | bool result = sendCounterPacketTest.CreateCounterSetRecordTest(counterSet, counterSetRecord, errorMessage); |
| 471 | |
| 472 | BOOST_CHECK(result); |
| 473 | BOOST_CHECK(errorMessage.empty()); |
| 474 | BOOST_CHECK(counterSetRecord.size() == 8); // Size in words: header [2] + counter set name [6] |
| 475 | |
| 476 | uint16_t counterSetRecordWord0[] |
| 477 | { |
| 478 | static_cast<uint16_t>(counterSetRecord[0] >> 16), |
| 479 | static_cast<uint16_t>(counterSetRecord[0]) |
| 480 | }; |
| 481 | BOOST_CHECK(counterSetRecordWord0[0] == counterSetUid); // uid |
| 482 | BOOST_CHECK(counterSetRecordWord0[1] == counterSetCount); // cores |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 483 | BOOST_CHECK(counterSetRecord[1] == 2); // name_offset |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 484 | BOOST_CHECK(counterSetRecord[2] == counterSetName.size() + 1); // The length of the SWTrace string (name) |
| 485 | BOOST_CHECK(std::memcmp(counterSetRecord.data() + 3, counterSetName.data(), counterSetName.size()) == 0); // name |
| 486 | } |
| 487 | |
| 488 | BOOST_AUTO_TEST_CASE(CreateInvalidCounterSetRecordTest) |
| 489 | { |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 490 | MockBufferManager mockBuffer(0); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 491 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 492 | |
| 493 | // Create a counter set for testing |
| 494 | uint16_t counterSetUid = 27; |
| 495 | const std::string counterSetName = "some invalid_counter€£set"; |
| 496 | uint16_t counterSetCount = 3421; |
| 497 | const CounterSetPtr counterSet = std::make_unique<CounterSet>(counterSetUid, counterSetName, counterSetCount); |
| 498 | |
| 499 | // Create a counter set record |
| 500 | SendCounterPacket::CounterSetRecord counterSetRecord; |
| 501 | std::string errorMessage; |
| 502 | bool result = sendCounterPacketTest.CreateCounterSetRecordTest(counterSet, counterSetRecord, errorMessage); |
| 503 | |
| 504 | BOOST_CHECK(!result); |
| 505 | BOOST_CHECK(!errorMessage.empty()); |
| 506 | BOOST_CHECK(counterSetRecord.empty()); |
| 507 | } |
| 508 | |
| 509 | BOOST_AUTO_TEST_CASE(CreateEventRecordTest) |
| 510 | { |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 511 | MockBufferManager mockBuffer(0); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 512 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 513 | |
| 514 | // Create a counter for testing |
| 515 | uint16_t counterUid = 7256; |
| 516 | uint16_t maxCounterUid = 132; |
| 517 | uint16_t deviceUid = 132; |
| 518 | uint16_t counterSetUid = 4497; |
| 519 | uint16_t counterClass = 1; |
| 520 | uint16_t counterInterpolation = 1; |
| 521 | double counterMultiplier = 1234.567f; |
| 522 | const std::string counterName = "some_valid_counter"; |
| 523 | const std::string counterDescription = "a_counter_for_testing"; |
| 524 | const std::string counterUnits = "Mrads2"; |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 525 | const CounterPtr counter = std::make_unique<Counter>(armnn::profiling::BACKEND_ID, |
| 526 | counterUid, |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 527 | maxCounterUid, |
| 528 | counterClass, |
| 529 | counterInterpolation, |
| 530 | counterMultiplier, |
| 531 | counterName, |
| 532 | counterDescription, |
| 533 | counterUnits, |
| 534 | deviceUid, |
| 535 | counterSetUid); |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 536 | ARMNN_ASSERT(counter); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 537 | |
| 538 | // Create an event record |
| 539 | SendCounterPacket::EventRecord eventRecord; |
| 540 | std::string errorMessage; |
| 541 | bool result = sendCounterPacketTest.CreateEventRecordTest(counter, eventRecord, errorMessage); |
| 542 | |
| 543 | BOOST_CHECK(result); |
| 544 | BOOST_CHECK(errorMessage.empty()); |
| 545 | BOOST_CHECK(eventRecord.size() == 24); // Size in words: header [8] + counter name [6] + description [7] + units [3] |
| 546 | |
| 547 | uint16_t eventRecordWord0[] |
| 548 | { |
| 549 | static_cast<uint16_t>(eventRecord[0] >> 16), |
| 550 | static_cast<uint16_t>(eventRecord[0]) |
| 551 | }; |
| 552 | uint16_t eventRecordWord1[] |
| 553 | { |
| 554 | static_cast<uint16_t>(eventRecord[1] >> 16), |
| 555 | static_cast<uint16_t>(eventRecord[1]) |
| 556 | }; |
| 557 | uint16_t eventRecordWord2[] |
| 558 | { |
| 559 | static_cast<uint16_t>(eventRecord[2] >> 16), |
| 560 | static_cast<uint16_t>(eventRecord[2]) |
| 561 | }; |
| 562 | uint32_t eventRecordWord34[] |
| 563 | { |
| 564 | eventRecord[3], |
| 565 | eventRecord[4] |
| 566 | }; |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 567 | |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 568 | BOOST_CHECK(eventRecordWord0[0] == maxCounterUid); // max_counter_uid |
| 569 | BOOST_CHECK(eventRecordWord0[1] == counterUid); // counter_uid |
| 570 | BOOST_CHECK(eventRecordWord1[0] == deviceUid); // device |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 571 | |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 572 | BOOST_CHECK(eventRecordWord1[1] == counterSetUid); // counter_set |
| 573 | BOOST_CHECK(eventRecordWord2[0] == counterClass); // class |
| 574 | BOOST_CHECK(eventRecordWord2[1] == counterInterpolation); // interpolation |
| 575 | BOOST_CHECK(std::memcmp(eventRecordWord34, &counterMultiplier, sizeof(counterMultiplier)) == 0); // multiplier |
| 576 | |
| 577 | ARMNN_NO_CONVERSION_WARN_BEGIN |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 578 | uint32_t eventRecordBlockSize = 8u * sizeof(uint32_t); |
| 579 | uint32_t counterNameOffset = eventRecordBlockSize; // The name is the first item in pool |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 580 | uint32_t counterDescriptionOffset = counterNameOffset + // Counter name offset |
| 581 | 4u + // Counter name length (uint32_t) |
| 582 | counterName.size() + // 18u |
| 583 | 1u + // Null-terminator |
| 584 | 1u; // Rounding to the next word |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 585 | |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 586 | size_t counterUnitsOffset = counterDescriptionOffset + // Counter description offset |
| 587 | 4u + // Counter description length (uint32_t) |
| 588 | counterDescription.size() + // 21u |
| 589 | 1u + // Null-terminator |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 590 | 2u; // Rounding to the next word |
| 591 | |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 592 | ARMNN_NO_CONVERSION_WARN_END |
| 593 | |
| 594 | BOOST_CHECK(eventRecord[5] == counterNameOffset); // name_offset |
| 595 | BOOST_CHECK(eventRecord[6] == counterDescriptionOffset); // description_offset |
| 596 | BOOST_CHECK(eventRecord[7] == counterUnitsOffset); // units_offset |
| 597 | |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 598 | // Offsets are relative to the start of the eventRecord |
| 599 | auto eventRecordPool = reinterpret_cast<unsigned char*>(eventRecord.data()); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 600 | size_t uint32_t_size = sizeof(uint32_t); |
| 601 | |
| 602 | // The length of the SWTrace string (name) |
| 603 | BOOST_CHECK(eventRecordPool[counterNameOffset] == counterName.size() + 1); |
| 604 | // The counter name |
| 605 | BOOST_CHECK(std::memcmp(eventRecordPool + |
| 606 | counterNameOffset + // Offset |
| 607 | uint32_t_size /* The length of the name */, |
| 608 | counterName.data(), |
| 609 | counterName.size()) == 0); // name |
| 610 | // The null-terminator at the end of the name |
| 611 | BOOST_CHECK(eventRecordPool[counterNameOffset + uint32_t_size + counterName.size()] == '\0'); |
| 612 | |
| 613 | // The length of the SWTrace string (description) |
| 614 | BOOST_CHECK(eventRecordPool[counterDescriptionOffset] == counterDescription.size() + 1); |
| 615 | // The counter description |
| 616 | BOOST_CHECK(std::memcmp(eventRecordPool + |
| 617 | counterDescriptionOffset + // Offset |
| 618 | uint32_t_size /* The length of the description */, |
| 619 | counterDescription.data(), |
| 620 | counterDescription.size()) == 0); // description |
| 621 | // The null-terminator at the end of the description |
| 622 | BOOST_CHECK(eventRecordPool[counterDescriptionOffset + uint32_t_size + counterDescription.size()] == '\0'); |
| 623 | |
| 624 | // The length of the SWTrace namestring (units) |
| 625 | BOOST_CHECK(eventRecordPool[counterUnitsOffset] == counterUnits.size() + 1); |
| 626 | // The counter units |
| 627 | BOOST_CHECK(std::memcmp(eventRecordPool + |
| 628 | counterUnitsOffset + // Offset |
| 629 | uint32_t_size /* The length of the units */, |
| 630 | counterUnits.data(), |
| 631 | counterUnits.size()) == 0); // units |
| 632 | // The null-terminator at the end of the units |
| 633 | BOOST_CHECK(eventRecordPool[counterUnitsOffset + uint32_t_size + counterUnits.size()] == '\0'); |
| 634 | } |
| 635 | |
| 636 | BOOST_AUTO_TEST_CASE(CreateEventRecordNoUnitsTest) |
| 637 | { |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 638 | MockBufferManager mockBuffer(0); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 639 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 640 | |
| 641 | // Create a counter for testing |
| 642 | uint16_t counterUid = 44312; |
| 643 | uint16_t maxCounterUid = 345; |
| 644 | uint16_t deviceUid = 101; |
| 645 | uint16_t counterSetUid = 34035; |
| 646 | uint16_t counterClass = 0; |
| 647 | uint16_t counterInterpolation = 1; |
| 648 | double counterMultiplier = 4435.0023f; |
| 649 | const std::string counterName = "some_valid_counter"; |
| 650 | const std::string counterDescription = "a_counter_for_testing"; |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 651 | const CounterPtr counter = std::make_unique<Counter>(armnn::profiling::BACKEND_ID, |
| 652 | counterUid, |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 653 | maxCounterUid, |
| 654 | counterClass, |
| 655 | counterInterpolation, |
| 656 | counterMultiplier, |
| 657 | counterName, |
| 658 | counterDescription, |
| 659 | "", |
| 660 | deviceUid, |
| 661 | counterSetUid); |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 662 | ARMNN_ASSERT(counter); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 663 | |
| 664 | // Create an event record |
| 665 | SendCounterPacket::EventRecord eventRecord; |
| 666 | std::string errorMessage; |
| 667 | bool result = sendCounterPacketTest.CreateEventRecordTest(counter, eventRecord, errorMessage); |
| 668 | |
| 669 | BOOST_CHECK(result); |
| 670 | BOOST_CHECK(errorMessage.empty()); |
| 671 | BOOST_CHECK(eventRecord.size() == 21); // Size in words: header [8] + counter name [6] + description [7] |
| 672 | |
| 673 | uint16_t eventRecordWord0[] |
| 674 | { |
| 675 | static_cast<uint16_t>(eventRecord[0] >> 16), |
| 676 | static_cast<uint16_t>(eventRecord[0]) |
| 677 | }; |
| 678 | uint16_t eventRecordWord1[] |
| 679 | { |
| 680 | static_cast<uint16_t>(eventRecord[1] >> 16), |
| 681 | static_cast<uint16_t>(eventRecord[1]) |
| 682 | }; |
| 683 | uint16_t eventRecordWord2[] |
| 684 | { |
| 685 | static_cast<uint16_t>(eventRecord[2] >> 16), |
| 686 | static_cast<uint16_t>(eventRecord[2]) |
| 687 | }; |
| 688 | uint32_t eventRecordWord34[] |
| 689 | { |
| 690 | eventRecord[3], |
| 691 | eventRecord[4] |
| 692 | }; |
| 693 | BOOST_CHECK(eventRecordWord0[0] == maxCounterUid); // max_counter_uid |
| 694 | BOOST_CHECK(eventRecordWord0[1] == counterUid); // counter_uid |
| 695 | BOOST_CHECK(eventRecordWord1[0] == deviceUid); // device |
| 696 | BOOST_CHECK(eventRecordWord1[1] == counterSetUid); // counter_set |
| 697 | BOOST_CHECK(eventRecordWord2[0] == counterClass); // class |
| 698 | BOOST_CHECK(eventRecordWord2[1] == counterInterpolation); // interpolation |
| 699 | BOOST_CHECK(std::memcmp(eventRecordWord34, &counterMultiplier, sizeof(counterMultiplier)) == 0); // multiplier |
| 700 | |
| 701 | ARMNN_NO_CONVERSION_WARN_BEGIN |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 702 | uint32_t eventRecordBlockSize = 8u * sizeof(uint32_t); |
| 703 | uint32_t counterNameOffset = eventRecordBlockSize; // The name is the first item in pool |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 704 | uint32_t counterDescriptionOffset = counterNameOffset + // Counter name offset |
| 705 | 4u + // Counter name length (uint32_t) |
| 706 | counterName.size() + // 18u |
| 707 | 1u + // Null-terminator |
| 708 | 1u; // Rounding to the next word |
| 709 | ARMNN_NO_CONVERSION_WARN_END |
| 710 | |
| 711 | BOOST_CHECK(eventRecord[5] == counterNameOffset); // name_offset |
| 712 | BOOST_CHECK(eventRecord[6] == counterDescriptionOffset); // description_offset |
| 713 | BOOST_CHECK(eventRecord[7] == 0); // units_offset |
| 714 | |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 715 | // Offsets are relative to the start of the eventRecord |
| 716 | auto eventRecordPool = reinterpret_cast<unsigned char*>(eventRecord.data()); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 717 | size_t uint32_t_size = sizeof(uint32_t); |
| 718 | |
| 719 | // The length of the SWTrace string (name) |
| 720 | BOOST_CHECK(eventRecordPool[counterNameOffset] == counterName.size() + 1); |
| 721 | // The counter name |
| 722 | BOOST_CHECK(std::memcmp(eventRecordPool + |
| 723 | counterNameOffset + // Offset |
| 724 | uint32_t_size, // The length of the name |
| 725 | counterName.data(), |
| 726 | counterName.size()) == 0); // name |
| 727 | // The null-terminator at the end of the name |
| 728 | BOOST_CHECK(eventRecordPool[counterNameOffset + uint32_t_size + counterName.size()] == '\0'); |
| 729 | |
| 730 | // The length of the SWTrace string (description) |
| 731 | BOOST_CHECK(eventRecordPool[counterDescriptionOffset] == counterDescription.size() + 1); |
| 732 | // The counter description |
| 733 | BOOST_CHECK(std::memcmp(eventRecordPool + |
| 734 | counterDescriptionOffset + // Offset |
| 735 | uint32_t_size, // The length of the description |
| 736 | counterDescription.data(), |
| 737 | counterDescription.size()) == 0); // description |
| 738 | // The null-terminator at the end of the description |
| 739 | BOOST_CHECK(eventRecordPool[counterDescriptionOffset + uint32_t_size + counterDescription.size()] == '\0'); |
| 740 | } |
| 741 | |
| 742 | BOOST_AUTO_TEST_CASE(CreateInvalidEventRecordTest1) |
| 743 | { |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 744 | MockBufferManager mockBuffer(0); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 745 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 746 | |
| 747 | // Create a counter for testing |
| 748 | uint16_t counterUid = 7256; |
| 749 | uint16_t maxCounterUid = 132; |
| 750 | uint16_t deviceUid = 132; |
| 751 | uint16_t counterSetUid = 4497; |
| 752 | uint16_t counterClass = 1; |
| 753 | uint16_t counterInterpolation = 1; |
| 754 | double counterMultiplier = 1234.567f; |
| 755 | const std::string counterName = "some_invalid_counter £££"; // Invalid name |
| 756 | const std::string counterDescription = "a_counter_for_testing"; |
| 757 | const std::string counterUnits = "Mrads2"; |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 758 | const CounterPtr counter = std::make_unique<Counter>(armnn::profiling::BACKEND_ID, |
| 759 | counterUid, |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 760 | maxCounterUid, |
| 761 | counterClass, |
| 762 | counterInterpolation, |
| 763 | counterMultiplier, |
| 764 | counterName, |
| 765 | counterDescription, |
| 766 | counterUnits, |
| 767 | deviceUid, |
| 768 | counterSetUid); |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 769 | ARMNN_ASSERT(counter); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 770 | |
| 771 | // Create an event record |
| 772 | SendCounterPacket::EventRecord eventRecord; |
| 773 | std::string errorMessage; |
| 774 | bool result = sendCounterPacketTest.CreateEventRecordTest(counter, eventRecord, errorMessage); |
| 775 | |
| 776 | BOOST_CHECK(!result); |
| 777 | BOOST_CHECK(!errorMessage.empty()); |
| 778 | BOOST_CHECK(eventRecord.empty()); |
| 779 | } |
| 780 | |
| 781 | BOOST_AUTO_TEST_CASE(CreateInvalidEventRecordTest2) |
| 782 | { |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 783 | MockBufferManager mockBuffer(0); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 784 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 785 | |
| 786 | // Create a counter for testing |
| 787 | uint16_t counterUid = 7256; |
| 788 | uint16_t maxCounterUid = 132; |
| 789 | uint16_t deviceUid = 132; |
| 790 | uint16_t counterSetUid = 4497; |
| 791 | uint16_t counterClass = 1; |
| 792 | uint16_t counterInterpolation = 1; |
| 793 | double counterMultiplier = 1234.567f; |
| 794 | const std::string counterName = "some_invalid_counter"; |
| 795 | const std::string counterDescription = "an invalid d€scription"; // Invalid description |
| 796 | const std::string counterUnits = "Mrads2"; |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 797 | const CounterPtr counter = std::make_unique<Counter>(armnn::profiling::BACKEND_ID, |
| 798 | counterUid, |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 799 | maxCounterUid, |
| 800 | counterClass, |
| 801 | counterInterpolation, |
| 802 | counterMultiplier, |
| 803 | counterName, |
| 804 | counterDescription, |
| 805 | counterUnits, |
| 806 | deviceUid, |
| 807 | counterSetUid); |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 808 | ARMNN_ASSERT(counter); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 809 | |
| 810 | // Create an event record |
| 811 | SendCounterPacket::EventRecord eventRecord; |
| 812 | std::string errorMessage; |
| 813 | bool result = sendCounterPacketTest.CreateEventRecordTest(counter, eventRecord, errorMessage); |
| 814 | |
| 815 | BOOST_CHECK(!result); |
| 816 | BOOST_CHECK(!errorMessage.empty()); |
| 817 | BOOST_CHECK(eventRecord.empty()); |
| 818 | } |
| 819 | |
| 820 | BOOST_AUTO_TEST_CASE(CreateInvalidEventRecordTest3) |
| 821 | { |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 822 | MockBufferManager mockBuffer(0); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 823 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 824 | |
| 825 | // Create a counter for testing |
| 826 | uint16_t counterUid = 7256; |
| 827 | uint16_t maxCounterUid = 132; |
| 828 | uint16_t deviceUid = 132; |
| 829 | uint16_t counterSetUid = 4497; |
| 830 | uint16_t counterClass = 1; |
| 831 | uint16_t counterInterpolation = 1; |
| 832 | double counterMultiplier = 1234.567f; |
| 833 | const std::string counterName = "some_invalid_counter"; |
| 834 | const std::string counterDescription = "a valid description"; |
| 835 | const std::string counterUnits = "Mrad s2"; // Invalid units |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 836 | const CounterPtr counter = std::make_unique<Counter>(armnn::profiling::BACKEND_ID, |
| 837 | counterUid, |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 838 | maxCounterUid, |
| 839 | counterClass, |
| 840 | counterInterpolation, |
| 841 | counterMultiplier, |
| 842 | counterName, |
| 843 | counterDescription, |
| 844 | counterUnits, |
| 845 | deviceUid, |
| 846 | counterSetUid); |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 847 | ARMNN_ASSERT(counter); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 848 | |
| 849 | // Create an event record |
| 850 | SendCounterPacket::EventRecord eventRecord; |
| 851 | std::string errorMessage; |
| 852 | bool result = sendCounterPacketTest.CreateEventRecordTest(counter, eventRecord, errorMessage); |
| 853 | |
| 854 | BOOST_CHECK(!result); |
| 855 | BOOST_CHECK(!errorMessage.empty()); |
| 856 | BOOST_CHECK(eventRecord.empty()); |
| 857 | } |
| 858 | |
| 859 | BOOST_AUTO_TEST_CASE(CreateCategoryRecordTest) |
| 860 | { |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 861 | MockBufferManager mockBuffer(0); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 862 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 863 | |
| 864 | // Create a category for testing |
| 865 | const std::string categoryName = "some_category"; |
Sadik Armagan | 4c99899 | 2020-02-25 12:44:44 +0000 | [diff] [blame] | 866 | const CategoryPtr category = std::make_unique<Category>(categoryName); |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 867 | ARMNN_ASSERT(category); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 868 | category->m_Counters = { 11u, 23u, 5670u }; |
| 869 | |
| 870 | // Create a collection of counters |
| 871 | Counters counters; |
| 872 | counters.insert(std::make_pair<uint16_t, CounterPtr>(11, |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 873 | CounterPtr(new Counter(armnn::profiling::BACKEND_ID, |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 874 | 0, |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 875 | 11, |
| 876 | 0, |
| 877 | 0, |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 878 | 534.0003f, |
| 879 | "counter1", |
| 880 | "the first counter", |
| 881 | "millipi2", |
| 882 | 0, |
| 883 | 0)))); |
| 884 | counters.insert(std::make_pair<uint16_t, CounterPtr>(23, |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 885 | CounterPtr(new Counter(armnn::profiling::BACKEND_ID, |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 886 | 1, |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 887 | 23, |
| 888 | 0, |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 889 | 1, |
| 890 | 534.0003f, |
| 891 | "this is counter 2", |
| 892 | "the second counter", |
| 893 | "", |
| 894 | 0, |
| 895 | 0)))); |
| 896 | counters.insert(std::make_pair<uint16_t, CounterPtr>(5670, |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 897 | CounterPtr(new Counter(armnn::profiling::BACKEND_ID, |
| 898 | 2, |
| 899 | 5670, |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 900 | 0, |
| 901 | 0, |
| 902 | 534.0003f, |
| 903 | "and this is number 3", |
| 904 | "the third counter", |
| 905 | "blah_per_second", |
| 906 | 0, |
| 907 | 0)))); |
| 908 | Counter* counter1 = counters.find(11)->second.get(); |
| 909 | Counter* counter2 = counters.find(23)->second.get(); |
| 910 | Counter* counter3 = counters.find(5670)->second.get(); |
Narumol Prangnawarat | ac2770a | 2020-04-01 16:51:23 +0100 | [diff] [blame] | 911 | ARMNN_ASSERT(counter1); |
| 912 | ARMNN_ASSERT(counter2); |
| 913 | ARMNN_ASSERT(counter3); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 914 | uint16_t categoryEventCount = boost::numeric_cast<uint16_t>(counters.size()); |
| 915 | |
| 916 | // Create a category record |
| 917 | SendCounterPacket::CategoryRecord categoryRecord; |
| 918 | std::string errorMessage; |
| 919 | bool result = sendCounterPacketTest.CreateCategoryRecordTest(category, counters, categoryRecord, errorMessage); |
| 920 | |
| 921 | BOOST_CHECK(result); |
| 922 | BOOST_CHECK(errorMessage.empty()); |
Sadik Armagan | 4c99899 | 2020-02-25 12:44:44 +0000 | [diff] [blame] | 923 | BOOST_CHECK(categoryRecord.size() == 79); // Size in words: header [3] + event pointer table [3] + |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 924 | // category name [5] + event records [68 = 22 + 20 + 26] |
| 925 | |
Sadik Armagan | 4c99899 | 2020-02-25 12:44:44 +0000 | [diff] [blame] | 926 | uint16_t categoryRecordWord1[] |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 927 | { |
| 928 | static_cast<uint16_t>(categoryRecord[0] >> 16), |
| 929 | static_cast<uint16_t>(categoryRecord[0]) |
| 930 | }; |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 931 | BOOST_CHECK(categoryRecordWord1[0] == categoryEventCount); // event_count |
| 932 | BOOST_CHECK(categoryRecordWord1[1] == 0); // reserved |
| 933 | |
| 934 | size_t uint32_t_size = sizeof(uint32_t); |
| 935 | |
| 936 | ARMNN_NO_CONVERSION_WARN_BEGIN |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 937 | uint32_t categoryRecordBlockSize = 3u * uint32_t_size; |
| 938 | uint32_t eventPointerTableOffset = categoryRecordBlockSize; // The event pointer table is the first item in pool |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 939 | uint32_t categoryNameOffset = eventPointerTableOffset + // Event pointer table offset |
| 940 | categoryEventCount * uint32_t_size; // The size of the event pointer table |
| 941 | ARMNN_NO_CONVERSION_WARN_END |
| 942 | |
Sadik Armagan | 4c99899 | 2020-02-25 12:44:44 +0000 | [diff] [blame] | 943 | BOOST_CHECK(categoryRecord[1] == eventPointerTableOffset); // event_pointer_table_offset |
| 944 | BOOST_CHECK(categoryRecord[2] == categoryNameOffset); // name_offset |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 945 | // Offsets are relative to the start of the category record |
| 946 | auto categoryRecordPool = reinterpret_cast<unsigned char*>(categoryRecord.data()); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 947 | |
| 948 | // The event pointer table |
| 949 | uint32_t eventRecord0Offset = categoryRecordPool[eventPointerTableOffset + 0 * uint32_t_size]; |
| 950 | uint32_t eventRecord1Offset = categoryRecordPool[eventPointerTableOffset + 1 * uint32_t_size]; |
| 951 | uint32_t eventRecord2Offset = categoryRecordPool[eventPointerTableOffset + 2 * uint32_t_size]; |
| 952 | BOOST_CHECK(eventRecord0Offset == 32); |
| 953 | BOOST_CHECK(eventRecord1Offset == 120); |
| 954 | BOOST_CHECK(eventRecord2Offset == 200); |
| 955 | |
| 956 | // The length of the SWTrace namestring (name) |
| 957 | BOOST_CHECK(categoryRecordPool[categoryNameOffset] == categoryName.size() + 1); |
| 958 | // The category name |
| 959 | BOOST_CHECK(std::memcmp(categoryRecordPool + |
| 960 | categoryNameOffset + // Offset |
| 961 | uint32_t_size, // The length of the name |
| 962 | categoryName.data(), |
| 963 | categoryName.size()) == 0); // name |
| 964 | // The null-terminator at the end of the name |
| 965 | BOOST_CHECK(categoryRecordPool[categoryNameOffset + uint32_t_size + categoryName.size()] == '\0'); |
| 966 | |
| 967 | // For brevity, checking only the UIDs, max counter UIDs and names of the counters in the event records, |
| 968 | // as the event records already have a number of unit tests dedicated to them |
| 969 | |
| 970 | // Counter1 UID and max counter UID |
| 971 | uint16_t eventRecord0Word0[2] = { 0u, 0u }; |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 972 | std::memcpy(eventRecord0Word0, categoryRecordPool + categoryRecordBlockSize + eventRecord0Offset, |
| 973 | sizeof(eventRecord0Word0)); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 974 | BOOST_CHECK(eventRecord0Word0[0] == counter1->m_Uid); |
| 975 | BOOST_CHECK(eventRecord0Word0[1] == counter1->m_MaxCounterUid); |
| 976 | |
| 977 | // Counter1 name |
| 978 | uint32_t counter1NameOffset = 0; |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 979 | std::memcpy(&counter1NameOffset, categoryRecordPool + eventRecord0Offset + 5u * uint32_t_size, uint32_t_size); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 980 | BOOST_CHECK(counter1NameOffset == 0); |
| 981 | // The length of the SWTrace string (name) |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 982 | BOOST_CHECK(categoryRecordPool[eventRecord0Offset + // Offset to the event record |
| 983 | categoryRecordBlockSize + // Offset to the end of the category record block |
| 984 | 8u * uint32_t_size + // Offset to the event record pool |
| 985 | counter1NameOffset // Offset to the name of the counter |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 986 | ] == counter1->m_Name.size() + 1); // The length of the name including the |
| 987 | // null-terminator |
| 988 | // The counter1 name |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 989 | BOOST_CHECK(std::memcmp(categoryRecordPool + // The beginning of the category pool |
| 990 | categoryRecordBlockSize + // Offset to the end of the category record block |
| 991 | eventRecord0Offset + // Offset to the event record |
| 992 | 8u * uint32_t_size + // Offset to the event record pool |
| 993 | counter1NameOffset + // Offset to the name of the counter |
| 994 | uint32_t_size, // The length of the name |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 995 | counter1->m_Name.data(), |
| 996 | counter1->m_Name.size()) == 0); // name |
| 997 | // The null-terminator at the end of the counter1 name |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 998 | BOOST_CHECK(categoryRecordPool[eventRecord0Offset + // Offset to the event record |
| 999 | categoryRecordBlockSize + // Offset to the end of the category record block |
| 1000 | 8u * uint32_t_size + // Offset to the event record pool |
| 1001 | counter1NameOffset + // Offset to the name of the counter |
| 1002 | uint32_t_size + // The length of the name |
| 1003 | counter1->m_Name.size() // The name of the counter |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1004 | ] == '\0'); |
| 1005 | |
| 1006 | // Counter2 name |
| 1007 | uint32_t counter2NameOffset = 0; |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1008 | std::memcpy(&counter2NameOffset, categoryRecordPool + |
| 1009 | categoryRecordBlockSize + |
| 1010 | eventRecord1Offset + |
| 1011 | 5u * uint32_t_size, |
| 1012 | uint32_t_size); |
| 1013 | BOOST_CHECK(counter2NameOffset == 8u * uint32_t_size ); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1014 | // The length of the SWTrace string (name) |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1015 | |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1016 | BOOST_CHECK(categoryRecordPool[eventRecord1Offset + // Offset to the event record |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1017 | categoryRecordBlockSize + |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1018 | counter2NameOffset // Offset to the name of the counter |
| 1019 | ] == counter2->m_Name.size() + 1); // The length of the name including the |
| 1020 | // null-terminator |
| 1021 | // The counter2 name |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1022 | BOOST_CHECK(std::memcmp(categoryRecordPool + // The beginning of the category pool |
| 1023 | categoryRecordBlockSize + // Offset to the end of the category record block |
| 1024 | eventRecord1Offset + // Offset to the event record |
| 1025 | counter2NameOffset + // Offset to the name of the counter |
| 1026 | uint32_t_size, // The length of the name |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1027 | counter2->m_Name.data(), |
| 1028 | counter2->m_Name.size()) == 0); // name |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1029 | |
| 1030 | |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1031 | // The null-terminator at the end of the counter2 name |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1032 | BOOST_CHECK(categoryRecordPool[eventRecord1Offset + // Offset to the event record |
| 1033 | categoryRecordBlockSize + // Offset to the end of the category record block |
| 1034 | counter2NameOffset + // Offset to the name of the counter |
| 1035 | uint32_t_size + // The length of the name |
| 1036 | counter2->m_Name.size() // The name of the counter |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1037 | ] == '\0'); |
| 1038 | |
| 1039 | // Counter3 name |
| 1040 | uint32_t counter3NameOffset = 0; |
| 1041 | std::memcpy(&counter3NameOffset, categoryRecordPool + eventRecord2Offset + 5u * uint32_t_size, uint32_t_size); |
| 1042 | BOOST_CHECK(counter3NameOffset == 0); |
| 1043 | // The length of the SWTrace string (name) |
| 1044 | BOOST_CHECK(categoryRecordPool[eventRecord2Offset + // Offset to the event record |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1045 | categoryRecordBlockSize + |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1046 | 8u * uint32_t_size + // Offset to the event record pool |
| 1047 | counter3NameOffset // Offset to the name of the counter |
| 1048 | ] == counter3->m_Name.size() + 1); // The length of the name including the |
| 1049 | // null-terminator |
| 1050 | // The counter3 name |
| 1051 | BOOST_CHECK(std::memcmp(categoryRecordPool + // The beginning of the category pool |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1052 | categoryRecordBlockSize + |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1053 | eventRecord2Offset + // Offset to the event record |
| 1054 | 8u * uint32_t_size + // Offset to the event record pool |
| 1055 | counter3NameOffset + // Offset to the name of the counter |
| 1056 | uint32_t_size, // The length of the name |
| 1057 | counter3->m_Name.data(), |
| 1058 | counter3->m_Name.size()) == 0); // name |
| 1059 | // The null-terminator at the end of the counter3 name |
| 1060 | BOOST_CHECK(categoryRecordPool[eventRecord2Offset + // Offset to the event record |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1061 | categoryRecordBlockSize + |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1062 | 8u * uint32_t_size + // Offset to the event record pool |
| 1063 | counter3NameOffset + // Offset to the name of the counter |
| 1064 | uint32_t_size + // The length of the name |
| 1065 | counter3->m_Name.size() // The name of the counter |
| 1066 | ] == '\0'); |
| 1067 | } |
| 1068 | |
| 1069 | BOOST_AUTO_TEST_CASE(CreateInvalidCategoryRecordTest1) |
| 1070 | { |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1071 | MockBufferManager mockBuffer(0); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1072 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1073 | |
| 1074 | // Create a category for testing |
| 1075 | const std::string categoryName = "some invalid category"; |
Sadik Armagan | 4c99899 | 2020-02-25 12:44:44 +0000 | [diff] [blame] | 1076 | const CategoryPtr category = std::make_unique<Category>(categoryName); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1077 | BOOST_CHECK(category); |
| 1078 | |
| 1079 | // Create a category record |
| 1080 | Counters counters; |
| 1081 | SendCounterPacket::CategoryRecord categoryRecord; |
| 1082 | std::string errorMessage; |
| 1083 | bool result = sendCounterPacketTest.CreateCategoryRecordTest(category, counters, categoryRecord, errorMessage); |
| 1084 | |
| 1085 | BOOST_CHECK(!result); |
| 1086 | BOOST_CHECK(!errorMessage.empty()); |
| 1087 | BOOST_CHECK(categoryRecord.empty()); |
| 1088 | } |
| 1089 | |
| 1090 | BOOST_AUTO_TEST_CASE(CreateInvalidCategoryRecordTest2) |
| 1091 | { |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1092 | MockBufferManager mockBuffer(0); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1093 | SendCounterPacketTest sendCounterPacketTest(mockBuffer); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1094 | |
| 1095 | // Create a category for testing |
| 1096 | const std::string categoryName = "some_category"; |
Sadik Armagan | 4c99899 | 2020-02-25 12:44:44 +0000 | [diff] [blame] | 1097 | const CategoryPtr category = std::make_unique<Category>(categoryName); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1098 | BOOST_CHECK(category); |
| 1099 | category->m_Counters = { 11u, 23u, 5670u }; |
| 1100 | |
| 1101 | // Create a collection of counters |
| 1102 | Counters counters; |
| 1103 | counters.insert(std::make_pair<uint16_t, CounterPtr>(11, |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1104 | CounterPtr(new Counter(armnn::profiling::BACKEND_ID, |
| 1105 | 11, |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1106 | 1234, |
| 1107 | 0, |
| 1108 | 1, |
| 1109 | 534.0003f, |
| 1110 | "count€r1", // Invalid name |
| 1111 | "the first counter", |
| 1112 | "millipi2", |
| 1113 | 0, |
| 1114 | 0)))); |
| 1115 | |
| 1116 | Counter* counter1 = counters.find(11)->second.get(); |
| 1117 | BOOST_CHECK(counter1); |
| 1118 | |
| 1119 | // Create a category record |
| 1120 | SendCounterPacket::CategoryRecord categoryRecord; |
| 1121 | std::string errorMessage; |
| 1122 | bool result = sendCounterPacketTest.CreateCategoryRecordTest(category, counters, categoryRecord, errorMessage); |
| 1123 | |
| 1124 | BOOST_CHECK(!result); |
| 1125 | BOOST_CHECK(!errorMessage.empty()); |
| 1126 | BOOST_CHECK(categoryRecord.empty()); |
| 1127 | } |
| 1128 | |
| 1129 | BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest1) |
| 1130 | { |
| 1131 | // The counter directory used for testing |
| 1132 | CounterDirectory counterDirectory; |
| 1133 | |
| 1134 | // Register a device |
| 1135 | const std::string device1Name = "device1"; |
| 1136 | const Device* device1 = nullptr; |
| 1137 | BOOST_CHECK_NO_THROW(device1 = counterDirectory.RegisterDevice(device1Name, 3)); |
| 1138 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 1139 | BOOST_CHECK(device1); |
| 1140 | |
| 1141 | // Register a device |
| 1142 | const std::string device2Name = "device2"; |
| 1143 | const Device* device2 = nullptr; |
| 1144 | BOOST_CHECK_NO_THROW(device2 = counterDirectory.RegisterDevice(device2Name)); |
| 1145 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 2); |
| 1146 | BOOST_CHECK(device2); |
| 1147 | |
| 1148 | // Buffer with not enough space |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1149 | MockBufferManager mockBuffer(10); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1150 | SendCounterPacket sendCounterPacket(mockBuffer); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1151 | BOOST_CHECK_THROW(sendCounterPacket.SendCounterDirectoryPacket(counterDirectory), |
| 1152 | armnn::profiling::BufferExhaustion); |
| 1153 | } |
| 1154 | |
| 1155 | BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest2) |
| 1156 | { |
| 1157 | // The counter directory used for testing |
| 1158 | CounterDirectory counterDirectory; |
| 1159 | |
| 1160 | // Register a device |
| 1161 | const std::string device1Name = "device1"; |
| 1162 | const Device* device1 = nullptr; |
| 1163 | BOOST_CHECK_NO_THROW(device1 = counterDirectory.RegisterDevice(device1Name, 3)); |
| 1164 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 1165 | BOOST_CHECK(device1); |
| 1166 | |
| 1167 | // Register a device |
| 1168 | const std::string device2Name = "device2"; |
| 1169 | const Device* device2 = nullptr; |
| 1170 | BOOST_CHECK_NO_THROW(device2 = counterDirectory.RegisterDevice(device2Name)); |
| 1171 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 2); |
| 1172 | BOOST_CHECK(device2); |
| 1173 | |
| 1174 | // Register a counter set |
| 1175 | const std::string counterSet1Name = "counterset1"; |
| 1176 | const CounterSet* counterSet1 = nullptr; |
| 1177 | BOOST_CHECK_NO_THROW(counterSet1 = counterDirectory.RegisterCounterSet(counterSet1Name)); |
| 1178 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1); |
| 1179 | BOOST_CHECK(counterSet1); |
| 1180 | |
| 1181 | // Register a category associated to "device1" and "counterset1" |
| 1182 | const std::string category1Name = "category1"; |
| 1183 | const Category* category1 = nullptr; |
Sadik Armagan | 4c99899 | 2020-02-25 12:44:44 +0000 | [diff] [blame] | 1184 | BOOST_CHECK_NO_THROW(category1 = counterDirectory.RegisterCategory(category1Name)); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1185 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 1186 | BOOST_CHECK(category1); |
| 1187 | |
| 1188 | // Register a category not associated to "device2" but no counter set |
| 1189 | const std::string category2Name = "category2"; |
| 1190 | const Category* category2 = nullptr; |
Sadik Armagan | 4c99899 | 2020-02-25 12:44:44 +0000 | [diff] [blame] | 1191 | BOOST_CHECK_NO_THROW(category2 = counterDirectory.RegisterCategory(category2Name)); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1192 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 2); |
| 1193 | BOOST_CHECK(category2); |
| 1194 | |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 1195 | uint16_t numberOfCores = 4; |
Sadik Armagan | 4c99899 | 2020-02-25 12:44:44 +0000 | [diff] [blame] | 1196 | |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1197 | // Register a counter associated to "category1" |
| 1198 | const Counter* counter1 = nullptr; |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1199 | BOOST_CHECK_NO_THROW(counter1 = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1200 | 0, |
| 1201 | category1Name, |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1202 | 0, |
| 1203 | 1, |
| 1204 | 123.45f, |
| 1205 | "counter1", |
| 1206 | "counter1description", |
Sadik Armagan | 4c99899 | 2020-02-25 12:44:44 +0000 | [diff] [blame] | 1207 | std::string("counter1units"), |
| 1208 | numberOfCores)); |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 1209 | BOOST_CHECK(counterDirectory.GetCounterCount() == 4); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1210 | BOOST_CHECK(counter1); |
| 1211 | |
| 1212 | // Register a counter associated to "category1" |
| 1213 | const Counter* counter2 = nullptr; |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1214 | BOOST_CHECK_NO_THROW(counter2 = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1215 | 4, |
| 1216 | category1Name, |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1217 | 1, |
| 1218 | 0, |
| 1219 | 330.1245656765f, |
| 1220 | "counter2", |
| 1221 | "counter2description", |
| 1222 | std::string("counter2units"), |
| 1223 | armnn::EmptyOptional(), |
| 1224 | device2->m_Uid, |
| 1225 | 0)); |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 1226 | BOOST_CHECK(counterDirectory.GetCounterCount() == 5); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1227 | BOOST_CHECK(counter2); |
| 1228 | |
| 1229 | // Register a counter associated to "category2" |
| 1230 | const Counter* counter3 = nullptr; |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1231 | BOOST_CHECK_NO_THROW(counter3 = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1232 | 5, |
| 1233 | category2Name, |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1234 | 1, |
| 1235 | 1, |
| 1236 | 0.0000045399f, |
| 1237 | "counter3", |
| 1238 | "counter3description", |
| 1239 | armnn::EmptyOptional(), |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 1240 | numberOfCores, |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1241 | device2->m_Uid, |
| 1242 | counterSet1->m_Uid)); |
| 1243 | BOOST_CHECK(counterDirectory.GetCounterCount() == 9); |
| 1244 | BOOST_CHECK(counter3); |
| 1245 | |
| 1246 | // Buffer with enough space |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1247 | MockBufferManager mockBuffer(1024); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1248 | SendCounterPacket sendCounterPacket(mockBuffer); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1249 | BOOST_CHECK_NO_THROW(sendCounterPacket.SendCounterDirectoryPacket(counterDirectory)); |
| 1250 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1251 | // Get the readable buffer |
| 1252 | auto readBuffer = mockBuffer.GetReadableBuffer(); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1253 | |
| 1254 | // Check the packet header |
Finn Williams | 985fecf | 2020-04-30 11:06:43 +0100 | [diff] [blame] | 1255 | const uint32_t packetHeaderWord0 = ReadUint32(readBuffer, 0); |
| 1256 | const uint32_t packetHeaderWord1 = ReadUint32(readBuffer, 4); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1257 | BOOST_TEST(((packetHeaderWord0 >> 26) & 0x3F) == 0); // packet_family |
| 1258 | BOOST_TEST(((packetHeaderWord0 >> 16) & 0x3FF) == 2); // packet_id |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 1259 | BOOST_TEST(packetHeaderWord1 == 432); // data_length |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1260 | |
| 1261 | // Check the body header |
Finn Williams | 985fecf | 2020-04-30 11:06:43 +0100 | [diff] [blame] | 1262 | const uint32_t bodyHeaderWord0 = ReadUint32(readBuffer, 8); |
| 1263 | const uint32_t bodyHeaderWord1 = ReadUint32(readBuffer, 12); |
| 1264 | const uint32_t bodyHeaderWord2 = ReadUint32(readBuffer, 16); |
| 1265 | const uint32_t bodyHeaderWord3 = ReadUint32(readBuffer, 20); |
| 1266 | const uint32_t bodyHeaderWord4 = ReadUint32(readBuffer, 24); |
| 1267 | const uint32_t bodyHeaderWord5 = ReadUint32(readBuffer, 28); |
| 1268 | const uint16_t deviceRecordCount = static_cast<uint16_t>(bodyHeaderWord0 >> 16); |
| 1269 | const uint16_t counterSetRecordCount = static_cast<uint16_t>(bodyHeaderWord2 >> 16); |
| 1270 | const uint16_t categoryRecordCount = static_cast<uint16_t>(bodyHeaderWord4 >> 16); |
| 1271 | BOOST_TEST(deviceRecordCount == 2); // device_records_count |
| 1272 | BOOST_TEST(bodyHeaderWord1 == bodyHeaderSize * 4); // device_records_pointer_table_offset |
| 1273 | BOOST_TEST(counterSetRecordCount == 1); // counter_set_count |
| 1274 | BOOST_TEST(bodyHeaderWord3 == 8 + bodyHeaderSize * 4); // counter_set_pointer_table_offset |
| 1275 | BOOST_TEST(categoryRecordCount == 2); // categories_count |
| 1276 | BOOST_TEST(bodyHeaderWord5 == 12 + bodyHeaderSize * 4); // categories_pointer_table_offset |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1277 | |
| 1278 | // Check the device records pointer table |
Finn Williams | 985fecf | 2020-04-30 11:06:43 +0100 | [diff] [blame] | 1279 | const uint32_t deviceRecordOffset0 = ReadUint32(readBuffer, 32); |
| 1280 | const uint32_t deviceRecordOffset1 = ReadUint32(readBuffer, 36); |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1281 | BOOST_TEST(deviceRecordOffset0 == 20); // Device record offset for "device1" |
| 1282 | BOOST_TEST(deviceRecordOffset1 == 40); // Device record offset for "device2" |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1283 | |
| 1284 | // Check the counter set pointer table |
Finn Williams | 985fecf | 2020-04-30 11:06:43 +0100 | [diff] [blame] | 1285 | const uint32_t counterSetRecordOffset0 = ReadUint32(readBuffer, 40); |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1286 | BOOST_TEST(counterSetRecordOffset0 == 52); // Counter set record offset for "counterset1" |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1287 | |
| 1288 | // Check the category pointer table |
Finn Williams | 985fecf | 2020-04-30 11:06:43 +0100 | [diff] [blame] | 1289 | const uint32_t categoryRecordOffset0 = ReadUint32(readBuffer, 44); |
| 1290 | const uint32_t categoryRecordOffset1 = ReadUint32(readBuffer, 48); |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1291 | BOOST_TEST(categoryRecordOffset0 == 72); // Category record offset for "category1" |
| 1292 | BOOST_TEST(categoryRecordOffset1 == 176); // Category record offset for "category2" |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1293 | |
| 1294 | // Get the device record pool offset |
Finn Williams | 985fecf | 2020-04-30 11:06:43 +0100 | [diff] [blame] | 1295 | const uint32_t uint32_t_size = sizeof(uint32_t); |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1296 | const uint32_t packetHeaderSize = 2u * uint32_t_size; |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1297 | |
| 1298 | // Device record structure/collection used for testing |
| 1299 | struct DeviceRecord |
| 1300 | { |
| 1301 | uint16_t uid; |
| 1302 | uint16_t cores; |
| 1303 | uint32_t name_offset; |
| 1304 | uint32_t name_length; |
| 1305 | std::string name; |
| 1306 | }; |
| 1307 | std::vector<DeviceRecord> deviceRecords; |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1308 | const uint32_t deviceRecordsPointerTableOffset = packetHeaderSize + |
Finn Williams | 985fecf | 2020-04-30 11:06:43 +0100 | [diff] [blame] | 1309 | bodyHeaderWord1; // device_records_pointer_table_offset |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1310 | |
| 1311 | const unsigned char* readData = readBuffer->GetReadableData(); |
| 1312 | |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1313 | uint32_t offset = 0; |
| 1314 | std::vector<uint32_t> data(800); |
| 1315 | |
| 1316 | for (uint32_t i = 0; i < 800; i+=uint32_t_size) |
| 1317 | { |
| 1318 | data[i] = ReadUint32(readBuffer, offset); |
| 1319 | offset += uint32_t_size; |
| 1320 | } |
| 1321 | |
| 1322 | std::vector<uint32_t> deviceRecordOffsets(deviceRecordCount); |
| 1323 | offset = deviceRecordsPointerTableOffset; |
| 1324 | for (uint32_t i = 0; i < deviceRecordCount; ++i) |
| 1325 | { |
| 1326 | // deviceRecordOffset is relative to the start of the deviceRecordsPointerTable |
| 1327 | deviceRecordOffsets[i] = ReadUint32(readBuffer, offset) + deviceRecordsPointerTableOffset; |
| 1328 | offset += uint32_t_size; |
| 1329 | } |
| 1330 | |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1331 | for (uint32_t i = 0; i < deviceRecordCount; i++) |
| 1332 | { |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1333 | // Collect the data for the device record |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1334 | const uint32_t deviceRecordWord0 = ReadUint32(readBuffer, deviceRecordOffsets[i] + 0 * uint32_t_size); |
| 1335 | const uint32_t deviceRecordWord1 = ReadUint32(readBuffer, deviceRecordOffsets[i] + 1 * uint32_t_size); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1336 | DeviceRecord deviceRecord; |
| 1337 | deviceRecord.uid = static_cast<uint16_t>(deviceRecordWord0 >> 16); // uid |
| 1338 | deviceRecord.cores = static_cast<uint16_t>(deviceRecordWord0); // cores |
| 1339 | deviceRecord.name_offset = deviceRecordWord1; // name_offset |
| 1340 | |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1341 | uint32_t deviceRecordPoolOffset = deviceRecordOffsets[i] + // Packet body offset |
| 1342 | deviceRecord.name_offset * uint32_t_size; // Device name offset |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1343 | uint32_t deviceRecordNameLength = ReadUint32(readBuffer, deviceRecordPoolOffset); |
| 1344 | deviceRecord.name_length = deviceRecordNameLength; // name_length |
| 1345 | unsigned char deviceRecordNameNullTerminator = // name null-terminator |
| 1346 | ReadUint8(readBuffer, deviceRecordPoolOffset + uint32_t_size + deviceRecordNameLength - 1); |
| 1347 | BOOST_CHECK(deviceRecordNameNullTerminator == '\0'); |
| 1348 | std::vector<unsigned char> deviceRecordNameBuffer(deviceRecord.name_length - 1); |
| 1349 | std::memcpy(deviceRecordNameBuffer.data(), |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1350 | readData + deviceRecordPoolOffset + uint32_t_size, deviceRecordNameBuffer.size()); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1351 | deviceRecord.name.assign(deviceRecordNameBuffer.begin(), deviceRecordNameBuffer.end()); // name |
| 1352 | |
| 1353 | deviceRecords.push_back(deviceRecord); |
| 1354 | } |
| 1355 | |
| 1356 | // Check that the device records are correct |
| 1357 | BOOST_CHECK(deviceRecords.size() == 2); |
| 1358 | for (const DeviceRecord& deviceRecord : deviceRecords) |
| 1359 | { |
| 1360 | const Device* device = counterDirectory.GetDevice(deviceRecord.uid); |
| 1361 | BOOST_CHECK(device); |
| 1362 | BOOST_CHECK(device->m_Uid == deviceRecord.uid); |
| 1363 | BOOST_CHECK(device->m_Cores == deviceRecord.cores); |
| 1364 | BOOST_CHECK(device->m_Name == deviceRecord.name); |
| 1365 | } |
| 1366 | |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1367 | |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1368 | // Counter set record structure/collection used for testing |
| 1369 | struct CounterSetRecord |
| 1370 | { |
| 1371 | uint16_t uid; |
| 1372 | uint16_t count; |
| 1373 | uint32_t name_offset; |
| 1374 | uint32_t name_length; |
| 1375 | std::string name; |
| 1376 | }; |
| 1377 | std::vector<CounterSetRecord> counterSetRecords; |
Finn Williams | 985fecf | 2020-04-30 11:06:43 +0100 | [diff] [blame] | 1378 | const uint32_t counterSetRecordsPointerTableOffset = 2u * uint32_t_size + // packet_header |
| 1379 | bodyHeaderWord3; // counter_set_pointer_table_offset |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1380 | |
| 1381 | offset = counterSetRecordsPointerTableOffset; |
| 1382 | std::vector<uint32_t> counterSetRecordOffsets(counterSetRecordCount); |
| 1383 | |
| 1384 | for (uint32_t i = 0; i < counterSetRecordCount; ++i) |
| 1385 | { |
| 1386 | // counterSetRecordOffset is relative to the start of the dcounterSetRecordsPointerTable |
| 1387 | counterSetRecordOffsets[i] = ReadUint32(readBuffer, offset) + counterSetRecordsPointerTableOffset; |
| 1388 | offset += uint32_t_size; |
| 1389 | } |
| 1390 | |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1391 | for (uint32_t i = 0; i < counterSetRecordCount; i++) |
| 1392 | { |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1393 | // Collect the data for the counter set record |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1394 | const uint32_t counterSetRecordWord0 = ReadUint32(readBuffer, counterSetRecordOffsets[i] + 0 * uint32_t_size); |
| 1395 | const uint32_t counterSetRecordWord1 = ReadUint32(readBuffer, counterSetRecordOffsets[i] + 1 * uint32_t_size); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1396 | CounterSetRecord counterSetRecord; |
| 1397 | counterSetRecord.uid = static_cast<uint16_t>(counterSetRecordWord0 >> 16); // uid |
| 1398 | counterSetRecord.count = static_cast<uint16_t>(counterSetRecordWord0); // count |
| 1399 | counterSetRecord.name_offset = counterSetRecordWord1; // name_offset |
| 1400 | |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1401 | uint32_t counterSetRecordPoolOffset = counterSetRecordOffsets[i] + // Packet body offset |
| 1402 | counterSetRecord.name_offset * uint32_t_size; // Counter set name offset |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1403 | uint32_t counterSetRecordNameLength = ReadUint32(readBuffer, counterSetRecordPoolOffset); |
| 1404 | counterSetRecord.name_length = counterSetRecordNameLength; // name_length |
| 1405 | unsigned char counterSetRecordNameNullTerminator = // name null-terminator |
| 1406 | ReadUint8(readBuffer, counterSetRecordPoolOffset + uint32_t_size + counterSetRecordNameLength - 1); |
| 1407 | BOOST_CHECK(counterSetRecordNameNullTerminator == '\0'); |
| 1408 | std::vector<unsigned char> counterSetRecordNameBuffer(counterSetRecord.name_length - 1); |
| 1409 | std::memcpy(counterSetRecordNameBuffer.data(), |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1410 | readData + counterSetRecordPoolOffset + uint32_t_size, counterSetRecordNameBuffer.size()); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1411 | counterSetRecord.name.assign(counterSetRecordNameBuffer.begin(), counterSetRecordNameBuffer.end()); // name |
| 1412 | |
| 1413 | counterSetRecords.push_back(counterSetRecord); |
| 1414 | } |
| 1415 | |
| 1416 | // Check that the counter set records are correct |
| 1417 | BOOST_CHECK(counterSetRecords.size() == 1); |
| 1418 | for (const CounterSetRecord& counterSetRecord : counterSetRecords) |
| 1419 | { |
| 1420 | const CounterSet* counterSet = counterDirectory.GetCounterSet(counterSetRecord.uid); |
| 1421 | BOOST_CHECK(counterSet); |
| 1422 | BOOST_CHECK(counterSet->m_Uid == counterSetRecord.uid); |
| 1423 | BOOST_CHECK(counterSet->m_Count == counterSetRecord.count); |
| 1424 | BOOST_CHECK(counterSet->m_Name == counterSetRecord.name); |
| 1425 | } |
| 1426 | |
| 1427 | // Event record structure/collection used for testing |
| 1428 | struct EventRecord |
| 1429 | { |
| 1430 | uint16_t counter_uid; |
| 1431 | uint16_t max_counter_uid; |
| 1432 | uint16_t device; |
| 1433 | uint16_t counter_set; |
| 1434 | uint16_t counter_class; |
| 1435 | uint16_t interpolation; |
| 1436 | double multiplier; |
| 1437 | uint32_t name_offset; |
| 1438 | uint32_t name_length; |
| 1439 | std::string name; |
| 1440 | uint32_t description_offset; |
| 1441 | uint32_t description_length; |
| 1442 | std::string description; |
| 1443 | uint32_t units_offset; |
| 1444 | uint32_t units_length; |
| 1445 | std::string units; |
| 1446 | }; |
| 1447 | // Category record structure/collection used for testing |
| 1448 | struct CategoryRecord |
| 1449 | { |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1450 | uint16_t event_count; |
| 1451 | uint32_t event_pointer_table_offset; |
| 1452 | uint32_t name_offset; |
| 1453 | uint32_t name_length; |
| 1454 | std::string name; |
| 1455 | std::vector<uint32_t> event_pointer_table; |
| 1456 | std::vector<EventRecord> event_records; |
| 1457 | }; |
| 1458 | std::vector<CategoryRecord> categoryRecords; |
Finn Williams | 985fecf | 2020-04-30 11:06:43 +0100 | [diff] [blame] | 1459 | const uint32_t categoryRecordsPointerTableOffset = 2u * uint32_t_size + // packet_header |
| 1460 | bodyHeaderWord5; // categories_pointer_table_offset |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1461 | |
| 1462 | offset = categoryRecordsPointerTableOffset; |
| 1463 | std::vector<uint32_t> categoryRecordOffsets(categoryRecordCount); |
| 1464 | for (uint32_t i = 0; i < categoryRecordCount; ++i) |
| 1465 | { |
| 1466 | // categoryRecordOffset is relative to the start of the categoryRecordsPointerTable |
| 1467 | categoryRecordOffsets[i] = ReadUint32(readBuffer, offset) + categoryRecordsPointerTableOffset; |
| 1468 | offset += uint32_t_size; |
| 1469 | } |
| 1470 | |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1471 | for (uint32_t i = 0; i < categoryRecordCount; i++) |
| 1472 | { |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1473 | // Collect the data for the category record |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1474 | const uint32_t categoryRecordWord1 = ReadUint32(readBuffer, categoryRecordOffsets[i] + 0 * uint32_t_size); |
| 1475 | const uint32_t categoryRecordWord2 = ReadUint32(readBuffer, categoryRecordOffsets[i] + 1 * uint32_t_size); |
| 1476 | const uint32_t categoryRecordWord3 = ReadUint32(readBuffer, categoryRecordOffsets[i] + 2 * uint32_t_size); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1477 | CategoryRecord categoryRecord; |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1478 | categoryRecord.event_count = static_cast<uint16_t>(categoryRecordWord1 >> 16); // event_count |
| 1479 | categoryRecord.event_pointer_table_offset = categoryRecordWord2; // event_pointer_table_offset |
| 1480 | categoryRecord.name_offset = categoryRecordWord3; // name_offset |
| 1481 | |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1482 | uint32_t categoryRecordNameLength = ReadUint32(readBuffer, |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1483 | categoryRecordOffsets[i] + categoryRecord.name_offset); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1484 | categoryRecord.name_length = categoryRecordNameLength; // name_length |
| 1485 | unsigned char categoryRecordNameNullTerminator = |
| 1486 | ReadUint8(readBuffer, |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1487 | categoryRecordOffsets[i] + |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1488 | categoryRecord.name_offset + |
| 1489 | uint32_t_size + |
| 1490 | categoryRecordNameLength - 1); // name null-terminator |
| 1491 | BOOST_CHECK(categoryRecordNameNullTerminator == '\0'); |
| 1492 | std::vector<unsigned char> categoryRecordNameBuffer(categoryRecord.name_length - 1); |
| 1493 | std::memcpy(categoryRecordNameBuffer.data(), |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1494 | readData + |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1495 | categoryRecordOffsets[i] + |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1496 | categoryRecord.name_offset + |
| 1497 | uint32_t_size, |
| 1498 | categoryRecordNameBuffer.size()); |
| 1499 | categoryRecord.name.assign(categoryRecordNameBuffer.begin(), categoryRecordNameBuffer.end()); // name |
| 1500 | |
| 1501 | categoryRecord.event_pointer_table.resize(categoryRecord.event_count); |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1502 | offset = categoryRecordOffsets[i] + categoryRecord.event_pointer_table_offset; |
| 1503 | for (uint32_t eventOffsetIndex = 0; eventOffsetIndex < categoryRecord.event_count; ++eventOffsetIndex) |
| 1504 | { |
| 1505 | // eventRecordOffset is relative to the start of the event pointer table |
| 1506 | categoryRecord.event_pointer_table[eventOffsetIndex] = ReadUint32(readBuffer, offset) + |
| 1507 | categoryRecordOffsets[i] + |
| 1508 | categoryRecord.event_pointer_table_offset; |
| 1509 | offset += uint32_t_size; |
| 1510 | } |
| 1511 | |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1512 | for (uint32_t eventIndex = 0; eventIndex < categoryRecord.event_count; eventIndex++) |
| 1513 | { |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1514 | const uint32_t eventOffset = categoryRecord.event_pointer_table[eventIndex]; |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1515 | // Collect the data for the event record |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1516 | const uint32_t eventRecordWord0 = ReadUint32(readBuffer, eventOffset + 0 * uint32_t_size); |
| 1517 | const uint32_t eventRecordWord1 = ReadUint32(readBuffer, eventOffset + 1 * uint32_t_size); |
| 1518 | const uint32_t eventRecordWord2 = ReadUint32(readBuffer, eventOffset + 2 * uint32_t_size); |
| 1519 | const uint64_t eventRecordWord34 = ReadUint64(readBuffer, eventOffset + 3 * uint32_t_size); |
| 1520 | const uint32_t eventRecordWord5 = ReadUint32(readBuffer, eventOffset + 5 * uint32_t_size); |
| 1521 | const uint32_t eventRecordWord6 = ReadUint32(readBuffer, eventOffset + 6 * uint32_t_size); |
| 1522 | const uint32_t eventRecordWord7 = ReadUint32(readBuffer, eventOffset + 7 * uint32_t_size); |
| 1523 | |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1524 | EventRecord eventRecord; |
| 1525 | eventRecord.counter_uid = static_cast<uint16_t>(eventRecordWord0); // counter_uid |
| 1526 | eventRecord.max_counter_uid = static_cast<uint16_t>(eventRecordWord0 >> 16); // max_counter_uid |
| 1527 | eventRecord.device = static_cast<uint16_t>(eventRecordWord1 >> 16); // device |
| 1528 | eventRecord.counter_set = static_cast<uint16_t>(eventRecordWord1); // counter_set |
| 1529 | eventRecord.counter_class = static_cast<uint16_t>(eventRecordWord2 >> 16); // class |
| 1530 | eventRecord.interpolation = static_cast<uint16_t>(eventRecordWord2); // interpolation |
| 1531 | std::memcpy(&eventRecord.multiplier, &eventRecordWord34, sizeof(eventRecord.multiplier)); // multiplier |
| 1532 | eventRecord.name_offset = static_cast<uint32_t>(eventRecordWord5); // name_offset |
| 1533 | eventRecord.description_offset = static_cast<uint32_t>(eventRecordWord6); // description_offset |
| 1534 | eventRecord.units_offset = static_cast<uint32_t>(eventRecordWord7); // units_offset |
| 1535 | |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1536 | uint32_t eventRecordNameLength = ReadUint32(readBuffer, eventOffset + eventRecord.name_offset); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1537 | eventRecord.name_length = eventRecordNameLength; // name_length |
| 1538 | unsigned char eventRecordNameNullTerminator = |
| 1539 | ReadUint8(readBuffer, |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1540 | eventOffset + |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1541 | eventRecord.name_offset + |
| 1542 | uint32_t_size + |
| 1543 | eventRecordNameLength - 1); // name null-terminator |
| 1544 | BOOST_CHECK(eventRecordNameNullTerminator == '\0'); |
| 1545 | std::vector<unsigned char> eventRecordNameBuffer(eventRecord.name_length - 1); |
| 1546 | std::memcpy(eventRecordNameBuffer.data(), |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1547 | readData + |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1548 | eventOffset + |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1549 | eventRecord.name_offset + |
| 1550 | uint32_t_size, |
| 1551 | eventRecordNameBuffer.size()); |
| 1552 | eventRecord.name.assign(eventRecordNameBuffer.begin(), eventRecordNameBuffer.end()); // name |
| 1553 | |
| 1554 | uint32_t eventRecordDescriptionLength = ReadUint32(readBuffer, |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1555 | eventOffset + eventRecord.description_offset); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1556 | eventRecord.description_length = eventRecordDescriptionLength; // description_length |
| 1557 | unsigned char eventRecordDescriptionNullTerminator = |
| 1558 | ReadUint8(readBuffer, |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1559 | eventOffset + |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1560 | eventRecord.description_offset + |
| 1561 | uint32_t_size + |
| 1562 | eventRecordDescriptionLength - 1); // description null-terminator |
| 1563 | BOOST_CHECK(eventRecordDescriptionNullTerminator == '\0'); |
| 1564 | std::vector<unsigned char> eventRecordDescriptionBuffer(eventRecord.description_length - 1); |
| 1565 | std::memcpy(eventRecordDescriptionBuffer.data(), |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1566 | readData + |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1567 | eventOffset + |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1568 | eventRecord.description_offset + |
| 1569 | uint32_t_size, |
| 1570 | eventRecordDescriptionBuffer.size()); |
| 1571 | eventRecord.description.assign(eventRecordDescriptionBuffer.begin(), |
| 1572 | eventRecordDescriptionBuffer.end()); // description |
| 1573 | |
| 1574 | if (eventRecord.units_offset > 0) |
| 1575 | { |
| 1576 | uint32_t eventRecordUnitsLength = ReadUint32(readBuffer, |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1577 | eventOffset + eventRecord.units_offset); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1578 | eventRecord.units_length = eventRecordUnitsLength; // units_length |
| 1579 | unsigned char eventRecordUnitsNullTerminator = |
| 1580 | ReadUint8(readBuffer, |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1581 | eventOffset + |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1582 | eventRecord.units_offset + |
| 1583 | uint32_t_size + |
| 1584 | eventRecordUnitsLength - 1); // units null-terminator |
| 1585 | BOOST_CHECK(eventRecordUnitsNullTerminator == '\0'); |
| 1586 | std::vector<unsigned char> eventRecordUnitsBuffer(eventRecord.units_length - 1); |
| 1587 | std::memcpy(eventRecordUnitsBuffer.data(), |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1588 | readData + |
Finn Williams | d44815f | 2020-05-01 13:25:55 +0100 | [diff] [blame] | 1589 | eventOffset + |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1590 | eventRecord.units_offset + |
| 1591 | uint32_t_size, |
| 1592 | eventRecordUnitsBuffer.size()); |
| 1593 | eventRecord.units.assign(eventRecordUnitsBuffer.begin(), eventRecordUnitsBuffer.end()); // units |
| 1594 | } |
| 1595 | |
| 1596 | categoryRecord.event_records.push_back(eventRecord); |
| 1597 | } |
| 1598 | |
| 1599 | categoryRecords.push_back(categoryRecord); |
| 1600 | } |
| 1601 | |
| 1602 | // Check that the category records are correct |
| 1603 | BOOST_CHECK(categoryRecords.size() == 2); |
| 1604 | for (const CategoryRecord& categoryRecord : categoryRecords) |
| 1605 | { |
| 1606 | const Category* category = counterDirectory.GetCategory(categoryRecord.name); |
| 1607 | BOOST_CHECK(category); |
| 1608 | BOOST_CHECK(category->m_Name == categoryRecord.name); |
Keith Davis | 33ed221 | 2020-03-30 10:43:41 +0100 | [diff] [blame] | 1609 | BOOST_CHECK(category->m_Counters.size() == categoryRecord.event_count + static_cast<size_t>(numberOfCores) -1); |
| 1610 | BOOST_CHECK(category->m_Counters.size() == categoryRecord.event_count + static_cast<size_t>(numberOfCores) -1); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1611 | |
| 1612 | // Check that the event records are correct |
| 1613 | for (const EventRecord& eventRecord : categoryRecord.event_records) |
| 1614 | { |
| 1615 | const Counter* counter = counterDirectory.GetCounter(eventRecord.counter_uid); |
| 1616 | BOOST_CHECK(counter); |
| 1617 | BOOST_CHECK(counter->m_MaxCounterUid == eventRecord.max_counter_uid); |
| 1618 | BOOST_CHECK(counter->m_DeviceUid == eventRecord.device); |
| 1619 | BOOST_CHECK(counter->m_CounterSetUid == eventRecord.counter_set); |
| 1620 | BOOST_CHECK(counter->m_Class == eventRecord.counter_class); |
| 1621 | BOOST_CHECK(counter->m_Interpolation == eventRecord.interpolation); |
| 1622 | BOOST_CHECK(counter->m_Multiplier == eventRecord.multiplier); |
| 1623 | BOOST_CHECK(counter->m_Name == eventRecord.name); |
| 1624 | BOOST_CHECK(counter->m_Description == eventRecord.description); |
| 1625 | BOOST_CHECK(counter->m_Units == eventRecord.units); |
| 1626 | } |
| 1627 | } |
| 1628 | } |
| 1629 | |
| 1630 | BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest3) |
| 1631 | { |
| 1632 | // Using a mock counter directory that allows to register invalid objects |
| 1633 | MockCounterDirectory counterDirectory; |
| 1634 | |
| 1635 | // Register an invalid device |
| 1636 | const std::string deviceName = "inv@lid dev!c€"; |
| 1637 | const Device* device = nullptr; |
| 1638 | BOOST_CHECK_NO_THROW(device = counterDirectory.RegisterDevice(deviceName, 3)); |
| 1639 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 1640 | BOOST_CHECK(device); |
| 1641 | |
| 1642 | // Buffer with enough space |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1643 | MockBufferManager mockBuffer(1024); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1644 | SendCounterPacket sendCounterPacket(mockBuffer); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1645 | BOOST_CHECK_THROW(sendCounterPacket.SendCounterDirectoryPacket(counterDirectory), armnn::RuntimeException); |
| 1646 | } |
| 1647 | |
| 1648 | BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest4) |
| 1649 | { |
| 1650 | // Using a mock counter directory that allows to register invalid objects |
| 1651 | MockCounterDirectory counterDirectory; |
| 1652 | |
| 1653 | // Register an invalid counter set |
| 1654 | const std::string counterSetName = "inv@lid count€rs€t"; |
| 1655 | const CounterSet* counterSet = nullptr; |
| 1656 | BOOST_CHECK_NO_THROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName)); |
| 1657 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1); |
| 1658 | BOOST_CHECK(counterSet); |
| 1659 | |
| 1660 | // Buffer with enough space |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1661 | MockBufferManager mockBuffer(1024); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1662 | SendCounterPacket sendCounterPacket(mockBuffer); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1663 | BOOST_CHECK_THROW(sendCounterPacket.SendCounterDirectoryPacket(counterDirectory), armnn::RuntimeException); |
| 1664 | } |
| 1665 | |
| 1666 | BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest5) |
| 1667 | { |
| 1668 | // Using a mock counter directory that allows to register invalid objects |
| 1669 | MockCounterDirectory counterDirectory; |
| 1670 | |
| 1671 | // Register an invalid category |
| 1672 | const std::string categoryName = "c@t€gory"; |
| 1673 | const Category* category = nullptr; |
| 1674 | BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName)); |
| 1675 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 1676 | BOOST_CHECK(category); |
| 1677 | |
| 1678 | // Buffer with enough space |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1679 | MockBufferManager mockBuffer(1024); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1680 | SendCounterPacket sendCounterPacket(mockBuffer); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1681 | BOOST_CHECK_THROW(sendCounterPacket.SendCounterDirectoryPacket(counterDirectory), armnn::RuntimeException); |
| 1682 | } |
| 1683 | |
| 1684 | BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest6) |
| 1685 | { |
| 1686 | // Using a mock counter directory that allows to register invalid objects |
| 1687 | MockCounterDirectory counterDirectory; |
| 1688 | |
| 1689 | // Register an invalid device |
| 1690 | const std::string deviceName = "inv@lid dev!c€"; |
| 1691 | const Device* device = nullptr; |
| 1692 | BOOST_CHECK_NO_THROW(device = counterDirectory.RegisterDevice(deviceName, 3)); |
| 1693 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 1694 | BOOST_CHECK(device); |
| 1695 | |
| 1696 | // Register an invalid counter set |
| 1697 | const std::string counterSetName = "inv@lid count€rs€t"; |
| 1698 | const CounterSet* counterSet = nullptr; |
| 1699 | BOOST_CHECK_NO_THROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName)); |
| 1700 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1); |
| 1701 | BOOST_CHECK(counterSet); |
| 1702 | |
| 1703 | // Register an invalid category associated to an invalid device and an invalid counter set |
| 1704 | const std::string categoryName = "c@t€gory"; |
| 1705 | const Category* category = nullptr; |
Sadik Armagan | 4c99899 | 2020-02-25 12:44:44 +0000 | [diff] [blame] | 1706 | BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName)); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1707 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 1708 | BOOST_CHECK(category); |
| 1709 | |
| 1710 | // Buffer with enough space |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1711 | MockBufferManager mockBuffer(1024); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1712 | SendCounterPacket sendCounterPacket(mockBuffer); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1713 | BOOST_CHECK_THROW(sendCounterPacket.SendCounterDirectoryPacket(counterDirectory), armnn::RuntimeException); |
| 1714 | } |
| 1715 | |
| 1716 | BOOST_AUTO_TEST_CASE(SendCounterDirectoryPacketTest7) |
| 1717 | { |
| 1718 | // Using a mock counter directory that allows to register invalid objects |
| 1719 | MockCounterDirectory counterDirectory; |
| 1720 | |
| 1721 | // Register an valid device |
| 1722 | const std::string deviceName = "valid device"; |
| 1723 | const Device* device = nullptr; |
| 1724 | BOOST_CHECK_NO_THROW(device = counterDirectory.RegisterDevice(deviceName, 3)); |
| 1725 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 1726 | BOOST_CHECK(device); |
| 1727 | |
| 1728 | // Register an valid counter set |
| 1729 | const std::string counterSetName = "valid counterset"; |
| 1730 | const CounterSet* counterSet = nullptr; |
| 1731 | BOOST_CHECK_NO_THROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName)); |
| 1732 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1); |
| 1733 | BOOST_CHECK(counterSet); |
| 1734 | |
| 1735 | // Register an valid category associated to a valid device and a valid counter set |
| 1736 | const std::string categoryName = "category"; |
| 1737 | const Category* category = nullptr; |
Sadik Armagan | 4c99899 | 2020-02-25 12:44:44 +0000 | [diff] [blame] | 1738 | BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName)); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1739 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 1740 | BOOST_CHECK(category); |
| 1741 | |
| 1742 | // Register an invalid counter associated to a valid category |
| 1743 | const Counter* counter = nullptr; |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1744 | BOOST_CHECK_NO_THROW(counter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1745 | 0, |
| 1746 | categoryName, |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1747 | 0, |
| 1748 | 1, |
| 1749 | 123.45f, |
| 1750 | "counter", |
| 1751 | "counter description", |
| 1752 | std::string("invalid counter units"), |
| 1753 | 5, |
| 1754 | device->m_Uid, |
| 1755 | counterSet->m_Uid)); |
| 1756 | BOOST_CHECK(counterDirectory.GetCounterCount() == 5); |
| 1757 | BOOST_CHECK(counter); |
| 1758 | |
| 1759 | // Buffer with enough space |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1760 | MockBufferManager mockBuffer(1024); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1761 | SendCounterPacket sendCounterPacket(mockBuffer); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1762 | BOOST_CHECK_THROW(sendCounterPacket.SendCounterDirectoryPacket(counterDirectory), armnn::RuntimeException); |
| 1763 | } |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 1764 | |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1765 | BOOST_AUTO_TEST_CASE(SendThreadTest0) |
| 1766 | { |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 1767 | ProfilingStateMachine profilingStateMachine; |
| 1768 | SetActiveProfilingState(profilingStateMachine); |
| 1769 | |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1770 | MockProfilingConnection mockProfilingConnection; |
Matteo Martincigh | 61d6f73 | 2019-10-03 11:21:18 +0100 | [diff] [blame] | 1771 | MockStreamCounterBuffer mockStreamCounterBuffer(0); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1772 | SendCounterPacket sendCounterPacket(mockStreamCounterBuffer); |
| 1773 | SendThread sendThread(profilingStateMachine, mockStreamCounterBuffer, sendCounterPacket); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1774 | |
| 1775 | // Try to start the send thread many times, it must only start once |
| 1776 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1777 | sendThread.Start(mockProfilingConnection); |
| 1778 | BOOST_CHECK(sendThread.IsRunning()); |
| 1779 | sendThread.Start(mockProfilingConnection); |
| 1780 | sendThread.Start(mockProfilingConnection); |
| 1781 | sendThread.Start(mockProfilingConnection); |
| 1782 | sendThread.Start(mockProfilingConnection); |
| 1783 | BOOST_CHECK(sendThread.IsRunning()); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1784 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1785 | sendThread.Stop(); |
| 1786 | BOOST_CHECK(!sendThread.IsRunning()); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | BOOST_AUTO_TEST_CASE(SendThreadTest1) |
| 1790 | { |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 1791 | ProfilingStateMachine profilingStateMachine; |
| 1792 | SetActiveProfilingState(profilingStateMachine); |
| 1793 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1794 | unsigned int totalWrittenSize = 0; |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1795 | |
| 1796 | MockProfilingConnection mockProfilingConnection; |
Matteo Martincigh | 61d6f73 | 2019-10-03 11:21:18 +0100 | [diff] [blame] | 1797 | MockStreamCounterBuffer mockStreamCounterBuffer(1024); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1798 | SendCounterPacket sendCounterPacket(mockStreamCounterBuffer); |
| 1799 | SendThread sendThread(profilingStateMachine, mockStreamCounterBuffer, sendCounterPacket); |
| 1800 | sendThread.Start(mockProfilingConnection); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1801 | |
| 1802 | // Interleaving writes and reads to/from the buffer with pauses to test that the send thread actually waits for |
| 1803 | // something to become available for reading |
| 1804 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 1805 | std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS)); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1806 | |
| 1807 | CounterDirectory counterDirectory; |
| 1808 | sendCounterPacket.SendStreamMetaDataPacket(); |
| 1809 | |
Finn Williams | a0de056 | 2020-04-22 12:27:37 +0100 | [diff] [blame] | 1810 | totalWrittenSize += GetStreamMetaDataPacketSize(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1811 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1812 | sendThread.SetReadyToRead(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1813 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 1814 | std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS)); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1815 | |
| 1816 | sendCounterPacket.SendCounterDirectoryPacket(counterDirectory); |
| 1817 | |
| 1818 | // Get the size of the Counter Directory Packet |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1819 | unsigned int counterDirectoryPacketSize = 32; |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1820 | totalWrittenSize += counterDirectoryPacketSize; |
| 1821 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1822 | sendThread.SetReadyToRead(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1823 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 1824 | std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS)); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1825 | |
| 1826 | sendCounterPacket.SendPeriodicCounterCapturePacket(123u, |
| 1827 | { |
| 1828 | { 1u, 23u }, |
| 1829 | { 33u, 1207623u } |
| 1830 | }); |
| 1831 | |
| 1832 | // Get the size of the Periodic Counter Capture Packet |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1833 | unsigned int periodicCounterCapturePacketSize = 28; |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1834 | totalWrittenSize += periodicCounterCapturePacketSize; |
| 1835 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1836 | sendThread.SetReadyToRead(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1837 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 1838 | std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS)); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1839 | |
| 1840 | sendCounterPacket.SendPeriodicCounterCapturePacket(44u, |
| 1841 | { |
| 1842 | { 211u, 923u } |
| 1843 | }); |
| 1844 | |
| 1845 | // Get the size of the Periodic Counter Capture Packet |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1846 | periodicCounterCapturePacketSize = 22; |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1847 | totalWrittenSize += periodicCounterCapturePacketSize; |
| 1848 | |
| 1849 | sendCounterPacket.SendPeriodicCounterCapturePacket(1234u, |
| 1850 | { |
| 1851 | { 555u, 23u }, |
| 1852 | { 556u, 6u }, |
| 1853 | { 557u, 893454u }, |
| 1854 | { 558u, 1456623u }, |
| 1855 | { 559u, 571090u } |
| 1856 | }); |
| 1857 | |
| 1858 | // Get the size of the Periodic Counter Capture Packet |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1859 | periodicCounterCapturePacketSize = 46; |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1860 | totalWrittenSize += periodicCounterCapturePacketSize; |
| 1861 | |
| 1862 | sendCounterPacket.SendPeriodicCounterCapturePacket(997u, |
| 1863 | { |
| 1864 | { 88u, 11u }, |
| 1865 | { 96u, 22u }, |
| 1866 | { 97u, 33u }, |
| 1867 | { 999u, 444u } |
| 1868 | }); |
| 1869 | |
| 1870 | // Get the size of the Periodic Counter Capture Packet |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1871 | periodicCounterCapturePacketSize = 40; |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1872 | totalWrittenSize += periodicCounterCapturePacketSize; |
| 1873 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1874 | sendThread.SetReadyToRead(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1875 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 1876 | std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS)); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1877 | |
| 1878 | sendCounterPacket.SendPeriodicCounterSelectionPacket(1000u, { 1345u, 254u, 4536u, 408u, 54u, 6323u, 428u, 1u, 6u }); |
| 1879 | |
| 1880 | // Get the size of the Periodic Counter Capture Packet |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1881 | periodicCounterCapturePacketSize = 30; |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1882 | totalWrittenSize += periodicCounterCapturePacketSize; |
| 1883 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1884 | sendThread.SetReadyToRead(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1885 | |
Finn Williams | 109c05b | 2019-11-29 13:56:33 +0000 | [diff] [blame] | 1886 | // To test an exact value of the "read size" in the mock buffer, wait to allow the send thread to |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1887 | // read all what's remaining in the buffer |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 1888 | std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS)); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1889 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1890 | sendThread.Stop(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1891 | |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1892 | BOOST_CHECK(mockStreamCounterBuffer.GetCommittedSize() == totalWrittenSize); |
Matteo Martincigh | 61d6f73 | 2019-10-03 11:21:18 +0100 | [diff] [blame] | 1893 | BOOST_CHECK(mockStreamCounterBuffer.GetReadableSize() == totalWrittenSize); |
| 1894 | BOOST_CHECK(mockStreamCounterBuffer.GetReadSize() == totalWrittenSize); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1895 | } |
| 1896 | |
| 1897 | BOOST_AUTO_TEST_CASE(SendThreadTest2) |
| 1898 | { |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 1899 | ProfilingStateMachine profilingStateMachine; |
| 1900 | SetActiveProfilingState(profilingStateMachine); |
| 1901 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1902 | unsigned int totalWrittenSize = 0; |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1903 | |
| 1904 | MockProfilingConnection mockProfilingConnection; |
Matteo Martincigh | 61d6f73 | 2019-10-03 11:21:18 +0100 | [diff] [blame] | 1905 | MockStreamCounterBuffer mockStreamCounterBuffer(1024); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1906 | SendCounterPacket sendCounterPacket(mockStreamCounterBuffer); |
| 1907 | SendThread sendThread(profilingStateMachine, mockStreamCounterBuffer, sendCounterPacket); |
| 1908 | sendThread.Start(mockProfilingConnection); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1909 | |
| 1910 | // Adding many spurious "ready to read" signals throughout the test to check that the send thread is |
| 1911 | // capable of handling unnecessary read requests |
| 1912 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 1913 | std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS)); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1914 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1915 | sendThread.SetReadyToRead(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1916 | |
| 1917 | CounterDirectory counterDirectory; |
| 1918 | sendCounterPacket.SendStreamMetaDataPacket(); |
| 1919 | |
Finn Williams | a0de056 | 2020-04-22 12:27:37 +0100 | [diff] [blame] | 1920 | totalWrittenSize += GetStreamMetaDataPacketSize(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1921 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1922 | sendThread.SetReadyToRead(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1923 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 1924 | std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS)); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1925 | |
| 1926 | sendCounterPacket.SendCounterDirectoryPacket(counterDirectory); |
| 1927 | |
| 1928 | // Get the size of the Counter Directory Packet |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1929 | unsigned int counterDirectoryPacketSize = 32; |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1930 | totalWrittenSize += counterDirectoryPacketSize; |
| 1931 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1932 | sendThread.SetReadyToRead(); |
| 1933 | sendThread.SetReadyToRead(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1934 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 1935 | std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS)); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1936 | |
| 1937 | sendCounterPacket.SendPeriodicCounterCapturePacket(123u, |
| 1938 | { |
| 1939 | { 1u, 23u }, |
| 1940 | { 33u, 1207623u } |
| 1941 | }); |
| 1942 | |
| 1943 | // Get the size of the Periodic Counter Capture Packet |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1944 | unsigned int periodicCounterCapturePacketSize = 28; |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1945 | totalWrittenSize += periodicCounterCapturePacketSize; |
| 1946 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1947 | sendThread.SetReadyToRead(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1948 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 1949 | std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS)); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1950 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1951 | sendThread.SetReadyToRead(); |
| 1952 | sendThread.SetReadyToRead(); |
| 1953 | sendThread.SetReadyToRead(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1954 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 1955 | std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS)); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1956 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1957 | sendThread.SetReadyToRead(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1958 | sendCounterPacket.SendPeriodicCounterCapturePacket(44u, |
| 1959 | { |
| 1960 | { 211u, 923u } |
| 1961 | }); |
| 1962 | |
| 1963 | // Get the size of the Periodic Counter Capture Packet |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1964 | periodicCounterCapturePacketSize = 22; |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1965 | totalWrittenSize += periodicCounterCapturePacketSize; |
| 1966 | |
| 1967 | sendCounterPacket.SendPeriodicCounterCapturePacket(1234u, |
| 1968 | { |
| 1969 | { 555u, 23u }, |
| 1970 | { 556u, 6u }, |
| 1971 | { 557u, 893454u }, |
| 1972 | { 558u, 1456623u }, |
| 1973 | { 559u, 571090u } |
| 1974 | }); |
| 1975 | |
| 1976 | // Get the size of the Periodic Counter Capture Packet |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1977 | periodicCounterCapturePacketSize = 46; |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1978 | totalWrittenSize += periodicCounterCapturePacketSize; |
| 1979 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1980 | sendThread.SetReadyToRead(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1981 | sendCounterPacket.SendPeriodicCounterCapturePacket(997u, |
| 1982 | { |
| 1983 | { 88u, 11u }, |
| 1984 | { 96u, 22u }, |
| 1985 | { 97u, 33u }, |
| 1986 | { 999u, 444u } |
| 1987 | }); |
| 1988 | |
| 1989 | // Get the size of the Periodic Counter Capture Packet |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1990 | periodicCounterCapturePacketSize = 40; |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1991 | totalWrittenSize += periodicCounterCapturePacketSize; |
| 1992 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 1993 | sendThread.SetReadyToRead(); |
| 1994 | sendThread.SetReadyToRead(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1995 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 1996 | std::this_thread::sleep_for(std::chrono::milliseconds(WAIT_UNTIL_READABLE_MS)); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 1997 | |
| 1998 | sendCounterPacket.SendPeriodicCounterSelectionPacket(1000u, { 1345u, 254u, 4536u, 408u, 54u, 6323u, 428u, 1u, 6u }); |
| 1999 | |
| 2000 | // Get the size of the Periodic Counter Capture Packet |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 2001 | periodicCounterCapturePacketSize = 30; |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2002 | totalWrittenSize += periodicCounterCapturePacketSize; |
| 2003 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2004 | sendThread.SetReadyToRead(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2005 | |
Finn Williams | 109c05b | 2019-11-29 13:56:33 +0000 | [diff] [blame] | 2006 | // To test an exact value of the "read size" in the mock buffer, wait to allow the send thread to |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2007 | // read all what's remaining in the buffer |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2008 | sendThread.Stop(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2009 | |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2010 | BOOST_CHECK(mockStreamCounterBuffer.GetCommittedSize() == totalWrittenSize); |
Matteo Martincigh | 61d6f73 | 2019-10-03 11:21:18 +0100 | [diff] [blame] | 2011 | BOOST_CHECK(mockStreamCounterBuffer.GetReadableSize() == totalWrittenSize); |
| 2012 | BOOST_CHECK(mockStreamCounterBuffer.GetReadSize() == totalWrittenSize); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2013 | } |
| 2014 | |
| 2015 | BOOST_AUTO_TEST_CASE(SendThreadTest3) |
| 2016 | { |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2017 | ProfilingStateMachine profilingStateMachine; |
| 2018 | SetActiveProfilingState(profilingStateMachine); |
| 2019 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 2020 | unsigned int totalWrittenSize = 0; |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2021 | |
| 2022 | MockProfilingConnection mockProfilingConnection; |
Matteo Martincigh | 61d6f73 | 2019-10-03 11:21:18 +0100 | [diff] [blame] | 2023 | MockStreamCounterBuffer mockStreamCounterBuffer(1024); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2024 | SendCounterPacket sendCounterPacket(mockStreamCounterBuffer); |
| 2025 | SendThread sendThread(profilingStateMachine, mockStreamCounterBuffer, sendCounterPacket); |
| 2026 | sendThread.Start(mockProfilingConnection); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2027 | |
| 2028 | // Not using pauses or "grace periods" to stress test the send thread |
| 2029 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2030 | sendThread.SetReadyToRead(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2031 | |
| 2032 | CounterDirectory counterDirectory; |
| 2033 | sendCounterPacket.SendStreamMetaDataPacket(); |
| 2034 | |
Finn Williams | a0de056 | 2020-04-22 12:27:37 +0100 | [diff] [blame] | 2035 | totalWrittenSize += GetStreamMetaDataPacketSize(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2036 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2037 | sendThread.SetReadyToRead(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2038 | sendCounterPacket.SendCounterDirectoryPacket(counterDirectory); |
| 2039 | |
| 2040 | // Get the size of the Counter Directory Packet |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 2041 | unsigned int counterDirectoryPacketSize =32; |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2042 | totalWrittenSize += counterDirectoryPacketSize; |
| 2043 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2044 | sendThread.SetReadyToRead(); |
| 2045 | sendThread.SetReadyToRead(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2046 | sendCounterPacket.SendPeriodicCounterCapturePacket(123u, |
| 2047 | { |
| 2048 | { 1u, 23u }, |
| 2049 | { 33u, 1207623u } |
| 2050 | }); |
| 2051 | |
| 2052 | // Get the size of the Periodic Counter Capture Packet |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 2053 | unsigned int periodicCounterCapturePacketSize = 28; |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2054 | totalWrittenSize += periodicCounterCapturePacketSize; |
| 2055 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2056 | sendThread.SetReadyToRead(); |
| 2057 | sendThread.SetReadyToRead(); |
| 2058 | sendThread.SetReadyToRead(); |
| 2059 | sendThread.SetReadyToRead(); |
| 2060 | sendThread.SetReadyToRead(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2061 | sendCounterPacket.SendPeriodicCounterCapturePacket(44u, |
| 2062 | { |
| 2063 | { 211u, 923u } |
| 2064 | }); |
| 2065 | |
| 2066 | // Get the size of the Periodic Counter Capture Packet |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 2067 | periodicCounterCapturePacketSize = 22; |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2068 | totalWrittenSize += periodicCounterCapturePacketSize; |
| 2069 | |
| 2070 | sendCounterPacket.SendPeriodicCounterCapturePacket(1234u, |
| 2071 | { |
| 2072 | { 555u, 23u }, |
| 2073 | { 556u, 6u }, |
| 2074 | { 557u, 893454u }, |
| 2075 | { 558u, 1456623u }, |
| 2076 | { 559u, 571090u } |
| 2077 | }); |
| 2078 | |
| 2079 | // Get the size of the Periodic Counter Capture Packet |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 2080 | periodicCounterCapturePacketSize = 46; |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2081 | totalWrittenSize += periodicCounterCapturePacketSize; |
| 2082 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2083 | sendThread.SetReadyToRead(); |
| 2084 | sendThread.SetReadyToRead(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2085 | sendCounterPacket.SendPeriodicCounterCapturePacket(997u, |
| 2086 | { |
| 2087 | { 88u, 11u }, |
| 2088 | { 96u, 22u }, |
| 2089 | { 97u, 33u }, |
| 2090 | { 999u, 444u } |
| 2091 | }); |
| 2092 | |
| 2093 | // Get the size of the Periodic Counter Capture Packet |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 2094 | periodicCounterCapturePacketSize = 40; |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2095 | totalWrittenSize += periodicCounterCapturePacketSize; |
| 2096 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2097 | sendThread.SetReadyToRead(); |
| 2098 | sendThread.SetReadyToRead(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2099 | sendCounterPacket.SendPeriodicCounterSelectionPacket(1000u, { 1345u, 254u, 4536u, 408u, 54u, 6323u, 428u, 1u, 6u }); |
| 2100 | |
| 2101 | // Get the size of the Periodic Counter Capture Packet |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 2102 | periodicCounterCapturePacketSize = 30; |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2103 | totalWrittenSize += periodicCounterCapturePacketSize; |
| 2104 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2105 | sendThread.SetReadyToRead(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2106 | |
| 2107 | // Abruptly terminating the send thread, the amount of data sent may be less that the amount written (the send |
| 2108 | // thread is not guaranteed to flush the buffer) |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2109 | sendThread.Stop(); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2110 | |
Matteo Martincigh | 61d6f73 | 2019-10-03 11:21:18 +0100 | [diff] [blame] | 2111 | BOOST_CHECK(mockStreamCounterBuffer.GetCommittedSize() == totalWrittenSize); |
| 2112 | BOOST_CHECK(mockStreamCounterBuffer.GetReadableSize() <= totalWrittenSize); |
| 2113 | BOOST_CHECK(mockStreamCounterBuffer.GetReadSize() <= totalWrittenSize); |
| 2114 | BOOST_CHECK(mockStreamCounterBuffer.GetReadSize() <= mockStreamCounterBuffer.GetReadableSize()); |
| 2115 | BOOST_CHECK(mockStreamCounterBuffer.GetReadSize() <= mockStreamCounterBuffer.GetCommittedSize()); |
Matteo Martincigh | 24e8f92 | 2019-09-19 11:57:46 +0100 | [diff] [blame] | 2116 | } |
| 2117 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2118 | BOOST_AUTO_TEST_CASE(SendCounterPacketTestWithSendThread) |
| 2119 | { |
| 2120 | ProfilingStateMachine profilingStateMachine; |
| 2121 | SetWaitingForAckProfilingState(profilingStateMachine); |
| 2122 | |
| 2123 | MockProfilingConnection mockProfilingConnection; |
| 2124 | BufferManager bufferManager(1, 1024); |
| 2125 | SendCounterPacket sendCounterPacket(bufferManager); |
| 2126 | SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket, -1); |
| 2127 | sendThread.Start(mockProfilingConnection); |
| 2128 | |
Finn Williams | a0de056 | 2020-04-22 12:27:37 +0100 | [diff] [blame] | 2129 | unsigned int streamMetadataPacketsize = GetStreamMetaDataPacketSize(); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2130 | |
| 2131 | sendThread.Stop(); |
| 2132 | |
| 2133 | // check for packet in ProfilingConnection |
| 2134 | BOOST_CHECK(mockProfilingConnection.CheckForPacket({PacketType::StreamMetaData, streamMetadataPacketsize}) == 1); |
| 2135 | |
| 2136 | SetActiveProfilingState(profilingStateMachine); |
| 2137 | sendThread.Start(mockProfilingConnection); |
| 2138 | |
| 2139 | // SendCounterDirectoryPacket |
| 2140 | CounterDirectory counterDirectory; |
| 2141 | sendCounterPacket.SendCounterDirectoryPacket(counterDirectory); |
| 2142 | |
| 2143 | sendThread.Stop(); |
| 2144 | unsigned int counterDirectoryPacketSize = 32; |
| 2145 | // check for packet in ProfilingConnection |
| 2146 | BOOST_CHECK(mockProfilingConnection.CheckForPacket( |
| 2147 | {PacketType::CounterDirectory, counterDirectoryPacketSize}) == 1); |
| 2148 | |
| 2149 | sendThread.Start(mockProfilingConnection); |
| 2150 | |
| 2151 | // SendPeriodicCounterCapturePacket |
| 2152 | sendCounterPacket.SendPeriodicCounterCapturePacket(123u, |
| 2153 | { |
| 2154 | { 1u, 23u }, |
| 2155 | { 33u, 1207623u } |
| 2156 | }); |
| 2157 | |
| 2158 | sendThread.Stop(); |
| 2159 | |
| 2160 | unsigned int periodicCounterCapturePacketSize = 28; |
| 2161 | BOOST_CHECK(mockProfilingConnection.CheckForPacket( |
| 2162 | {PacketType::PeriodicCounterCapture, periodicCounterCapturePacketSize}) == 1); |
| 2163 | } |
| 2164 | |
Narumol Prangnawarat | 0ec068f | 2019-09-30 16:20:20 +0100 | [diff] [blame] | 2165 | BOOST_AUTO_TEST_CASE(SendThreadBufferTest) |
| 2166 | { |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2167 | ProfilingStateMachine profilingStateMachine; |
| 2168 | SetActiveProfilingState(profilingStateMachine); |
| 2169 | |
Narumol Prangnawarat | 0ec068f | 2019-09-30 16:20:20 +0100 | [diff] [blame] | 2170 | MockProfilingConnection mockProfilingConnection; |
Narumol Prangnawarat | 0ec068f | 2019-09-30 16:20:20 +0100 | [diff] [blame] | 2171 | BufferManager bufferManager(3, 1024); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2172 | SendCounterPacket sendCounterPacket(bufferManager); |
| 2173 | SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket, -1); |
| 2174 | sendThread.Start(mockProfilingConnection); |
Narumol Prangnawarat | 0ec068f | 2019-09-30 16:20:20 +0100 | [diff] [blame] | 2175 | |
| 2176 | // SendStreamMetaDataPacket |
| 2177 | sendCounterPacket.SendStreamMetaDataPacket(); |
| 2178 | |
| 2179 | // Read data from the buffer |
| 2180 | // Buffer should become readable after commit by SendStreamMetaDataPacket |
| 2181 | auto packetBuffer = bufferManager.GetReadableBuffer(); |
| 2182 | BOOST_TEST(packetBuffer.get()); |
| 2183 | |
Finn Williams | a0de056 | 2020-04-22 12:27:37 +0100 | [diff] [blame] | 2184 | unsigned int streamMetadataPacketsize = GetStreamMetaDataPacketSize(); |
Narumol Prangnawarat | 0ec068f | 2019-09-30 16:20:20 +0100 | [diff] [blame] | 2185 | BOOST_TEST(packetBuffer->GetSize() == streamMetadataPacketsize); |
| 2186 | |
| 2187 | // Recommit to be read by sendCounterPacket |
| 2188 | bufferManager.Commit(packetBuffer, streamMetadataPacketsize); |
| 2189 | |
Narumol Prangnawarat | 0ec068f | 2019-09-30 16:20:20 +0100 | [diff] [blame] | 2190 | // SendCounterDirectoryPacket |
| 2191 | CounterDirectory counterDirectory; |
| 2192 | sendCounterPacket.SendCounterDirectoryPacket(counterDirectory); |
| 2193 | |
Narumol Prangnawarat | 0ec068f | 2019-09-30 16:20:20 +0100 | [diff] [blame] | 2194 | // SendPeriodicCounterCapturePacket |
| 2195 | sendCounterPacket.SendPeriodicCounterCapturePacket(123u, |
| 2196 | { |
| 2197 | { 1u, 23u }, |
| 2198 | { 33u, 1207623u } |
| 2199 | }); |
| 2200 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2201 | sendThread.Stop(); |
Narumol Prangnawarat | 0ec068f | 2019-09-30 16:20:20 +0100 | [diff] [blame] | 2202 | |
| 2203 | // The buffer is read by the send thread so it should not be in the readable buffer. |
| 2204 | auto readBuffer = bufferManager.GetReadableBuffer(); |
| 2205 | BOOST_TEST(!readBuffer); |
| 2206 | |
| 2207 | // Successfully reserved the buffer with requested size |
| 2208 | unsigned int reservedSize = 0; |
| 2209 | auto reservedBuffer = bufferManager.Reserve(512, reservedSize); |
| 2210 | BOOST_TEST(reservedSize == 512); |
| 2211 | BOOST_TEST(reservedBuffer.get()); |
| 2212 | |
Finn Williams | 09ad6f9 | 2019-12-19 17:05:18 +0000 | [diff] [blame] | 2213 | const auto writtenDataSize = mockProfilingConnection.GetWrittenDataSize(); |
| 2214 | const auto metaDataPacketCount = |
| 2215 | mockProfilingConnection.CheckForPacket({PacketType::StreamMetaData, streamMetadataPacketsize}); |
| 2216 | |
| 2217 | BOOST_TEST(metaDataPacketCount >= 1); |
| 2218 | BOOST_TEST(mockProfilingConnection.CheckForPacket({PacketType::CounterDirectory, 32}) == 1); |
| 2219 | BOOST_TEST(mockProfilingConnection.CheckForPacket({PacketType::PeriodicCounterCapture, 28}) == 1); |
| 2220 | // Check that we only received the packets we expected |
| 2221 | BOOST_TEST(metaDataPacketCount + 2 == writtenDataSize); |
Narumol Prangnawarat | 0ec068f | 2019-09-30 16:20:20 +0100 | [diff] [blame] | 2222 | } |
| 2223 | |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2224 | BOOST_AUTO_TEST_CASE(SendThreadSendStreamMetadataPacket1) |
| 2225 | { |
| 2226 | ProfilingStateMachine profilingStateMachine; |
| 2227 | |
| 2228 | MockProfilingConnection mockProfilingConnection; |
| 2229 | BufferManager bufferManager(3, 1024); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2230 | SendCounterPacket sendCounterPacket(bufferManager); |
| 2231 | SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket); |
| 2232 | sendThread.Start(mockProfilingConnection); |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2233 | |
| 2234 | // The profiling state is set to "Uninitialized", so the send thread should throw an exception |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2235 | BOOST_CHECK_THROW(sendThread.Stop(), armnn::RuntimeException); |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2236 | } |
| 2237 | |
| 2238 | BOOST_AUTO_TEST_CASE(SendThreadSendStreamMetadataPacket2) |
| 2239 | { |
| 2240 | ProfilingStateMachine profilingStateMachine; |
| 2241 | SetNotConnectedProfilingState(profilingStateMachine); |
| 2242 | |
| 2243 | MockProfilingConnection mockProfilingConnection; |
| 2244 | BufferManager bufferManager(3, 1024); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2245 | SendCounterPacket sendCounterPacket(bufferManager); |
| 2246 | SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket); |
| 2247 | sendThread.Start(mockProfilingConnection); |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2248 | |
| 2249 | // The profiling state is set to "NotConnected", so the send thread should throw an exception |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2250 | BOOST_CHECK_THROW(sendThread.Stop(), armnn::RuntimeException); |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2251 | } |
| 2252 | |
| 2253 | BOOST_AUTO_TEST_CASE(SendThreadSendStreamMetadataPacket3) |
| 2254 | { |
| 2255 | ProfilingStateMachine profilingStateMachine; |
| 2256 | SetWaitingForAckProfilingState(profilingStateMachine); |
| 2257 | |
Finn Williams | a0de056 | 2020-04-22 12:27:37 +0100 | [diff] [blame] | 2258 | unsigned int streamMetadataPacketsize = GetStreamMetaDataPacketSize(); |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2259 | |
| 2260 | MockProfilingConnection mockProfilingConnection; |
| 2261 | BufferManager bufferManager(3, 1024); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2262 | SendCounterPacket sendCounterPacket(bufferManager); |
| 2263 | SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket); |
| 2264 | sendThread.Start(mockProfilingConnection); |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2265 | |
| 2266 | // The profiling state is set to "WaitingForAck", so the send thread should send a Stream Metadata packet |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2267 | // Wait for sendThread to join |
| 2268 | BOOST_CHECK_NO_THROW(sendThread.Stop()); |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2269 | |
Finn Williams | 09ad6f9 | 2019-12-19 17:05:18 +0000 | [diff] [blame] | 2270 | // Check that the buffer contains at least one Stream Metadata packet and no other packets |
| 2271 | const auto writtenDataSize = mockProfilingConnection.GetWrittenDataSize(); |
| 2272 | |
| 2273 | BOOST_TEST(writtenDataSize >= 1); |
| 2274 | BOOST_TEST(mockProfilingConnection.CheckForPacket( |
| 2275 | {PacketType::StreamMetaData, streamMetadataPacketsize}) == writtenDataSize); |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2276 | } |
| 2277 | |
| 2278 | BOOST_AUTO_TEST_CASE(SendThreadSendStreamMetadataPacket4) |
| 2279 | { |
| 2280 | ProfilingStateMachine profilingStateMachine; |
| 2281 | SetWaitingForAckProfilingState(profilingStateMachine); |
| 2282 | |
Finn Williams | a0de056 | 2020-04-22 12:27:37 +0100 | [diff] [blame] | 2283 | unsigned int streamMetadataPacketsize = GetStreamMetaDataPacketSize(); |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2284 | |
| 2285 | MockProfilingConnection mockProfilingConnection; |
| 2286 | BufferManager bufferManager(3, 1024); |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2287 | SendCounterPacket sendCounterPacket(bufferManager); |
| 2288 | SendThread sendThread(profilingStateMachine, bufferManager, sendCounterPacket); |
| 2289 | sendThread.Start(mockProfilingConnection); |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2290 | |
| 2291 | // The profiling state is set to "WaitingForAck", so the send thread should send a Stream Metadata packet |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2292 | // Wait for sendThread to join |
| 2293 | sendThread.Stop(); |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2294 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2295 | sendThread.Start(mockProfilingConnection); |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2296 | // Check that the profiling state is still "WaitingForAck" |
| 2297 | BOOST_TEST((profilingStateMachine.GetCurrentState() == ProfilingState::WaitingForAck)); |
| 2298 | |
Finn Williams | 3e2969d | 2019-12-06 17:47:36 +0000 | [diff] [blame] | 2299 | // Check that the buffer contains at least one Stream Metadata packet |
Finn Williams | 09ad6f9 | 2019-12-19 17:05:18 +0000 | [diff] [blame] | 2300 | BOOST_TEST(mockProfilingConnection.CheckForPacket({PacketType::StreamMetaData, streamMetadataPacketsize}) >= 1); |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2301 | |
| 2302 | mockProfilingConnection.Clear(); |
| 2303 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2304 | sendThread.Stop(); |
| 2305 | sendThread.Start(mockProfilingConnection); |
Finn Williams | 09ad6f9 | 2019-12-19 17:05:18 +0000 | [diff] [blame] | 2306 | |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2307 | // Try triggering a new buffer read |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2308 | sendThread.SetReadyToRead(); |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2309 | |
Sadik Armagan | 3896b47 | 2020-02-10 12:24:15 +0000 | [diff] [blame] | 2310 | // Wait for sendThread to join |
| 2311 | BOOST_CHECK_NO_THROW(sendThread.Stop()); |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2312 | |
| 2313 | // Check that the profiling state is still "WaitingForAck" |
| 2314 | BOOST_TEST((profilingStateMachine.GetCurrentState() == ProfilingState::WaitingForAck)); |
| 2315 | |
Finn Williams | 09ad6f9 | 2019-12-19 17:05:18 +0000 | [diff] [blame] | 2316 | // Check that the buffer contains at least one Stream Metadata packet and no other packets |
| 2317 | const auto writtenDataSize = mockProfilingConnection.GetWrittenDataSize(); |
| 2318 | |
| 2319 | BOOST_TEST(writtenDataSize >= 1); |
| 2320 | BOOST_TEST(mockProfilingConnection.CheckForPacket( |
| 2321 | {PacketType::StreamMetaData, streamMetadataPacketsize}) == writtenDataSize); |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2322 | } |
| 2323 | |
Ferran Balaguer | af5c46b | 2019-08-30 15:49:15 +0100 | [diff] [blame] | 2324 | BOOST_AUTO_TEST_SUITE_END() |