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