Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 6 | #include "ProfilingTests.hpp" |
Teresa Charlin | 9bab496 | 2019-09-06 12:28:35 +0100 | [diff] [blame] | 7 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 8 | #include <CommandHandler.hpp> |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 9 | #include <CommandHandlerKey.hpp> |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 10 | #include <CommandHandlerRegistry.hpp> |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 11 | #include <ConnectionAcknowledgedCommandHandler.hpp> |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 12 | #include <CounterDirectory.hpp> |
| 13 | #include <EncodeVersion.hpp> |
| 14 | #include <Holder.hpp> |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 15 | #include <ICounterValues.hpp> |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 16 | #include <Packet.hpp> |
| 17 | #include <PacketVersionResolver.hpp> |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 18 | #include <PeriodicCounterCapture.hpp> |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 19 | #include <PeriodicCounterSelectionCommandHandler.hpp> |
| 20 | #include <ProfilingStateMachine.hpp> |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 21 | #include <ProfilingUtils.hpp> |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 22 | #include <RequestCounterDirectoryCommandHandler.hpp> |
Teresa Charlin | 9bab496 | 2019-09-06 12:28:35 +0100 | [diff] [blame] | 23 | #include <Runtime.hpp> |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 24 | #include <SocketProfilingConnection.hpp> |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 25 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 26 | #include <armnn/Conversion.hpp> |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 27 | |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 28 | #include <armnn/Utils.hpp> |
| 29 | |
Sadik Armagan | bd9e2c5 | 2019-09-26 23:13:31 +0100 | [diff] [blame] | 30 | #include <boost/algorithm/string.hpp> |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 31 | #include <boost/numeric/conversion/cast.hpp> |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 32 | |
Nikhil Raj | bc62605 | 2019-08-15 15:49:45 +0100 | [diff] [blame] | 33 | #include <cstdint> |
| 34 | #include <cstring> |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 35 | #include <iostream> |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 36 | #include <limits> |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 37 | #include <map> |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 38 | #include <random> |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 39 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 40 | using namespace armnn::profiling; |
| 41 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 42 | BOOST_AUTO_TEST_SUITE(ExternalProfiling) |
| 43 | |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 44 | BOOST_AUTO_TEST_CASE(CheckCommandHandlerKeyComparisons) |
| 45 | { |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 46 | CommandHandlerKey testKey1_0(1, 1, 1); |
| 47 | CommandHandlerKey testKey1_1(1, 1, 1); |
| 48 | CommandHandlerKey testKey1_2(1, 2, 1); |
| 49 | |
| 50 | CommandHandlerKey testKey0(0, 1, 1); |
| 51 | CommandHandlerKey testKey1(0, 1, 1); |
| 52 | CommandHandlerKey testKey2(0, 1, 1); |
| 53 | CommandHandlerKey testKey3(0, 0, 0); |
| 54 | CommandHandlerKey testKey4(0, 2, 2); |
| 55 | CommandHandlerKey testKey5(0, 0, 2); |
| 56 | |
| 57 | BOOST_CHECK(testKey1_0 > testKey0); |
| 58 | BOOST_CHECK(testKey1_0 == testKey1_1); |
| 59 | BOOST_CHECK(testKey1_0 < testKey1_2); |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 60 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 61 | BOOST_CHECK(testKey1 < testKey4); |
| 62 | BOOST_CHECK(testKey1 > testKey3); |
| 63 | BOOST_CHECK(testKey1 <= testKey4); |
| 64 | BOOST_CHECK(testKey1 >= testKey3); |
| 65 | BOOST_CHECK(testKey1 <= testKey2); |
| 66 | BOOST_CHECK(testKey1 >= testKey2); |
| 67 | BOOST_CHECK(testKey1 == testKey2); |
| 68 | BOOST_CHECK(testKey1 == testKey1); |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 69 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 70 | BOOST_CHECK(!(testKey1 == testKey5)); |
| 71 | BOOST_CHECK(!(testKey1 != testKey1)); |
| 72 | BOOST_CHECK(testKey1 != testKey5); |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 73 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 74 | BOOST_CHECK(testKey1 == testKey2 && testKey2 == testKey1); |
| 75 | BOOST_CHECK(testKey0 == testKey1 && testKey1 == testKey2 && testKey0 == testKey2); |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 76 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 77 | BOOST_CHECK(testKey1.GetPacketId() == 1); |
| 78 | BOOST_CHECK(testKey1.GetVersion() == 1); |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 79 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 80 | std::vector<CommandHandlerKey> vect = { CommandHandlerKey(0, 0, 1), CommandHandlerKey(0, 2, 0), |
| 81 | CommandHandlerKey(0, 1, 0), CommandHandlerKey(0, 2, 1), |
| 82 | CommandHandlerKey(0, 1, 1), CommandHandlerKey(0, 0, 1), |
| 83 | CommandHandlerKey(0, 2, 0), CommandHandlerKey(0, 0, 0) }; |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 84 | |
| 85 | std::sort(vect.begin(), vect.end()); |
| 86 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 87 | std::vector<CommandHandlerKey> expectedVect = { CommandHandlerKey(0, 0, 0), CommandHandlerKey(0, 0, 1), |
| 88 | CommandHandlerKey(0, 0, 1), CommandHandlerKey(0, 1, 0), |
| 89 | CommandHandlerKey(0, 1, 1), CommandHandlerKey(0, 2, 0), |
| 90 | CommandHandlerKey(0, 2, 0), CommandHandlerKey(0, 2, 1) }; |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 91 | |
| 92 | BOOST_CHECK(vect == expectedVect); |
| 93 | } |
| 94 | |
Jim Flynn | ed25e0e | 2019-10-18 13:21:43 +0100 | [diff] [blame] | 95 | BOOST_AUTO_TEST_CASE(CheckPacketKeyComparisons) |
| 96 | { |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 97 | PacketKey key0(0, 0); |
| 98 | PacketKey key1(0, 0); |
| 99 | PacketKey key2(0, 1); |
| 100 | PacketKey key3(0, 2); |
| 101 | PacketKey key4(1, 0); |
| 102 | PacketKey key5(1, 0); |
| 103 | PacketKey key6(1, 1); |
Jim Flynn | ed25e0e | 2019-10-18 13:21:43 +0100 | [diff] [blame] | 104 | |
| 105 | BOOST_CHECK(!(key0 < key1)); |
| 106 | BOOST_CHECK(!(key0 > key1)); |
| 107 | BOOST_CHECK(key0 <= key1); |
| 108 | BOOST_CHECK(key0 >= key1); |
| 109 | BOOST_CHECK(key0 == key1); |
| 110 | BOOST_CHECK(key0 < key2); |
| 111 | BOOST_CHECK(key2 < key3); |
| 112 | BOOST_CHECK(key3 > key0); |
| 113 | BOOST_CHECK(key4 == key5); |
| 114 | BOOST_CHECK(key4 > key0); |
| 115 | BOOST_CHECK(key5 < key6); |
| 116 | BOOST_CHECK(key5 <= key6); |
| 117 | BOOST_CHECK(key5 != key6); |
| 118 | } |
| 119 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 120 | BOOST_AUTO_TEST_CASE(CheckCommandHandler) |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 121 | { |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 122 | PacketVersionResolver packetVersionResolver; |
| 123 | ProfilingStateMachine profilingStateMachine; |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 124 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 125 | TestProfilingConnectionBase testProfilingConnectionBase; |
| 126 | TestProfilingConnectionTimeoutError testProfilingConnectionTimeOutError; |
| 127 | TestProfilingConnectionArmnnError testProfilingConnectionArmnnError; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 128 | CounterDirectory counterDirectory; |
| 129 | MockBufferManager mockBuffer(1024); |
| 130 | SendCounterPacket sendCounterPacket(profilingStateMachine, mockBuffer); |
| 131 | ConnectionAcknowledgedCommandHandler connectionAcknowledgedCommandHandler(0, 1, 4194304, counterDirectory, |
| 132 | sendCounterPacket, profilingStateMachine); |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 133 | CommandHandlerRegistry commandHandlerRegistry; |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 134 | |
Matteo Martincigh | c2728f9 | 2019-10-07 12:35:21 +0100 | [diff] [blame] | 135 | commandHandlerRegistry.RegisterFunctor(&connectionAcknowledgedCommandHandler); |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 136 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 137 | profilingStateMachine.TransitionToState(ProfilingState::NotConnected); |
| 138 | profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck); |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 139 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 140 | CommandHandler commandHandler0(1, true, commandHandlerRegistry, packetVersionResolver); |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 141 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 142 | commandHandler0.Start(testProfilingConnectionBase); |
| 143 | commandHandler0.Start(testProfilingConnectionBase); |
| 144 | commandHandler0.Start(testProfilingConnectionBase); |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 145 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 146 | commandHandler0.Stop(); |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 147 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 148 | BOOST_CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::Active); |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 149 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 150 | profilingStateMachine.TransitionToState(ProfilingState::NotConnected); |
| 151 | profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck); |
| 152 | // commandHandler1 should give up after one timeout |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 153 | CommandHandler commandHandler1(10, true, commandHandlerRegistry, packetVersionResolver); |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 154 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 155 | commandHandler1.Start(testProfilingConnectionTimeOutError); |
Matteo Martincigh | 8881393 | 2019-10-04 14:40:04 +0100 | [diff] [blame] | 156 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 157 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
Matteo Martincigh | 8881393 | 2019-10-04 14:40:04 +0100 | [diff] [blame] | 158 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 159 | BOOST_CHECK(!commandHandler1.IsRunning()); |
| 160 | commandHandler1.Stop(); |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 161 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 162 | BOOST_CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::WaitingForAck); |
| 163 | // Now commandHandler1 should persist after a timeout |
| 164 | commandHandler1.SetStopAfterTimeout(false); |
| 165 | commandHandler1.Start(testProfilingConnectionTimeOutError); |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 166 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 167 | for (int i = 0; i < 100; i++) |
| 168 | { |
| 169 | if (profilingStateMachine.GetCurrentState() == ProfilingState::Active) |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 170 | { |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 171 | break; |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 172 | } |
| 173 | |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 174 | std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 175 | } |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 176 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 177 | commandHandler1.Stop(); |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 178 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 179 | BOOST_CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::Active); |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 180 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 181 | CommandHandler commandHandler2(100, false, commandHandlerRegistry, packetVersionResolver); |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 182 | |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 183 | commandHandler2.Start(testProfilingConnectionArmnnError); |
| 184 | |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 185 | // commandHandler2 should not stop once it encounters a non timing error |
| 186 | std::this_thread::sleep_for(std::chrono::milliseconds(500)); |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 187 | |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 188 | BOOST_CHECK(commandHandler2.IsRunning()); |
Matteo Martincigh | 8a83717 | 2019-10-04 17:01:07 +0100 | [diff] [blame] | 189 | commandHandler2.Stop(); |
FinnWilliamsArm | 4833cea | 2019-09-17 16:53:53 +0100 | [diff] [blame] | 190 | } |
| 191 | |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 192 | BOOST_AUTO_TEST_CASE(CheckEncodeVersion) |
| 193 | { |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 194 | Version version1(12); |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 195 | |
| 196 | BOOST_CHECK(version1.GetMajor() == 0); |
| 197 | BOOST_CHECK(version1.GetMinor() == 0); |
| 198 | BOOST_CHECK(version1.GetPatch() == 12); |
| 199 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 200 | Version version2(4108); |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 201 | |
| 202 | BOOST_CHECK(version2.GetMajor() == 0); |
| 203 | BOOST_CHECK(version2.GetMinor() == 1); |
| 204 | BOOST_CHECK(version2.GetPatch() == 12); |
| 205 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 206 | Version version3(4198412); |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 207 | |
| 208 | BOOST_CHECK(version3.GetMajor() == 1); |
| 209 | BOOST_CHECK(version3.GetMinor() == 1); |
| 210 | BOOST_CHECK(version3.GetPatch() == 12); |
| 211 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 212 | Version version4(0); |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 213 | |
| 214 | BOOST_CHECK(version4.GetMajor() == 0); |
| 215 | BOOST_CHECK(version4.GetMinor() == 0); |
| 216 | BOOST_CHECK(version4.GetPatch() == 0); |
| 217 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 218 | Version version5(1, 0, 0); |
Nikhil Raj | d88e47c | 2019-08-19 10:04:23 +0100 | [diff] [blame] | 219 | BOOST_CHECK(version5.GetEncodedValue() == 4194304); |
| 220 | } |
| 221 | |
Nikhil Raj | bc62605 | 2019-08-15 15:49:45 +0100 | [diff] [blame] | 222 | BOOST_AUTO_TEST_CASE(CheckPacketClass) |
| 223 | { |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 224 | uint32_t length = 4; |
Matteo Martincigh | 67ef2a5 | 2019-10-10 13:29:02 +0100 | [diff] [blame] | 225 | std::unique_ptr<unsigned char[]> packetData0 = std::make_unique<unsigned char[]>(length); |
| 226 | std::unique_ptr<unsigned char[]> packetData1 = std::make_unique<unsigned char[]>(0); |
| 227 | std::unique_ptr<unsigned char[]> nullPacketData; |
Nikhil Raj | bc62605 | 2019-08-15 15:49:45 +0100 | [diff] [blame] | 228 | |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 229 | Packet packetTest0(472580096, length, packetData0); |
Nikhil Raj | bc62605 | 2019-08-15 15:49:45 +0100 | [diff] [blame] | 230 | |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 231 | BOOST_CHECK(packetTest0.GetHeader() == 472580096); |
| 232 | BOOST_CHECK(packetTest0.GetPacketFamily() == 7); |
| 233 | BOOST_CHECK(packetTest0.GetPacketId() == 43); |
| 234 | BOOST_CHECK(packetTest0.GetLength() == length); |
| 235 | BOOST_CHECK(packetTest0.GetPacketType() == 3); |
| 236 | BOOST_CHECK(packetTest0.GetPacketClass() == 5); |
Nikhil Raj | bc62605 | 2019-08-15 15:49:45 +0100 | [diff] [blame] | 237 | |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 238 | BOOST_CHECK_THROW(Packet packetTest1(472580096, 0, packetData1), armnn::Exception); |
| 239 | BOOST_CHECK_NO_THROW(Packet packetTest2(472580096, 0, nullPacketData)); |
Nikhil Raj | bc62605 | 2019-08-15 15:49:45 +0100 | [diff] [blame] | 240 | |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 241 | Packet packetTest3(472580096, 0, nullPacketData); |
| 242 | BOOST_CHECK(packetTest3.GetLength() == 0); |
| 243 | BOOST_CHECK(packetTest3.GetData() == nullptr); |
| 244 | |
Matteo Martincigh | 67ef2a5 | 2019-10-10 13:29:02 +0100 | [diff] [blame] | 245 | const unsigned char* packetTest0Data = packetTest0.GetData(); |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 246 | Packet packetTest4(std::move(packetTest0)); |
| 247 | |
| 248 | BOOST_CHECK(packetTest0.GetData() == nullptr); |
| 249 | BOOST_CHECK(packetTest4.GetData() == packetTest0Data); |
| 250 | |
| 251 | BOOST_CHECK(packetTest4.GetHeader() == 472580096); |
| 252 | BOOST_CHECK(packetTest4.GetPacketFamily() == 7); |
| 253 | BOOST_CHECK(packetTest4.GetPacketId() == 43); |
| 254 | BOOST_CHECK(packetTest4.GetLength() == length); |
| 255 | BOOST_CHECK(packetTest4.GetPacketType() == 3); |
| 256 | BOOST_CHECK(packetTest4.GetPacketClass() == 5); |
Nikhil Raj | bc62605 | 2019-08-15 15:49:45 +0100 | [diff] [blame] | 257 | } |
| 258 | |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 259 | BOOST_AUTO_TEST_CASE(CheckCommandHandlerFunctor) |
| 260 | { |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 261 | // Hard code the version as it will be the same during a single profiling session |
| 262 | uint32_t version = 1; |
| 263 | |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 264 | TestFunctorA testFunctorA(7, 461, version); |
| 265 | TestFunctorB testFunctorB(8, 963, version); |
| 266 | TestFunctorC testFunctorC(5, 983, version); |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 267 | |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 268 | CommandHandlerKey keyA(testFunctorA.GetFamilyId(), testFunctorA.GetPacketId(), testFunctorA.GetVersion()); |
| 269 | CommandHandlerKey keyB(testFunctorB.GetFamilyId(), testFunctorB.GetPacketId(), testFunctorB.GetVersion()); |
| 270 | CommandHandlerKey keyC(testFunctorC.GetFamilyId(), testFunctorC.GetPacketId(), testFunctorC.GetVersion()); |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 271 | |
| 272 | // Create the unwrapped map to simulate the Command Handler Registry |
| 273 | std::map<CommandHandlerKey, CommandHandlerFunctor*> registry; |
| 274 | |
| 275 | registry.insert(std::make_pair(keyB, &testFunctorB)); |
| 276 | registry.insert(std::make_pair(keyA, &testFunctorA)); |
| 277 | registry.insert(std::make_pair(keyC, &testFunctorC)); |
| 278 | |
| 279 | // Check the order of the map is correct |
| 280 | auto it = registry.begin(); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 281 | BOOST_CHECK(it->first == keyC); // familyId == 5 |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 282 | it++; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 283 | BOOST_CHECK(it->first == keyA); // familyId == 7 |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 284 | it++; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 285 | BOOST_CHECK(it->first == keyB); // familyId == 8 |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 286 | |
Matteo Martincigh | 67ef2a5 | 2019-10-10 13:29:02 +0100 | [diff] [blame] | 287 | std::unique_ptr<unsigned char[]> packetDataA; |
| 288 | std::unique_ptr<unsigned char[]> packetDataB; |
| 289 | std::unique_ptr<unsigned char[]> packetDataC; |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 290 | |
| 291 | Packet packetA(500000000, 0, packetDataA); |
| 292 | Packet packetB(600000000, 0, packetDataB); |
| 293 | Packet packetC(400000000, 0, packetDataC); |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 294 | |
| 295 | // Check the correct operator of derived class is called |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 296 | registry.at(CommandHandlerKey(packetA.GetPacketFamily(), packetA.GetPacketId(), version))->operator()(packetA); |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 297 | BOOST_CHECK(testFunctorA.GetCount() == 1); |
| 298 | BOOST_CHECK(testFunctorB.GetCount() == 0); |
| 299 | BOOST_CHECK(testFunctorC.GetCount() == 0); |
| 300 | |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 301 | registry.at(CommandHandlerKey(packetB.GetPacketFamily(), packetB.GetPacketId(), version))->operator()(packetB); |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 302 | BOOST_CHECK(testFunctorA.GetCount() == 1); |
| 303 | BOOST_CHECK(testFunctorB.GetCount() == 1); |
| 304 | BOOST_CHECK(testFunctorC.GetCount() == 0); |
| 305 | |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 306 | registry.at(CommandHandlerKey(packetC.GetPacketFamily(), packetC.GetPacketId(), version))->operator()(packetC); |
Francis Murtagh | 11f99b4 | 2019-08-16 11:28:52 +0100 | [diff] [blame] | 307 | BOOST_CHECK(testFunctorA.GetCount() == 1); |
| 308 | BOOST_CHECK(testFunctorB.GetCount() == 1); |
| 309 | BOOST_CHECK(testFunctorC.GetCount() == 1); |
| 310 | } |
| 311 | |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 312 | BOOST_AUTO_TEST_CASE(CheckCommandHandlerRegistry) |
| 313 | { |
| 314 | // Hard code the version as it will be the same during a single profiling session |
| 315 | uint32_t version = 1; |
| 316 | |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 317 | TestFunctorA testFunctorA(7, 461, version); |
| 318 | TestFunctorB testFunctorB(8, 963, version); |
| 319 | TestFunctorC testFunctorC(5, 983, version); |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 320 | |
| 321 | // Create the Command Handler Registry |
| 322 | CommandHandlerRegistry registry; |
| 323 | |
| 324 | // Register multiple different derived classes |
Matteo Martincigh | c2728f9 | 2019-10-07 12:35:21 +0100 | [diff] [blame] | 325 | registry.RegisterFunctor(&testFunctorA); |
| 326 | registry.RegisterFunctor(&testFunctorB); |
| 327 | registry.RegisterFunctor(&testFunctorC); |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 328 | |
Matteo Martincigh | 67ef2a5 | 2019-10-10 13:29:02 +0100 | [diff] [blame] | 329 | std::unique_ptr<unsigned char[]> packetDataA; |
| 330 | std::unique_ptr<unsigned char[]> packetDataB; |
| 331 | std::unique_ptr<unsigned char[]> packetDataC; |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 332 | |
| 333 | Packet packetA(500000000, 0, packetDataA); |
| 334 | Packet packetB(600000000, 0, packetDataB); |
| 335 | Packet packetC(400000000, 0, packetDataC); |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 336 | |
| 337 | // Check the correct operator of derived class is called |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 338 | registry.GetFunctor(packetA.GetPacketFamily(), packetA.GetPacketId(), version)->operator()(packetA); |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 339 | BOOST_CHECK(testFunctorA.GetCount() == 1); |
| 340 | BOOST_CHECK(testFunctorB.GetCount() == 0); |
| 341 | BOOST_CHECK(testFunctorC.GetCount() == 0); |
| 342 | |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 343 | registry.GetFunctor(packetB.GetPacketFamily(), packetB.GetPacketId(), version)->operator()(packetB); |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 344 | BOOST_CHECK(testFunctorA.GetCount() == 1); |
| 345 | BOOST_CHECK(testFunctorB.GetCount() == 1); |
| 346 | BOOST_CHECK(testFunctorC.GetCount() == 0); |
| 347 | |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 348 | registry.GetFunctor(packetC.GetPacketFamily(), packetC.GetPacketId(), version)->operator()(packetC); |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 349 | BOOST_CHECK(testFunctorA.GetCount() == 1); |
| 350 | BOOST_CHECK(testFunctorB.GetCount() == 1); |
| 351 | BOOST_CHECK(testFunctorC.GetCount() == 1); |
| 352 | |
| 353 | // Re-register an existing key with a new function |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 354 | registry.RegisterFunctor(&testFunctorC, testFunctorA.GetFamilyId(), testFunctorA.GetPacketId(), version); |
| 355 | registry.GetFunctor(packetA.GetPacketFamily(), packetA.GetPacketId(), version)->operator()(packetC); |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 356 | BOOST_CHECK(testFunctorA.GetCount() == 1); |
| 357 | BOOST_CHECK(testFunctorB.GetCount() == 1); |
| 358 | BOOST_CHECK(testFunctorC.GetCount() == 2); |
| 359 | |
| 360 | // Check that non-existent key returns nullptr for its functor |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 361 | BOOST_CHECK_THROW(registry.GetFunctor(0, 0, 0), armnn::Exception); |
Francis Murtagh | 94d7915 | 2019-08-16 17:45:07 +0100 | [diff] [blame] | 362 | } |
| 363 | |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 364 | BOOST_AUTO_TEST_CASE(CheckPacketVersionResolver) |
| 365 | { |
| 366 | // Set up random number generator for generating packetId values |
| 367 | std::random_device device; |
| 368 | std::mt19937 generator(device()); |
| 369 | std::uniform_int_distribution<uint32_t> distribution(std::numeric_limits<uint32_t>::min(), |
| 370 | std::numeric_limits<uint32_t>::max()); |
| 371 | |
| 372 | // NOTE: Expected version is always 1.0.0, regardless of packetId |
| 373 | const Version expectedVersion(1, 0, 0); |
| 374 | |
| 375 | PacketVersionResolver packetVersionResolver; |
| 376 | |
| 377 | constexpr unsigned int numTests = 10u; |
| 378 | |
| 379 | for (unsigned int i = 0u; i < numTests; ++i) |
| 380 | { |
Jim Flynn | ed25e0e | 2019-10-18 13:21:43 +0100 | [diff] [blame] | 381 | const uint32_t familyId = distribution(generator); |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 382 | const uint32_t packetId = distribution(generator); |
Jim Flynn | ed25e0e | 2019-10-18 13:21:43 +0100 | [diff] [blame] | 383 | Version resolvedVersion = packetVersionResolver.ResolvePacketVersion(familyId, packetId); |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 384 | |
| 385 | BOOST_TEST(resolvedVersion == expectedVersion); |
| 386 | } |
| 387 | } |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 388 | |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 389 | void ProfilingCurrentStateThreadImpl(ProfilingStateMachine& states) |
| 390 | { |
| 391 | ProfilingState newState = ProfilingState::NotConnected; |
| 392 | states.GetCurrentState(); |
| 393 | states.TransitionToState(newState); |
| 394 | } |
| 395 | |
| 396 | BOOST_AUTO_TEST_CASE(CheckProfilingStateMachine) |
| 397 | { |
| 398 | ProfilingStateMachine profilingState1(ProfilingState::Uninitialised); |
| 399 | profilingState1.TransitionToState(ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 400 | BOOST_CHECK(profilingState1.GetCurrentState() == ProfilingState::Uninitialised); |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 401 | |
| 402 | ProfilingStateMachine profilingState2(ProfilingState::Uninitialised); |
| 403 | profilingState2.TransitionToState(ProfilingState::NotConnected); |
| 404 | BOOST_CHECK(profilingState2.GetCurrentState() == ProfilingState::NotConnected); |
| 405 | |
| 406 | ProfilingStateMachine profilingState3(ProfilingState::NotConnected); |
| 407 | profilingState3.TransitionToState(ProfilingState::NotConnected); |
| 408 | BOOST_CHECK(profilingState3.GetCurrentState() == ProfilingState::NotConnected); |
| 409 | |
| 410 | ProfilingStateMachine profilingState4(ProfilingState::NotConnected); |
| 411 | profilingState4.TransitionToState(ProfilingState::WaitingForAck); |
| 412 | BOOST_CHECK(profilingState4.GetCurrentState() == ProfilingState::WaitingForAck); |
| 413 | |
| 414 | ProfilingStateMachine profilingState5(ProfilingState::WaitingForAck); |
| 415 | profilingState5.TransitionToState(ProfilingState::WaitingForAck); |
| 416 | BOOST_CHECK(profilingState5.GetCurrentState() == ProfilingState::WaitingForAck); |
| 417 | |
| 418 | ProfilingStateMachine profilingState6(ProfilingState::WaitingForAck); |
| 419 | profilingState6.TransitionToState(ProfilingState::Active); |
| 420 | BOOST_CHECK(profilingState6.GetCurrentState() == ProfilingState::Active); |
| 421 | |
| 422 | ProfilingStateMachine profilingState7(ProfilingState::Active); |
| 423 | profilingState7.TransitionToState(ProfilingState::NotConnected); |
| 424 | BOOST_CHECK(profilingState7.GetCurrentState() == ProfilingState::NotConnected); |
| 425 | |
| 426 | ProfilingStateMachine profilingState8(ProfilingState::Active); |
| 427 | profilingState8.TransitionToState(ProfilingState::Active); |
| 428 | BOOST_CHECK(profilingState8.GetCurrentState() == ProfilingState::Active); |
| 429 | |
| 430 | ProfilingStateMachine profilingState9(ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 431 | BOOST_CHECK_THROW(profilingState9.TransitionToState(ProfilingState::WaitingForAck), armnn::Exception); |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 432 | |
| 433 | ProfilingStateMachine profilingState10(ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 434 | BOOST_CHECK_THROW(profilingState10.TransitionToState(ProfilingState::Active), armnn::Exception); |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 435 | |
| 436 | ProfilingStateMachine profilingState11(ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 437 | BOOST_CHECK_THROW(profilingState11.TransitionToState(ProfilingState::Uninitialised), armnn::Exception); |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 438 | |
| 439 | ProfilingStateMachine profilingState12(ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 440 | BOOST_CHECK_THROW(profilingState12.TransitionToState(ProfilingState::Active), armnn::Exception); |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 441 | |
| 442 | ProfilingStateMachine profilingState13(ProfilingState::WaitingForAck); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 443 | BOOST_CHECK_THROW(profilingState13.TransitionToState(ProfilingState::Uninitialised), armnn::Exception); |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 444 | |
| 445 | ProfilingStateMachine profilingState14(ProfilingState::WaitingForAck); |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 446 | profilingState14.TransitionToState(ProfilingState::NotConnected); |
| 447 | BOOST_CHECK(profilingState14.GetCurrentState() == ProfilingState::NotConnected); |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 448 | |
| 449 | ProfilingStateMachine profilingState15(ProfilingState::Active); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 450 | BOOST_CHECK_THROW(profilingState15.TransitionToState(ProfilingState::Uninitialised), armnn::Exception); |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 451 | |
| 452 | ProfilingStateMachine profilingState16(armnn::profiling::ProfilingState::Active); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 453 | BOOST_CHECK_THROW(profilingState16.TransitionToState(ProfilingState::WaitingForAck), armnn::Exception); |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 454 | |
| 455 | ProfilingStateMachine profilingState17(ProfilingState::Uninitialised); |
| 456 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 457 | std::thread thread1(ProfilingCurrentStateThreadImpl, std::ref(profilingState17)); |
| 458 | std::thread thread2(ProfilingCurrentStateThreadImpl, std::ref(profilingState17)); |
| 459 | std::thread thread3(ProfilingCurrentStateThreadImpl, std::ref(profilingState17)); |
| 460 | std::thread thread4(ProfilingCurrentStateThreadImpl, std::ref(profilingState17)); |
| 461 | std::thread thread5(ProfilingCurrentStateThreadImpl, std::ref(profilingState17)); |
Nikhil Raj | 3ecc510 | 2019-09-03 15:55:33 +0100 | [diff] [blame] | 462 | |
| 463 | thread1.join(); |
| 464 | thread2.join(); |
| 465 | thread3.join(); |
| 466 | thread4.join(); |
| 467 | thread5.join(); |
| 468 | |
| 469 | BOOST_TEST((profilingState17.GetCurrentState() == ProfilingState::NotConnected)); |
| 470 | } |
Aron Virginas-Tar | e898db9 | 2019-08-22 12:56:34 +0100 | [diff] [blame] | 471 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 472 | 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] | 473 | { |
| 474 | holder.SetCaptureData(capturePeriod, counterIds); |
| 475 | } |
| 476 | |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 477 | void CaptureDataReadThreadImpl(const Holder& holder, CaptureData& captureData) |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 478 | { |
| 479 | captureData = holder.GetCaptureData(); |
| 480 | } |
| 481 | |
| 482 | BOOST_AUTO_TEST_CASE(CheckCaptureDataHolder) |
| 483 | { |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 484 | std::map<uint32_t, std::vector<uint16_t>> periodIdMap; |
| 485 | std::vector<uint16_t> counterIds; |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 486 | uint32_t numThreads = 10; |
| 487 | for (uint32_t i = 0; i < numThreads; ++i) |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 488 | { |
| 489 | counterIds.emplace_back(i); |
| 490 | periodIdMap.insert(std::make_pair(i, counterIds)); |
| 491 | } |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 492 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 493 | // Verify the read and write threads set the holder correctly |
| 494 | // and retrieve the expected values |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 495 | Holder holder; |
| 496 | BOOST_CHECK((holder.GetCaptureData()).GetCapturePeriod() == 0); |
| 497 | BOOST_CHECK(((holder.GetCaptureData()).GetCounterIds()).empty()); |
| 498 | |
| 499 | // Check Holder functions |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 500 | std::thread thread1(CaptureDataWriteThreadImpl, std::ref(holder), 2, std::ref(periodIdMap[2])); |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 501 | thread1.join(); |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 502 | BOOST_CHECK((holder.GetCaptureData()).GetCapturePeriod() == 2); |
| 503 | BOOST_CHECK((holder.GetCaptureData()).GetCounterIds() == periodIdMap[2]); |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 504 | // NOTE: now that we have some initial values in the holder we don't have to worry |
| 505 | // in the multi-threaded section below about a read thread accessing the holder |
| 506 | // before any write thread has gotten to it so we read period = 0, counterIds empty |
| 507 | // instead of period = 0, counterIds = {0} as will the case when write thread 0 |
| 508 | // has executed. |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 509 | |
| 510 | CaptureData captureData; |
| 511 | std::thread thread2(CaptureDataReadThreadImpl, std::ref(holder), std::ref(captureData)); |
| 512 | thread2.join(); |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 513 | BOOST_CHECK(captureData.GetCapturePeriod() == 2); |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 514 | BOOST_CHECK(captureData.GetCounterIds() == periodIdMap[2]); |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 515 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 516 | std::map<uint32_t, CaptureData> captureDataIdMap; |
| 517 | for (uint32_t i = 0; i < numThreads; ++i) |
| 518 | { |
| 519 | CaptureData perThreadCaptureData; |
| 520 | captureDataIdMap.insert(std::make_pair(i, perThreadCaptureData)); |
| 521 | } |
| 522 | |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 523 | std::vector<std::thread> threadsVect; |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 524 | std::vector<std::thread> readThreadsVect; |
| 525 | for (uint32_t i = 0; i < numThreads; ++i) |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 526 | { |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 527 | threadsVect.emplace_back( |
| 528 | std::thread(CaptureDataWriteThreadImpl, std::ref(holder), i, std::ref(periodIdMap[i]))); |
Francis Murtagh | 0696569 | 2019-09-05 16:29:01 +0100 | [diff] [blame] | 529 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 530 | // Verify that the CaptureData goes into the thread in a virgin state |
| 531 | BOOST_CHECK(captureDataIdMap.at(i).GetCapturePeriod() == 0); |
| 532 | BOOST_CHECK(captureDataIdMap.at(i).GetCounterIds().empty()); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 533 | readThreadsVect.emplace_back( |
| 534 | std::thread(CaptureDataReadThreadImpl, std::ref(holder), std::ref(captureDataIdMap.at(i)))); |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 535 | } |
| 536 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 537 | for (uint32_t i = 0; i < numThreads; ++i) |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 538 | { |
| 539 | threadsVect[i].join(); |
Francis Murtagh | bd70716 | 2019-09-09 11:26:44 +0100 | [diff] [blame] | 540 | readThreadsVect[i].join(); |
| 541 | } |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 542 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 543 | // Look at the CaptureData that each read thread has filled |
| 544 | // the capture period it read should match the counter ids entry |
| 545 | for (uint32_t i = 0; i < numThreads; ++i) |
| 546 | { |
| 547 | CaptureData perThreadCaptureData = captureDataIdMap.at(i); |
| 548 | BOOST_CHECK(perThreadCaptureData.GetCounterIds() == periodIdMap.at(perThreadCaptureData.GetCapturePeriod())); |
| 549 | } |
Matthew Bentham | 46d1c62 | 2019-09-13 12:45:04 +0100 | [diff] [blame] | 550 | } |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 551 | |
Matthew Bentham | 46d1c62 | 2019-09-13 12:45:04 +0100 | [diff] [blame] | 552 | BOOST_AUTO_TEST_CASE(CaptureDataMethods) |
| 553 | { |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 554 | // Check CaptureData setter and getter functions |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 555 | std::vector<uint16_t> counterIds = { 42, 29, 13 }; |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 556 | CaptureData captureData; |
| 557 | BOOST_CHECK(captureData.GetCapturePeriod() == 0); |
| 558 | BOOST_CHECK((captureData.GetCounterIds()).empty()); |
| 559 | captureData.SetCapturePeriod(150); |
| 560 | captureData.SetCounterIds(counterIds); |
| 561 | BOOST_CHECK(captureData.GetCapturePeriod() == 150); |
| 562 | BOOST_CHECK(captureData.GetCounterIds() == counterIds); |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 563 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 564 | // Check assignment operator |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 565 | CaptureData secondCaptureData; |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 566 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 567 | secondCaptureData = captureData; |
| 568 | BOOST_CHECK(secondCaptureData.GetCapturePeriod() == 150); |
Matthew Bentham | 46d1c62 | 2019-09-13 12:45:04 +0100 | [diff] [blame] | 569 | BOOST_CHECK(secondCaptureData.GetCounterIds() == counterIds); |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 570 | |
| 571 | // Check copy constructor |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 572 | CaptureData copyConstructedCaptureData(captureData); |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 573 | |
Jim Flynn | 8355ec9 | 2019-09-17 12:29:50 +0100 | [diff] [blame] | 574 | BOOST_CHECK(copyConstructedCaptureData.GetCapturePeriod() == 150); |
Matthew Bentham | 46d1c62 | 2019-09-13 12:45:04 +0100 | [diff] [blame] | 575 | BOOST_CHECK(copyConstructedCaptureData.GetCounterIds() == counterIds); |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 576 | } |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 577 | |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 578 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceDisabled) |
| 579 | { |
| 580 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 581 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 582 | profilingService.ResetExternalProfilingOptions(options, true); |
| 583 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 584 | profilingService.Update(); |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 585 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 586 | } |
| 587 | |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 588 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceEnabled) |
| 589 | { |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 590 | // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output |
| 591 | LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning); |
| 592 | |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 593 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 594 | options.m_EnableProfiling = true; |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 595 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 596 | profilingService.ResetExternalProfilingOptions(options, true); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 597 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
| 598 | profilingService.Update(); |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 599 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 600 | |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 601 | // Redirect the output to a local stream so that we can parse the warning message |
Sadik Armagan | bd9e2c5 | 2019-09-26 23:13:31 +0100 | [diff] [blame] | 602 | std::stringstream ss; |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 603 | StreamRedirector streamRedirector(std::cout, ss.rdbuf()); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 604 | profilingService.Update(); |
Sadik Armagan | bd9e2c5 | 2019-09-26 23:13:31 +0100 | [diff] [blame] | 605 | BOOST_CHECK(boost::contains(ss.str(), "Cannot connect to stream socket: Connection refused")); |
| 606 | } |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 607 | |
| 608 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceEnabledRuntime) |
| 609 | { |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 610 | // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output |
| 611 | LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning); |
| 612 | |
Keith Davis | 02356de | 2019-08-26 18:28:17 +0100 | [diff] [blame] | 613 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 614 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 615 | profilingService.ResetExternalProfilingOptions(options, true); |
| 616 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 617 | profilingService.Update(); |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 618 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
FinnWilliamsArm | ce2d9d1 | 2019-09-18 10:28:16 +0100 | [diff] [blame] | 619 | options.m_EnableProfiling = true; |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 620 | profilingService.ResetExternalProfilingOptions(options); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 621 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
| 622 | profilingService.Update(); |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 623 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
Sadik Armagan | bd9e2c5 | 2019-09-26 23:13:31 +0100 | [diff] [blame] | 624 | |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 625 | // Redirect the output to a local stream so that we can parse the warning message |
Sadik Armagan | bd9e2c5 | 2019-09-26 23:13:31 +0100 | [diff] [blame] | 626 | std::stringstream ss; |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 627 | StreamRedirector streamRedirector(std::cout, ss.rdbuf()); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 628 | profilingService.Update(); |
Sadik Armagan | bd9e2c5 | 2019-09-26 23:13:31 +0100 | [diff] [blame] | 629 | BOOST_CHECK(boost::contains(ss.str(), "Cannot connect to stream socket: Connection refused")); |
Francis Murtagh | 68f78d8 | 2019-09-04 16:42:29 +0100 | [diff] [blame] | 630 | } |
| 631 | |
FinnWilliamsArm | ce2d9d1 | 2019-09-18 10:28:16 +0100 | [diff] [blame] | 632 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceCounterDirectory) |
| 633 | { |
| 634 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 635 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 636 | profilingService.ResetExternalProfilingOptions(options, true); |
FinnWilliamsArm | ce2d9d1 | 2019-09-18 10:28:16 +0100 | [diff] [blame] | 637 | |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 638 | const ICounterDirectory& counterDirectory0 = profilingService.GetCounterDirectory(); |
FinnWilliamsArm | ce2d9d1 | 2019-09-18 10:28:16 +0100 | [diff] [blame] | 639 | BOOST_CHECK(counterDirectory0.GetCounterCount() == 0); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 640 | profilingService.Update(); |
| 641 | BOOST_CHECK(counterDirectory0.GetCounterCount() == 0); |
FinnWilliamsArm | ce2d9d1 | 2019-09-18 10:28:16 +0100 | [diff] [blame] | 642 | |
| 643 | options.m_EnableProfiling = true; |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 644 | profilingService.ResetExternalProfilingOptions(options); |
FinnWilliamsArm | ce2d9d1 | 2019-09-18 10:28:16 +0100 | [diff] [blame] | 645 | |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 646 | const ICounterDirectory& counterDirectory1 = profilingService.GetCounterDirectory(); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 647 | BOOST_CHECK(counterDirectory1.GetCounterCount() == 0); |
| 648 | profilingService.Update(); |
FinnWilliamsArm | ce2d9d1 | 2019-09-18 10:28:16 +0100 | [diff] [blame] | 649 | BOOST_CHECK(counterDirectory1.GetCounterCount() != 0); |
| 650 | } |
| 651 | |
FinnWilliamsArm | f6e534a | 2019-09-16 15:45:42 +0100 | [diff] [blame] | 652 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceCounterValues) |
| 653 | { |
| 654 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 655 | options.m_EnableProfiling = true; |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 656 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 657 | profilingService.ResetExternalProfilingOptions(options, true); |
| 658 | |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 659 | profilingService.Update(); |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 660 | const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory(); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 661 | const Counters& counters = counterDirectory.GetCounters(); |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 662 | BOOST_CHECK(!counters.empty()); |
| 663 | |
| 664 | // Get the UID of the first counter for testing |
| 665 | uint16_t counterUid = counters.begin()->first; |
FinnWilliamsArm | f6e534a | 2019-09-16 15:45:42 +0100 | [diff] [blame] | 666 | |
| 667 | ProfilingService* profilingServicePtr = &profilingService; |
| 668 | std::vector<std::thread> writers; |
| 669 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 670 | for (int i = 0; i < 100; ++i) |
FinnWilliamsArm | f6e534a | 2019-09-16 15:45:42 +0100 | [diff] [blame] | 671 | { |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 672 | // Increment and decrement the first counter |
| 673 | writers.push_back(std::thread(&ProfilingService::IncrementCounterValue, profilingServicePtr, counterUid)); |
| 674 | writers.push_back(std::thread(&ProfilingService::DecrementCounterValue, profilingServicePtr, counterUid)); |
| 675 | // Add 10 and subtract 5 from the first counter |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 676 | writers.push_back(std::thread(&ProfilingService::AddCounterValue, profilingServicePtr, counterUid, 10)); |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 677 | writers.push_back(std::thread(&ProfilingService::SubtractCounterValue, profilingServicePtr, counterUid, 5)); |
FinnWilliamsArm | f6e534a | 2019-09-16 15:45:42 +0100 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | std::for_each(writers.begin(), writers.end(), mem_fn(&std::thread::join)); |
| 681 | |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 682 | uint32_t counterValue = 0; |
| 683 | BOOST_CHECK_NO_THROW(counterValue = profilingService.GetCounterValue(counterUid)); |
FinnWilliamsArm | f6e534a | 2019-09-16 15:45:42 +0100 | [diff] [blame] | 684 | BOOST_CHECK(counterValue == 500); |
| 685 | |
Matteo Martincigh | a84edee | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 686 | BOOST_CHECK_NO_THROW(profilingService.SetCounterValue(counterUid, 0)); |
| 687 | BOOST_CHECK_NO_THROW(counterValue = profilingService.GetCounterValue(counterUid)); |
FinnWilliamsArm | f6e534a | 2019-09-16 15:45:42 +0100 | [diff] [blame] | 688 | BOOST_CHECK(counterValue == 0); |
FinnWilliamsArm | f6e534a | 2019-09-16 15:45:42 +0100 | [diff] [blame] | 689 | } |
| 690 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 691 | BOOST_AUTO_TEST_CASE(CheckProfilingObjectUids) |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 692 | { |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 693 | uint16_t uid = 0; |
| 694 | BOOST_CHECK_NO_THROW(uid = GetNextUid()); |
| 695 | BOOST_CHECK(uid >= 1); |
| 696 | |
| 697 | uint16_t nextUid = 0; |
| 698 | BOOST_CHECK_NO_THROW(nextUid = GetNextUid()); |
| 699 | BOOST_CHECK(nextUid > uid); |
| 700 | |
| 701 | std::vector<uint16_t> counterUids; |
| 702 | BOOST_CHECK_NO_THROW(counterUids = GetNextCounterUids(0)); |
| 703 | BOOST_CHECK(counterUids.size() == 1); |
| 704 | BOOST_CHECK(counterUids[0] >= 0); |
| 705 | |
| 706 | std::vector<uint16_t> nextCounterUids; |
| 707 | BOOST_CHECK_NO_THROW(nextCounterUids = GetNextCounterUids(1)); |
| 708 | BOOST_CHECK(nextCounterUids.size() == 1); |
| 709 | BOOST_CHECK(nextCounterUids[0] > counterUids[0]); |
| 710 | |
| 711 | std::vector<uint16_t> counterUidsMultiCore; |
| 712 | uint16_t numberOfCores = 13; |
| 713 | BOOST_CHECK_NO_THROW(counterUidsMultiCore = GetNextCounterUids(numberOfCores)); |
| 714 | BOOST_CHECK(counterUidsMultiCore.size() == numberOfCores); |
| 715 | BOOST_CHECK(counterUidsMultiCore.front() >= nextCounterUids[0]); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 716 | for (size_t i = 1; i < numberOfCores; i++) |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 717 | { |
| 718 | BOOST_CHECK(counterUidsMultiCore[i] == counterUidsMultiCore[i - 1] + 1); |
| 719 | } |
| 720 | BOOST_CHECK(counterUidsMultiCore.back() == counterUidsMultiCore.front() + numberOfCores - 1); |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 721 | } |
| 722 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 723 | BOOST_AUTO_TEST_CASE(CheckCounterDirectoryRegisterCategory) |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 724 | { |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 725 | CounterDirectory counterDirectory; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 726 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 0); |
| 727 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 0); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 728 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 729 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 730 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 731 | // Register a category with an invalid name |
| 732 | const Category* noCategory = nullptr; |
| 733 | BOOST_CHECK_THROW(noCategory = counterDirectory.RegisterCategory(""), armnn::InvalidArgumentException); |
| 734 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 0); |
| 735 | BOOST_CHECK(!noCategory); |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 736 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 737 | // Register a category with an invalid name |
| 738 | BOOST_CHECK_THROW(noCategory = counterDirectory.RegisterCategory("invalid category"), |
| 739 | armnn::InvalidArgumentException); |
| 740 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 0); |
| 741 | BOOST_CHECK(!noCategory); |
| 742 | |
| 743 | // Register a new category |
| 744 | const std::string categoryName = "some_category"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 745 | const Category* category = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 746 | BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName)); |
| 747 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 748 | BOOST_CHECK(category); |
| 749 | BOOST_CHECK(category->m_Name == categoryName); |
| 750 | BOOST_CHECK(category->m_Counters.empty()); |
| 751 | BOOST_CHECK(category->m_DeviceUid == 0); |
| 752 | BOOST_CHECK(category->m_CounterSetUid == 0); |
| 753 | |
| 754 | // Get the registered category |
| 755 | const Category* registeredCategory = counterDirectory.GetCategory(categoryName); |
| 756 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 757 | BOOST_CHECK(registeredCategory); |
| 758 | BOOST_CHECK(registeredCategory == category); |
| 759 | |
| 760 | // Try to get a category not registered |
| 761 | const Category* notRegisteredCategory = counterDirectory.GetCategory("not_registered_category"); |
| 762 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 763 | BOOST_CHECK(!notRegisteredCategory); |
| 764 | |
| 765 | // Register a category already registered |
| 766 | const Category* anotherCategory = nullptr; |
| 767 | BOOST_CHECK_THROW(anotherCategory = counterDirectory.RegisterCategory(categoryName), |
| 768 | armnn::InvalidArgumentException); |
| 769 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 770 | BOOST_CHECK(!anotherCategory); |
| 771 | |
| 772 | // Register a device for testing |
| 773 | const std::string deviceName = "some_device"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 774 | const Device* device = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 775 | BOOST_CHECK_NO_THROW(device = counterDirectory.RegisterDevice(deviceName)); |
| 776 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 777 | BOOST_CHECK(device); |
| 778 | BOOST_CHECK(device->m_Uid >= 1); |
| 779 | BOOST_CHECK(device->m_Name == deviceName); |
| 780 | BOOST_CHECK(device->m_Cores == 0); |
| 781 | |
| 782 | // Register a new category not associated to any device |
| 783 | const std::string categoryWoDeviceName = "some_category_without_device"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 784 | const Category* categoryWoDevice = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 785 | BOOST_CHECK_NO_THROW(categoryWoDevice = counterDirectory.RegisterCategory(categoryWoDeviceName, 0)); |
| 786 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 2); |
| 787 | BOOST_CHECK(categoryWoDevice); |
| 788 | BOOST_CHECK(categoryWoDevice->m_Name == categoryWoDeviceName); |
| 789 | BOOST_CHECK(categoryWoDevice->m_Counters.empty()); |
| 790 | BOOST_CHECK(categoryWoDevice->m_DeviceUid == 0); |
| 791 | BOOST_CHECK(categoryWoDevice->m_CounterSetUid == 0); |
| 792 | |
| 793 | // Register a new category associated to an invalid device |
| 794 | const std::string categoryWInvalidDeviceName = "some_category_with_invalid_device"; |
| 795 | |
| 796 | ARMNN_NO_CONVERSION_WARN_BEGIN |
| 797 | uint16_t invalidDeviceUid = device->m_Uid + 10; |
| 798 | ARMNN_NO_CONVERSION_WARN_END |
| 799 | |
| 800 | const Category* categoryWInvalidDevice = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 801 | BOOST_CHECK_THROW(categoryWInvalidDevice = |
| 802 | counterDirectory.RegisterCategory(categoryWInvalidDeviceName, invalidDeviceUid), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 803 | armnn::InvalidArgumentException); |
| 804 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 2); |
| 805 | BOOST_CHECK(!categoryWInvalidDevice); |
| 806 | |
| 807 | // Register a new category associated to a valid device |
| 808 | const std::string categoryWValidDeviceName = "some_category_with_valid_device"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 809 | const Category* categoryWValidDevice = nullptr; |
| 810 | BOOST_CHECK_NO_THROW(categoryWValidDevice = |
| 811 | counterDirectory.RegisterCategory(categoryWValidDeviceName, device->m_Uid)); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 812 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 3); |
| 813 | BOOST_CHECK(categoryWValidDevice); |
| 814 | BOOST_CHECK(categoryWValidDevice != category); |
| 815 | BOOST_CHECK(categoryWValidDevice->m_Name == categoryWValidDeviceName); |
| 816 | BOOST_CHECK(categoryWValidDevice->m_DeviceUid == device->m_Uid); |
| 817 | BOOST_CHECK(categoryWValidDevice->m_CounterSetUid == 0); |
| 818 | |
| 819 | // Register a counter set for testing |
| 820 | const std::string counterSetName = "some_counter_set"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 821 | const CounterSet* counterSet = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 822 | BOOST_CHECK_NO_THROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName)); |
| 823 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1); |
| 824 | BOOST_CHECK(counterSet); |
| 825 | BOOST_CHECK(counterSet->m_Uid >= 1); |
| 826 | BOOST_CHECK(counterSet->m_Name == counterSetName); |
| 827 | BOOST_CHECK(counterSet->m_Count == 0); |
| 828 | |
| 829 | // Register a new category not associated to any counter set |
| 830 | const std::string categoryWoCounterSetName = "some_category_without_counter_set"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 831 | const Category* categoryWoCounterSet = nullptr; |
| 832 | BOOST_CHECK_NO_THROW(categoryWoCounterSet = |
| 833 | counterDirectory.RegisterCategory(categoryWoCounterSetName, armnn::EmptyOptional(), 0)); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 834 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 4); |
| 835 | BOOST_CHECK(categoryWoCounterSet); |
| 836 | BOOST_CHECK(categoryWoCounterSet->m_Name == categoryWoCounterSetName); |
| 837 | BOOST_CHECK(categoryWoCounterSet->m_DeviceUid == 0); |
| 838 | BOOST_CHECK(categoryWoCounterSet->m_CounterSetUid == 0); |
| 839 | |
| 840 | // Register a new category associated to an invalid counter set |
| 841 | const std::string categoryWInvalidCounterSetName = "some_category_with_invalid_counter_set"; |
| 842 | |
| 843 | ARMNN_NO_CONVERSION_WARN_BEGIN |
| 844 | uint16_t invalidCunterSetUid = counterSet->m_Uid + 10; |
| 845 | ARMNN_NO_CONVERSION_WARN_END |
| 846 | |
| 847 | const Category* categoryWInvalidCounterSet = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 848 | BOOST_CHECK_THROW(categoryWInvalidCounterSet = counterDirectory.RegisterCategory( |
| 849 | categoryWInvalidCounterSetName, armnn::EmptyOptional(), invalidCunterSetUid), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 850 | armnn::InvalidArgumentException); |
| 851 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 4); |
| 852 | BOOST_CHECK(!categoryWInvalidCounterSet); |
| 853 | |
| 854 | // Register a new category associated to a valid counter set |
| 855 | const std::string categoryWValidCounterSetName = "some_category_with_valid_counter_set"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 856 | const Category* categoryWValidCounterSet = nullptr; |
| 857 | BOOST_CHECK_NO_THROW(categoryWValidCounterSet = counterDirectory.RegisterCategory( |
| 858 | categoryWValidCounterSetName, armnn::EmptyOptional(), counterSet->m_Uid)); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 859 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 5); |
| 860 | BOOST_CHECK(categoryWValidCounterSet); |
| 861 | BOOST_CHECK(categoryWValidCounterSet != category); |
| 862 | BOOST_CHECK(categoryWValidCounterSet->m_Name == categoryWValidCounterSetName); |
| 863 | BOOST_CHECK(categoryWValidCounterSet->m_DeviceUid == 0); |
| 864 | BOOST_CHECK(categoryWValidCounterSet->m_CounterSetUid == counterSet->m_Uid); |
| 865 | |
| 866 | // Register a new category associated to a valid device and counter set |
| 867 | const std::string categoryWValidDeviceAndValidCounterSetName = "some_category_with_valid_device_and_counter_set"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 868 | const Category* categoryWValidDeviceAndValidCounterSet = nullptr; |
| 869 | BOOST_CHECK_NO_THROW(categoryWValidDeviceAndValidCounterSet = counterDirectory.RegisterCategory( |
| 870 | categoryWValidDeviceAndValidCounterSetName, device->m_Uid, counterSet->m_Uid)); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 871 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 6); |
| 872 | BOOST_CHECK(categoryWValidDeviceAndValidCounterSet); |
| 873 | BOOST_CHECK(categoryWValidDeviceAndValidCounterSet != category); |
| 874 | BOOST_CHECK(categoryWValidDeviceAndValidCounterSet->m_Name == categoryWValidDeviceAndValidCounterSetName); |
| 875 | BOOST_CHECK(categoryWValidDeviceAndValidCounterSet->m_DeviceUid == device->m_Uid); |
| 876 | BOOST_CHECK(categoryWValidDeviceAndValidCounterSet->m_CounterSetUid == counterSet->m_Uid); |
| 877 | } |
| 878 | |
| 879 | BOOST_AUTO_TEST_CASE(CheckCounterDirectoryRegisterDevice) |
| 880 | { |
| 881 | CounterDirectory counterDirectory; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 882 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 0); |
| 883 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 0); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 884 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 885 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 886 | |
| 887 | // Register a device with an invalid name |
| 888 | const Device* noDevice = nullptr; |
| 889 | BOOST_CHECK_THROW(noDevice = counterDirectory.RegisterDevice(""), armnn::InvalidArgumentException); |
| 890 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 0); |
| 891 | BOOST_CHECK(!noDevice); |
| 892 | |
| 893 | // Register a device with an invalid name |
| 894 | BOOST_CHECK_THROW(noDevice = counterDirectory.RegisterDevice("inv@lid nam€"), armnn::InvalidArgumentException); |
| 895 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 0); |
| 896 | BOOST_CHECK(!noDevice); |
| 897 | |
| 898 | // Register a new device with no cores or parent category |
| 899 | const std::string deviceName = "some_device"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 900 | const Device* device = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 901 | BOOST_CHECK_NO_THROW(device = counterDirectory.RegisterDevice(deviceName)); |
| 902 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 903 | BOOST_CHECK(device); |
| 904 | BOOST_CHECK(device->m_Name == deviceName); |
| 905 | BOOST_CHECK(device->m_Uid >= 1); |
| 906 | BOOST_CHECK(device->m_Cores == 0); |
| 907 | |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 908 | // Try getting an unregistered device |
| 909 | const Device* unregisteredDevice = counterDirectory.GetDevice(9999); |
| 910 | BOOST_CHECK(!unregisteredDevice); |
| 911 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 912 | // Get the registered device |
| 913 | const Device* registeredDevice = counterDirectory.GetDevice(device->m_Uid); |
| 914 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 915 | BOOST_CHECK(registeredDevice); |
| 916 | BOOST_CHECK(registeredDevice == device); |
| 917 | |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 918 | // Register a device with the name of a device already registered |
| 919 | const Device* deviceSameName = nullptr; |
| 920 | BOOST_CHECK_THROW(deviceSameName = counterDirectory.RegisterDevice(deviceName), armnn::InvalidArgumentException); |
| 921 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 922 | BOOST_CHECK(!deviceSameName); |
| 923 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 924 | // Register a new device with cores and no parent category |
| 925 | const std::string deviceWCoresName = "some_device_with_cores"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 926 | const Device* deviceWCores = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 927 | BOOST_CHECK_NO_THROW(deviceWCores = counterDirectory.RegisterDevice(deviceWCoresName, 2)); |
| 928 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 2); |
| 929 | BOOST_CHECK(deviceWCores); |
| 930 | BOOST_CHECK(deviceWCores->m_Name == deviceWCoresName); |
| 931 | BOOST_CHECK(deviceWCores->m_Uid >= 1); |
| 932 | BOOST_CHECK(deviceWCores->m_Uid > device->m_Uid); |
| 933 | BOOST_CHECK(deviceWCores->m_Cores == 2); |
| 934 | |
| 935 | // Get the registered device |
| 936 | const Device* registeredDeviceWCores = counterDirectory.GetDevice(deviceWCores->m_Uid); |
| 937 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 2); |
| 938 | BOOST_CHECK(registeredDeviceWCores); |
| 939 | BOOST_CHECK(registeredDeviceWCores == deviceWCores); |
| 940 | BOOST_CHECK(registeredDeviceWCores != device); |
| 941 | |
| 942 | // Register a new device with cores and invalid parent category |
| 943 | const std::string deviceWCoresWInvalidParentCategoryName = "some_device_with_cores_with_invalid_parent_category"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 944 | const Device* deviceWCoresWInvalidParentCategory = nullptr; |
| 945 | BOOST_CHECK_THROW(deviceWCoresWInvalidParentCategory = |
| 946 | counterDirectory.RegisterDevice(deviceWCoresWInvalidParentCategoryName, 3, std::string("")), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 947 | armnn::InvalidArgumentException); |
| 948 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 2); |
| 949 | BOOST_CHECK(!deviceWCoresWInvalidParentCategory); |
| 950 | |
| 951 | // Register a new device with cores and invalid parent category |
| 952 | const std::string deviceWCoresWInvalidParentCategoryName2 = "some_device_with_cores_with_invalid_parent_category2"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 953 | const Device* deviceWCoresWInvalidParentCategory2 = nullptr; |
| 954 | BOOST_CHECK_THROW(deviceWCoresWInvalidParentCategory2 = counterDirectory.RegisterDevice( |
| 955 | deviceWCoresWInvalidParentCategoryName2, 3, std::string("invalid_parent_category")), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 956 | armnn::InvalidArgumentException); |
| 957 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 2); |
| 958 | BOOST_CHECK(!deviceWCoresWInvalidParentCategory2); |
| 959 | |
| 960 | // Register a category for testing |
| 961 | const std::string categoryName = "some_category"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 962 | const Category* category = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 963 | BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName)); |
| 964 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 965 | BOOST_CHECK(category); |
| 966 | BOOST_CHECK(category->m_Name == categoryName); |
| 967 | BOOST_CHECK(category->m_Counters.empty()); |
| 968 | BOOST_CHECK(category->m_DeviceUid == 0); |
| 969 | BOOST_CHECK(category->m_CounterSetUid == 0); |
| 970 | |
| 971 | // Register a new device with cores and valid parent category |
| 972 | const std::string deviceWCoresWValidParentCategoryName = "some_device_with_cores_with_valid_parent_category"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 973 | const Device* deviceWCoresWValidParentCategory = nullptr; |
| 974 | BOOST_CHECK_NO_THROW(deviceWCoresWValidParentCategory = |
| 975 | counterDirectory.RegisterDevice(deviceWCoresWValidParentCategoryName, 4, categoryName)); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 976 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 3); |
| 977 | BOOST_CHECK(deviceWCoresWValidParentCategory); |
| 978 | BOOST_CHECK(deviceWCoresWValidParentCategory->m_Name == deviceWCoresWValidParentCategoryName); |
| 979 | BOOST_CHECK(deviceWCoresWValidParentCategory->m_Uid >= 1); |
| 980 | BOOST_CHECK(deviceWCoresWValidParentCategory->m_Uid > device->m_Uid); |
| 981 | BOOST_CHECK(deviceWCoresWValidParentCategory->m_Uid > deviceWCores->m_Uid); |
| 982 | BOOST_CHECK(deviceWCoresWValidParentCategory->m_Cores == 4); |
| 983 | BOOST_CHECK(category->m_DeviceUid == deviceWCoresWValidParentCategory->m_Uid); |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 984 | |
| 985 | // Register a device associated to a category already associated to a different device |
| 986 | const std::string deviceSameCategoryName = "some_device_with_invalid_parent_category"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 987 | const Device* deviceSameCategory = nullptr; |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 988 | BOOST_CHECK_THROW(deviceSameCategory = counterDirectory.RegisterDevice(deviceSameCategoryName, 0, categoryName), |
| 989 | armnn::InvalidArgumentException); |
| 990 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 3); |
| 991 | BOOST_CHECK(!deviceSameCategory); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | BOOST_AUTO_TEST_CASE(CheckCounterDirectoryRegisterCounterSet) |
| 995 | { |
| 996 | CounterDirectory counterDirectory; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 997 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 0); |
| 998 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 0); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 999 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1000 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1001 | |
| 1002 | // Register a counter set with an invalid name |
| 1003 | const CounterSet* noCounterSet = nullptr; |
| 1004 | BOOST_CHECK_THROW(noCounterSet = counterDirectory.RegisterCounterSet(""), armnn::InvalidArgumentException); |
| 1005 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0); |
| 1006 | BOOST_CHECK(!noCounterSet); |
| 1007 | |
| 1008 | // Register a counter set with an invalid name |
| 1009 | BOOST_CHECK_THROW(noCounterSet = counterDirectory.RegisterCounterSet("invalid name"), |
| 1010 | armnn::InvalidArgumentException); |
| 1011 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0); |
| 1012 | BOOST_CHECK(!noCounterSet); |
| 1013 | |
| 1014 | // Register a new counter set with no count or parent category |
| 1015 | const std::string counterSetName = "some_counter_set"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1016 | const CounterSet* counterSet = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1017 | BOOST_CHECK_NO_THROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName)); |
| 1018 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1); |
| 1019 | BOOST_CHECK(counterSet); |
| 1020 | BOOST_CHECK(counterSet->m_Name == counterSetName); |
| 1021 | BOOST_CHECK(counterSet->m_Uid >= 1); |
| 1022 | BOOST_CHECK(counterSet->m_Count == 0); |
| 1023 | |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1024 | // Try getting an unregistered counter set |
| 1025 | const CounterSet* unregisteredCounterSet = counterDirectory.GetCounterSet(9999); |
| 1026 | BOOST_CHECK(!unregisteredCounterSet); |
| 1027 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1028 | // Get the registered counter set |
| 1029 | const CounterSet* registeredCounterSet = counterDirectory.GetCounterSet(counterSet->m_Uid); |
| 1030 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1); |
| 1031 | BOOST_CHECK(registeredCounterSet); |
| 1032 | BOOST_CHECK(registeredCounterSet == counterSet); |
| 1033 | |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1034 | // Register a counter set with the name of a counter set already registered |
| 1035 | const CounterSet* counterSetSameName = nullptr; |
| 1036 | BOOST_CHECK_THROW(counterSetSameName = counterDirectory.RegisterCounterSet(counterSetName), |
| 1037 | armnn::InvalidArgumentException); |
| 1038 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1); |
| 1039 | BOOST_CHECK(!counterSetSameName); |
| 1040 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1041 | // Register a new counter set with count and no parent category |
| 1042 | const std::string counterSetWCountName = "some_counter_set_with_count"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1043 | const CounterSet* counterSetWCount = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1044 | BOOST_CHECK_NO_THROW(counterSetWCount = counterDirectory.RegisterCounterSet(counterSetWCountName, 37)); |
| 1045 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 2); |
| 1046 | BOOST_CHECK(counterSetWCount); |
| 1047 | BOOST_CHECK(counterSetWCount->m_Name == counterSetWCountName); |
| 1048 | BOOST_CHECK(counterSetWCount->m_Uid >= 1); |
| 1049 | BOOST_CHECK(counterSetWCount->m_Uid > counterSet->m_Uid); |
| 1050 | BOOST_CHECK(counterSetWCount->m_Count == 37); |
| 1051 | |
| 1052 | // Get the registered counter set |
| 1053 | const CounterSet* registeredCounterSetWCount = counterDirectory.GetCounterSet(counterSetWCount->m_Uid); |
| 1054 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 2); |
| 1055 | BOOST_CHECK(registeredCounterSetWCount); |
| 1056 | BOOST_CHECK(registeredCounterSetWCount == counterSetWCount); |
| 1057 | BOOST_CHECK(registeredCounterSetWCount != counterSet); |
| 1058 | |
| 1059 | // Register a new counter set with count and invalid parent category |
| 1060 | const std::string counterSetWCountWInvalidParentCategoryName = "some_counter_set_with_count_" |
| 1061 | "with_invalid_parent_category"; |
| 1062 | const CounterSet* counterSetWCountWInvalidParentCategory = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1063 | BOOST_CHECK_THROW(counterSetWCountWInvalidParentCategory = counterDirectory.RegisterCounterSet( |
| 1064 | counterSetWCountWInvalidParentCategoryName, 42, std::string("")), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1065 | armnn::InvalidArgumentException); |
| 1066 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 2); |
| 1067 | BOOST_CHECK(!counterSetWCountWInvalidParentCategory); |
| 1068 | |
| 1069 | // Register a new counter set with count and invalid parent category |
| 1070 | const std::string counterSetWCountWInvalidParentCategoryName2 = "some_counter_set_with_count_" |
| 1071 | "with_invalid_parent_category2"; |
| 1072 | const CounterSet* counterSetWCountWInvalidParentCategory2 = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1073 | BOOST_CHECK_THROW(counterSetWCountWInvalidParentCategory2 = counterDirectory.RegisterCounterSet( |
| 1074 | counterSetWCountWInvalidParentCategoryName2, 42, std::string("invalid_parent_category")), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1075 | armnn::InvalidArgumentException); |
| 1076 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 2); |
| 1077 | BOOST_CHECK(!counterSetWCountWInvalidParentCategory2); |
| 1078 | |
| 1079 | // Register a category for testing |
| 1080 | const std::string categoryName = "some_category"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1081 | const Category* category = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1082 | BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName)); |
| 1083 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 1084 | BOOST_CHECK(category); |
| 1085 | BOOST_CHECK(category->m_Name == categoryName); |
| 1086 | BOOST_CHECK(category->m_Counters.empty()); |
| 1087 | BOOST_CHECK(category->m_DeviceUid == 0); |
| 1088 | BOOST_CHECK(category->m_CounterSetUid == 0); |
| 1089 | |
| 1090 | // Register a new counter set with count and valid parent category |
| 1091 | const std::string counterSetWCountWValidParentCategoryName = "some_counter_set_with_count_" |
| 1092 | "with_valid_parent_category"; |
| 1093 | const CounterSet* counterSetWCountWValidParentCategory = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1094 | BOOST_CHECK_NO_THROW(counterSetWCountWValidParentCategory = counterDirectory.RegisterCounterSet( |
| 1095 | counterSetWCountWValidParentCategoryName, 42, categoryName)); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1096 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 3); |
| 1097 | BOOST_CHECK(counterSetWCountWValidParentCategory); |
| 1098 | BOOST_CHECK(counterSetWCountWValidParentCategory->m_Name == counterSetWCountWValidParentCategoryName); |
| 1099 | BOOST_CHECK(counterSetWCountWValidParentCategory->m_Uid >= 1); |
| 1100 | BOOST_CHECK(counterSetWCountWValidParentCategory->m_Uid > counterSet->m_Uid); |
| 1101 | BOOST_CHECK(counterSetWCountWValidParentCategory->m_Uid > counterSetWCount->m_Uid); |
| 1102 | BOOST_CHECK(counterSetWCountWValidParentCategory->m_Count == 42); |
| 1103 | BOOST_CHECK(category->m_CounterSetUid == counterSetWCountWValidParentCategory->m_Uid); |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1104 | |
| 1105 | // Register a counter set associated to a category already associated to a different counter set |
| 1106 | const std::string counterSetSameCategoryName = "some_counter_set_with_invalid_parent_category"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1107 | const CounterSet* counterSetSameCategory = nullptr; |
| 1108 | BOOST_CHECK_THROW(counterSetSameCategory = |
| 1109 | counterDirectory.RegisterCounterSet(counterSetSameCategoryName, 0, categoryName), |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1110 | armnn::InvalidArgumentException); |
| 1111 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 3); |
| 1112 | BOOST_CHECK(!counterSetSameCategory); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | BOOST_AUTO_TEST_CASE(CheckCounterDirectoryRegisterCounter) |
| 1116 | { |
| 1117 | CounterDirectory counterDirectory; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1118 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 0); |
| 1119 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 0); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1120 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1121 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1122 | |
| 1123 | // Register a counter with an invalid parent category name |
| 1124 | const Counter* noCounter = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1125 | BOOST_CHECK_THROW(noCounter = |
| 1126 | counterDirectory.RegisterCounter("", 0, 1, 123.45f, "valid name", "valid description"), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1127 | armnn::InvalidArgumentException); |
| 1128 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1129 | BOOST_CHECK(!noCounter); |
| 1130 | |
| 1131 | // Register a counter with an invalid parent category name |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1132 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter("invalid parent category", 0, 1, 123.45f, |
| 1133 | "valid name", "valid description"), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1134 | armnn::InvalidArgumentException); |
| 1135 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1136 | BOOST_CHECK(!noCounter); |
| 1137 | |
| 1138 | // Register a counter with an invalid class |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1139 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter("valid_parent_category", 2, 1, 123.45f, "valid name", |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1140 | "valid description"), |
| 1141 | armnn::InvalidArgumentException); |
| 1142 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1143 | BOOST_CHECK(!noCounter); |
| 1144 | |
| 1145 | // Register a counter with an invalid interpolation |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1146 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter("valid_parent_category", 0, 3, 123.45f, "valid name", |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1147 | "valid description"), |
| 1148 | armnn::InvalidArgumentException); |
| 1149 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1150 | BOOST_CHECK(!noCounter); |
| 1151 | |
| 1152 | // Register a counter with an invalid multiplier |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1153 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter("valid_parent_category", 0, 1, .0f, "valid name", |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1154 | "valid description"), |
| 1155 | armnn::InvalidArgumentException); |
| 1156 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1157 | BOOST_CHECK(!noCounter); |
| 1158 | |
| 1159 | // Register a counter with an invalid name |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1160 | BOOST_CHECK_THROW( |
| 1161 | noCounter = counterDirectory.RegisterCounter("valid_parent_category", 0, 1, 123.45f, "", "valid description"), |
| 1162 | armnn::InvalidArgumentException); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1163 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1164 | BOOST_CHECK(!noCounter); |
| 1165 | |
| 1166 | // Register a counter with an invalid name |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1167 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter("valid_parent_category", 0, 1, 123.45f, |
| 1168 | "invalid nam€", "valid description"), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1169 | armnn::InvalidArgumentException); |
| 1170 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1171 | BOOST_CHECK(!noCounter); |
| 1172 | |
| 1173 | // Register a counter with an invalid description |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1174 | BOOST_CHECK_THROW(noCounter = |
| 1175 | counterDirectory.RegisterCounter("valid_parent_category", 0, 1, 123.45f, "valid name", ""), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1176 | armnn::InvalidArgumentException); |
| 1177 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1178 | BOOST_CHECK(!noCounter); |
| 1179 | |
| 1180 | // Register a counter with an invalid description |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1181 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter("valid_parent_category", 0, 1, 123.45f, "valid name", |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1182 | "inv@lid description"), |
| 1183 | armnn::InvalidArgumentException); |
| 1184 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1185 | BOOST_CHECK(!noCounter); |
| 1186 | |
| 1187 | // Register a counter with an invalid unit2 |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1188 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter("valid_parent_category", 0, 1, 123.45f, "valid name", |
| 1189 | "valid description", std::string("Mb/s2")), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1190 | armnn::InvalidArgumentException); |
| 1191 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1192 | BOOST_CHECK(!noCounter); |
| 1193 | |
| 1194 | // Register a counter with a non-existing parent category name |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1195 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter("invalid_parent_category", 0, 1, 123.45f, |
| 1196 | "valid name", "valid description"), |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1197 | armnn::InvalidArgumentException); |
| 1198 | BOOST_CHECK(counterDirectory.GetCounterCount() == 0); |
| 1199 | BOOST_CHECK(!noCounter); |
| 1200 | |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1201 | // Try getting an unregistered counter |
| 1202 | const Counter* unregisteredCounter = counterDirectory.GetCounter(9999); |
| 1203 | BOOST_CHECK(!unregisteredCounter); |
| 1204 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1205 | // Register a category for testing |
| 1206 | const std::string categoryName = "some_category"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1207 | const Category* category = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1208 | BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName)); |
| 1209 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 1); |
| 1210 | BOOST_CHECK(category); |
| 1211 | BOOST_CHECK(category->m_Name == categoryName); |
| 1212 | BOOST_CHECK(category->m_Counters.empty()); |
| 1213 | BOOST_CHECK(category->m_DeviceUid == 0); |
| 1214 | BOOST_CHECK(category->m_CounterSetUid == 0); |
| 1215 | |
| 1216 | // Register a counter with a valid parent category name |
| 1217 | const Counter* counter = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1218 | BOOST_CHECK_NO_THROW( |
| 1219 | counter = counterDirectory.RegisterCounter(categoryName, 0, 1, 123.45f, "valid name", "valid description")); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1220 | BOOST_CHECK(counterDirectory.GetCounterCount() == 1); |
| 1221 | BOOST_CHECK(counter); |
| 1222 | BOOST_CHECK(counter->m_Uid >= 0); |
| 1223 | BOOST_CHECK(counter->m_MaxCounterUid == counter->m_Uid); |
| 1224 | BOOST_CHECK(counter->m_Class == 0); |
| 1225 | BOOST_CHECK(counter->m_Interpolation == 1); |
| 1226 | BOOST_CHECK(counter->m_Multiplier == 123.45f); |
| 1227 | BOOST_CHECK(counter->m_Name == "valid name"); |
| 1228 | BOOST_CHECK(counter->m_Description == "valid description"); |
| 1229 | BOOST_CHECK(counter->m_Units == ""); |
| 1230 | BOOST_CHECK(counter->m_DeviceUid == 0); |
| 1231 | BOOST_CHECK(counter->m_CounterSetUid == 0); |
| 1232 | BOOST_CHECK(category->m_Counters.size() == 1); |
| 1233 | BOOST_CHECK(category->m_Counters.back() == counter->m_Uid); |
| 1234 | |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1235 | // Register a counter with a name of a counter already registered for the given parent category name |
| 1236 | const Counter* counterSameName = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1237 | BOOST_CHECK_THROW(counterSameName = |
| 1238 | counterDirectory.RegisterCounter(categoryName, 0, 0, 1.0f, "valid name", "valid description"), |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1239 | armnn::InvalidArgumentException); |
| 1240 | BOOST_CHECK(counterDirectory.GetCounterCount() == 1); |
| 1241 | BOOST_CHECK(!counterSameName); |
| 1242 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1243 | // Register a counter with a valid parent category name and units |
| 1244 | const Counter* counterWUnits = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1245 | BOOST_CHECK_NO_THROW(counterWUnits = counterDirectory.RegisterCounter(categoryName, 0, 1, 123.45f, "valid name 2", |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1246 | "valid description", |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1247 | std::string("Mnnsq2"))); // Units |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1248 | BOOST_CHECK(counterDirectory.GetCounterCount() == 2); |
| 1249 | BOOST_CHECK(counterWUnits); |
| 1250 | BOOST_CHECK(counterWUnits->m_Uid >= 0); |
| 1251 | BOOST_CHECK(counterWUnits->m_Uid > counter->m_Uid); |
| 1252 | BOOST_CHECK(counterWUnits->m_MaxCounterUid == counterWUnits->m_Uid); |
| 1253 | BOOST_CHECK(counterWUnits->m_Class == 0); |
| 1254 | BOOST_CHECK(counterWUnits->m_Interpolation == 1); |
| 1255 | BOOST_CHECK(counterWUnits->m_Multiplier == 123.45f); |
| 1256 | BOOST_CHECK(counterWUnits->m_Name == "valid name 2"); |
| 1257 | BOOST_CHECK(counterWUnits->m_Description == "valid description"); |
| 1258 | BOOST_CHECK(counterWUnits->m_Units == "Mnnsq2"); |
| 1259 | BOOST_CHECK(counterWUnits->m_DeviceUid == 0); |
| 1260 | BOOST_CHECK(counterWUnits->m_CounterSetUid == 0); |
| 1261 | BOOST_CHECK(category->m_Counters.size() == 2); |
| 1262 | BOOST_CHECK(category->m_Counters.back() == counterWUnits->m_Uid); |
| 1263 | |
| 1264 | // Register a counter with a valid parent category name and not associated with a device |
| 1265 | const Counter* counterWoDevice = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1266 | BOOST_CHECK_NO_THROW(counterWoDevice = counterDirectory.RegisterCounter( |
| 1267 | categoryName, 0, 1, 123.45f, "valid name 3", "valid description", |
| 1268 | armnn::EmptyOptional(), // Units |
| 1269 | armnn::EmptyOptional(), // Number of cores |
| 1270 | 0)); // Device UID |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1271 | BOOST_CHECK(counterDirectory.GetCounterCount() == 3); |
| 1272 | BOOST_CHECK(counterWoDevice); |
| 1273 | BOOST_CHECK(counterWoDevice->m_Uid >= 0); |
| 1274 | BOOST_CHECK(counterWoDevice->m_Uid > counter->m_Uid); |
| 1275 | BOOST_CHECK(counterWoDevice->m_MaxCounterUid == counterWoDevice->m_Uid); |
| 1276 | BOOST_CHECK(counterWoDevice->m_Class == 0); |
| 1277 | BOOST_CHECK(counterWoDevice->m_Interpolation == 1); |
| 1278 | BOOST_CHECK(counterWoDevice->m_Multiplier == 123.45f); |
| 1279 | BOOST_CHECK(counterWoDevice->m_Name == "valid name 3"); |
| 1280 | BOOST_CHECK(counterWoDevice->m_Description == "valid description"); |
| 1281 | BOOST_CHECK(counterWoDevice->m_Units == ""); |
| 1282 | BOOST_CHECK(counterWoDevice->m_DeviceUid == 0); |
| 1283 | BOOST_CHECK(counterWoDevice->m_CounterSetUid == 0); |
| 1284 | BOOST_CHECK(category->m_Counters.size() == 3); |
| 1285 | BOOST_CHECK(category->m_Counters.back() == counterWoDevice->m_Uid); |
| 1286 | |
| 1287 | // Register a counter with a valid parent category name and associated to an invalid device |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1288 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(categoryName, 0, 1, 123.45f, "valid name 4", |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1289 | "valid description", |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1290 | armnn::EmptyOptional(), // Units |
| 1291 | armnn::EmptyOptional(), // Number of cores |
| 1292 | 100), // Device UID |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1293 | armnn::InvalidArgumentException); |
| 1294 | BOOST_CHECK(counterDirectory.GetCounterCount() == 3); |
| 1295 | BOOST_CHECK(!noCounter); |
| 1296 | |
| 1297 | // Register a device for testing |
| 1298 | const std::string deviceName = "some_device"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1299 | const Device* device = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1300 | BOOST_CHECK_NO_THROW(device = counterDirectory.RegisterDevice(deviceName)); |
| 1301 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 1); |
| 1302 | BOOST_CHECK(device); |
| 1303 | BOOST_CHECK(device->m_Name == deviceName); |
| 1304 | BOOST_CHECK(device->m_Uid >= 1); |
| 1305 | BOOST_CHECK(device->m_Cores == 0); |
| 1306 | |
| 1307 | // Register a counter with a valid parent category name and associated to a device |
| 1308 | const Counter* counterWDevice = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1309 | BOOST_CHECK_NO_THROW(counterWDevice = counterDirectory.RegisterCounter(categoryName, 0, 1, 123.45f, "valid name 5", |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1310 | "valid description", |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1311 | armnn::EmptyOptional(), // Units |
| 1312 | armnn::EmptyOptional(), // Number of cores |
| 1313 | device->m_Uid)); // Device UID |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1314 | BOOST_CHECK(counterDirectory.GetCounterCount() == 4); |
| 1315 | BOOST_CHECK(counterWDevice); |
| 1316 | BOOST_CHECK(counterWDevice->m_Uid >= 0); |
| 1317 | BOOST_CHECK(counterWDevice->m_Uid > counter->m_Uid); |
| 1318 | BOOST_CHECK(counterWDevice->m_MaxCounterUid == counterWDevice->m_Uid); |
| 1319 | BOOST_CHECK(counterWDevice->m_Class == 0); |
| 1320 | BOOST_CHECK(counterWDevice->m_Interpolation == 1); |
| 1321 | BOOST_CHECK(counterWDevice->m_Multiplier == 123.45f); |
| 1322 | BOOST_CHECK(counterWDevice->m_Name == "valid name 5"); |
| 1323 | BOOST_CHECK(counterWDevice->m_Description == "valid description"); |
| 1324 | BOOST_CHECK(counterWDevice->m_Units == ""); |
| 1325 | BOOST_CHECK(counterWDevice->m_DeviceUid == device->m_Uid); |
| 1326 | BOOST_CHECK(counterWDevice->m_CounterSetUid == 0); |
| 1327 | BOOST_CHECK(category->m_Counters.size() == 4); |
| 1328 | BOOST_CHECK(category->m_Counters.back() == counterWDevice->m_Uid); |
| 1329 | |
| 1330 | // Register a counter with a valid parent category name and not associated with a counter set |
| 1331 | const Counter* counterWoCounterSet = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1332 | BOOST_CHECK_NO_THROW(counterWoCounterSet = counterDirectory.RegisterCounter( |
| 1333 | categoryName, 0, 1, 123.45f, "valid name 6", "valid description", |
| 1334 | armnn::EmptyOptional(), // Units |
| 1335 | armnn::EmptyOptional(), // Number of cores |
| 1336 | armnn::EmptyOptional(), // Device UID |
| 1337 | 0)); // Counter set UID |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1338 | BOOST_CHECK(counterDirectory.GetCounterCount() == 5); |
| 1339 | BOOST_CHECK(counterWoCounterSet); |
| 1340 | BOOST_CHECK(counterWoCounterSet->m_Uid >= 0); |
| 1341 | BOOST_CHECK(counterWoCounterSet->m_Uid > counter->m_Uid); |
| 1342 | BOOST_CHECK(counterWoCounterSet->m_MaxCounterUid == counterWoCounterSet->m_Uid); |
| 1343 | BOOST_CHECK(counterWoCounterSet->m_Class == 0); |
| 1344 | BOOST_CHECK(counterWoCounterSet->m_Interpolation == 1); |
| 1345 | BOOST_CHECK(counterWoCounterSet->m_Multiplier == 123.45f); |
| 1346 | BOOST_CHECK(counterWoCounterSet->m_Name == "valid name 6"); |
| 1347 | BOOST_CHECK(counterWoCounterSet->m_Description == "valid description"); |
| 1348 | BOOST_CHECK(counterWoCounterSet->m_Units == ""); |
| 1349 | BOOST_CHECK(counterWoCounterSet->m_DeviceUid == 0); |
| 1350 | BOOST_CHECK(counterWoCounterSet->m_CounterSetUid == 0); |
| 1351 | BOOST_CHECK(category->m_Counters.size() == 5); |
| 1352 | BOOST_CHECK(category->m_Counters.back() == counterWoCounterSet->m_Uid); |
| 1353 | |
| 1354 | // Register a counter with a valid parent category name and associated to an invalid counter set |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1355 | BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(categoryName, 0, 1, 123.45f, "valid name 7", |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1356 | "valid description", |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1357 | armnn::EmptyOptional(), // Units |
| 1358 | armnn::EmptyOptional(), // Number of cores |
| 1359 | armnn::EmptyOptional(), // Device UID |
| 1360 | 100), // Counter set UID |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1361 | armnn::InvalidArgumentException); |
| 1362 | BOOST_CHECK(counterDirectory.GetCounterCount() == 5); |
| 1363 | BOOST_CHECK(!noCounter); |
| 1364 | |
| 1365 | // Register a counter with a valid parent category name and with a given number of cores |
| 1366 | const Counter* counterWNumberOfCores = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1367 | uint16_t numberOfCores = 15; |
| 1368 | BOOST_CHECK_NO_THROW(counterWNumberOfCores = counterDirectory.RegisterCounter( |
| 1369 | categoryName, 0, 1, 123.45f, "valid name 8", "valid description", |
| 1370 | armnn::EmptyOptional(), // Units |
| 1371 | numberOfCores, // Number of cores |
| 1372 | armnn::EmptyOptional(), // Device UID |
| 1373 | armnn::EmptyOptional())); // Counter set UID |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1374 | BOOST_CHECK(counterDirectory.GetCounterCount() == 20); |
| 1375 | BOOST_CHECK(counterWNumberOfCores); |
| 1376 | BOOST_CHECK(counterWNumberOfCores->m_Uid >= 0); |
| 1377 | BOOST_CHECK(counterWNumberOfCores->m_Uid > counter->m_Uid); |
| 1378 | BOOST_CHECK(counterWNumberOfCores->m_MaxCounterUid == counterWNumberOfCores->m_Uid + numberOfCores - 1); |
| 1379 | BOOST_CHECK(counterWNumberOfCores->m_Class == 0); |
| 1380 | BOOST_CHECK(counterWNumberOfCores->m_Interpolation == 1); |
| 1381 | BOOST_CHECK(counterWNumberOfCores->m_Multiplier == 123.45f); |
| 1382 | BOOST_CHECK(counterWNumberOfCores->m_Name == "valid name 8"); |
| 1383 | BOOST_CHECK(counterWNumberOfCores->m_Description == "valid description"); |
| 1384 | BOOST_CHECK(counterWNumberOfCores->m_Units == ""); |
| 1385 | BOOST_CHECK(counterWNumberOfCores->m_DeviceUid == 0); |
| 1386 | BOOST_CHECK(counterWNumberOfCores->m_CounterSetUid == 0); |
| 1387 | BOOST_CHECK(category->m_Counters.size() == 20); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1388 | for (size_t i = 0; i < numberOfCores; i++) |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1389 | { |
| 1390 | BOOST_CHECK(category->m_Counters[category->m_Counters.size() - numberOfCores + i] == |
| 1391 | counterWNumberOfCores->m_Uid + i); |
| 1392 | } |
| 1393 | |
| 1394 | // Register a multi-core device for testing |
| 1395 | const std::string multiCoreDeviceName = "some_multi_core_device"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1396 | const Device* multiCoreDevice = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1397 | BOOST_CHECK_NO_THROW(multiCoreDevice = counterDirectory.RegisterDevice(multiCoreDeviceName, 4)); |
| 1398 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 2); |
| 1399 | BOOST_CHECK(multiCoreDevice); |
| 1400 | BOOST_CHECK(multiCoreDevice->m_Name == multiCoreDeviceName); |
| 1401 | BOOST_CHECK(multiCoreDevice->m_Uid >= 1); |
| 1402 | BOOST_CHECK(multiCoreDevice->m_Cores == 4); |
| 1403 | |
| 1404 | // Register a counter with a valid parent category name and associated to the multi-core device |
| 1405 | const Counter* counterWMultiCoreDevice = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1406 | BOOST_CHECK_NO_THROW(counterWMultiCoreDevice = counterDirectory.RegisterCounter( |
| 1407 | categoryName, 0, 1, 123.45f, "valid name 9", "valid description", |
| 1408 | armnn::EmptyOptional(), // Units |
| 1409 | armnn::EmptyOptional(), // Number of cores |
| 1410 | multiCoreDevice->m_Uid, // Device UID |
| 1411 | armnn::EmptyOptional())); // Counter set UID |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1412 | BOOST_CHECK(counterDirectory.GetCounterCount() == 24); |
| 1413 | BOOST_CHECK(counterWMultiCoreDevice); |
| 1414 | BOOST_CHECK(counterWMultiCoreDevice->m_Uid >= 0); |
| 1415 | BOOST_CHECK(counterWMultiCoreDevice->m_Uid > counter->m_Uid); |
| 1416 | BOOST_CHECK(counterWMultiCoreDevice->m_MaxCounterUid == |
| 1417 | counterWMultiCoreDevice->m_Uid + multiCoreDevice->m_Cores - 1); |
| 1418 | BOOST_CHECK(counterWMultiCoreDevice->m_Class == 0); |
| 1419 | BOOST_CHECK(counterWMultiCoreDevice->m_Interpolation == 1); |
| 1420 | BOOST_CHECK(counterWMultiCoreDevice->m_Multiplier == 123.45f); |
| 1421 | BOOST_CHECK(counterWMultiCoreDevice->m_Name == "valid name 9"); |
| 1422 | BOOST_CHECK(counterWMultiCoreDevice->m_Description == "valid description"); |
| 1423 | BOOST_CHECK(counterWMultiCoreDevice->m_Units == ""); |
| 1424 | BOOST_CHECK(counterWMultiCoreDevice->m_DeviceUid == multiCoreDevice->m_Uid); |
| 1425 | BOOST_CHECK(counterWMultiCoreDevice->m_CounterSetUid == 0); |
| 1426 | BOOST_CHECK(category->m_Counters.size() == 24); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1427 | for (size_t i = 0; i < 4; i++) |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1428 | { |
| 1429 | BOOST_CHECK(category->m_Counters[category->m_Counters.size() - 4 + i] == counterWMultiCoreDevice->m_Uid + i); |
| 1430 | } |
| 1431 | |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1432 | // Register a multi-core device associate to a parent category for testing |
| 1433 | const std::string multiCoreDeviceNameWParentCategory = "some_multi_core_device_with_parent_category"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1434 | const Device* multiCoreDeviceWParentCategory = nullptr; |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1435 | BOOST_CHECK_NO_THROW(multiCoreDeviceWParentCategory = |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1436 | counterDirectory.RegisterDevice(multiCoreDeviceNameWParentCategory, 2, categoryName)); |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1437 | BOOST_CHECK(counterDirectory.GetDeviceCount() == 3); |
| 1438 | BOOST_CHECK(multiCoreDeviceWParentCategory); |
| 1439 | BOOST_CHECK(multiCoreDeviceWParentCategory->m_Name == multiCoreDeviceNameWParentCategory); |
| 1440 | BOOST_CHECK(multiCoreDeviceWParentCategory->m_Uid >= 1); |
| 1441 | BOOST_CHECK(multiCoreDeviceWParentCategory->m_Cores == 2); |
| 1442 | |
| 1443 | // Register a counter with a valid parent category name and getting the number of cores of the multi-core device |
| 1444 | // associated to that category |
| 1445 | const Counter* counterWMultiCoreDeviceWParentCategory = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1446 | BOOST_CHECK_NO_THROW(counterWMultiCoreDeviceWParentCategory = counterDirectory.RegisterCounter( |
| 1447 | categoryName, 0, 1, 123.45f, "valid name 10", "valid description", |
| 1448 | armnn::EmptyOptional(), // Units |
| 1449 | armnn::EmptyOptional(), // Number of cores |
| 1450 | armnn::EmptyOptional(), // Device UID |
| 1451 | armnn::EmptyOptional())); // Counter set UID |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1452 | BOOST_CHECK(counterDirectory.GetCounterCount() == 26); |
| 1453 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory); |
| 1454 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Uid >= 0); |
| 1455 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Uid > counter->m_Uid); |
| 1456 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_MaxCounterUid == |
| 1457 | counterWMultiCoreDeviceWParentCategory->m_Uid + multiCoreDeviceWParentCategory->m_Cores - 1); |
| 1458 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Class == 0); |
| 1459 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Interpolation == 1); |
| 1460 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Multiplier == 123.45f); |
| 1461 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Name == "valid name 10"); |
| 1462 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Description == "valid description"); |
| 1463 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Units == ""); |
| 1464 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_DeviceUid == 0); |
| 1465 | BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_CounterSetUid == 0); |
| 1466 | BOOST_CHECK(category->m_Counters.size() == 26); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1467 | for (size_t i = 0; i < 2; i++) |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1468 | { |
| 1469 | BOOST_CHECK(category->m_Counters[category->m_Counters.size() - 2 + i] == |
| 1470 | counterWMultiCoreDeviceWParentCategory->m_Uid + i); |
| 1471 | } |
| 1472 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1473 | // Register a counter set for testing |
| 1474 | const std::string counterSetName = "some_counter_set"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1475 | const CounterSet* counterSet = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1476 | BOOST_CHECK_NO_THROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName)); |
| 1477 | BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1); |
| 1478 | BOOST_CHECK(counterSet); |
| 1479 | BOOST_CHECK(counterSet->m_Name == counterSetName); |
| 1480 | BOOST_CHECK(counterSet->m_Uid >= 1); |
| 1481 | BOOST_CHECK(counterSet->m_Count == 0); |
| 1482 | |
| 1483 | // Register a counter with a valid parent category name and associated to a counter set |
| 1484 | const Counter* counterWCounterSet = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1485 | BOOST_CHECK_NO_THROW(counterWCounterSet = counterDirectory.RegisterCounter( |
| 1486 | categoryName, 0, 1, 123.45f, "valid name 11", "valid description", |
| 1487 | armnn::EmptyOptional(), // Units |
| 1488 | 0, // Number of cores |
| 1489 | armnn::EmptyOptional(), // Device UID |
| 1490 | counterSet->m_Uid)); // Counter set UID |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1491 | BOOST_CHECK(counterDirectory.GetCounterCount() == 27); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1492 | BOOST_CHECK(counterWCounterSet); |
| 1493 | BOOST_CHECK(counterWCounterSet->m_Uid >= 0); |
| 1494 | BOOST_CHECK(counterWCounterSet->m_Uid > counter->m_Uid); |
| 1495 | BOOST_CHECK(counterWCounterSet->m_MaxCounterUid == counterWCounterSet->m_Uid); |
| 1496 | BOOST_CHECK(counterWCounterSet->m_Class == 0); |
| 1497 | BOOST_CHECK(counterWCounterSet->m_Interpolation == 1); |
| 1498 | BOOST_CHECK(counterWCounterSet->m_Multiplier == 123.45f); |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1499 | BOOST_CHECK(counterWCounterSet->m_Name == "valid name 11"); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1500 | BOOST_CHECK(counterWCounterSet->m_Description == "valid description"); |
| 1501 | BOOST_CHECK(counterWCounterSet->m_Units == ""); |
| 1502 | BOOST_CHECK(counterWCounterSet->m_DeviceUid == 0); |
| 1503 | BOOST_CHECK(counterWCounterSet->m_CounterSetUid == counterSet->m_Uid); |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1504 | BOOST_CHECK(category->m_Counters.size() == 27); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1505 | BOOST_CHECK(category->m_Counters.back() == counterWCounterSet->m_Uid); |
| 1506 | |
| 1507 | // Register a counter with a valid parent category name and associated to a device and a counter set |
| 1508 | const Counter* counterWDeviceWCounterSet = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1509 | BOOST_CHECK_NO_THROW(counterWDeviceWCounterSet = counterDirectory.RegisterCounter( |
| 1510 | categoryName, 0, 1, 123.45f, "valid name 12", "valid description", |
| 1511 | armnn::EmptyOptional(), // Units |
| 1512 | 1, // Number of cores |
| 1513 | device->m_Uid, // Device UID |
| 1514 | counterSet->m_Uid)); // Counter set UID |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1515 | BOOST_CHECK(counterDirectory.GetCounterCount() == 28); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1516 | BOOST_CHECK(counterWDeviceWCounterSet); |
| 1517 | BOOST_CHECK(counterWDeviceWCounterSet->m_Uid >= 0); |
| 1518 | BOOST_CHECK(counterWDeviceWCounterSet->m_Uid > counter->m_Uid); |
| 1519 | BOOST_CHECK(counterWDeviceWCounterSet->m_MaxCounterUid == counterWDeviceWCounterSet->m_Uid); |
| 1520 | BOOST_CHECK(counterWDeviceWCounterSet->m_Class == 0); |
| 1521 | BOOST_CHECK(counterWDeviceWCounterSet->m_Interpolation == 1); |
| 1522 | BOOST_CHECK(counterWDeviceWCounterSet->m_Multiplier == 123.45f); |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1523 | BOOST_CHECK(counterWDeviceWCounterSet->m_Name == "valid name 12"); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1524 | BOOST_CHECK(counterWDeviceWCounterSet->m_Description == "valid description"); |
| 1525 | BOOST_CHECK(counterWDeviceWCounterSet->m_Units == ""); |
| 1526 | BOOST_CHECK(counterWDeviceWCounterSet->m_DeviceUid == device->m_Uid); |
| 1527 | BOOST_CHECK(counterWDeviceWCounterSet->m_CounterSetUid == counterSet->m_Uid); |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1528 | BOOST_CHECK(category->m_Counters.size() == 28); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1529 | BOOST_CHECK(category->m_Counters.back() == counterWDeviceWCounterSet->m_Uid); |
| 1530 | |
| 1531 | // Register another category for testing |
| 1532 | const std::string anotherCategoryName = "some_other_category"; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1533 | const Category* anotherCategory = nullptr; |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1534 | BOOST_CHECK_NO_THROW(anotherCategory = counterDirectory.RegisterCategory(anotherCategoryName)); |
| 1535 | BOOST_CHECK(counterDirectory.GetCategoryCount() == 2); |
| 1536 | BOOST_CHECK(anotherCategory); |
| 1537 | BOOST_CHECK(anotherCategory != category); |
| 1538 | BOOST_CHECK(anotherCategory->m_Name == anotherCategoryName); |
| 1539 | BOOST_CHECK(anotherCategory->m_Counters.empty()); |
| 1540 | BOOST_CHECK(anotherCategory->m_DeviceUid == 0); |
| 1541 | BOOST_CHECK(anotherCategory->m_CounterSetUid == 0); |
| 1542 | |
| 1543 | // Register a counter to the other category |
| 1544 | const Counter* anotherCounter = nullptr; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1545 | BOOST_CHECK_NO_THROW(anotherCounter = counterDirectory.RegisterCounter(anotherCategoryName, 1, 0, .00043f, |
| 1546 | "valid name", "valid description", |
| 1547 | armnn::EmptyOptional(), // Units |
| 1548 | armnn::EmptyOptional(), // Number of cores |
| 1549 | device->m_Uid, // Device UID |
| 1550 | counterSet->m_Uid)); // Counter set UID |
Matteo Martincigh | 657ab2d | 2019-09-18 10:53:24 +0100 | [diff] [blame] | 1551 | BOOST_CHECK(counterDirectory.GetCounterCount() == 29); |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1552 | BOOST_CHECK(anotherCounter); |
| 1553 | BOOST_CHECK(anotherCounter->m_Uid >= 0); |
| 1554 | BOOST_CHECK(anotherCounter->m_MaxCounterUid == anotherCounter->m_Uid); |
| 1555 | BOOST_CHECK(anotherCounter->m_Class == 1); |
| 1556 | BOOST_CHECK(anotherCounter->m_Interpolation == 0); |
| 1557 | BOOST_CHECK(anotherCounter->m_Multiplier == .00043f); |
| 1558 | BOOST_CHECK(anotherCounter->m_Name == "valid name"); |
| 1559 | BOOST_CHECK(anotherCounter->m_Description == "valid description"); |
| 1560 | BOOST_CHECK(anotherCounter->m_Units == ""); |
| 1561 | BOOST_CHECK(anotherCounter->m_DeviceUid == device->m_Uid); |
| 1562 | BOOST_CHECK(anotherCounter->m_CounterSetUid == counterSet->m_Uid); |
| 1563 | BOOST_CHECK(anotherCategory->m_Counters.size() == 1); |
| 1564 | BOOST_CHECK(anotherCategory->m_Counters.back() == anotherCounter->m_Uid); |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1565 | } |
| 1566 | |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1567 | BOOST_AUTO_TEST_CASE(CounterSelectionCommandHandlerParseData) |
| 1568 | { |
| 1569 | using boost::numeric_cast; |
| 1570 | |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 1571 | ProfilingStateMachine profilingStateMachine; |
| 1572 | |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1573 | class TestCaptureThread : public IPeriodicCounterCapture |
| 1574 | { |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1575 | void Start() override |
| 1576 | {} |
| 1577 | void Stop() override |
| 1578 | {} |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1579 | }; |
| 1580 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 1581 | class TestReadCounterValues : public IReadCounterValues |
| 1582 | { |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1583 | bool IsCounterRegistered(uint16_t counterUid) const override |
| 1584 | { |
| 1585 | return true; |
| 1586 | } |
| 1587 | uint16_t GetCounterCount() const override |
| 1588 | { |
| 1589 | return 0; |
| 1590 | } |
| 1591 | uint32_t GetCounterValue(uint16_t counterUid) const override |
| 1592 | { |
| 1593 | return 0; |
| 1594 | } |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 1595 | }; |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 1596 | const uint32_t familyId = 0; |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1597 | const uint32_t packetId = 0x40000; |
| 1598 | |
| 1599 | uint32_t version = 1; |
| 1600 | Holder holder; |
| 1601 | TestCaptureThread captureThread; |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 1602 | TestReadCounterValues readCounterValues; |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1603 | MockBufferManager mockBuffer(512); |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 1604 | SendCounterPacket sendCounterPacket(profilingStateMachine, mockBuffer); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1605 | |
| 1606 | uint32_t sizeOfUint32 = numeric_cast<uint32_t>(sizeof(uint32_t)); |
| 1607 | uint32_t sizeOfUint16 = numeric_cast<uint32_t>(sizeof(uint16_t)); |
| 1608 | |
| 1609 | // Data with period and counters |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1610 | uint32_t period1 = 10; |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1611 | uint32_t dataLength1 = 8; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1612 | uint32_t offset = 0; |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1613 | |
Matteo Martincigh | 67ef2a5 | 2019-10-10 13:29:02 +0100 | [diff] [blame] | 1614 | std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength1); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1615 | unsigned char* data1 = reinterpret_cast<unsigned char*>(uniqueData1.get()); |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 1616 | |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1617 | WriteUint32(data1, offset, period1); |
| 1618 | offset += sizeOfUint32; |
| 1619 | WriteUint16(data1, offset, 4000); |
| 1620 | offset += sizeOfUint16; |
| 1621 | WriteUint16(data1, offset, 5000); |
| 1622 | |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 1623 | Packet packetA(packetId, dataLength1, uniqueData1); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1624 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1625 | PeriodicCounterSelectionCommandHandler commandHandler(familyId, packetId, version, holder, captureThread, |
| 1626 | readCounterValues, sendCounterPacket, profilingStateMachine); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1627 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 1628 | profilingStateMachine.TransitionToState(ProfilingState::Uninitialised); |
| 1629 | BOOST_CHECK_THROW(commandHandler(packetA), armnn::RuntimeException); |
| 1630 | profilingStateMachine.TransitionToState(ProfilingState::NotConnected); |
| 1631 | BOOST_CHECK_THROW(commandHandler(packetA), armnn::RuntimeException); |
| 1632 | profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck); |
| 1633 | BOOST_CHECK_THROW(commandHandler(packetA), armnn::RuntimeException); |
| 1634 | profilingStateMachine.TransitionToState(ProfilingState::Active); |
| 1635 | BOOST_CHECK_NO_THROW(commandHandler(packetA)); |
| 1636 | |
| 1637 | const std::vector<uint16_t> counterIdsA = holder.GetCaptureData().GetCounterIds(); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1638 | |
| 1639 | BOOST_TEST(holder.GetCaptureData().GetCapturePeriod() == period1); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 1640 | BOOST_TEST(counterIdsA.size() == 2); |
| 1641 | BOOST_TEST(counterIdsA[0] == 4000); |
| 1642 | BOOST_TEST(counterIdsA[1] == 5000); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1643 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1644 | auto readBuffer = mockBuffer.GetReadableBuffer(); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1645 | |
| 1646 | offset = 0; |
| 1647 | |
| 1648 | uint32_t headerWord0 = ReadUint32(readBuffer, offset); |
| 1649 | offset += sizeOfUint32; |
| 1650 | uint32_t headerWord1 = ReadUint32(readBuffer, offset); |
| 1651 | offset += sizeOfUint32; |
| 1652 | uint32_t period = ReadUint32(readBuffer, offset); |
| 1653 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1654 | BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0); // packet family |
| 1655 | BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 4); // packet id |
| 1656 | BOOST_TEST(headerWord1 == 8); // data lenght |
| 1657 | BOOST_TEST(period == 10); // capture period |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1658 | |
| 1659 | uint16_t counterId = 0; |
| 1660 | offset += sizeOfUint32; |
| 1661 | counterId = ReadUint16(readBuffer, offset); |
| 1662 | BOOST_TEST(counterId == 4000); |
| 1663 | offset += sizeOfUint16; |
| 1664 | counterId = ReadUint16(readBuffer, offset); |
| 1665 | BOOST_TEST(counterId == 5000); |
| 1666 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1667 | mockBuffer.MarkRead(readBuffer); |
| 1668 | |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1669 | // Data with period only |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1670 | uint32_t period2 = 11; |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1671 | uint32_t dataLength2 = 4; |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1672 | |
Matteo Martincigh | 67ef2a5 | 2019-10-10 13:29:02 +0100 | [diff] [blame] | 1673 | std::unique_ptr<unsigned char[]> uniqueData2 = std::make_unique<unsigned char[]>(dataLength2); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1674 | |
FinnWilliamsArm | a0c7871 | 2019-09-16 12:06:47 +0100 | [diff] [blame] | 1675 | WriteUint32(reinterpret_cast<unsigned char*>(uniqueData2.get()), 0, period2); |
| 1676 | |
| 1677 | Packet packetB(packetId, dataLength2, uniqueData2); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1678 | |
| 1679 | commandHandler(packetB); |
| 1680 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 1681 | const std::vector<uint16_t> counterIdsB = holder.GetCaptureData().GetCounterIds(); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1682 | |
| 1683 | BOOST_TEST(holder.GetCaptureData().GetCapturePeriod() == period2); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 1684 | BOOST_TEST(counterIdsB.size() == 0); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1685 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1686 | readBuffer = mockBuffer.GetReadableBuffer(); |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1687 | |
| 1688 | offset = 0; |
| 1689 | |
| 1690 | headerWord0 = ReadUint32(readBuffer, offset); |
| 1691 | offset += sizeOfUint32; |
| 1692 | headerWord1 = ReadUint32(readBuffer, offset); |
| 1693 | offset += sizeOfUint32; |
| 1694 | period = ReadUint32(readBuffer, offset); |
| 1695 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1696 | BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0); // packet family |
| 1697 | BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 4); // packet id |
| 1698 | BOOST_TEST(headerWord1 == 4); // data length |
| 1699 | BOOST_TEST(period == 11); // capture period |
Ferran Balaguer | 1b94172 | 2019-08-28 16:57:18 +0100 | [diff] [blame] | 1700 | } |
| 1701 | |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1702 | BOOST_AUTO_TEST_CASE(CheckConnectionAcknowledged) |
| 1703 | { |
| 1704 | using boost::numeric_cast; |
| 1705 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1706 | const uint32_t packetFamilyId = 0; |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1707 | const uint32_t connectionPacketId = 0x10000; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1708 | const uint32_t version = 1; |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1709 | |
| 1710 | uint32_t sizeOfUint32 = numeric_cast<uint32_t>(sizeof(uint32_t)); |
| 1711 | uint32_t sizeOfUint16 = numeric_cast<uint32_t>(sizeof(uint16_t)); |
| 1712 | |
| 1713 | // Data with period and counters |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1714 | uint32_t period1 = 10; |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1715 | uint32_t dataLength1 = 8; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1716 | uint32_t offset = 0; |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1717 | |
Matteo Martincigh | 67ef2a5 | 2019-10-10 13:29:02 +0100 | [diff] [blame] | 1718 | std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength1); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1719 | unsigned char* data1 = reinterpret_cast<unsigned char*>(uniqueData1.get()); |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1720 | |
| 1721 | WriteUint32(data1, offset, period1); |
| 1722 | offset += sizeOfUint32; |
| 1723 | WriteUint16(data1, offset, 4000); |
| 1724 | offset += sizeOfUint16; |
| 1725 | WriteUint16(data1, offset, 5000); |
| 1726 | |
| 1727 | Packet packetA(connectionPacketId, dataLength1, uniqueData1); |
| 1728 | |
| 1729 | ProfilingStateMachine profilingState(ProfilingState::Uninitialised); |
| 1730 | BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1731 | CounterDirectory counterDirectory; |
| 1732 | MockBufferManager mockBuffer(1024); |
| 1733 | SendCounterPacket sendCounterPacket(profilingState, mockBuffer); |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1734 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1735 | ConnectionAcknowledgedCommandHandler commandHandler(packetFamilyId, connectionPacketId, version, counterDirectory, |
| 1736 | sendCounterPacket, profilingState); |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1737 | |
| 1738 | // command handler received packet on ProfilingState::Uninitialised |
| 1739 | BOOST_CHECK_THROW(commandHandler(packetA), armnn::Exception); |
| 1740 | |
| 1741 | profilingState.TransitionToState(ProfilingState::NotConnected); |
| 1742 | BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::NotConnected); |
| 1743 | // command handler received packet on ProfilingState::NotConnected |
| 1744 | BOOST_CHECK_THROW(commandHandler(packetA), armnn::Exception); |
| 1745 | |
| 1746 | profilingState.TransitionToState(ProfilingState::WaitingForAck); |
| 1747 | BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::WaitingForAck); |
| 1748 | // command handler received packet on ProfilingState::WaitingForAck |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 1749 | BOOST_CHECK_NO_THROW(commandHandler(packetA)); |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1750 | BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::Active); |
| 1751 | |
| 1752 | // command handler received packet on ProfilingState::Active |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 1753 | BOOST_CHECK_NO_THROW(commandHandler(packetA)); |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1754 | BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::Active); |
| 1755 | |
| 1756 | // command handler received different packet |
| 1757 | const uint32_t differentPacketId = 0x40000; |
| 1758 | Packet packetB(differentPacketId, dataLength1, uniqueData1); |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 1759 | profilingState.TransitionToState(ProfilingState::NotConnected); |
| 1760 | profilingState.TransitionToState(ProfilingState::WaitingForAck); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1761 | ConnectionAcknowledgedCommandHandler differentCommandHandler(packetFamilyId, differentPacketId, version, |
| 1762 | counterDirectory, sendCounterPacket, profilingState); |
Sadik Armagan | b5f01b2 | 2019-09-18 17:29:00 +0100 | [diff] [blame] | 1763 | BOOST_CHECK_THROW(differentCommandHandler(packetB), armnn::Exception); |
| 1764 | } |
| 1765 | |
Teresa Charlin | 9bab496 | 2019-09-06 12:28:35 +0100 | [diff] [blame] | 1766 | BOOST_AUTO_TEST_CASE(CheckSocketProfilingConnection) |
| 1767 | { |
| 1768 | // Check that creating a SocketProfilingConnection results in an exception as the Gator UDS doesn't exist. |
| 1769 | BOOST_CHECK_THROW(new SocketProfilingConnection(), armnn::Exception); |
| 1770 | } |
| 1771 | |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1772 | BOOST_AUTO_TEST_CASE(SwTraceIsValidCharTest) |
| 1773 | { |
| 1774 | // Only ASCII 7-bit encoding supported |
| 1775 | for (unsigned char c = 0; c < 128; c++) |
| 1776 | { |
| 1777 | BOOST_CHECK(SwTraceCharPolicy::IsValidChar(c)); |
| 1778 | } |
| 1779 | |
| 1780 | // Not ASCII |
| 1781 | for (unsigned char c = 255; c >= 128; c++) |
| 1782 | { |
| 1783 | BOOST_CHECK(!SwTraceCharPolicy::IsValidChar(c)); |
| 1784 | } |
| 1785 | } |
| 1786 | |
| 1787 | BOOST_AUTO_TEST_CASE(SwTraceIsValidNameCharTest) |
| 1788 | { |
| 1789 | // Only alpha-numeric and underscore ASCII 7-bit encoding supported |
| 1790 | const unsigned char validChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"; |
| 1791 | for (unsigned char i = 0; i < sizeof(validChars) / sizeof(validChars[0]) - 1; i++) |
| 1792 | { |
| 1793 | BOOST_CHECK(SwTraceNameCharPolicy::IsValidChar(validChars[i])); |
| 1794 | } |
| 1795 | |
| 1796 | // Non alpha-numeric chars |
| 1797 | for (unsigned char c = 0; c < 48; c++) |
| 1798 | { |
| 1799 | BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c)); |
| 1800 | } |
| 1801 | for (unsigned char c = 58; c < 65; c++) |
| 1802 | { |
| 1803 | BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c)); |
| 1804 | } |
| 1805 | for (unsigned char c = 91; c < 95; c++) |
| 1806 | { |
| 1807 | BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c)); |
| 1808 | } |
| 1809 | for (unsigned char c = 96; c < 97; c++) |
| 1810 | { |
| 1811 | BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c)); |
| 1812 | } |
| 1813 | for (unsigned char c = 123; c < 128; c++) |
| 1814 | { |
| 1815 | BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c)); |
| 1816 | } |
| 1817 | |
| 1818 | // Not ASCII |
| 1819 | for (unsigned char c = 255; c >= 128; c++) |
| 1820 | { |
| 1821 | BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c)); |
| 1822 | } |
| 1823 | } |
| 1824 | |
| 1825 | BOOST_AUTO_TEST_CASE(IsValidSwTraceStringTest) |
| 1826 | { |
| 1827 | // Valid SWTrace strings |
| 1828 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("")); |
| 1829 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("_")); |
| 1830 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("0123")); |
| 1831 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("valid_string")); |
| 1832 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("VALID_string_456")); |
| 1833 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>(" ")); |
| 1834 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("valid string")); |
| 1835 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("!$%")); |
| 1836 | BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("valid|\\~string#123")); |
| 1837 | |
| 1838 | // Invalid SWTrace strings |
| 1839 | BOOST_CHECK(!IsValidSwTraceString<SwTraceCharPolicy>("€£")); |
| 1840 | BOOST_CHECK(!IsValidSwTraceString<SwTraceCharPolicy>("invalid‡string")); |
| 1841 | BOOST_CHECK(!IsValidSwTraceString<SwTraceCharPolicy>("12Ž34")); |
| 1842 | } |
| 1843 | |
| 1844 | BOOST_AUTO_TEST_CASE(IsValidSwTraceNameStringTest) |
| 1845 | { |
| 1846 | // Valid SWTrace name strings |
| 1847 | BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("")); |
| 1848 | BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("_")); |
| 1849 | BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("0123")); |
| 1850 | BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("valid_string")); |
| 1851 | BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("VALID_string_456")); |
| 1852 | |
| 1853 | // Invalid SWTrace name strings |
| 1854 | BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>(" ")); |
| 1855 | BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("invalid string")); |
| 1856 | BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("!$%")); |
| 1857 | BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("invalid|\\~string#123")); |
| 1858 | BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("€£")); |
| 1859 | BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("invalid‡string")); |
| 1860 | BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("12Ž34")); |
| 1861 | } |
| 1862 | |
| 1863 | template <typename SwTracePolicy> |
| 1864 | void StringToSwTraceStringTestHelper(const std::string& testString, std::vector<uint32_t> buffer, size_t expectedSize) |
| 1865 | { |
| 1866 | // Convert the test string to a SWTrace string |
| 1867 | BOOST_CHECK(StringToSwTraceString<SwTracePolicy>(testString, buffer)); |
| 1868 | |
| 1869 | // The buffer must contain at least the length of the string |
| 1870 | BOOST_CHECK(!buffer.empty()); |
| 1871 | |
| 1872 | // The buffer must be of the expected size (in words) |
| 1873 | BOOST_CHECK(buffer.size() == expectedSize); |
| 1874 | |
| 1875 | // The first word of the byte must be the length of the string including the null-terminator |
| 1876 | BOOST_CHECK(buffer[0] == testString.size() + 1); |
| 1877 | |
| 1878 | // The contents of the buffer must match the test string |
| 1879 | BOOST_CHECK(std::memcmp(testString.data(), buffer.data() + 1, testString.size()) == 0); |
| 1880 | |
| 1881 | // The buffer must include the null-terminator at the end of the string |
| 1882 | size_t nullTerminatorIndex = sizeof(uint32_t) + testString.size(); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1883 | BOOST_CHECK(reinterpret_cast<unsigned char*>(buffer.data())[nullTerminatorIndex] == '\0'); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 1884 | } |
| 1885 | |
| 1886 | BOOST_AUTO_TEST_CASE(StringToSwTraceStringTest) |
| 1887 | { |
| 1888 | std::vector<uint32_t> buffer; |
| 1889 | |
| 1890 | // Valid SWTrace strings (expected size in words) |
| 1891 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("", buffer, 2); |
| 1892 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("_", buffer, 2); |
| 1893 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("0123", buffer, 3); |
| 1894 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("valid_string", buffer, 5); |
| 1895 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("VALID_string_456", buffer, 6); |
| 1896 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>(" ", buffer, 2); |
| 1897 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("valid string", buffer, 5); |
| 1898 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("!$%", buffer, 2); |
| 1899 | StringToSwTraceStringTestHelper<SwTraceCharPolicy>("valid|\\~string#123", buffer, 6); |
| 1900 | |
| 1901 | // Invalid SWTrace strings |
| 1902 | BOOST_CHECK(!StringToSwTraceString<SwTraceCharPolicy>("€£", buffer)); |
| 1903 | BOOST_CHECK(buffer.empty()); |
| 1904 | BOOST_CHECK(!StringToSwTraceString<SwTraceCharPolicy>("invalid‡string", buffer)); |
| 1905 | BOOST_CHECK(buffer.empty()); |
| 1906 | BOOST_CHECK(!StringToSwTraceString<SwTraceCharPolicy>("12Ž34", buffer)); |
| 1907 | BOOST_CHECK(buffer.empty()); |
| 1908 | } |
| 1909 | |
| 1910 | BOOST_AUTO_TEST_CASE(StringToSwTraceNameStringTest) |
| 1911 | { |
| 1912 | std::vector<uint32_t> buffer; |
| 1913 | |
| 1914 | // Valid SWTrace namestrings (expected size in words) |
| 1915 | StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("", buffer, 2); |
| 1916 | StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("_", buffer, 2); |
| 1917 | StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("0123", buffer, 3); |
| 1918 | StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("valid_string", buffer, 5); |
| 1919 | StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("VALID_string_456", buffer, 6); |
| 1920 | |
| 1921 | // Invalid SWTrace namestrings |
| 1922 | BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>(" ", buffer)); |
| 1923 | BOOST_CHECK(buffer.empty()); |
| 1924 | BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("invalid string", buffer)); |
| 1925 | BOOST_CHECK(buffer.empty()); |
| 1926 | BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("!$%", buffer)); |
| 1927 | BOOST_CHECK(buffer.empty()); |
| 1928 | BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("invalid|\\~string#123", buffer)); |
| 1929 | BOOST_CHECK(buffer.empty()); |
| 1930 | BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("€£", buffer)); |
| 1931 | BOOST_CHECK(buffer.empty()); |
| 1932 | BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("invalid‡string", buffer)); |
| 1933 | BOOST_CHECK(buffer.empty()); |
| 1934 | BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("12Ž34", buffer)); |
| 1935 | BOOST_CHECK(buffer.empty()); |
| 1936 | } |
| 1937 | |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 1938 | BOOST_AUTO_TEST_CASE(CheckPeriodicCounterCaptureThread) |
| 1939 | { |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 1940 | class CaptureReader : public IReadCounterValues |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 1941 | { |
| 1942 | public: |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 1943 | CaptureReader(uint16_t counterSize) |
| 1944 | { |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1945 | for (uint16_t i = 0; i < counterSize; ++i) |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 1946 | { |
| 1947 | m_Data[i] = 0; |
| 1948 | } |
| 1949 | m_CounterSize = counterSize; |
| 1950 | } |
| 1951 | //not used |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 1952 | bool IsCounterRegistered(uint16_t counterUid) const override |
| 1953 | { |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 1954 | return false; |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 1955 | } |
| 1956 | |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 1957 | uint16_t GetCounterCount() const override |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 1958 | { |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 1959 | return m_CounterSize; |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 1960 | } |
| 1961 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 1962 | uint32_t GetCounterValue(uint16_t counterUid) const override |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 1963 | { |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1964 | if (counterUid > m_CounterSize) |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 1965 | { |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 1966 | BOOST_FAIL("Invalid counter Uid"); |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 1967 | } |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 1968 | return m_Data.at(counterUid).load(); |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 1969 | } |
| 1970 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 1971 | void SetCounterValue(uint16_t counterUid, uint32_t value) |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 1972 | { |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1973 | if (counterUid > m_CounterSize) |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 1974 | { |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 1975 | BOOST_FAIL("Invalid counter Uid"); |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 1976 | } |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 1977 | m_Data.at(counterUid).store(value); |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 1978 | } |
| 1979 | |
| 1980 | private: |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 1981 | std::unordered_map<uint16_t, std::atomic<uint32_t>> m_Data; |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 1982 | uint16_t m_CounterSize; |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 1983 | }; |
| 1984 | |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 1985 | ProfilingStateMachine profilingStateMachine; |
| 1986 | |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 1987 | Holder data; |
| 1988 | std::vector<uint16_t> captureIds1 = { 0, 1 }; |
| 1989 | std::vector<uint16_t> captureIds2; |
| 1990 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 1991 | MockBufferManager mockBuffer(512); |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 1992 | SendCounterPacket sendCounterPacket(profilingStateMachine, mockBuffer); |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 1993 | |
| 1994 | std::vector<uint16_t> counterIds; |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 1995 | CaptureReader captureReader(2); |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 1996 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1997 | unsigned int valueA = 10; |
| 1998 | unsigned int valueB = 15; |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 1999 | unsigned int numSteps = 5; |
| 2000 | |
| 2001 | PeriodicCounterCapture periodicCounterCapture(std::ref(data), std::ref(sendCounterPacket), captureReader); |
| 2002 | |
Matteo Martincigh | e0e6efc | 2019-10-04 17:17:42 +0100 | [diff] [blame] | 2003 | for (unsigned int i = 0; i < numSteps; ++i) |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2004 | { |
| 2005 | data.SetCaptureData(1, captureIds1); |
| 2006 | captureReader.SetCounterValue(0, valueA * (i + 1)); |
| 2007 | captureReader.SetCounterValue(1, valueB * (i + 1)); |
| 2008 | |
| 2009 | periodicCounterCapture.Start(); |
Finn Williams | f4d59a6 | 2019-10-14 15:55:18 +0100 | [diff] [blame] | 2010 | periodicCounterCapture.Stop(); |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2011 | } |
| 2012 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 2013 | auto buffer = mockBuffer.GetReadableBuffer(); |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2014 | |
| 2015 | uint32_t headerWord0 = ReadUint32(buffer, 0); |
| 2016 | uint32_t headerWord1 = ReadUint32(buffer, 4); |
| 2017 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2018 | BOOST_TEST(((headerWord0 >> 26) & 0x0000003F) == 1); // packet family |
| 2019 | BOOST_TEST(((headerWord0 >> 19) & 0x0000007F) == 0); // packet class |
| 2020 | BOOST_TEST(((headerWord0 >> 16) & 0x00000007) == 0); // packet type |
Matteo Martincigh | 8d9590e | 2019-10-15 09:35:29 +0100 | [diff] [blame] | 2021 | BOOST_TEST(headerWord1 == 20); |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2022 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2023 | uint32_t offset = 16; |
Francis Murtagh | fcb8ef6 | 2019-09-20 15:40:09 +0100 | [diff] [blame] | 2024 | uint16_t readIndex = ReadUint16(buffer, offset); |
| 2025 | BOOST_TEST(0 == readIndex); |
| 2026 | |
| 2027 | offset += 2; |
| 2028 | uint32_t readValue = ReadUint32(buffer, offset); |
| 2029 | BOOST_TEST((valueA * numSteps) == readValue); |
| 2030 | |
| 2031 | offset += 4; |
| 2032 | readIndex = ReadUint16(buffer, offset); |
| 2033 | BOOST_TEST(1 == readIndex); |
| 2034 | |
| 2035 | offset += 2; |
| 2036 | readValue = ReadUint32(buffer, offset); |
| 2037 | BOOST_TEST((valueB * numSteps) == readValue); |
| 2038 | } |
| 2039 | |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2040 | BOOST_AUTO_TEST_CASE(RequestCounterDirectoryCommandHandlerTest1) |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2041 | { |
| 2042 | using boost::numeric_cast; |
| 2043 | |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 2044 | const uint32_t familyId = 0; |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2045 | const uint32_t packetId = 3; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2046 | const uint32_t version = 1; |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2047 | ProfilingStateMachine profilingStateMachine; |
| 2048 | CounterDirectory counterDirectory; |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 2049 | MockBufferManager mockBuffer(1024); |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2050 | SendCounterPacket sendCounterPacket(profilingStateMachine, mockBuffer); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2051 | RequestCounterDirectoryCommandHandler commandHandler(familyId, packetId, version, counterDirectory, |
| 2052 | sendCounterPacket, profilingStateMachine); |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2053 | |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2054 | const uint32_t wrongPacketId = 47; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2055 | const uint32_t wrongHeader = (wrongPacketId & 0x000003FF) << 16; |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2056 | |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2057 | Packet wrongPacket(wrongHeader); |
| 2058 | |
| 2059 | profilingStateMachine.TransitionToState(ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2060 | BOOST_CHECK_THROW(commandHandler(wrongPacket), armnn::RuntimeException); // Wrong profiling state |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2061 | profilingStateMachine.TransitionToState(ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2062 | BOOST_CHECK_THROW(commandHandler(wrongPacket), armnn::RuntimeException); // Wrong profiling state |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2063 | profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2064 | BOOST_CHECK_THROW(commandHandler(wrongPacket), armnn::RuntimeException); // Wrong profiling state |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2065 | profilingStateMachine.TransitionToState(ProfilingState::Active); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2066 | BOOST_CHECK_THROW(commandHandler(wrongPacket), armnn::InvalidArgumentException); // Wrong packet |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2067 | |
| 2068 | const uint32_t rightHeader = (packetId & 0x000003FF) << 16; |
| 2069 | |
| 2070 | Packet rightPacket(rightHeader); |
| 2071 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2072 | BOOST_CHECK_NO_THROW(commandHandler(rightPacket)); // Right packet |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2073 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 2074 | auto readBuffer = mockBuffer.GetReadableBuffer(); |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2075 | |
| 2076 | uint32_t headerWord0 = ReadUint32(readBuffer, 0); |
| 2077 | uint32_t headerWord1 = ReadUint32(readBuffer, 4); |
| 2078 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2079 | BOOST_TEST(((headerWord0 >> 26) & 0x0000003F) == 0); // packet family |
| 2080 | BOOST_TEST(((headerWord0 >> 16) & 0x000003FF) == 2); // packet id |
| 2081 | BOOST_TEST(headerWord1 == 24); // data length |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2082 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2083 | uint32_t bodyHeaderWord0 = ReadUint32(readBuffer, 8); |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2084 | uint16_t deviceRecordCount = numeric_cast<uint16_t>(bodyHeaderWord0 >> 16); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2085 | BOOST_TEST(deviceRecordCount == 0); // device_records_count |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2086 | } |
| 2087 | |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2088 | BOOST_AUTO_TEST_CASE(RequestCounterDirectoryCommandHandlerTest2) |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2089 | { |
| 2090 | using boost::numeric_cast; |
| 2091 | |
Jim Flynn | 397043f | 2019-10-17 17:37:10 +0100 | [diff] [blame] | 2092 | const uint32_t familyId = 0; |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2093 | const uint32_t packetId = 3; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2094 | const uint32_t version = 1; |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2095 | ProfilingStateMachine profilingStateMachine; |
| 2096 | CounterDirectory counterDirectory; |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 2097 | MockBufferManager mockBuffer(1024); |
Matteo Martincigh | 5d737fb | 2019-10-07 13:05:13 +0100 | [diff] [blame] | 2098 | SendCounterPacket sendCounterPacket(profilingStateMachine, mockBuffer); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2099 | RequestCounterDirectoryCommandHandler commandHandler(familyId, packetId, version, counterDirectory, |
| 2100 | sendCounterPacket, profilingStateMachine); |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2101 | const uint32_t header = (packetId & 0x000003FF) << 16; |
| 2102 | Packet packet(header); |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2103 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2104 | const Device* device = counterDirectory.RegisterDevice("deviceA", 1); |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2105 | const CounterSet* counterSet = counterDirectory.RegisterCounterSet("countersetA"); |
| 2106 | counterDirectory.RegisterCategory("categoryA", device->m_Uid, counterSet->m_Uid); |
| 2107 | counterDirectory.RegisterCounter("categoryA", 0, 1, 2.0f, "counterA", "descA"); |
| 2108 | counterDirectory.RegisterCounter("categoryA", 1, 1, 3.0f, "counterB", "descB"); |
| 2109 | |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2110 | profilingStateMachine.TransitionToState(ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2111 | BOOST_CHECK_THROW(commandHandler(packet), armnn::RuntimeException); // Wrong profiling state |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2112 | profilingStateMachine.TransitionToState(ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2113 | BOOST_CHECK_THROW(commandHandler(packet), armnn::RuntimeException); // Wrong profiling state |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2114 | profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2115 | BOOST_CHECK_THROW(commandHandler(packet), armnn::RuntimeException); // Wrong profiling state |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2116 | profilingStateMachine.TransitionToState(ProfilingState::Active); |
| 2117 | BOOST_CHECK_NO_THROW(commandHandler(packet)); |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2118 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 2119 | auto readBuffer = mockBuffer.GetReadableBuffer(); |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2120 | |
| 2121 | uint32_t headerWord0 = ReadUint32(readBuffer, 0); |
| 2122 | uint32_t headerWord1 = ReadUint32(readBuffer, 4); |
| 2123 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2124 | BOOST_TEST(((headerWord0 >> 26) & 0x0000003F) == 0); // packet family |
| 2125 | BOOST_TEST(((headerWord0 >> 16) & 0x000003FF) == 2); // packet id |
| 2126 | BOOST_TEST(headerWord1 == 240); // data length |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2127 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2128 | uint32_t bodyHeaderWord0 = ReadUint32(readBuffer, 8); |
| 2129 | uint32_t bodyHeaderWord1 = ReadUint32(readBuffer, 12); |
| 2130 | uint32_t bodyHeaderWord2 = ReadUint32(readBuffer, 16); |
| 2131 | uint32_t bodyHeaderWord3 = ReadUint32(readBuffer, 20); |
| 2132 | uint32_t bodyHeaderWord4 = ReadUint32(readBuffer, 24); |
| 2133 | uint32_t bodyHeaderWord5 = ReadUint32(readBuffer, 28); |
| 2134 | uint16_t deviceRecordCount = numeric_cast<uint16_t>(bodyHeaderWord0 >> 16); |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2135 | uint16_t counterSetRecordCount = numeric_cast<uint16_t>(bodyHeaderWord2 >> 16); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2136 | uint16_t categoryRecordCount = numeric_cast<uint16_t>(bodyHeaderWord4 >> 16); |
| 2137 | BOOST_TEST(deviceRecordCount == 1); // device_records_count |
| 2138 | BOOST_TEST(bodyHeaderWord1 == 0); // device_records_pointer_table_offset |
| 2139 | BOOST_TEST(counterSetRecordCount == 1); // counter_set_count |
| 2140 | BOOST_TEST(bodyHeaderWord3 == 4); // counter_set_pointer_table_offset |
| 2141 | BOOST_TEST(categoryRecordCount == 1); // categories_count |
| 2142 | BOOST_TEST(bodyHeaderWord5 == 8); // categories_pointer_table_offset |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2143 | |
| 2144 | uint32_t deviceRecordOffset = ReadUint32(readBuffer, 32); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2145 | BOOST_TEST(deviceRecordOffset == 0); |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2146 | |
| 2147 | uint32_t counterSetRecordOffset = ReadUint32(readBuffer, 36); |
| 2148 | BOOST_TEST(counterSetRecordOffset == 20); |
| 2149 | |
| 2150 | uint32_t categoryRecordOffset = ReadUint32(readBuffer, 40); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2151 | BOOST_TEST(categoryRecordOffset == 44); |
Narumol Prangnawarat | 4803369 | 2019-09-20 12:04:55 +0100 | [diff] [blame] | 2152 | } |
| 2153 | |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2154 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceBadConnectionAcknowledgedPacket) |
| 2155 | { |
| 2156 | // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output |
| 2157 | LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning); |
| 2158 | |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 2159 | // Swap the profiling connection factory in the profiling service instance with our mock one |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2160 | SwapProfilingConnectionFactoryHelper helper; |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 2161 | |
| 2162 | // Redirect the standard output to a local stream so that we can parse the warning message |
| 2163 | std::stringstream ss; |
| 2164 | StreamRedirector streamRedirector(std::cout, ss.rdbuf()); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2165 | |
| 2166 | // Calculate the size of a Stream Metadata packet |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2167 | std::string processName = GetProcessName().substr(0, 60); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2168 | unsigned int processNameSize = processName.empty() ? 0 : boost::numeric_cast<unsigned int>(processName.size()) + 1; |
| 2169 | unsigned int streamMetadataPacketsize = 118 + processNameSize; |
| 2170 | |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2171 | // Reset the profiling service to the uninitialized state |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2172 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2173 | options.m_EnableProfiling = true; |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2174 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 2175 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2176 | |
| 2177 | // Bring the profiling service to the "WaitingForAck" state |
| 2178 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2179 | profilingService.Update(); // Initialize the counter directory |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2180 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2181 | profilingService.Update(); // Create the profiling connection |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2182 | |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 2183 | // Get the mock profiling connection |
| 2184 | MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 2185 | BOOST_CHECK(mockProfilingConnection); |
| 2186 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2187 | // Remove the packets received so far |
| 2188 | mockProfilingConnection->Clear(); |
| 2189 | |
| 2190 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
| 2191 | profilingService.Update(); |
| 2192 | |
| 2193 | // Wait for the Stream Metadata packet to be sent |
| 2194 | helper.WaitForProfilingPacketsSent(); |
| 2195 | |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2196 | // Check that the mock profiling connection contains one Stream Metadata packet |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 2197 | const std::vector<uint32_t> writtenData = mockProfilingConnection->GetWrittenData(); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2198 | BOOST_TEST(writtenData.size() == 1); |
| 2199 | BOOST_TEST(writtenData[0] == streamMetadataPacketsize); |
| 2200 | |
| 2201 | // Write a valid "Connection Acknowledged" packet into the mock profiling connection, to simulate a valid |
| 2202 | // reply from an external profiling service |
| 2203 | |
| 2204 | // Connection Acknowledged Packet header (word 0, word 1 is always zero): |
| 2205 | // 26:31 [6] packet_family: Control Packet Family, value 0b000000 |
| 2206 | // 16:25 [10] packet_id: Packet identifier, value 0b0000000001 |
| 2207 | // 8:15 [8] reserved: Reserved, value 0b00000000 |
| 2208 | // 0:7 [8] reserved: Reserved, value 0b00000000 |
| 2209 | uint32_t packetFamily = 0; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2210 | uint32_t packetId = 37; // Wrong packet id!!! |
| 2211 | uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2212 | |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 2213 | // Create the Connection Acknowledged Packet |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2214 | Packet connectionAcknowledgedPacket(header); |
| 2215 | |
| 2216 | // Write the packet to the mock profiling connection |
| 2217 | mockProfilingConnection->WritePacket(std::move(connectionAcknowledgedPacket)); |
| 2218 | |
| 2219 | // Wait for a bit (must at least be the delay value of the mock profiling connection) to make sure that |
| 2220 | // the Connection Acknowledged packet gets processed by the profiling service |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 2221 | std::this_thread::sleep_for(std::chrono::seconds(2)); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2222 | |
| 2223 | // Check that the expected error has occurred and logged to the standard output |
| 2224 | BOOST_CHECK(boost::contains(ss.str(), "Functor with requested PacketId=37 and Version=4194304 does not exist")); |
| 2225 | |
| 2226 | // The Connection Acknowledged Command Handler should not have updated the profiling state |
| 2227 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 2228 | |
| 2229 | // Reset the profiling service to stop any running thread |
| 2230 | options.m_EnableProfiling = false; |
| 2231 | profilingService.ResetExternalProfilingOptions(options, true); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2232 | } |
| 2233 | |
| 2234 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodConnectionAcknowledgedPacket) |
| 2235 | { |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 2236 | // Swap the profiling connection factory in the profiling service instance with our mock one |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2237 | SwapProfilingConnectionFactoryHelper helper; |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2238 | |
| 2239 | // Calculate the size of a Stream Metadata packet |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2240 | std::string processName = GetProcessName().substr(0, 60); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2241 | unsigned int processNameSize = processName.empty() ? 0 : boost::numeric_cast<unsigned int>(processName.size()) + 1; |
| 2242 | unsigned int streamMetadataPacketsize = 118 + processNameSize; |
| 2243 | |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2244 | // Reset the profiling service to the uninitialized state |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2245 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2246 | options.m_EnableProfiling = true; |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2247 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 2248 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2249 | |
| 2250 | // Bring the profiling service to the "WaitingForAck" state |
| 2251 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2252 | profilingService.Update(); // Initialize the counter directory |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2253 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2254 | profilingService.Update(); // Create the profiling connection |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2255 | |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 2256 | // Get the mock profiling connection |
| 2257 | MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 2258 | BOOST_CHECK(mockProfilingConnection); |
| 2259 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2260 | // Remove the packets received so far |
| 2261 | mockProfilingConnection->Clear(); |
| 2262 | |
| 2263 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2264 | profilingService.Update(); // Start the command handler and the send thread |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2265 | |
| 2266 | // Wait for the Stream Metadata packet to be sent |
| 2267 | helper.WaitForProfilingPacketsSent(); |
| 2268 | |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2269 | // Check that the mock profiling connection contains one Stream Metadata packet |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 2270 | const std::vector<uint32_t> writtenData = mockProfilingConnection->GetWrittenData(); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2271 | BOOST_TEST(writtenData.size() == 1); |
| 2272 | BOOST_TEST(writtenData[0] == streamMetadataPacketsize); |
| 2273 | |
| 2274 | // Write a valid "Connection Acknowledged" packet into the mock profiling connection, to simulate a valid |
| 2275 | // reply from an external profiling service |
| 2276 | |
| 2277 | // Connection Acknowledged Packet header (word 0, word 1 is always zero): |
| 2278 | // 26:31 [6] packet_family: Control Packet Family, value 0b000000 |
| 2279 | // 16:25 [10] packet_id: Packet identifier, value 0b0000000001 |
| 2280 | // 8:15 [8] reserved: Reserved, value 0b00000000 |
| 2281 | // 0:7 [8] reserved: Reserved, value 0b00000000 |
| 2282 | uint32_t packetFamily = 0; |
| 2283 | uint32_t packetId = 1; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2284 | uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2285 | |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 2286 | // Create the Connection Acknowledged Packet |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2287 | Packet connectionAcknowledgedPacket(header); |
| 2288 | |
| 2289 | // Write the packet to the mock profiling connection |
| 2290 | mockProfilingConnection->WritePacket(std::move(connectionAcknowledgedPacket)); |
| 2291 | |
| 2292 | // Wait for a bit (must at least be the delay value of the mock profiling connection) to make sure that |
| 2293 | // the Connection Acknowledged packet gets processed by the profiling service |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 2294 | std::this_thread::sleep_for(std::chrono::seconds(2)); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2295 | |
| 2296 | // The Connection Acknowledged Command Handler should have updated the profiling state accordingly |
| 2297 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
Matteo Martincigh | d0613b5 | 2019-10-09 16:47:04 +0100 | [diff] [blame] | 2298 | |
| 2299 | // Reset the profiling service to stop any running thread |
| 2300 | options.m_EnableProfiling = false; |
| 2301 | profilingService.ResetExternalProfilingOptions(options, true); |
Matteo Martincigh | 54fb957 | 2019-10-02 12:50:57 +0100 | [diff] [blame] | 2302 | } |
| 2303 | |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2304 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceBadRequestCounterDirectoryPacket) |
| 2305 | { |
| 2306 | // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output |
| 2307 | LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning); |
| 2308 | |
| 2309 | // Swap the profiling connection factory in the profiling service instance with our mock one |
| 2310 | SwapProfilingConnectionFactoryHelper helper; |
| 2311 | |
| 2312 | // Redirect the standard output to a local stream so that we can parse the warning message |
| 2313 | std::stringstream ss; |
| 2314 | StreamRedirector streamRedirector(std::cout, ss.rdbuf()); |
| 2315 | |
| 2316 | // Reset the profiling service to the uninitialized state |
| 2317 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2318 | options.m_EnableProfiling = true; |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2319 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 2320 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2321 | |
| 2322 | // Bring the profiling service to the "Active" state |
| 2323 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
| 2324 | helper.ForceTransitionToState(ProfilingState::NotConnected); |
| 2325 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2326 | profilingService.Update(); // Create the profiling connection |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2327 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2328 | profilingService.Update(); // Start the command handler and the send thread |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2329 | |
| 2330 | // Wait for the Stream Metadata packet the be sent |
| 2331 | // (we are not testing the connection acknowledgement here so it will be ignored by this test) |
| 2332 | helper.WaitForProfilingPacketsSent(); |
| 2333 | |
| 2334 | // Force the profiling service to the "Active" state |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2335 | helper.ForceTransitionToState(ProfilingState::Active); |
| 2336 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2337 | |
| 2338 | // Get the mock profiling connection |
| 2339 | MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 2340 | BOOST_CHECK(mockProfilingConnection); |
| 2341 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2342 | // Remove the packets received so far |
| 2343 | mockProfilingConnection->Clear(); |
| 2344 | |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2345 | // Write a valid "Request Counter Directory" packet into the mock profiling connection, to simulate a valid |
| 2346 | // reply from an external profiling service |
| 2347 | |
| 2348 | // Request Counter Directory packet header (word 0, word 1 is always zero): |
| 2349 | // 26:31 [6] packet_family: Control Packet Family, value 0b000000 |
| 2350 | // 16:25 [10] packet_id: Packet identifier, value 0b0000000011 |
| 2351 | // 8:15 [8] reserved: Reserved, value 0b00000000 |
| 2352 | // 0:7 [8] reserved: Reserved, value 0b00000000 |
| 2353 | uint32_t packetFamily = 0; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2354 | uint32_t packetId = 123; // Wrong packet id!!! |
| 2355 | uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16); |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2356 | |
| 2357 | // Create the Request Counter Directory packet |
| 2358 | Packet requestCounterDirectoryPacket(header); |
| 2359 | |
| 2360 | // Write the packet to the mock profiling connection |
| 2361 | mockProfilingConnection->WritePacket(std::move(requestCounterDirectoryPacket)); |
| 2362 | |
| 2363 | // Wait for a bit (must at least be the delay value of the mock profiling connection) to make sure that |
| 2364 | // the Create the Request Counter packet gets processed by the profiling service |
| 2365 | std::this_thread::sleep_for(std::chrono::seconds(2)); |
| 2366 | |
| 2367 | // Check that the expected error has occurred and logged to the standard output |
| 2368 | BOOST_CHECK(boost::contains(ss.str(), "Functor with requested PacketId=123 and Version=4194304 does not exist")); |
| 2369 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2370 | // The Request Counter Directory Command Handler should not have updated the profiling state |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2371 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2372 | |
| 2373 | // Reset the profiling service to stop any running thread |
| 2374 | options.m_EnableProfiling = false; |
| 2375 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2376 | } |
| 2377 | |
| 2378 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodRequestCounterDirectoryPacket) |
| 2379 | { |
| 2380 | // Swap the profiling connection factory in the profiling service instance with our mock one |
| 2381 | SwapProfilingConnectionFactoryHelper helper; |
| 2382 | |
| 2383 | // Reset the profiling service to the uninitialized state |
| 2384 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2385 | options.m_EnableProfiling = true; |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2386 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 2387 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2388 | |
| 2389 | // Bring the profiling service to the "Active" state |
| 2390 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2391 | profilingService.Update(); // Initialize the counter directory |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2392 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2393 | profilingService.Update(); // Create the profiling connection |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2394 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2395 | profilingService.Update(); // Start the command handler and the send thread |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2396 | |
| 2397 | // Wait for the Stream Metadata packet the be sent |
| 2398 | // (we are not testing the connection acknowledgement here so it will be ignored by this test) |
| 2399 | helper.WaitForProfilingPacketsSent(); |
| 2400 | |
| 2401 | // Force the profiling service to the "Active" state |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2402 | helper.ForceTransitionToState(ProfilingState::Active); |
| 2403 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2404 | |
| 2405 | // Get the mock profiling connection |
| 2406 | MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 2407 | BOOST_CHECK(mockProfilingConnection); |
| 2408 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2409 | // Remove the packets received so far |
| 2410 | mockProfilingConnection->Clear(); |
| 2411 | |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2412 | // Write a valid "Request Counter Directory" packet into the mock profiling connection, to simulate a valid |
| 2413 | // reply from an external profiling service |
| 2414 | |
| 2415 | // Request Counter Directory packet header (word 0, word 1 is always zero): |
| 2416 | // 26:31 [6] packet_family: Control Packet Family, value 0b000000 |
| 2417 | // 16:25 [10] packet_id: Packet identifier, value 0b0000000011 |
| 2418 | // 8:15 [8] reserved: Reserved, value 0b00000000 |
| 2419 | // 0:7 [8] reserved: Reserved, value 0b00000000 |
| 2420 | uint32_t packetFamily = 0; |
| 2421 | uint32_t packetId = 3; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2422 | uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16); |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2423 | |
| 2424 | // Create the Request Counter Directory packet |
| 2425 | Packet requestCounterDirectoryPacket(header); |
| 2426 | |
| 2427 | // Write the packet to the mock profiling connection |
| 2428 | mockProfilingConnection->WritePacket(std::move(requestCounterDirectoryPacket)); |
| 2429 | |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2430 | // Wait for the Counter Directory packet to be sent |
| 2431 | helper.WaitForProfilingPacketsSent(); |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2432 | |
| 2433 | // Check that the mock profiling connection contains one Counter Directory packet |
| 2434 | const std::vector<uint32_t> writtenData = mockProfilingConnection->GetWrittenData(); |
| 2435 | BOOST_TEST(writtenData.size() == 1); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2436 | BOOST_TEST(writtenData[0] == 416); // The size of the expected Counter Directory packet |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2437 | |
| 2438 | // The Request Counter Directory Command Handler should not have updated the profiling state |
| 2439 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2440 | |
| 2441 | // Reset the profiling service to stop any running thread |
| 2442 | options.m_EnableProfiling = false; |
| 2443 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2444 | } |
| 2445 | |
| 2446 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceBadPeriodicCounterSelectionPacket) |
| 2447 | { |
| 2448 | // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output |
| 2449 | LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning); |
| 2450 | |
| 2451 | // Swap the profiling connection factory in the profiling service instance with our mock one |
| 2452 | SwapProfilingConnectionFactoryHelper helper; |
| 2453 | |
| 2454 | // Redirect the standard output to a local stream so that we can parse the warning message |
| 2455 | std::stringstream ss; |
| 2456 | StreamRedirector streamRedirector(std::cout, ss.rdbuf()); |
| 2457 | |
| 2458 | // Reset the profiling service to the uninitialized state |
| 2459 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2460 | options.m_EnableProfiling = true; |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2461 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 2462 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2463 | |
| 2464 | // Bring the profiling service to the "Active" state |
| 2465 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2466 | profilingService.Update(); // Initialize the counter directory |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2467 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2468 | profilingService.Update(); // Create the profiling connection |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2469 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2470 | profilingService.Update(); // Start the command handler and the send thread |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2471 | |
| 2472 | // Wait for the Stream Metadata packet the be sent |
| 2473 | // (we are not testing the connection acknowledgement here so it will be ignored by this test) |
| 2474 | helper.WaitForProfilingPacketsSent(); |
| 2475 | |
| 2476 | // Force the profiling service to the "Active" state |
| 2477 | helper.ForceTransitionToState(ProfilingState::Active); |
| 2478 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2479 | |
| 2480 | // Get the mock profiling connection |
| 2481 | MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 2482 | BOOST_CHECK(mockProfilingConnection); |
| 2483 | |
| 2484 | // Remove the packets received so far |
| 2485 | mockProfilingConnection->Clear(); |
| 2486 | |
| 2487 | // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an |
| 2488 | // external profiling service |
| 2489 | |
| 2490 | // Periodic Counter Selection packet header: |
| 2491 | // 26:31 [6] packet_family: Control Packet Family, value 0b000000 |
| 2492 | // 16:25 [10] packet_id: Packet identifier, value 0b0000000100 |
| 2493 | // 8:15 [8] reserved: Reserved, value 0b00000000 |
| 2494 | // 0:7 [8] reserved: Reserved, value 0b00000000 |
| 2495 | uint32_t packetFamily = 0; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2496 | uint32_t packetId = 999; // Wrong packet id!!! |
| 2497 | uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2498 | |
| 2499 | // Create the Periodic Counter Selection packet |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2500 | Packet periodicCounterSelectionPacket(header); // Length == 0, this will disable the collection of counters |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2501 | |
| 2502 | // Write the packet to the mock profiling connection |
| 2503 | mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket)); |
| 2504 | |
| 2505 | // Wait for a bit (must at least be the delay value of the mock profiling connection) to make sure that |
| 2506 | // the Periodic Counter Selection packet gets processed by the profiling service |
| 2507 | std::this_thread::sleep_for(std::chrono::seconds(2)); |
| 2508 | |
| 2509 | // Check that the expected error has occurred and logged to the standard output |
| 2510 | BOOST_CHECK(boost::contains(ss.str(), "Functor with requested PacketId=999 and Version=4194304 does not exist")); |
| 2511 | |
| 2512 | // The Periodic Counter Selection Handler should not have updated the profiling state |
| 2513 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2514 | |
| 2515 | // Reset the profiling service to stop any running thread |
| 2516 | options.m_EnableProfiling = false; |
| 2517 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2518 | } |
| 2519 | |
| 2520 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceBadPeriodicCounterSelectionPacketInvalidCounterUid) |
| 2521 | { |
| 2522 | // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output |
| 2523 | LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning); |
| 2524 | |
| 2525 | // Swap the profiling connection factory in the profiling service instance with our mock one |
| 2526 | SwapProfilingConnectionFactoryHelper helper; |
| 2527 | |
| 2528 | // Reset the profiling service to the uninitialized state |
| 2529 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2530 | options.m_EnableProfiling = true; |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2531 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 2532 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2533 | |
| 2534 | // Bring the profiling service to the "Active" state |
| 2535 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2536 | profilingService.Update(); // Initialize the counter directory |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2537 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2538 | profilingService.Update(); // Create the profiling connection |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2539 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2540 | profilingService.Update(); // Start the command handler and the send thread |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2541 | |
| 2542 | // Wait for the Stream Metadata packet the be sent |
| 2543 | // (we are not testing the connection acknowledgement here so it will be ignored by this test) |
| 2544 | helper.WaitForProfilingPacketsSent(); |
| 2545 | |
| 2546 | // Force the profiling service to the "Active" state |
| 2547 | helper.ForceTransitionToState(ProfilingState::Active); |
| 2548 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2549 | |
| 2550 | // Get the mock profiling connection |
| 2551 | MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 2552 | BOOST_CHECK(mockProfilingConnection); |
| 2553 | |
| 2554 | // Remove the packets received so far |
| 2555 | mockProfilingConnection->Clear(); |
| 2556 | |
| 2557 | // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an |
| 2558 | // external profiling service |
| 2559 | |
| 2560 | // Periodic Counter Selection packet header: |
| 2561 | // 26:31 [6] packet_family: Control Packet Family, value 0b000000 |
| 2562 | // 16:25 [10] packet_id: Packet identifier, value 0b0000000100 |
| 2563 | // 8:15 [8] reserved: Reserved, value 0b00000000 |
| 2564 | // 0:7 [8] reserved: Reserved, value 0b00000000 |
| 2565 | uint32_t packetFamily = 0; |
| 2566 | uint32_t packetId = 4; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2567 | uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2568 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2569 | uint32_t capturePeriod = 123456; // Some capture period (microseconds) |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2570 | |
| 2571 | // Get the first valid counter UID |
| 2572 | const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory(); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2573 | const Counters& counters = counterDirectory.GetCounters(); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2574 | BOOST_CHECK(counters.size() > 1); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2575 | uint16_t counterUidA = counters.begin()->first; // First valid counter UID |
| 2576 | uint16_t counterUidB = 9999; // Second invalid counter UID |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2577 | |
| 2578 | uint32_t length = 8; |
| 2579 | |
| 2580 | auto data = std::make_unique<unsigned char[]>(length); |
| 2581 | WriteUint32(data.get(), 0, capturePeriod); |
| 2582 | WriteUint16(data.get(), 4, counterUidA); |
| 2583 | WriteUint16(data.get(), 6, counterUidB); |
| 2584 | |
| 2585 | // Create the Periodic Counter Selection packet |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2586 | Packet periodicCounterSelectionPacket(header, length, data); // Length > 0, this will start the Period Counter |
| 2587 | // Capture thread |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2588 | |
| 2589 | // Write the packet to the mock profiling connection |
| 2590 | mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket)); |
| 2591 | |
| 2592 | // Expecting one Periodic Counter Selection packet and at least one Periodic Counter Capture packet |
| 2593 | int expectedPackets = 2; |
| 2594 | std::vector<uint32_t> receivedPackets; |
| 2595 | |
| 2596 | // Keep waiting until all the expected packets have been received |
| 2597 | do |
| 2598 | { |
| 2599 | helper.WaitForProfilingPacketsSent(); |
| 2600 | const std::vector<uint32_t> writtenData = mockProfilingConnection->GetWrittenData(); |
| 2601 | if (writtenData.empty()) |
| 2602 | { |
| 2603 | BOOST_ERROR("Packets should be available for reading at this point"); |
| 2604 | return; |
| 2605 | } |
| 2606 | receivedPackets.insert(receivedPackets.end(), writtenData.begin(), writtenData.end()); |
| 2607 | expectedPackets -= boost::numeric_cast<int>(writtenData.size()); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2608 | } while (expectedPackets > 0); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2609 | BOOST_TEST(!receivedPackets.empty()); |
| 2610 | |
| 2611 | // The size of the expected Periodic Counter Selection packet |
| 2612 | BOOST_TEST((std::find(receivedPackets.begin(), receivedPackets.end(), 14) != receivedPackets.end())); |
| 2613 | // The size of the expected Periodic Counter Capture packet |
| 2614 | BOOST_TEST((std::find(receivedPackets.begin(), receivedPackets.end(), 22) != receivedPackets.end())); |
| 2615 | |
| 2616 | // The Periodic Counter Selection Handler should not have updated the profiling state |
| 2617 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2618 | |
| 2619 | // Reset the profiling service to stop any running thread |
| 2620 | options.m_EnableProfiling = false; |
| 2621 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2622 | } |
| 2623 | |
| 2624 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodPeriodicCounterSelectionPacketNoCounters) |
| 2625 | { |
| 2626 | // Swap the profiling connection factory in the profiling service instance with our mock one |
| 2627 | SwapProfilingConnectionFactoryHelper helper; |
| 2628 | |
| 2629 | // Reset the profiling service to the uninitialized state |
| 2630 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2631 | options.m_EnableProfiling = true; |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2632 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 2633 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2634 | |
| 2635 | // Bring the profiling service to the "Active" state |
| 2636 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2637 | profilingService.Update(); // Initialize the counter directory |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2638 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2639 | profilingService.Update(); // Create the profiling connection |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2640 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2641 | profilingService.Update(); // Start the command handler and the send thread |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2642 | |
| 2643 | // Wait for the Stream Metadata packet the be sent |
| 2644 | // (we are not testing the connection acknowledgement here so it will be ignored by this test) |
| 2645 | helper.WaitForProfilingPacketsSent(); |
| 2646 | |
| 2647 | // Force the profiling service to the "Active" state |
| 2648 | helper.ForceTransitionToState(ProfilingState::Active); |
| 2649 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2650 | |
| 2651 | // Get the mock profiling connection |
| 2652 | MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 2653 | BOOST_CHECK(mockProfilingConnection); |
| 2654 | |
| 2655 | // Remove the packets received so far |
| 2656 | mockProfilingConnection->Clear(); |
| 2657 | |
| 2658 | // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an |
| 2659 | // external profiling service |
| 2660 | |
| 2661 | // Periodic Counter Selection packet header: |
| 2662 | // 26:31 [6] packet_family: Control Packet Family, value 0b000000 |
| 2663 | // 16:25 [10] packet_id: Packet identifier, value 0b0000000100 |
| 2664 | // 8:15 [8] reserved: Reserved, value 0b00000000 |
| 2665 | // 0:7 [8] reserved: Reserved, value 0b00000000 |
| 2666 | uint32_t packetFamily = 0; |
| 2667 | uint32_t packetId = 4; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2668 | uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2669 | |
| 2670 | // Create the Periodic Counter Selection packet |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2671 | Packet periodicCounterSelectionPacket(header); // Length == 0, this will disable the collection of counters |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2672 | |
| 2673 | // Write the packet to the mock profiling connection |
| 2674 | mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket)); |
| 2675 | |
| 2676 | // Wait for the Periodic Counter Selection packet to be sent |
| 2677 | helper.WaitForProfilingPacketsSent(); |
| 2678 | |
| 2679 | // The Periodic Counter Selection Handler should not have updated the profiling state |
| 2680 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2681 | |
| 2682 | // Check that the mock profiling connection contains one Periodic Counter Selection |
| 2683 | const std::vector<uint32_t> writtenData = mockProfilingConnection->GetWrittenData(); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2684 | BOOST_TEST(writtenData.size() == 1); // Only one packet is expected (no Periodic Counter packets) |
| 2685 | BOOST_TEST(writtenData[0] == 12); // The size of the expected Periodic Counter Selection (echos the sent one) |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2686 | |
| 2687 | // Reset the profiling service to stop any running thread |
| 2688 | options.m_EnableProfiling = false; |
| 2689 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2690 | } |
| 2691 | |
| 2692 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodPeriodicCounterSelectionPacketSingleCounter) |
| 2693 | { |
| 2694 | // Swap the profiling connection factory in the profiling service instance with our mock one |
| 2695 | SwapProfilingConnectionFactoryHelper helper; |
| 2696 | |
| 2697 | // Reset the profiling service to the uninitialized state |
| 2698 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2699 | options.m_EnableProfiling = true; |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2700 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 2701 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2702 | |
| 2703 | // Bring the profiling service to the "Active" state |
| 2704 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2705 | profilingService.Update(); // Initialize the counter directory |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2706 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2707 | profilingService.Update(); // Create the profiling connection |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2708 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2709 | profilingService.Update(); // Start the command handler and the send thread |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2710 | |
| 2711 | // Wait for the Stream Metadata packet the be sent |
| 2712 | // (we are not testing the connection acknowledgement here so it will be ignored by this test) |
| 2713 | helper.WaitForProfilingPacketsSent(); |
| 2714 | |
| 2715 | // Force the profiling service to the "Active" state |
| 2716 | helper.ForceTransitionToState(ProfilingState::Active); |
| 2717 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2718 | |
| 2719 | // Get the mock profiling connection |
| 2720 | MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 2721 | BOOST_CHECK(mockProfilingConnection); |
| 2722 | |
| 2723 | // Remove the packets received so far |
| 2724 | mockProfilingConnection->Clear(); |
| 2725 | |
| 2726 | // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an |
| 2727 | // external profiling service |
| 2728 | |
| 2729 | // Periodic Counter Selection packet header: |
| 2730 | // 26:31 [6] packet_family: Control Packet Family, value 0b000000 |
| 2731 | // 16:25 [10] packet_id: Packet identifier, value 0b0000000100 |
| 2732 | // 8:15 [8] reserved: Reserved, value 0b00000000 |
| 2733 | // 0:7 [8] reserved: Reserved, value 0b00000000 |
| 2734 | uint32_t packetFamily = 0; |
| 2735 | uint32_t packetId = 4; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2736 | uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2737 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2738 | uint32_t capturePeriod = 123456; // Some capture period (microseconds) |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2739 | |
| 2740 | // Get the first valid counter UID |
| 2741 | const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory(); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2742 | const Counters& counters = counterDirectory.GetCounters(); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2743 | BOOST_CHECK(!counters.empty()); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2744 | uint16_t counterUid = counters.begin()->first; // Valid counter UID |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2745 | |
| 2746 | uint32_t length = 6; |
| 2747 | |
| 2748 | auto data = std::make_unique<unsigned char[]>(length); |
| 2749 | WriteUint32(data.get(), 0, capturePeriod); |
| 2750 | WriteUint16(data.get(), 4, counterUid); |
| 2751 | |
| 2752 | // Create the Periodic Counter Selection packet |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2753 | Packet periodicCounterSelectionPacket(header, length, data); // Length > 0, this will start the Period Counter |
| 2754 | // Capture thread |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2755 | |
| 2756 | // Write the packet to the mock profiling connection |
| 2757 | mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket)); |
| 2758 | |
| 2759 | // Expecting one Periodic Counter Selection packet and at least one Periodic Counter Capture packet |
| 2760 | int expectedPackets = 2; |
| 2761 | std::vector<uint32_t> receivedPackets; |
| 2762 | |
| 2763 | // Keep waiting until all the expected packets have been received |
| 2764 | do |
| 2765 | { |
| 2766 | helper.WaitForProfilingPacketsSent(); |
| 2767 | const std::vector<uint32_t> writtenData = mockProfilingConnection->GetWrittenData(); |
| 2768 | if (writtenData.empty()) |
| 2769 | { |
| 2770 | BOOST_ERROR("Packets should be available for reading at this point"); |
| 2771 | return; |
| 2772 | } |
| 2773 | receivedPackets.insert(receivedPackets.end(), writtenData.begin(), writtenData.end()); |
| 2774 | expectedPackets -= boost::numeric_cast<int>(writtenData.size()); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2775 | } while (expectedPackets > 0); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2776 | BOOST_TEST(!receivedPackets.empty()); |
| 2777 | |
| 2778 | // The size of the expected Periodic Counter Selection packet (echos the sent one) |
| 2779 | BOOST_TEST((std::find(receivedPackets.begin(), receivedPackets.end(), 14) != receivedPackets.end())); |
| 2780 | // The size of the expected Periodic Counter Capture packet |
| 2781 | BOOST_TEST((std::find(receivedPackets.begin(), receivedPackets.end(), 22) != receivedPackets.end())); |
| 2782 | |
| 2783 | // The Periodic Counter Selection Handler should not have updated the profiling state |
| 2784 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2785 | |
| 2786 | // Reset the profiling service to stop any running thread |
| 2787 | options.m_EnableProfiling = false; |
| 2788 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2789 | } |
| 2790 | |
| 2791 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodPeriodicCounterSelectionPacketMultipleCounters) |
| 2792 | { |
| 2793 | // Swap the profiling connection factory in the profiling service instance with our mock one |
| 2794 | SwapProfilingConnectionFactoryHelper helper; |
| 2795 | |
| 2796 | // Reset the profiling service to the uninitialized state |
| 2797 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2798 | options.m_EnableProfiling = true; |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2799 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 2800 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2801 | |
| 2802 | // Bring the profiling service to the "Active" state |
| 2803 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2804 | profilingService.Update(); // Initialize the counter directory |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2805 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2806 | profilingService.Update(); // Create the profiling connection |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2807 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2808 | profilingService.Update(); // Start the command handler and the send thread |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2809 | |
| 2810 | // Wait for the Stream Metadata packet the be sent |
| 2811 | // (we are not testing the connection acknowledgement here so it will be ignored by this test) |
| 2812 | helper.WaitForProfilingPacketsSent(); |
| 2813 | |
| 2814 | // Force the profiling service to the "Active" state |
| 2815 | helper.ForceTransitionToState(ProfilingState::Active); |
| 2816 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2817 | |
| 2818 | // Get the mock profiling connection |
| 2819 | MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 2820 | BOOST_CHECK(mockProfilingConnection); |
| 2821 | |
| 2822 | // Remove the packets received so far |
| 2823 | mockProfilingConnection->Clear(); |
| 2824 | |
| 2825 | // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an |
| 2826 | // external profiling service |
| 2827 | |
| 2828 | // Periodic Counter Selection packet header: |
| 2829 | // 26:31 [6] packet_family: Control Packet Family, value 0b000000 |
| 2830 | // 16:25 [10] packet_id: Packet identifier, value 0b0000000100 |
| 2831 | // 8:15 [8] reserved: Reserved, value 0b00000000 |
| 2832 | // 0:7 [8] reserved: Reserved, value 0b00000000 |
| 2833 | uint32_t packetFamily = 0; |
| 2834 | uint32_t packetId = 4; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2835 | uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2836 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2837 | uint32_t capturePeriod = 123456; // Some capture period (microseconds) |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2838 | |
| 2839 | // Get the first valid counter UID |
| 2840 | const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory(); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2841 | const Counters& counters = counterDirectory.GetCounters(); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2842 | BOOST_CHECK(counters.size() > 1); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2843 | uint16_t counterUidA = counters.begin()->first; // First valid counter UID |
| 2844 | uint16_t counterUidB = (counters.begin()++)->first; // Second valid counter UID |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2845 | |
| 2846 | uint32_t length = 8; |
| 2847 | |
| 2848 | auto data = std::make_unique<unsigned char[]>(length); |
| 2849 | WriteUint32(data.get(), 0, capturePeriod); |
| 2850 | WriteUint16(data.get(), 4, counterUidA); |
| 2851 | WriteUint16(data.get(), 6, counterUidB); |
| 2852 | |
| 2853 | // Create the Periodic Counter Selection packet |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2854 | Packet periodicCounterSelectionPacket(header, length, data); // Length > 0, this will start the Period Counter |
| 2855 | // Capture thread |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2856 | |
| 2857 | // Write the packet to the mock profiling connection |
| 2858 | mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket)); |
| 2859 | |
| 2860 | // Expecting one Periodic Counter Selection packet and at least one Periodic Counter Capture packet |
| 2861 | int expectedPackets = 2; |
| 2862 | std::vector<uint32_t> receivedPackets; |
| 2863 | |
| 2864 | // Keep waiting until all the expected packets have been received |
| 2865 | do |
| 2866 | { |
| 2867 | helper.WaitForProfilingPacketsSent(); |
| 2868 | const std::vector<uint32_t> writtenData = mockProfilingConnection->GetWrittenData(); |
| 2869 | if (writtenData.empty()) |
| 2870 | { |
| 2871 | BOOST_ERROR("Packets should be available for reading at this point"); |
| 2872 | return; |
| 2873 | } |
| 2874 | receivedPackets.insert(receivedPackets.end(), writtenData.begin(), writtenData.end()); |
| 2875 | expectedPackets -= boost::numeric_cast<int>(writtenData.size()); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2876 | } while (expectedPackets > 0); |
Matteo Martincigh | e848538 | 2019-10-10 14:08:21 +0100 | [diff] [blame] | 2877 | BOOST_TEST(!receivedPackets.empty()); |
| 2878 | |
| 2879 | // The size of the expected Periodic Counter Selection packet (echos the sent one) |
| 2880 | BOOST_TEST((std::find(receivedPackets.begin(), receivedPackets.end(), 16) != receivedPackets.end())); |
| 2881 | // The size of the expected Periodic Counter Capture packet |
| 2882 | BOOST_TEST((std::find(receivedPackets.begin(), receivedPackets.end(), 28) != receivedPackets.end())); |
| 2883 | |
| 2884 | // The Periodic Counter Selection Handler should not have updated the profiling state |
| 2885 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
Matteo Martincigh | 8efc500 | 2019-10-10 14:30:29 +0100 | [diff] [blame] | 2886 | |
| 2887 | // Reset the profiling service to stop any running thread |
| 2888 | options.m_EnableProfiling = false; |
| 2889 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2890 | } |
| 2891 | |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2892 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceDisconnect) |
| 2893 | { |
| 2894 | // Swap the profiling connection factory in the profiling service instance with our mock one |
| 2895 | SwapProfilingConnectionFactoryHelper helper; |
| 2896 | |
| 2897 | // Reset the profiling service to the uninitialized state |
| 2898 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2899 | options.m_EnableProfiling = true; |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2900 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 2901 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2902 | |
| 2903 | // Try to disconnect the profiling service while in the "Uninitialised" state |
| 2904 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
| 2905 | profilingService.Disconnect(); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2906 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); // The state should not change |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2907 | |
| 2908 | // Try to disconnect the profiling service while in the "NotConnected" state |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2909 | profilingService.Update(); // Initialize the counter directory |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2910 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
| 2911 | profilingService.Disconnect(); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2912 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); // The state should not change |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2913 | |
| 2914 | // Try to disconnect the profiling service while in the "WaitingForAck" state |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2915 | profilingService.Update(); // Create the profiling connection |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2916 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
| 2917 | profilingService.Disconnect(); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2918 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); // The state should not change |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2919 | |
| 2920 | // Try to disconnect the profiling service while in the "Active" state |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2921 | profilingService.Update(); // Start the command handler and the send thread |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2922 | |
| 2923 | // Wait for the Stream Metadata packet the be sent |
| 2924 | // (we are not testing the connection acknowledgement here so it will be ignored by this test) |
| 2925 | helper.WaitForProfilingPacketsSent(); |
| 2926 | |
| 2927 | // Force the profiling service to the "Active" state |
| 2928 | helper.ForceTransitionToState(ProfilingState::Active); |
| 2929 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2930 | |
| 2931 | // Get the mock profiling connection |
| 2932 | MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 2933 | BOOST_CHECK(mockProfilingConnection); |
| 2934 | |
| 2935 | // Check that the profiling connection is open |
| 2936 | BOOST_CHECK(mockProfilingConnection->IsOpen()); |
| 2937 | |
| 2938 | profilingService.Disconnect(); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2939 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); // The state should have changed |
Jim Flynn | 53e4699 | 2019-10-14 12:31:10 +0100 | [diff] [blame] | 2940 | |
| 2941 | // Check that the profiling connection has been reset |
| 2942 | mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 2943 | BOOST_CHECK(mockProfilingConnection == nullptr); |
| 2944 | |
| 2945 | // Reset the profiling service to stop any running thread |
| 2946 | options.m_EnableProfiling = false; |
| 2947 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2948 | } |
| 2949 | |
Matteo Martincigh | 994b534 | 2019-10-11 17:19:56 +0100 | [diff] [blame] | 2950 | BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodPerJobCounterSelectionPacket) |
| 2951 | { |
| 2952 | // Swap the profiling connection factory in the profiling service instance with our mock one |
| 2953 | SwapProfilingConnectionFactoryHelper helper; |
| 2954 | |
| 2955 | // Reset the profiling service to the uninitialized state |
| 2956 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2957 | options.m_EnableProfiling = true; |
Matteo Martincigh | 994b534 | 2019-10-11 17:19:56 +0100 | [diff] [blame] | 2958 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 2959 | profilingService.ResetExternalProfilingOptions(options, true); |
| 2960 | |
| 2961 | // Bring the profiling service to the "Active" state |
| 2962 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2963 | profilingService.Update(); // Initialize the counter directory |
Matteo Martincigh | 994b534 | 2019-10-11 17:19:56 +0100 | [diff] [blame] | 2964 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2965 | profilingService.Update(); // Create the profiling connection |
Matteo Martincigh | 994b534 | 2019-10-11 17:19:56 +0100 | [diff] [blame] | 2966 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2967 | profilingService.Update(); // Start the command handler and the send thread |
Matteo Martincigh | 994b534 | 2019-10-11 17:19:56 +0100 | [diff] [blame] | 2968 | |
| 2969 | // Wait for the Stream Metadata packet the be sent |
| 2970 | // (we are not testing the connection acknowledgement here so it will be ignored by this test) |
| 2971 | helper.WaitForProfilingPacketsSent(); |
| 2972 | |
| 2973 | // Force the profiling service to the "Active" state |
| 2974 | helper.ForceTransitionToState(ProfilingState::Active); |
| 2975 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 2976 | |
| 2977 | // Get the mock profiling connection |
| 2978 | MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection(); |
| 2979 | BOOST_CHECK(mockProfilingConnection); |
| 2980 | |
| 2981 | // Remove the packets received so far |
| 2982 | mockProfilingConnection->Clear(); |
| 2983 | |
| 2984 | // Write a "Per-Job Counter Selection" packet into the mock profiling connection, to simulate an input from an |
| 2985 | // external profiling service |
| 2986 | |
| 2987 | // Per-Job Counter Selection packet header: |
| 2988 | // 26:31 [6] packet_family: Control Packet Family, value 0b000000 |
| 2989 | // 16:25 [10] packet_id: Packet identifier, value 0b0000000100 |
| 2990 | // 8:15 [8] reserved: Reserved, value 0b00000000 |
| 2991 | // 0:7 [8] reserved: Reserved, value 0b00000000 |
| 2992 | uint32_t packetFamily = 0; |
| 2993 | uint32_t packetId = 5; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2994 | uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16); |
Matteo Martincigh | 994b534 | 2019-10-11 17:19:56 +0100 | [diff] [blame] | 2995 | |
| 2996 | // Create the Per-Job Counter Selection packet |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 2997 | Packet periodicCounterSelectionPacket(header); // Length == 0, this will disable the collection of counters |
Matteo Martincigh | 994b534 | 2019-10-11 17:19:56 +0100 | [diff] [blame] | 2998 | |
| 2999 | // Write the packet to the mock profiling connection |
| 3000 | mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket)); |
| 3001 | |
| 3002 | // Wait for a bit (must at least be the delay value of the mock profiling connection) to make sure that |
| 3003 | // the Per-Job Counter Selection packet gets processed by the profiling service |
| 3004 | std::this_thread::sleep_for(std::chrono::seconds(2)); |
| 3005 | |
| 3006 | // The Per-Job Counter Selection packets are dropped silently, so there should be no reply coming |
| 3007 | // from the profiling service |
| 3008 | const std::vector<uint32_t> writtenData = mockProfilingConnection->GetWrittenData(); |
| 3009 | BOOST_TEST(writtenData.empty()); |
| 3010 | |
| 3011 | // The Per-Job Counter Selection Command Handler should not have updated the profiling state |
| 3012 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active); |
| 3013 | |
| 3014 | // Reset the profiling service to stop any running thread |
| 3015 | options.m_EnableProfiling = false; |
| 3016 | profilingService.ResetExternalProfilingOptions(options, true); |
| 3017 | } |
| 3018 | |
Jim Flynn | 672d06e | 2019-10-15 10:18:11 +0100 | [diff] [blame] | 3019 | BOOST_AUTO_TEST_CASE(CheckConfigureProfilingServiceOn) |
| 3020 | { |
| 3021 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 3022 | options.m_EnableProfiling = true; |
Jim Flynn | 672d06e | 2019-10-15 10:18:11 +0100 | [diff] [blame] | 3023 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 3024 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
| 3025 | profilingService.ConfigureProfilingService(options); |
| 3026 | // should get as far as NOT_CONNECTED |
| 3027 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); |
| 3028 | // Reset the profiling service to stop any running thread |
| 3029 | options.m_EnableProfiling = false; |
| 3030 | profilingService.ResetExternalProfilingOptions(options, true); |
| 3031 | } |
| 3032 | |
| 3033 | BOOST_AUTO_TEST_CASE(CheckConfigureProfilingServiceOff) |
| 3034 | { |
| 3035 | armnn::Runtime::CreationOptions::ExternalProfilingOptions options; |
| 3036 | ProfilingService& profilingService = ProfilingService::Instance(); |
| 3037 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
| 3038 | profilingService.ConfigureProfilingService(options); |
| 3039 | // should not move from Uninitialised |
| 3040 | BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); |
| 3041 | // Reset the profiling service to stop any running thread |
| 3042 | options.m_EnableProfiling = false; |
| 3043 | profilingService.ResetExternalProfilingOptions(options, true); |
| 3044 | } |
| 3045 | |
Francis Murtagh | 1f7db45 | 2019-08-14 09:49:34 +0100 | [diff] [blame] | 3046 | BOOST_AUTO_TEST_SUITE_END() |