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