Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 6 | #include "ProfilingTests.hpp" |
Teresa Charlin | 9bab496 | 2019-09-06 12:28:35 +0100 | [diff] [blame] | 7 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 8 | #include <CommandHandler.hpp> |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 9 | #include <CommandHandlerKey.hpp> |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 10 | #include <CommandHandlerRegistry.hpp> |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 11 | #include <ConnectionAcknowledgedCommandHandler.hpp> |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 12 | #include <CounterDirectory.hpp> |
| 13 | #include <EncodeVersion.hpp> |
| 14 | #include <Holder.hpp> |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 15 | #include <ICounterValues.hpp> |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 16 | #include <Packet.hpp> |
| 17 | #include <PacketVersionResolver.hpp> |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 18 | #include <PeriodicCounterCapture.hpp> |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 19 | #include <PeriodicCounterSelectionCommandHandler.hpp> |
| 20 | #include <ProfilingStateMachine.hpp> |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 21 | #include <ProfilingUtils.hpp> |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 22 | #include <RequestCounterDirectoryCommandHandler.hpp> |
Teresa Charlin | 9bab496 | 2019-09-06 12:28:35 +0100 | [diff] [blame] | 23 | #include <Runtime.hpp> |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 24 | #include <SocketProfilingConnection.hpp> |
Matteo Martincigh | cdfb941 | 2019-11-08 11:23:06 +0000 | [diff] [blame] | 25 | #include <SendCounterPacket.hpp> |
| 26 | #include <SendTimelinePacket.hpp> |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 27 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 28 | #include <armnn/Conversion.hpp> |
Colm Donelan | 0270524 | 2019-11-14 14:19:07 +0000 | [diff] [blame] | 29 | #include <armnn/Types.hpp> |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 30 | |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 31 | #include <armnn/Utils.hpp> |
| 32 | |
Sadik Armagan | bd9e2c5 | 2019-09-26 23:13:31 +0100 | [diff] [blame] | 33 | #include <boost/algorithm/string.hpp> |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 34 | #include <boost/numeric/conversion/cast.hpp> |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 35 | |
Nikhil Raj | bc62605 | 2019-08-15 15:49:45 +0100 | [diff] [blame] | 36 | #include <cstdint> |
| 37 | #include <cstring> |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 38 | #include <iostream> |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 39 | #include <limits> |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 40 | #include <map> |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 41 | #include <random> |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 42 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 43 | using namespace armnn::profiling; |
| 44 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 45 | BOOST_AUTO_TEST_SUITE(ExternalProfiling) |
| 46 | |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 47 | BOOST_AUTO_TEST_CASE(CheckCommandHandlerKeyComparisons) |
| 48 | { |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 49 | CommandHandlerKey testKey1_0(1, 1, 1); |
| 50 | CommandHandlerKey testKey1_1(1, 1, 1); |
| 51 | CommandHandlerKey testKey1_2(1, 2, 1); |
| 52 | |
| 53 | CommandHandlerKey testKey0(0, 1, 1); |
| 54 | CommandHandlerKey testKey1(0, 1, 1); |
| 55 | CommandHandlerKey testKey2(0, 1, 1); |
| 56 | CommandHandlerKey testKey3(0, 0, 0); |
| 57 | CommandHandlerKey testKey4(0, 2, 2); |
| 58 | CommandHandlerKey testKey5(0, 0, 2); |
| 59 | |
| 60 | BOOST_CHECK(testKey1_0 > testKey0); |
| 61 | BOOST_CHECK(testKey1_0 == testKey1_1); |
| 62 | BOOST_CHECK(testKey1_0 < testKey1_2); |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 63 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 64 | BOOST_CHECK(testKey1 < testKey4); |
| 65 | BOOST_CHECK(testKey1 > testKey3); |
| 66 | BOOST_CHECK(testKey1 <= testKey4); |
| 67 | BOOST_CHECK(testKey1 >= testKey3); |
| 68 | BOOST_CHECK(testKey1 <= testKey2); |
| 69 | BOOST_CHECK(testKey1 >= testKey2); |
| 70 | BOOST_CHECK(testKey1 == testKey2); |
| 71 | BOOST_CHECK(testKey1 == testKey1); |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 72 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 73 | BOOST_CHECK(!(testKey1 == testKey5)); |
| 74 | BOOST_CHECK(!(testKey1 != testKey1)); |
| 75 | BOOST_CHECK(testKey1 != testKey5); |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 76 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 77 | BOOST_CHECK(testKey1 == testKey2 && testKey2 == testKey1); |
| 78 | BOOST_CHECK(testKey0 == testKey1 && testKey1 == testKey2 && testKey0 == testKey2); |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 79 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 80 | BOOST_CHECK(testKey1.GetPacketId() == 1); |
| 81 | BOOST_CHECK(testKey1.GetVersion() == 1); |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 82 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 83 | std::vector<CommandHandlerKey> vect = { CommandHandlerKey(0, 0, 1), CommandHandlerKey(0, 2, 0), |
| 84 | CommandHandlerKey(0, 1, 0), CommandHandlerKey(0, 2, 1), |
| 85 | CommandHandlerKey(0, 1, 1), CommandHandlerKey(0, 0, 1), |
| 86 | CommandHandlerKey(0, 2, 0), CommandHandlerKey(0, 0, 0) }; |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 87 | |
| 88 | std::sort(vect.begin(), vect.end()); |
| 89 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 90 | std::vector<CommandHandlerKey> expectedVect = { CommandHandlerKey(0, 0, 0), CommandHandlerKey(0, 0, 1), |
| 91 | CommandHandlerKey(0, 0, 1), CommandHandlerKey(0, 1, 0), |
| 92 | CommandHandlerKey(0, 1, 1), CommandHandlerKey(0, 2, 0), |
| 93 | CommandHandlerKey(0, 2, 0), CommandHandlerKey(0, 2, 1) }; |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 94 | |
| 95 | BOOST_CHECK(vect == expectedVect); |
| 96 | } |
| 97 | |
Jim Flynn | ed25e0e | 2019-10-18 13:21:43 +0100 | [diff] [blame] | 98 | BOOST_AUTO_TEST_CASE(CheckPacketKeyComparisons) |
| 99 | { |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 100 | PacketKey key0(0, 0); |
| 101 | PacketKey key1(0, 0); |
| 102 | PacketKey key2(0, 1); |
| 103 | PacketKey key3(0, 2); |
| 104 | PacketKey key4(1, 0); |
| 105 | PacketKey key5(1, 0); |
| 106 | PacketKey key6(1, 1); |
Jim Flynn | ed25e0e | 2019-10-18 13:21:43 +0100 | [diff] [blame] | 107 | |
| 108 | BOOST_CHECK(!(key0 < key1)); |
| 109 | BOOST_CHECK(!(key0 > key1)); |
| 110 | BOOST_CHECK(key0 <= key1); |
| 111 | BOOST_CHECK(key0 >= key1); |
| 112 | BOOST_CHECK(key0 == key1); |
| 113 | BOOST_CHECK(key0 < key2); |
| 114 | BOOST_CHECK(key2 < key3); |
| 115 | BOOST_CHECK(key3 > key0); |
| 116 | BOOST_CHECK(key4 == key5); |
| 117 | BOOST_CHECK(key4 > key0); |
| 118 | BOOST_CHECK(key5 < key6); |
| 119 | BOOST_CHECK(key5 <= key6); |
| 120 | BOOST_CHECK(key5 != key6); |
| 121 | } |
| 122 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 123 | BOOST_AUTO_TEST_CASE(CheckCommandHandler) |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 124 | { |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 125 | PacketVersionResolver packetVersionResolver; |
| 126 | ProfilingStateMachine profilingStateMachine; |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 127 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 128 | TestProfilingConnectionBase testProfilingConnectionBase; |
| 129 | TestProfilingConnectionTimeoutError testProfilingConnectionTimeOutError; |
| 130 | TestProfilingConnectionArmnnError testProfilingConnectionArmnnError; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 131 | CounterDirectory counterDirectory; |
| 132 | MockBufferManager mockBuffer(1024); |
| 133 | SendCounterPacket sendCounterPacket(profilingStateMachine, mockBuffer); |
Matteo Martincigh | cdfb941 | 2019-11-08 11:23:06 +0000 | [diff] [blame] | 134 | SendTimelinePacket sendTimelinePacket(mockBuffer); |
| 135 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 136 | ConnectionAcknowledgedCommandHandler connectionAcknowledgedCommandHandler(0, 1, 4194304, counterDirectory, |
Matteo Martincigh | cdfb941 | 2019-11-08 11:23:06 +0000 | [diff] [blame] | 137 | sendCounterPacket, sendTimelinePacket, |
| 138 | profilingStateMachine); |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 139 | CommandHandlerRegistry commandHandlerRegistry; |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 140 | |
Matteo Martincigh | c2728f9 | 2019-10-07 12:35:21 +0100 | [diff] [blame] | 141 | commandHandlerRegistry.RegisterFunctor(&connectionAcknowledgedCommandHandler); |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 142 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 143 | profilingStateMachine.TransitionToState(ProfilingState::NotConnected); |
| 144 | profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck); |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 145 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 146 | // A 1mSec timeout should be enough to slow the command handler thread a little. |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 147 | CommandHandler commandHandler0(1, true, commandHandlerRegistry, packetVersionResolver); |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 148 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 149 | // This should start the command handler thread return the connection ack and put the profiling |
| 150 | // service into active state. |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 151 | commandHandler0.Start(testProfilingConnectionBase); |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 152 | // Try to start the send thread many times, it must only start once |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 153 | commandHandler0.Start(testProfilingConnectionBase); |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 154 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 155 | // This could take up to 20mSec but we'll check often. |
| 156 | for (int i = 0; i < 10; i++) |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 157 | { |
| 158 | if (profilingStateMachine.GetCurrentState() == ProfilingState::Active) |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 159 | { |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 160 | break; |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 161 | } |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 162 | std::this_thread::sleep_for(std::chrono::milliseconds(2)); |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 163 | } |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 164 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 165 | BOOST_CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::Active); |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 166 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 167 | // Close the thread again. |
| 168 | commandHandler0.Stop(); |
| 169 | |
| 170 | profilingStateMachine.TransitionToState(ProfilingState::NotConnected); |
| 171 | profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck); |
| 172 | |
| 173 | // In this test we'll simulate a timeout without a connection ack packet being received. |
| 174 | // Stop after timeout is set so we expect the command handler to stop almost immediately. |
| 175 | CommandHandler commandHandler1(1, true, commandHandlerRegistry, packetVersionResolver); |
| 176 | |
| 177 | commandHandler1.Start(testProfilingConnectionTimeOutError); |
| 178 | // Wait until we know a timeout exception has been sent at least once. |
| 179 | for (int i = 0; i < 10; i++) |
| 180 | { |
| 181 | if (testProfilingConnectionTimeOutError.ReadCalledCount()) |
| 182 | { |
| 183 | break; |
| 184 | } |
| 185 | std::this_thread::sleep_for(std::chrono::milliseconds(2)); |
| 186 | } |
| 187 | // and leave another short period for the timeout exception to be processed and the loop to break. |
| 188 | std::this_thread::sleep_for(std::chrono::milliseconds(3)); |
| 189 | |
| 190 | // The command handler loop should have stopped after the timeout. |
| 191 | BOOST_CHECK(!commandHandler1.IsRunning()); |
| 192 | |
| 193 | commandHandler1.Stop(); |
| 194 | // The state machine should never have received the ack so will still be in WaitingForAck. |
| 195 | BOOST_CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::WaitingForAck); |
| 196 | |
| 197 | // Disable stop after timeout and now commandHandler1 should persist after a timeout |
| 198 | commandHandler1.SetStopAfterTimeout(false); |
| 199 | // Restart the thread. |
| 200 | commandHandler1.Start(testProfilingConnectionTimeOutError); |
| 201 | |
| 202 | // Wait for at the three timeouts and the ack to be sent. |
| 203 | for (int i = 0; i < 10; i++) |
| 204 | { |
| 205 | if (testProfilingConnectionTimeOutError.ReadCalledCount() > 3) |
| 206 | { |
| 207 | break; |
| 208 | } |
| 209 | std::this_thread::sleep_for(std::chrono::milliseconds(2)); |
| 210 | } |
| 211 | commandHandler1.Stop(); |
| 212 | |
| 213 | // Even after the 3 exceptions the ack packet should have transitioned the command handler to active. |
| 214 | BOOST_CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::Active); |
| 215 | |
| 216 | // A command handler that gets exceptions other than timeouts should keep going. |
| 217 | CommandHandler commandHandler2(1, false, commandHandlerRegistry, packetVersionResolver); |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 218 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 219 | commandHandler2.Start(testProfilingConnectionArmnnError); |
| 220 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 221 | // Wait for two exceptions to be thrown. |
| 222 | for (int i = 0; i < 10; i++) |
| 223 | { |
| 224 | if (testProfilingConnectionTimeOutError.ReadCalledCount() >= 2) |
| 225 | { |
| 226 | break; |
| 227 | } |
| 228 | std::this_thread::sleep_for(std::chrono::milliseconds(2)); |
| 229 | } |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 230 | |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 231 | BOOST_CHECK(commandHandler2.IsRunning()); |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 232 | commandHandler2.Stop(); |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 233 | } |
| 234 | |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 235 | BOOST_AUTO_TEST_CASE(CheckEncodeVersion) |
| 236 | { |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 237 | Version version1(12); |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 238 | |
| 239 | BOOST_CHECK(version1.GetMajor() == 0); |
| 240 | BOOST_CHECK(version1.GetMinor() == 0); |
| 241 | BOOST_CHECK(version1.GetPatch() == 12); |
| 242 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 243 | Version version2(4108); |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 244 | |
| 245 | BOOST_CHECK(version2.GetMajor() == 0); |
| 246 | BOOST_CHECK(version2.GetMinor() == 1); |
| 247 | BOOST_CHECK(version2.GetPatch() == 12); |
| 248 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 249 | Version version3(4198412); |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 250 | |
| 251 | BOOST_CHECK(version3.GetMajor() == 1); |
| 252 | BOOST_CHECK(version3.GetMinor() == 1); |
| 253 | BOOST_CHECK(version3.GetPatch() == 12); |
| 254 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 255 | Version version4(0); |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 256 | |
| 257 | BOOST_CHECK(version4.GetMajor() == 0); |
| 258 | BOOST_CHECK(version4.GetMinor() == 0); |
| 259 | BOOST_CHECK(version4.GetPatch() == 0); |
| 260 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 261 | Version version5(1, 0, 0); |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 262 | BOOST_CHECK(version5.GetEncodedValue() == 4194304); |
| 263 | } |
| 264 | |
Nikhil Raj | bc62605 | 2019-08-15 15:49:45 +0100 | [diff] [blame] | 265 | BOOST_AUTO_TEST_CASE(CheckPacketClass) |
| 266 | { |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 267 | uint32_t length = 4; |
Matteo Martincigh | 67ef2a5 | 2019-10-10 13:29:02 +0100 | [diff] [blame] | 268 | std::unique_ptr<unsigned char[]> packetData0 = std::make_unique<unsigned char[]>(length); |
| 269 | std::unique_ptr<unsigned char[]> packetData1 = std::make_unique<unsigned char[]>(0); |
| 270 | std::unique_ptr<unsigned char[]> nullPacketData; |
Nikhil Raj | bc62605 | 2019-08-15 15:49:45 +0100 | [diff] [blame] | 271 | |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 272 | Packet packetTest0(472580096, length, packetData0); |
Nikhil Raj | bc62605 | 2019-08-15 15:49:45 +0100 | [diff] [blame] | 273 | |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 274 | BOOST_CHECK(packetTest0.GetHeader() == 472580096); |
| 275 | BOOST_CHECK(packetTest0.GetPacketFamily() == 7); |
| 276 | BOOST_CHECK(packetTest0.GetPacketId() == 43); |
| 277 | BOOST_CHECK(packetTest0.GetLength() == length); |
| 278 | BOOST_CHECK(packetTest0.GetPacketType() == 3); |
| 279 | BOOST_CHECK(packetTest0.GetPacketClass() == 5); |
Nikhil Raj | bc62605 | 2019-08-15 15:49:45 +0100 | [diff] [blame] | 280 | |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 281 | BOOST_CHECK_THROW(Packet packetTest1(472580096, 0, packetData1), armnn::Exception); |
| 282 | BOOST_CHECK_NO_THROW(Packet packetTest2(472580096, 0, nullPacketData)); |
Nikhil Raj | bc62605 | 2019-08-15 15:49:45 +0100 | [diff] [blame] | 283 | |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 284 | Packet packetTest3(472580096, 0, nullPacketData); |
| 285 | BOOST_CHECK(packetTest3.GetLength() == 0); |
| 286 | BOOST_CHECK(packetTest3.GetData() == nullptr); |
| 287 | |
Matteo Martincigh | 67ef2a5 | 2019-10-10 13:29:02 +0100 | [diff] [blame] | 288 | const unsigned char* packetTest0Data = packetTest0.GetData(); |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 289 | Packet packetTest4(std::move(packetTest0)); |
| 290 | |
| 291 | BOOST_CHECK(packetTest0.GetData() == nullptr); |
| 292 | BOOST_CHECK(packetTest4.GetData() == packetTest0Data); |
| 293 | |
| 294 | BOOST_CHECK(packetTest4.GetHeader() == 472580096); |
| 295 | BOOST_CHECK(packetTest4.GetPacketFamily() == 7); |
| 296 | BOOST_CHECK(packetTest4.GetPacketId() == 43); |
| 297 | BOOST_CHECK(packetTest4.GetLength() == length); |
| 298 | BOOST_CHECK(packetTest4.GetPacketType() == 3); |
| 299 | BOOST_CHECK(packetTest4.GetPacketClass() == 5); |
Nikhil Raj | bc62605 | 2019-08-15 15:49:45 +0100 | [diff] [blame] | 300 | } |
| 301 | |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 302 | BOOST_AUTO_TEST_CASE(CheckCommandHandlerFunctor) |
| 303 | { |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 304 | // Hard code the version as it will be the same during a single profiling session |
| 305 | uint32_t version = 1; |
| 306 | |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 307 | TestFunctorA testFunctorA(7, 461, version); |
| 308 | TestFunctorB testFunctorB(8, 963, version); |
| 309 | TestFunctorC testFunctorC(5, 983, version); |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 310 | |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 311 | CommandHandlerKey keyA(testFunctorA.GetFamilyId(), testFunctorA.GetPacketId(), testFunctorA.GetVersion()); |
| 312 | CommandHandlerKey keyB(testFunctorB.GetFamilyId(), testFunctorB.GetPacketId(), testFunctorB.GetVersion()); |
| 313 | CommandHandlerKey keyC(testFunctorC.GetFamilyId(), testFunctorC.GetPacketId(), testFunctorC.GetVersion()); |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 314 | |
| 315 | // Create the unwrapped map to simulate the Command Handler Registry |
| 316 | std::map<CommandHandlerKey, CommandHandlerFunctor*> registry; |
| 317 | |
| 318 | registry.insert(std::make_pair(keyB, &testFunctorB)); |
| 319 | registry.insert(std::make_pair(keyA, &testFunctorA)); |
| 320 | registry.insert(std::make_pair(keyC, &testFunctorC)); |
| 321 | |
| 322 | // Check the order of the map is correct |
| 323 | auto it = registry.begin(); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 324 | BOOST_CHECK(it->first == keyC); // familyId == 5 |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 325 | it++; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 326 | BOOST_CHECK(it->first == keyA); // familyId == 7 |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 327 | it++; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 328 | BOOST_CHECK(it->first == keyB); // familyId == 8 |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 329 | |
Matteo Martincigh | 67ef2a5 | 2019-10-10 13:29:02 +0100 | [diff] [blame] | 330 | std::unique_ptr<unsigned char[]> packetDataA; |
| 331 | std::unique_ptr<unsigned char[]> packetDataB; |
| 332 | std::unique_ptr<unsigned char[]> packetDataC; |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 333 | |
| 334 | Packet packetA(500000000, 0, packetDataA); |
| 335 | Packet packetB(600000000, 0, packetDataB); |
| 336 | Packet packetC(400000000, 0, packetDataC); |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 337 | |
| 338 | // Check the correct operator of derived class is called |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 339 | registry.at(CommandHandlerKey(packetA.GetPacketFamily(), packetA.GetPacketId(), version))->operator()(packetA); |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 340 | BOOST_CHECK(testFunctorA.GetCount() == 1); |
| 341 | BOOST_CHECK(testFunctorB.GetCount() == 0); |
| 342 | BOOST_CHECK(testFunctorC.GetCount() == 0); |
| 343 | |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 344 | registry.at(CommandHandlerKey(packetB.GetPacketFamily(), packetB.GetPacketId(), version))->operator()(packetB); |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 345 | BOOST_CHECK(testFunctorA.GetCount() == 1); |
| 346 | BOOST_CHECK(testFunctorB.GetCount() == 1); |
| 347 | BOOST_CHECK(testFunctorC.GetCount() == 0); |
| 348 | |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 349 | registry.at(CommandHandlerKey(packetC.GetPacketFamily(), packetC.GetPacketId(), version))->operator()(packetC); |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 350 | BOOST_CHECK(testFunctorA.GetCount() == 1); |
| 351 | BOOST_CHECK(testFunctorB.GetCount() == 1); |
| 352 | BOOST_CHECK(testFunctorC.GetCount() == 1); |
| 353 | } |
| 354 | |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 355 | BOOST_AUTO_TEST_CASE(CheckCommandHandlerRegistry) |
| 356 | { |
| 357 | // Hard code the version as it will be the same during a single profiling session |
| 358 | uint32_t version = 1; |
| 359 | |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 360 | TestFunctorA testFunctorA(7, 461, version); |
| 361 | TestFunctorB testFunctorB(8, 963, version); |
| 362 | TestFunctorC testFunctorC(5, 983, version); |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 363 | |
| 364 | // Create the Command Handler Registry |
| 365 | CommandHandlerRegistry registry; |
| 366 | |
| 367 | // Register multiple different derived classes |
Matteo Martincigh | c2728f9 | 2019-10-07 12:35:21 +0100 | [diff] [blame] | 368 | registry.RegisterFunctor(&testFunctorA); |
| 369 | registry.RegisterFunctor(&testFunctorB); |
| 370 | registry.RegisterFunctor(&testFunctorC); |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 371 | |
Matteo Martincigh | 67ef2a5 | 2019-10-10 13:29:02 +0100 | [diff] [blame] | 372 | std::unique_ptr<unsigned char[]> packetDataA; |
| 373 | std::unique_ptr<unsigned char[]> packetDataB; |
| 374 | std::unique_ptr<unsigned char[]> packetDataC; |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 375 | |
| 376 | Packet packetA(500000000, 0, packetDataA); |
| 377 | Packet packetB(600000000, 0, packetDataB); |
| 378 | Packet packetC(400000000, 0, packetDataC); |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 379 | |
| 380 | // Check the correct operator of derived class is called |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 381 | registry.GetFunctor(packetA.GetPacketFamily(), packetA.GetPacketId(), version)->operator()(packetA); |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 382 | BOOST_CHECK(testFunctorA.GetCount() == 1); |
| 383 | BOOST_CHECK(testFunctorB.GetCount() == 0); |
| 384 | BOOST_CHECK(testFunctorC.GetCount() == 0); |
| 385 | |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 386 | registry.GetFunctor(packetB.GetPacketFamily(), packetB.GetPacketId(), version)->operator()(packetB); |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 387 | BOOST_CHECK(testFunctorA.GetCount() == 1); |
| 388 | BOOST_CHECK(testFunctorB.GetCount() == 1); |
| 389 | BOOST_CHECK(testFunctorC.GetCount() == 0); |
| 390 | |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 391 | registry.GetFunctor(packetC.GetPacketFamily(), packetC.GetPacketId(), version)->operator()(packetC); |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 392 | BOOST_CHECK(testFunctorA.GetCount() == 1); |
| 393 | BOOST_CHECK(testFunctorB.GetCount() == 1); |
| 394 | BOOST_CHECK(testFunctorC.GetCount() == 1); |
| 395 | |
| 396 | // Re-register an existing key with a new function |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 397 | registry.RegisterFunctor(&testFunctorC, testFunctorA.GetFamilyId(), testFunctorA.GetPacketId(), version); |
| 398 | registry.GetFunctor(packetA.GetPacketFamily(), packetA.GetPacketId(), version)->operator()(packetC); |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 399 | BOOST_CHECK(testFunctorA.GetCount() == 1); |
| 400 | BOOST_CHECK(testFunctorB.GetCount() == 1); |
| 401 | BOOST_CHECK(testFunctorC.GetCount() == 2); |
| 402 | |
| 403 | // Check that non-existent key returns nullptr for its functor |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 404 | BOOST_CHECK_THROW(registry.GetFunctor(0, 0, 0), armnn::Exception); |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 405 | } |
| 406 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 407 | BOOST_AUTO_TEST_CASE(CheckPacketVersionResolver) |
| 408 | { |
| 409 | // Set up random number generator for generating packetId values |
| 410 | std::random_device device; |
| 411 | std::mt19937 generator(device()); |
| 412 | std::uniform_int_distribution<uint32_t> distribution(std::numeric_limits<uint32_t>::min(), |
| 413 | std::numeric_limits<uint32_t>::max()); |
| 414 | |
| 415 | // NOTE: Expected version is always 1.0.0, regardless of packetId |
| 416 | const Version expectedVersion(1, 0, 0); |
| 417 | |
| 418 | PacketVersionResolver packetVersionResolver; |
| 419 | |
| 420 | constexpr unsigned int numTests = 10u; |
| 421 | |
| 422 | for (unsigned int i = 0u; i < numTests; ++i) |
| 423 | { |
Jim Flynn | ed25e0e | 2019-10-18 13:21:43 +0100 | [diff] [blame] | 424 | const uint32_t familyId = distribution(generator); |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 425 | const uint32_t packetId = distribution(generator); |
Jim Flynn | ed25e0e | 2019-10-18 13:21:43 +0100 | [diff] [blame] | 426 | Version resolvedVersion = packetVersionResolver.ResolvePacketVersion(familyId, packetId); |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 427 | |
| 428 | BOOST_TEST(resolvedVersion == expectedVersion); |
| 429 | } |
| 430 | } |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 431 | |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 432 | void ProfilingCurrentStateThreadImpl(ProfilingStateMachine& states) |
| 433 | { |
| 434 | ProfilingState newState = ProfilingState::NotConnected; |
| 435 | states.GetCurrentState(); |
| 436 | states.TransitionToState(newState); |
| 437 | } |
| 438 | |
| 439 | BOOST_AUTO_TEST_CASE(CheckProfilingStateMachine) |
| 440 | { |
| 441 | ProfilingStateMachine profilingState1(ProfilingState::Uninitialised); |
| 442 | profilingState1.TransitionToState(ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 443 | BOOST_CHECK(profilingState1.GetCurrentState() == ProfilingState::Uninitialised); |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 444 | |
| 445 | ProfilingStateMachine profilingState2(ProfilingState::Uninitialised); |
| 446 | profilingState2.TransitionToState(ProfilingState::NotConnected); |
| 447 | BOOST_CHECK(profilingState2.GetCurrentState() == ProfilingState::NotConnected); |
| 448 | |
| 449 | ProfilingStateMachine profilingState3(ProfilingState::NotConnected); |
| 450 | profilingState3.TransitionToState(ProfilingState::NotConnected); |
| 451 | BOOST_CHECK(profilingState3.GetCurrentState() == ProfilingState::NotConnected); |
| 452 | |
| 453 | ProfilingStateMachine profilingState4(ProfilingState::NotConnected); |
| 454 | profilingState4.TransitionToState(ProfilingState::WaitingForAck); |
| 455 | BOOST_CHECK(profilingState4.GetCurrentState() == ProfilingState::WaitingForAck); |
| 456 | |
| 457 | ProfilingStateMachine profilingState5(ProfilingState::WaitingForAck); |
| 458 | profilingState5.TransitionToState(ProfilingState::WaitingForAck); |
| 459 | BOOST_CHECK(profilingState5.GetCurrentState() == ProfilingState::WaitingForAck); |
| 460 | |
| 461 | ProfilingStateMachine profilingState6(ProfilingState::WaitingForAck); |
| 462 | profilingState6.TransitionToState(ProfilingState::Active); |
| 463 | BOOST_CHECK(profilingState6.GetCurrentState() == ProfilingState::Active); |
| 464 | |
| 465 | ProfilingStateMachine profilingState7(ProfilingState::Active); |
| 466 | profilingState7.TransitionToState(ProfilingState::NotConnected); |
| 467 | BOOST_CHECK(profilingState7.GetCurrentState() == ProfilingState::NotConnected); |
| 468 | |
| 469 | ProfilingStateMachine profilingState8(ProfilingState::Active); |
| 470 | profilingState8.TransitionToState(ProfilingState::Active); |
| 471 | BOOST_CHECK(profilingState8.GetCurrentState() == ProfilingState::Active); |
| 472 | |
| 473 | ProfilingStateMachine profilingState9(ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 474 | BOOST_CHECK_THROW(profilingState9.TransitionToState(ProfilingState::WaitingForAck), armnn::Exception); |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 475 | |
| 476 | ProfilingStateMachine profilingState10(ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 477 | BOOST_CHECK_THROW(profilingState10.TransitionToState(ProfilingState::Active), armnn::Exception); |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 478 | |
| 479 | ProfilingStateMachine profilingState11(ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 480 | BOOST_CHECK_THROW(profilingState11.TransitionToState(ProfilingState::Uninitialised), armnn::Exception); |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 481 | |
| 482 | ProfilingStateMachine profilingState12(ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 483 | BOOST_CHECK_THROW(profilingState12.TransitionToState(ProfilingState::Active), armnn::Exception); |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 484 | |
| 485 | ProfilingStateMachine profilingState13(ProfilingState::WaitingForAck); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 486 | BOOST_CHECK_THROW(profilingState13.TransitionToState(ProfilingState::Uninitialised), armnn::Exception); |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 487 | |
| 488 | ProfilingStateMachine profilingState14(ProfilingState::WaitingForAck); |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 489 | profilingState14.TransitionToState(ProfilingState::NotConnected); |
| 490 | BOOST_CHECK(profilingState14.GetCurrentState() == ProfilingState::NotConnected); |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 491 | |
| 492 | ProfilingStateMachine profilingState15(ProfilingState::Active); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 493 | BOOST_CHECK_THROW(profilingState15.TransitionToState(ProfilingState::Uninitialised), armnn::Exception); |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 494 | |
| 495 | ProfilingStateMachine profilingState16(armnn::profiling::ProfilingState::Active); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 496 | BOOST_CHECK_THROW(profilingState16.TransitionToState(ProfilingState::WaitingForAck), armnn::Exception); |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 497 | |
| 498 | ProfilingStateMachine profilingState17(ProfilingState::Uninitialised); |
| 499 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 500 | std::thread thread1(ProfilingCurrentStateThreadImpl, std::ref(profilingState17)); |
| 501 | std::thread thread2(ProfilingCurrentStateThreadImpl, std::ref(profilingState17)); |
| 502 | std::thread thread3(ProfilingCurrentStateThreadImpl, std::ref(profilingState17)); |
| 503 | std::thread thread4(ProfilingCurrentStateThreadImpl, std::ref(profilingState17)); |
| 504 | std::thread thread5(ProfilingCurrentStateThreadImpl, std::ref(profilingState17)); |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 505 | |
| 506 | thread1.join(); |
| 507 | thread2.join(); |
| 508 | thread3.join(); |
| 509 | thread4.join(); |
| 510 | thread5.join(); |
| 511 | |
| 512 | BOOST_TEST((profilingState17.GetCurrentState() == ProfilingState::NotConnected)); |
| 513 | } |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 514 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 515 | void CaptureDataWriteThreadImpl(Holder& holder, uint32_t capturePeriod, const std::vector<uint16_t>& counterIds) |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 516 | { |
| 517 | holder.SetCaptureData(capturePeriod, counterIds); |
| 518 | } |
| 519 | |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 520 | void CaptureDataReadThreadImpl(const Holder& holder, CaptureData& captureData) |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 521 | { |
| 522 | captureData = holder.GetCaptureData(); |
| 523 | } |
| 524 | |
| 525 | BOOST_AUTO_TEST_CASE(CheckCaptureDataHolder) |
| 526 | { |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 527 | std::map<uint32_t, std::vector<uint16_t>> periodIdMap; |
| 528 | std::vector<uint16_t> counterIds; |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 529 | uint32_t numThreads = 10; |
| 530 | for (uint32_t i = 0; i < numThreads; ++i) |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 531 | { |
| 532 | counterIds.emplace_back(i); |
| 533 | periodIdMap.insert(std::make_pair(i, counterIds)); |
| 534 | } |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 535 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 536 | // Verify the read and write threads set the holder correctly |
| 537 | // and retrieve the expected values |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 538 | Holder holder; |
| 539 | BOOST_CHECK((holder.GetCaptureData()).GetCapturePeriod() == 0); |
| 540 | BOOST_CHECK(((holder.GetCaptureData()).GetCounterIds()).empty()); |
| 541 | |
| 542 | // Check Holder functions |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 543 | std::thread thread1(CaptureDataWriteThreadImpl, std::ref(holder), 2, std::ref(periodIdMap[2])); |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 544 | thread1.join(); |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 545 | BOOST_CHECK((holder.GetCaptureData()).GetCapturePeriod() == 2); |
| 546 | BOOST_CHECK((holder.GetCaptureData()).GetCounterIds() == periodIdMap[2]); |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 547 | // NOTE: now that we have some initial values in the holder we don't have to worry |
| 548 | // in the multi-threaded section below about a read thread accessing the holder |
| 549 | // before any write thread has gotten to it so we read period = 0, counterIds empty |
| 550 | // instead of period = 0, counterIds = {0} as will the case when write thread 0 |
| 551 | // has executed. |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 552 | |
| 553 | CaptureData captureData; |
| 554 | std::thread thread2(CaptureDataReadThreadImpl, std::ref(holder), std::ref(captureData)); |
| 555 | thread2.join(); |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 556 | BOOST_CHECK(captureData.GetCapturePeriod() == 2); |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 557 | BOOST_CHECK(captureData.GetCounterIds() == periodIdMap[2]); |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 558 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 559 | std::map<uint32_t, CaptureData> captureDataIdMap; |
| 560 | for (uint32_t i = 0; i < numThreads; ++i) |
| 561 | { |
| 562 | CaptureData perThreadCaptureData; |
| 563 | captureDataIdMap.insert(std::make_pair(i, perThreadCaptureData)); |
| 564 | } |
| 565 | |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 566 | std::vector<std::thread> threadsVect; |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 567 | std::vector<std::thread> readThreadsVect; |
| 568 | for (uint32_t i = 0; i < numThreads; ++i) |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 569 | { |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 570 | threadsVect.emplace_back( |
| 571 | std::thread(CaptureDataWriteThreadImpl, std::ref(holder), i, std::ref(periodIdMap[i]))); |
Francis Murtagh | 0696569 | 2019-09-05 16:29:01 +0100 | [diff] [blame] | 572 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 573 | // Verify that the CaptureData goes into the thread in a virgin state |
| 574 | BOOST_CHECK(captureDataIdMap.at(i).GetCapturePeriod() == 0); |
| 575 | BOOST_CHECK(captureDataIdMap.at(i).GetCounterIds().empty()); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 576 | readThreadsVect.emplace_back( |
| 577 | std::thread(CaptureDataReadThreadImpl, std::ref(holder), std::ref(captureDataIdMap.at(i)))); |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 578 | } |
| 579 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 580 | for (uint32_t i = 0; i < numThreads; ++i) |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 581 | { |
| 582 | threadsVect[i].join(); |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 583 | readThreadsVect[i].join(); |
| 584 | } |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 585 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 586 | // Look at the CaptureData that each read thread has filled |
| 587 | // the capture period it read should match the counter ids entry |
| 588 | for (uint32_t i = 0; i < numThreads; ++i) |
| 589 | { |
| 590 | CaptureData perThreadCaptureData = captureDataIdMap.at(i); |
| 591 | BOOST_CHECK(perThreadCaptureData.GetCounterIds() == periodIdMap.at(perThreadCaptureData.GetCapturePeriod())); |
| 592 | } |
Matthew Bentham | 46d1c62 | 2019-09-13 12:45:04 +0100 | [diff] [blame] | 593 | } |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 594 | |
Matthew Bentham | 46d1c62 | 2019-09-13 12:45:04 +0100 | [diff] [blame] | 595 | BOOST_AUTO_TEST_CASE(CaptureDataMethods) |
| 596 | { |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 597 | // Check CaptureData setter and getter functions |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 598 | std::vector<uint16_t> counterIds = { 42, 29, 13 }; |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 599 | CaptureData captureData; |
| 600 | BOOST_CHECK(captureData.GetCapturePeriod() == 0); |
| 601 | BOOST_CHECK((captureData.GetCounterIds()).empty()); |
| 602 | captureData.SetCapturePeriod(150); |
| 603 | captureData.SetCounterIds(counterIds); |
| 604 | BOOST_CHECK(captureData.GetCapturePeriod() == 150); |
| 605 | BOOST_CHECK(captureData.GetCounterIds() == counterIds); |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 606 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 607 | // Check assignment operator |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 608 | CaptureData secondCaptureData; |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 609 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 610 | secondCaptureData = captureData; |
| 611 | BOOST_CHECK(secondCaptureData.GetCapturePeriod() == 150); |
Matthew Bentham | 46d1c62 | 2019-09-13 12:45:04 +0100 | [diff] [blame] | 612 | BOOST_CHECK(secondCaptureData.GetCounterIds() == counterIds); |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 613 | |
| 614 | // Check copy constructor |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 615 | CaptureData copyConstructedCaptureData(captureData); |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 616 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 617 | BOOST_CHECK(copyConstructedCaptureData.GetCapturePeriod() == 150); |
Matthew Bentham | 46d1c62 | 2019-09-13 12:45:04 +0100 | [diff] [blame] | 618 | BOOST_CHECK(copyConstructedCaptureData.GetCounterIds() == counterIds); |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 619 | } |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 620 | |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 621 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceDisabled) |
| 622 | { |
| 623 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 624 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 625 | profilingService.ResetExternalProfilingOptions(options, true); |
| 626 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 627 | profilingService.Update(); |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 628 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 629 | } |
| 630 | |
FinnWilliamsArm | ce2d9d1 | 2019-09-18 10:28:16 +0100 | [diff] [blame] | 631 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceCounterDirectory) |
| 632 | { |
| 633 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 634 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 635 | profilingService.ResetExternalProfilingOptions(options, true); |
FinnWilliamsArm | ce2d9d1 | 2019-09-18 10:28:16 +0100 | [diff] [blame] | 636 | |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 637 | const ICounterDirectory& counterDirectory0 = profilingService.GetCounterDirectory(); |
FinnWilliamsArm | ce2d9d1 | 2019-09-18 10:28:16 +0100 | [diff] [blame] | 638 | BOOST_CHECK(counterDirectory0.GetCounterCount() == 0); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 639 | profilingService.Update(); |
| 640 | BOOST_CHECK(counterDirectory0.GetCounterCount() == 0); |
FinnWilliamsArm | ce2d9d1 | 2019-09-18 10:28:16 +0100 | [diff] [blame] | 641 | |
| 642 | options.m_EnableProfiling = true; |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 643 | profilingService.ResetExternalProfilingOptions(options); |
FinnWilliamsArm | ce2d9d1 | 2019-09-18 10:28:16 +0100 | [diff] [blame] | 644 | |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 645 | const ICounterDirectory& counterDirectory1 = profilingService.GetCounterDirectory(); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 646 | BOOST_CHECK(counterDirectory1.GetCounterCount() == 0); |
| 647 | profilingService.Update(); |
FinnWilliamsArm | ce2d9d1 | 2019-09-18 10:28:16 +0100 | [diff] [blame] | 648 | BOOST_CHECK(counterDirectory1.GetCounterCount() != 0); |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 649 | // Reset the profiling service to stop any running thread |
| 650 | options.m_EnableProfiling = false; |
| 651 | profilingService.ResetExternalProfilingOptions(options, true); |
FinnWilliamsArm | ce2d9d1 | 2019-09-18 10:28:16 +0100 | [diff] [blame] | 652 | } |
| 653 | |
FinnWilliamsArm | f6e534a | 2019-09-16 15:45:42 +0100 | [diff] [blame] | 654 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceCounterValues) |
| 655 | { |
| 656 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 657 | options.m_EnableProfiling = true; |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 658 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 659 | profilingService.ResetExternalProfilingOptions(options, true); |
| 660 | |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 661 | profilingService.Update(); |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 662 | const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory(); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 663 | const Counters& counters = counterDirectory.GetCounters(); |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 664 | BOOST_CHECK(!counters.empty()); |
| 665 | |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 666 | // Get the UID of the first counter for testing; |
FinnWilliamsArm | f6e534a | 2019-09-16 15:45:42 +0100 | [diff] [blame] | 667 | |
| 668 | ProfilingService* profilingServicePtr = &profilingService; |
| 669 | std::vector<std::thread> writers; |
| 670 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 671 | for (int i = 0; i < 100; ++i) |
FinnWilliamsArm | f6e534a | 2019-09-16 15:45:42 +0100 | [diff] [blame] | 672 | { |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 673 | // Increment and decrement the first counter |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 674 | writers.push_back(std::thread(&ProfilingService::IncrementCounterValue, |
| 675 | profilingServicePtr, |
| 676 | armnn::profiling::REGISTERED_BACKENDS)); |
| 677 | |
| 678 | writers.push_back(std::thread(&ProfilingService::IncrementCounterValue, |
| 679 | profilingServicePtr, |
| 680 | armnn::profiling::UNREGISTERED_BACKENDS)); |
| 681 | |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 682 | // Add 10 and subtract 5 from the first counter |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 683 | writers.push_back(std::thread(&ProfilingService::AddCounterValue, |
| 684 | profilingServicePtr, |
| 685 | armnn::profiling::INFERENCES_RUN, |
| 686 | 10)); |
| 687 | writers.push_back(std::thread(&ProfilingService::SubtractCounterValue, |
| 688 | profilingServicePtr, |
| 689 | armnn::profiling::INFERENCES_RUN, |
| 690 | 5)); |
FinnWilliamsArm | f6e534a | 2019-09-16 15:45:42 +0100 | [diff] [blame] | 691 | } |
FinnWilliamsArm | f6e534a | 2019-09-16 15:45:42 +0100 | [diff] [blame] | 692 | std::for_each(writers.begin(), writers.end(), mem_fn(&std::thread::join)); |
| 693 | |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 694 | uint32_t counterValue = 0; |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 695 | BOOST_CHECK(counterValue == |
| 696 | (profilingService.GetCounterValue(armnn::profiling::UNREGISTERED_BACKENDS) |
| 697 | - profilingService.GetCounterValue(armnn::profiling::REGISTERED_BACKENDS))); |
| 698 | BOOST_CHECK(profilingService.GetCounterValue(armnn::profiling::INFERENCES_RUN) == 500); |
FinnWilliamsArm | f6e534a | 2019-09-16 15:45:42 +0100 | [diff] [blame] | 699 | |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 700 | BOOST_CHECK_NO_THROW(profilingService.SetCounterValue(armnn::profiling::UNREGISTERED_BACKENDS, 4)); |
| 701 | BOOST_CHECK_NO_THROW(counterValue = profilingService.GetCounterValue(armnn::profiling::UNREGISTERED_BACKENDS)); |
| 702 | BOOST_CHECK(counterValue == 4); |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 703 | // Reset the profiling service to stop any running thread |
| 704 | options.m_EnableProfiling = false; |
| 705 | profilingService.ResetExternalProfilingOptions(options, true); |
FinnWilliamsArm | f6e534a | 2019-09-16 15:45:42 +0100 | [diff] [blame] | 706 | } |
| 707 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 708 | BOOST_AUTO_TEST_CASE(CheckProfilingObjectUids) |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 709 | { |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 710 | uint16_t uid = 0; |
| 711 | BOOST_CHECK_NO_THROW(uid = GetNextUid()); |
| 712 | BOOST_CHECK(uid >= 1); |
| 713 | |
| 714 | uint16_t nextUid = 0; |
| 715 | BOOST_CHECK_NO_THROW(nextUid = GetNextUid()); |
| 716 | BOOST_CHECK(nextUid > uid); |
| 717 | |
| 718 | std::vector<uint16_t> counterUids; |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 719 | BOOST_CHECK_NO_THROW(counterUids = GetNextCounterUids(uid,0)); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 720 | BOOST_CHECK(counterUids.size() == 1); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 721 | |
| 722 | std::vector<uint16_t> nextCounterUids; |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 723 | BOOST_CHECK_NO_THROW(nextCounterUids = GetNextCounterUids(nextUid, 2)); |
| 724 | BOOST_CHECK(nextCounterUids.size() == 2); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 725 | BOOST_CHECK(nextCounterUids[0] > counterUids[0]); |
| 726 | |
| 727 | std::vector<uint16_t> counterUidsMultiCore; |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 728 | uint16_t thirdUid = 4; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 729 | uint16_t numberOfCores = 13; |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 730 | BOOST_CHECK_NO_THROW(counterUidsMultiCore = GetNextCounterUids(thirdUid, numberOfCores)); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 731 | BOOST_CHECK(counterUidsMultiCore.size() == numberOfCores); |
| 732 | BOOST_CHECK(counterUidsMultiCore.front() >= nextCounterUids[0]); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 733 | for (size_t i = 1; i < numberOfCores; i++) |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 734 | { |
| 735 | BOOST_CHECK(counterUidsMultiCore[i] == counterUidsMultiCore[i - 1] + 1); |
| 736 | } |
| 737 | BOOST_CHECK(counterUidsMultiCore.back() == counterUidsMultiCore.front() + numberOfCores - 1); |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 738 | } |
| 739 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 740 | BOOST_AUTO_TEST_CASE(CheckCounterDirectoryRegisterCategory) |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 741 | { |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 742 | CounterDirectory counterDirectory; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 743 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 0); |
| 744 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 0); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 745 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 746 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 747 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 748 | // Register a category with an invalid name |
| 749 | const Category* noCategory = nullptr; |
| 750 | BOOST_CHECK_THROW(noCategory = counterDirectory.RegisterCategory(""), armnn::InvalidArgumentException); |
| 751 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 0); |
| 752 | BOOST_CHECK(!noCategory); |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 753 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 754 | // Register a category with an invalid name |
| 755 | BOOST_CHECK_THROW(noCategory = counterDirectory.RegisterCategory("invalid category"), |
| 756 | armnn::InvalidArgumentException); |
| 757 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 0); |
| 758 | BOOST_CHECK(!noCategory); |
| 759 | |
| 760 | // Register a new category |
| 761 | const std::string categoryName = "some_category"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 762 | const Category* category = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 763 | BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName)); |
| 764 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 765 | BOOST_CHECK(category); |
| 766 | BOOST_CHECK(category->m_Name == categoryName); |
| 767 | BOOST_CHECK(category->m_Counters.empty()); |
| 768 | BOOST_CHECK(category->m_DeviceUid == 0); |
| 769 | BOOST_CHECK(category->m_CounterSetUid == 0); |
| 770 | |
| 771 | // Get the registered category |
| 772 | const Category* registeredCategory = counterDirectory.GetCategory(categoryName); |
| 773 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 774 | BOOST_CHECK(registeredCategory); |
| 775 | BOOST_CHECK(registeredCategory == category); |
| 776 | |
| 777 | // Try to get a category not registered |
| 778 | const Category* notRegisteredCategory = counterDirectory.GetCategory("not_registered_category"); |
| 779 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 780 | BOOST_CHECK(!notRegisteredCategory); |
| 781 | |
| 782 | // Register a category already registered |
| 783 | const Category* anotherCategory = nullptr; |
| 784 | BOOST_CHECK_THROW(anotherCategory = counterDirectory.RegisterCategory(categoryName), |
| 785 | armnn::InvalidArgumentException); |
| 786 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 787 | BOOST_CHECK(!anotherCategory); |
| 788 | |
| 789 | // Register a device for testing |
| 790 | const std::string deviceName = "some_device"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 791 | const Device* device = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 792 | BOOST_CHECK_NO_THROW(device = counterDirectory.RegisterDevice(deviceName)); |
| 793 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 794 | BOOST_CHECK(device); |
| 795 | BOOST_CHECK(device->m_Uid >= 1); |
| 796 | BOOST_CHECK(device->m_Name == deviceName); |
| 797 | BOOST_CHECK(device->m_Cores == 0); |
| 798 | |
| 799 | // Register a new category not associated to any device |
| 800 | const std::string categoryWoDeviceName = "some_category_without_device"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 801 | const Category* categoryWoDevice = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 802 | BOOST_CHECK_NO_THROW(categoryWoDevice = counterDirectory.RegisterCategory(categoryWoDeviceName, 0)); |
| 803 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 2); |
| 804 | BOOST_CHECK(categoryWoDevice); |
| 805 | BOOST_CHECK(categoryWoDevice->m_Name == categoryWoDeviceName); |
| 806 | BOOST_CHECK(categoryWoDevice->m_Counters.empty()); |
| 807 | BOOST_CHECK(categoryWoDevice->m_DeviceUid == 0); |
| 808 | BOOST_CHECK(categoryWoDevice->m_CounterSetUid == 0); |
| 809 | |
| 810 | // Register a new category associated to an invalid device |
| 811 | const std::string categoryWInvalidDeviceName = "some_category_with_invalid_device"; |
| 812 | |
| 813 | ARMNN_NO_CONVERSION_WARN_BEGIN |
| 814 | uint16_t invalidDeviceUid = device->m_Uid + 10; |
| 815 | ARMNN_NO_CONVERSION_WARN_END |
| 816 | |
| 817 | const Category* categoryWInvalidDevice = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 818 | BOOST_CHECK_THROW(categoryWInvalidDevice = |
| 819 | counterDirectory.RegisterCategory(categoryWInvalidDeviceName, invalidDeviceUid), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 820 | armnn::InvalidArgumentException); |
| 821 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 2); |
| 822 | BOOST_CHECK(!categoryWInvalidDevice); |
| 823 | |
| 824 | // Register a new category associated to a valid device |
| 825 | const std::string categoryWValidDeviceName = "some_category_with_valid_device"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 826 | const Category* categoryWValidDevice = nullptr; |
| 827 | BOOST_CHECK_NO_THROW(categoryWValidDevice = |
| 828 | counterDirectory.RegisterCategory(categoryWValidDeviceName, device->m_Uid)); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 829 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 3); |
| 830 | BOOST_CHECK(categoryWValidDevice); |
| 831 | BOOST_CHECK(categoryWValidDevice != category); |
| 832 | BOOST_CHECK(categoryWValidDevice->m_Name == categoryWValidDeviceName); |
| 833 | BOOST_CHECK(categoryWValidDevice->m_DeviceUid == device->m_Uid); |
| 834 | BOOST_CHECK(categoryWValidDevice->m_CounterSetUid == 0); |
| 835 | |
| 836 | // Register a counter set for testing |
| 837 | const std::string counterSetName = "some_counter_set"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 838 | const CounterSet* counterSet = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 839 | BOOST_CHECK_NO_THROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName)); |
| 840 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1); |
| 841 | BOOST_CHECK(counterSet); |
| 842 | BOOST_CHECK(counterSet->m_Uid >= 1); |
| 843 | BOOST_CHECK(counterSet->m_Name == counterSetName); |
| 844 | BOOST_CHECK(counterSet->m_Count == 0); |
| 845 | |
| 846 | // Register a new category not associated to any counter set |
| 847 | const std::string categoryWoCounterSetName = "some_category_without_counter_set"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 848 | const Category* categoryWoCounterSet = nullptr; |
| 849 | BOOST_CHECK_NO_THROW(categoryWoCounterSet = |
| 850 | counterDirectory.RegisterCategory(categoryWoCounterSetName, armnn::EmptyOptional(), 0)); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 851 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 4); |
| 852 | BOOST_CHECK(categoryWoCounterSet); |
| 853 | BOOST_CHECK(categoryWoCounterSet->m_Name == categoryWoCounterSetName); |
| 854 | BOOST_CHECK(categoryWoCounterSet->m_DeviceUid == 0); |
| 855 | BOOST_CHECK(categoryWoCounterSet->m_CounterSetUid == 0); |
| 856 | |
| 857 | // Register a new category associated to an invalid counter set |
| 858 | const std::string categoryWInvalidCounterSetName = "some_category_with_invalid_counter_set"; |
| 859 | |
| 860 | ARMNN_NO_CONVERSION_WARN_BEGIN |
| 861 | uint16_t invalidCunterSetUid = counterSet->m_Uid + 10; |
| 862 | ARMNN_NO_CONVERSION_WARN_END |
| 863 | |
| 864 | const Category* categoryWInvalidCounterSet = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 865 | BOOST_CHECK_THROW(categoryWInvalidCounterSet = counterDirectory.RegisterCategory( |
| 866 | categoryWInvalidCounterSetName, armnn::EmptyOptional(), invalidCunterSetUid), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 867 | armnn::InvalidArgumentException); |
| 868 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 4); |
| 869 | BOOST_CHECK(!categoryWInvalidCounterSet); |
| 870 | |
| 871 | // Register a new category associated to a valid counter set |
| 872 | const std::string categoryWValidCounterSetName = "some_category_with_valid_counter_set"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 873 | const Category* categoryWValidCounterSet = nullptr; |
| 874 | BOOST_CHECK_NO_THROW(categoryWValidCounterSet = counterDirectory.RegisterCategory( |
| 875 | categoryWValidCounterSetName, armnn::EmptyOptional(), counterSet->m_Uid)); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 876 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 5); |
| 877 | BOOST_CHECK(categoryWValidCounterSet); |
| 878 | BOOST_CHECK(categoryWValidCounterSet != category); |
| 879 | BOOST_CHECK(categoryWValidCounterSet->m_Name == categoryWValidCounterSetName); |
| 880 | BOOST_CHECK(categoryWValidCounterSet->m_DeviceUid == 0); |
| 881 | BOOST_CHECK(categoryWValidCounterSet->m_CounterSetUid == counterSet->m_Uid); |
| 882 | |
| 883 | // Register a new category associated to a valid device and counter set |
| 884 | const std::string categoryWValidDeviceAndValidCounterSetName = "some_category_with_valid_device_and_counter_set"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 885 | const Category* categoryWValidDeviceAndValidCounterSet = nullptr; |
| 886 | BOOST_CHECK_NO_THROW(categoryWValidDeviceAndValidCounterSet = counterDirectory.RegisterCategory( |
| 887 | categoryWValidDeviceAndValidCounterSetName, device->m_Uid, counterSet->m_Uid)); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 888 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 6); |
| 889 | BOOST_CHECK(categoryWValidDeviceAndValidCounterSet); |
| 890 | BOOST_CHECK(categoryWValidDeviceAndValidCounterSet != category); |
| 891 | BOOST_CHECK(categoryWValidDeviceAndValidCounterSet->m_Name == categoryWValidDeviceAndValidCounterSetName); |
| 892 | BOOST_CHECK(categoryWValidDeviceAndValidCounterSet->m_DeviceUid == device->m_Uid); |
| 893 | BOOST_CHECK(categoryWValidDeviceAndValidCounterSet->m_CounterSetUid == counterSet->m_Uid); |
| 894 | } |
| 895 | |
| 896 | BOOST_AUTO_TEST_CASE(CheckCounterDirectoryRegisterDevice) |
| 897 | { |
| 898 | CounterDirectory counterDirectory; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 899 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 0); |
| 900 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 0); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 901 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 902 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 903 | |
| 904 | // Register a device with an invalid name |
| 905 | const Device* noDevice = nullptr; |
| 906 | BOOST_CHECK_THROW(noDevice = counterDirectory.RegisterDevice(""), armnn::InvalidArgumentException); |
| 907 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 0); |
| 908 | BOOST_CHECK(!noDevice); |
| 909 | |
| 910 | // Register a device with an invalid name |
| 911 | BOOST_CHECK_THROW(noDevice = counterDirectory.RegisterDevice("inv@lid nam€"), armnn::InvalidArgumentException); |
| 912 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 0); |
| 913 | BOOST_CHECK(!noDevice); |
| 914 | |
| 915 | // Register a new device with no cores or parent category |
| 916 | const std::string deviceName = "some_device"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 917 | const Device* device = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 918 | BOOST_CHECK_NO_THROW(device = counterDirectory.RegisterDevice(deviceName)); |
| 919 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 920 | BOOST_CHECK(device); |
| 921 | BOOST_CHECK(device->m_Name == deviceName); |
| 922 | BOOST_CHECK(device->m_Uid >= 1); |
| 923 | BOOST_CHECK(device->m_Cores == 0); |
| 924 | |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 925 | // Try getting an unregistered device |
| 926 | const Device* unregisteredDevice = counterDirectory.GetDevice(9999); |
| 927 | BOOST_CHECK(!unregisteredDevice); |
| 928 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 929 | // Get the registered device |
| 930 | const Device* registeredDevice = counterDirectory.GetDevice(device->m_Uid); |
| 931 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 932 | BOOST_CHECK(registeredDevice); |
| 933 | BOOST_CHECK(registeredDevice == device); |
| 934 | |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 935 | // Register a device with the name of a device already registered |
| 936 | const Device* deviceSameName = nullptr; |
| 937 | BOOST_CHECK_THROW(deviceSameName = counterDirectory.RegisterDevice(deviceName), armnn::InvalidArgumentException); |
| 938 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 939 | BOOST_CHECK(!deviceSameName); |
| 940 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 941 | // Register a new device with cores and no parent category |
| 942 | const std::string deviceWCoresName = "some_device_with_cores"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 943 | const Device* deviceWCores = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 944 | BOOST_CHECK_NO_THROW(deviceWCores = counterDirectory.RegisterDevice(deviceWCoresName, 2)); |
| 945 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 2); |
| 946 | BOOST_CHECK(deviceWCores); |
| 947 | BOOST_CHECK(deviceWCores->m_Name == deviceWCoresName); |
| 948 | BOOST_CHECK(deviceWCores->m_Uid >= 1); |
| 949 | BOOST_CHECK(deviceWCores->m_Uid > device->m_Uid); |
| 950 | BOOST_CHECK(deviceWCores->m_Cores == 2); |
| 951 | |
| 952 | // Get the registered device |
| 953 | const Device* registeredDeviceWCores = counterDirectory.GetDevice(deviceWCores->m_Uid); |
| 954 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 2); |
| 955 | BOOST_CHECK(registeredDeviceWCores); |
| 956 | BOOST_CHECK(registeredDeviceWCores == deviceWCores); |
| 957 | BOOST_CHECK(registeredDeviceWCores != device); |
| 958 | |
| 959 | // Register a new device with cores and invalid parent category |
| 960 | const std::string deviceWCoresWInvalidParentCategoryName = "some_device_with_cores_with_invalid_parent_category"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 961 | const Device* deviceWCoresWInvalidParentCategory = nullptr; |
| 962 | BOOST_CHECK_THROW(deviceWCoresWInvalidParentCategory = |
| 963 | counterDirectory.RegisterDevice(deviceWCoresWInvalidParentCategoryName, 3, std::string("")), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 964 | armnn::InvalidArgumentException); |
| 965 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 2); |
| 966 | BOOST_CHECK(!deviceWCoresWInvalidParentCategory); |
| 967 | |
| 968 | // Register a new device with cores and invalid parent category |
| 969 | const std::string deviceWCoresWInvalidParentCategoryName2 = "some_device_with_cores_with_invalid_parent_category2"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 970 | const Device* deviceWCoresWInvalidParentCategory2 = nullptr; |
| 971 | BOOST_CHECK_THROW(deviceWCoresWInvalidParentCategory2 = counterDirectory.RegisterDevice( |
| 972 | deviceWCoresWInvalidParentCategoryName2, 3, std::string("invalid_parent_category")), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 973 | armnn::InvalidArgumentException); |
| 974 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 2); |
| 975 | BOOST_CHECK(!deviceWCoresWInvalidParentCategory2); |
| 976 | |
| 977 | // Register a category for testing |
| 978 | const std::string categoryName = "some_category"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 979 | const Category* category = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 980 | BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName)); |
| 981 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 982 | BOOST_CHECK(category); |
| 983 | BOOST_CHECK(category->m_Name == categoryName); |
| 984 | BOOST_CHECK(category->m_Counters.empty()); |
| 985 | BOOST_CHECK(category->m_DeviceUid == 0); |
| 986 | BOOST_CHECK(category->m_CounterSetUid == 0); |
| 987 | |
| 988 | // Register a new device with cores and valid parent category |
| 989 | const std::string deviceWCoresWValidParentCategoryName = "some_device_with_cores_with_valid_parent_category"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 990 | const Device* deviceWCoresWValidParentCategory = nullptr; |
| 991 | BOOST_CHECK_NO_THROW(deviceWCoresWValidParentCategory = |
| 992 | counterDirectory.RegisterDevice(deviceWCoresWValidParentCategoryName, 4, categoryName)); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 993 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 3); |
| 994 | BOOST_CHECK(deviceWCoresWValidParentCategory); |
| 995 | BOOST_CHECK(deviceWCoresWValidParentCategory->m_Name == deviceWCoresWValidParentCategoryName); |
| 996 | BOOST_CHECK(deviceWCoresWValidParentCategory->m_Uid >= 1); |
| 997 | BOOST_CHECK(deviceWCoresWValidParentCategory->m_Uid > device->m_Uid); |
| 998 | BOOST_CHECK(deviceWCoresWValidParentCategory->m_Uid > deviceWCores->m_Uid); |
| 999 | BOOST_CHECK(deviceWCoresWValidParentCategory->m_Cores == 4); |
| 1000 | BOOST_CHECK(category->m_DeviceUid == deviceWCoresWValidParentCategory->m_Uid); |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1001 | |
| 1002 | // Register a device associated to a category already associated to a different device |
| 1003 | const std::string deviceSameCategoryName = "some_device_with_invalid_parent_category"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1004 | const Device* deviceSameCategory = nullptr; |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1005 | BOOST_CHECK_THROW(deviceSameCategory = counterDirectory.RegisterDevice(deviceSameCategoryName, 0, categoryName), |
| 1006 | armnn::InvalidArgumentException); |
| 1007 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 3); |
| 1008 | BOOST_CHECK(!deviceSameCategory); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | BOOST_AUTO_TEST_CASE(CheckCounterDirectoryRegisterCounterSet) |
| 1012 | { |
| 1013 | CounterDirectory counterDirectory; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1014 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 0); |
| 1015 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 0); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1016 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1017 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1018 | |
| 1019 | // Register a counter set with an invalid name |
| 1020 | const CounterSet* noCounterSet = nullptr; |
| 1021 | BOOST_CHECK_THROW(noCounterSet = counterDirectory.RegisterCounterSet(""), armnn::InvalidArgumentException); |
| 1022 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0); |
| 1023 | BOOST_CHECK(!noCounterSet); |
| 1024 | |
| 1025 | // Register a counter set with an invalid name |
| 1026 | BOOST_CHECK_THROW(noCounterSet = counterDirectory.RegisterCounterSet("invalid name"), |
| 1027 | armnn::InvalidArgumentException); |
| 1028 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0); |
| 1029 | BOOST_CHECK(!noCounterSet); |
| 1030 | |
| 1031 | // Register a new counter set with no count or parent category |
| 1032 | const std::string counterSetName = "some_counter_set"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1033 | const CounterSet* counterSet = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1034 | BOOST_CHECK_NO_THROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName)); |
| 1035 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1); |
| 1036 | BOOST_CHECK(counterSet); |
| 1037 | BOOST_CHECK(counterSet->m_Name == counterSetName); |
| 1038 | BOOST_CHECK(counterSet->m_Uid >= 1); |
| 1039 | BOOST_CHECK(counterSet->m_Count == 0); |
| 1040 | |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1041 | // Try getting an unregistered counter set |
| 1042 | const CounterSet* unregisteredCounterSet = counterDirectory.GetCounterSet(9999); |
| 1043 | BOOST_CHECK(!unregisteredCounterSet); |
| 1044 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1045 | // Get the registered counter set |
| 1046 | const CounterSet* registeredCounterSet = counterDirectory.GetCounterSet(counterSet->m_Uid); |
| 1047 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1); |
| 1048 | BOOST_CHECK(registeredCounterSet); |
| 1049 | BOOST_CHECK(registeredCounterSet == counterSet); |
| 1050 | |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1051 | // Register a counter set with the name of a counter set already registered |
| 1052 | const CounterSet* counterSetSameName = nullptr; |
| 1053 | BOOST_CHECK_THROW(counterSetSameName = counterDirectory.RegisterCounterSet(counterSetName), |
| 1054 | armnn::InvalidArgumentException); |
| 1055 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1); |
| 1056 | BOOST_CHECK(!counterSetSameName); |
| 1057 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1058 | // Register a new counter set with count and no parent category |
| 1059 | const std::string counterSetWCountName = "some_counter_set_with_count"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1060 | const CounterSet* counterSetWCount = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1061 | BOOST_CHECK_NO_THROW(counterSetWCount = counterDirectory.RegisterCounterSet(counterSetWCountName, 37)); |
| 1062 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 2); |
| 1063 | BOOST_CHECK(counterSetWCount); |
| 1064 | BOOST_CHECK(counterSetWCount->m_Name == counterSetWCountName); |
| 1065 | BOOST_CHECK(counterSetWCount->m_Uid >= 1); |
| 1066 | BOOST_CHECK(counterSetWCount->m_Uid > counterSet->m_Uid); |
| 1067 | BOOST_CHECK(counterSetWCount->m_Count == 37); |
| 1068 | |
| 1069 | // Get the registered counter set |
| 1070 | const CounterSet* registeredCounterSetWCount = counterDirectory.GetCounterSet(counterSetWCount->m_Uid); |
| 1071 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 2); |
| 1072 | BOOST_CHECK(registeredCounterSetWCount); |
| 1073 | BOOST_CHECK(registeredCounterSetWCount == counterSetWCount); |
| 1074 | BOOST_CHECK(registeredCounterSetWCount != counterSet); |
| 1075 | |
| 1076 | // Register a new counter set with count and invalid parent category |
| 1077 | const std::string counterSetWCountWInvalidParentCategoryName = "some_counter_set_with_count_" |
| 1078 | "with_invalid_parent_category"; |
| 1079 | const CounterSet* counterSetWCountWInvalidParentCategory = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1080 | BOOST_CHECK_THROW(counterSetWCountWInvalidParentCategory = counterDirectory.RegisterCounterSet( |
| 1081 | counterSetWCountWInvalidParentCategoryName, 42, std::string("")), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1082 | armnn::InvalidArgumentException); |
| 1083 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 2); |
| 1084 | BOOST_CHECK(!counterSetWCountWInvalidParentCategory); |
| 1085 | |
| 1086 | // Register a new counter set with count and invalid parent category |
| 1087 | const std::string counterSetWCountWInvalidParentCategoryName2 = "some_counter_set_with_count_" |
| 1088 | "with_invalid_parent_category2"; |
| 1089 | const CounterSet* counterSetWCountWInvalidParentCategory2 = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1090 | BOOST_CHECK_THROW(counterSetWCountWInvalidParentCategory2 = counterDirectory.RegisterCounterSet( |
| 1091 | counterSetWCountWInvalidParentCategoryName2, 42, std::string("invalid_parent_category")), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1092 | armnn::InvalidArgumentException); |
| 1093 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 2); |
| 1094 | BOOST_CHECK(!counterSetWCountWInvalidParentCategory2); |
| 1095 | |
| 1096 | // Register a category for testing |
| 1097 | const std::string categoryName = "some_category"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1098 | const Category* category = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1099 | BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName)); |
| 1100 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 1101 | BOOST_CHECK(category); |
| 1102 | BOOST_CHECK(category->m_Name == categoryName); |
| 1103 | BOOST_CHECK(category->m_Counters.empty()); |
| 1104 | BOOST_CHECK(category->m_DeviceUid == 0); |
| 1105 | BOOST_CHECK(category->m_CounterSetUid == 0); |
| 1106 | |
| 1107 | // Register a new counter set with count and valid parent category |
| 1108 | const std::string counterSetWCountWValidParentCategoryName = "some_counter_set_with_count_" |
| 1109 | "with_valid_parent_category"; |
| 1110 | const CounterSet* counterSetWCountWValidParentCategory = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1111 | BOOST_CHECK_NO_THROW(counterSetWCountWValidParentCategory = counterDirectory.RegisterCounterSet( |
| 1112 | counterSetWCountWValidParentCategoryName, 42, categoryName)); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1113 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 3); |
| 1114 | BOOST_CHECK(counterSetWCountWValidParentCategory); |
| 1115 | BOOST_CHECK(counterSetWCountWValidParentCategory->m_Name == counterSetWCountWValidParentCategoryName); |
| 1116 | BOOST_CHECK(counterSetWCountWValidParentCategory->m_Uid >= 1); |
| 1117 | BOOST_CHECK(counterSetWCountWValidParentCategory->m_Uid > counterSet->m_Uid); |
| 1118 | BOOST_CHECK(counterSetWCountWValidParentCategory->m_Uid > counterSetWCount->m_Uid); |
| 1119 | BOOST_CHECK(counterSetWCountWValidParentCategory->m_Count == 42); |
| 1120 | BOOST_CHECK(category->m_CounterSetUid == counterSetWCountWValidParentCategory->m_Uid); |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1121 | |
| 1122 | // Register a counter set associated to a category already associated to a different counter set |
| 1123 | const std::string counterSetSameCategoryName = "some_counter_set_with_invalid_parent_category"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1124 | const CounterSet* counterSetSameCategory = nullptr; |
| 1125 | BOOST_CHECK_THROW(counterSetSameCategory = |
| 1126 | counterDirectory.RegisterCounterSet(counterSetSameCategoryName, 0, categoryName), |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1127 | armnn::InvalidArgumentException); |
| 1128 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 3); |
| 1129 | BOOST_CHECK(!counterSetSameCategory); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | BOOST_AUTO_TEST_CASE(CheckCounterDirectoryRegisterCounter) |
| 1133 | { |
| 1134 | CounterDirectory counterDirectory; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1135 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 0); |
| 1136 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 0); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1137 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1138 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1139 | |
| 1140 | // Register a counter with an invalid parent category name |
| 1141 | const Counter* noCounter = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1142 | BOOST_CHECK_THROW(noCounter = |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1143 | counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1144 | 0, |
| 1145 | "", |
| 1146 | 0, |
| 1147 | 1, |
| 1148 | 123.45f, |
| 1149 | "valid ", |
| 1150 | "name"), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1151 | armnn::InvalidArgumentException); |
| 1152 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1153 | BOOST_CHECK(!noCounter); |
| 1154 | |
| 1155 | // Register a counter with an invalid parent category name |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1156 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1157 | 1, |
| 1158 | "invalid parent category", |
| 1159 | 0, |
| 1160 | 1, |
| 1161 | 123.45f, |
| 1162 | "valid name", |
| 1163 | "valid description"), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1164 | armnn::InvalidArgumentException); |
| 1165 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1166 | BOOST_CHECK(!noCounter); |
| 1167 | |
| 1168 | // Register a counter with an invalid class |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1169 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1170 | 2, |
| 1171 | "valid_parent_category", |
| 1172 | 2, |
| 1173 | 1, |
| 1174 | 123.45f, |
| 1175 | "valid " |
| 1176 | "name", |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1177 | "valid description"), |
| 1178 | armnn::InvalidArgumentException); |
| 1179 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1180 | BOOST_CHECK(!noCounter); |
| 1181 | |
| 1182 | // Register a counter with an invalid interpolation |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1183 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1184 | 4, |
| 1185 | "valid_parent_category", |
| 1186 | 0, |
| 1187 | 3, |
| 1188 | 123.45f, |
| 1189 | "valid " |
| 1190 | "name", |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1191 | "valid description"), |
| 1192 | armnn::InvalidArgumentException); |
| 1193 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1194 | BOOST_CHECK(!noCounter); |
| 1195 | |
| 1196 | // Register a counter with an invalid multiplier |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1197 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1198 | 5, |
| 1199 | "valid_parent_category", |
| 1200 | 0, |
| 1201 | 1, |
| 1202 | .0f, |
| 1203 | "valid " |
| 1204 | "name", |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1205 | "valid description"), |
| 1206 | armnn::InvalidArgumentException); |
| 1207 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1208 | BOOST_CHECK(!noCounter); |
| 1209 | |
| 1210 | // Register a counter with an invalid name |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1211 | BOOST_CHECK_THROW( |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1212 | noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1213 | 6, |
| 1214 | "valid_parent_category", |
| 1215 | 0, |
| 1216 | 1, |
| 1217 | 123.45f, |
| 1218 | "", |
| 1219 | "valid description"), |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1220 | armnn::InvalidArgumentException); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1221 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1222 | BOOST_CHECK(!noCounter); |
| 1223 | |
| 1224 | // Register a counter with an invalid name |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1225 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1226 | 7, |
| 1227 | "valid_parent_category", |
| 1228 | 0, |
| 1229 | 1, |
| 1230 | 123.45f, |
| 1231 | "invalid nam€", |
| 1232 | "valid description"), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1233 | armnn::InvalidArgumentException); |
| 1234 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1235 | BOOST_CHECK(!noCounter); |
| 1236 | |
| 1237 | // Register a counter with an invalid description |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1238 | BOOST_CHECK_THROW(noCounter = |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1239 | counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1240 | 8, |
| 1241 | "valid_parent_category", |
| 1242 | 0, |
| 1243 | 1, |
| 1244 | 123.45f, |
| 1245 | "valid name", |
| 1246 | ""), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1247 | armnn::InvalidArgumentException); |
| 1248 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1249 | BOOST_CHECK(!noCounter); |
| 1250 | |
| 1251 | // Register a counter with an invalid description |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1252 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1253 | 9, |
| 1254 | "valid_parent_category", |
| 1255 | 0, |
| 1256 | 1, |
| 1257 | 123.45f, |
| 1258 | "valid " |
| 1259 | "name", |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1260 | "inv@lid description"), |
| 1261 | armnn::InvalidArgumentException); |
| 1262 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1263 | BOOST_CHECK(!noCounter); |
| 1264 | |
| 1265 | // Register a counter with an invalid unit2 |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1266 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1267 | 10, |
| 1268 | "valid_parent_category", |
| 1269 | 0, |
| 1270 | 1, |
| 1271 | 123.45f, |
| 1272 | "valid name", |
| 1273 | "valid description", |
| 1274 | std::string("Mb/s2")), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1275 | armnn::InvalidArgumentException); |
| 1276 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1277 | BOOST_CHECK(!noCounter); |
| 1278 | |
| 1279 | // Register a counter with a non-existing parent category name |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1280 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1281 | 11, |
| 1282 | "invalid_parent_category", |
| 1283 | 0, |
| 1284 | 1, |
| 1285 | 123.45f, |
| 1286 | "valid name", |
| 1287 | "valid description"), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1288 | armnn::InvalidArgumentException); |
| 1289 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1290 | BOOST_CHECK(!noCounter); |
| 1291 | |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1292 | // Try getting an unregistered counter |
| 1293 | const Counter* unregisteredCounter = counterDirectory.GetCounter(9999); |
| 1294 | BOOST_CHECK(!unregisteredCounter); |
| 1295 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1296 | // Register a category for testing |
| 1297 | const std::string categoryName = "some_category"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1298 | const Category* category = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1299 | BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName)); |
| 1300 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 1301 | BOOST_CHECK(category); |
| 1302 | BOOST_CHECK(category->m_Name == categoryName); |
| 1303 | BOOST_CHECK(category->m_Counters.empty()); |
| 1304 | BOOST_CHECK(category->m_DeviceUid == 0); |
| 1305 | BOOST_CHECK(category->m_CounterSetUid == 0); |
| 1306 | |
| 1307 | // Register a counter with a valid parent category name |
| 1308 | const Counter* counter = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1309 | BOOST_CHECK_NO_THROW( |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1310 | counter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1311 | 12, |
| 1312 | categoryName, |
| 1313 | 0, |
| 1314 | 1, |
| 1315 | 123.45f, |
| 1316 | "valid name", |
| 1317 | "valid description")); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1318 | BOOST_CHECK(counterDirectory.GetCounterCount() == 1); |
| 1319 | BOOST_CHECK(counter); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1320 | BOOST_CHECK(counter->m_MaxCounterUid == counter->m_Uid); |
| 1321 | BOOST_CHECK(counter->m_Class == 0); |
| 1322 | BOOST_CHECK(counter->m_Interpolation == 1); |
| 1323 | BOOST_CHECK(counter->m_Multiplier == 123.45f); |
| 1324 | BOOST_CHECK(counter->m_Name == "valid name"); |
| 1325 | BOOST_CHECK(counter->m_Description == "valid description"); |
| 1326 | BOOST_CHECK(counter->m_Units == ""); |
| 1327 | BOOST_CHECK(counter->m_DeviceUid == 0); |
| 1328 | BOOST_CHECK(counter->m_CounterSetUid == 0); |
| 1329 | BOOST_CHECK(category->m_Counters.size() == 1); |
| 1330 | BOOST_CHECK(category->m_Counters.back() == counter->m_Uid); |
| 1331 | |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1332 | // Register a counter with a name of a counter already registered for the given parent category name |
| 1333 | const Counter* counterSameName = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1334 | BOOST_CHECK_THROW(counterSameName = |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1335 | counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1336 | 13, |
| 1337 | categoryName, |
| 1338 | 0, |
| 1339 | 0, |
| 1340 | 1.0f, |
| 1341 | "valid name", |
| 1342 | "valid description", |
| 1343 | std::string("description")), |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1344 | armnn::InvalidArgumentException); |
| 1345 | BOOST_CHECK(counterDirectory.GetCounterCount() == 1); |
| 1346 | BOOST_CHECK(!counterSameName); |
| 1347 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1348 | // Register a counter with a valid parent category name and units |
| 1349 | const Counter* counterWUnits = nullptr; |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1350 | BOOST_CHECK_NO_THROW(counterWUnits = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1351 | 14, |
| 1352 | categoryName, |
| 1353 | 0, |
| 1354 | 1, |
| 1355 | 123.45f, |
| 1356 | "valid name 2", |
| 1357 | "valid description", |
| 1358 | std::string("Mnnsq2"))); // Units |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1359 | BOOST_CHECK(counterDirectory.GetCounterCount() == 2); |
| 1360 | BOOST_CHECK(counterWUnits); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1361 | BOOST_CHECK(counterWUnits->m_Uid > counter->m_Uid); |
| 1362 | BOOST_CHECK(counterWUnits->m_MaxCounterUid == counterWUnits->m_Uid); |
| 1363 | BOOST_CHECK(counterWUnits->m_Class == 0); |
| 1364 | BOOST_CHECK(counterWUnits->m_Interpolation == 1); |
| 1365 | BOOST_CHECK(counterWUnits->m_Multiplier == 123.45f); |
| 1366 | BOOST_CHECK(counterWUnits->m_Name == "valid name 2"); |
| 1367 | BOOST_CHECK(counterWUnits->m_Description == "valid description"); |
| 1368 | BOOST_CHECK(counterWUnits->m_Units == "Mnnsq2"); |
| 1369 | BOOST_CHECK(counterWUnits->m_DeviceUid == 0); |
| 1370 | BOOST_CHECK(counterWUnits->m_CounterSetUid == 0); |
| 1371 | BOOST_CHECK(category->m_Counters.size() == 2); |
| 1372 | BOOST_CHECK(category->m_Counters.back() == counterWUnits->m_Uid); |
| 1373 | |
| 1374 | // Register a counter with a valid parent category name and not associated with a device |
| 1375 | const Counter* counterWoDevice = nullptr; |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1376 | BOOST_CHECK_NO_THROW(counterWoDevice = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1377 | 26, |
| 1378 | categoryName, |
| 1379 | 0, |
| 1380 | 1, |
| 1381 | 123.45f, |
| 1382 | "valid name 3", |
| 1383 | "valid description", |
| 1384 | armnn::EmptyOptional(),// Units |
| 1385 | armnn::EmptyOptional(),// Number of cores |
| 1386 | 0)); // Device UID |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1387 | BOOST_CHECK(counterDirectory.GetCounterCount() == 3); |
| 1388 | BOOST_CHECK(counterWoDevice); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1389 | BOOST_CHECK(counterWoDevice->m_Uid > counter->m_Uid); |
| 1390 | BOOST_CHECK(counterWoDevice->m_MaxCounterUid == counterWoDevice->m_Uid); |
| 1391 | BOOST_CHECK(counterWoDevice->m_Class == 0); |
| 1392 | BOOST_CHECK(counterWoDevice->m_Interpolation == 1); |
| 1393 | BOOST_CHECK(counterWoDevice->m_Multiplier == 123.45f); |
| 1394 | BOOST_CHECK(counterWoDevice->m_Name == "valid name 3"); |
| 1395 | BOOST_CHECK(counterWoDevice->m_Description == "valid description"); |
| 1396 | BOOST_CHECK(counterWoDevice->m_Units == ""); |
| 1397 | BOOST_CHECK(counterWoDevice->m_DeviceUid == 0); |
| 1398 | BOOST_CHECK(counterWoDevice->m_CounterSetUid == 0); |
| 1399 | BOOST_CHECK(category->m_Counters.size() == 3); |
| 1400 | BOOST_CHECK(category->m_Counters.back() == counterWoDevice->m_Uid); |
| 1401 | |
| 1402 | // Register a counter with a valid parent category name and associated to an invalid device |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1403 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1404 | 15, |
| 1405 | categoryName, |
| 1406 | 0, |
| 1407 | 1, |
| 1408 | 123.45f, |
| 1409 | "valid name 4", |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1410 | "valid description", |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1411 | armnn::EmptyOptional(), // Units |
| 1412 | armnn::EmptyOptional(), // Number of cores |
| 1413 | 100), // Device UID |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1414 | armnn::InvalidArgumentException); |
| 1415 | BOOST_CHECK(counterDirectory.GetCounterCount() == 3); |
| 1416 | BOOST_CHECK(!noCounter); |
| 1417 | |
| 1418 | // Register a device for testing |
| 1419 | const std::string deviceName = "some_device"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1420 | const Device* device = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1421 | BOOST_CHECK_NO_THROW(device = counterDirectory.RegisterDevice(deviceName)); |
| 1422 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 1423 | BOOST_CHECK(device); |
| 1424 | BOOST_CHECK(device->m_Name == deviceName); |
| 1425 | BOOST_CHECK(device->m_Uid >= 1); |
| 1426 | BOOST_CHECK(device->m_Cores == 0); |
| 1427 | |
| 1428 | // Register a counter with a valid parent category name and associated to a device |
| 1429 | const Counter* counterWDevice = nullptr; |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1430 | BOOST_CHECK_NO_THROW(counterWDevice = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1431 | 16, |
| 1432 | categoryName, |
| 1433 | 0, |
| 1434 | 1, |
| 1435 | 123.45f, |
| 1436 | "valid name 5", |
| 1437 | std::string("valid description"), |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1438 | armnn::EmptyOptional(), // Units |
| 1439 | armnn::EmptyOptional(), // Number of cores |
| 1440 | device->m_Uid)); // Device UID |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1441 | BOOST_CHECK(counterDirectory.GetCounterCount() == 4); |
| 1442 | BOOST_CHECK(counterWDevice); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1443 | BOOST_CHECK(counterWDevice->m_Uid > counter->m_Uid); |
| 1444 | BOOST_CHECK(counterWDevice->m_MaxCounterUid == counterWDevice->m_Uid); |
| 1445 | BOOST_CHECK(counterWDevice->m_Class == 0); |
| 1446 | BOOST_CHECK(counterWDevice->m_Interpolation == 1); |
| 1447 | BOOST_CHECK(counterWDevice->m_Multiplier == 123.45f); |
| 1448 | BOOST_CHECK(counterWDevice->m_Name == "valid name 5"); |
| 1449 | BOOST_CHECK(counterWDevice->m_Description == "valid description"); |
| 1450 | BOOST_CHECK(counterWDevice->m_Units == ""); |
| 1451 | BOOST_CHECK(counterWDevice->m_DeviceUid == device->m_Uid); |
| 1452 | BOOST_CHECK(counterWDevice->m_CounterSetUid == 0); |
| 1453 | BOOST_CHECK(category->m_Counters.size() == 4); |
| 1454 | BOOST_CHECK(category->m_Counters.back() == counterWDevice->m_Uid); |
| 1455 | |
| 1456 | // Register a counter with a valid parent category name and not associated with a counter set |
| 1457 | const Counter* counterWoCounterSet = nullptr; |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1458 | BOOST_CHECK_NO_THROW(counterWoCounterSet = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1459 | 17, |
| 1460 | categoryName, |
| 1461 | 0, |
| 1462 | 1, |
| 1463 | 123.45f, |
| 1464 | "valid name 6", |
| 1465 | "valid description", |
| 1466 | armnn::EmptyOptional(),// Units |
| 1467 | armnn::EmptyOptional(),// No of cores |
| 1468 | armnn::EmptyOptional(),// Device UID |
| 1469 | 0)); // CounterSet UID |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1470 | BOOST_CHECK(counterDirectory.GetCounterCount() == 5); |
| 1471 | BOOST_CHECK(counterWoCounterSet); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1472 | BOOST_CHECK(counterWoCounterSet->m_Uid > counter->m_Uid); |
| 1473 | BOOST_CHECK(counterWoCounterSet->m_MaxCounterUid == counterWoCounterSet->m_Uid); |
| 1474 | BOOST_CHECK(counterWoCounterSet->m_Class == 0); |
| 1475 | BOOST_CHECK(counterWoCounterSet->m_Interpolation == 1); |
| 1476 | BOOST_CHECK(counterWoCounterSet->m_Multiplier == 123.45f); |
| 1477 | BOOST_CHECK(counterWoCounterSet->m_Name == "valid name 6"); |
| 1478 | BOOST_CHECK(counterWoCounterSet->m_Description == "valid description"); |
| 1479 | BOOST_CHECK(counterWoCounterSet->m_Units == ""); |
| 1480 | BOOST_CHECK(counterWoCounterSet->m_DeviceUid == 0); |
| 1481 | BOOST_CHECK(counterWoCounterSet->m_CounterSetUid == 0); |
| 1482 | BOOST_CHECK(category->m_Counters.size() == 5); |
| 1483 | BOOST_CHECK(category->m_Counters.back() == counterWoCounterSet->m_Uid); |
| 1484 | |
| 1485 | // Register a counter with a valid parent category name and associated to an invalid counter set |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1486 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1487 | 18, |
| 1488 | categoryName, |
| 1489 | 0, |
| 1490 | 1, |
| 1491 | 123.45f, |
| 1492 | "valid ", |
| 1493 | "name 7", |
| 1494 | std::string("valid description"), |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1495 | armnn::EmptyOptional(), // Units |
| 1496 | armnn::EmptyOptional(), // Number of cores |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1497 | 100), // Counter set UID |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1498 | armnn::InvalidArgumentException); |
| 1499 | BOOST_CHECK(counterDirectory.GetCounterCount() == 5); |
| 1500 | BOOST_CHECK(!noCounter); |
| 1501 | |
| 1502 | // Register a counter with a valid parent category name and with a given number of cores |
| 1503 | const Counter* counterWNumberOfCores = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1504 | uint16_t numberOfCores = 15; |
| 1505 | BOOST_CHECK_NO_THROW(counterWNumberOfCores = counterDirectory.RegisterCounter( |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1506 | armnn::profiling::BACKEND_ID, 50, |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1507 | categoryName, 0, 1, 123.45f, "valid name 8", "valid description", |
| 1508 | armnn::EmptyOptional(), // Units |
| 1509 | numberOfCores, // Number of cores |
| 1510 | armnn::EmptyOptional(), // Device UID |
| 1511 | armnn::EmptyOptional())); // Counter set UID |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1512 | BOOST_CHECK(counterDirectory.GetCounterCount() == 20); |
| 1513 | BOOST_CHECK(counterWNumberOfCores); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1514 | BOOST_CHECK(counterWNumberOfCores->m_Uid > counter->m_Uid); |
| 1515 | BOOST_CHECK(counterWNumberOfCores->m_MaxCounterUid == counterWNumberOfCores->m_Uid + numberOfCores - 1); |
| 1516 | BOOST_CHECK(counterWNumberOfCores->m_Class == 0); |
| 1517 | BOOST_CHECK(counterWNumberOfCores->m_Interpolation == 1); |
| 1518 | BOOST_CHECK(counterWNumberOfCores->m_Multiplier == 123.45f); |
| 1519 | BOOST_CHECK(counterWNumberOfCores->m_Name == "valid name 8"); |
| 1520 | BOOST_CHECK(counterWNumberOfCores->m_Description == "valid description"); |
| 1521 | BOOST_CHECK(counterWNumberOfCores->m_Units == ""); |
| 1522 | BOOST_CHECK(counterWNumberOfCores->m_DeviceUid == 0); |
| 1523 | BOOST_CHECK(counterWNumberOfCores->m_CounterSetUid == 0); |
| 1524 | BOOST_CHECK(category->m_Counters.size() == 20); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1525 | for (size_t i = 0; i < numberOfCores; i++) |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1526 | { |
| 1527 | BOOST_CHECK(category->m_Counters[category->m_Counters.size() - numberOfCores + i] == |
| 1528 | counterWNumberOfCores->m_Uid + i); |
| 1529 | } |
| 1530 | |
| 1531 | // Register a multi-core device for testing |
| 1532 | const std::string multiCoreDeviceName = "some_multi_core_device"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1533 | const Device* multiCoreDevice = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1534 | BOOST_CHECK_NO_THROW(multiCoreDevice = counterDirectory.RegisterDevice(multiCoreDeviceName, 4)); |
| 1535 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 2); |
| 1536 | BOOST_CHECK(multiCoreDevice); |
| 1537 | BOOST_CHECK(multiCoreDevice->m_Name == multiCoreDeviceName); |
| 1538 | BOOST_CHECK(multiCoreDevice->m_Uid >= 1); |
| 1539 | BOOST_CHECK(multiCoreDevice->m_Cores == 4); |
| 1540 | |
| 1541 | // Register a counter with a valid parent category name and associated to the multi-core device |
| 1542 | const Counter* counterWMultiCoreDevice = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1543 | BOOST_CHECK_NO_THROW(counterWMultiCoreDevice = counterDirectory.RegisterCounter( |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1544 | armnn::profiling::BACKEND_ID, 19, categoryName, 0, 1, |
| 1545 | 123.45f, "valid name 9", "valid description", |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1546 | armnn::EmptyOptional(), // Units |
| 1547 | armnn::EmptyOptional(), // Number of cores |
| 1548 | multiCoreDevice->m_Uid, // Device UID |
| 1549 | armnn::EmptyOptional())); // Counter set UID |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1550 | BOOST_CHECK(counterDirectory.GetCounterCount() == 24); |
| 1551 | BOOST_CHECK(counterWMultiCoreDevice); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1552 | BOOST_CHECK(counterWMultiCoreDevice->m_Uid > counter->m_Uid); |
| 1553 | BOOST_CHECK(counterWMultiCoreDevice->m_MaxCounterUid == |
| 1554 | counterWMultiCoreDevice->m_Uid + multiCoreDevice->m_Cores - 1); |
| 1555 | BOOST_CHECK(counterWMultiCoreDevice->m_Class == 0); |
| 1556 | BOOST_CHECK(counterWMultiCoreDevice->m_Interpolation == 1); |
| 1557 | BOOST_CHECK(counterWMultiCoreDevice->m_Multiplier == 123.45f); |
| 1558 | BOOST_CHECK(counterWMultiCoreDevice->m_Name == "valid name 9"); |
| 1559 | BOOST_CHECK(counterWMultiCoreDevice->m_Description == "valid description"); |
| 1560 | BOOST_CHECK(counterWMultiCoreDevice->m_Units == ""); |
| 1561 | BOOST_CHECK(counterWMultiCoreDevice->m_DeviceUid == multiCoreDevice->m_Uid); |
| 1562 | BOOST_CHECK(counterWMultiCoreDevice->m_CounterSetUid == 0); |
| 1563 | BOOST_CHECK(category->m_Counters.size() == 24); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1564 | for (size_t i = 0; i < 4; i++) |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1565 | { |
| 1566 | BOOST_CHECK(category->m_Counters[category->m_Counters.size() - 4 + i] == counterWMultiCoreDevice->m_Uid + i); |
| 1567 | } |
| 1568 | |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1569 | // Register a multi-core device associate to a parent category for testing |
| 1570 | const std::string multiCoreDeviceNameWParentCategory = "some_multi_core_device_with_parent_category"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1571 | const Device* multiCoreDeviceWParentCategory = nullptr; |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1572 | BOOST_CHECK_NO_THROW(multiCoreDeviceWParentCategory = |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1573 | counterDirectory.RegisterDevice(multiCoreDeviceNameWParentCategory, 2, categoryName)); |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1574 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 3); |
| 1575 | BOOST_CHECK(multiCoreDeviceWParentCategory); |
| 1576 | BOOST_CHECK(multiCoreDeviceWParentCategory->m_Name == multiCoreDeviceNameWParentCategory); |
| 1577 | BOOST_CHECK(multiCoreDeviceWParentCategory->m_Uid >= 1); |
| 1578 | BOOST_CHECK(multiCoreDeviceWParentCategory->m_Cores == 2); |
| 1579 | |
| 1580 | // Register a counter with a valid parent category name and getting the number of cores of the multi-core device |
| 1581 | // associated to that category |
| 1582 | const Counter* counterWMultiCoreDeviceWParentCategory = nullptr; |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1583 | BOOST_CHECK_NO_THROW(counterWMultiCoreDeviceWParentCategory = |
| 1584 | counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, |
| 1585 | 100, |
| 1586 | categoryName, |
| 1587 | 0, |
| 1588 | 1, |
| 1589 | 123.45f, |
| 1590 | "valid name 10", |
| 1591 | "valid description", |
| 1592 | armnn::EmptyOptional(),// Units |
| 1593 | armnn::EmptyOptional(),// Number of cores |
| 1594 | armnn::EmptyOptional(),// Device UID |
| 1595 | armnn::EmptyOptional()));// Counter set UID |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1596 | BOOST_CHECK(counterDirectory.GetCounterCount() == 26); |
| 1597 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory); |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1598 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Uid > counter->m_Uid); |
| 1599 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_MaxCounterUid == |
| 1600 | counterWMultiCoreDeviceWParentCategory->m_Uid + multiCoreDeviceWParentCategory->m_Cores - 1); |
| 1601 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Class == 0); |
| 1602 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Interpolation == 1); |
| 1603 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Multiplier == 123.45f); |
| 1604 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Name == "valid name 10"); |
| 1605 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Description == "valid description"); |
| 1606 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Units == ""); |
| 1607 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_DeviceUid == 0); |
| 1608 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_CounterSetUid == 0); |
| 1609 | BOOST_CHECK(category->m_Counters.size() == 26); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1610 | for (size_t i = 0; i < 2; i++) |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1611 | { |
| 1612 | BOOST_CHECK(category->m_Counters[category->m_Counters.size() - 2 + i] == |
| 1613 | counterWMultiCoreDeviceWParentCategory->m_Uid + i); |
| 1614 | } |
| 1615 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1616 | // Register a counter set for testing |
| 1617 | const std::string counterSetName = "some_counter_set"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1618 | const CounterSet* counterSet = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1619 | BOOST_CHECK_NO_THROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName)); |
| 1620 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1); |
| 1621 | BOOST_CHECK(counterSet); |
| 1622 | BOOST_CHECK(counterSet->m_Name == counterSetName); |
| 1623 | BOOST_CHECK(counterSet->m_Uid >= 1); |
| 1624 | BOOST_CHECK(counterSet->m_Count == 0); |
| 1625 | |
| 1626 | // Register a counter with a valid parent category name and associated to a counter set |
| 1627 | const Counter* counterWCounterSet = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1628 | BOOST_CHECK_NO_THROW(counterWCounterSet = counterDirectory.RegisterCounter( |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1629 | armnn::profiling::BACKEND_ID, 300, |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1630 | categoryName, 0, 1, 123.45f, "valid name 11", "valid description", |
| 1631 | armnn::EmptyOptional(), // Units |
| 1632 | 0, // Number of cores |
| 1633 | armnn::EmptyOptional(), // Device UID |
| 1634 | counterSet->m_Uid)); // Counter set UID |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1635 | BOOST_CHECK(counterDirectory.GetCounterCount() == 27); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1636 | BOOST_CHECK(counterWCounterSet); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1637 | BOOST_CHECK(counterWCounterSet->m_Uid > counter->m_Uid); |
| 1638 | BOOST_CHECK(counterWCounterSet->m_MaxCounterUid == counterWCounterSet->m_Uid); |
| 1639 | BOOST_CHECK(counterWCounterSet->m_Class == 0); |
| 1640 | BOOST_CHECK(counterWCounterSet->m_Interpolation == 1); |
| 1641 | BOOST_CHECK(counterWCounterSet->m_Multiplier == 123.45f); |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1642 | BOOST_CHECK(counterWCounterSet->m_Name == "valid name 11"); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1643 | BOOST_CHECK(counterWCounterSet->m_Description == "valid description"); |
| 1644 | BOOST_CHECK(counterWCounterSet->m_Units == ""); |
| 1645 | BOOST_CHECK(counterWCounterSet->m_DeviceUid == 0); |
| 1646 | BOOST_CHECK(counterWCounterSet->m_CounterSetUid == counterSet->m_Uid); |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1647 | BOOST_CHECK(category->m_Counters.size() == 27); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1648 | BOOST_CHECK(category->m_Counters.back() == counterWCounterSet->m_Uid); |
| 1649 | |
| 1650 | // Register a counter with a valid parent category name and associated to a device and a counter set |
| 1651 | const Counter* counterWDeviceWCounterSet = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1652 | BOOST_CHECK_NO_THROW(counterWDeviceWCounterSet = counterDirectory.RegisterCounter( |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1653 | armnn::profiling::BACKEND_ID, 23, |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1654 | categoryName, 0, 1, 123.45f, "valid name 12", "valid description", |
| 1655 | armnn::EmptyOptional(), // Units |
| 1656 | 1, // Number of cores |
| 1657 | device->m_Uid, // Device UID |
| 1658 | counterSet->m_Uid)); // Counter set UID |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1659 | BOOST_CHECK(counterDirectory.GetCounterCount() == 28); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1660 | BOOST_CHECK(counterWDeviceWCounterSet); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1661 | BOOST_CHECK(counterWDeviceWCounterSet->m_Uid > counter->m_Uid); |
| 1662 | BOOST_CHECK(counterWDeviceWCounterSet->m_MaxCounterUid == counterWDeviceWCounterSet->m_Uid); |
| 1663 | BOOST_CHECK(counterWDeviceWCounterSet->m_Class == 0); |
| 1664 | BOOST_CHECK(counterWDeviceWCounterSet->m_Interpolation == 1); |
| 1665 | BOOST_CHECK(counterWDeviceWCounterSet->m_Multiplier == 123.45f); |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1666 | BOOST_CHECK(counterWDeviceWCounterSet->m_Name == "valid name 12"); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1667 | BOOST_CHECK(counterWDeviceWCounterSet->m_Description == "valid description"); |
| 1668 | BOOST_CHECK(counterWDeviceWCounterSet->m_Units == ""); |
| 1669 | BOOST_CHECK(counterWDeviceWCounterSet->m_DeviceUid == device->m_Uid); |
| 1670 | BOOST_CHECK(counterWDeviceWCounterSet->m_CounterSetUid == counterSet->m_Uid); |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1671 | BOOST_CHECK(category->m_Counters.size() == 28); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1672 | BOOST_CHECK(category->m_Counters.back() == counterWDeviceWCounterSet->m_Uid); |
| 1673 | |
| 1674 | // Register another category for testing |
| 1675 | const std::string anotherCategoryName = "some_other_category"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1676 | const Category* anotherCategory = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1677 | BOOST_CHECK_NO_THROW(anotherCategory = counterDirectory.RegisterCategory(anotherCategoryName)); |
| 1678 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 2); |
| 1679 | BOOST_CHECK(anotherCategory); |
| 1680 | BOOST_CHECK(anotherCategory != category); |
| 1681 | BOOST_CHECK(anotherCategory->m_Name == anotherCategoryName); |
| 1682 | BOOST_CHECK(anotherCategory->m_Counters.empty()); |
| 1683 | BOOST_CHECK(anotherCategory->m_DeviceUid == 0); |
| 1684 | BOOST_CHECK(anotherCategory->m_CounterSetUid == 0); |
| 1685 | |
| 1686 | // Register a counter to the other category |
| 1687 | const Counter* anotherCounter = nullptr; |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 1688 | BOOST_CHECK_NO_THROW(anotherCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, 24, |
| 1689 | anotherCategoryName, 1, 0, .00043f, |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1690 | "valid name", "valid description", |
| 1691 | armnn::EmptyOptional(), // Units |
| 1692 | armnn::EmptyOptional(), // Number of cores |
| 1693 | device->m_Uid, // Device UID |
| 1694 | counterSet->m_Uid)); // Counter set UID |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1695 | BOOST_CHECK(counterDirectory.GetCounterCount() == 29); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1696 | BOOST_CHECK(anotherCounter); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1697 | BOOST_CHECK(anotherCounter->m_MaxCounterUid == anotherCounter->m_Uid); |
| 1698 | BOOST_CHECK(anotherCounter->m_Class == 1); |
| 1699 | BOOST_CHECK(anotherCounter->m_Interpolation == 0); |
| 1700 | BOOST_CHECK(anotherCounter->m_Multiplier == .00043f); |
| 1701 | BOOST_CHECK(anotherCounter->m_Name == "valid name"); |
| 1702 | BOOST_CHECK(anotherCounter->m_Description == "valid description"); |
| 1703 | BOOST_CHECK(anotherCounter->m_Units == ""); |
| 1704 | BOOST_CHECK(anotherCounter->m_DeviceUid == device->m_Uid); |
| 1705 | BOOST_CHECK(anotherCounter->m_CounterSetUid == counterSet->m_Uid); |
| 1706 | BOOST_CHECK(anotherCategory->m_Counters.size() == 1); |
| 1707 | BOOST_CHECK(anotherCategory->m_Counters.back() == anotherCounter->m_Uid); |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1708 | } |
| 1709 | |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1710 | BOOST_AUTO_TEST_CASE(CounterSelectionCommandHandlerParseData) |
| 1711 | { |
| 1712 | using boost::numeric_cast; |
| 1713 | |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 1714 | ProfilingStateMachine profilingStateMachine; |
| 1715 | |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1716 | class TestCaptureThread : public IPeriodicCounterCapture |
| 1717 | { |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1718 | void Start() override |
| 1719 | {} |
| 1720 | void Stop() override |
| 1721 | {} |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1722 | }; |
| 1723 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 1724 | class TestReadCounterValues : public IReadCounterValues |
| 1725 | { |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1726 | bool IsCounterRegistered(uint16_t counterUid) const override |
| 1727 | { |
Derek Lamberti | 1dd75b3 | 2019-12-10 21:23:23 +0000 | [diff] [blame^] | 1728 | boost::ignore_unused(counterUid); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1729 | return true; |
| 1730 | } |
| 1731 | uint16_t GetCounterCount() const override |
| 1732 | { |
| 1733 | return 0; |
| 1734 | } |
| 1735 | uint32_t GetCounterValue(uint16_t counterUid) const override |
| 1736 | { |
Derek Lamberti | 1dd75b3 | 2019-12-10 21:23:23 +0000 | [diff] [blame^] | 1737 | boost::ignore_unused(counterUid); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1738 | return 0; |
| 1739 | } |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 1740 | }; |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 1741 | const uint32_t familyId = 0; |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1742 | const uint32_t packetId = 0x40000; |
| 1743 | |
| 1744 | uint32_t version = 1; |
| 1745 | Holder holder; |
| 1746 | TestCaptureThread captureThread; |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 1747 | TestReadCounterValues readCounterValues; |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1748 | MockBufferManager mockBuffer(512); |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 1749 | SendCounterPacket sendCounterPacket(profilingStateMachine, mockBuffer); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1750 | |
| 1751 | uint32_t sizeOfUint32 = numeric_cast<uint32_t>(sizeof(uint32_t)); |
| 1752 | uint32_t sizeOfUint16 = numeric_cast<uint32_t>(sizeof(uint16_t)); |
| 1753 | |
| 1754 | // Data with period and counters |
Colm Donelan | 0270524 | 2019-11-14 14:19:07 +0000 | [diff] [blame] | 1755 | uint32_t period1 = armnn::LOWEST_CAPTURE_PERIOD; |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1756 | uint32_t dataLength1 = 8; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1757 | uint32_t offset = 0; |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1758 | |
Matteo Martincigh | 67ef2a5 | 2019-10-10 13:29:02 +0100 | [diff] [blame] | 1759 | std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength1); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1760 | unsigned char* data1 = reinterpret_cast<unsigned char*>(uniqueData1.get()); |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 1761 | |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1762 | WriteUint32(data1, offset, period1); |
| 1763 | offset += sizeOfUint32; |
| 1764 | WriteUint16(data1, offset, 4000); |
| 1765 | offset += sizeOfUint16; |
| 1766 | WriteUint16(data1, offset, 5000); |
| 1767 | |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 1768 | Packet packetA(packetId, dataLength1, uniqueData1); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1769 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1770 | PeriodicCounterSelectionCommandHandler commandHandler(familyId, packetId, version, holder, captureThread, |
| 1771 | readCounterValues, sendCounterPacket, profilingStateMachine); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1772 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 1773 | profilingStateMachine.TransitionToState(ProfilingState::Uninitialised); |
| 1774 | BOOST_CHECK_THROW(commandHandler(packetA), armnn::RuntimeException); |
| 1775 | profilingStateMachine.TransitionToState(ProfilingState::NotConnected); |
| 1776 | BOOST_CHECK_THROW(commandHandler(packetA), armnn::RuntimeException); |
| 1777 | profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck); |
| 1778 | BOOST_CHECK_THROW(commandHandler(packetA), armnn::RuntimeException); |
| 1779 | profilingStateMachine.TransitionToState(ProfilingState::Active); |
| 1780 | BOOST_CHECK_NO_THROW(commandHandler(packetA)); |
| 1781 | |
| 1782 | const std::vector<uint16_t> counterIdsA = holder.GetCaptureData().GetCounterIds(); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1783 | |
| 1784 | BOOST_TEST(holder.GetCaptureData().GetCapturePeriod() == period1); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 1785 | BOOST_TEST(counterIdsA.size() == 2); |
| 1786 | BOOST_TEST(counterIdsA[0] == 4000); |
| 1787 | BOOST_TEST(counterIdsA[1] == 5000); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1788 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1789 | auto readBuffer = mockBuffer.GetReadableBuffer(); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1790 | |
| 1791 | offset = 0; |
| 1792 | |
| 1793 | uint32_t headerWord0 = ReadUint32(readBuffer, offset); |
| 1794 | offset += sizeOfUint32; |
| 1795 | uint32_t headerWord1 = ReadUint32(readBuffer, offset); |
| 1796 | offset += sizeOfUint32; |
| 1797 | uint32_t period = ReadUint32(readBuffer, offset); |
| 1798 | |
Colm Donelan | 0270524 | 2019-11-14 14:19:07 +0000 | [diff] [blame] | 1799 | BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0); // packet family |
| 1800 | BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 4); // packet id |
| 1801 | BOOST_TEST(headerWord1 == 8); // data length |
| 1802 | BOOST_TEST(period == armnn::LOWEST_CAPTURE_PERIOD); // capture period |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1803 | |
| 1804 | uint16_t counterId = 0; |
| 1805 | offset += sizeOfUint32; |
| 1806 | counterId = ReadUint16(readBuffer, offset); |
| 1807 | BOOST_TEST(counterId == 4000); |
| 1808 | offset += sizeOfUint16; |
| 1809 | counterId = ReadUint16(readBuffer, offset); |
| 1810 | BOOST_TEST(counterId == 5000); |
| 1811 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1812 | mockBuffer.MarkRead(readBuffer); |
| 1813 | |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1814 | // Data with period only |
Colm Donelan | 0270524 | 2019-11-14 14:19:07 +0000 | [diff] [blame] | 1815 | uint32_t period2 = 9000; // We'll specify a value below LOWEST_CAPTURE_PERIOD. It should be pulled upwards. |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1816 | uint32_t dataLength2 = 4; |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1817 | |
Matteo Martincigh | 67ef2a5 | 2019-10-10 13:29:02 +0100 | [diff] [blame] | 1818 | std::unique_ptr<unsigned char[]> uniqueData2 = std::make_unique<unsigned char[]>(dataLength2); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1819 | |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 1820 | WriteUint32(reinterpret_cast<unsigned char*>(uniqueData2.get()), 0, period2); |
| 1821 | |
| 1822 | Packet packetB(packetId, dataLength2, uniqueData2); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1823 | |
| 1824 | commandHandler(packetB); |
| 1825 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 1826 | const std::vector<uint16_t> counterIdsB = holder.GetCaptureData().GetCounterIds(); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1827 | |
Colm Donelan | 0270524 | 2019-11-14 14:19:07 +0000 | [diff] [blame] | 1828 | // Value should have been pulled up from 9000 to LOWEST_CAPTURE_PERIOD. |
| 1829 | BOOST_TEST(holder.GetCaptureData().GetCapturePeriod() == armnn::LOWEST_CAPTURE_PERIOD); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 1830 | BOOST_TEST(counterIdsB.size() == 0); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1831 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1832 | readBuffer = mockBuffer.GetReadableBuffer(); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1833 | |
| 1834 | offset = 0; |
| 1835 | |
| 1836 | headerWord0 = ReadUint32(readBuffer, offset); |
| 1837 | offset += sizeOfUint32; |
| 1838 | headerWord1 = ReadUint32(readBuffer, offset); |
| 1839 | offset += sizeOfUint32; |
| 1840 | period = ReadUint32(readBuffer, offset); |
| 1841 | |
Colm Donelan | 0270524 | 2019-11-14 14:19:07 +0000 | [diff] [blame] | 1842 | BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0); // packet family |
| 1843 | BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 4); // packet id |
| 1844 | BOOST_TEST(headerWord1 == 4); // data length |
| 1845 | BOOST_TEST(period == armnn::LOWEST_CAPTURE_PERIOD); // capture period |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1846 | } |
| 1847 | |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1848 | BOOST_AUTO_TEST_CASE(CheckConnectionAcknowledged) |
| 1849 | { |
| 1850 | using boost::numeric_cast; |
| 1851 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1852 | const uint32_t packetFamilyId = 0; |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1853 | const uint32_t connectionPacketId = 0x10000; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1854 | const uint32_t version = 1; |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1855 | |
| 1856 | uint32_t sizeOfUint32 = numeric_cast<uint32_t>(sizeof(uint32_t)); |
| 1857 | uint32_t sizeOfUint16 = numeric_cast<uint32_t>(sizeof(uint16_t)); |
| 1858 | |
| 1859 | // Data with period and counters |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1860 | uint32_t period1 = 10; |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1861 | uint32_t dataLength1 = 8; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1862 | uint32_t offset = 0; |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1863 | |
Matteo Martincigh | 67ef2a5 | 2019-10-10 13:29:02 +0100 | [diff] [blame] | 1864 | std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength1); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1865 | unsigned char* data1 = reinterpret_cast<unsigned char*>(uniqueData1.get()); |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1866 | |
| 1867 | WriteUint32(data1, offset, period1); |
| 1868 | offset += sizeOfUint32; |
| 1869 | WriteUint16(data1, offset, 4000); |
| 1870 | offset += sizeOfUint16; |
| 1871 | WriteUint16(data1, offset, 5000); |
| 1872 | |
| 1873 | Packet packetA(connectionPacketId, dataLength1, uniqueData1); |
| 1874 | |
| 1875 | ProfilingStateMachine profilingState(ProfilingState::Uninitialised); |
| 1876 | BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1877 | CounterDirectory counterDirectory; |
| 1878 | MockBufferManager mockBuffer(1024); |
| 1879 | SendCounterPacket sendCounterPacket(profilingState, mockBuffer); |
Matteo Martincigh | cdfb941 | 2019-11-08 11:23:06 +0000 | [diff] [blame] | 1880 | SendTimelinePacket sendTimelinePacket(mockBuffer); |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1881 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1882 | ConnectionAcknowledgedCommandHandler commandHandler(packetFamilyId, connectionPacketId, version, counterDirectory, |
Matteo Martincigh | cdfb941 | 2019-11-08 11:23:06 +0000 | [diff] [blame] | 1883 | sendCounterPacket, sendTimelinePacket, profilingState); |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1884 | |
| 1885 | // command handler received packet on ProfilingState::Uninitialised |
| 1886 | BOOST_CHECK_THROW(commandHandler(packetA), armnn::Exception); |
| 1887 | |
| 1888 | profilingState.TransitionToState(ProfilingState::NotConnected); |
| 1889 | BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::NotConnected); |
| 1890 | // command handler received packet on ProfilingState::NotConnected |
| 1891 | BOOST_CHECK_THROW(commandHandler(packetA), armnn::Exception); |
| 1892 | |
| 1893 | profilingState.TransitionToState(ProfilingState::WaitingForAck); |
| 1894 | BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::WaitingForAck); |
| 1895 | // command handler received packet on ProfilingState::WaitingForAck |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 1896 | BOOST_CHECK_NO_THROW(commandHandler(packetA)); |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1897 | BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::Active); |
| 1898 | |
| 1899 | // command handler received packet on ProfilingState::Active |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 1900 | BOOST_CHECK_NO_THROW(commandHandler(packetA)); |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1901 | BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::Active); |
| 1902 | |
| 1903 | // command handler received different packet |
| 1904 | const uint32_t differentPacketId = 0x40000; |
| 1905 | Packet packetB(differentPacketId, dataLength1, uniqueData1); |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 1906 | profilingState.TransitionToState(ProfilingState::NotConnected); |
| 1907 | profilingState.TransitionToState(ProfilingState::WaitingForAck); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1908 | ConnectionAcknowledgedCommandHandler differentCommandHandler(packetFamilyId, differentPacketId, version, |
Matteo Martincigh | cdfb941 | 2019-11-08 11:23:06 +0000 | [diff] [blame] | 1909 | counterDirectory, sendCounterPacket, |
| 1910 | sendTimelinePacket, profilingState); |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1911 | BOOST_CHECK_THROW(differentCommandHandler(packetB), armnn::Exception); |
| 1912 | } |
| 1913 | |
Teresa Charlin | 9bab496 | 2019-09-06 12:28:35 +0100 | [diff] [blame] | 1914 | BOOST_AUTO_TEST_CASE(CheckSocketProfilingConnection) |
| 1915 | { |
| 1916 | // Check that creating a SocketProfilingConnection results in an exception as the Gator UDS doesn't exist. |
| 1917 | BOOST_CHECK_THROW(new SocketProfilingConnection(), armnn::Exception); |
| 1918 | } |
| 1919 | |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1920 | BOOST_AUTO_TEST_CASE(SwTraceIsValidCharTest) |
| 1921 | { |
| 1922 | // Only ASCII 7-bit encoding supported |
| 1923 | for (unsigned char c = 0; c < 128; c++) |
| 1924 | { |
| 1925 | BOOST_CHECK(SwTraceCharPolicy::IsValidChar(c)); |
| 1926 | } |
| 1927 | |
| 1928 | // Not ASCII |
| 1929 | for (unsigned char c = 255; c >= 128; c++) |
| 1930 | { |
| 1931 | BOOST_CHECK(!SwTraceCharPolicy::IsValidChar(c)); |
| 1932 | } |
| 1933 | } |
| 1934 | |
| 1935 | BOOST_AUTO_TEST_CASE(SwTraceIsValidNameCharTest) |
| 1936 | { |
| 1937 | // Only alpha-numeric and underscore ASCII 7-bit encoding supported |
| 1938 | const unsigned char validChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"; |
| 1939 | for (unsigned char i = 0; i < sizeof(validChars) / sizeof(validChars[0]) - 1; i++) |
| 1940 | { |
| 1941 | BOOST_CHECK(SwTraceNameCharPolicy::IsValidChar(validChars[i])); |
| 1942 | } |
| 1943 | |
| 1944 | // Non alpha-numeric chars |
| 1945 | for (unsigned char c = 0; c < 48; c++) |
| 1946 | { |
| 1947 | BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c)); |
| 1948 | } |
| 1949 | for (unsigned char c = 58; c < 65; c++) |
| 1950 | { |
| 1951 | BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c)); |
| 1952 | } |
| 1953 | for (unsigned char c = 91; c < 95; c++) |
| 1954 | { |
| 1955 | BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c)); |
| 1956 | } |
| 1957 | for (unsigned char c = 96; c < 97; c++) |
| 1958 | { |
| 1959 | BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c)); |
| 1960 | } |
| 1961 | for (unsigned char c = 123; c < 128; c++) |
| 1962 | { |
| 1963 | BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c)); |
| 1964 | } |
| 1965 | |
| 1966 | // Not ASCII |
| 1967 | for (unsigned char c = 255; c >= 128; c++) |
| 1968 | { |
| 1969 | BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c)); |
| 1970 | } |
| 1971 | } |
| 1972 | |
| 1973 | BOOST_AUTO_TEST_CASE(IsValidSwTraceStringTest) |
| 1974 | { |
| 1975 | // Valid SWTrace strings |
| 1976 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("")); |
| 1977 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("_")); |
| 1978 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("0123")); |
| 1979 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("valid_string")); |
| 1980 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("VALID_string_456")); |
| 1981 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>(" ")); |
| 1982 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("valid string")); |
| 1983 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("!$%")); |
| 1984 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("valid|\\~string#123")); |
| 1985 | |
| 1986 | // Invalid SWTrace strings |
| 1987 | BOOST_CHECK(!IsValidSwTraceString<SwTraceCharPolicy>("€£")); |
| 1988 | BOOST_CHECK(!IsValidSwTraceString<SwTraceCharPolicy>("invalid‡string")); |
| 1989 | BOOST_CHECK(!IsValidSwTraceString<SwTraceCharPolicy>("12Ž34")); |
| 1990 | } |
| 1991 | |
| 1992 | BOOST_AUTO_TEST_CASE(IsValidSwTraceNameStringTest) |
| 1993 | { |
| 1994 | // Valid SWTrace name strings |
| 1995 | BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("")); |
| 1996 | BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("_")); |
| 1997 | BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("0123")); |
| 1998 | BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("valid_string")); |
| 1999 | BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("VALID_string_456")); |
| 2000 | |
| 2001 | // Invalid SWTrace name strings |
| 2002 | BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>(" ")); |
| 2003 | BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("invalid string")); |
| 2004 | BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("!$%")); |
| 2005 | BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("invalid|\\~string#123")); |
| 2006 | BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("€£")); |
| 2007 | BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("invalid‡string")); |
| 2008 | BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("12Ž34")); |
| 2009 | } |
| 2010 | |
| 2011 | template <typename SwTracePolicy> |
| 2012 | void StringToSwTraceStringTestHelper(const std::string& testString, std::vector<uint32_t> buffer, size_t expectedSize) |
| 2013 | { |
| 2014 | // Convert the test string to a SWTrace string |
| 2015 | BOOST_CHECK(StringToSwTraceString<SwTracePolicy>(testString, buffer)); |
| 2016 | |
| 2017 | // The buffer must contain at least the length of the string |
| 2018 | BOOST_CHECK(!buffer.empty()); |
| 2019 | |
| 2020 | // The buffer must be of the expected size (in words) |
| 2021 | BOOST_CHECK(buffer.size() == expectedSize); |
| 2022 | |
| 2023 | // The first word of the byte must be the length of the string including the null-terminator |
| 2024 | BOOST_CHECK(buffer[0] == testString.size() + 1); |
| 2025 | |
| 2026 | // The contents of the buffer must match the test string |
| 2027 | BOOST_CHECK(std::memcmp(testString.data(), buffer.data() + 1, testString.size()) == 0); |
| 2028 | |
| 2029 | // The buffer must include the null-terminator at the end of the string |
| 2030 | size_t nullTerminatorIndex = sizeof(uint32_t) + testString.size(); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2031 | BOOST_CHECK(reinterpret_cast<unsigned char*>(buffer.data())[nullTerminatorIndex] == '\0'); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 2032 | } |
| 2033 | |
| 2034 | BOOST_AUTO_TEST_CASE(StringToSwTraceStringTest) |
| 2035 | { |
| 2036 | std::vector<uint32_t> buffer; |
| 2037 | |
| 2038 | // Valid SWTrace strings (expected size in words) |
| 2039 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("", buffer, 2); |
| 2040 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("_", buffer, 2); |
| 2041 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("0123", buffer, 3); |
| 2042 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("valid_string", buffer, 5); |
| 2043 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("VALID_string_456", buffer, 6); |
| 2044 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>(" ", buffer, 2); |
| 2045 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("valid string", buffer, 5); |
| 2046 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("!$%", buffer, 2); |
| 2047 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("valid|\\~string#123", buffer, 6); |
| 2048 | |
| 2049 | // Invalid SWTrace strings |
| 2050 | BOOST_CHECK(!StringToSwTraceString<SwTraceCharPolicy>("€£", buffer)); |
| 2051 | BOOST_CHECK(buffer.empty()); |
| 2052 | BOOST_CHECK(!StringToSwTraceString<SwTraceCharPolicy>("invalid‡string", buffer)); |
| 2053 | BOOST_CHECK(buffer.empty()); |
| 2054 | BOOST_CHECK(!StringToSwTraceString<SwTraceCharPolicy>("12Ž34", buffer)); |
| 2055 | BOOST_CHECK(buffer.empty()); |
| 2056 | } |
| 2057 | |
| 2058 | BOOST_AUTO_TEST_CASE(StringToSwTraceNameStringTest) |
| 2059 | { |
| 2060 | std::vector<uint32_t> buffer; |
| 2061 | |
| 2062 | // Valid SWTrace namestrings (expected size in words) |
| 2063 | StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("", buffer, 2); |
| 2064 | StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("_", buffer, 2); |
| 2065 | StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("0123", buffer, 3); |
| 2066 | StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("valid_string", buffer, 5); |
| 2067 | StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("VALID_string_456", buffer, 6); |
| 2068 | |
| 2069 | // Invalid SWTrace namestrings |
| 2070 | BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>(" ", buffer)); |
| 2071 | BOOST_CHECK(buffer.empty()); |
| 2072 | BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("invalid string", buffer)); |
| 2073 | BOOST_CHECK(buffer.empty()); |
| 2074 | BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("!$%", buffer)); |
| 2075 | BOOST_CHECK(buffer.empty()); |
| 2076 | BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("invalid|\\~string#123", buffer)); |
| 2077 | BOOST_CHECK(buffer.empty()); |
| 2078 | BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("€£", buffer)); |
| 2079 | BOOST_CHECK(buffer.empty()); |
| 2080 | BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("invalid‡string", buffer)); |
| 2081 | BOOST_CHECK(buffer.empty()); |
| 2082 | BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("12Ž34", buffer)); |
| 2083 | BOOST_CHECK(buffer.empty()); |
| 2084 | } |
| 2085 | |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2086 | BOOST_AUTO_TEST_CASE(CheckPeriodicCounterCaptureThread) |
| 2087 | { |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 2088 | class CaptureReader : public IReadCounterValues |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2089 | { |
| 2090 | public: |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 2091 | CaptureReader(uint16_t counterSize) |
| 2092 | { |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2093 | for (uint16_t i = 0; i < counterSize; ++i) |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 2094 | { |
| 2095 | m_Data[i] = 0; |
| 2096 | } |
| 2097 | m_CounterSize = counterSize; |
| 2098 | } |
| 2099 | //not used |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2100 | bool IsCounterRegistered(uint16_t counterUid) const override |
| 2101 | { |
Derek Lamberti | 1dd75b3 | 2019-12-10 21:23:23 +0000 | [diff] [blame^] | 2102 | boost::ignore_unused(counterUid); |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 2103 | return false; |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2104 | } |
| 2105 | |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 2106 | uint16_t GetCounterCount() const override |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2107 | { |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 2108 | return m_CounterSize; |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 2109 | } |
| 2110 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2111 | uint32_t GetCounterValue(uint16_t counterUid) const override |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 2112 | { |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2113 | if (counterUid > m_CounterSize) |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2114 | { |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 2115 | BOOST_FAIL("Invalid counter Uid"); |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2116 | } |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2117 | return m_Data.at(counterUid).load(); |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2118 | } |
| 2119 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2120 | void SetCounterValue(uint16_t counterUid, uint32_t value) |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2121 | { |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2122 | if (counterUid > m_CounterSize) |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2123 | { |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 2124 | BOOST_FAIL("Invalid counter Uid"); |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2125 | } |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 2126 | m_Data.at(counterUid).store(value); |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2127 | } |
| 2128 | |
| 2129 | private: |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2130 | std::unordered_map<uint16_t, std::atomic<uint32_t>> m_Data; |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 2131 | uint16_t m_CounterSize; |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2132 | }; |
| 2133 | |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2134 | ProfilingStateMachine profilingStateMachine; |
| 2135 | |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2136 | Holder data; |
| 2137 | std::vector<uint16_t> captureIds1 = { 0, 1 }; |
| 2138 | std::vector<uint16_t> captureIds2; |
| 2139 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 2140 | MockBufferManager mockBuffer(512); |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2141 | SendCounterPacket sendCounterPacket(profilingStateMachine, mockBuffer); |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2142 | |
| 2143 | std::vector<uint16_t> counterIds; |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 2144 | CaptureReader captureReader(2); |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2145 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2146 | unsigned int valueA = 10; |
| 2147 | unsigned int valueB = 15; |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2148 | unsigned int numSteps = 5; |
| 2149 | |
| 2150 | PeriodicCounterCapture periodicCounterCapture(std::ref(data), std::ref(sendCounterPacket), captureReader); |
| 2151 | |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 2152 | for (unsigned int i = 0; i < numSteps; ++i) |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2153 | { |
| 2154 | data.SetCaptureData(1, captureIds1); |
| 2155 | captureReader.SetCounterValue(0, valueA * (i + 1)); |
| 2156 | captureReader.SetCounterValue(1, valueB * (i + 1)); |
| 2157 | |
| 2158 | periodicCounterCapture.Start(); |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 2159 | periodicCounterCapture.Stop(); |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2160 | } |
| 2161 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 2162 | auto buffer = mockBuffer.GetReadableBuffer(); |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2163 | |
| 2164 | uint32_t headerWord0 = ReadUint32(buffer, 0); |
| 2165 | uint32_t headerWord1 = ReadUint32(buffer, 4); |
| 2166 | |
Jim Flynn | fc36562 | 2019-12-04 10:07:20 +0000 | [diff] [blame] | 2167 | BOOST_TEST(((headerWord0 >> 26) & 0x0000003F) == 3); // packet family |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2168 | BOOST_TEST(((headerWord0 >> 19) & 0x0000007F) == 0); // packet class |
| 2169 | BOOST_TEST(((headerWord0 >> 16) & 0x00000007) == 0); // packet type |
Matteo Martincigh | 8d9590e | 2019-10-15 09:35:29 +0100 | [diff] [blame] | 2170 | BOOST_TEST(headerWord1 == 20); |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2171 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2172 | uint32_t offset = 16; |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2173 | uint16_t readIndex = ReadUint16(buffer, offset); |
| 2174 | BOOST_TEST(0 == readIndex); |
| 2175 | |
| 2176 | offset += 2; |
| 2177 | uint32_t readValue = ReadUint32(buffer, offset); |
| 2178 | BOOST_TEST((valueA * numSteps) == readValue); |
| 2179 | |
| 2180 | offset += 4; |
| 2181 | readIndex = ReadUint16(buffer, offset); |
| 2182 | BOOST_TEST(1 == readIndex); |
| 2183 | |
| 2184 | offset += 2; |
| 2185 | readValue = ReadUint32(buffer, offset); |
| 2186 | BOOST_TEST((valueB * numSteps) == readValue); |
| 2187 | } |
| 2188 | |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2189 | BOOST_AUTO_TEST_CASE(RequestCounterDirectoryCommandHandlerTest1) |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2190 | { |
| 2191 | using boost::numeric_cast; |
| 2192 | |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 2193 | const uint32_t familyId = 0; |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2194 | const uint32_t packetId = 3; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2195 | const uint32_t version = 1; |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2196 | ProfilingStateMachine profilingStateMachine; |
| 2197 | CounterDirectory counterDirectory; |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2198 | MockBufferManager mockBuffer1(1024); |
| 2199 | SendCounterPacket sendCounterPacket(profilingStateMachine, mockBuffer1); |
| 2200 | MockBufferManager mockBuffer2(1024); |
| 2201 | SendTimelinePacket sendTimelinePacket(mockBuffer2); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2202 | RequestCounterDirectoryCommandHandler commandHandler(familyId, packetId, version, counterDirectory, |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2203 | sendCounterPacket, sendTimelinePacket, profilingStateMachine); |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2204 | |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2205 | const uint32_t wrongPacketId = 47; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2206 | const uint32_t wrongHeader = (wrongPacketId & 0x000003FF) << 16; |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2207 | |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2208 | Packet wrongPacket(wrongHeader); |
| 2209 | |
| 2210 | profilingStateMachine.TransitionToState(ProfilingState::Uninitialised); |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2211 | BOOST_CHECK_THROW(commandHandler(wrongPacket), armnn::RuntimeException); // Wrong profiling state |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2212 | profilingStateMachine.TransitionToState(ProfilingState::NotConnected); |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2213 | BOOST_CHECK_THROW(commandHandler(wrongPacket), armnn::RuntimeException); // Wrong profiling state |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2214 | profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck); |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2215 | BOOST_CHECK_THROW(commandHandler(wrongPacket), armnn::RuntimeException); // Wrong profiling state |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2216 | profilingStateMachine.TransitionToState(ProfilingState::Active); |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2217 | BOOST_CHECK_THROW(commandHandler(wrongPacket), armnn::InvalidArgumentException); // Wrong packet |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2218 | |
| 2219 | const uint32_t rightHeader = (packetId & 0x000003FF) << 16; |
| 2220 | |
| 2221 | Packet rightPacket(rightHeader); |
| 2222 | |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2223 | BOOST_CHECK_NO_THROW(commandHandler(rightPacket)); // Right packet |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2224 | |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2225 | auto readBuffer1 = mockBuffer1.GetReadableBuffer(); |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2226 | |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2227 | uint32_t header1Word0 = ReadUint32(readBuffer1, 0); |
| 2228 | uint32_t header1Word1 = ReadUint32(readBuffer1, 4); |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2229 | |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2230 | // Counter directory packet |
| 2231 | BOOST_TEST(((header1Word0 >> 26) & 0x0000003F) == 0); // packet family |
| 2232 | BOOST_TEST(((header1Word0 >> 16) & 0x000003FF) == 2); // packet id |
| 2233 | BOOST_TEST(header1Word1 == 24); // data length |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2234 | |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2235 | uint32_t bodyHeader1Word0 = ReadUint32(readBuffer1, 8); |
| 2236 | uint16_t deviceRecordCount = numeric_cast<uint16_t>(bodyHeader1Word0 >> 16); |
| 2237 | BOOST_TEST(deviceRecordCount == 0); // device_records_count |
| 2238 | |
| 2239 | auto readBuffer2 = mockBuffer2.GetReadableBuffer(); |
| 2240 | |
| 2241 | uint32_t header2Word0 = ReadUint32(readBuffer2, 0); |
| 2242 | uint32_t header2Word1 = ReadUint32(readBuffer2, 4); |
| 2243 | |
| 2244 | // Timeline message directory packet |
| 2245 | BOOST_TEST(((header2Word0 >> 26) & 0x0000003F) == 1); // packet family |
| 2246 | BOOST_TEST(((header2Word0 >> 16) & 0x000003FF) == 0); // packet id |
| 2247 | BOOST_TEST(header2Word1 == 419); // data length |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2248 | } |
| 2249 | |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2250 | BOOST_AUTO_TEST_CASE(RequestCounterDirectoryCommandHandlerTest2) |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2251 | { |
| 2252 | using boost::numeric_cast; |
| 2253 | |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 2254 | const uint32_t familyId = 0; |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2255 | const uint32_t packetId = 3; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2256 | const uint32_t version = 1; |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2257 | ProfilingStateMachine profilingStateMachine; |
| 2258 | CounterDirectory counterDirectory; |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2259 | MockBufferManager mockBuffer1(1024); |
| 2260 | SendCounterPacket sendCounterPacket(profilingStateMachine, mockBuffer1); |
| 2261 | MockBufferManager mockBuffer2(1024); |
| 2262 | SendTimelinePacket sendTimelinePacket(mockBuffer2); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2263 | RequestCounterDirectoryCommandHandler commandHandler(familyId, packetId, version, counterDirectory, |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2264 | sendCounterPacket, sendTimelinePacket, profilingStateMachine); |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2265 | const uint32_t header = (packetId & 0x000003FF) << 16; |
| 2266 | Packet packet(header); |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2267 | |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2268 | const Device* device = counterDirectory.RegisterDevice("deviceA", 1); |
| 2269 | BOOST_CHECK(device != nullptr); |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2270 | const CounterSet* counterSet = counterDirectory.RegisterCounterSet("countersetA"); |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2271 | BOOST_CHECK(counterSet != nullptr); |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2272 | counterDirectory.RegisterCategory("categoryA", device->m_Uid, counterSet->m_Uid); |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 2273 | counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, 24, |
| 2274 | "categoryA", 0, 1, 2.0f, "counterA", "descA"); |
| 2275 | counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, 25, |
| 2276 | "categoryA", 1, 1, 3.0f, "counterB", "descB"); |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2277 | |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2278 | profilingStateMachine.TransitionToState(ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2279 | BOOST_CHECK_THROW(commandHandler(packet), armnn::RuntimeException); // Wrong profiling state |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2280 | profilingStateMachine.TransitionToState(ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2281 | BOOST_CHECK_THROW(commandHandler(packet), armnn::RuntimeException); // Wrong profiling state |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2282 | profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2283 | BOOST_CHECK_THROW(commandHandler(packet), armnn::RuntimeException); // Wrong profiling state |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2284 | profilingStateMachine.TransitionToState(ProfilingState::Active); |
| 2285 | BOOST_CHECK_NO_THROW(commandHandler(packet)); |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2286 | |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2287 | auto readBuffer1 = mockBuffer1.GetReadableBuffer(); |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2288 | |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2289 | uint32_t header1Word0 = ReadUint32(readBuffer1, 0); |
| 2290 | uint32_t header1Word1 = ReadUint32(readBuffer1, 4); |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2291 | |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2292 | BOOST_TEST(((header1Word0 >> 26) & 0x0000003F) == 0); // packet family |
| 2293 | BOOST_TEST(((header1Word0 >> 16) & 0x000003FF) == 2); // packet id |
| 2294 | BOOST_TEST(header1Word1 == 240); // data length |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2295 | |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2296 | uint32_t bodyHeader1Word0 = ReadUint32(readBuffer1, 8); |
| 2297 | uint32_t bodyHeader1Word1 = ReadUint32(readBuffer1, 12); |
| 2298 | uint32_t bodyHeader1Word2 = ReadUint32(readBuffer1, 16); |
| 2299 | uint32_t bodyHeader1Word3 = ReadUint32(readBuffer1, 20); |
| 2300 | uint32_t bodyHeader1Word4 = ReadUint32(readBuffer1, 24); |
| 2301 | uint32_t bodyHeader1Word5 = ReadUint32(readBuffer1, 28); |
| 2302 | uint16_t deviceRecordCount = numeric_cast<uint16_t>(bodyHeader1Word0 >> 16); |
| 2303 | uint16_t counterSetRecordCount = numeric_cast<uint16_t>(bodyHeader1Word2 >> 16); |
| 2304 | uint16_t categoryRecordCount = numeric_cast<uint16_t>(bodyHeader1Word4 >> 16); |
| 2305 | BOOST_TEST(deviceRecordCount == 1); // device_records_count |
| 2306 | BOOST_TEST(bodyHeader1Word1 == 0); // device_records_pointer_table_offset |
| 2307 | BOOST_TEST(counterSetRecordCount == 1); // counter_set_count |
| 2308 | BOOST_TEST(bodyHeader1Word3 == 4); // counter_set_pointer_table_offset |
| 2309 | BOOST_TEST(categoryRecordCount == 1); // categories_count |
| 2310 | BOOST_TEST(bodyHeader1Word5 == 8); // categories_pointer_table_offset |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2311 | |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2312 | uint32_t deviceRecordOffset = ReadUint32(readBuffer1, 32); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2313 | BOOST_TEST(deviceRecordOffset == 0); |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2314 | |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2315 | uint32_t counterSetRecordOffset = ReadUint32(readBuffer1, 36); |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2316 | BOOST_TEST(counterSetRecordOffset == 20); |
| 2317 | |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2318 | uint32_t categoryRecordOffset = ReadUint32(readBuffer1, 40); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2319 | BOOST_TEST(categoryRecordOffset == 44); |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2320 | |
| 2321 | auto readBuffer2 = mockBuffer2.GetReadableBuffer(); |
| 2322 | |
| 2323 | uint32_t header2Word0 = ReadUint32(readBuffer2, 0); |
| 2324 | uint32_t header2Word1 = ReadUint32(readBuffer2, 4); |
| 2325 | |
| 2326 | // Timeline message directory packet |
| 2327 | BOOST_TEST(((header2Word0 >> 26) & 0x0000003F) == 1); // packet family |
| 2328 | BOOST_TEST(((header2Word0 >> 16) & 0x000003FF) == 0); // packet id |
| 2329 | BOOST_TEST(header2Word1 == 419); // data length |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2330 | } |
| 2331 | |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2332 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodConnectionAcknowledgedPacket) |
| 2333 | { |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 2334 | // Swap the profiling connection factory in the profiling service instance with our mock one |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2335 | SwapProfilingConnectionFactoryHelper helper; |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2336 | |
| 2337 | // Calculate the size of a Stream Metadata packet |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2338 | std::string processName = GetProcessName().substr(0, 60); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2339 | unsigned int processNameSize = processName.empty() ? 0 : boost::numeric_cast<unsigned int>(processName.size()) + 1; |
| 2340 | unsigned int streamMetadataPacketsize = 118 + processNameSize; |
| 2341 | |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2342 | // Reset the profiling service to the uninitialized state |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2343 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2344 | options.m_EnableProfiling = true; |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2345 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 2346 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2347 | |
| 2348 | // Bring the profiling service to the "WaitingForAck" state |
| 2349 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2350 | profilingService.Update(); // Initialize the counter directory |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2351 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2352 | profilingService.Update(); // Create the profiling connection |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2353 | |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 2354 | // Get the mock profiling connection |
| 2355 | MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 2356 | BOOST_CHECK(mockProfilingConnection); |
| 2357 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2358 | // Remove the packets received so far |
| 2359 | mockProfilingConnection->Clear(); |
| 2360 | |
| 2361 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2362 | profilingService.Update(); // Start the command handler and the send thread |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2363 | |
| 2364 | // Wait for the Stream Metadata packet to be sent |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2365 | helper.WaitForProfilingPacketsSent(mockProfilingConnection); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2366 | |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2367 | // Check that the mock profiling connection contains one Stream Metadata packet |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 2368 | const std::vector<uint32_t> writtenData = mockProfilingConnection->GetWrittenData(); |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2369 | if (writtenData.size() > 1) |
| 2370 | { |
| 2371 | // If this thread has been blocked for some time a second or more Stream Metadata packet could have been sent. |
| 2372 | // In these cases make sure all packet are of length streamMetadataPacketsize |
| 2373 | for(uint32_t packetLength : writtenData) |
| 2374 | { |
| 2375 | BOOST_TEST(packetLength == streamMetadataPacketsize); |
| 2376 | } |
| 2377 | } |
| 2378 | else |
| 2379 | { |
| 2380 | BOOST_TEST(writtenData.size() == 1); |
| 2381 | BOOST_TEST(writtenData[0] == streamMetadataPacketsize); |
| 2382 | } |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2383 | |
| 2384 | // Write a valid "Connection Acknowledged" packet into the mock profiling connection, to simulate a valid |
| 2385 | // reply from an external profiling service |
| 2386 | |
| 2387 | // Connection Acknowledged Packet header (word 0, word 1 is always zero): |
| 2388 | // 26:31 [6] packet_family: Control Packet Family, value 0b000000 |
| 2389 | // 16:25 [10] packet_id: Packet identifier, value 0b0000000001 |
| 2390 | // 8:15 [8] reserved: Reserved, value 0b00000000 |
| 2391 | // 0:7 [8] reserved: Reserved, value 0b00000000 |
| 2392 | uint32_t packetFamily = 0; |
| 2393 | uint32_t packetId = 1; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2394 | uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2395 | |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 2396 | // Create the Connection Acknowledged Packet |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2397 | Packet connectionAcknowledgedPacket(header); |
| 2398 | |
| 2399 | // Write the packet to the mock profiling connection |
| 2400 | mockProfilingConnection->WritePacket(std::move(connectionAcknowledgedPacket)); |
| 2401 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2402 | // Wait for the counter directory packet to ensure the ConnectionAcknowledgedCommandHandler has run. |
| 2403 | helper.WaitForProfilingPacketsSent(mockProfilingConnection, 5000); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2404 | |
| 2405 | // The Connection Acknowledged Command Handler should have updated the profiling state accordingly |
| 2406 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 2407 | |
| 2408 | // Reset the profiling service to stop any running thread |
| 2409 | options.m_EnableProfiling = false; |
| 2410 | profilingService.ResetExternalProfilingOptions(options, true); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2411 | } |
| 2412 | |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2413 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodRequestCounterDirectoryPacket) |
| 2414 | { |
| 2415 | // Swap the profiling connection factory in the profiling service instance with our mock one |
| 2416 | SwapProfilingConnectionFactoryHelper helper; |
| 2417 | |
| 2418 | // Reset the profiling service to the uninitialized state |
| 2419 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2420 | options.m_EnableProfiling = true; |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2421 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 2422 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2423 | |
| 2424 | // Bring the profiling service to the "Active" state |
| 2425 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2426 | profilingService.Update(); // Initialize the counter directory |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2427 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2428 | profilingService.Update(); // Create the profiling connection |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2429 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2430 | profilingService.Update(); // Start the command handler and the send thread |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2431 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2432 | // Get the mock profiling connection |
| 2433 | MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 2434 | BOOST_CHECK(mockProfilingConnection); |
| 2435 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2436 | // Wait for the Stream Metadata packet the be sent |
| 2437 | // (we are not testing the connection acknowledgement here so it will be ignored by this test) |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2438 | helper.WaitForProfilingPacketsSent(mockProfilingConnection); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2439 | |
| 2440 | // Force the profiling service to the "Active" state |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2441 | helper.ForceTransitionToState(ProfilingState::Active); |
| 2442 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2443 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2444 | // Remove the packets received so far |
| 2445 | mockProfilingConnection->Clear(); |
| 2446 | |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2447 | // Write a valid "Request Counter Directory" packet into the mock profiling connection, to simulate a valid |
| 2448 | // reply from an external profiling service |
| 2449 | |
| 2450 | // Request Counter Directory packet header (word 0, word 1 is always zero): |
| 2451 | // 26:31 [6] packet_family: Control Packet Family, value 0b000000 |
| 2452 | // 16:25 [10] packet_id: Packet identifier, value 0b0000000011 |
| 2453 | // 8:15 [8] reserved: Reserved, value 0b00000000 |
| 2454 | // 0:7 [8] reserved: Reserved, value 0b00000000 |
| 2455 | uint32_t packetFamily = 0; |
| 2456 | uint32_t packetId = 3; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2457 | uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16); |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2458 | |
| 2459 | // Create the Request Counter Directory packet |
| 2460 | Packet requestCounterDirectoryPacket(header); |
| 2461 | |
| 2462 | // Write the packet to the mock profiling connection |
| 2463 | mockProfilingConnection->WritePacket(std::move(requestCounterDirectoryPacket)); |
| 2464 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2465 | // Wait for the Counter Directory packet to be sent |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2466 | helper.WaitForProfilingPacketsSent(mockProfilingConnection, 5000); |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2467 | |
| 2468 | // Check that the mock profiling connection contains one Counter Directory packet |
| 2469 | const std::vector<uint32_t> writtenData = mockProfilingConnection->GetWrittenData(); |
Matteo Martincigh | 9723d02 | 2019-11-13 10:56:41 +0000 | [diff] [blame] | 2470 | BOOST_TEST(writtenData.size() == 2); |
| 2471 | BOOST_TEST(writtenData[0] == 427); // The size of the expected Timeline Directory packet |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 2472 | BOOST_TEST(writtenData[1] ==656); // The size of the expected Counter Directory packet |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2473 | |
| 2474 | // The Request Counter Directory Command Handler should not have updated the profiling state |
| 2475 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2476 | |
| 2477 | // Reset the profiling service to stop any running thread |
| 2478 | options.m_EnableProfiling = false; |
| 2479 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2480 | } |
| 2481 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2482 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceBadPeriodicCounterSelectionPacketInvalidCounterUid) |
| 2483 | { |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2484 | // Swap the profiling connection factory in the profiling service instance with our mock one |
| 2485 | SwapProfilingConnectionFactoryHelper helper; |
| 2486 | |
| 2487 | // Reset the profiling service to the uninitialized state |
| 2488 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2489 | options.m_EnableProfiling = true; |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2490 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 2491 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2492 | |
| 2493 | // Bring the profiling service to the "Active" state |
| 2494 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2495 | profilingService.Update(); // Initialize the counter directory |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2496 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2497 | profilingService.Update(); // Create the profiling connection |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2498 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2499 | profilingService.Update(); // Start the command handler and the send thread |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2500 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2501 | // Get the mock profiling connection |
| 2502 | MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 2503 | BOOST_CHECK(mockProfilingConnection); |
| 2504 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2505 | // Wait for the Stream Metadata packet the be sent |
| 2506 | // (we are not testing the connection acknowledgement here so it will be ignored by this test) |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2507 | helper.WaitForProfilingPacketsSent(mockProfilingConnection); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2508 | |
| 2509 | // Force the profiling service to the "Active" state |
| 2510 | helper.ForceTransitionToState(ProfilingState::Active); |
| 2511 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2512 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2513 | // Remove the packets received so far |
| 2514 | mockProfilingConnection->Clear(); |
| 2515 | |
| 2516 | // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an |
| 2517 | // external profiling service |
| 2518 | |
| 2519 | // Periodic Counter Selection packet header: |
| 2520 | // 26:31 [6] packet_family: Control Packet Family, value 0b000000 |
| 2521 | // 16:25 [10] packet_id: Packet identifier, value 0b0000000100 |
| 2522 | // 8:15 [8] reserved: Reserved, value 0b00000000 |
| 2523 | // 0:7 [8] reserved: Reserved, value 0b00000000 |
| 2524 | uint32_t packetFamily = 0; |
| 2525 | uint32_t packetId = 4; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2526 | uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2527 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2528 | uint32_t capturePeriod = 123456; // Some capture period (microseconds) |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2529 | |
| 2530 | // Get the first valid counter UID |
| 2531 | const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory(); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2532 | const Counters& counters = counterDirectory.GetCounters(); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2533 | BOOST_CHECK(counters.size() > 1); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2534 | uint16_t counterUidA = counters.begin()->first; // First valid counter UID |
| 2535 | uint16_t counterUidB = 9999; // Second invalid counter UID |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2536 | |
| 2537 | uint32_t length = 8; |
| 2538 | |
| 2539 | auto data = std::make_unique<unsigned char[]>(length); |
| 2540 | WriteUint32(data.get(), 0, capturePeriod); |
| 2541 | WriteUint16(data.get(), 4, counterUidA); |
| 2542 | WriteUint16(data.get(), 6, counterUidB); |
| 2543 | |
| 2544 | // Create the Periodic Counter Selection packet |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2545 | Packet periodicCounterSelectionPacket(header, length, data); // Length > 0, this will start the Period Counter |
| 2546 | // Capture thread |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2547 | |
| 2548 | // Write the packet to the mock profiling connection |
| 2549 | mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket)); |
| 2550 | |
| 2551 | // Expecting one Periodic Counter Selection packet and at least one Periodic Counter Capture packet |
| 2552 | int expectedPackets = 2; |
| 2553 | std::vector<uint32_t> receivedPackets; |
| 2554 | |
| 2555 | // Keep waiting until all the expected packets have been received |
| 2556 | do |
| 2557 | { |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2558 | helper.WaitForProfilingPacketsSent(mockProfilingConnection); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2559 | const std::vector<uint32_t> writtenData = mockProfilingConnection->GetWrittenData(); |
| 2560 | if (writtenData.empty()) |
| 2561 | { |
| 2562 | BOOST_ERROR("Packets should be available for reading at this point"); |
| 2563 | return; |
| 2564 | } |
| 2565 | receivedPackets.insert(receivedPackets.end(), writtenData.begin(), writtenData.end()); |
| 2566 | expectedPackets -= boost::numeric_cast<int>(writtenData.size()); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2567 | } while (expectedPackets > 0); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2568 | BOOST_TEST(!receivedPackets.empty()); |
| 2569 | |
| 2570 | // The size of the expected Periodic Counter Selection packet |
| 2571 | BOOST_TEST((std::find(receivedPackets.begin(), receivedPackets.end(), 14) != receivedPackets.end())); |
| 2572 | // The size of the expected Periodic Counter Capture packet |
| 2573 | BOOST_TEST((std::find(receivedPackets.begin(), receivedPackets.end(), 22) != receivedPackets.end())); |
| 2574 | |
| 2575 | // The Periodic Counter Selection Handler should not have updated the profiling state |
| 2576 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2577 | |
| 2578 | // Reset the profiling service to stop any running thread |
| 2579 | options.m_EnableProfiling = false; |
| 2580 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2581 | } |
| 2582 | |
| 2583 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodPeriodicCounterSelectionPacketNoCounters) |
| 2584 | { |
| 2585 | // Swap the profiling connection factory in the profiling service instance with our mock one |
| 2586 | SwapProfilingConnectionFactoryHelper helper; |
| 2587 | |
| 2588 | // Reset the profiling service to the uninitialized state |
| 2589 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2590 | options.m_EnableProfiling = true; |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2591 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 2592 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2593 | |
| 2594 | // Bring the profiling service to the "Active" state |
| 2595 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2596 | profilingService.Update(); // Initialize the counter directory |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2597 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2598 | profilingService.Update(); // Create the profiling connection |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2599 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2600 | profilingService.Update(); // Start the command handler and the send thread |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2601 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2602 | // Get the mock profiling connection |
| 2603 | MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 2604 | BOOST_CHECK(mockProfilingConnection); |
| 2605 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2606 | // Wait for the Stream Metadata packet the be sent |
| 2607 | // (we are not testing the connection acknowledgement here so it will be ignored by this test) |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2608 | helper.WaitForProfilingPacketsSent(mockProfilingConnection); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2609 | |
| 2610 | // Force the profiling service to the "Active" state |
| 2611 | helper.ForceTransitionToState(ProfilingState::Active); |
| 2612 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2613 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2614 | // Remove the packets received so far |
| 2615 | mockProfilingConnection->Clear(); |
| 2616 | |
| 2617 | // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an |
| 2618 | // external profiling service |
| 2619 | |
| 2620 | // Periodic Counter Selection packet header: |
| 2621 | // 26:31 [6] packet_family: Control Packet Family, value 0b000000 |
| 2622 | // 16:25 [10] packet_id: Packet identifier, value 0b0000000100 |
| 2623 | // 8:15 [8] reserved: Reserved, value 0b00000000 |
| 2624 | // 0:7 [8] reserved: Reserved, value 0b00000000 |
| 2625 | uint32_t packetFamily = 0; |
| 2626 | uint32_t packetId = 4; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2627 | uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2628 | |
| 2629 | // Create the Periodic Counter Selection packet |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2630 | Packet periodicCounterSelectionPacket(header); // Length == 0, this will disable the collection of counters |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2631 | |
| 2632 | // Write the packet to the mock profiling connection |
| 2633 | mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket)); |
| 2634 | |
| 2635 | // Wait for the Periodic Counter Selection packet to be sent |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2636 | helper.WaitForProfilingPacketsSent(mockProfilingConnection, 5000); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2637 | |
| 2638 | // The Periodic Counter Selection Handler should not have updated the profiling state |
| 2639 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2640 | |
| 2641 | // Check that the mock profiling connection contains one Periodic Counter Selection |
| 2642 | const std::vector<uint32_t> writtenData = mockProfilingConnection->GetWrittenData(); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2643 | BOOST_TEST(writtenData.size() == 1); // Only one packet is expected (no Periodic Counter packets) |
| 2644 | BOOST_TEST(writtenData[0] == 12); // The size of the expected Periodic Counter Selection (echos the sent one) |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2645 | |
| 2646 | // Reset the profiling service to stop any running thread |
| 2647 | options.m_EnableProfiling = false; |
| 2648 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2649 | } |
| 2650 | |
| 2651 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodPeriodicCounterSelectionPacketSingleCounter) |
| 2652 | { |
| 2653 | // Swap the profiling connection factory in the profiling service instance with our mock one |
| 2654 | SwapProfilingConnectionFactoryHelper helper; |
| 2655 | |
| 2656 | // Reset the profiling service to the uninitialized state |
| 2657 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2658 | options.m_EnableProfiling = true; |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2659 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 2660 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2661 | |
| 2662 | // Bring the profiling service to the "Active" state |
| 2663 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2664 | profilingService.Update(); // Initialize the counter directory |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2665 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2666 | profilingService.Update(); // Create the profiling connection |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2667 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2668 | profilingService.Update(); // Start the command handler and the send thread |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2669 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2670 | // Get the mock profiling connection |
| 2671 | MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 2672 | BOOST_CHECK(mockProfilingConnection); |
| 2673 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2674 | // Wait for the Stream Metadata packet the be sent |
| 2675 | // (we are not testing the connection acknowledgement here so it will be ignored by this test) |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2676 | helper.WaitForProfilingPacketsSent(mockProfilingConnection); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2677 | |
| 2678 | // Force the profiling service to the "Active" state |
| 2679 | helper.ForceTransitionToState(ProfilingState::Active); |
| 2680 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2681 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2682 | // Remove the packets received so far |
| 2683 | mockProfilingConnection->Clear(); |
| 2684 | |
| 2685 | // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an |
| 2686 | // external profiling service |
| 2687 | |
| 2688 | // Periodic Counter Selection packet header: |
| 2689 | // 26:31 [6] packet_family: Control Packet Family, value 0b000000 |
| 2690 | // 16:25 [10] packet_id: Packet identifier, value 0b0000000100 |
| 2691 | // 8:15 [8] reserved: Reserved, value 0b00000000 |
| 2692 | // 0:7 [8] reserved: Reserved, value 0b00000000 |
| 2693 | uint32_t packetFamily = 0; |
| 2694 | uint32_t packetId = 4; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2695 | uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2696 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2697 | uint32_t capturePeriod = 123456; // Some capture period (microseconds) |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2698 | |
| 2699 | // Get the first valid counter UID |
| 2700 | const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory(); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2701 | const Counters& counters = counterDirectory.GetCounters(); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2702 | BOOST_CHECK(!counters.empty()); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2703 | uint16_t counterUid = counters.begin()->first; // Valid counter UID |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2704 | |
| 2705 | uint32_t length = 6; |
| 2706 | |
| 2707 | auto data = std::make_unique<unsigned char[]>(length); |
| 2708 | WriteUint32(data.get(), 0, capturePeriod); |
| 2709 | WriteUint16(data.get(), 4, counterUid); |
| 2710 | |
| 2711 | // Create the Periodic Counter Selection packet |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2712 | Packet periodicCounterSelectionPacket(header, length, data); // Length > 0, this will start the Period Counter |
| 2713 | // Capture thread |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2714 | |
| 2715 | // Write the packet to the mock profiling connection |
| 2716 | mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket)); |
| 2717 | |
| 2718 | // Expecting one Periodic Counter Selection packet and at least one Periodic Counter Capture packet |
| 2719 | int expectedPackets = 2; |
| 2720 | std::vector<uint32_t> receivedPackets; |
| 2721 | |
| 2722 | // Keep waiting until all the expected packets have been received |
| 2723 | do |
| 2724 | { |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2725 | helper.WaitForProfilingPacketsSent(mockProfilingConnection); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2726 | const std::vector<uint32_t> writtenData = mockProfilingConnection->GetWrittenData(); |
| 2727 | if (writtenData.empty()) |
| 2728 | { |
| 2729 | BOOST_ERROR("Packets should be available for reading at this point"); |
| 2730 | return; |
| 2731 | } |
| 2732 | receivedPackets.insert(receivedPackets.end(), writtenData.begin(), writtenData.end()); |
| 2733 | expectedPackets -= boost::numeric_cast<int>(writtenData.size()); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2734 | } while (expectedPackets > 0); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2735 | BOOST_TEST(!receivedPackets.empty()); |
| 2736 | |
| 2737 | // The size of the expected Periodic Counter Selection packet (echos the sent one) |
| 2738 | BOOST_TEST((std::find(receivedPackets.begin(), receivedPackets.end(), 14) != receivedPackets.end())); |
| 2739 | // The size of the expected Periodic Counter Capture packet |
| 2740 | BOOST_TEST((std::find(receivedPackets.begin(), receivedPackets.end(), 22) != receivedPackets.end())); |
| 2741 | |
| 2742 | // The Periodic Counter Selection Handler should not have updated the profiling state |
| 2743 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2744 | |
| 2745 | // Reset the profiling service to stop any running thread |
| 2746 | options.m_EnableProfiling = false; |
| 2747 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2748 | } |
| 2749 | |
| 2750 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodPeriodicCounterSelectionPacketMultipleCounters) |
| 2751 | { |
| 2752 | // Swap the profiling connection factory in the profiling service instance with our mock one |
| 2753 | SwapProfilingConnectionFactoryHelper helper; |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2754 | // Reset the profiling service to the uninitialized state |
| 2755 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2756 | options.m_EnableProfiling = true; |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2757 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 2758 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2759 | |
| 2760 | // Bring the profiling service to the "Active" state |
| 2761 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2762 | profilingService.Update(); // Initialize the counter directory |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2763 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2764 | profilingService.Update(); // Create the profiling connection |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2765 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2766 | profilingService.Update(); // Start the command handler and the send thread |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2767 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2768 | // Get the mock profiling connection |
| 2769 | MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 2770 | BOOST_CHECK(mockProfilingConnection); |
| 2771 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2772 | // Wait for the Stream Metadata packet the be sent |
| 2773 | // (we are not testing the connection acknowledgement here so it will be ignored by this test) |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2774 | helper.WaitForProfilingPacketsSent(mockProfilingConnection); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2775 | |
| 2776 | // Force the profiling service to the "Active" state |
| 2777 | helper.ForceTransitionToState(ProfilingState::Active); |
| 2778 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2779 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2780 | // Remove the packets received so far |
| 2781 | mockProfilingConnection->Clear(); |
| 2782 | |
| 2783 | // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an |
| 2784 | // external profiling service |
| 2785 | |
| 2786 | // Periodic Counter Selection packet header: |
| 2787 | // 26:31 [6] packet_family: Control Packet Family, value 0b000000 |
| 2788 | // 16:25 [10] packet_id: Packet identifier, value 0b0000000100 |
| 2789 | // 8:15 [8] reserved: Reserved, value 0b00000000 |
| 2790 | // 0:7 [8] reserved: Reserved, value 0b00000000 |
| 2791 | uint32_t packetFamily = 0; |
| 2792 | uint32_t packetId = 4; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2793 | uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2794 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2795 | uint32_t capturePeriod = 123456; // Some capture period (microseconds) |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2796 | |
| 2797 | // Get the first valid counter UID |
| 2798 | const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory(); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2799 | const Counters& counters = counterDirectory.GetCounters(); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2800 | BOOST_CHECK(counters.size() > 1); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2801 | uint16_t counterUidA = counters.begin()->first; // First valid counter UID |
| 2802 | uint16_t counterUidB = (counters.begin()++)->first; // Second valid counter UID |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2803 | |
| 2804 | uint32_t length = 8; |
| 2805 | |
| 2806 | auto data = std::make_unique<unsigned char[]>(length); |
| 2807 | WriteUint32(data.get(), 0, capturePeriod); |
| 2808 | WriteUint16(data.get(), 4, counterUidA); |
| 2809 | WriteUint16(data.get(), 6, counterUidB); |
| 2810 | |
| 2811 | // Create the Periodic Counter Selection packet |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2812 | Packet periodicCounterSelectionPacket(header, length, data); // Length > 0, this will start the Period Counter |
| 2813 | // Capture thread |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2814 | |
| 2815 | // Write the packet to the mock profiling connection |
| 2816 | mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket)); |
| 2817 | |
| 2818 | // Expecting one Periodic Counter Selection packet and at least one Periodic Counter Capture packet |
| 2819 | int expectedPackets = 2; |
| 2820 | std::vector<uint32_t> receivedPackets; |
| 2821 | |
| 2822 | // Keep waiting until all the expected packets have been received |
| 2823 | do |
| 2824 | { |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2825 | helper.WaitForProfilingPacketsSent(mockProfilingConnection); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2826 | const std::vector<uint32_t> writtenData = mockProfilingConnection->GetWrittenData(); |
| 2827 | if (writtenData.empty()) |
| 2828 | { |
| 2829 | BOOST_ERROR("Packets should be available for reading at this point"); |
| 2830 | return; |
| 2831 | } |
| 2832 | receivedPackets.insert(receivedPackets.end(), writtenData.begin(), writtenData.end()); |
| 2833 | expectedPackets -= boost::numeric_cast<int>(writtenData.size()); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2834 | } while (expectedPackets > 0); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2835 | BOOST_TEST(!receivedPackets.empty()); |
| 2836 | |
| 2837 | // The size of the expected Periodic Counter Selection packet (echos the sent one) |
| 2838 | BOOST_TEST((std::find(receivedPackets.begin(), receivedPackets.end(), 16) != receivedPackets.end())); |
| 2839 | // The size of the expected Periodic Counter Capture packet |
| 2840 | BOOST_TEST((std::find(receivedPackets.begin(), receivedPackets.end(), 28) != receivedPackets.end())); |
| 2841 | |
| 2842 | // The Periodic Counter Selection Handler should not have updated the profiling state |
| 2843 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2844 | |
| 2845 | // Reset the profiling service to stop any running thread |
| 2846 | options.m_EnableProfiling = false; |
| 2847 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2848 | } |
| 2849 | |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2850 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceDisconnect) |
| 2851 | { |
| 2852 | // Swap the profiling connection factory in the profiling service instance with our mock one |
| 2853 | SwapProfilingConnectionFactoryHelper helper; |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2854 | // Reset the profiling service to the uninitialized state |
| 2855 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2856 | options.m_EnableProfiling = true; |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2857 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 2858 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2859 | |
| 2860 | // Try to disconnect the profiling service while in the "Uninitialised" state |
| 2861 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
| 2862 | profilingService.Disconnect(); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2863 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); // The state should not change |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2864 | |
| 2865 | // Try to disconnect the profiling service while in the "NotConnected" state |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2866 | profilingService.Update(); // Initialize the counter directory |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2867 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
| 2868 | profilingService.Disconnect(); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2869 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); // The state should not change |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2870 | |
| 2871 | // Try to disconnect the profiling service while in the "WaitingForAck" state |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2872 | profilingService.Update(); // Create the profiling connection |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2873 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
| 2874 | profilingService.Disconnect(); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2875 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); // The state should not change |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2876 | |
| 2877 | // Try to disconnect the profiling service while in the "Active" state |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2878 | profilingService.Update(); // Start the command handler and the send thread |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2879 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2880 | // Get the mock profiling connection |
| 2881 | MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 2882 | BOOST_CHECK(mockProfilingConnection); |
| 2883 | |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2884 | // Wait for the Stream Metadata packet the be sent |
| 2885 | // (we are not testing the connection acknowledgement here so it will be ignored by this test) |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2886 | helper.WaitForProfilingPacketsSent(mockProfilingConnection); |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2887 | |
| 2888 | // Force the profiling service to the "Active" state |
| 2889 | helper.ForceTransitionToState(ProfilingState::Active); |
| 2890 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2891 | |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2892 | // Check that the profiling connection is open |
| 2893 | BOOST_CHECK(mockProfilingConnection->IsOpen()); |
| 2894 | |
| 2895 | profilingService.Disconnect(); |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2896 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); // The state should have changed |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2897 | |
| 2898 | // Check that the profiling connection has been reset |
| 2899 | mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 2900 | BOOST_CHECK(mockProfilingConnection == nullptr); |
| 2901 | |
| 2902 | // Reset the profiling service to stop any running thread |
| 2903 | options.m_EnableProfiling = false; |
| 2904 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2905 | } |
| 2906 | |
Matteo Martincigh | 994b534 | 2019-10-11 17:19:56 +0100 | [diff] [blame] | 2907 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodPerJobCounterSelectionPacket) |
| 2908 | { |
| 2909 | // Swap the profiling connection factory in the profiling service instance with our mock one |
| 2910 | SwapProfilingConnectionFactoryHelper helper; |
Matteo Martincigh | 994b534 | 2019-10-11 17:19:56 +0100 | [diff] [blame] | 2911 | // Reset the profiling service to the uninitialized state |
| 2912 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2913 | options.m_EnableProfiling = true; |
Matteo Martincigh | 994b534 | 2019-10-11 17:19:56 +0100 | [diff] [blame] | 2914 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 2915 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2916 | |
| 2917 | // Bring the profiling service to the "Active" state |
| 2918 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2919 | profilingService.Update(); // Initialize the counter directory |
Matteo Martincigh | 994b534 | 2019-10-11 17:19:56 +0100 | [diff] [blame] | 2920 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2921 | profilingService.Update(); // Create the profiling connection |
Matteo Martincigh | 994b534 | 2019-10-11 17:19:56 +0100 | [diff] [blame] | 2922 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2923 | profilingService.Update(); // Start the command handler and the send thread |
Matteo Martincigh | 994b534 | 2019-10-11 17:19:56 +0100 | [diff] [blame] | 2924 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2925 | // Get the mock profiling connection |
| 2926 | MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 2927 | BOOST_CHECK(mockProfilingConnection); |
| 2928 | |
Matteo Martincigh | 994b534 | 2019-10-11 17:19:56 +0100 | [diff] [blame] | 2929 | // Wait for the Stream Metadata packet the be sent |
| 2930 | // (we are not testing the connection acknowledgement here so it will be ignored by this test) |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2931 | helper.WaitForProfilingPacketsSent(mockProfilingConnection); |
Matteo Martincigh | 994b534 | 2019-10-11 17:19:56 +0100 | [diff] [blame] | 2932 | |
| 2933 | // Force the profiling service to the "Active" state |
| 2934 | helper.ForceTransitionToState(ProfilingState::Active); |
| 2935 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2936 | |
Matteo Martincigh | 994b534 | 2019-10-11 17:19:56 +0100 | [diff] [blame] | 2937 | // Remove the packets received so far |
| 2938 | mockProfilingConnection->Clear(); |
| 2939 | |
| 2940 | // Write a "Per-Job Counter Selection" packet into the mock profiling connection, to simulate an input from an |
| 2941 | // external profiling service |
| 2942 | |
| 2943 | // Per-Job Counter Selection packet header: |
| 2944 | // 26:31 [6] packet_family: Control Packet Family, value 0b000000 |
| 2945 | // 16:25 [10] packet_id: Packet identifier, value 0b0000000100 |
| 2946 | // 8:15 [8] reserved: Reserved, value 0b00000000 |
| 2947 | // 0:7 [8] reserved: Reserved, value 0b00000000 |
| 2948 | uint32_t packetFamily = 0; |
| 2949 | uint32_t packetId = 5; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2950 | uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16); |
Matteo Martincigh | 994b534 | 2019-10-11 17:19:56 +0100 | [diff] [blame] | 2951 | |
| 2952 | // Create the Per-Job Counter Selection packet |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2953 | Packet periodicCounterSelectionPacket(header); // Length == 0, this will disable the collection of counters |
Matteo Martincigh | 994b534 | 2019-10-11 17:19:56 +0100 | [diff] [blame] | 2954 | |
| 2955 | // Write the packet to the mock profiling connection |
| 2956 | mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket)); |
| 2957 | |
| 2958 | // Wait for a bit (must at least be the delay value of the mock profiling connection) to make sure that |
| 2959 | // the Per-Job Counter Selection packet gets processed by the profiling service |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 2960 | std::this_thread::sleep_for(std::chrono::milliseconds(5)); |
Matteo Martincigh | 994b534 | 2019-10-11 17:19:56 +0100 | [diff] [blame] | 2961 | |
| 2962 | // The Per-Job Counter Selection packets are dropped silently, so there should be no reply coming |
| 2963 | // from the profiling service |
| 2964 | const std::vector<uint32_t> writtenData = mockProfilingConnection->GetWrittenData(); |
| 2965 | BOOST_TEST(writtenData.empty()); |
| 2966 | |
| 2967 | // The Per-Job Counter Selection Command Handler should not have updated the profiling state |
| 2968 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2969 | |
| 2970 | // Reset the profiling service to stop any running thread |
| 2971 | options.m_EnableProfiling = false; |
| 2972 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2973 | } |
| 2974 | |
Jim Flynn | 672d06e | 2019-10-15 10:18:11 +0100 | [diff] [blame] | 2975 | BOOST_AUTO_TEST_CASE(CheckConfigureProfilingServiceOn) |
| 2976 | { |
| 2977 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2978 | options.m_EnableProfiling = true; |
Jim Flynn | 672d06e | 2019-10-15 10:18:11 +0100 | [diff] [blame] | 2979 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 2980 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
| 2981 | profilingService.ConfigureProfilingService(options); |
| 2982 | // should get as far as NOT_CONNECTED |
| 2983 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
| 2984 | // Reset the profiling service to stop any running thread |
| 2985 | options.m_EnableProfiling = false; |
| 2986 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2987 | } |
| 2988 | |
| 2989 | BOOST_AUTO_TEST_CASE(CheckConfigureProfilingServiceOff) |
| 2990 | { |
| 2991 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
| 2992 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 2993 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
| 2994 | profilingService.ConfigureProfilingService(options); |
| 2995 | // should not move from Uninitialised |
| 2996 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
| 2997 | // Reset the profiling service to stop any running thread |
| 2998 | options.m_EnableProfiling = false; |
| 2999 | profilingService.ResetExternalProfilingOptions(options, true); |
| 3000 | } |
| 3001 | |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 3002 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceEnabled) |
| 3003 | { |
| 3004 | // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output |
| 3005 | LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning); |
| 3006 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
| 3007 | options.m_EnableProfiling = true; |
| 3008 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 3009 | profilingService.ResetExternalProfilingOptions(options, true); |
| 3010 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
| 3011 | profilingService.Update(); |
| 3012 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
| 3013 | |
| 3014 | // Redirect the output to a local stream so that we can parse the warning message |
| 3015 | std::stringstream ss; |
| 3016 | StreamRedirector streamRedirector(std::cout, ss.rdbuf()); |
| 3017 | profilingService.Update(); |
| 3018 | streamRedirector.CancelRedirect(); |
| 3019 | |
| 3020 | // Check that the expected error has occurred and logged to the standard output |
| 3021 | if (!boost::contains(ss.str(), "Cannot connect to stream socket: Connection refused")) |
| 3022 | { |
| 3023 | std::cout << ss.str(); |
| 3024 | BOOST_FAIL("Expected string not found."); |
| 3025 | } |
| 3026 | // Reset the profiling service to stop any running thread |
| 3027 | options.m_EnableProfiling = false; |
| 3028 | profilingService.ResetExternalProfilingOptions(options, true); |
| 3029 | } |
| 3030 | |
| 3031 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceEnabledRuntime) |
| 3032 | { |
| 3033 | // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output |
| 3034 | LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning); |
| 3035 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
| 3036 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 3037 | profilingService.ResetExternalProfilingOptions(options, true); |
| 3038 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
| 3039 | profilingService.Update(); |
| 3040 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
| 3041 | options.m_EnableProfiling = true; |
| 3042 | profilingService.ResetExternalProfilingOptions(options); |
| 3043 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
| 3044 | profilingService.Update(); |
| 3045 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
| 3046 | |
| 3047 | // Redirect the output to a local stream so that we can parse the warning message |
| 3048 | std::stringstream ss; |
| 3049 | StreamRedirector streamRedirector(std::cout, ss.rdbuf()); |
| 3050 | profilingService.Update(); |
| 3051 | |
| 3052 | streamRedirector.CancelRedirect(); |
| 3053 | |
| 3054 | // Check that the expected error has occurred and logged to the standard output |
| 3055 | if (!boost::contains(ss.str(), "Cannot connect to stream socket: Connection refused")) |
| 3056 | { |
| 3057 | std::cout << ss.str(); |
| 3058 | BOOST_FAIL("Expected string not found."); |
| 3059 | } |
| 3060 | // Reset the profiling service to stop any running thread |
| 3061 | options.m_EnableProfiling = false; |
| 3062 | profilingService.ResetExternalProfilingOptions(options, true); |
| 3063 | } |
| 3064 | |
| 3065 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceBadConnectionAcknowledgedPacket) |
| 3066 | { |
| 3067 | // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output |
| 3068 | LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning); |
| 3069 | // Swap the profiling connection factory in the profiling service instance with our mock one |
| 3070 | SwapProfilingConnectionFactoryHelper helper; |
| 3071 | |
| 3072 | // Redirect the standard output to a local stream so that we can parse the warning message |
| 3073 | std::stringstream ss; |
| 3074 | StreamRedirector streamRedirector(std::cout, ss.rdbuf()); |
| 3075 | |
| 3076 | // Calculate the size of a Stream Metadata packet |
| 3077 | std::string processName = GetProcessName().substr(0, 60); |
| 3078 | unsigned int processNameSize = processName.empty() ? 0 : boost::numeric_cast<unsigned int>(processName.size()) + 1; |
| 3079 | unsigned int streamMetadataPacketsize = 118 + processNameSize; |
| 3080 | |
| 3081 | // Reset the profiling service to the uninitialized state |
| 3082 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
| 3083 | options.m_EnableProfiling = true; |
| 3084 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 3085 | profilingService.ResetExternalProfilingOptions(options, true); |
| 3086 | |
| 3087 | // Bring the profiling service to the "WaitingForAck" state |
| 3088 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
| 3089 | profilingService.Update(); // Initialize the counter directory |
| 3090 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
| 3091 | profilingService.Update(); // Create the profiling connection |
| 3092 | |
| 3093 | // Get the mock profiling connection |
| 3094 | MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 3095 | BOOST_CHECK(mockProfilingConnection); |
| 3096 | |
| 3097 | // Remove the packets received so far |
| 3098 | mockProfilingConnection->Clear(); |
| 3099 | |
| 3100 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
| 3101 | profilingService.Update(); |
| 3102 | |
| 3103 | // Wait for the Stream Metadata packet to be sent |
| 3104 | helper.WaitForProfilingPacketsSent(mockProfilingConnection); |
| 3105 | |
| 3106 | // Check that the mock profiling connection contains one Stream Metadata packet |
| 3107 | const std::vector<uint32_t> writtenData = mockProfilingConnection->GetWrittenData(); |
| 3108 | if (writtenData.size() > 1) |
| 3109 | { |
| 3110 | // If this thread has been blocked for some time a second or more Stream Metadata packet could have been sent. |
| 3111 | // In these cases make sure all packet are of length streamMetadataPacketsize |
| 3112 | for(uint32_t packetLength : writtenData) |
| 3113 | { |
| 3114 | BOOST_TEST(packetLength == streamMetadataPacketsize); |
| 3115 | } |
| 3116 | } |
| 3117 | else |
| 3118 | { |
| 3119 | BOOST_TEST(writtenData.size() == 1); |
| 3120 | BOOST_TEST(writtenData[0] == streamMetadataPacketsize); |
| 3121 | } |
| 3122 | |
| 3123 | // Write a valid "Connection Acknowledged" packet into the mock profiling connection, to simulate a valid |
| 3124 | // reply from an external profiling service |
| 3125 | |
| 3126 | // Connection Acknowledged Packet header (word 0, word 1 is always zero): |
| 3127 | // 26:31 [6] packet_family: Control Packet Family, value 0b000000 |
| 3128 | // 16:25 [10] packet_id: Packet identifier, value 0b0000000001 |
| 3129 | // 8:15 [8] reserved: Reserved, value 0b00000000 |
| 3130 | // 0:7 [8] reserved: Reserved, value 0b00000000 |
| 3131 | uint32_t packetFamily = 0; |
| 3132 | uint32_t packetId = 37; // Wrong packet id!!! |
| 3133 | uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16); |
| 3134 | |
| 3135 | // Create the Connection Acknowledged Packet |
| 3136 | Packet connectionAcknowledgedPacket(header); |
| 3137 | |
| 3138 | // Write the packet to the mock profiling connection |
| 3139 | mockProfilingConnection->WritePacket(std::move(connectionAcknowledgedPacket)); |
| 3140 | |
| 3141 | // Wait for a bit (must at least be the delay value of the mock profiling connection) to make sure that |
| 3142 | // the Connection Acknowledged packet gets processed by the profiling service |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 3143 | std::this_thread::sleep_for(std::chrono::milliseconds(15)); |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 3144 | |
| 3145 | streamRedirector.CancelRedirect(); |
| 3146 | |
| 3147 | // Check that the expected error has occurred and logged to the standard output |
| 3148 | if (!boost::contains(ss.str(), "Functor with requested PacketId=37 and Version=4194304 does not exist")) |
| 3149 | { |
| 3150 | std::cout << ss.str(); |
| 3151 | BOOST_FAIL("Expected string not found."); |
| 3152 | } |
| 3153 | |
| 3154 | // The Connection Acknowledged Command Handler should not have updated the profiling state |
| 3155 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
| 3156 | |
| 3157 | // Reset the profiling service to stop any running thread |
| 3158 | options.m_EnableProfiling = false; |
| 3159 | profilingService.ResetExternalProfilingOptions(options, true); |
| 3160 | } |
| 3161 | |
| 3162 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceBadRequestCounterDirectoryPacket) |
| 3163 | { |
| 3164 | // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output |
| 3165 | LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning); |
| 3166 | // Swap the profiling connection factory in the profiling service instance with our mock one |
| 3167 | SwapProfilingConnectionFactoryHelper helper; |
| 3168 | |
| 3169 | // Redirect the standard output to a local stream so that we can parse the warning message |
| 3170 | std::stringstream ss; |
| 3171 | StreamRedirector streamRedirector(std::cout, ss.rdbuf()); |
| 3172 | |
| 3173 | // Reset the profiling service to the uninitialized state |
| 3174 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
| 3175 | options.m_EnableProfiling = true; |
| 3176 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 3177 | profilingService.ResetExternalProfilingOptions(options, true); |
| 3178 | |
| 3179 | // Bring the profiling service to the "Active" state |
| 3180 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
| 3181 | helper.ForceTransitionToState(ProfilingState::NotConnected); |
| 3182 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
| 3183 | profilingService.Update(); // Create the profiling connection |
| 3184 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
| 3185 | profilingService.Update(); // Start the command handler and the send thread |
| 3186 | |
| 3187 | // Get the mock profiling connection |
| 3188 | MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 3189 | BOOST_CHECK(mockProfilingConnection); |
| 3190 | |
| 3191 | // Wait for the Stream Metadata packet the be sent |
| 3192 | // (we are not testing the connection acknowledgement here so it will be ignored by this test) |
| 3193 | helper.WaitForProfilingPacketsSent(mockProfilingConnection); |
| 3194 | |
| 3195 | // Force the profiling service to the "Active" state |
| 3196 | helper.ForceTransitionToState(ProfilingState::Active); |
| 3197 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 3198 | |
| 3199 | // Remove the packets received so far |
| 3200 | mockProfilingConnection->Clear(); |
| 3201 | |
| 3202 | // Write a valid "Request Counter Directory" packet into the mock profiling connection, to simulate a valid |
| 3203 | // reply from an external profiling service |
| 3204 | |
| 3205 | // Request Counter Directory packet header (word 0, word 1 is always zero): |
| 3206 | // 26:31 [6] packet_family: Control Packet Family, value 0b000000 |
| 3207 | // 16:25 [10] packet_id: Packet identifier, value 0b0000000011 |
| 3208 | // 8:15 [8] reserved: Reserved, value 0b00000000 |
| 3209 | // 0:7 [8] reserved: Reserved, value 0b00000000 |
| 3210 | uint32_t packetFamily = 0; |
| 3211 | uint32_t packetId = 123; // Wrong packet id!!! |
| 3212 | uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16); |
| 3213 | |
| 3214 | // Create the Request Counter Directory packet |
| 3215 | Packet requestCounterDirectoryPacket(header); |
| 3216 | |
| 3217 | // Write the packet to the mock profiling connection |
| 3218 | mockProfilingConnection->WritePacket(std::move(requestCounterDirectoryPacket)); |
| 3219 | |
| 3220 | // Wait for a bit (must at least be the delay value of the mock profiling connection) to make sure that |
| 3221 | // the Create the Request Counter packet gets processed by the profiling service |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 3222 | std::this_thread::sleep_for(std::chrono::milliseconds(15)); |
Colm Donelan | 2ba48d2 | 2019-11-29 09:10:59 +0000 | [diff] [blame] | 3223 | |
| 3224 | streamRedirector.CancelRedirect(); |
| 3225 | |
| 3226 | // Check that the expected error has occurred and logged to the standard output |
| 3227 | if (!boost::contains(ss.str(), "Functor with requested PacketId=123 and Version=4194304 does not exist")) |
| 3228 | { |
| 3229 | std::cout << ss.str(); |
| 3230 | BOOST_FAIL("Expected string not found."); |
| 3231 | } |
| 3232 | |
| 3233 | // The Request Counter Directory Command Handler should not have updated the profiling state |
| 3234 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 3235 | |
| 3236 | // Reset the profiling service to stop any running thread |
| 3237 | options.m_EnableProfiling = false; |
| 3238 | profilingService.ResetExternalProfilingOptions(options, true); |
| 3239 | } |
| 3240 | |
| 3241 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceBadPeriodicCounterSelectionPacket) |
| 3242 | { |
| 3243 | // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output |
| 3244 | LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning); |
| 3245 | // Swap the profiling connection factory in the profiling service instance with our mock one |
| 3246 | SwapProfilingConnectionFactoryHelper helper; |
| 3247 | |
| 3248 | // Redirect the standard output to a local stream so that we can parse the warning message |
| 3249 | std::stringstream ss; |
| 3250 | StreamRedirector streamRedirector(std::cout, ss.rdbuf()); |
| 3251 | |
| 3252 | // Reset the profiling service to the uninitialized state |
| 3253 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
| 3254 | options.m_EnableProfiling = true; |
| 3255 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 3256 | profilingService.ResetExternalProfilingOptions(options, true); |
| 3257 | |
| 3258 | // Bring the profiling service to the "Active" state |
| 3259 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
| 3260 | profilingService.Update(); // Initialize the counter directory |
| 3261 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
| 3262 | profilingService.Update(); // Create the profiling connection |
| 3263 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
| 3264 | profilingService.Update(); // Start the command handler and the send thread |
| 3265 | |
| 3266 | // Get the mock profiling connection |
| 3267 | MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 3268 | BOOST_CHECK(mockProfilingConnection); |
| 3269 | |
| 3270 | // Wait for the Stream Metadata packet the be sent |
| 3271 | // (we are not testing the connection acknowledgement here so it will be ignored by this test) |
| 3272 | helper.WaitForProfilingPacketsSent(mockProfilingConnection); |
| 3273 | |
| 3274 | // Force the profiling service to the "Active" state |
| 3275 | helper.ForceTransitionToState(ProfilingState::Active); |
| 3276 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 3277 | |
| 3278 | // Remove the packets received so far |
| 3279 | mockProfilingConnection->Clear(); |
| 3280 | |
| 3281 | // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an |
| 3282 | // external profiling service |
| 3283 | |
| 3284 | // Periodic Counter Selection packet header: |
| 3285 | // 26:31 [6] packet_family: Control Packet Family, value 0b000000 |
| 3286 | // 16:25 [10] packet_id: Packet identifier, value 0b0000000100 |
| 3287 | // 8:15 [8] reserved: Reserved, value 0b00000000 |
| 3288 | // 0:7 [8] reserved: Reserved, value 0b00000000 |
| 3289 | uint32_t packetFamily = 0; |
| 3290 | uint32_t packetId = 999; // Wrong packet id!!! |
| 3291 | uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16); |
| 3292 | |
| 3293 | // Create the Periodic Counter Selection packet |
| 3294 | Packet periodicCounterSelectionPacket(header); // Length == 0, this will disable the collection of counters |
| 3295 | |
| 3296 | // Write the packet to the mock profiling connection |
| 3297 | mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket)); |
| 3298 | |
| 3299 | // Wait for a bit (must at least be the delay value of the mock profiling connection) to make sure that |
| 3300 | // the Periodic Counter Selection packet gets processed by the profiling service |
| 3301 | std::this_thread::sleep_for(std::chrono::milliseconds(7)); |
| 3302 | |
| 3303 | // Check that the expected error has occurred and logged to the standard output |
| 3304 | streamRedirector.CancelRedirect(); |
| 3305 | |
| 3306 | // Check that the expected error has occurred and logged to the standard output |
| 3307 | if (!boost::contains(ss.str(), "Functor with requested PacketId=999 and Version=4194304 does not exist")) |
| 3308 | { |
| 3309 | std::cout << ss.str(); |
| 3310 | BOOST_FAIL("Expected string not found."); |
| 3311 | } |
| 3312 | |
| 3313 | // The Periodic Counter Selection Handler should not have updated the profiling state |
| 3314 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 3315 | |
| 3316 | // Reset the profiling service to stop any running thread |
| 3317 | options.m_EnableProfiling = false; |
| 3318 | profilingService.ResetExternalProfilingOptions(options, true); |
| 3319 | } |
| 3320 | |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 3321 | BOOST_AUTO_TEST_SUITE_END() |