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