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