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