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