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