blob: b15ddf78854f2428a2be4fd7844ba5884e5d32d5 [file] [log] [blame]
Francis Murtagh1f7db452019-08-14 09:49:34 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
Matteo Martincighd0613b52019-10-09 16:47:04 +01006#include "ProfilingTests.hpp"
Teresa Charlin9bab4962019-09-06 12:28:35 +01007
James Conroy2dcd3fe2020-02-06 18:34:52 +00008#include <backends/BackendProfiling.hpp>
Matteo Martincigh8a837172019-10-04 17:01:07 +01009#include <CommandHandler.hpp>
Matteo Martincigh6db5f202019-09-05 12:02:04 +010010#include <CommandHandlerKey.hpp>
Matteo Martincigh6db5f202019-09-05 12:02:04 +010011#include <CommandHandlerRegistry.hpp>
Sadik Armaganb5f01b22019-09-18 17:29:00 +010012#include <ConnectionAcknowledgedCommandHandler.hpp>
Matteo Martincigh6db5f202019-09-05 12:02:04 +010013#include <CounterDirectory.hpp>
David Monahande803072020-01-30 12:44:23 +000014#include <CounterIdMap.hpp>
Matteo Martincigh6db5f202019-09-05 12:02:04 +010015#include <EncodeVersion.hpp>
16#include <Holder.hpp>
Matteo Martincighe0e6efc2019-10-04 17:17:42 +010017#include <ICounterValues.hpp>
Matteo Martincigh6db5f202019-09-05 12:02:04 +010018#include <Packet.hpp>
19#include <PacketVersionResolver.hpp>
Francis Murtaghfcb8ef62019-09-20 15:40:09 +010020#include <PeriodicCounterCapture.hpp>
Matteo Martincigh6db5f202019-09-05 12:02:04 +010021#include <PeriodicCounterSelectionCommandHandler.hpp>
22#include <ProfilingStateMachine.hpp>
Matteo Martincigh6db5f202019-09-05 12:02:04 +010023#include <ProfilingUtils.hpp>
James Conroy2dcd3fe2020-02-06 18:34:52 +000024#include <RegisterBackendCounters.hpp>
Narumol Prangnawarat48033692019-09-20 12:04:55 +010025#include <RequestCounterDirectoryCommandHandler.hpp>
Teresa Charlin9bab4962019-09-06 12:28:35 +010026#include <Runtime.hpp>
Matteo Martincigh6db5f202019-09-05 12:02:04 +010027#include <SocketProfilingConnection.hpp>
Matteo Martincighcdfb9412019-11-08 11:23:06 +000028#include <SendCounterPacket.hpp>
29#include <SendTimelinePacket.hpp>
Keith Davis02356de2019-08-26 18:28:17 +010030
Matteo Martincigh6db5f202019-09-05 12:02:04 +010031#include <armnn/Conversion.hpp>
Colm Donelan02705242019-11-14 14:19:07 +000032#include <armnn/Types.hpp>
Ferran Balaguer1b941722019-08-28 16:57:18 +010033
Matteo Martincigh54fb9572019-10-02 12:50:57 +010034#include <armnn/Utils.hpp>
35
Sadik Armaganbd9e2c52019-09-26 23:13:31 +010036#include <boost/algorithm/string.hpp>
Ferran Balaguer1b941722019-08-28 16:57:18 +010037#include <boost/numeric/conversion/cast.hpp>
Francis Murtagh1f7db452019-08-14 09:49:34 +010038
Nikhil Rajbc626052019-08-15 15:49:45 +010039#include <cstdint>
40#include <cstring>
Keith Davis3201eea2019-10-24 17:30:41 +010041#include <iostream>
Aron Virginas-Tare898db92019-08-22 12:56:34 +010042#include <limits>
Francis Murtagh11f99b42019-08-16 11:28:52 +010043#include <map>
Aron Virginas-Tare898db92019-08-22 12:56:34 +010044#include <random>
James Conroy2dcd3fe2020-02-06 18:34:52 +000045
Francis Murtagh1f7db452019-08-14 09:49:34 +010046
Aron Virginas-Tare898db92019-08-22 12:56:34 +010047using namespace armnn::profiling;
Finn Williams09ad6f92019-12-19 17:05:18 +000048using PacketType = MockProfilingConnection::PacketType;
Aron Virginas-Tare898db92019-08-22 12:56:34 +010049
Matteo Martincigh8a837172019-10-04 17:01:07 +010050BOOST_AUTO_TEST_SUITE(ExternalProfiling)
51
Francis Murtagh1f7db452019-08-14 09:49:34 +010052BOOST_AUTO_TEST_CASE(CheckCommandHandlerKeyComparisons)
53{
Jim Flynn397043f2019-10-17 17:37:10 +010054 CommandHandlerKey testKey1_0(1, 1, 1);
55 CommandHandlerKey testKey1_1(1, 1, 1);
56 CommandHandlerKey testKey1_2(1, 2, 1);
57
58 CommandHandlerKey testKey0(0, 1, 1);
59 CommandHandlerKey testKey1(0, 1, 1);
60 CommandHandlerKey testKey2(0, 1, 1);
61 CommandHandlerKey testKey3(0, 0, 0);
62 CommandHandlerKey testKey4(0, 2, 2);
63 CommandHandlerKey testKey5(0, 0, 2);
64
65 BOOST_CHECK(testKey1_0 > testKey0);
66 BOOST_CHECK(testKey1_0 == testKey1_1);
67 BOOST_CHECK(testKey1_0 < testKey1_2);
Francis Murtagh1f7db452019-08-14 09:49:34 +010068
Keith Davis3201eea2019-10-24 17:30:41 +010069 BOOST_CHECK(testKey1 < testKey4);
70 BOOST_CHECK(testKey1 > testKey3);
71 BOOST_CHECK(testKey1 <= testKey4);
72 BOOST_CHECK(testKey1 >= testKey3);
73 BOOST_CHECK(testKey1 <= testKey2);
74 BOOST_CHECK(testKey1 >= testKey2);
75 BOOST_CHECK(testKey1 == testKey2);
76 BOOST_CHECK(testKey1 == testKey1);
Francis Murtagh1f7db452019-08-14 09:49:34 +010077
Keith Davis3201eea2019-10-24 17:30:41 +010078 BOOST_CHECK(!(testKey1 == testKey5));
79 BOOST_CHECK(!(testKey1 != testKey1));
80 BOOST_CHECK(testKey1 != testKey5);
Francis Murtagh1f7db452019-08-14 09:49:34 +010081
Keith Davis3201eea2019-10-24 17:30:41 +010082 BOOST_CHECK(testKey1 == testKey2 && testKey2 == testKey1);
83 BOOST_CHECK(testKey0 == testKey1 && testKey1 == testKey2 && testKey0 == testKey2);
Francis Murtagh1f7db452019-08-14 09:49:34 +010084
Keith Davis3201eea2019-10-24 17:30:41 +010085 BOOST_CHECK(testKey1.GetPacketId() == 1);
86 BOOST_CHECK(testKey1.GetVersion() == 1);
Francis Murtagh1f7db452019-08-14 09:49:34 +010087
Keith Davis3201eea2019-10-24 17:30:41 +010088 std::vector<CommandHandlerKey> vect = { CommandHandlerKey(0, 0, 1), CommandHandlerKey(0, 2, 0),
89 CommandHandlerKey(0, 1, 0), CommandHandlerKey(0, 2, 1),
90 CommandHandlerKey(0, 1, 1), CommandHandlerKey(0, 0, 1),
91 CommandHandlerKey(0, 2, 0), CommandHandlerKey(0, 0, 0) };
Francis Murtagh1f7db452019-08-14 09:49:34 +010092
93 std::sort(vect.begin(), vect.end());
94
Keith Davis3201eea2019-10-24 17:30:41 +010095 std::vector<CommandHandlerKey> expectedVect = { CommandHandlerKey(0, 0, 0), CommandHandlerKey(0, 0, 1),
96 CommandHandlerKey(0, 0, 1), CommandHandlerKey(0, 1, 0),
97 CommandHandlerKey(0, 1, 1), CommandHandlerKey(0, 2, 0),
98 CommandHandlerKey(0, 2, 0), CommandHandlerKey(0, 2, 1) };
Francis Murtagh1f7db452019-08-14 09:49:34 +010099
100 BOOST_CHECK(vect == expectedVect);
101}
102
Jim Flynned25e0e2019-10-18 13:21:43 +0100103BOOST_AUTO_TEST_CASE(CheckPacketKeyComparisons)
104{
Keith Davis3201eea2019-10-24 17:30:41 +0100105 PacketKey key0(0, 0);
106 PacketKey key1(0, 0);
107 PacketKey key2(0, 1);
108 PacketKey key3(0, 2);
109 PacketKey key4(1, 0);
110 PacketKey key5(1, 0);
111 PacketKey key6(1, 1);
Jim Flynned25e0e2019-10-18 13:21:43 +0100112
113 BOOST_CHECK(!(key0 < key1));
114 BOOST_CHECK(!(key0 > key1));
115 BOOST_CHECK(key0 <= key1);
116 BOOST_CHECK(key0 >= key1);
117 BOOST_CHECK(key0 == key1);
118 BOOST_CHECK(key0 < key2);
119 BOOST_CHECK(key2 < key3);
120 BOOST_CHECK(key3 > key0);
121 BOOST_CHECK(key4 == key5);
122 BOOST_CHECK(key4 > key0);
123 BOOST_CHECK(key5 < key6);
124 BOOST_CHECK(key5 <= key6);
125 BOOST_CHECK(key5 != key6);
126}
127
Matteo Martincigh8a837172019-10-04 17:01:07 +0100128BOOST_AUTO_TEST_CASE(CheckCommandHandler)
FinnWilliamsArm4833cea2019-09-17 16:53:53 +0100129{
Matteo Martincigh8a837172019-10-04 17:01:07 +0100130 PacketVersionResolver packetVersionResolver;
131 ProfilingStateMachine profilingStateMachine;
FinnWilliamsArm4833cea2019-09-17 16:53:53 +0100132
Matteo Martincigh8a837172019-10-04 17:01:07 +0100133 TestProfilingConnectionBase testProfilingConnectionBase;
134 TestProfilingConnectionTimeoutError testProfilingConnectionTimeOutError;
135 TestProfilingConnectionArmnnError testProfilingConnectionArmnnError;
Keith Davis3201eea2019-10-24 17:30:41 +0100136 CounterDirectory counterDirectory;
137 MockBufferManager mockBuffer(1024);
138 SendCounterPacket sendCounterPacket(profilingStateMachine, mockBuffer);
Matteo Martincighcdfb9412019-11-08 11:23:06 +0000139 SendTimelinePacket sendTimelinePacket(mockBuffer);
140
Keith Davis3201eea2019-10-24 17:30:41 +0100141 ConnectionAcknowledgedCommandHandler connectionAcknowledgedCommandHandler(0, 1, 4194304, counterDirectory,
Matteo Martincighcdfb9412019-11-08 11:23:06 +0000142 sendCounterPacket, sendTimelinePacket,
143 profilingStateMachine);
Matteo Martincigh8a837172019-10-04 17:01:07 +0100144 CommandHandlerRegistry commandHandlerRegistry;
FinnWilliamsArm4833cea2019-09-17 16:53:53 +0100145
Matteo Martincighc2728f92019-10-07 12:35:21 +0100146 commandHandlerRegistry.RegisterFunctor(&connectionAcknowledgedCommandHandler);
FinnWilliamsArm4833cea2019-09-17 16:53:53 +0100147
Matteo Martincigh8a837172019-10-04 17:01:07 +0100148 profilingStateMachine.TransitionToState(ProfilingState::NotConnected);
149 profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck);
FinnWilliamsArm4833cea2019-09-17 16:53:53 +0100150
Keith Davis3201eea2019-10-24 17:30:41 +0100151 CommandHandler commandHandler0(1, true, commandHandlerRegistry, packetVersionResolver);
FinnWilliamsArm4833cea2019-09-17 16:53:53 +0100152
Colm Donelan2ba48d22019-11-29 09:10:59 +0000153 // This should start the command handler thread return the connection ack and put the profiling
154 // service into active state.
Matteo Martincigh8a837172019-10-04 17:01:07 +0100155 commandHandler0.Start(testProfilingConnectionBase);
Colm Donelan2ba48d22019-11-29 09:10:59 +0000156 // Try to start the send thread many times, it must only start once
Matteo Martincigh8a837172019-10-04 17:01:07 +0100157 commandHandler0.Start(testProfilingConnectionBase);
FinnWilliamsArm4833cea2019-09-17 16:53:53 +0100158
Colm Donelan2ba48d22019-11-29 09:10:59 +0000159 // This could take up to 20mSec but we'll check often.
160 for (int i = 0; i < 10; i++)
Matteo Martincigh8a837172019-10-04 17:01:07 +0100161 {
162 if (profilingStateMachine.GetCurrentState() == ProfilingState::Active)
FinnWilliamsArm4833cea2019-09-17 16:53:53 +0100163 {
Matteo Martincigh8a837172019-10-04 17:01:07 +0100164 break;
FinnWilliamsArm4833cea2019-09-17 16:53:53 +0100165 }
Colm Donelan2ba48d22019-11-29 09:10:59 +0000166 std::this_thread::sleep_for(std::chrono::milliseconds(2));
Matteo Martincigh8a837172019-10-04 17:01:07 +0100167 }
FinnWilliamsArm4833cea2019-09-17 16:53:53 +0100168
Matteo Martincigh8a837172019-10-04 17:01:07 +0100169 BOOST_CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::Active);
FinnWilliamsArm4833cea2019-09-17 16:53:53 +0100170
Colm Donelan2ba48d22019-11-29 09:10:59 +0000171 // Close the thread again.
172 commandHandler0.Stop();
173
174 profilingStateMachine.TransitionToState(ProfilingState::NotConnected);
175 profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck);
176
177 // In this test we'll simulate a timeout without a connection ack packet being received.
178 // Stop after timeout is set so we expect the command handler to stop almost immediately.
179 CommandHandler commandHandler1(1, true, commandHandlerRegistry, packetVersionResolver);
180
181 commandHandler1.Start(testProfilingConnectionTimeOutError);
182 // Wait until we know a timeout exception has been sent at least once.
183 for (int i = 0; i < 10; i++)
184 {
185 if (testProfilingConnectionTimeOutError.ReadCalledCount())
186 {
187 break;
188 }
189 std::this_thread::sleep_for(std::chrono::milliseconds(2));
190 }
Colm Donelan2ba48d22019-11-29 09:10:59 +0000191
192 // The command handler loop should have stopped after the timeout.
Finn Williams09ad6f92019-12-19 17:05:18 +0000193 // wait for the timeout exception to be processed and the loop to break.
194 uint32_t timeout = 50;
195 uint32_t timeSlept = 0;
196 while (commandHandler1.IsRunning())
197 {
198 if (timeSlept >= timeout)
199 {
200 BOOST_FAIL("Timeout: The command handler loop did not stop after the timeout");
201 }
202 std::this_thread::sleep_for(std::chrono::milliseconds(1));
203 timeSlept ++;
204 }
Colm Donelan2ba48d22019-11-29 09:10:59 +0000205
206 commandHandler1.Stop();
207 // The state machine should never have received the ack so will still be in WaitingForAck.
208 BOOST_CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::WaitingForAck);
209
Finn Williams09ad6f92019-12-19 17:05:18 +0000210 // Now try sending a bad connection acknowledged packet
211 TestProfilingConnectionBadAckPacket testProfilingConnectionBadAckPacket;
212 commandHandler1.Start(testProfilingConnectionBadAckPacket);
213 commandHandler1.Stop();
214 // This should also not change the state machine
215 BOOST_CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::WaitingForAck);
216
Colm Donelan2ba48d22019-11-29 09:10:59 +0000217 // Disable stop after timeout and now commandHandler1 should persist after a timeout
218 commandHandler1.SetStopAfterTimeout(false);
219 // Restart the thread.
220 commandHandler1.Start(testProfilingConnectionTimeOutError);
221
222 // Wait for at the three timeouts and the ack to be sent.
223 for (int i = 0; i < 10; i++)
224 {
225 if (testProfilingConnectionTimeOutError.ReadCalledCount() > 3)
226 {
227 break;
228 }
229 std::this_thread::sleep_for(std::chrono::milliseconds(2));
230 }
231 commandHandler1.Stop();
232
233 // Even after the 3 exceptions the ack packet should have transitioned the command handler to active.
234 BOOST_CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::Active);
235
236 // A command handler that gets exceptions other than timeouts should keep going.
237 CommandHandler commandHandler2(1, false, commandHandlerRegistry, packetVersionResolver);
FinnWilliamsArm4833cea2019-09-17 16:53:53 +0100238
Matteo Martincigh8a837172019-10-04 17:01:07 +0100239 commandHandler2.Start(testProfilingConnectionArmnnError);
240
Colm Donelan2ba48d22019-11-29 09:10:59 +0000241 // Wait for two exceptions to be thrown.
242 for (int i = 0; i < 10; i++)
243 {
244 if (testProfilingConnectionTimeOutError.ReadCalledCount() >= 2)
245 {
246 break;
247 }
248 std::this_thread::sleep_for(std::chrono::milliseconds(2));
249 }
FinnWilliamsArm4833cea2019-09-17 16:53:53 +0100250
Matteo Martincighd0613b52019-10-09 16:47:04 +0100251 BOOST_CHECK(commandHandler2.IsRunning());
Matteo Martincigh8a837172019-10-04 17:01:07 +0100252 commandHandler2.Stop();
FinnWilliamsArm4833cea2019-09-17 16:53:53 +0100253}
254
Nikhil Rajd88e47c2019-08-19 10:04:23 +0100255BOOST_AUTO_TEST_CASE(CheckEncodeVersion)
256{
Aron Virginas-Tare898db92019-08-22 12:56:34 +0100257 Version version1(12);
Nikhil Rajd88e47c2019-08-19 10:04:23 +0100258
259 BOOST_CHECK(version1.GetMajor() == 0);
260 BOOST_CHECK(version1.GetMinor() == 0);
261 BOOST_CHECK(version1.GetPatch() == 12);
262
Aron Virginas-Tare898db92019-08-22 12:56:34 +0100263 Version version2(4108);
Nikhil Rajd88e47c2019-08-19 10:04:23 +0100264
265 BOOST_CHECK(version2.GetMajor() == 0);
266 BOOST_CHECK(version2.GetMinor() == 1);
267 BOOST_CHECK(version2.GetPatch() == 12);
268
Aron Virginas-Tare898db92019-08-22 12:56:34 +0100269 Version version3(4198412);
Nikhil Rajd88e47c2019-08-19 10:04:23 +0100270
271 BOOST_CHECK(version3.GetMajor() == 1);
272 BOOST_CHECK(version3.GetMinor() == 1);
273 BOOST_CHECK(version3.GetPatch() == 12);
274
Aron Virginas-Tare898db92019-08-22 12:56:34 +0100275 Version version4(0);
Nikhil Rajd88e47c2019-08-19 10:04:23 +0100276
277 BOOST_CHECK(version4.GetMajor() == 0);
278 BOOST_CHECK(version4.GetMinor() == 0);
279 BOOST_CHECK(version4.GetPatch() == 0);
280
Aron Virginas-Tare898db92019-08-22 12:56:34 +0100281 Version version5(1, 0, 0);
Nikhil Rajd88e47c2019-08-19 10:04:23 +0100282 BOOST_CHECK(version5.GetEncodedValue() == 4194304);
283}
284
Nikhil Rajbc626052019-08-15 15:49:45 +0100285BOOST_AUTO_TEST_CASE(CheckPacketClass)
286{
Keith Davis3201eea2019-10-24 17:30:41 +0100287 uint32_t length = 4;
Matteo Martincigh67ef2a52019-10-10 13:29:02 +0100288 std::unique_ptr<unsigned char[]> packetData0 = std::make_unique<unsigned char[]>(length);
289 std::unique_ptr<unsigned char[]> packetData1 = std::make_unique<unsigned char[]>(0);
290 std::unique_ptr<unsigned char[]> nullPacketData;
Nikhil Rajbc626052019-08-15 15:49:45 +0100291
FinnWilliamsArma0c78712019-09-16 12:06:47 +0100292 Packet packetTest0(472580096, length, packetData0);
Nikhil Rajbc626052019-08-15 15:49:45 +0100293
FinnWilliamsArma0c78712019-09-16 12:06:47 +0100294 BOOST_CHECK(packetTest0.GetHeader() == 472580096);
295 BOOST_CHECK(packetTest0.GetPacketFamily() == 7);
296 BOOST_CHECK(packetTest0.GetPacketId() == 43);
297 BOOST_CHECK(packetTest0.GetLength() == length);
298 BOOST_CHECK(packetTest0.GetPacketType() == 3);
299 BOOST_CHECK(packetTest0.GetPacketClass() == 5);
Nikhil Rajbc626052019-08-15 15:49:45 +0100300
FinnWilliamsArma0c78712019-09-16 12:06:47 +0100301 BOOST_CHECK_THROW(Packet packetTest1(472580096, 0, packetData1), armnn::Exception);
302 BOOST_CHECK_NO_THROW(Packet packetTest2(472580096, 0, nullPacketData));
Nikhil Rajbc626052019-08-15 15:49:45 +0100303
FinnWilliamsArma0c78712019-09-16 12:06:47 +0100304 Packet packetTest3(472580096, 0, nullPacketData);
305 BOOST_CHECK(packetTest3.GetLength() == 0);
306 BOOST_CHECK(packetTest3.GetData() == nullptr);
307
Matteo Martincigh67ef2a52019-10-10 13:29:02 +0100308 const unsigned char* packetTest0Data = packetTest0.GetData();
FinnWilliamsArma0c78712019-09-16 12:06:47 +0100309 Packet packetTest4(std::move(packetTest0));
310
311 BOOST_CHECK(packetTest0.GetData() == nullptr);
312 BOOST_CHECK(packetTest4.GetData() == packetTest0Data);
313
314 BOOST_CHECK(packetTest4.GetHeader() == 472580096);
315 BOOST_CHECK(packetTest4.GetPacketFamily() == 7);
316 BOOST_CHECK(packetTest4.GetPacketId() == 43);
317 BOOST_CHECK(packetTest4.GetLength() == length);
318 BOOST_CHECK(packetTest4.GetPacketType() == 3);
319 BOOST_CHECK(packetTest4.GetPacketClass() == 5);
Nikhil Rajbc626052019-08-15 15:49:45 +0100320}
321
Francis Murtagh11f99b42019-08-16 11:28:52 +0100322BOOST_AUTO_TEST_CASE(CheckCommandHandlerFunctor)
323{
Francis Murtagh11f99b42019-08-16 11:28:52 +0100324 // Hard code the version as it will be the same during a single profiling session
325 uint32_t version = 1;
326
Jim Flynn397043f2019-10-17 17:37:10 +0100327 TestFunctorA testFunctorA(7, 461, version);
328 TestFunctorB testFunctorB(8, 963, version);
329 TestFunctorC testFunctorC(5, 983, version);
Francis Murtagh11f99b42019-08-16 11:28:52 +0100330
Jim Flynn397043f2019-10-17 17:37:10 +0100331 CommandHandlerKey keyA(testFunctorA.GetFamilyId(), testFunctorA.GetPacketId(), testFunctorA.GetVersion());
332 CommandHandlerKey keyB(testFunctorB.GetFamilyId(), testFunctorB.GetPacketId(), testFunctorB.GetVersion());
333 CommandHandlerKey keyC(testFunctorC.GetFamilyId(), testFunctorC.GetPacketId(), testFunctorC.GetVersion());
Francis Murtagh11f99b42019-08-16 11:28:52 +0100334
335 // Create the unwrapped map to simulate the Command Handler Registry
336 std::map<CommandHandlerKey, CommandHandlerFunctor*> registry;
337
338 registry.insert(std::make_pair(keyB, &testFunctorB));
339 registry.insert(std::make_pair(keyA, &testFunctorA));
340 registry.insert(std::make_pair(keyC, &testFunctorC));
341
342 // Check the order of the map is correct
343 auto it = registry.begin();
Keith Davis3201eea2019-10-24 17:30:41 +0100344 BOOST_CHECK(it->first == keyC); // familyId == 5
Francis Murtagh11f99b42019-08-16 11:28:52 +0100345 it++;
Keith Davis3201eea2019-10-24 17:30:41 +0100346 BOOST_CHECK(it->first == keyA); // familyId == 7
Francis Murtagh11f99b42019-08-16 11:28:52 +0100347 it++;
Keith Davis3201eea2019-10-24 17:30:41 +0100348 BOOST_CHECK(it->first == keyB); // familyId == 8
Francis Murtagh11f99b42019-08-16 11:28:52 +0100349
Matteo Martincigh67ef2a52019-10-10 13:29:02 +0100350 std::unique_ptr<unsigned char[]> packetDataA;
351 std::unique_ptr<unsigned char[]> packetDataB;
352 std::unique_ptr<unsigned char[]> packetDataC;
FinnWilliamsArma0c78712019-09-16 12:06:47 +0100353
354 Packet packetA(500000000, 0, packetDataA);
355 Packet packetB(600000000, 0, packetDataB);
356 Packet packetC(400000000, 0, packetDataC);
Francis Murtagh11f99b42019-08-16 11:28:52 +0100357
358 // Check the correct operator of derived class is called
Jim Flynn397043f2019-10-17 17:37:10 +0100359 registry.at(CommandHandlerKey(packetA.GetPacketFamily(), packetA.GetPacketId(), version))->operator()(packetA);
Francis Murtagh11f99b42019-08-16 11:28:52 +0100360 BOOST_CHECK(testFunctorA.GetCount() == 1);
361 BOOST_CHECK(testFunctorB.GetCount() == 0);
362 BOOST_CHECK(testFunctorC.GetCount() == 0);
363
Jim Flynn397043f2019-10-17 17:37:10 +0100364 registry.at(CommandHandlerKey(packetB.GetPacketFamily(), packetB.GetPacketId(), version))->operator()(packetB);
Francis Murtagh11f99b42019-08-16 11:28:52 +0100365 BOOST_CHECK(testFunctorA.GetCount() == 1);
366 BOOST_CHECK(testFunctorB.GetCount() == 1);
367 BOOST_CHECK(testFunctorC.GetCount() == 0);
368
Jim Flynn397043f2019-10-17 17:37:10 +0100369 registry.at(CommandHandlerKey(packetC.GetPacketFamily(), packetC.GetPacketId(), version))->operator()(packetC);
Francis Murtagh11f99b42019-08-16 11:28:52 +0100370 BOOST_CHECK(testFunctorA.GetCount() == 1);
371 BOOST_CHECK(testFunctorB.GetCount() == 1);
372 BOOST_CHECK(testFunctorC.GetCount() == 1);
373}
374
Francis Murtagh94d79152019-08-16 17:45:07 +0100375BOOST_AUTO_TEST_CASE(CheckCommandHandlerRegistry)
376{
377 // Hard code the version as it will be the same during a single profiling session
378 uint32_t version = 1;
379
Jim Flynn397043f2019-10-17 17:37:10 +0100380 TestFunctorA testFunctorA(7, 461, version);
381 TestFunctorB testFunctorB(8, 963, version);
382 TestFunctorC testFunctorC(5, 983, version);
Francis Murtagh94d79152019-08-16 17:45:07 +0100383
384 // Create the Command Handler Registry
385 CommandHandlerRegistry registry;
386
387 // Register multiple different derived classes
Matteo Martincighc2728f92019-10-07 12:35:21 +0100388 registry.RegisterFunctor(&testFunctorA);
389 registry.RegisterFunctor(&testFunctorB);
390 registry.RegisterFunctor(&testFunctorC);
Francis Murtagh94d79152019-08-16 17:45:07 +0100391
Matteo Martincigh67ef2a52019-10-10 13:29:02 +0100392 std::unique_ptr<unsigned char[]> packetDataA;
393 std::unique_ptr<unsigned char[]> packetDataB;
394 std::unique_ptr<unsigned char[]> packetDataC;
FinnWilliamsArma0c78712019-09-16 12:06:47 +0100395
396 Packet packetA(500000000, 0, packetDataA);
397 Packet packetB(600000000, 0, packetDataB);
398 Packet packetC(400000000, 0, packetDataC);
Francis Murtagh94d79152019-08-16 17:45:07 +0100399
400 // Check the correct operator of derived class is called
Jim Flynn397043f2019-10-17 17:37:10 +0100401 registry.GetFunctor(packetA.GetPacketFamily(), packetA.GetPacketId(), version)->operator()(packetA);
Francis Murtagh94d79152019-08-16 17:45:07 +0100402 BOOST_CHECK(testFunctorA.GetCount() == 1);
403 BOOST_CHECK(testFunctorB.GetCount() == 0);
404 BOOST_CHECK(testFunctorC.GetCount() == 0);
405
Jim Flynn397043f2019-10-17 17:37:10 +0100406 registry.GetFunctor(packetB.GetPacketFamily(), packetB.GetPacketId(), version)->operator()(packetB);
Francis Murtagh94d79152019-08-16 17:45:07 +0100407 BOOST_CHECK(testFunctorA.GetCount() == 1);
408 BOOST_CHECK(testFunctorB.GetCount() == 1);
409 BOOST_CHECK(testFunctorC.GetCount() == 0);
410
Jim Flynn397043f2019-10-17 17:37:10 +0100411 registry.GetFunctor(packetC.GetPacketFamily(), packetC.GetPacketId(), version)->operator()(packetC);
Francis Murtagh94d79152019-08-16 17:45:07 +0100412 BOOST_CHECK(testFunctorA.GetCount() == 1);
413 BOOST_CHECK(testFunctorB.GetCount() == 1);
414 BOOST_CHECK(testFunctorC.GetCount() == 1);
415
416 // Re-register an existing key with a new function
Jim Flynn397043f2019-10-17 17:37:10 +0100417 registry.RegisterFunctor(&testFunctorC, testFunctorA.GetFamilyId(), testFunctorA.GetPacketId(), version);
418 registry.GetFunctor(packetA.GetPacketFamily(), packetA.GetPacketId(), version)->operator()(packetC);
Francis Murtagh94d79152019-08-16 17:45:07 +0100419 BOOST_CHECK(testFunctorA.GetCount() == 1);
420 BOOST_CHECK(testFunctorB.GetCount() == 1);
421 BOOST_CHECK(testFunctorC.GetCount() == 2);
422
423 // Check that non-existent key returns nullptr for its functor
Jim Flynn397043f2019-10-17 17:37:10 +0100424 BOOST_CHECK_THROW(registry.GetFunctor(0, 0, 0), armnn::Exception);
Francis Murtagh94d79152019-08-16 17:45:07 +0100425}
426
Aron Virginas-Tare898db92019-08-22 12:56:34 +0100427BOOST_AUTO_TEST_CASE(CheckPacketVersionResolver)
428{
429 // Set up random number generator for generating packetId values
430 std::random_device device;
431 std::mt19937 generator(device());
432 std::uniform_int_distribution<uint32_t> distribution(std::numeric_limits<uint32_t>::min(),
433 std::numeric_limits<uint32_t>::max());
434
435 // NOTE: Expected version is always 1.0.0, regardless of packetId
436 const Version expectedVersion(1, 0, 0);
437
438 PacketVersionResolver packetVersionResolver;
439
440 constexpr unsigned int numTests = 10u;
441
442 for (unsigned int i = 0u; i < numTests; ++i)
443 {
Jim Flynned25e0e2019-10-18 13:21:43 +0100444 const uint32_t familyId = distribution(generator);
Aron Virginas-Tare898db92019-08-22 12:56:34 +0100445 const uint32_t packetId = distribution(generator);
Jim Flynned25e0e2019-10-18 13:21:43 +0100446 Version resolvedVersion = packetVersionResolver.ResolvePacketVersion(familyId, packetId);
Aron Virginas-Tare898db92019-08-22 12:56:34 +0100447
448 BOOST_TEST(resolvedVersion == expectedVersion);
449 }
450}
Matteo Martincighd0613b52019-10-09 16:47:04 +0100451
Nikhil Raj3ecc5102019-09-03 15:55:33 +0100452void ProfilingCurrentStateThreadImpl(ProfilingStateMachine& states)
453{
454 ProfilingState newState = ProfilingState::NotConnected;
455 states.GetCurrentState();
456 states.TransitionToState(newState);
457}
458
459BOOST_AUTO_TEST_CASE(CheckProfilingStateMachine)
460{
461 ProfilingStateMachine profilingState1(ProfilingState::Uninitialised);
462 profilingState1.TransitionToState(ProfilingState::Uninitialised);
Keith Davis3201eea2019-10-24 17:30:41 +0100463 BOOST_CHECK(profilingState1.GetCurrentState() == ProfilingState::Uninitialised);
Nikhil Raj3ecc5102019-09-03 15:55:33 +0100464
465 ProfilingStateMachine profilingState2(ProfilingState::Uninitialised);
466 profilingState2.TransitionToState(ProfilingState::NotConnected);
467 BOOST_CHECK(profilingState2.GetCurrentState() == ProfilingState::NotConnected);
468
469 ProfilingStateMachine profilingState3(ProfilingState::NotConnected);
470 profilingState3.TransitionToState(ProfilingState::NotConnected);
471 BOOST_CHECK(profilingState3.GetCurrentState() == ProfilingState::NotConnected);
472
473 ProfilingStateMachine profilingState4(ProfilingState::NotConnected);
474 profilingState4.TransitionToState(ProfilingState::WaitingForAck);
475 BOOST_CHECK(profilingState4.GetCurrentState() == ProfilingState::WaitingForAck);
476
477 ProfilingStateMachine profilingState5(ProfilingState::WaitingForAck);
478 profilingState5.TransitionToState(ProfilingState::WaitingForAck);
479 BOOST_CHECK(profilingState5.GetCurrentState() == ProfilingState::WaitingForAck);
480
481 ProfilingStateMachine profilingState6(ProfilingState::WaitingForAck);
482 profilingState6.TransitionToState(ProfilingState::Active);
483 BOOST_CHECK(profilingState6.GetCurrentState() == ProfilingState::Active);
484
485 ProfilingStateMachine profilingState7(ProfilingState::Active);
486 profilingState7.TransitionToState(ProfilingState::NotConnected);
487 BOOST_CHECK(profilingState7.GetCurrentState() == ProfilingState::NotConnected);
488
489 ProfilingStateMachine profilingState8(ProfilingState::Active);
490 profilingState8.TransitionToState(ProfilingState::Active);
491 BOOST_CHECK(profilingState8.GetCurrentState() == ProfilingState::Active);
492
493 ProfilingStateMachine profilingState9(ProfilingState::Uninitialised);
Keith Davis3201eea2019-10-24 17:30:41 +0100494 BOOST_CHECK_THROW(profilingState9.TransitionToState(ProfilingState::WaitingForAck), armnn::Exception);
Nikhil Raj3ecc5102019-09-03 15:55:33 +0100495
496 ProfilingStateMachine profilingState10(ProfilingState::Uninitialised);
Keith Davis3201eea2019-10-24 17:30:41 +0100497 BOOST_CHECK_THROW(profilingState10.TransitionToState(ProfilingState::Active), armnn::Exception);
Nikhil Raj3ecc5102019-09-03 15:55:33 +0100498
499 ProfilingStateMachine profilingState11(ProfilingState::NotConnected);
Keith Davis3201eea2019-10-24 17:30:41 +0100500 BOOST_CHECK_THROW(profilingState11.TransitionToState(ProfilingState::Uninitialised), armnn::Exception);
Nikhil Raj3ecc5102019-09-03 15:55:33 +0100501
502 ProfilingStateMachine profilingState12(ProfilingState::NotConnected);
Keith Davis3201eea2019-10-24 17:30:41 +0100503 BOOST_CHECK_THROW(profilingState12.TransitionToState(ProfilingState::Active), armnn::Exception);
Nikhil Raj3ecc5102019-09-03 15:55:33 +0100504
505 ProfilingStateMachine profilingState13(ProfilingState::WaitingForAck);
Keith Davis3201eea2019-10-24 17:30:41 +0100506 BOOST_CHECK_THROW(profilingState13.TransitionToState(ProfilingState::Uninitialised), armnn::Exception);
Nikhil Raj3ecc5102019-09-03 15:55:33 +0100507
508 ProfilingStateMachine profilingState14(ProfilingState::WaitingForAck);
Jim Flynn53e46992019-10-14 12:31:10 +0100509 profilingState14.TransitionToState(ProfilingState::NotConnected);
510 BOOST_CHECK(profilingState14.GetCurrentState() == ProfilingState::NotConnected);
Nikhil Raj3ecc5102019-09-03 15:55:33 +0100511
512 ProfilingStateMachine profilingState15(ProfilingState::Active);
Keith Davis3201eea2019-10-24 17:30:41 +0100513 BOOST_CHECK_THROW(profilingState15.TransitionToState(ProfilingState::Uninitialised), armnn::Exception);
Nikhil Raj3ecc5102019-09-03 15:55:33 +0100514
515 ProfilingStateMachine profilingState16(armnn::profiling::ProfilingState::Active);
Keith Davis3201eea2019-10-24 17:30:41 +0100516 BOOST_CHECK_THROW(profilingState16.TransitionToState(ProfilingState::WaitingForAck), armnn::Exception);
Nikhil Raj3ecc5102019-09-03 15:55:33 +0100517
518 ProfilingStateMachine profilingState17(ProfilingState::Uninitialised);
519
Keith Davis3201eea2019-10-24 17:30:41 +0100520 std::thread thread1(ProfilingCurrentStateThreadImpl, std::ref(profilingState17));
521 std::thread thread2(ProfilingCurrentStateThreadImpl, std::ref(profilingState17));
522 std::thread thread3(ProfilingCurrentStateThreadImpl, std::ref(profilingState17));
523 std::thread thread4(ProfilingCurrentStateThreadImpl, std::ref(profilingState17));
524 std::thread thread5(ProfilingCurrentStateThreadImpl, std::ref(profilingState17));
Nikhil Raj3ecc5102019-09-03 15:55:33 +0100525
526 thread1.join();
527 thread2.join();
528 thread3.join();
529 thread4.join();
530 thread5.join();
531
532 BOOST_TEST((profilingState17.GetCurrentState() == ProfilingState::NotConnected));
533}
Aron Virginas-Tare898db92019-08-22 12:56:34 +0100534
Jim Flynn8355ec92019-09-17 12:29:50 +0100535void CaptureDataWriteThreadImpl(Holder& holder, uint32_t capturePeriod, const std::vector<uint16_t>& counterIds)
Francis Murtagh68f78d82019-09-04 16:42:29 +0100536{
537 holder.SetCaptureData(capturePeriod, counterIds);
538}
539
Francis Murtaghbd707162019-09-09 11:26:44 +0100540void CaptureDataReadThreadImpl(const Holder& holder, CaptureData& captureData)
Francis Murtagh68f78d82019-09-04 16:42:29 +0100541{
542 captureData = holder.GetCaptureData();
543}
544
545BOOST_AUTO_TEST_CASE(CheckCaptureDataHolder)
546{
Francis Murtaghbd707162019-09-09 11:26:44 +0100547 std::map<uint32_t, std::vector<uint16_t>> periodIdMap;
548 std::vector<uint16_t> counterIds;
Jim Flynn8355ec92019-09-17 12:29:50 +0100549 uint32_t numThreads = 10;
550 for (uint32_t i = 0; i < numThreads; ++i)
Francis Murtaghbd707162019-09-09 11:26:44 +0100551 {
552 counterIds.emplace_back(i);
553 periodIdMap.insert(std::make_pair(i, counterIds));
554 }
Francis Murtagh68f78d82019-09-04 16:42:29 +0100555
Jim Flynn8355ec92019-09-17 12:29:50 +0100556 // Verify the read and write threads set the holder correctly
557 // and retrieve the expected values
Francis Murtagh68f78d82019-09-04 16:42:29 +0100558 Holder holder;
559 BOOST_CHECK((holder.GetCaptureData()).GetCapturePeriod() == 0);
560 BOOST_CHECK(((holder.GetCaptureData()).GetCounterIds()).empty());
561
562 // Check Holder functions
Francis Murtaghbd707162019-09-09 11:26:44 +0100563 std::thread thread1(CaptureDataWriteThreadImpl, std::ref(holder), 2, std::ref(periodIdMap[2]));
Francis Murtagh68f78d82019-09-04 16:42:29 +0100564 thread1.join();
Francis Murtaghbd707162019-09-09 11:26:44 +0100565 BOOST_CHECK((holder.GetCaptureData()).GetCapturePeriod() == 2);
566 BOOST_CHECK((holder.GetCaptureData()).GetCounterIds() == periodIdMap[2]);
Jim Flynn8355ec92019-09-17 12:29:50 +0100567 // NOTE: now that we have some initial values in the holder we don't have to worry
568 // in the multi-threaded section below about a read thread accessing the holder
569 // before any write thread has gotten to it so we read period = 0, counterIds empty
570 // instead of period = 0, counterIds = {0} as will the case when write thread 0
571 // has executed.
Francis Murtagh68f78d82019-09-04 16:42:29 +0100572
573 CaptureData captureData;
574 std::thread thread2(CaptureDataReadThreadImpl, std::ref(holder), std::ref(captureData));
575 thread2.join();
Jim Flynn8355ec92019-09-17 12:29:50 +0100576 BOOST_CHECK(captureData.GetCapturePeriod() == 2);
Francis Murtaghbd707162019-09-09 11:26:44 +0100577 BOOST_CHECK(captureData.GetCounterIds() == periodIdMap[2]);
Francis Murtagh68f78d82019-09-04 16:42:29 +0100578
Jim Flynn8355ec92019-09-17 12:29:50 +0100579 std::map<uint32_t, CaptureData> captureDataIdMap;
580 for (uint32_t i = 0; i < numThreads; ++i)
581 {
582 CaptureData perThreadCaptureData;
583 captureDataIdMap.insert(std::make_pair(i, perThreadCaptureData));
584 }
585
Francis Murtaghbd707162019-09-09 11:26:44 +0100586 std::vector<std::thread> threadsVect;
Jim Flynn8355ec92019-09-17 12:29:50 +0100587 std::vector<std::thread> readThreadsVect;
588 for (uint32_t i = 0; i < numThreads; ++i)
Francis Murtaghbd707162019-09-09 11:26:44 +0100589 {
Keith Davis3201eea2019-10-24 17:30:41 +0100590 threadsVect.emplace_back(
591 std::thread(CaptureDataWriteThreadImpl, std::ref(holder), i, std::ref(periodIdMap[i])));
Francis Murtagh06965692019-09-05 16:29:01 +0100592
Jim Flynn8355ec92019-09-17 12:29:50 +0100593 // Verify that the CaptureData goes into the thread in a virgin state
594 BOOST_CHECK(captureDataIdMap.at(i).GetCapturePeriod() == 0);
595 BOOST_CHECK(captureDataIdMap.at(i).GetCounterIds().empty());
Keith Davis3201eea2019-10-24 17:30:41 +0100596 readThreadsVect.emplace_back(
597 std::thread(CaptureDataReadThreadImpl, std::ref(holder), std::ref(captureDataIdMap.at(i))));
Francis Murtaghbd707162019-09-09 11:26:44 +0100598 }
599
Jim Flynn8355ec92019-09-17 12:29:50 +0100600 for (uint32_t i = 0; i < numThreads; ++i)
Francis Murtaghbd707162019-09-09 11:26:44 +0100601 {
602 threadsVect[i].join();
Francis Murtaghbd707162019-09-09 11:26:44 +0100603 readThreadsVect[i].join();
604 }
Francis Murtagh68f78d82019-09-04 16:42:29 +0100605
Jim Flynn8355ec92019-09-17 12:29:50 +0100606 // Look at the CaptureData that each read thread has filled
607 // the capture period it read should match the counter ids entry
608 for (uint32_t i = 0; i < numThreads; ++i)
609 {
610 CaptureData perThreadCaptureData = captureDataIdMap.at(i);
611 BOOST_CHECK(perThreadCaptureData.GetCounterIds() == periodIdMap.at(perThreadCaptureData.GetCapturePeriod()));
612 }
Matthew Bentham46d1c622019-09-13 12:45:04 +0100613}
Francis Murtagh68f78d82019-09-04 16:42:29 +0100614
Matthew Bentham46d1c622019-09-13 12:45:04 +0100615BOOST_AUTO_TEST_CASE(CaptureDataMethods)
616{
Jim Flynn8355ec92019-09-17 12:29:50 +0100617 // Check CaptureData setter and getter functions
Keith Davis3201eea2019-10-24 17:30:41 +0100618 std::vector<uint16_t> counterIds = { 42, 29, 13 };
Jim Flynn8355ec92019-09-17 12:29:50 +0100619 CaptureData captureData;
620 BOOST_CHECK(captureData.GetCapturePeriod() == 0);
621 BOOST_CHECK((captureData.GetCounterIds()).empty());
622 captureData.SetCapturePeriod(150);
623 captureData.SetCounterIds(counterIds);
624 BOOST_CHECK(captureData.GetCapturePeriod() == 150);
625 BOOST_CHECK(captureData.GetCounterIds() == counterIds);
Francis Murtagh68f78d82019-09-04 16:42:29 +0100626
Jim Flynn8355ec92019-09-17 12:29:50 +0100627 // Check assignment operator
Francis Murtagh68f78d82019-09-04 16:42:29 +0100628 CaptureData secondCaptureData;
Francis Murtagh68f78d82019-09-04 16:42:29 +0100629
Jim Flynn8355ec92019-09-17 12:29:50 +0100630 secondCaptureData = captureData;
631 BOOST_CHECK(secondCaptureData.GetCapturePeriod() == 150);
Matthew Bentham46d1c622019-09-13 12:45:04 +0100632 BOOST_CHECK(secondCaptureData.GetCounterIds() == counterIds);
Francis Murtagh68f78d82019-09-04 16:42:29 +0100633
634 // Check copy constructor
Jim Flynn8355ec92019-09-17 12:29:50 +0100635 CaptureData copyConstructedCaptureData(captureData);
Francis Murtagh68f78d82019-09-04 16:42:29 +0100636
Jim Flynn8355ec92019-09-17 12:29:50 +0100637 BOOST_CHECK(copyConstructedCaptureData.GetCapturePeriod() == 150);
Matthew Bentham46d1c622019-09-13 12:45:04 +0100638 BOOST_CHECK(copyConstructedCaptureData.GetCounterIds() == counterIds);
Keith Davis02356de2019-08-26 18:28:17 +0100639}
Francis Murtagh68f78d82019-09-04 16:42:29 +0100640
Keith Davis02356de2019-08-26 18:28:17 +0100641BOOST_AUTO_TEST_CASE(CheckProfilingServiceDisabled)
642{
643 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
Matteo Martincigha84edee2019-10-02 12:50:57 +0100644 ProfilingService& profilingService = ProfilingService::Instance();
645 profilingService.ResetExternalProfilingOptions(options, true);
646 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
Matteo Martincigh54fb9572019-10-02 12:50:57 +0100647 profilingService.Update();
Matteo Martincigha84edee2019-10-02 12:50:57 +0100648 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
Keith Davis02356de2019-08-26 18:28:17 +0100649}
650
FinnWilliamsArmce2d9d12019-09-18 10:28:16 +0100651BOOST_AUTO_TEST_CASE(CheckProfilingServiceCounterDirectory)
652{
653 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
Matteo Martincigha84edee2019-10-02 12:50:57 +0100654 ProfilingService& profilingService = ProfilingService::Instance();
655 profilingService.ResetExternalProfilingOptions(options, true);
FinnWilliamsArmce2d9d12019-09-18 10:28:16 +0100656
Matteo Martincigha84edee2019-10-02 12:50:57 +0100657 const ICounterDirectory& counterDirectory0 = profilingService.GetCounterDirectory();
FinnWilliamsArmce2d9d12019-09-18 10:28:16 +0100658 BOOST_CHECK(counterDirectory0.GetCounterCount() == 0);
Matteo Martincigh54fb9572019-10-02 12:50:57 +0100659 profilingService.Update();
660 BOOST_CHECK(counterDirectory0.GetCounterCount() == 0);
FinnWilliamsArmce2d9d12019-09-18 10:28:16 +0100661
662 options.m_EnableProfiling = true;
Matteo Martincigha84edee2019-10-02 12:50:57 +0100663 profilingService.ResetExternalProfilingOptions(options);
FinnWilliamsArmce2d9d12019-09-18 10:28:16 +0100664
Matteo Martincigha84edee2019-10-02 12:50:57 +0100665 const ICounterDirectory& counterDirectory1 = profilingService.GetCounterDirectory();
Matteo Martincigh54fb9572019-10-02 12:50:57 +0100666 BOOST_CHECK(counterDirectory1.GetCounterCount() == 0);
667 profilingService.Update();
FinnWilliamsArmce2d9d12019-09-18 10:28:16 +0100668 BOOST_CHECK(counterDirectory1.GetCounterCount() != 0);
Colm Donelan2ba48d22019-11-29 09:10:59 +0000669 // Reset the profiling service to stop any running thread
670 options.m_EnableProfiling = false;
671 profilingService.ResetExternalProfilingOptions(options, true);
FinnWilliamsArmce2d9d12019-09-18 10:28:16 +0100672}
673
FinnWilliamsArmf6e534a2019-09-16 15:45:42 +0100674BOOST_AUTO_TEST_CASE(CheckProfilingServiceCounterValues)
675{
676 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
Keith Davis3201eea2019-10-24 17:30:41 +0100677 options.m_EnableProfiling = true;
Matteo Martincigha84edee2019-10-02 12:50:57 +0100678 ProfilingService& profilingService = ProfilingService::Instance();
679 profilingService.ResetExternalProfilingOptions(options, true);
680
Matteo Martincigh54fb9572019-10-02 12:50:57 +0100681 profilingService.Update();
Matteo Martincigha84edee2019-10-02 12:50:57 +0100682 const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory();
Keith Davis3201eea2019-10-24 17:30:41 +0100683 const Counters& counters = counterDirectory.GetCounters();
Matteo Martincigha84edee2019-10-02 12:50:57 +0100684 BOOST_CHECK(!counters.empty());
685
Keith Davise394bd92019-12-02 15:12:19 +0000686 // Get the UID of the first counter for testing;
FinnWilliamsArmf6e534a2019-09-16 15:45:42 +0100687
688 ProfilingService* profilingServicePtr = &profilingService;
689 std::vector<std::thread> writers;
690
Keith Davis3201eea2019-10-24 17:30:41 +0100691 for (int i = 0; i < 100; ++i)
FinnWilliamsArmf6e534a2019-09-16 15:45:42 +0100692 {
Matteo Martincigha84edee2019-10-02 12:50:57 +0100693 // Increment and decrement the first counter
Keith Davise394bd92019-12-02 15:12:19 +0000694 writers.push_back(std::thread(&ProfilingService::IncrementCounterValue,
695 profilingServicePtr,
696 armnn::profiling::REGISTERED_BACKENDS));
697
698 writers.push_back(std::thread(&ProfilingService::IncrementCounterValue,
699 profilingServicePtr,
700 armnn::profiling::UNREGISTERED_BACKENDS));
701
Matteo Martincigha84edee2019-10-02 12:50:57 +0100702 // Add 10 and subtract 5 from the first counter
Keith Davise394bd92019-12-02 15:12:19 +0000703 writers.push_back(std::thread(&ProfilingService::AddCounterValue,
704 profilingServicePtr,
705 armnn::profiling::INFERENCES_RUN,
706 10));
707 writers.push_back(std::thread(&ProfilingService::SubtractCounterValue,
708 profilingServicePtr,
709 armnn::profiling::INFERENCES_RUN,
710 5));
FinnWilliamsArmf6e534a2019-09-16 15:45:42 +0100711 }
FinnWilliamsArmf6e534a2019-09-16 15:45:42 +0100712 std::for_each(writers.begin(), writers.end(), mem_fn(&std::thread::join));
713
Matteo Martincigha84edee2019-10-02 12:50:57 +0100714 uint32_t counterValue = 0;
Keith Davise394bd92019-12-02 15:12:19 +0000715 BOOST_CHECK(counterValue ==
716 (profilingService.GetCounterValue(armnn::profiling::UNREGISTERED_BACKENDS)
717 - profilingService.GetCounterValue(armnn::profiling::REGISTERED_BACKENDS)));
718 BOOST_CHECK(profilingService.GetCounterValue(armnn::profiling::INFERENCES_RUN) == 500);
FinnWilliamsArmf6e534a2019-09-16 15:45:42 +0100719
Keith Davise394bd92019-12-02 15:12:19 +0000720 BOOST_CHECK_NO_THROW(profilingService.SetCounterValue(armnn::profiling::UNREGISTERED_BACKENDS, 4));
721 BOOST_CHECK_NO_THROW(counterValue = profilingService.GetCounterValue(armnn::profiling::UNREGISTERED_BACKENDS));
722 BOOST_CHECK(counterValue == 4);
Colm Donelan2ba48d22019-11-29 09:10:59 +0000723 // Reset the profiling service to stop any running thread
724 options.m_EnableProfiling = false;
725 profilingService.ResetExternalProfilingOptions(options, true);
FinnWilliamsArmf6e534a2019-09-16 15:45:42 +0100726}
727
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100728BOOST_AUTO_TEST_CASE(CheckProfilingObjectUids)
Matteo Martincighab173e92019-09-05 12:02:04 +0100729{
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100730 uint16_t uid = 0;
731 BOOST_CHECK_NO_THROW(uid = GetNextUid());
732 BOOST_CHECK(uid >= 1);
733
734 uint16_t nextUid = 0;
735 BOOST_CHECK_NO_THROW(nextUid = GetNextUid());
736 BOOST_CHECK(nextUid > uid);
737
738 std::vector<uint16_t> counterUids;
Keith Davise394bd92019-12-02 15:12:19 +0000739 BOOST_CHECK_NO_THROW(counterUids = GetNextCounterUids(uid,0));
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100740 BOOST_CHECK(counterUids.size() == 1);
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100741
742 std::vector<uint16_t> nextCounterUids;
Keith Davise394bd92019-12-02 15:12:19 +0000743 BOOST_CHECK_NO_THROW(nextCounterUids = GetNextCounterUids(nextUid, 2));
744 BOOST_CHECK(nextCounterUids.size() == 2);
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100745 BOOST_CHECK(nextCounterUids[0] > counterUids[0]);
746
747 std::vector<uint16_t> counterUidsMultiCore;
Keith Davise394bd92019-12-02 15:12:19 +0000748 uint16_t thirdUid = 4;
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100749 uint16_t numberOfCores = 13;
Keith Davise394bd92019-12-02 15:12:19 +0000750 BOOST_CHECK_NO_THROW(counterUidsMultiCore = GetNextCounterUids(thirdUid, numberOfCores));
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100751 BOOST_CHECK(counterUidsMultiCore.size() == numberOfCores);
752 BOOST_CHECK(counterUidsMultiCore.front() >= nextCounterUids[0]);
Keith Davis3201eea2019-10-24 17:30:41 +0100753 for (size_t i = 1; i < numberOfCores; i++)
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100754 {
755 BOOST_CHECK(counterUidsMultiCore[i] == counterUidsMultiCore[i - 1] + 1);
756 }
757 BOOST_CHECK(counterUidsMultiCore.back() == counterUidsMultiCore.front() + numberOfCores - 1);
Matteo Martincighab173e92019-09-05 12:02:04 +0100758}
759
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100760BOOST_AUTO_TEST_CASE(CheckCounterDirectoryRegisterCategory)
Matteo Martincighab173e92019-09-05 12:02:04 +0100761{
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100762 CounterDirectory counterDirectory;
Keith Davis3201eea2019-10-24 17:30:41 +0100763 BOOST_CHECK(counterDirectory.GetCategoryCount() == 0);
764 BOOST_CHECK(counterDirectory.GetDeviceCount() == 0);
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100765 BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0);
Keith Davis3201eea2019-10-24 17:30:41 +0100766 BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
Matteo Martincighab173e92019-09-05 12:02:04 +0100767
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100768 // Register a category with an invalid name
769 const Category* noCategory = nullptr;
770 BOOST_CHECK_THROW(noCategory = counterDirectory.RegisterCategory(""), armnn::InvalidArgumentException);
771 BOOST_CHECK(counterDirectory.GetCategoryCount() == 0);
772 BOOST_CHECK(!noCategory);
Matteo Martincighab173e92019-09-05 12:02:04 +0100773
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100774 // Register a category with an invalid name
775 BOOST_CHECK_THROW(noCategory = counterDirectory.RegisterCategory("invalid category"),
776 armnn::InvalidArgumentException);
777 BOOST_CHECK(counterDirectory.GetCategoryCount() == 0);
778 BOOST_CHECK(!noCategory);
779
780 // Register a new category
781 const std::string categoryName = "some_category";
Keith Davis3201eea2019-10-24 17:30:41 +0100782 const Category* category = nullptr;
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100783 BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName));
784 BOOST_CHECK(counterDirectory.GetCategoryCount() == 1);
785 BOOST_CHECK(category);
786 BOOST_CHECK(category->m_Name == categoryName);
787 BOOST_CHECK(category->m_Counters.empty());
788 BOOST_CHECK(category->m_DeviceUid == 0);
789 BOOST_CHECK(category->m_CounterSetUid == 0);
790
791 // Get the registered category
792 const Category* registeredCategory = counterDirectory.GetCategory(categoryName);
793 BOOST_CHECK(counterDirectory.GetCategoryCount() == 1);
794 BOOST_CHECK(registeredCategory);
795 BOOST_CHECK(registeredCategory == category);
796
797 // Try to get a category not registered
798 const Category* notRegisteredCategory = counterDirectory.GetCategory("not_registered_category");
799 BOOST_CHECK(counterDirectory.GetCategoryCount() == 1);
800 BOOST_CHECK(!notRegisteredCategory);
801
802 // Register a category already registered
803 const Category* anotherCategory = nullptr;
804 BOOST_CHECK_THROW(anotherCategory = counterDirectory.RegisterCategory(categoryName),
805 armnn::InvalidArgumentException);
806 BOOST_CHECK(counterDirectory.GetCategoryCount() == 1);
807 BOOST_CHECK(!anotherCategory);
808
809 // Register a device for testing
810 const std::string deviceName = "some_device";
Keith Davis3201eea2019-10-24 17:30:41 +0100811 const Device* device = nullptr;
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100812 BOOST_CHECK_NO_THROW(device = counterDirectory.RegisterDevice(deviceName));
813 BOOST_CHECK(counterDirectory.GetDeviceCount() == 1);
814 BOOST_CHECK(device);
815 BOOST_CHECK(device->m_Uid >= 1);
816 BOOST_CHECK(device->m_Name == deviceName);
817 BOOST_CHECK(device->m_Cores == 0);
818
819 // Register a new category not associated to any device
820 const std::string categoryWoDeviceName = "some_category_without_device";
Keith Davis3201eea2019-10-24 17:30:41 +0100821 const Category* categoryWoDevice = nullptr;
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100822 BOOST_CHECK_NO_THROW(categoryWoDevice = counterDirectory.RegisterCategory(categoryWoDeviceName, 0));
823 BOOST_CHECK(counterDirectory.GetCategoryCount() == 2);
824 BOOST_CHECK(categoryWoDevice);
825 BOOST_CHECK(categoryWoDevice->m_Name == categoryWoDeviceName);
826 BOOST_CHECK(categoryWoDevice->m_Counters.empty());
827 BOOST_CHECK(categoryWoDevice->m_DeviceUid == 0);
828 BOOST_CHECK(categoryWoDevice->m_CounterSetUid == 0);
829
830 // Register a new category associated to an invalid device
831 const std::string categoryWInvalidDeviceName = "some_category_with_invalid_device";
832
833 ARMNN_NO_CONVERSION_WARN_BEGIN
834 uint16_t invalidDeviceUid = device->m_Uid + 10;
835 ARMNN_NO_CONVERSION_WARN_END
836
837 const Category* categoryWInvalidDevice = nullptr;
Keith Davis3201eea2019-10-24 17:30:41 +0100838 BOOST_CHECK_THROW(categoryWInvalidDevice =
839 counterDirectory.RegisterCategory(categoryWInvalidDeviceName, invalidDeviceUid),
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100840 armnn::InvalidArgumentException);
841 BOOST_CHECK(counterDirectory.GetCategoryCount() == 2);
842 BOOST_CHECK(!categoryWInvalidDevice);
843
844 // Register a new category associated to a valid device
845 const std::string categoryWValidDeviceName = "some_category_with_valid_device";
Keith Davis3201eea2019-10-24 17:30:41 +0100846 const Category* categoryWValidDevice = nullptr;
847 BOOST_CHECK_NO_THROW(categoryWValidDevice =
848 counterDirectory.RegisterCategory(categoryWValidDeviceName, device->m_Uid));
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100849 BOOST_CHECK(counterDirectory.GetCategoryCount() == 3);
850 BOOST_CHECK(categoryWValidDevice);
851 BOOST_CHECK(categoryWValidDevice != category);
852 BOOST_CHECK(categoryWValidDevice->m_Name == categoryWValidDeviceName);
853 BOOST_CHECK(categoryWValidDevice->m_DeviceUid == device->m_Uid);
854 BOOST_CHECK(categoryWValidDevice->m_CounterSetUid == 0);
855
856 // Register a counter set for testing
857 const std::string counterSetName = "some_counter_set";
Keith Davis3201eea2019-10-24 17:30:41 +0100858 const CounterSet* counterSet = nullptr;
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100859 BOOST_CHECK_NO_THROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName));
860 BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1);
861 BOOST_CHECK(counterSet);
862 BOOST_CHECK(counterSet->m_Uid >= 1);
863 BOOST_CHECK(counterSet->m_Name == counterSetName);
864 BOOST_CHECK(counterSet->m_Count == 0);
865
866 // Register a new category not associated to any counter set
867 const std::string categoryWoCounterSetName = "some_category_without_counter_set";
Keith Davis3201eea2019-10-24 17:30:41 +0100868 const Category* categoryWoCounterSet = nullptr;
869 BOOST_CHECK_NO_THROW(categoryWoCounterSet =
870 counterDirectory.RegisterCategory(categoryWoCounterSetName, armnn::EmptyOptional(), 0));
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100871 BOOST_CHECK(counterDirectory.GetCategoryCount() == 4);
872 BOOST_CHECK(categoryWoCounterSet);
873 BOOST_CHECK(categoryWoCounterSet->m_Name == categoryWoCounterSetName);
874 BOOST_CHECK(categoryWoCounterSet->m_DeviceUid == 0);
875 BOOST_CHECK(categoryWoCounterSet->m_CounterSetUid == 0);
876
877 // Register a new category associated to an invalid counter set
878 const std::string categoryWInvalidCounterSetName = "some_category_with_invalid_counter_set";
879
880 ARMNN_NO_CONVERSION_WARN_BEGIN
881 uint16_t invalidCunterSetUid = counterSet->m_Uid + 10;
882 ARMNN_NO_CONVERSION_WARN_END
883
884 const Category* categoryWInvalidCounterSet = nullptr;
Keith Davis3201eea2019-10-24 17:30:41 +0100885 BOOST_CHECK_THROW(categoryWInvalidCounterSet = counterDirectory.RegisterCategory(
886 categoryWInvalidCounterSetName, armnn::EmptyOptional(), invalidCunterSetUid),
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100887 armnn::InvalidArgumentException);
888 BOOST_CHECK(counterDirectory.GetCategoryCount() == 4);
889 BOOST_CHECK(!categoryWInvalidCounterSet);
890
891 // Register a new category associated to a valid counter set
892 const std::string categoryWValidCounterSetName = "some_category_with_valid_counter_set";
Keith Davis3201eea2019-10-24 17:30:41 +0100893 const Category* categoryWValidCounterSet = nullptr;
894 BOOST_CHECK_NO_THROW(categoryWValidCounterSet = counterDirectory.RegisterCategory(
895 categoryWValidCounterSetName, armnn::EmptyOptional(), counterSet->m_Uid));
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100896 BOOST_CHECK(counterDirectory.GetCategoryCount() == 5);
897 BOOST_CHECK(categoryWValidCounterSet);
898 BOOST_CHECK(categoryWValidCounterSet != category);
899 BOOST_CHECK(categoryWValidCounterSet->m_Name == categoryWValidCounterSetName);
900 BOOST_CHECK(categoryWValidCounterSet->m_DeviceUid == 0);
901 BOOST_CHECK(categoryWValidCounterSet->m_CounterSetUid == counterSet->m_Uid);
902
903 // Register a new category associated to a valid device and counter set
904 const std::string categoryWValidDeviceAndValidCounterSetName = "some_category_with_valid_device_and_counter_set";
Keith Davis3201eea2019-10-24 17:30:41 +0100905 const Category* categoryWValidDeviceAndValidCounterSet = nullptr;
906 BOOST_CHECK_NO_THROW(categoryWValidDeviceAndValidCounterSet = counterDirectory.RegisterCategory(
907 categoryWValidDeviceAndValidCounterSetName, device->m_Uid, counterSet->m_Uid));
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100908 BOOST_CHECK(counterDirectory.GetCategoryCount() == 6);
909 BOOST_CHECK(categoryWValidDeviceAndValidCounterSet);
910 BOOST_CHECK(categoryWValidDeviceAndValidCounterSet != category);
911 BOOST_CHECK(categoryWValidDeviceAndValidCounterSet->m_Name == categoryWValidDeviceAndValidCounterSetName);
912 BOOST_CHECK(categoryWValidDeviceAndValidCounterSet->m_DeviceUid == device->m_Uid);
913 BOOST_CHECK(categoryWValidDeviceAndValidCounterSet->m_CounterSetUid == counterSet->m_Uid);
914}
915
916BOOST_AUTO_TEST_CASE(CheckCounterDirectoryRegisterDevice)
917{
918 CounterDirectory counterDirectory;
Keith Davis3201eea2019-10-24 17:30:41 +0100919 BOOST_CHECK(counterDirectory.GetCategoryCount() == 0);
920 BOOST_CHECK(counterDirectory.GetDeviceCount() == 0);
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100921 BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0);
Keith Davis3201eea2019-10-24 17:30:41 +0100922 BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100923
924 // Register a device with an invalid name
925 const Device* noDevice = nullptr;
926 BOOST_CHECK_THROW(noDevice = counterDirectory.RegisterDevice(""), armnn::InvalidArgumentException);
927 BOOST_CHECK(counterDirectory.GetDeviceCount() == 0);
928 BOOST_CHECK(!noDevice);
929
930 // Register a device with an invalid name
931 BOOST_CHECK_THROW(noDevice = counterDirectory.RegisterDevice("inv@lid nam€"), armnn::InvalidArgumentException);
932 BOOST_CHECK(counterDirectory.GetDeviceCount() == 0);
933 BOOST_CHECK(!noDevice);
934
935 // Register a new device with no cores or parent category
936 const std::string deviceName = "some_device";
Keith Davis3201eea2019-10-24 17:30:41 +0100937 const Device* device = nullptr;
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100938 BOOST_CHECK_NO_THROW(device = counterDirectory.RegisterDevice(deviceName));
939 BOOST_CHECK(counterDirectory.GetDeviceCount() == 1);
940 BOOST_CHECK(device);
941 BOOST_CHECK(device->m_Name == deviceName);
942 BOOST_CHECK(device->m_Uid >= 1);
943 BOOST_CHECK(device->m_Cores == 0);
944
Matteo Martincigh657ab2d2019-09-18 10:53:24 +0100945 // Try getting an unregistered device
946 const Device* unregisteredDevice = counterDirectory.GetDevice(9999);
947 BOOST_CHECK(!unregisteredDevice);
948
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100949 // Get the registered device
950 const Device* registeredDevice = counterDirectory.GetDevice(device->m_Uid);
951 BOOST_CHECK(counterDirectory.GetDeviceCount() == 1);
952 BOOST_CHECK(registeredDevice);
953 BOOST_CHECK(registeredDevice == device);
954
Matteo Martincigh657ab2d2019-09-18 10:53:24 +0100955 // Register a device with the name of a device already registered
956 const Device* deviceSameName = nullptr;
957 BOOST_CHECK_THROW(deviceSameName = counterDirectory.RegisterDevice(deviceName), armnn::InvalidArgumentException);
958 BOOST_CHECK(counterDirectory.GetDeviceCount() == 1);
959 BOOST_CHECK(!deviceSameName);
960
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100961 // Register a new device with cores and no parent category
962 const std::string deviceWCoresName = "some_device_with_cores";
Keith Davis3201eea2019-10-24 17:30:41 +0100963 const Device* deviceWCores = nullptr;
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100964 BOOST_CHECK_NO_THROW(deviceWCores = counterDirectory.RegisterDevice(deviceWCoresName, 2));
965 BOOST_CHECK(counterDirectory.GetDeviceCount() == 2);
966 BOOST_CHECK(deviceWCores);
967 BOOST_CHECK(deviceWCores->m_Name == deviceWCoresName);
968 BOOST_CHECK(deviceWCores->m_Uid >= 1);
969 BOOST_CHECK(deviceWCores->m_Uid > device->m_Uid);
970 BOOST_CHECK(deviceWCores->m_Cores == 2);
971
972 // Get the registered device
973 const Device* registeredDeviceWCores = counterDirectory.GetDevice(deviceWCores->m_Uid);
974 BOOST_CHECK(counterDirectory.GetDeviceCount() == 2);
975 BOOST_CHECK(registeredDeviceWCores);
976 BOOST_CHECK(registeredDeviceWCores == deviceWCores);
977 BOOST_CHECK(registeredDeviceWCores != device);
978
979 // Register a new device with cores and invalid parent category
980 const std::string deviceWCoresWInvalidParentCategoryName = "some_device_with_cores_with_invalid_parent_category";
Keith Davis3201eea2019-10-24 17:30:41 +0100981 const Device* deviceWCoresWInvalidParentCategory = nullptr;
982 BOOST_CHECK_THROW(deviceWCoresWInvalidParentCategory =
983 counterDirectory.RegisterDevice(deviceWCoresWInvalidParentCategoryName, 3, std::string("")),
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100984 armnn::InvalidArgumentException);
985 BOOST_CHECK(counterDirectory.GetDeviceCount() == 2);
986 BOOST_CHECK(!deviceWCoresWInvalidParentCategory);
987
988 // Register a new device with cores and invalid parent category
989 const std::string deviceWCoresWInvalidParentCategoryName2 = "some_device_with_cores_with_invalid_parent_category2";
Keith Davis3201eea2019-10-24 17:30:41 +0100990 const Device* deviceWCoresWInvalidParentCategory2 = nullptr;
991 BOOST_CHECK_THROW(deviceWCoresWInvalidParentCategory2 = counterDirectory.RegisterDevice(
992 deviceWCoresWInvalidParentCategoryName2, 3, std::string("invalid_parent_category")),
Matteo Martincigh6db5f202019-09-05 12:02:04 +0100993 armnn::InvalidArgumentException);
994 BOOST_CHECK(counterDirectory.GetDeviceCount() == 2);
995 BOOST_CHECK(!deviceWCoresWInvalidParentCategory2);
996
997 // Register a category for testing
998 const std::string categoryName = "some_category";
Keith Davis3201eea2019-10-24 17:30:41 +0100999 const Category* category = nullptr;
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001000 BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName));
1001 BOOST_CHECK(counterDirectory.GetCategoryCount() == 1);
1002 BOOST_CHECK(category);
1003 BOOST_CHECK(category->m_Name == categoryName);
1004 BOOST_CHECK(category->m_Counters.empty());
1005 BOOST_CHECK(category->m_DeviceUid == 0);
1006 BOOST_CHECK(category->m_CounterSetUid == 0);
1007
1008 // Register a new device with cores and valid parent category
1009 const std::string deviceWCoresWValidParentCategoryName = "some_device_with_cores_with_valid_parent_category";
Keith Davis3201eea2019-10-24 17:30:41 +01001010 const Device* deviceWCoresWValidParentCategory = nullptr;
1011 BOOST_CHECK_NO_THROW(deviceWCoresWValidParentCategory =
1012 counterDirectory.RegisterDevice(deviceWCoresWValidParentCategoryName, 4, categoryName));
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001013 BOOST_CHECK(counterDirectory.GetDeviceCount() == 3);
1014 BOOST_CHECK(deviceWCoresWValidParentCategory);
1015 BOOST_CHECK(deviceWCoresWValidParentCategory->m_Name == deviceWCoresWValidParentCategoryName);
1016 BOOST_CHECK(deviceWCoresWValidParentCategory->m_Uid >= 1);
1017 BOOST_CHECK(deviceWCoresWValidParentCategory->m_Uid > device->m_Uid);
1018 BOOST_CHECK(deviceWCoresWValidParentCategory->m_Uid > deviceWCores->m_Uid);
1019 BOOST_CHECK(deviceWCoresWValidParentCategory->m_Cores == 4);
1020 BOOST_CHECK(category->m_DeviceUid == deviceWCoresWValidParentCategory->m_Uid);
Matteo Martincigh657ab2d2019-09-18 10:53:24 +01001021
1022 // Register a device associated to a category already associated to a different device
1023 const std::string deviceSameCategoryName = "some_device_with_invalid_parent_category";
Keith Davis3201eea2019-10-24 17:30:41 +01001024 const Device* deviceSameCategory = nullptr;
Matteo Martincigh657ab2d2019-09-18 10:53:24 +01001025 BOOST_CHECK_THROW(deviceSameCategory = counterDirectory.RegisterDevice(deviceSameCategoryName, 0, categoryName),
1026 armnn::InvalidArgumentException);
1027 BOOST_CHECK(counterDirectory.GetDeviceCount() == 3);
1028 BOOST_CHECK(!deviceSameCategory);
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001029}
1030
1031BOOST_AUTO_TEST_CASE(CheckCounterDirectoryRegisterCounterSet)
1032{
1033 CounterDirectory counterDirectory;
Keith Davis3201eea2019-10-24 17:30:41 +01001034 BOOST_CHECK(counterDirectory.GetCategoryCount() == 0);
1035 BOOST_CHECK(counterDirectory.GetDeviceCount() == 0);
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001036 BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0);
Keith Davis3201eea2019-10-24 17:30:41 +01001037 BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001038
1039 // Register a counter set with an invalid name
1040 const CounterSet* noCounterSet = nullptr;
1041 BOOST_CHECK_THROW(noCounterSet = counterDirectory.RegisterCounterSet(""), armnn::InvalidArgumentException);
1042 BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0);
1043 BOOST_CHECK(!noCounterSet);
1044
1045 // Register a counter set with an invalid name
1046 BOOST_CHECK_THROW(noCounterSet = counterDirectory.RegisterCounterSet("invalid name"),
1047 armnn::InvalidArgumentException);
1048 BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0);
1049 BOOST_CHECK(!noCounterSet);
1050
1051 // Register a new counter set with no count or parent category
1052 const std::string counterSetName = "some_counter_set";
Keith Davis3201eea2019-10-24 17:30:41 +01001053 const CounterSet* counterSet = nullptr;
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001054 BOOST_CHECK_NO_THROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName));
1055 BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1);
1056 BOOST_CHECK(counterSet);
1057 BOOST_CHECK(counterSet->m_Name == counterSetName);
1058 BOOST_CHECK(counterSet->m_Uid >= 1);
1059 BOOST_CHECK(counterSet->m_Count == 0);
1060
Matteo Martincigh657ab2d2019-09-18 10:53:24 +01001061 // Try getting an unregistered counter set
1062 const CounterSet* unregisteredCounterSet = counterDirectory.GetCounterSet(9999);
1063 BOOST_CHECK(!unregisteredCounterSet);
1064
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001065 // Get the registered counter set
1066 const CounterSet* registeredCounterSet = counterDirectory.GetCounterSet(counterSet->m_Uid);
1067 BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1);
1068 BOOST_CHECK(registeredCounterSet);
1069 BOOST_CHECK(registeredCounterSet == counterSet);
1070
Matteo Martincigh657ab2d2019-09-18 10:53:24 +01001071 // Register a counter set with the name of a counter set already registered
1072 const CounterSet* counterSetSameName = nullptr;
1073 BOOST_CHECK_THROW(counterSetSameName = counterDirectory.RegisterCounterSet(counterSetName),
1074 armnn::InvalidArgumentException);
1075 BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1);
1076 BOOST_CHECK(!counterSetSameName);
1077
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001078 // Register a new counter set with count and no parent category
1079 const std::string counterSetWCountName = "some_counter_set_with_count";
Keith Davis3201eea2019-10-24 17:30:41 +01001080 const CounterSet* counterSetWCount = nullptr;
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001081 BOOST_CHECK_NO_THROW(counterSetWCount = counterDirectory.RegisterCounterSet(counterSetWCountName, 37));
1082 BOOST_CHECK(counterDirectory.GetCounterSetCount() == 2);
1083 BOOST_CHECK(counterSetWCount);
1084 BOOST_CHECK(counterSetWCount->m_Name == counterSetWCountName);
1085 BOOST_CHECK(counterSetWCount->m_Uid >= 1);
1086 BOOST_CHECK(counterSetWCount->m_Uid > counterSet->m_Uid);
1087 BOOST_CHECK(counterSetWCount->m_Count == 37);
1088
1089 // Get the registered counter set
1090 const CounterSet* registeredCounterSetWCount = counterDirectory.GetCounterSet(counterSetWCount->m_Uid);
1091 BOOST_CHECK(counterDirectory.GetCounterSetCount() == 2);
1092 BOOST_CHECK(registeredCounterSetWCount);
1093 BOOST_CHECK(registeredCounterSetWCount == counterSetWCount);
1094 BOOST_CHECK(registeredCounterSetWCount != counterSet);
1095
1096 // Register a new counter set with count and invalid parent category
1097 const std::string counterSetWCountWInvalidParentCategoryName = "some_counter_set_with_count_"
1098 "with_invalid_parent_category";
1099 const CounterSet* counterSetWCountWInvalidParentCategory = nullptr;
Keith Davis3201eea2019-10-24 17:30:41 +01001100 BOOST_CHECK_THROW(counterSetWCountWInvalidParentCategory = counterDirectory.RegisterCounterSet(
1101 counterSetWCountWInvalidParentCategoryName, 42, std::string("")),
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001102 armnn::InvalidArgumentException);
1103 BOOST_CHECK(counterDirectory.GetCounterSetCount() == 2);
1104 BOOST_CHECK(!counterSetWCountWInvalidParentCategory);
1105
1106 // Register a new counter set with count and invalid parent category
1107 const std::string counterSetWCountWInvalidParentCategoryName2 = "some_counter_set_with_count_"
1108 "with_invalid_parent_category2";
1109 const CounterSet* counterSetWCountWInvalidParentCategory2 = nullptr;
Keith Davis3201eea2019-10-24 17:30:41 +01001110 BOOST_CHECK_THROW(counterSetWCountWInvalidParentCategory2 = counterDirectory.RegisterCounterSet(
1111 counterSetWCountWInvalidParentCategoryName2, 42, std::string("invalid_parent_category")),
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001112 armnn::InvalidArgumentException);
1113 BOOST_CHECK(counterDirectory.GetCounterSetCount() == 2);
1114 BOOST_CHECK(!counterSetWCountWInvalidParentCategory2);
1115
1116 // Register a category for testing
1117 const std::string categoryName = "some_category";
Keith Davis3201eea2019-10-24 17:30:41 +01001118 const Category* category = nullptr;
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001119 BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName));
1120 BOOST_CHECK(counterDirectory.GetCategoryCount() == 1);
1121 BOOST_CHECK(category);
1122 BOOST_CHECK(category->m_Name == categoryName);
1123 BOOST_CHECK(category->m_Counters.empty());
1124 BOOST_CHECK(category->m_DeviceUid == 0);
1125 BOOST_CHECK(category->m_CounterSetUid == 0);
1126
1127 // Register a new counter set with count and valid parent category
1128 const std::string counterSetWCountWValidParentCategoryName = "some_counter_set_with_count_"
1129 "with_valid_parent_category";
1130 const CounterSet* counterSetWCountWValidParentCategory = nullptr;
Keith Davis3201eea2019-10-24 17:30:41 +01001131 BOOST_CHECK_NO_THROW(counterSetWCountWValidParentCategory = counterDirectory.RegisterCounterSet(
1132 counterSetWCountWValidParentCategoryName, 42, categoryName));
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001133 BOOST_CHECK(counterDirectory.GetCounterSetCount() == 3);
1134 BOOST_CHECK(counterSetWCountWValidParentCategory);
1135 BOOST_CHECK(counterSetWCountWValidParentCategory->m_Name == counterSetWCountWValidParentCategoryName);
1136 BOOST_CHECK(counterSetWCountWValidParentCategory->m_Uid >= 1);
1137 BOOST_CHECK(counterSetWCountWValidParentCategory->m_Uid > counterSet->m_Uid);
1138 BOOST_CHECK(counterSetWCountWValidParentCategory->m_Uid > counterSetWCount->m_Uid);
1139 BOOST_CHECK(counterSetWCountWValidParentCategory->m_Count == 42);
1140 BOOST_CHECK(category->m_CounterSetUid == counterSetWCountWValidParentCategory->m_Uid);
Matteo Martincigh657ab2d2019-09-18 10:53:24 +01001141
1142 // Register a counter set associated to a category already associated to a different counter set
1143 const std::string counterSetSameCategoryName = "some_counter_set_with_invalid_parent_category";
Keith Davis3201eea2019-10-24 17:30:41 +01001144 const CounterSet* counterSetSameCategory = nullptr;
1145 BOOST_CHECK_THROW(counterSetSameCategory =
1146 counterDirectory.RegisterCounterSet(counterSetSameCategoryName, 0, categoryName),
Matteo Martincigh657ab2d2019-09-18 10:53:24 +01001147 armnn::InvalidArgumentException);
1148 BOOST_CHECK(counterDirectory.GetCounterSetCount() == 3);
1149 BOOST_CHECK(!counterSetSameCategory);
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001150}
1151
1152BOOST_AUTO_TEST_CASE(CheckCounterDirectoryRegisterCounter)
1153{
1154 CounterDirectory counterDirectory;
Keith Davis3201eea2019-10-24 17:30:41 +01001155 BOOST_CHECK(counterDirectory.GetCategoryCount() == 0);
1156 BOOST_CHECK(counterDirectory.GetDeviceCount() == 0);
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001157 BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0);
Keith Davis3201eea2019-10-24 17:30:41 +01001158 BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001159
1160 // Register a counter with an invalid parent category name
1161 const Counter* noCounter = nullptr;
Keith Davis3201eea2019-10-24 17:30:41 +01001162 BOOST_CHECK_THROW(noCounter =
Keith Davise394bd92019-12-02 15:12:19 +00001163 counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1164 0,
1165 "",
1166 0,
1167 1,
1168 123.45f,
1169 "valid ",
1170 "name"),
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001171 armnn::InvalidArgumentException);
1172 BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1173 BOOST_CHECK(!noCounter);
1174
1175 // Register a counter with an invalid parent category name
Keith Davise394bd92019-12-02 15:12:19 +00001176 BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1177 1,
1178 "invalid parent category",
1179 0,
1180 1,
1181 123.45f,
1182 "valid name",
1183 "valid description"),
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001184 armnn::InvalidArgumentException);
1185 BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1186 BOOST_CHECK(!noCounter);
1187
1188 // Register a counter with an invalid class
Keith Davise394bd92019-12-02 15:12:19 +00001189 BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1190 2,
1191 "valid_parent_category",
1192 2,
1193 1,
1194 123.45f,
1195 "valid "
1196 "name",
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001197 "valid description"),
1198 armnn::InvalidArgumentException);
1199 BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1200 BOOST_CHECK(!noCounter);
1201
1202 // Register a counter with an invalid interpolation
Keith Davise394bd92019-12-02 15:12:19 +00001203 BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1204 4,
1205 "valid_parent_category",
1206 0,
1207 3,
1208 123.45f,
1209 "valid "
1210 "name",
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001211 "valid description"),
1212 armnn::InvalidArgumentException);
1213 BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1214 BOOST_CHECK(!noCounter);
1215
1216 // Register a counter with an invalid multiplier
Keith Davise394bd92019-12-02 15:12:19 +00001217 BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1218 5,
1219 "valid_parent_category",
1220 0,
1221 1,
1222 .0f,
1223 "valid "
1224 "name",
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001225 "valid description"),
1226 armnn::InvalidArgumentException);
1227 BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1228 BOOST_CHECK(!noCounter);
1229
1230 // Register a counter with an invalid name
Keith Davis3201eea2019-10-24 17:30:41 +01001231 BOOST_CHECK_THROW(
Keith Davise394bd92019-12-02 15:12:19 +00001232 noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1233 6,
1234 "valid_parent_category",
1235 0,
1236 1,
1237 123.45f,
1238 "",
1239 "valid description"),
Keith Davis3201eea2019-10-24 17:30:41 +01001240 armnn::InvalidArgumentException);
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001241 BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1242 BOOST_CHECK(!noCounter);
1243
1244 // Register a counter with an invalid name
Keith Davise394bd92019-12-02 15:12:19 +00001245 BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1246 7,
1247 "valid_parent_category",
1248 0,
1249 1,
1250 123.45f,
1251 "invalid nam€",
1252 "valid description"),
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001253 armnn::InvalidArgumentException);
1254 BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1255 BOOST_CHECK(!noCounter);
1256
1257 // Register a counter with an invalid description
Keith Davis3201eea2019-10-24 17:30:41 +01001258 BOOST_CHECK_THROW(noCounter =
Keith Davise394bd92019-12-02 15:12:19 +00001259 counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1260 8,
1261 "valid_parent_category",
1262 0,
1263 1,
1264 123.45f,
1265 "valid name",
1266 ""),
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001267 armnn::InvalidArgumentException);
1268 BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1269 BOOST_CHECK(!noCounter);
1270
1271 // Register a counter with an invalid description
Keith Davise394bd92019-12-02 15:12:19 +00001272 BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1273 9,
1274 "valid_parent_category",
1275 0,
1276 1,
1277 123.45f,
1278 "valid "
1279 "name",
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001280 "inv@lid description"),
1281 armnn::InvalidArgumentException);
1282 BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1283 BOOST_CHECK(!noCounter);
1284
1285 // Register a counter with an invalid unit2
Keith Davise394bd92019-12-02 15:12:19 +00001286 BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1287 10,
1288 "valid_parent_category",
1289 0,
1290 1,
1291 123.45f,
1292 "valid name",
1293 "valid description",
1294 std::string("Mb/s2")),
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001295 armnn::InvalidArgumentException);
1296 BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1297 BOOST_CHECK(!noCounter);
1298
1299 // Register a counter with a non-existing parent category name
Keith Davise394bd92019-12-02 15:12:19 +00001300 BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1301 11,
1302 "invalid_parent_category",
1303 0,
1304 1,
1305 123.45f,
1306 "valid name",
1307 "valid description"),
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001308 armnn::InvalidArgumentException);
1309 BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1310 BOOST_CHECK(!noCounter);
1311
Matteo Martincigh657ab2d2019-09-18 10:53:24 +01001312 // Try getting an unregistered counter
1313 const Counter* unregisteredCounter = counterDirectory.GetCounter(9999);
1314 BOOST_CHECK(!unregisteredCounter);
1315
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001316 // Register a category for testing
1317 const std::string categoryName = "some_category";
Keith Davis3201eea2019-10-24 17:30:41 +01001318 const Category* category = nullptr;
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001319 BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName));
1320 BOOST_CHECK(counterDirectory.GetCategoryCount() == 1);
1321 BOOST_CHECK(category);
1322 BOOST_CHECK(category->m_Name == categoryName);
1323 BOOST_CHECK(category->m_Counters.empty());
1324 BOOST_CHECK(category->m_DeviceUid == 0);
1325 BOOST_CHECK(category->m_CounterSetUid == 0);
1326
1327 // Register a counter with a valid parent category name
1328 const Counter* counter = nullptr;
Keith Davis3201eea2019-10-24 17:30:41 +01001329 BOOST_CHECK_NO_THROW(
Keith Davise394bd92019-12-02 15:12:19 +00001330 counter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1331 12,
1332 categoryName,
1333 0,
1334 1,
1335 123.45f,
1336 "valid name",
1337 "valid description"));
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001338 BOOST_CHECK(counterDirectory.GetCounterCount() == 1);
1339 BOOST_CHECK(counter);
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001340 BOOST_CHECK(counter->m_MaxCounterUid == counter->m_Uid);
1341 BOOST_CHECK(counter->m_Class == 0);
1342 BOOST_CHECK(counter->m_Interpolation == 1);
1343 BOOST_CHECK(counter->m_Multiplier == 123.45f);
1344 BOOST_CHECK(counter->m_Name == "valid name");
1345 BOOST_CHECK(counter->m_Description == "valid description");
1346 BOOST_CHECK(counter->m_Units == "");
1347 BOOST_CHECK(counter->m_DeviceUid == 0);
1348 BOOST_CHECK(counter->m_CounterSetUid == 0);
1349 BOOST_CHECK(category->m_Counters.size() == 1);
1350 BOOST_CHECK(category->m_Counters.back() == counter->m_Uid);
1351
Matteo Martincigh657ab2d2019-09-18 10:53:24 +01001352 // Register a counter with a name of a counter already registered for the given parent category name
1353 const Counter* counterSameName = nullptr;
Keith Davis3201eea2019-10-24 17:30:41 +01001354 BOOST_CHECK_THROW(counterSameName =
Keith Davise394bd92019-12-02 15:12:19 +00001355 counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1356 13,
1357 categoryName,
1358 0,
1359 0,
1360 1.0f,
1361 "valid name",
1362 "valid description",
1363 std::string("description")),
Matteo Martincigh657ab2d2019-09-18 10:53:24 +01001364 armnn::InvalidArgumentException);
1365 BOOST_CHECK(counterDirectory.GetCounterCount() == 1);
1366 BOOST_CHECK(!counterSameName);
1367
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001368 // Register a counter with a valid parent category name and units
1369 const Counter* counterWUnits = nullptr;
Keith Davise394bd92019-12-02 15:12:19 +00001370 BOOST_CHECK_NO_THROW(counterWUnits = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1371 14,
1372 categoryName,
1373 0,
1374 1,
1375 123.45f,
1376 "valid name 2",
1377 "valid description",
1378 std::string("Mnnsq2"))); // Units
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001379 BOOST_CHECK(counterDirectory.GetCounterCount() == 2);
1380 BOOST_CHECK(counterWUnits);
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001381 BOOST_CHECK(counterWUnits->m_Uid > counter->m_Uid);
1382 BOOST_CHECK(counterWUnits->m_MaxCounterUid == counterWUnits->m_Uid);
1383 BOOST_CHECK(counterWUnits->m_Class == 0);
1384 BOOST_CHECK(counterWUnits->m_Interpolation == 1);
1385 BOOST_CHECK(counterWUnits->m_Multiplier == 123.45f);
1386 BOOST_CHECK(counterWUnits->m_Name == "valid name 2");
1387 BOOST_CHECK(counterWUnits->m_Description == "valid description");
1388 BOOST_CHECK(counterWUnits->m_Units == "Mnnsq2");
1389 BOOST_CHECK(counterWUnits->m_DeviceUid == 0);
1390 BOOST_CHECK(counterWUnits->m_CounterSetUid == 0);
1391 BOOST_CHECK(category->m_Counters.size() == 2);
1392 BOOST_CHECK(category->m_Counters.back() == counterWUnits->m_Uid);
1393
1394 // Register a counter with a valid parent category name and not associated with a device
1395 const Counter* counterWoDevice = nullptr;
Keith Davise394bd92019-12-02 15:12:19 +00001396 BOOST_CHECK_NO_THROW(counterWoDevice = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1397 26,
1398 categoryName,
1399 0,
1400 1,
1401 123.45f,
1402 "valid name 3",
1403 "valid description",
1404 armnn::EmptyOptional(),// Units
1405 armnn::EmptyOptional(),// Number of cores
1406 0)); // Device UID
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001407 BOOST_CHECK(counterDirectory.GetCounterCount() == 3);
1408 BOOST_CHECK(counterWoDevice);
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001409 BOOST_CHECK(counterWoDevice->m_Uid > counter->m_Uid);
1410 BOOST_CHECK(counterWoDevice->m_MaxCounterUid == counterWoDevice->m_Uid);
1411 BOOST_CHECK(counterWoDevice->m_Class == 0);
1412 BOOST_CHECK(counterWoDevice->m_Interpolation == 1);
1413 BOOST_CHECK(counterWoDevice->m_Multiplier == 123.45f);
1414 BOOST_CHECK(counterWoDevice->m_Name == "valid name 3");
1415 BOOST_CHECK(counterWoDevice->m_Description == "valid description");
1416 BOOST_CHECK(counterWoDevice->m_Units == "");
1417 BOOST_CHECK(counterWoDevice->m_DeviceUid == 0);
1418 BOOST_CHECK(counterWoDevice->m_CounterSetUid == 0);
1419 BOOST_CHECK(category->m_Counters.size() == 3);
1420 BOOST_CHECK(category->m_Counters.back() == counterWoDevice->m_Uid);
1421
1422 // Register a counter with a valid parent category name and associated to an invalid device
Keith Davise394bd92019-12-02 15:12:19 +00001423 BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1424 15,
1425 categoryName,
1426 0,
1427 1,
1428 123.45f,
1429 "valid name 4",
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001430 "valid description",
Keith Davis3201eea2019-10-24 17:30:41 +01001431 armnn::EmptyOptional(), // Units
1432 armnn::EmptyOptional(), // Number of cores
1433 100), // Device UID
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001434 armnn::InvalidArgumentException);
1435 BOOST_CHECK(counterDirectory.GetCounterCount() == 3);
1436 BOOST_CHECK(!noCounter);
1437
1438 // Register a device for testing
1439 const std::string deviceName = "some_device";
Keith Davis3201eea2019-10-24 17:30:41 +01001440 const Device* device = nullptr;
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001441 BOOST_CHECK_NO_THROW(device = counterDirectory.RegisterDevice(deviceName));
1442 BOOST_CHECK(counterDirectory.GetDeviceCount() == 1);
1443 BOOST_CHECK(device);
1444 BOOST_CHECK(device->m_Name == deviceName);
1445 BOOST_CHECK(device->m_Uid >= 1);
1446 BOOST_CHECK(device->m_Cores == 0);
1447
1448 // Register a counter with a valid parent category name and associated to a device
1449 const Counter* counterWDevice = nullptr;
Keith Davise394bd92019-12-02 15:12:19 +00001450 BOOST_CHECK_NO_THROW(counterWDevice = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1451 16,
1452 categoryName,
1453 0,
1454 1,
1455 123.45f,
1456 "valid name 5",
1457 std::string("valid description"),
Keith Davis3201eea2019-10-24 17:30:41 +01001458 armnn::EmptyOptional(), // Units
1459 armnn::EmptyOptional(), // Number of cores
1460 device->m_Uid)); // Device UID
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001461 BOOST_CHECK(counterDirectory.GetCounterCount() == 4);
1462 BOOST_CHECK(counterWDevice);
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001463 BOOST_CHECK(counterWDevice->m_Uid > counter->m_Uid);
1464 BOOST_CHECK(counterWDevice->m_MaxCounterUid == counterWDevice->m_Uid);
1465 BOOST_CHECK(counterWDevice->m_Class == 0);
1466 BOOST_CHECK(counterWDevice->m_Interpolation == 1);
1467 BOOST_CHECK(counterWDevice->m_Multiplier == 123.45f);
1468 BOOST_CHECK(counterWDevice->m_Name == "valid name 5");
1469 BOOST_CHECK(counterWDevice->m_Description == "valid description");
1470 BOOST_CHECK(counterWDevice->m_Units == "");
1471 BOOST_CHECK(counterWDevice->m_DeviceUid == device->m_Uid);
1472 BOOST_CHECK(counterWDevice->m_CounterSetUid == 0);
1473 BOOST_CHECK(category->m_Counters.size() == 4);
1474 BOOST_CHECK(category->m_Counters.back() == counterWDevice->m_Uid);
1475
1476 // Register a counter with a valid parent category name and not associated with a counter set
1477 const Counter* counterWoCounterSet = nullptr;
Keith Davise394bd92019-12-02 15:12:19 +00001478 BOOST_CHECK_NO_THROW(counterWoCounterSet = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1479 17,
1480 categoryName,
1481 0,
1482 1,
1483 123.45f,
1484 "valid name 6",
1485 "valid description",
1486 armnn::EmptyOptional(),// Units
1487 armnn::EmptyOptional(),// No of cores
1488 armnn::EmptyOptional(),// Device UID
1489 0)); // CounterSet UID
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001490 BOOST_CHECK(counterDirectory.GetCounterCount() == 5);
1491 BOOST_CHECK(counterWoCounterSet);
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001492 BOOST_CHECK(counterWoCounterSet->m_Uid > counter->m_Uid);
1493 BOOST_CHECK(counterWoCounterSet->m_MaxCounterUid == counterWoCounterSet->m_Uid);
1494 BOOST_CHECK(counterWoCounterSet->m_Class == 0);
1495 BOOST_CHECK(counterWoCounterSet->m_Interpolation == 1);
1496 BOOST_CHECK(counterWoCounterSet->m_Multiplier == 123.45f);
1497 BOOST_CHECK(counterWoCounterSet->m_Name == "valid name 6");
1498 BOOST_CHECK(counterWoCounterSet->m_Description == "valid description");
1499 BOOST_CHECK(counterWoCounterSet->m_Units == "");
1500 BOOST_CHECK(counterWoCounterSet->m_DeviceUid == 0);
1501 BOOST_CHECK(counterWoCounterSet->m_CounterSetUid == 0);
1502 BOOST_CHECK(category->m_Counters.size() == 5);
1503 BOOST_CHECK(category->m_Counters.back() == counterWoCounterSet->m_Uid);
1504
1505 // Register a counter with a valid parent category name and associated to an invalid counter set
Keith Davise394bd92019-12-02 15:12:19 +00001506 BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1507 18,
1508 categoryName,
1509 0,
1510 1,
1511 123.45f,
1512 "valid ",
1513 "name 7",
1514 std::string("valid description"),
Keith Davis3201eea2019-10-24 17:30:41 +01001515 armnn::EmptyOptional(), // Units
1516 armnn::EmptyOptional(), // Number of cores
Keith Davise394bd92019-12-02 15:12:19 +00001517 100), // Counter set UID
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001518 armnn::InvalidArgumentException);
1519 BOOST_CHECK(counterDirectory.GetCounterCount() == 5);
1520 BOOST_CHECK(!noCounter);
1521
1522 // Register a counter with a valid parent category name and with a given number of cores
1523 const Counter* counterWNumberOfCores = nullptr;
Keith Davis3201eea2019-10-24 17:30:41 +01001524 uint16_t numberOfCores = 15;
1525 BOOST_CHECK_NO_THROW(counterWNumberOfCores = counterDirectory.RegisterCounter(
Keith Davise394bd92019-12-02 15:12:19 +00001526 armnn::profiling::BACKEND_ID, 50,
Keith Davis3201eea2019-10-24 17:30:41 +01001527 categoryName, 0, 1, 123.45f, "valid name 8", "valid description",
1528 armnn::EmptyOptional(), // Units
1529 numberOfCores, // Number of cores
1530 armnn::EmptyOptional(), // Device UID
1531 armnn::EmptyOptional())); // Counter set UID
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001532 BOOST_CHECK(counterDirectory.GetCounterCount() == 20);
1533 BOOST_CHECK(counterWNumberOfCores);
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001534 BOOST_CHECK(counterWNumberOfCores->m_Uid > counter->m_Uid);
1535 BOOST_CHECK(counterWNumberOfCores->m_MaxCounterUid == counterWNumberOfCores->m_Uid + numberOfCores - 1);
1536 BOOST_CHECK(counterWNumberOfCores->m_Class == 0);
1537 BOOST_CHECK(counterWNumberOfCores->m_Interpolation == 1);
1538 BOOST_CHECK(counterWNumberOfCores->m_Multiplier == 123.45f);
1539 BOOST_CHECK(counterWNumberOfCores->m_Name == "valid name 8");
1540 BOOST_CHECK(counterWNumberOfCores->m_Description == "valid description");
1541 BOOST_CHECK(counterWNumberOfCores->m_Units == "");
1542 BOOST_CHECK(counterWNumberOfCores->m_DeviceUid == 0);
1543 BOOST_CHECK(counterWNumberOfCores->m_CounterSetUid == 0);
1544 BOOST_CHECK(category->m_Counters.size() == 20);
Keith Davis3201eea2019-10-24 17:30:41 +01001545 for (size_t i = 0; i < numberOfCores; i++)
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001546 {
1547 BOOST_CHECK(category->m_Counters[category->m_Counters.size() - numberOfCores + i] ==
1548 counterWNumberOfCores->m_Uid + i);
1549 }
1550
1551 // Register a multi-core device for testing
1552 const std::string multiCoreDeviceName = "some_multi_core_device";
Keith Davis3201eea2019-10-24 17:30:41 +01001553 const Device* multiCoreDevice = nullptr;
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001554 BOOST_CHECK_NO_THROW(multiCoreDevice = counterDirectory.RegisterDevice(multiCoreDeviceName, 4));
1555 BOOST_CHECK(counterDirectory.GetDeviceCount() == 2);
1556 BOOST_CHECK(multiCoreDevice);
1557 BOOST_CHECK(multiCoreDevice->m_Name == multiCoreDeviceName);
1558 BOOST_CHECK(multiCoreDevice->m_Uid >= 1);
1559 BOOST_CHECK(multiCoreDevice->m_Cores == 4);
1560
1561 // Register a counter with a valid parent category name and associated to the multi-core device
1562 const Counter* counterWMultiCoreDevice = nullptr;
Keith Davis3201eea2019-10-24 17:30:41 +01001563 BOOST_CHECK_NO_THROW(counterWMultiCoreDevice = counterDirectory.RegisterCounter(
Keith Davise394bd92019-12-02 15:12:19 +00001564 armnn::profiling::BACKEND_ID, 19, categoryName, 0, 1,
1565 123.45f, "valid name 9", "valid description",
Keith Davis3201eea2019-10-24 17:30:41 +01001566 armnn::EmptyOptional(), // Units
1567 armnn::EmptyOptional(), // Number of cores
1568 multiCoreDevice->m_Uid, // Device UID
1569 armnn::EmptyOptional())); // Counter set UID
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001570 BOOST_CHECK(counterDirectory.GetCounterCount() == 24);
1571 BOOST_CHECK(counterWMultiCoreDevice);
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001572 BOOST_CHECK(counterWMultiCoreDevice->m_Uid > counter->m_Uid);
1573 BOOST_CHECK(counterWMultiCoreDevice->m_MaxCounterUid ==
1574 counterWMultiCoreDevice->m_Uid + multiCoreDevice->m_Cores - 1);
1575 BOOST_CHECK(counterWMultiCoreDevice->m_Class == 0);
1576 BOOST_CHECK(counterWMultiCoreDevice->m_Interpolation == 1);
1577 BOOST_CHECK(counterWMultiCoreDevice->m_Multiplier == 123.45f);
1578 BOOST_CHECK(counterWMultiCoreDevice->m_Name == "valid name 9");
1579 BOOST_CHECK(counterWMultiCoreDevice->m_Description == "valid description");
1580 BOOST_CHECK(counterWMultiCoreDevice->m_Units == "");
1581 BOOST_CHECK(counterWMultiCoreDevice->m_DeviceUid == multiCoreDevice->m_Uid);
1582 BOOST_CHECK(counterWMultiCoreDevice->m_CounterSetUid == 0);
1583 BOOST_CHECK(category->m_Counters.size() == 24);
Keith Davis3201eea2019-10-24 17:30:41 +01001584 for (size_t i = 0; i < 4; i++)
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001585 {
1586 BOOST_CHECK(category->m_Counters[category->m_Counters.size() - 4 + i] == counterWMultiCoreDevice->m_Uid + i);
1587 }
1588
Matteo Martincigh657ab2d2019-09-18 10:53:24 +01001589 // Register a multi-core device associate to a parent category for testing
1590 const std::string multiCoreDeviceNameWParentCategory = "some_multi_core_device_with_parent_category";
Keith Davis3201eea2019-10-24 17:30:41 +01001591 const Device* multiCoreDeviceWParentCategory = nullptr;
Matteo Martincigh657ab2d2019-09-18 10:53:24 +01001592 BOOST_CHECK_NO_THROW(multiCoreDeviceWParentCategory =
Keith Davis3201eea2019-10-24 17:30:41 +01001593 counterDirectory.RegisterDevice(multiCoreDeviceNameWParentCategory, 2, categoryName));
Matteo Martincigh657ab2d2019-09-18 10:53:24 +01001594 BOOST_CHECK(counterDirectory.GetDeviceCount() == 3);
1595 BOOST_CHECK(multiCoreDeviceWParentCategory);
1596 BOOST_CHECK(multiCoreDeviceWParentCategory->m_Name == multiCoreDeviceNameWParentCategory);
1597 BOOST_CHECK(multiCoreDeviceWParentCategory->m_Uid >= 1);
1598 BOOST_CHECK(multiCoreDeviceWParentCategory->m_Cores == 2);
1599
1600 // Register a counter with a valid parent category name and getting the number of cores of the multi-core device
1601 // associated to that category
1602 const Counter* counterWMultiCoreDeviceWParentCategory = nullptr;
Keith Davise394bd92019-12-02 15:12:19 +00001603 BOOST_CHECK_NO_THROW(counterWMultiCoreDeviceWParentCategory =
1604 counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1605 100,
1606 categoryName,
1607 0,
1608 1,
1609 123.45f,
1610 "valid name 10",
1611 "valid description",
1612 armnn::EmptyOptional(),// Units
1613 armnn::EmptyOptional(),// Number of cores
1614 armnn::EmptyOptional(),// Device UID
1615 armnn::EmptyOptional()));// Counter set UID
Matteo Martincigh657ab2d2019-09-18 10:53:24 +01001616 BOOST_CHECK(counterDirectory.GetCounterCount() == 26);
1617 BOOST_CHECK(counterWMultiCoreDeviceWParentCategory);
Matteo Martincigh657ab2d2019-09-18 10:53:24 +01001618 BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Uid > counter->m_Uid);
1619 BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_MaxCounterUid ==
1620 counterWMultiCoreDeviceWParentCategory->m_Uid + multiCoreDeviceWParentCategory->m_Cores - 1);
1621 BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Class == 0);
1622 BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Interpolation == 1);
1623 BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Multiplier == 123.45f);
1624 BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Name == "valid name 10");
1625 BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Description == "valid description");
1626 BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Units == "");
1627 BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_DeviceUid == 0);
1628 BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_CounterSetUid == 0);
1629 BOOST_CHECK(category->m_Counters.size() == 26);
Keith Davis3201eea2019-10-24 17:30:41 +01001630 for (size_t i = 0; i < 2; i++)
Matteo Martincigh657ab2d2019-09-18 10:53:24 +01001631 {
1632 BOOST_CHECK(category->m_Counters[category->m_Counters.size() - 2 + i] ==
1633 counterWMultiCoreDeviceWParentCategory->m_Uid + i);
1634 }
1635
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001636 // Register a counter set for testing
1637 const std::string counterSetName = "some_counter_set";
Keith Davis3201eea2019-10-24 17:30:41 +01001638 const CounterSet* counterSet = nullptr;
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001639 BOOST_CHECK_NO_THROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName));
1640 BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1);
1641 BOOST_CHECK(counterSet);
1642 BOOST_CHECK(counterSet->m_Name == counterSetName);
1643 BOOST_CHECK(counterSet->m_Uid >= 1);
1644 BOOST_CHECK(counterSet->m_Count == 0);
1645
1646 // Register a counter with a valid parent category name and associated to a counter set
1647 const Counter* counterWCounterSet = nullptr;
Keith Davis3201eea2019-10-24 17:30:41 +01001648 BOOST_CHECK_NO_THROW(counterWCounterSet = counterDirectory.RegisterCounter(
Keith Davise394bd92019-12-02 15:12:19 +00001649 armnn::profiling::BACKEND_ID, 300,
Keith Davis3201eea2019-10-24 17:30:41 +01001650 categoryName, 0, 1, 123.45f, "valid name 11", "valid description",
1651 armnn::EmptyOptional(), // Units
1652 0, // Number of cores
1653 armnn::EmptyOptional(), // Device UID
1654 counterSet->m_Uid)); // Counter set UID
Matteo Martincigh657ab2d2019-09-18 10:53:24 +01001655 BOOST_CHECK(counterDirectory.GetCounterCount() == 27);
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001656 BOOST_CHECK(counterWCounterSet);
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001657 BOOST_CHECK(counterWCounterSet->m_Uid > counter->m_Uid);
1658 BOOST_CHECK(counterWCounterSet->m_MaxCounterUid == counterWCounterSet->m_Uid);
1659 BOOST_CHECK(counterWCounterSet->m_Class == 0);
1660 BOOST_CHECK(counterWCounterSet->m_Interpolation == 1);
1661 BOOST_CHECK(counterWCounterSet->m_Multiplier == 123.45f);
Matteo Martincigh657ab2d2019-09-18 10:53:24 +01001662 BOOST_CHECK(counterWCounterSet->m_Name == "valid name 11");
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001663 BOOST_CHECK(counterWCounterSet->m_Description == "valid description");
1664 BOOST_CHECK(counterWCounterSet->m_Units == "");
1665 BOOST_CHECK(counterWCounterSet->m_DeviceUid == 0);
1666 BOOST_CHECK(counterWCounterSet->m_CounterSetUid == counterSet->m_Uid);
Matteo Martincigh657ab2d2019-09-18 10:53:24 +01001667 BOOST_CHECK(category->m_Counters.size() == 27);
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001668 BOOST_CHECK(category->m_Counters.back() == counterWCounterSet->m_Uid);
1669
1670 // Register a counter with a valid parent category name and associated to a device and a counter set
1671 const Counter* counterWDeviceWCounterSet = nullptr;
Keith Davis3201eea2019-10-24 17:30:41 +01001672 BOOST_CHECK_NO_THROW(counterWDeviceWCounterSet = counterDirectory.RegisterCounter(
Keith Davise394bd92019-12-02 15:12:19 +00001673 armnn::profiling::BACKEND_ID, 23,
Keith Davis3201eea2019-10-24 17:30:41 +01001674 categoryName, 0, 1, 123.45f, "valid name 12", "valid description",
1675 armnn::EmptyOptional(), // Units
1676 1, // Number of cores
1677 device->m_Uid, // Device UID
1678 counterSet->m_Uid)); // Counter set UID
Matteo Martincigh657ab2d2019-09-18 10:53:24 +01001679 BOOST_CHECK(counterDirectory.GetCounterCount() == 28);
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001680 BOOST_CHECK(counterWDeviceWCounterSet);
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001681 BOOST_CHECK(counterWDeviceWCounterSet->m_Uid > counter->m_Uid);
1682 BOOST_CHECK(counterWDeviceWCounterSet->m_MaxCounterUid == counterWDeviceWCounterSet->m_Uid);
1683 BOOST_CHECK(counterWDeviceWCounterSet->m_Class == 0);
1684 BOOST_CHECK(counterWDeviceWCounterSet->m_Interpolation == 1);
1685 BOOST_CHECK(counterWDeviceWCounterSet->m_Multiplier == 123.45f);
Matteo Martincigh657ab2d2019-09-18 10:53:24 +01001686 BOOST_CHECK(counterWDeviceWCounterSet->m_Name == "valid name 12");
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001687 BOOST_CHECK(counterWDeviceWCounterSet->m_Description == "valid description");
1688 BOOST_CHECK(counterWDeviceWCounterSet->m_Units == "");
1689 BOOST_CHECK(counterWDeviceWCounterSet->m_DeviceUid == device->m_Uid);
1690 BOOST_CHECK(counterWDeviceWCounterSet->m_CounterSetUid == counterSet->m_Uid);
Matteo Martincigh657ab2d2019-09-18 10:53:24 +01001691 BOOST_CHECK(category->m_Counters.size() == 28);
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001692 BOOST_CHECK(category->m_Counters.back() == counterWDeviceWCounterSet->m_Uid);
1693
1694 // Register another category for testing
1695 const std::string anotherCategoryName = "some_other_category";
Keith Davis3201eea2019-10-24 17:30:41 +01001696 const Category* anotherCategory = nullptr;
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001697 BOOST_CHECK_NO_THROW(anotherCategory = counterDirectory.RegisterCategory(anotherCategoryName));
1698 BOOST_CHECK(counterDirectory.GetCategoryCount() == 2);
1699 BOOST_CHECK(anotherCategory);
1700 BOOST_CHECK(anotherCategory != category);
1701 BOOST_CHECK(anotherCategory->m_Name == anotherCategoryName);
1702 BOOST_CHECK(anotherCategory->m_Counters.empty());
1703 BOOST_CHECK(anotherCategory->m_DeviceUid == 0);
1704 BOOST_CHECK(anotherCategory->m_CounterSetUid == 0);
1705
1706 // Register a counter to the other category
1707 const Counter* anotherCounter = nullptr;
Keith Davise394bd92019-12-02 15:12:19 +00001708 BOOST_CHECK_NO_THROW(anotherCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, 24,
1709 anotherCategoryName, 1, 0, .00043f,
Keith Davis3201eea2019-10-24 17:30:41 +01001710 "valid name", "valid description",
1711 armnn::EmptyOptional(), // Units
1712 armnn::EmptyOptional(), // Number of cores
1713 device->m_Uid, // Device UID
1714 counterSet->m_Uid)); // Counter set UID
Matteo Martincigh657ab2d2019-09-18 10:53:24 +01001715 BOOST_CHECK(counterDirectory.GetCounterCount() == 29);
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001716 BOOST_CHECK(anotherCounter);
Matteo Martincigh6db5f202019-09-05 12:02:04 +01001717 BOOST_CHECK(anotherCounter->m_MaxCounterUid == anotherCounter->m_Uid);
1718 BOOST_CHECK(anotherCounter->m_Class == 1);
1719 BOOST_CHECK(anotherCounter->m_Interpolation == 0);
1720 BOOST_CHECK(anotherCounter->m_Multiplier == .00043f);
1721 BOOST_CHECK(anotherCounter->m_Name == "valid name");
1722 BOOST_CHECK(anotherCounter->m_Description == "valid description");
1723 BOOST_CHECK(anotherCounter->m_Units == "");
1724 BOOST_CHECK(anotherCounter->m_DeviceUid == device->m_Uid);
1725 BOOST_CHECK(anotherCounter->m_CounterSetUid == counterSet->m_Uid);
1726 BOOST_CHECK(anotherCategory->m_Counters.size() == 1);
1727 BOOST_CHECK(anotherCategory->m_Counters.back() == anotherCounter->m_Uid);
Matteo Martincighab173e92019-09-05 12:02:04 +01001728}
1729
Ferran Balaguer1b941722019-08-28 16:57:18 +01001730BOOST_AUTO_TEST_CASE(CounterSelectionCommandHandlerParseData)
1731{
1732 using boost::numeric_cast;
1733
Matteo Martincigh5d737fb2019-10-07 13:05:13 +01001734 ProfilingStateMachine profilingStateMachine;
1735
Ferran Balaguer1b941722019-08-28 16:57:18 +01001736 class TestCaptureThread : public IPeriodicCounterCapture
1737 {
Keith Davis3201eea2019-10-24 17:30:41 +01001738 void Start() override
1739 {}
1740 void Stop() override
1741 {}
Ferran Balaguer1b941722019-08-28 16:57:18 +01001742 };
1743
Matteo Martincighe8485382019-10-10 14:08:21 +01001744 class TestReadCounterValues : public IReadCounterValues
1745 {
Keith Davis3201eea2019-10-24 17:30:41 +01001746 bool IsCounterRegistered(uint16_t counterUid) const override
1747 {
Derek Lamberti1dd75b32019-12-10 21:23:23 +00001748 boost::ignore_unused(counterUid);
Keith Davis3201eea2019-10-24 17:30:41 +01001749 return true;
1750 }
1751 uint16_t GetCounterCount() const override
1752 {
1753 return 0;
1754 }
1755 uint32_t GetCounterValue(uint16_t counterUid) const override
1756 {
Derek Lamberti1dd75b32019-12-10 21:23:23 +00001757 boost::ignore_unused(counterUid);
Keith Davis3201eea2019-10-24 17:30:41 +01001758 return 0;
1759 }
Matteo Martincighe8485382019-10-10 14:08:21 +01001760 };
Jim Flynn397043f2019-10-17 17:37:10 +01001761 const uint32_t familyId = 0;
Ferran Balaguer1b941722019-08-28 16:57:18 +01001762 const uint32_t packetId = 0x40000;
1763
1764 uint32_t version = 1;
1765 Holder holder;
1766 TestCaptureThread captureThread;
Matteo Martincighe8485382019-10-10 14:08:21 +01001767 TestReadCounterValues readCounterValues;
Narumol Prangnawarat404b2752019-09-24 17:23:16 +01001768 MockBufferManager mockBuffer(512);
Matteo Martincigh5d737fb2019-10-07 13:05:13 +01001769 SendCounterPacket sendCounterPacket(profilingStateMachine, mockBuffer);
Ferran Balaguer1b941722019-08-28 16:57:18 +01001770
1771 uint32_t sizeOfUint32 = numeric_cast<uint32_t>(sizeof(uint32_t));
1772 uint32_t sizeOfUint16 = numeric_cast<uint32_t>(sizeof(uint16_t));
1773
1774 // Data with period and counters
Colm Donelan02705242019-11-14 14:19:07 +00001775 uint32_t period1 = armnn::LOWEST_CAPTURE_PERIOD;
Ferran Balaguer1b941722019-08-28 16:57:18 +01001776 uint32_t dataLength1 = 8;
Keith Davis3201eea2019-10-24 17:30:41 +01001777 uint32_t offset = 0;
Ferran Balaguer1b941722019-08-28 16:57:18 +01001778
Matteo Martincigh67ef2a52019-10-10 13:29:02 +01001779 std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength1);
Keith Davis3201eea2019-10-24 17:30:41 +01001780 unsigned char* data1 = reinterpret_cast<unsigned char*>(uniqueData1.get());
FinnWilliamsArma0c78712019-09-16 12:06:47 +01001781
Ferran Balaguer1b941722019-08-28 16:57:18 +01001782 WriteUint32(data1, offset, period1);
1783 offset += sizeOfUint32;
1784 WriteUint16(data1, offset, 4000);
1785 offset += sizeOfUint16;
1786 WriteUint16(data1, offset, 5000);
1787
FinnWilliamsArma0c78712019-09-16 12:06:47 +01001788 Packet packetA(packetId, dataLength1, uniqueData1);
Ferran Balaguer1b941722019-08-28 16:57:18 +01001789
Keith Davis3201eea2019-10-24 17:30:41 +01001790 PeriodicCounterSelectionCommandHandler commandHandler(familyId, packetId, version, holder, captureThread,
1791 readCounterValues, sendCounterPacket, profilingStateMachine);
Ferran Balaguer1b941722019-08-28 16:57:18 +01001792
Matteo Martincighe8485382019-10-10 14:08:21 +01001793 profilingStateMachine.TransitionToState(ProfilingState::Uninitialised);
1794 BOOST_CHECK_THROW(commandHandler(packetA), armnn::RuntimeException);
1795 profilingStateMachine.TransitionToState(ProfilingState::NotConnected);
1796 BOOST_CHECK_THROW(commandHandler(packetA), armnn::RuntimeException);
1797 profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck);
1798 BOOST_CHECK_THROW(commandHandler(packetA), armnn::RuntimeException);
1799 profilingStateMachine.TransitionToState(ProfilingState::Active);
1800 BOOST_CHECK_NO_THROW(commandHandler(packetA));
1801
1802 const std::vector<uint16_t> counterIdsA = holder.GetCaptureData().GetCounterIds();
Ferran Balaguer1b941722019-08-28 16:57:18 +01001803
1804 BOOST_TEST(holder.GetCaptureData().GetCapturePeriod() == period1);
Matteo Martincighe8485382019-10-10 14:08:21 +01001805 BOOST_TEST(counterIdsA.size() == 2);
1806 BOOST_TEST(counterIdsA[0] == 4000);
1807 BOOST_TEST(counterIdsA[1] == 5000);
Ferran Balaguer1b941722019-08-28 16:57:18 +01001808
Narumol Prangnawarat404b2752019-09-24 17:23:16 +01001809 auto readBuffer = mockBuffer.GetReadableBuffer();
Ferran Balaguer1b941722019-08-28 16:57:18 +01001810
1811 offset = 0;
1812
1813 uint32_t headerWord0 = ReadUint32(readBuffer, offset);
1814 offset += sizeOfUint32;
1815 uint32_t headerWord1 = ReadUint32(readBuffer, offset);
1816 offset += sizeOfUint32;
1817 uint32_t period = ReadUint32(readBuffer, offset);
1818
Colm Donelan02705242019-11-14 14:19:07 +00001819 BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0); // packet family
1820 BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 4); // packet id
1821 BOOST_TEST(headerWord1 == 8); // data length
1822 BOOST_TEST(period == armnn::LOWEST_CAPTURE_PERIOD); // capture period
Ferran Balaguer1b941722019-08-28 16:57:18 +01001823
1824 uint16_t counterId = 0;
1825 offset += sizeOfUint32;
1826 counterId = ReadUint16(readBuffer, offset);
1827 BOOST_TEST(counterId == 4000);
1828 offset += sizeOfUint16;
1829 counterId = ReadUint16(readBuffer, offset);
1830 BOOST_TEST(counterId == 5000);
1831
Narumol Prangnawarat404b2752019-09-24 17:23:16 +01001832 mockBuffer.MarkRead(readBuffer);
1833
Ferran Balaguer1b941722019-08-28 16:57:18 +01001834 // Data with period only
Colm Donelan02705242019-11-14 14:19:07 +00001835 uint32_t period2 = 9000; // We'll specify a value below LOWEST_CAPTURE_PERIOD. It should be pulled upwards.
Ferran Balaguer1b941722019-08-28 16:57:18 +01001836 uint32_t dataLength2 = 4;
Ferran Balaguer1b941722019-08-28 16:57:18 +01001837
Matteo Martincigh67ef2a52019-10-10 13:29:02 +01001838 std::unique_ptr<unsigned char[]> uniqueData2 = std::make_unique<unsigned char[]>(dataLength2);
Ferran Balaguer1b941722019-08-28 16:57:18 +01001839
FinnWilliamsArma0c78712019-09-16 12:06:47 +01001840 WriteUint32(reinterpret_cast<unsigned char*>(uniqueData2.get()), 0, period2);
1841
1842 Packet packetB(packetId, dataLength2, uniqueData2);
Ferran Balaguer1b941722019-08-28 16:57:18 +01001843
1844 commandHandler(packetB);
1845
Matteo Martincighe8485382019-10-10 14:08:21 +01001846 const std::vector<uint16_t> counterIdsB = holder.GetCaptureData().GetCounterIds();
Ferran Balaguer1b941722019-08-28 16:57:18 +01001847
Colm Donelan02705242019-11-14 14:19:07 +00001848 // Value should have been pulled up from 9000 to LOWEST_CAPTURE_PERIOD.
1849 BOOST_TEST(holder.GetCaptureData().GetCapturePeriod() == armnn::LOWEST_CAPTURE_PERIOD);
Matteo Martincighe8485382019-10-10 14:08:21 +01001850 BOOST_TEST(counterIdsB.size() == 0);
Ferran Balaguer1b941722019-08-28 16:57:18 +01001851
Narumol Prangnawarat404b2752019-09-24 17:23:16 +01001852 readBuffer = mockBuffer.GetReadableBuffer();
Ferran Balaguer1b941722019-08-28 16:57:18 +01001853
1854 offset = 0;
1855
1856 headerWord0 = ReadUint32(readBuffer, offset);
1857 offset += sizeOfUint32;
1858 headerWord1 = ReadUint32(readBuffer, offset);
1859 offset += sizeOfUint32;
1860 period = ReadUint32(readBuffer, offset);
1861
Colm Donelan02705242019-11-14 14:19:07 +00001862 BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0); // packet family
1863 BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 4); // packet id
1864 BOOST_TEST(headerWord1 == 4); // data length
1865 BOOST_TEST(period == armnn::LOWEST_CAPTURE_PERIOD); // capture period
Ferran Balaguer1b941722019-08-28 16:57:18 +01001866}
1867
Sadik Armaganb5f01b22019-09-18 17:29:00 +01001868BOOST_AUTO_TEST_CASE(CheckConnectionAcknowledged)
1869{
1870 using boost::numeric_cast;
1871
Keith Davis3201eea2019-10-24 17:30:41 +01001872 const uint32_t packetFamilyId = 0;
Sadik Armaganb5f01b22019-09-18 17:29:00 +01001873 const uint32_t connectionPacketId = 0x10000;
Keith Davis3201eea2019-10-24 17:30:41 +01001874 const uint32_t version = 1;
Sadik Armaganb5f01b22019-09-18 17:29:00 +01001875
1876 uint32_t sizeOfUint32 = numeric_cast<uint32_t>(sizeof(uint32_t));
1877 uint32_t sizeOfUint16 = numeric_cast<uint32_t>(sizeof(uint16_t));
1878
1879 // Data with period and counters
Keith Davis3201eea2019-10-24 17:30:41 +01001880 uint32_t period1 = 10;
Sadik Armaganb5f01b22019-09-18 17:29:00 +01001881 uint32_t dataLength1 = 8;
Keith Davis3201eea2019-10-24 17:30:41 +01001882 uint32_t offset = 0;
Sadik Armaganb5f01b22019-09-18 17:29:00 +01001883
Matteo Martincigh67ef2a52019-10-10 13:29:02 +01001884 std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength1);
Keith Davis3201eea2019-10-24 17:30:41 +01001885 unsigned char* data1 = reinterpret_cast<unsigned char*>(uniqueData1.get());
Sadik Armaganb5f01b22019-09-18 17:29:00 +01001886
1887 WriteUint32(data1, offset, period1);
1888 offset += sizeOfUint32;
1889 WriteUint16(data1, offset, 4000);
1890 offset += sizeOfUint16;
1891 WriteUint16(data1, offset, 5000);
1892
1893 Packet packetA(connectionPacketId, dataLength1, uniqueData1);
1894
1895 ProfilingStateMachine profilingState(ProfilingState::Uninitialised);
1896 BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::Uninitialised);
Keith Davis3201eea2019-10-24 17:30:41 +01001897 CounterDirectory counterDirectory;
1898 MockBufferManager mockBuffer(1024);
1899 SendCounterPacket sendCounterPacket(profilingState, mockBuffer);
Matteo Martincighcdfb9412019-11-08 11:23:06 +00001900 SendTimelinePacket sendTimelinePacket(mockBuffer);
Sadik Armaganb5f01b22019-09-18 17:29:00 +01001901
Keith Davis3201eea2019-10-24 17:30:41 +01001902 ConnectionAcknowledgedCommandHandler commandHandler(packetFamilyId, connectionPacketId, version, counterDirectory,
Matteo Martincighcdfb9412019-11-08 11:23:06 +00001903 sendCounterPacket, sendTimelinePacket, profilingState);
Sadik Armaganb5f01b22019-09-18 17:29:00 +01001904
1905 // command handler received packet on ProfilingState::Uninitialised
1906 BOOST_CHECK_THROW(commandHandler(packetA), armnn::Exception);
1907
1908 profilingState.TransitionToState(ProfilingState::NotConnected);
1909 BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::NotConnected);
1910 // command handler received packet on ProfilingState::NotConnected
1911 BOOST_CHECK_THROW(commandHandler(packetA), armnn::Exception);
1912
1913 profilingState.TransitionToState(ProfilingState::WaitingForAck);
1914 BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::WaitingForAck);
1915 // command handler received packet on ProfilingState::WaitingForAck
Matteo Martincighd0613b52019-10-09 16:47:04 +01001916 BOOST_CHECK_NO_THROW(commandHandler(packetA));
Sadik Armaganb5f01b22019-09-18 17:29:00 +01001917 BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::Active);
1918
1919 // command handler received packet on ProfilingState::Active
Matteo Martincighd0613b52019-10-09 16:47:04 +01001920 BOOST_CHECK_NO_THROW(commandHandler(packetA));
Sadik Armaganb5f01b22019-09-18 17:29:00 +01001921 BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::Active);
1922
1923 // command handler received different packet
1924 const uint32_t differentPacketId = 0x40000;
1925 Packet packetB(differentPacketId, dataLength1, uniqueData1);
Matteo Martincighd0613b52019-10-09 16:47:04 +01001926 profilingState.TransitionToState(ProfilingState::NotConnected);
1927 profilingState.TransitionToState(ProfilingState::WaitingForAck);
Keith Davis3201eea2019-10-24 17:30:41 +01001928 ConnectionAcknowledgedCommandHandler differentCommandHandler(packetFamilyId, differentPacketId, version,
Matteo Martincighcdfb9412019-11-08 11:23:06 +00001929 counterDirectory, sendCounterPacket,
1930 sendTimelinePacket, profilingState);
Sadik Armaganb5f01b22019-09-18 17:29:00 +01001931 BOOST_CHECK_THROW(differentCommandHandler(packetB), armnn::Exception);
1932}
1933
Teresa Charlin9bab4962019-09-06 12:28:35 +01001934BOOST_AUTO_TEST_CASE(CheckSocketProfilingConnection)
1935{
1936 // Check that creating a SocketProfilingConnection results in an exception as the Gator UDS doesn't exist.
1937 BOOST_CHECK_THROW(new SocketProfilingConnection(), armnn::Exception);
1938}
1939
Matteo Martincigh42f9d9e2019-09-05 12:02:04 +01001940BOOST_AUTO_TEST_CASE(SwTraceIsValidCharTest)
1941{
1942 // Only ASCII 7-bit encoding supported
1943 for (unsigned char c = 0; c < 128; c++)
1944 {
1945 BOOST_CHECK(SwTraceCharPolicy::IsValidChar(c));
1946 }
1947
1948 // Not ASCII
1949 for (unsigned char c = 255; c >= 128; c++)
1950 {
1951 BOOST_CHECK(!SwTraceCharPolicy::IsValidChar(c));
1952 }
1953}
1954
1955BOOST_AUTO_TEST_CASE(SwTraceIsValidNameCharTest)
1956{
1957 // Only alpha-numeric and underscore ASCII 7-bit encoding supported
1958 const unsigned char validChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
1959 for (unsigned char i = 0; i < sizeof(validChars) / sizeof(validChars[0]) - 1; i++)
1960 {
1961 BOOST_CHECK(SwTraceNameCharPolicy::IsValidChar(validChars[i]));
1962 }
1963
1964 // Non alpha-numeric chars
1965 for (unsigned char c = 0; c < 48; c++)
1966 {
1967 BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c));
1968 }
1969 for (unsigned char c = 58; c < 65; c++)
1970 {
1971 BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c));
1972 }
1973 for (unsigned char c = 91; c < 95; c++)
1974 {
1975 BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c));
1976 }
1977 for (unsigned char c = 96; c < 97; c++)
1978 {
1979 BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c));
1980 }
1981 for (unsigned char c = 123; c < 128; c++)
1982 {
1983 BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c));
1984 }
1985
1986 // Not ASCII
1987 for (unsigned char c = 255; c >= 128; c++)
1988 {
1989 BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c));
1990 }
1991}
1992
1993BOOST_AUTO_TEST_CASE(IsValidSwTraceStringTest)
1994{
1995 // Valid SWTrace strings
1996 BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>(""));
1997 BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("_"));
1998 BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("0123"));
1999 BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("valid_string"));
2000 BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("VALID_string_456"));
2001 BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>(" "));
2002 BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("valid string"));
2003 BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("!$%"));
2004 BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("valid|\\~string#123"));
2005
2006 // Invalid SWTrace strings
2007 BOOST_CHECK(!IsValidSwTraceString<SwTraceCharPolicy>("€£"));
2008 BOOST_CHECK(!IsValidSwTraceString<SwTraceCharPolicy>("invalid‡string"));
2009 BOOST_CHECK(!IsValidSwTraceString<SwTraceCharPolicy>("12Ž34"));
2010}
2011
2012BOOST_AUTO_TEST_CASE(IsValidSwTraceNameStringTest)
2013{
2014 // Valid SWTrace name strings
2015 BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>(""));
2016 BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("_"));
2017 BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("0123"));
2018 BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("valid_string"));
2019 BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("VALID_string_456"));
2020
2021 // Invalid SWTrace name strings
2022 BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>(" "));
2023 BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("invalid string"));
2024 BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("!$%"));
2025 BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("invalid|\\~string#123"));
2026 BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("€£"));
2027 BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("invalid‡string"));
2028 BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("12Ž34"));
2029}
2030
2031template <typename SwTracePolicy>
2032void StringToSwTraceStringTestHelper(const std::string& testString, std::vector<uint32_t> buffer, size_t expectedSize)
2033{
2034 // Convert the test string to a SWTrace string
2035 BOOST_CHECK(StringToSwTraceString<SwTracePolicy>(testString, buffer));
2036
2037 // The buffer must contain at least the length of the string
2038 BOOST_CHECK(!buffer.empty());
2039
2040 // The buffer must be of the expected size (in words)
2041 BOOST_CHECK(buffer.size() == expectedSize);
2042
2043 // The first word of the byte must be the length of the string including the null-terminator
2044 BOOST_CHECK(buffer[0] == testString.size() + 1);
2045
2046 // The contents of the buffer must match the test string
2047 BOOST_CHECK(std::memcmp(testString.data(), buffer.data() + 1, testString.size()) == 0);
2048
2049 // The buffer must include the null-terminator at the end of the string
2050 size_t nullTerminatorIndex = sizeof(uint32_t) + testString.size();
Keith Davis3201eea2019-10-24 17:30:41 +01002051 BOOST_CHECK(reinterpret_cast<unsigned char*>(buffer.data())[nullTerminatorIndex] == '\0');
Matteo Martincigh42f9d9e2019-09-05 12:02:04 +01002052}
2053
2054BOOST_AUTO_TEST_CASE(StringToSwTraceStringTest)
2055{
2056 std::vector<uint32_t> buffer;
2057
2058 // Valid SWTrace strings (expected size in words)
2059 StringToSwTraceStringTestHelper<SwTraceCharPolicy>("", buffer, 2);
2060 StringToSwTraceStringTestHelper<SwTraceCharPolicy>("_", buffer, 2);
2061 StringToSwTraceStringTestHelper<SwTraceCharPolicy>("0123", buffer, 3);
2062 StringToSwTraceStringTestHelper<SwTraceCharPolicy>("valid_string", buffer, 5);
2063 StringToSwTraceStringTestHelper<SwTraceCharPolicy>("VALID_string_456", buffer, 6);
2064 StringToSwTraceStringTestHelper<SwTraceCharPolicy>(" ", buffer, 2);
2065 StringToSwTraceStringTestHelper<SwTraceCharPolicy>("valid string", buffer, 5);
2066 StringToSwTraceStringTestHelper<SwTraceCharPolicy>("!$%", buffer, 2);
2067 StringToSwTraceStringTestHelper<SwTraceCharPolicy>("valid|\\~string#123", buffer, 6);
2068
2069 // Invalid SWTrace strings
2070 BOOST_CHECK(!StringToSwTraceString<SwTraceCharPolicy>("€£", buffer));
2071 BOOST_CHECK(buffer.empty());
2072 BOOST_CHECK(!StringToSwTraceString<SwTraceCharPolicy>("invalid‡string", buffer));
2073 BOOST_CHECK(buffer.empty());
2074 BOOST_CHECK(!StringToSwTraceString<SwTraceCharPolicy>("12Ž34", buffer));
2075 BOOST_CHECK(buffer.empty());
2076}
2077
2078BOOST_AUTO_TEST_CASE(StringToSwTraceNameStringTest)
2079{
2080 std::vector<uint32_t> buffer;
2081
2082 // Valid SWTrace namestrings (expected size in words)
2083 StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("", buffer, 2);
2084 StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("_", buffer, 2);
2085 StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("0123", buffer, 3);
2086 StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("valid_string", buffer, 5);
2087 StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("VALID_string_456", buffer, 6);
2088
2089 // Invalid SWTrace namestrings
2090 BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>(" ", buffer));
2091 BOOST_CHECK(buffer.empty());
2092 BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("invalid string", buffer));
2093 BOOST_CHECK(buffer.empty());
2094 BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("!$%", buffer));
2095 BOOST_CHECK(buffer.empty());
2096 BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("invalid|\\~string#123", buffer));
2097 BOOST_CHECK(buffer.empty());
2098 BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("€£", buffer));
2099 BOOST_CHECK(buffer.empty());
2100 BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("invalid‡string", buffer));
2101 BOOST_CHECK(buffer.empty());
2102 BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("12Ž34", buffer));
2103 BOOST_CHECK(buffer.empty());
2104}
2105
Francis Murtaghfcb8ef62019-09-20 15:40:09 +01002106BOOST_AUTO_TEST_CASE(CheckPeriodicCounterCaptureThread)
2107{
Matteo Martincighe0e6efc2019-10-04 17:17:42 +01002108 class CaptureReader : public IReadCounterValues
Francis Murtaghfcb8ef62019-09-20 15:40:09 +01002109 {
2110 public:
Finn Williamsf4d59a62019-10-14 15:55:18 +01002111 CaptureReader(uint16_t counterSize)
2112 {
Keith Davis3201eea2019-10-24 17:30:41 +01002113 for (uint16_t i = 0; i < counterSize; ++i)
Finn Williamsf4d59a62019-10-14 15:55:18 +01002114 {
2115 m_Data[i] = 0;
2116 }
2117 m_CounterSize = counterSize;
2118 }
2119 //not used
Matteo Martincighe8485382019-10-10 14:08:21 +01002120 bool IsCounterRegistered(uint16_t counterUid) const override
2121 {
Derek Lamberti1dd75b32019-12-10 21:23:23 +00002122 boost::ignore_unused(counterUid);
Finn Williamsf4d59a62019-10-14 15:55:18 +01002123 return false;
Matteo Martincighe8485382019-10-10 14:08:21 +01002124 }
2125
Matteo Martincighe0e6efc2019-10-04 17:17:42 +01002126 uint16_t GetCounterCount() const override
Francis Murtaghfcb8ef62019-09-20 15:40:09 +01002127 {
Finn Williamsf4d59a62019-10-14 15:55:18 +01002128 return m_CounterSize;
Matteo Martincighe0e6efc2019-10-04 17:17:42 +01002129 }
2130
Matteo Martincighe8485382019-10-10 14:08:21 +01002131 uint32_t GetCounterValue(uint16_t counterUid) const override
Matteo Martincighe0e6efc2019-10-04 17:17:42 +01002132 {
Keith Davis3201eea2019-10-24 17:30:41 +01002133 if (counterUid > m_CounterSize)
Francis Murtaghfcb8ef62019-09-20 15:40:09 +01002134 {
Finn Williamsf4d59a62019-10-14 15:55:18 +01002135 BOOST_FAIL("Invalid counter Uid");
Francis Murtaghfcb8ef62019-09-20 15:40:09 +01002136 }
Matteo Martincighe8485382019-10-10 14:08:21 +01002137 return m_Data.at(counterUid).load();
Francis Murtaghfcb8ef62019-09-20 15:40:09 +01002138 }
2139
Matteo Martincighe8485382019-10-10 14:08:21 +01002140 void SetCounterValue(uint16_t counterUid, uint32_t value)
Francis Murtaghfcb8ef62019-09-20 15:40:09 +01002141 {
Keith Davis3201eea2019-10-24 17:30:41 +01002142 if (counterUid > m_CounterSize)
Francis Murtaghfcb8ef62019-09-20 15:40:09 +01002143 {
Finn Williamsf4d59a62019-10-14 15:55:18 +01002144 BOOST_FAIL("Invalid counter Uid");
Francis Murtaghfcb8ef62019-09-20 15:40:09 +01002145 }
Finn Williamsf4d59a62019-10-14 15:55:18 +01002146 m_Data.at(counterUid).store(value);
Francis Murtaghfcb8ef62019-09-20 15:40:09 +01002147 }
2148
2149 private:
Matteo Martincighe8485382019-10-10 14:08:21 +01002150 std::unordered_map<uint16_t, std::atomic<uint32_t>> m_Data;
Finn Williamsf4d59a62019-10-14 15:55:18 +01002151 uint16_t m_CounterSize;
Francis Murtaghfcb8ef62019-09-20 15:40:09 +01002152 };
2153
Matteo Martincigh5d737fb2019-10-07 13:05:13 +01002154 ProfilingStateMachine profilingStateMachine;
2155
Francis Murtaghfcb8ef62019-09-20 15:40:09 +01002156 Holder data;
2157 std::vector<uint16_t> captureIds1 = { 0, 1 };
2158 std::vector<uint16_t> captureIds2;
2159
Narumol Prangnawarat404b2752019-09-24 17:23:16 +01002160 MockBufferManager mockBuffer(512);
Matteo Martincigh5d737fb2019-10-07 13:05:13 +01002161 SendCounterPacket sendCounterPacket(profilingStateMachine, mockBuffer);
Francis Murtaghfcb8ef62019-09-20 15:40:09 +01002162
2163 std::vector<uint16_t> counterIds;
Finn Williamsf4d59a62019-10-14 15:55:18 +01002164 CaptureReader captureReader(2);
Francis Murtaghfcb8ef62019-09-20 15:40:09 +01002165
Keith Davis3201eea2019-10-24 17:30:41 +01002166 unsigned int valueA = 10;
2167 unsigned int valueB = 15;
Francis Murtaghfcb8ef62019-09-20 15:40:09 +01002168 unsigned int numSteps = 5;
2169
2170 PeriodicCounterCapture periodicCounterCapture(std::ref(data), std::ref(sendCounterPacket), captureReader);
2171
Matteo Martincighe0e6efc2019-10-04 17:17:42 +01002172 for (unsigned int i = 0; i < numSteps; ++i)
Francis Murtaghfcb8ef62019-09-20 15:40:09 +01002173 {
2174 data.SetCaptureData(1, captureIds1);
2175 captureReader.SetCounterValue(0, valueA * (i + 1));
2176 captureReader.SetCounterValue(1, valueB * (i + 1));
2177
2178 periodicCounterCapture.Start();
Finn Williamsf4d59a62019-10-14 15:55:18 +01002179 periodicCounterCapture.Stop();
Francis Murtaghfcb8ef62019-09-20 15:40:09 +01002180 }
2181
Narumol Prangnawarat404b2752019-09-24 17:23:16 +01002182 auto buffer = mockBuffer.GetReadableBuffer();
Francis Murtaghfcb8ef62019-09-20 15:40:09 +01002183
2184 uint32_t headerWord0 = ReadUint32(buffer, 0);
2185 uint32_t headerWord1 = ReadUint32(buffer, 4);
2186
Jim Flynnfc365622019-12-04 10:07:20 +00002187 BOOST_TEST(((headerWord0 >> 26) & 0x0000003F) == 3); // packet family
Keith Davis3201eea2019-10-24 17:30:41 +01002188 BOOST_TEST(((headerWord0 >> 19) & 0x0000007F) == 0); // packet class
2189 BOOST_TEST(((headerWord0 >> 16) & 0x00000007) == 0); // packet type
Matteo Martincigh8d9590e2019-10-15 09:35:29 +01002190 BOOST_TEST(headerWord1 == 20);
Francis Murtaghfcb8ef62019-09-20 15:40:09 +01002191
Keith Davis3201eea2019-10-24 17:30:41 +01002192 uint32_t offset = 16;
Francis Murtaghfcb8ef62019-09-20 15:40:09 +01002193 uint16_t readIndex = ReadUint16(buffer, offset);
2194 BOOST_TEST(0 == readIndex);
2195
2196 offset += 2;
2197 uint32_t readValue = ReadUint32(buffer, offset);
2198 BOOST_TEST((valueA * numSteps) == readValue);
2199
2200 offset += 4;
2201 readIndex = ReadUint16(buffer, offset);
2202 BOOST_TEST(1 == readIndex);
2203
2204 offset += 2;
2205 readValue = ReadUint32(buffer, offset);
2206 BOOST_TEST((valueB * numSteps) == readValue);
2207}
2208
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002209BOOST_AUTO_TEST_CASE(RequestCounterDirectoryCommandHandlerTest1)
Narumol Prangnawarat48033692019-09-20 12:04:55 +01002210{
2211 using boost::numeric_cast;
2212
Jim Flynn397043f2019-10-17 17:37:10 +01002213 const uint32_t familyId = 0;
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002214 const uint32_t packetId = 3;
Keith Davis3201eea2019-10-24 17:30:41 +01002215 const uint32_t version = 1;
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002216 ProfilingStateMachine profilingStateMachine;
2217 CounterDirectory counterDirectory;
Matteo Martincigh9723d022019-11-13 10:56:41 +00002218 MockBufferManager mockBuffer1(1024);
2219 SendCounterPacket sendCounterPacket(profilingStateMachine, mockBuffer1);
2220 MockBufferManager mockBuffer2(1024);
2221 SendTimelinePacket sendTimelinePacket(mockBuffer2);
Keith Davis3201eea2019-10-24 17:30:41 +01002222 RequestCounterDirectoryCommandHandler commandHandler(familyId, packetId, version, counterDirectory,
Matteo Martincigh9723d022019-11-13 10:56:41 +00002223 sendCounterPacket, sendTimelinePacket, profilingStateMachine);
Narumol Prangnawarat48033692019-09-20 12:04:55 +01002224
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002225 const uint32_t wrongPacketId = 47;
Keith Davis3201eea2019-10-24 17:30:41 +01002226 const uint32_t wrongHeader = (wrongPacketId & 0x000003FF) << 16;
Narumol Prangnawarat48033692019-09-20 12:04:55 +01002227
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002228 Packet wrongPacket(wrongHeader);
2229
2230 profilingStateMachine.TransitionToState(ProfilingState::Uninitialised);
Matteo Martincigh9723d022019-11-13 10:56:41 +00002231 BOOST_CHECK_THROW(commandHandler(wrongPacket), armnn::RuntimeException); // Wrong profiling state
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002232 profilingStateMachine.TransitionToState(ProfilingState::NotConnected);
Matteo Martincigh9723d022019-11-13 10:56:41 +00002233 BOOST_CHECK_THROW(commandHandler(wrongPacket), armnn::RuntimeException); // Wrong profiling state
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002234 profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck);
Matteo Martincigh9723d022019-11-13 10:56:41 +00002235 BOOST_CHECK_THROW(commandHandler(wrongPacket), armnn::RuntimeException); // Wrong profiling state
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002236 profilingStateMachine.TransitionToState(ProfilingState::Active);
Matteo Martincigh9723d022019-11-13 10:56:41 +00002237 BOOST_CHECK_THROW(commandHandler(wrongPacket), armnn::InvalidArgumentException); // Wrong packet
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002238
2239 const uint32_t rightHeader = (packetId & 0x000003FF) << 16;
2240
2241 Packet rightPacket(rightHeader);
2242
Matteo Martincigh9723d022019-11-13 10:56:41 +00002243 BOOST_CHECK_NO_THROW(commandHandler(rightPacket)); // Right packet
Narumol Prangnawarat48033692019-09-20 12:04:55 +01002244
Matteo Martincigh9723d022019-11-13 10:56:41 +00002245 auto readBuffer1 = mockBuffer1.GetReadableBuffer();
Narumol Prangnawarat48033692019-09-20 12:04:55 +01002246
Matteo Martincigh9723d022019-11-13 10:56:41 +00002247 uint32_t header1Word0 = ReadUint32(readBuffer1, 0);
2248 uint32_t header1Word1 = ReadUint32(readBuffer1, 4);
Narumol Prangnawarat48033692019-09-20 12:04:55 +01002249
Matteo Martincigh9723d022019-11-13 10:56:41 +00002250 // Counter directory packet
2251 BOOST_TEST(((header1Word0 >> 26) & 0x0000003F) == 0); // packet family
2252 BOOST_TEST(((header1Word0 >> 16) & 0x000003FF) == 2); // packet id
2253 BOOST_TEST(header1Word1 == 24); // data length
Narumol Prangnawarat48033692019-09-20 12:04:55 +01002254
Matteo Martincigh9723d022019-11-13 10:56:41 +00002255 uint32_t bodyHeader1Word0 = ReadUint32(readBuffer1, 8);
2256 uint16_t deviceRecordCount = numeric_cast<uint16_t>(bodyHeader1Word0 >> 16);
2257 BOOST_TEST(deviceRecordCount == 0); // device_records_count
2258
2259 auto readBuffer2 = mockBuffer2.GetReadableBuffer();
2260
2261 uint32_t header2Word0 = ReadUint32(readBuffer2, 0);
2262 uint32_t header2Word1 = ReadUint32(readBuffer2, 4);
2263
2264 // Timeline message directory packet
2265 BOOST_TEST(((header2Word0 >> 26) & 0x0000003F) == 1); // packet family
2266 BOOST_TEST(((header2Word0 >> 16) & 0x000003FF) == 0); // packet id
2267 BOOST_TEST(header2Word1 == 419); // data length
Narumol Prangnawarat48033692019-09-20 12:04:55 +01002268}
2269
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002270BOOST_AUTO_TEST_CASE(RequestCounterDirectoryCommandHandlerTest2)
Narumol Prangnawarat48033692019-09-20 12:04:55 +01002271{
2272 using boost::numeric_cast;
2273
Jim Flynn397043f2019-10-17 17:37:10 +01002274 const uint32_t familyId = 0;
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002275 const uint32_t packetId = 3;
Keith Davis3201eea2019-10-24 17:30:41 +01002276 const uint32_t version = 1;
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002277 ProfilingStateMachine profilingStateMachine;
2278 CounterDirectory counterDirectory;
Matteo Martincigh9723d022019-11-13 10:56:41 +00002279 MockBufferManager mockBuffer1(1024);
2280 SendCounterPacket sendCounterPacket(profilingStateMachine, mockBuffer1);
2281 MockBufferManager mockBuffer2(1024);
2282 SendTimelinePacket sendTimelinePacket(mockBuffer2);
Keith Davis3201eea2019-10-24 17:30:41 +01002283 RequestCounterDirectoryCommandHandler commandHandler(familyId, packetId, version, counterDirectory,
Matteo Martincigh9723d022019-11-13 10:56:41 +00002284 sendCounterPacket, sendTimelinePacket, profilingStateMachine);
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002285 const uint32_t header = (packetId & 0x000003FF) << 16;
2286 Packet packet(header);
Narumol Prangnawarat48033692019-09-20 12:04:55 +01002287
Matteo Martincigh9723d022019-11-13 10:56:41 +00002288 const Device* device = counterDirectory.RegisterDevice("deviceA", 1);
2289 BOOST_CHECK(device != nullptr);
Narumol Prangnawarat48033692019-09-20 12:04:55 +01002290 const CounterSet* counterSet = counterDirectory.RegisterCounterSet("countersetA");
Matteo Martincigh9723d022019-11-13 10:56:41 +00002291 BOOST_CHECK(counterSet != nullptr);
Narumol Prangnawarat48033692019-09-20 12:04:55 +01002292 counterDirectory.RegisterCategory("categoryA", device->m_Uid, counterSet->m_Uid);
Keith Davise394bd92019-12-02 15:12:19 +00002293 counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, 24,
2294 "categoryA", 0, 1, 2.0f, "counterA", "descA");
2295 counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, 25,
2296 "categoryA", 1, 1, 3.0f, "counterB", "descB");
Narumol Prangnawarat48033692019-09-20 12:04:55 +01002297
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002298 profilingStateMachine.TransitionToState(ProfilingState::Uninitialised);
Keith Davis3201eea2019-10-24 17:30:41 +01002299 BOOST_CHECK_THROW(commandHandler(packet), armnn::RuntimeException); // Wrong profiling state
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002300 profilingStateMachine.TransitionToState(ProfilingState::NotConnected);
Keith Davis3201eea2019-10-24 17:30:41 +01002301 BOOST_CHECK_THROW(commandHandler(packet), armnn::RuntimeException); // Wrong profiling state
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002302 profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck);
Keith Davis3201eea2019-10-24 17:30:41 +01002303 BOOST_CHECK_THROW(commandHandler(packet), armnn::RuntimeException); // Wrong profiling state
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002304 profilingStateMachine.TransitionToState(ProfilingState::Active);
2305 BOOST_CHECK_NO_THROW(commandHandler(packet));
Narumol Prangnawarat48033692019-09-20 12:04:55 +01002306
Matteo Martincigh9723d022019-11-13 10:56:41 +00002307 auto readBuffer1 = mockBuffer1.GetReadableBuffer();
Narumol Prangnawarat48033692019-09-20 12:04:55 +01002308
Matteo Martincigh9723d022019-11-13 10:56:41 +00002309 uint32_t header1Word0 = ReadUint32(readBuffer1, 0);
2310 uint32_t header1Word1 = ReadUint32(readBuffer1, 4);
Narumol Prangnawarat48033692019-09-20 12:04:55 +01002311
Matteo Martincigh9723d022019-11-13 10:56:41 +00002312 BOOST_TEST(((header1Word0 >> 26) & 0x0000003F) == 0); // packet family
2313 BOOST_TEST(((header1Word0 >> 16) & 0x000003FF) == 2); // packet id
2314 BOOST_TEST(header1Word1 == 240); // data length
Narumol Prangnawarat48033692019-09-20 12:04:55 +01002315
Matteo Martincigh9723d022019-11-13 10:56:41 +00002316 uint32_t bodyHeader1Word0 = ReadUint32(readBuffer1, 8);
2317 uint32_t bodyHeader1Word1 = ReadUint32(readBuffer1, 12);
2318 uint32_t bodyHeader1Word2 = ReadUint32(readBuffer1, 16);
2319 uint32_t bodyHeader1Word3 = ReadUint32(readBuffer1, 20);
2320 uint32_t bodyHeader1Word4 = ReadUint32(readBuffer1, 24);
2321 uint32_t bodyHeader1Word5 = ReadUint32(readBuffer1, 28);
2322 uint16_t deviceRecordCount = numeric_cast<uint16_t>(bodyHeader1Word0 >> 16);
2323 uint16_t counterSetRecordCount = numeric_cast<uint16_t>(bodyHeader1Word2 >> 16);
2324 uint16_t categoryRecordCount = numeric_cast<uint16_t>(bodyHeader1Word4 >> 16);
2325 BOOST_TEST(deviceRecordCount == 1); // device_records_count
2326 BOOST_TEST(bodyHeader1Word1 == 0); // device_records_pointer_table_offset
2327 BOOST_TEST(counterSetRecordCount == 1); // counter_set_count
2328 BOOST_TEST(bodyHeader1Word3 == 4); // counter_set_pointer_table_offset
2329 BOOST_TEST(categoryRecordCount == 1); // categories_count
2330 BOOST_TEST(bodyHeader1Word5 == 8); // categories_pointer_table_offset
Narumol Prangnawarat48033692019-09-20 12:04:55 +01002331
Matteo Martincigh9723d022019-11-13 10:56:41 +00002332 uint32_t deviceRecordOffset = ReadUint32(readBuffer1, 32);
Keith Davis3201eea2019-10-24 17:30:41 +01002333 BOOST_TEST(deviceRecordOffset == 0);
Narumol Prangnawarat48033692019-09-20 12:04:55 +01002334
Matteo Martincigh9723d022019-11-13 10:56:41 +00002335 uint32_t counterSetRecordOffset = ReadUint32(readBuffer1, 36);
Narumol Prangnawarat48033692019-09-20 12:04:55 +01002336 BOOST_TEST(counterSetRecordOffset == 20);
2337
Matteo Martincigh9723d022019-11-13 10:56:41 +00002338 uint32_t categoryRecordOffset = ReadUint32(readBuffer1, 40);
Keith Davis3201eea2019-10-24 17:30:41 +01002339 BOOST_TEST(categoryRecordOffset == 44);
Matteo Martincigh9723d022019-11-13 10:56:41 +00002340
2341 auto readBuffer2 = mockBuffer2.GetReadableBuffer();
2342
2343 uint32_t header2Word0 = ReadUint32(readBuffer2, 0);
2344 uint32_t header2Word1 = ReadUint32(readBuffer2, 4);
2345
2346 // Timeline message directory packet
2347 BOOST_TEST(((header2Word0 >> 26) & 0x0000003F) == 1); // packet family
2348 BOOST_TEST(((header2Word0 >> 16) & 0x000003FF) == 0); // packet id
2349 BOOST_TEST(header2Word1 == 419); // data length
Narumol Prangnawarat48033692019-09-20 12:04:55 +01002350}
2351
Matteo Martincigh54fb9572019-10-02 12:50:57 +01002352BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodConnectionAcknowledgedPacket)
2353{
Matteo Martincighd0613b52019-10-09 16:47:04 +01002354 // Swap the profiling connection factory in the profiling service instance with our mock one
Matteo Martincigh54fb9572019-10-02 12:50:57 +01002355 SwapProfilingConnectionFactoryHelper helper;
Matteo Martincigh54fb9572019-10-02 12:50:57 +01002356
2357 // Calculate the size of a Stream Metadata packet
Keith Davis3201eea2019-10-24 17:30:41 +01002358 std::string processName = GetProcessName().substr(0, 60);
Matteo Martincigh54fb9572019-10-02 12:50:57 +01002359 unsigned int processNameSize = processName.empty() ? 0 : boost::numeric_cast<unsigned int>(processName.size()) + 1;
2360 unsigned int streamMetadataPacketsize = 118 + processNameSize;
2361
Jim Flynn53e46992019-10-14 12:31:10 +01002362 // Reset the profiling service to the uninitialized state
Matteo Martincigh54fb9572019-10-02 12:50:57 +01002363 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
Keith Davis3201eea2019-10-24 17:30:41 +01002364 options.m_EnableProfiling = true;
Matteo Martincigh54fb9572019-10-02 12:50:57 +01002365 ProfilingService& profilingService = ProfilingService::Instance();
2366 profilingService.ResetExternalProfilingOptions(options, true);
2367
2368 // Bring the profiling service to the "WaitingForAck" state
2369 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
Keith Davis3201eea2019-10-24 17:30:41 +01002370 profilingService.Update(); // Initialize the counter directory
Matteo Martincigh54fb9572019-10-02 12:50:57 +01002371 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
Keith Davis3201eea2019-10-24 17:30:41 +01002372 profilingService.Update(); // Create the profiling connection
Matteo Martincigh54fb9572019-10-02 12:50:57 +01002373
Matteo Martincighd0613b52019-10-09 16:47:04 +01002374 // Get the mock profiling connection
2375 MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
2376 BOOST_CHECK(mockProfilingConnection);
2377
Matteo Martincighe8485382019-10-10 14:08:21 +01002378 // Remove the packets received so far
2379 mockProfilingConnection->Clear();
2380
2381 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
Keith Davis3201eea2019-10-24 17:30:41 +01002382 profilingService.Update(); // Start the command handler and the send thread
Matteo Martincighe8485382019-10-10 14:08:21 +01002383
2384 // Wait for the Stream Metadata packet to be sent
Finn Williams09ad6f92019-12-19 17:05:18 +00002385 BOOST_CHECK(helper.WaitForPacketsSent(
2386 mockProfilingConnection, PacketType::StreamMetaData, streamMetadataPacketsize) >= 1);
Matteo Martincigh54fb9572019-10-02 12:50:57 +01002387
2388 // Write a valid "Connection Acknowledged" packet into the mock profiling connection, to simulate a valid
2389 // reply from an external profiling service
2390
2391 // Connection Acknowledged Packet header (word 0, word 1 is always zero):
2392 // 26:31 [6] packet_family: Control Packet Family, value 0b000000
2393 // 16:25 [10] packet_id: Packet identifier, value 0b0000000001
2394 // 8:15 [8] reserved: Reserved, value 0b00000000
2395 // 0:7 [8] reserved: Reserved, value 0b00000000
2396 uint32_t packetFamily = 0;
2397 uint32_t packetId = 1;
Keith Davis3201eea2019-10-24 17:30:41 +01002398 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
Matteo Martincigh54fb9572019-10-02 12:50:57 +01002399
Matteo Martincighd0613b52019-10-09 16:47:04 +01002400 // Create the Connection Acknowledged Packet
Matteo Martincigh54fb9572019-10-02 12:50:57 +01002401 Packet connectionAcknowledgedPacket(header);
2402
2403 // Write the packet to the mock profiling connection
2404 mockProfilingConnection->WritePacket(std::move(connectionAcknowledgedPacket));
2405
Colm Donelan2ba48d22019-11-29 09:10:59 +00002406 // Wait for the counter directory packet to ensure the ConnectionAcknowledgedCommandHandler has run.
Finn Williams09ad6f92019-12-19 17:05:18 +00002407 BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::CounterDirectory) == 1);
Matteo Martincigh54fb9572019-10-02 12:50:57 +01002408
2409 // The Connection Acknowledged Command Handler should have updated the profiling state accordingly
2410 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
Matteo Martincighd0613b52019-10-09 16:47:04 +01002411
2412 // Reset the profiling service to stop any running thread
2413 options.m_EnableProfiling = false;
2414 profilingService.ResetExternalProfilingOptions(options, true);
Matteo Martincigh54fb9572019-10-02 12:50:57 +01002415}
2416
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002417BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodRequestCounterDirectoryPacket)
2418{
2419 // Swap the profiling connection factory in the profiling service instance with our mock one
2420 SwapProfilingConnectionFactoryHelper helper;
2421
2422 // Reset the profiling service to the uninitialized state
2423 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
Keith Davis3201eea2019-10-24 17:30:41 +01002424 options.m_EnableProfiling = true;
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002425 ProfilingService& profilingService = ProfilingService::Instance();
2426 profilingService.ResetExternalProfilingOptions(options, true);
2427
2428 // Bring the profiling service to the "Active" state
2429 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
Keith Davis3201eea2019-10-24 17:30:41 +01002430 profilingService.Update(); // Initialize the counter directory
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002431 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
Keith Davis3201eea2019-10-24 17:30:41 +01002432 profilingService.Update(); // Create the profiling connection
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002433 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
Keith Davis3201eea2019-10-24 17:30:41 +01002434 profilingService.Update(); // Start the command handler and the send thread
Matteo Martincighe8485382019-10-10 14:08:21 +01002435
Colm Donelan2ba48d22019-11-29 09:10:59 +00002436 // Get the mock profiling connection
2437 MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
2438 BOOST_CHECK(mockProfilingConnection);
2439
Matteo Martincighe8485382019-10-10 14:08:21 +01002440 // Force the profiling service to the "Active" state
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002441 helper.ForceTransitionToState(ProfilingState::Active);
2442 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2443
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002444 // Write a valid "Request Counter Directory" packet into the mock profiling connection, to simulate a valid
2445 // reply from an external profiling service
2446
2447 // Request Counter Directory packet header (word 0, word 1 is always zero):
2448 // 26:31 [6] packet_family: Control Packet Family, value 0b000000
2449 // 16:25 [10] packet_id: Packet identifier, value 0b0000000011
2450 // 8:15 [8] reserved: Reserved, value 0b00000000
2451 // 0:7 [8] reserved: Reserved, value 0b00000000
2452 uint32_t packetFamily = 0;
2453 uint32_t packetId = 3;
Keith Davis3201eea2019-10-24 17:30:41 +01002454 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002455
2456 // Create the Request Counter Directory packet
2457 Packet requestCounterDirectoryPacket(header);
2458
2459 // Write the packet to the mock profiling connection
2460 mockProfilingConnection->WritePacket(std::move(requestCounterDirectoryPacket));
2461
Finn Williams09ad6f92019-12-19 17:05:18 +00002462 // Expecting one CounterDirectory Packet of length 656
2463 // and one TimelineMessageDirectory packet of length 427
2464 BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::CounterDirectory, 656) == 1);
2465 BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::TimelineMessageDirectory, 427) == 1);
Matteo Martincighe8485382019-10-10 14:08:21 +01002466
2467 // The Request Counter Directory Command Handler should not have updated the profiling state
2468 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2469
2470 // Reset the profiling service to stop any running thread
2471 options.m_EnableProfiling = false;
2472 profilingService.ResetExternalProfilingOptions(options, true);
2473}
2474
Matteo Martincighe8485382019-10-10 14:08:21 +01002475BOOST_AUTO_TEST_CASE(CheckProfilingServiceBadPeriodicCounterSelectionPacketInvalidCounterUid)
2476{
Matteo Martincighe8485382019-10-10 14:08:21 +01002477 // Swap the profiling connection factory in the profiling service instance with our mock one
2478 SwapProfilingConnectionFactoryHelper helper;
2479
2480 // Reset the profiling service to the uninitialized state
2481 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
Keith Davis3201eea2019-10-24 17:30:41 +01002482 options.m_EnableProfiling = true;
Matteo Martincighe8485382019-10-10 14:08:21 +01002483 ProfilingService& profilingService = ProfilingService::Instance();
2484 profilingService.ResetExternalProfilingOptions(options, true);
2485
2486 // Bring the profiling service to the "Active" state
2487 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
Keith Davis3201eea2019-10-24 17:30:41 +01002488 profilingService.Update(); // Initialize the counter directory
Matteo Martincighe8485382019-10-10 14:08:21 +01002489 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
Keith Davis3201eea2019-10-24 17:30:41 +01002490 profilingService.Update(); // Create the profiling connection
Matteo Martincighe8485382019-10-10 14:08:21 +01002491 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
Keith Davis3201eea2019-10-24 17:30:41 +01002492 profilingService.Update(); // Start the command handler and the send thread
Matteo Martincighe8485382019-10-10 14:08:21 +01002493
Colm Donelan2ba48d22019-11-29 09:10:59 +00002494 // Get the mock profiling connection
2495 MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
2496 BOOST_CHECK(mockProfilingConnection);
2497
Matteo Martincighe8485382019-10-10 14:08:21 +01002498 // Force the profiling service to the "Active" state
2499 helper.ForceTransitionToState(ProfilingState::Active);
2500 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2501
Matteo Martincighe8485382019-10-10 14:08:21 +01002502 // Remove the packets received so far
2503 mockProfilingConnection->Clear();
2504
2505 // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an
2506 // external profiling service
2507
2508 // Periodic Counter Selection packet header:
2509 // 26:31 [6] packet_family: Control Packet Family, value 0b000000
2510 // 16:25 [10] packet_id: Packet identifier, value 0b0000000100
2511 // 8:15 [8] reserved: Reserved, value 0b00000000
2512 // 0:7 [8] reserved: Reserved, value 0b00000000
2513 uint32_t packetFamily = 0;
2514 uint32_t packetId = 4;
Keith Davis3201eea2019-10-24 17:30:41 +01002515 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
Matteo Martincighe8485382019-10-10 14:08:21 +01002516
Keith Davis3201eea2019-10-24 17:30:41 +01002517 uint32_t capturePeriod = 123456; // Some capture period (microseconds)
Matteo Martincighe8485382019-10-10 14:08:21 +01002518
2519 // Get the first valid counter UID
2520 const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory();
Keith Davis3201eea2019-10-24 17:30:41 +01002521 const Counters& counters = counterDirectory.GetCounters();
Matteo Martincighe8485382019-10-10 14:08:21 +01002522 BOOST_CHECK(counters.size() > 1);
Keith Davis3201eea2019-10-24 17:30:41 +01002523 uint16_t counterUidA = counters.begin()->first; // First valid counter UID
2524 uint16_t counterUidB = 9999; // Second invalid counter UID
Matteo Martincighe8485382019-10-10 14:08:21 +01002525
2526 uint32_t length = 8;
2527
2528 auto data = std::make_unique<unsigned char[]>(length);
2529 WriteUint32(data.get(), 0, capturePeriod);
2530 WriteUint16(data.get(), 4, counterUidA);
2531 WriteUint16(data.get(), 6, counterUidB);
2532
2533 // Create the Periodic Counter Selection packet
Keith Davis3201eea2019-10-24 17:30:41 +01002534 Packet periodicCounterSelectionPacket(header, length, data); // Length > 0, this will start the Period Counter
2535 // Capture thread
Matteo Martincighe8485382019-10-10 14:08:21 +01002536
2537 // Write the packet to the mock profiling connection
2538 mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket));
2539
Finn Williams09ad6f92019-12-19 17:05:18 +00002540 // Expecting one Periodic Counter Selection packet of length 14
2541 // and at least one Periodic Counter Capture packet of length 22
2542 BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 14) == 1);
2543 BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 22) >= 1);
Matteo Martincighe8485382019-10-10 14:08:21 +01002544
2545 // The Periodic Counter Selection Handler should not have updated the profiling state
2546 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2547
2548 // Reset the profiling service to stop any running thread
2549 options.m_EnableProfiling = false;
2550 profilingService.ResetExternalProfilingOptions(options, true);
2551}
2552
2553BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodPeriodicCounterSelectionPacketNoCounters)
2554{
2555 // Swap the profiling connection factory in the profiling service instance with our mock one
2556 SwapProfilingConnectionFactoryHelper helper;
2557
2558 // Reset the profiling service to the uninitialized state
2559 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
Keith Davis3201eea2019-10-24 17:30:41 +01002560 options.m_EnableProfiling = true;
Matteo Martincighe8485382019-10-10 14:08:21 +01002561 ProfilingService& profilingService = ProfilingService::Instance();
2562 profilingService.ResetExternalProfilingOptions(options, true);
2563
2564 // Bring the profiling service to the "Active" state
2565 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
Keith Davis3201eea2019-10-24 17:30:41 +01002566 profilingService.Update(); // Initialize the counter directory
Matteo Martincighe8485382019-10-10 14:08:21 +01002567 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
Keith Davis3201eea2019-10-24 17:30:41 +01002568 profilingService.Update(); // Create the profiling connection
Matteo Martincighe8485382019-10-10 14:08:21 +01002569 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
Keith Davis3201eea2019-10-24 17:30:41 +01002570 profilingService.Update(); // Start the command handler and the send thread
Matteo Martincighe8485382019-10-10 14:08:21 +01002571
Colm Donelan2ba48d22019-11-29 09:10:59 +00002572 // Get the mock profiling connection
2573 MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
2574 BOOST_CHECK(mockProfilingConnection);
2575
Matteo Martincighe8485382019-10-10 14:08:21 +01002576 // Wait for the Stream Metadata packet the be sent
2577 // (we are not testing the connection acknowledgement here so it will be ignored by this test)
Finn Williams09ad6f92019-12-19 17:05:18 +00002578 helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
Matteo Martincighe8485382019-10-10 14:08:21 +01002579
2580 // Force the profiling service to the "Active" state
2581 helper.ForceTransitionToState(ProfilingState::Active);
2582 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2583
Matteo Martincighe8485382019-10-10 14:08:21 +01002584 // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an
2585 // external profiling service
2586
2587 // Periodic Counter Selection packet header:
2588 // 26:31 [6] packet_family: Control Packet Family, value 0b000000
2589 // 16:25 [10] packet_id: Packet identifier, value 0b0000000100
2590 // 8:15 [8] reserved: Reserved, value 0b00000000
2591 // 0:7 [8] reserved: Reserved, value 0b00000000
2592 uint32_t packetFamily = 0;
2593 uint32_t packetId = 4;
Keith Davis3201eea2019-10-24 17:30:41 +01002594 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
Matteo Martincighe8485382019-10-10 14:08:21 +01002595
2596 // Create the Periodic Counter Selection packet
Keith Davis3201eea2019-10-24 17:30:41 +01002597 Packet periodicCounterSelectionPacket(header); // Length == 0, this will disable the collection of counters
Matteo Martincighe8485382019-10-10 14:08:21 +01002598
2599 // Write the packet to the mock profiling connection
2600 mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket));
2601
Finn Williams09ad6f92019-12-19 17:05:18 +00002602 // Wait for the Periodic Counter Selection packet of length 12 to be sent
2603 // The size of the expected Periodic Counter Selection (echos the sent one)
2604 BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 12) == 1);
Matteo Martincighe8485382019-10-10 14:08:21 +01002605
2606 // The Periodic Counter Selection Handler should not have updated the profiling state
2607 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2608
Finn Williams09ad6f92019-12-19 17:05:18 +00002609 // No Periodic Counter packets are expected
2610 BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 0, 0) == 0);
Matteo Martincighe8485382019-10-10 14:08:21 +01002611
2612 // Reset the profiling service to stop any running thread
2613 options.m_EnableProfiling = false;
2614 profilingService.ResetExternalProfilingOptions(options, true);
2615}
2616
2617BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodPeriodicCounterSelectionPacketSingleCounter)
2618{
2619 // Swap the profiling connection factory in the profiling service instance with our mock one
2620 SwapProfilingConnectionFactoryHelper helper;
2621
2622 // Reset the profiling service to the uninitialized state
2623 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
Keith Davis3201eea2019-10-24 17:30:41 +01002624 options.m_EnableProfiling = true;
Matteo Martincighe8485382019-10-10 14:08:21 +01002625 ProfilingService& profilingService = ProfilingService::Instance();
2626 profilingService.ResetExternalProfilingOptions(options, true);
2627
2628 // Bring the profiling service to the "Active" state
2629 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
Keith Davis3201eea2019-10-24 17:30:41 +01002630 profilingService.Update(); // Initialize the counter directory
Matteo Martincighe8485382019-10-10 14:08:21 +01002631 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
Keith Davis3201eea2019-10-24 17:30:41 +01002632 profilingService.Update(); // Create the profiling connection
Matteo Martincighe8485382019-10-10 14:08:21 +01002633 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
Keith Davis3201eea2019-10-24 17:30:41 +01002634 profilingService.Update(); // Start the command handler and the send thread
Matteo Martincighe8485382019-10-10 14:08:21 +01002635
Colm Donelan2ba48d22019-11-29 09:10:59 +00002636 // Get the mock profiling connection
2637 MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
2638 BOOST_CHECK(mockProfilingConnection);
2639
Finn Williams09ad6f92019-12-19 17:05:18 +00002640 // Wait for the Stream Metadata packet to be sent
Matteo Martincighe8485382019-10-10 14:08:21 +01002641 // (we are not testing the connection acknowledgement here so it will be ignored by this test)
Finn Williams09ad6f92019-12-19 17:05:18 +00002642 helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
Matteo Martincighe8485382019-10-10 14:08:21 +01002643
2644 // Force the profiling service to the "Active" state
2645 helper.ForceTransitionToState(ProfilingState::Active);
2646 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2647
Matteo Martincighe8485382019-10-10 14:08:21 +01002648 // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an
2649 // external profiling service
2650
2651 // Periodic Counter Selection packet header:
2652 // 26:31 [6] packet_family: Control Packet Family, value 0b000000
2653 // 16:25 [10] packet_id: Packet identifier, value 0b0000000100
2654 // 8:15 [8] reserved: Reserved, value 0b00000000
2655 // 0:7 [8] reserved: Reserved, value 0b00000000
2656 uint32_t packetFamily = 0;
2657 uint32_t packetId = 4;
Keith Davis3201eea2019-10-24 17:30:41 +01002658 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
Matteo Martincighe8485382019-10-10 14:08:21 +01002659
Keith Davis3201eea2019-10-24 17:30:41 +01002660 uint32_t capturePeriod = 123456; // Some capture period (microseconds)
Matteo Martincighe8485382019-10-10 14:08:21 +01002661
2662 // Get the first valid counter UID
2663 const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory();
Keith Davis3201eea2019-10-24 17:30:41 +01002664 const Counters& counters = counterDirectory.GetCounters();
Matteo Martincighe8485382019-10-10 14:08:21 +01002665 BOOST_CHECK(!counters.empty());
Keith Davis3201eea2019-10-24 17:30:41 +01002666 uint16_t counterUid = counters.begin()->first; // Valid counter UID
Matteo Martincighe8485382019-10-10 14:08:21 +01002667
2668 uint32_t length = 6;
2669
2670 auto data = std::make_unique<unsigned char[]>(length);
2671 WriteUint32(data.get(), 0, capturePeriod);
2672 WriteUint16(data.get(), 4, counterUid);
2673
2674 // Create the Periodic Counter Selection packet
Keith Davis3201eea2019-10-24 17:30:41 +01002675 Packet periodicCounterSelectionPacket(header, length, data); // Length > 0, this will start the Period Counter
2676 // Capture thread
Matteo Martincighe8485382019-10-10 14:08:21 +01002677
2678 // Write the packet to the mock profiling connection
2679 mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket));
2680
Finn Williams09ad6f92019-12-19 17:05:18 +00002681 // Expecting one Periodic Counter Selection packet of length 14
2682 // and at least one Periodic Counter Capture packet of length 22
2683 BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 14) == 1);
2684 BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 22) >= 1);
Matteo Martincighe8485382019-10-10 14:08:21 +01002685
2686 // The Periodic Counter Selection Handler should not have updated the profiling state
2687 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2688
2689 // Reset the profiling service to stop any running thread
2690 options.m_EnableProfiling = false;
2691 profilingService.ResetExternalProfilingOptions(options, true);
2692}
2693
2694BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodPeriodicCounterSelectionPacketMultipleCounters)
2695{
2696 // Swap the profiling connection factory in the profiling service instance with our mock one
2697 SwapProfilingConnectionFactoryHelper helper;
Matteo Martincighe8485382019-10-10 14:08:21 +01002698 // Reset the profiling service to the uninitialized state
2699 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
Keith Davis3201eea2019-10-24 17:30:41 +01002700 options.m_EnableProfiling = true;
Matteo Martincighe8485382019-10-10 14:08:21 +01002701 ProfilingService& profilingService = ProfilingService::Instance();
2702 profilingService.ResetExternalProfilingOptions(options, true);
2703
2704 // Bring the profiling service to the "Active" state
2705 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
Keith Davis3201eea2019-10-24 17:30:41 +01002706 profilingService.Update(); // Initialize the counter directory
Matteo Martincighe8485382019-10-10 14:08:21 +01002707 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
Keith Davis3201eea2019-10-24 17:30:41 +01002708 profilingService.Update(); // Create the profiling connection
Matteo Martincighe8485382019-10-10 14:08:21 +01002709 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
Keith Davis3201eea2019-10-24 17:30:41 +01002710 profilingService.Update(); // Start the command handler and the send thread
Matteo Martincighe8485382019-10-10 14:08:21 +01002711
Colm Donelan2ba48d22019-11-29 09:10:59 +00002712 // Get the mock profiling connection
2713 MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
2714 BOOST_CHECK(mockProfilingConnection);
2715
Matteo Martincighe8485382019-10-10 14:08:21 +01002716 // Wait for the Stream Metadata packet the be sent
2717 // (we are not testing the connection acknowledgement here so it will be ignored by this test)
Finn Williams09ad6f92019-12-19 17:05:18 +00002718 helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
Matteo Martincighe8485382019-10-10 14:08:21 +01002719
2720 // Force the profiling service to the "Active" state
2721 helper.ForceTransitionToState(ProfilingState::Active);
2722 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2723
Matteo Martincighe8485382019-10-10 14:08:21 +01002724 // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an
2725 // external profiling service
2726
2727 // Periodic Counter Selection packet header:
2728 // 26:31 [6] packet_family: Control Packet Family, value 0b000000
2729 // 16:25 [10] packet_id: Packet identifier, value 0b0000000100
2730 // 8:15 [8] reserved: Reserved, value 0b00000000
2731 // 0:7 [8] reserved: Reserved, value 0b00000000
2732 uint32_t packetFamily = 0;
2733 uint32_t packetId = 4;
Keith Davis3201eea2019-10-24 17:30:41 +01002734 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
Matteo Martincighe8485382019-10-10 14:08:21 +01002735
Keith Davis3201eea2019-10-24 17:30:41 +01002736 uint32_t capturePeriod = 123456; // Some capture period (microseconds)
Matteo Martincighe8485382019-10-10 14:08:21 +01002737
2738 // Get the first valid counter UID
2739 const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory();
Keith Davis3201eea2019-10-24 17:30:41 +01002740 const Counters& counters = counterDirectory.GetCounters();
Matteo Martincighe8485382019-10-10 14:08:21 +01002741 BOOST_CHECK(counters.size() > 1);
Keith Davis3201eea2019-10-24 17:30:41 +01002742 uint16_t counterUidA = counters.begin()->first; // First valid counter UID
2743 uint16_t counterUidB = (counters.begin()++)->first; // Second valid counter UID
Matteo Martincighe8485382019-10-10 14:08:21 +01002744
2745 uint32_t length = 8;
2746
2747 auto data = std::make_unique<unsigned char[]>(length);
2748 WriteUint32(data.get(), 0, capturePeriod);
2749 WriteUint16(data.get(), 4, counterUidA);
2750 WriteUint16(data.get(), 6, counterUidB);
2751
2752 // Create the Periodic Counter Selection packet
Keith Davis3201eea2019-10-24 17:30:41 +01002753 Packet periodicCounterSelectionPacket(header, length, data); // Length > 0, this will start the Period Counter
2754 // Capture thread
Matteo Martincighe8485382019-10-10 14:08:21 +01002755
2756 // Write the packet to the mock profiling connection
2757 mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket));
2758
Finn Williams09ad6f92019-12-19 17:05:18 +00002759 // Expecting one PeriodicCounterSelection Packet with a length of 16
2760 // And at least one PeriodicCounterCapture Packet with a length of 28
2761 BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 16) == 1);
2762 BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 28) >= 1);
Matteo Martincighe8485382019-10-10 14:08:21 +01002763
2764 // The Periodic Counter Selection Handler should not have updated the profiling state
2765 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
Matteo Martincigh8efc5002019-10-10 14:30:29 +01002766
2767 // Reset the profiling service to stop any running thread
2768 options.m_EnableProfiling = false;
2769 profilingService.ResetExternalProfilingOptions(options, true);
2770}
2771
Jim Flynn53e46992019-10-14 12:31:10 +01002772BOOST_AUTO_TEST_CASE(CheckProfilingServiceDisconnect)
2773{
2774 // Swap the profiling connection factory in the profiling service instance with our mock one
2775 SwapProfilingConnectionFactoryHelper helper;
Jim Flynn53e46992019-10-14 12:31:10 +01002776 // Reset the profiling service to the uninitialized state
2777 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
Keith Davis3201eea2019-10-24 17:30:41 +01002778 options.m_EnableProfiling = true;
Jim Flynn53e46992019-10-14 12:31:10 +01002779 ProfilingService& profilingService = ProfilingService::Instance();
2780 profilingService.ResetExternalProfilingOptions(options, true);
2781
2782 // Try to disconnect the profiling service while in the "Uninitialised" state
2783 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2784 profilingService.Disconnect();
Keith Davis3201eea2019-10-24 17:30:41 +01002785 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); // The state should not change
Jim Flynn53e46992019-10-14 12:31:10 +01002786
2787 // Try to disconnect the profiling service while in the "NotConnected" state
Keith Davis3201eea2019-10-24 17:30:41 +01002788 profilingService.Update(); // Initialize the counter directory
Jim Flynn53e46992019-10-14 12:31:10 +01002789 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2790 profilingService.Disconnect();
Keith Davis3201eea2019-10-24 17:30:41 +01002791 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); // The state should not change
Jim Flynn53e46992019-10-14 12:31:10 +01002792
2793 // Try to disconnect the profiling service while in the "WaitingForAck" state
Keith Davis3201eea2019-10-24 17:30:41 +01002794 profilingService.Update(); // Create the profiling connection
Jim Flynn53e46992019-10-14 12:31:10 +01002795 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
2796 profilingService.Disconnect();
Keith Davis3201eea2019-10-24 17:30:41 +01002797 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); // The state should not change
Jim Flynn53e46992019-10-14 12:31:10 +01002798
2799 // Try to disconnect the profiling service while in the "Active" state
Keith Davis3201eea2019-10-24 17:30:41 +01002800 profilingService.Update(); // Start the command handler and the send thread
Jim Flynn53e46992019-10-14 12:31:10 +01002801
Colm Donelan2ba48d22019-11-29 09:10:59 +00002802 // Get the mock profiling connection
2803 MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
2804 BOOST_CHECK(mockProfilingConnection);
2805
Jim Flynn53e46992019-10-14 12:31:10 +01002806 // Wait for the Stream Metadata packet the be sent
2807 // (we are not testing the connection acknowledgement here so it will be ignored by this test)
Finn Williams09ad6f92019-12-19 17:05:18 +00002808 helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
Jim Flynn53e46992019-10-14 12:31:10 +01002809
2810 // Force the profiling service to the "Active" state
2811 helper.ForceTransitionToState(ProfilingState::Active);
2812 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2813
Jim Flynn53e46992019-10-14 12:31:10 +01002814 // Check that the profiling connection is open
2815 BOOST_CHECK(mockProfilingConnection->IsOpen());
2816
2817 profilingService.Disconnect();
Colm Donelan2ba48d22019-11-29 09:10:59 +00002818 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); // The state should have changed
Jim Flynn53e46992019-10-14 12:31:10 +01002819
2820 // Check that the profiling connection has been reset
2821 mockProfilingConnection = helper.GetMockProfilingConnection();
2822 BOOST_CHECK(mockProfilingConnection == nullptr);
2823
2824 // Reset the profiling service to stop any running thread
2825 options.m_EnableProfiling = false;
2826 profilingService.ResetExternalProfilingOptions(options, true);
2827}
2828
Matteo Martincigh994b5342019-10-11 17:19:56 +01002829BOOST_AUTO_TEST_CASE(CheckProfilingServiceGoodPerJobCounterSelectionPacket)
2830{
2831 // Swap the profiling connection factory in the profiling service instance with our mock one
2832 SwapProfilingConnectionFactoryHelper helper;
Matteo Martincigh994b5342019-10-11 17:19:56 +01002833 // Reset the profiling service to the uninitialized state
2834 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
Keith Davis3201eea2019-10-24 17:30:41 +01002835 options.m_EnableProfiling = true;
Matteo Martincigh994b5342019-10-11 17:19:56 +01002836 ProfilingService& profilingService = ProfilingService::Instance();
2837 profilingService.ResetExternalProfilingOptions(options, true);
2838
2839 // Bring the profiling service to the "Active" state
2840 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
Keith Davis3201eea2019-10-24 17:30:41 +01002841 profilingService.Update(); // Initialize the counter directory
Matteo Martincigh994b5342019-10-11 17:19:56 +01002842 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
Keith Davis3201eea2019-10-24 17:30:41 +01002843 profilingService.Update(); // Create the profiling connection
Matteo Martincigh994b5342019-10-11 17:19:56 +01002844 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
Keith Davis3201eea2019-10-24 17:30:41 +01002845 profilingService.Update(); // Start the command handler and the send thread
Matteo Martincigh994b5342019-10-11 17:19:56 +01002846
Colm Donelan2ba48d22019-11-29 09:10:59 +00002847 // Get the mock profiling connection
2848 MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
2849 BOOST_CHECK(mockProfilingConnection);
2850
Matteo Martincigh994b5342019-10-11 17:19:56 +01002851 // Wait for the Stream Metadata packet the be sent
2852 // (we are not testing the connection acknowledgement here so it will be ignored by this test)
Finn Williams09ad6f92019-12-19 17:05:18 +00002853 helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
Matteo Martincigh994b5342019-10-11 17:19:56 +01002854
2855 // Force the profiling service to the "Active" state
2856 helper.ForceTransitionToState(ProfilingState::Active);
2857 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2858
Matteo Martincigh994b5342019-10-11 17:19:56 +01002859 // Write a "Per-Job Counter Selection" packet into the mock profiling connection, to simulate an input from an
2860 // external profiling service
2861
2862 // Per-Job Counter Selection packet header:
2863 // 26:31 [6] packet_family: Control Packet Family, value 0b000000
2864 // 16:25 [10] packet_id: Packet identifier, value 0b0000000100
2865 // 8:15 [8] reserved: Reserved, value 0b00000000
2866 // 0:7 [8] reserved: Reserved, value 0b00000000
2867 uint32_t packetFamily = 0;
2868 uint32_t packetId = 5;
Keith Davis3201eea2019-10-24 17:30:41 +01002869 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
Matteo Martincigh994b5342019-10-11 17:19:56 +01002870
2871 // Create the Per-Job Counter Selection packet
Keith Davis3201eea2019-10-24 17:30:41 +01002872 Packet periodicCounterSelectionPacket(header); // Length == 0, this will disable the collection of counters
Matteo Martincigh994b5342019-10-11 17:19:56 +01002873
2874 // Write the packet to the mock profiling connection
2875 mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket));
2876
2877 // Wait for a bit (must at least be the delay value of the mock profiling connection) to make sure that
2878 // the Per-Job Counter Selection packet gets processed by the profiling service
Colm Donelan2ba48d22019-11-29 09:10:59 +00002879 std::this_thread::sleep_for(std::chrono::milliseconds(5));
Matteo Martincigh994b5342019-10-11 17:19:56 +01002880
Matteo Martincigh994b5342019-10-11 17:19:56 +01002881 // The Per-Job Counter Selection Command Handler should not have updated the profiling state
2882 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2883
Finn Williams09ad6f92019-12-19 17:05:18 +00002884 // The Per-Job Counter Selection packets are dropped silently, so there should be no reply coming
2885 // from the profiling service
2886 const auto StreamMetaDataSize = static_cast<unsigned long>(
2887 helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData, 0, 0));
2888 BOOST_CHECK(StreamMetaDataSize == mockProfilingConnection->GetWrittenDataSize());
2889
Matteo Martincigh994b5342019-10-11 17:19:56 +01002890 // Reset the profiling service to stop any running thread
2891 options.m_EnableProfiling = false;
2892 profilingService.ResetExternalProfilingOptions(options, true);
2893}
2894
Jim Flynn672d06e2019-10-15 10:18:11 +01002895BOOST_AUTO_TEST_CASE(CheckConfigureProfilingServiceOn)
2896{
2897 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
Keith Davis3201eea2019-10-24 17:30:41 +01002898 options.m_EnableProfiling = true;
Jim Flynn672d06e2019-10-15 10:18:11 +01002899 ProfilingService& profilingService = ProfilingService::Instance();
2900 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2901 profilingService.ConfigureProfilingService(options);
2902 // should get as far as NOT_CONNECTED
2903 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2904 // Reset the profiling service to stop any running thread
2905 options.m_EnableProfiling = false;
2906 profilingService.ResetExternalProfilingOptions(options, true);
2907}
2908
2909BOOST_AUTO_TEST_CASE(CheckConfigureProfilingServiceOff)
2910{
2911 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2912 ProfilingService& profilingService = ProfilingService::Instance();
2913 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2914 profilingService.ConfigureProfilingService(options);
2915 // should not move from Uninitialised
2916 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2917 // Reset the profiling service to stop any running thread
2918 options.m_EnableProfiling = false;
2919 profilingService.ResetExternalProfilingOptions(options, true);
2920}
2921
Colm Donelan2ba48d22019-11-29 09:10:59 +00002922BOOST_AUTO_TEST_CASE(CheckProfilingServiceEnabled)
2923{
2924 // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
2925 LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning);
2926 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2927 options.m_EnableProfiling = true;
2928 ProfilingService& profilingService = ProfilingService::Instance();
2929 profilingService.ResetExternalProfilingOptions(options, true);
2930 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2931 profilingService.Update();
2932 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2933
2934 // Redirect the output to a local stream so that we can parse the warning message
2935 std::stringstream ss;
2936 StreamRedirector streamRedirector(std::cout, ss.rdbuf());
2937 profilingService.Update();
Finn Williams09ad6f92019-12-19 17:05:18 +00002938
2939 // Reset the profiling service to stop any running thread
2940 options.m_EnableProfiling = false;
2941 profilingService.ResetExternalProfilingOptions(options, true);
2942
Colm Donelan2ba48d22019-11-29 09:10:59 +00002943 streamRedirector.CancelRedirect();
2944
2945 // Check that the expected error has occurred and logged to the standard output
2946 if (!boost::contains(ss.str(), "Cannot connect to stream socket: Connection refused"))
2947 {
2948 std::cout << ss.str();
2949 BOOST_FAIL("Expected string not found.");
2950 }
Colm Donelan2ba48d22019-11-29 09:10:59 +00002951}
2952
2953BOOST_AUTO_TEST_CASE(CheckProfilingServiceEnabledRuntime)
2954{
2955 // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
2956 LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning);
2957 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2958 ProfilingService& profilingService = ProfilingService::Instance();
2959 profilingService.ResetExternalProfilingOptions(options, true);
2960 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2961 profilingService.Update();
2962 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2963 options.m_EnableProfiling = true;
2964 profilingService.ResetExternalProfilingOptions(options);
2965 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2966 profilingService.Update();
2967 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2968
2969 // Redirect the output to a local stream so that we can parse the warning message
2970 std::stringstream ss;
2971 StreamRedirector streamRedirector(std::cout, ss.rdbuf());
2972 profilingService.Update();
2973
Finn Williams09ad6f92019-12-19 17:05:18 +00002974 // Reset the profiling service to stop any running thread
2975 options.m_EnableProfiling = false;
2976 profilingService.ResetExternalProfilingOptions(options, true);
2977
Colm Donelan2ba48d22019-11-29 09:10:59 +00002978 streamRedirector.CancelRedirect();
2979
2980 // Check that the expected error has occurred and logged to the standard output
2981 if (!boost::contains(ss.str(), "Cannot connect to stream socket: Connection refused"))
2982 {
2983 std::cout << ss.str();
2984 BOOST_FAIL("Expected string not found.");
2985 }
Colm Donelan2ba48d22019-11-29 09:10:59 +00002986}
2987
2988BOOST_AUTO_TEST_CASE(CheckProfilingServiceBadConnectionAcknowledgedPacket)
2989{
2990 // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
2991 LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning);
2992 // Swap the profiling connection factory in the profiling service instance with our mock one
2993 SwapProfilingConnectionFactoryHelper helper;
2994
2995 // Redirect the standard output to a local stream so that we can parse the warning message
2996 std::stringstream ss;
2997 StreamRedirector streamRedirector(std::cout, ss.rdbuf());
2998
Colm Donelan2ba48d22019-11-29 09:10:59 +00002999 // Reset the profiling service to the uninitialized state
3000 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3001 options.m_EnableProfiling = true;
3002 ProfilingService& profilingService = ProfilingService::Instance();
3003 profilingService.ResetExternalProfilingOptions(options, true);
3004
3005 // Bring the profiling service to the "WaitingForAck" state
3006 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3007 profilingService.Update(); // Initialize the counter directory
3008 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
3009 profilingService.Update(); // Create the profiling connection
3010
3011 // Get the mock profiling connection
3012 MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
3013 BOOST_CHECK(mockProfilingConnection);
3014
Colm Donelan2ba48d22019-11-29 09:10:59 +00003015 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
Colm Donelan2ba48d22019-11-29 09:10:59 +00003016
3017 // Connection Acknowledged Packet header (word 0, word 1 is always zero):
3018 // 26:31 [6] packet_family: Control Packet Family, value 0b000000
3019 // 16:25 [10] packet_id: Packet identifier, value 0b0000000001
3020 // 8:15 [8] reserved: Reserved, value 0b00000000
3021 // 0:7 [8] reserved: Reserved, value 0b00000000
3022 uint32_t packetFamily = 0;
3023 uint32_t packetId = 37; // Wrong packet id!!!
3024 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3025
3026 // Create the Connection Acknowledged Packet
3027 Packet connectionAcknowledgedPacket(header);
Finn Williams09ad6f92019-12-19 17:05:18 +00003028 // Write an invalid "Connection Acknowledged" packet into the mock profiling connection, to simulate an invalid
3029 // reply from an external profiling service
Colm Donelan2ba48d22019-11-29 09:10:59 +00003030 mockProfilingConnection->WritePacket(std::move(connectionAcknowledgedPacket));
3031
Finn Williams09ad6f92019-12-19 17:05:18 +00003032 // Start the command thread
3033 profilingService.Update();
3034
3035 // Wait for the command thread to join
3036 options.m_EnableProfiling = false;
3037 profilingService.ResetExternalProfilingOptions(options, true);
Colm Donelan2ba48d22019-11-29 09:10:59 +00003038
3039 streamRedirector.CancelRedirect();
3040
3041 // Check that the expected error has occurred and logged to the standard output
3042 if (!boost::contains(ss.str(), "Functor with requested PacketId=37 and Version=4194304 does not exist"))
3043 {
3044 std::cout << ss.str();
3045 BOOST_FAIL("Expected string not found.");
3046 }
Colm Donelan2ba48d22019-11-29 09:10:59 +00003047}
3048
3049BOOST_AUTO_TEST_CASE(CheckProfilingServiceBadRequestCounterDirectoryPacket)
3050{
3051 // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
3052 LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning);
3053 // Swap the profiling connection factory in the profiling service instance with our mock one
3054 SwapProfilingConnectionFactoryHelper helper;
3055
3056 // Redirect the standard output to a local stream so that we can parse the warning message
3057 std::stringstream ss;
3058 StreamRedirector streamRedirector(std::cout, ss.rdbuf());
3059
3060 // Reset the profiling service to the uninitialized state
3061 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3062 options.m_EnableProfiling = true;
3063 ProfilingService& profilingService = ProfilingService::Instance();
3064 profilingService.ResetExternalProfilingOptions(options, true);
3065
3066 // Bring the profiling service to the "Active" state
3067 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3068 helper.ForceTransitionToState(ProfilingState::NotConnected);
3069 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
3070 profilingService.Update(); // Create the profiling connection
3071 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
Colm Donelan2ba48d22019-11-29 09:10:59 +00003072
3073 // Get the mock profiling connection
3074 MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
3075 BOOST_CHECK(mockProfilingConnection);
3076
Colm Donelan2ba48d22019-11-29 09:10:59 +00003077 // Write a valid "Request Counter Directory" packet into the mock profiling connection, to simulate a valid
3078 // reply from an external profiling service
3079
3080 // Request Counter Directory packet header (word 0, word 1 is always zero):
3081 // 26:31 [6] packet_family: Control Packet Family, value 0b000000
3082 // 16:25 [10] packet_id: Packet identifier, value 0b0000000011
3083 // 8:15 [8] reserved: Reserved, value 0b00000000
3084 // 0:7 [8] reserved: Reserved, value 0b00000000
3085 uint32_t packetFamily = 0;
3086 uint32_t packetId = 123; // Wrong packet id!!!
3087 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3088
3089 // Create the Request Counter Directory packet
3090 Packet requestCounterDirectoryPacket(header);
3091
3092 // Write the packet to the mock profiling connection
3093 mockProfilingConnection->WritePacket(std::move(requestCounterDirectoryPacket));
3094
Finn Williams09ad6f92019-12-19 17:05:18 +00003095 // Start the command handler and the send thread
3096 profilingService.Update();
3097
3098 // Reset the profiling service to stop and join any running thread
3099 options.m_EnableProfiling = false;
3100 profilingService.ResetExternalProfilingOptions(options, true);
Colm Donelan2ba48d22019-11-29 09:10:59 +00003101
3102 streamRedirector.CancelRedirect();
3103
3104 // Check that the expected error has occurred and logged to the standard output
3105 if (!boost::contains(ss.str(), "Functor with requested PacketId=123 and Version=4194304 does not exist"))
3106 {
3107 std::cout << ss.str();
3108 BOOST_FAIL("Expected string not found.");
3109 }
Colm Donelan2ba48d22019-11-29 09:10:59 +00003110}
3111
3112BOOST_AUTO_TEST_CASE(CheckProfilingServiceBadPeriodicCounterSelectionPacket)
3113{
3114 // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
3115 LogLevelSwapper logLevelSwapper(armnn::LogSeverity::Warning);
3116 // Swap the profiling connection factory in the profiling service instance with our mock one
3117 SwapProfilingConnectionFactoryHelper helper;
3118
3119 // Redirect the standard output to a local stream so that we can parse the warning message
3120 std::stringstream ss;
3121 StreamRedirector streamRedirector(std::cout, ss.rdbuf());
3122
3123 // Reset the profiling service to the uninitialized state
3124 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3125 options.m_EnableProfiling = true;
3126 ProfilingService& profilingService = ProfilingService::Instance();
3127 profilingService.ResetExternalProfilingOptions(options, true);
3128
3129 // Bring the profiling service to the "Active" state
3130 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3131 profilingService.Update(); // Initialize the counter directory
3132 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
3133 profilingService.Update(); // Create the profiling connection
3134 BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
3135 profilingService.Update(); // Start the command handler and the send thread
3136
3137 // Get the mock profiling connection
3138 MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
3139 BOOST_CHECK(mockProfilingConnection);
3140
Colm Donelan2ba48d22019-11-29 09:10:59 +00003141 // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an
3142 // external profiling service
3143
3144 // Periodic Counter Selection packet header:
3145 // 26:31 [6] packet_family: Control Packet Family, value 0b000000
3146 // 16:25 [10] packet_id: Packet identifier, value 0b0000000100
3147 // 8:15 [8] reserved: Reserved, value 0b00000000
3148 // 0:7 [8] reserved: Reserved, value 0b00000000
3149 uint32_t packetFamily = 0;
3150 uint32_t packetId = 999; // Wrong packet id!!!
3151 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3152
3153 // Create the Periodic Counter Selection packet
3154 Packet periodicCounterSelectionPacket(header); // Length == 0, this will disable the collection of counters
3155
3156 // Write the packet to the mock profiling connection
3157 mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket));
Finn Williams09ad6f92019-12-19 17:05:18 +00003158 profilingService.Update();
Colm Donelan2ba48d22019-11-29 09:10:59 +00003159
Finn Williams09ad6f92019-12-19 17:05:18 +00003160 // Reset the profiling service to stop any running thread
3161 options.m_EnableProfiling = false;
3162 profilingService.ResetExternalProfilingOptions(options, true);
Colm Donelan2ba48d22019-11-29 09:10:59 +00003163
3164 // Check that the expected error has occurred and logged to the standard output
3165 streamRedirector.CancelRedirect();
3166
3167 // Check that the expected error has occurred and logged to the standard output
3168 if (!boost::contains(ss.str(), "Functor with requested PacketId=999 and Version=4194304 does not exist"))
3169 {
3170 std::cout << ss.str();
3171 BOOST_FAIL("Expected string not found.");
3172 }
Colm Donelan2ba48d22019-11-29 09:10:59 +00003173}
Jim Flynn97897022020-02-02 12:52:59 +00003174
David Monahande803072020-01-30 12:44:23 +00003175BOOST_AUTO_TEST_CASE(CheckCounterIdMap)
3176{
3177 CounterIdMap counterIdMap;
3178 BOOST_CHECK_THROW(counterIdMap.GetBackendId(0), armnn::Exception);
3179 BOOST_CHECK_THROW(counterIdMap.GetGlobalId(0, armnn::profiling::BACKEND_ID), armnn::Exception);
3180
3181 uint16_t globalCounterIds = 0;
3182
3183 armnn::BackendId cpuRefId(armnn::Compute::CpuRef);
3184 armnn::BackendId cpuAccId(armnn::Compute::CpuAcc);
3185
3186 std::vector<uint16_t> cpuRefCounters = {0, 1, 2, 3};
3187 std::vector<uint16_t> cpuAccCounters = {0, 1};
3188
3189 for (uint16_t backendCounterId : cpuRefCounters)
3190 {
3191 counterIdMap.RegisterMapping(globalCounterIds, backendCounterId, cpuRefId);
3192 ++globalCounterIds;
3193 }
3194 for (uint16_t backendCounterId : cpuAccCounters)
3195 {
3196 counterIdMap.RegisterMapping(globalCounterIds, backendCounterId, cpuAccId);
3197 ++globalCounterIds;
3198 }
3199
3200 BOOST_CHECK(counterIdMap.GetBackendId(0) == (std::pair<uint16_t, armnn::BackendId>(0, cpuRefId)));
3201 BOOST_CHECK(counterIdMap.GetBackendId(1) == (std::pair<uint16_t, armnn::BackendId>(1, cpuRefId)));
3202 BOOST_CHECK(counterIdMap.GetBackendId(2) == (std::pair<uint16_t, armnn::BackendId>(2, cpuRefId)));
3203 BOOST_CHECK(counterIdMap.GetBackendId(3) == (std::pair<uint16_t, armnn::BackendId>(3, cpuRefId)));
3204 BOOST_CHECK(counterIdMap.GetBackendId(4) == (std::pair<uint16_t, armnn::BackendId>(0, cpuAccId)));
3205 BOOST_CHECK(counterIdMap.GetBackendId(5) == (std::pair<uint16_t, armnn::BackendId>(1, cpuAccId)));
3206
3207 BOOST_CHECK(counterIdMap.GetGlobalId(0, cpuRefId) == 0);
3208 BOOST_CHECK(counterIdMap.GetGlobalId(1, cpuRefId) == 1);
3209 BOOST_CHECK(counterIdMap.GetGlobalId(2, cpuRefId) == 2);
3210 BOOST_CHECK(counterIdMap.GetGlobalId(3, cpuRefId) == 3);
3211 BOOST_CHECK(counterIdMap.GetGlobalId(0, cpuAccId) == 4);
3212 BOOST_CHECK(counterIdMap.GetGlobalId(1, cpuAccId) == 5);
3213}
Colm Donelan2ba48d22019-11-29 09:10:59 +00003214
Jim Flynn97897022020-02-02 12:52:59 +00003215BOOST_AUTO_TEST_CASE(CheckRegisterBackendCounters)
3216{
3217 uint16_t globalCounterIds = armnn::profiling::INFERENCES_RUN;
3218 armnn::BackendId cpuRefId(armnn::Compute::CpuRef);
3219
3220 RegisterBackendCounters registerBackendCounters(globalCounterIds, cpuRefId);
3221
3222 // Reset the profiling service to the uninitialized state
3223 armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3224 options.m_EnableProfiling = true;
3225 ProfilingService& profilingService = ProfilingService::Instance();
3226 profilingService.ResetExternalProfilingOptions(options, true);
3227
3228 BOOST_CHECK(profilingService.GetCounterDirectory().GetCategories().empty());
3229 registerBackendCounters.RegisterCategory("categoryOne");
3230 auto categoryOnePtr = profilingService.GetCounterDirectory().GetCategory("categoryOne");
3231 BOOST_CHECK(categoryOnePtr);
3232
3233 BOOST_CHECK(profilingService.GetCounterDirectory().GetDevices().empty());
3234 globalCounterIds = registerBackendCounters.RegisterDevice("deviceOne");
3235 auto deviceOnePtr = profilingService.GetCounterDirectory().GetDevice(globalCounterIds);
3236 BOOST_CHECK(deviceOnePtr);
3237 BOOST_CHECK(deviceOnePtr->m_Name == "deviceOne");
3238
3239 BOOST_CHECK(profilingService.GetCounterDirectory().GetCounterSets().empty());
3240 globalCounterIds = registerBackendCounters.RegisterCounterSet("counterSetOne");
3241 auto counterSetOnePtr = profilingService.GetCounterDirectory().GetCounterSet(globalCounterIds);
3242 BOOST_CHECK(counterSetOnePtr);
3243 BOOST_CHECK(counterSetOnePtr->m_Name == "counterSetOne");
3244
3245 uint16_t newGlobalCounterId = registerBackendCounters.RegisterCounter(0,
3246 "categoryOne",
3247 0,
3248 0,
3249 1.f,
3250 "CounterOne",
3251 "first test counter");
3252 BOOST_CHECK(newGlobalCounterId = armnn::profiling::INFERENCES_RUN + 1);
3253 uint16_t mappedGlobalId = profilingService.GetCounterMappings().GetGlobalId(0, cpuRefId);
3254 BOOST_CHECK(mappedGlobalId == newGlobalCounterId);
3255 auto backendMapping = profilingService.GetCounterMappings().GetBackendId(newGlobalCounterId);
3256 BOOST_CHECK(backendMapping.first == 0);
3257 BOOST_CHECK(backendMapping.second == cpuRefId);
3258
3259 // Reset the profiling service to stop any running thread
3260 options.m_EnableProfiling = false;
3261 profilingService.ResetExternalProfilingOptions(options, true);
3262}
3263
James Conroy2dcd3fe2020-02-06 18:34:52 +00003264BOOST_AUTO_TEST_CASE(CheckCounterStatusQuery)
3265{
3266 armnn::IRuntime::CreationOptions options;
3267 options.m_ProfilingOptions.m_EnableProfiling = true;
3268
3269 // Reset the profiling service to the uninitialized state
3270 ProfilingService& profilingService = ProfilingService::Instance();
3271 profilingService.ResetExternalProfilingOptions(options.m_ProfilingOptions, true);
3272
3273 const armnn::BackendId cpuRefId(armnn::Compute::CpuRef);
3274 const armnn::BackendId cpuAccId(armnn::Compute::CpuAcc);
3275
3276 // Create BackendProfiling for each backend
3277 BackendProfiling backendProfilingCpuRef(options, profilingService, cpuRefId);
3278 BackendProfiling backendProfilingCpuAcc(options, profilingService, cpuAccId);
3279
3280 uint16_t initialNumGlobalCounterIds = armnn::profiling::INFERENCES_RUN;
3281
3282 // Create RegisterBackendCounters for CpuRef
3283 RegisterBackendCounters registerBackendCountersCpuRef(initialNumGlobalCounterIds, cpuRefId);
3284
3285 // Create 'testCategory' in CounterDirectory (backend agnostic)
3286 BOOST_CHECK(profilingService.GetCounterDirectory().GetCategories().empty());
3287 registerBackendCountersCpuRef.RegisterCategory("testCategory");
3288 auto categoryOnePtr = profilingService.GetCounterDirectory().GetCategory("testCategory");
3289 BOOST_CHECK(categoryOnePtr);
3290
3291 // Counters:
3292 // Global | Local | Backend
3293 // 5 | 0 | CpuRef
3294 // 6 | 1 | CpuRef
3295 // 7 | 1 | CpuAcc
3296
3297 std::vector<uint16_t> cpuRefCounters = {0, 1};
3298 std::vector<uint16_t> cpuAccCounters = {0};
3299
3300 // Register the backend counters for CpuRef and validate GetGlobalId and GetBackendId
3301 uint16_t currentNumGlobalCounterIds = registerBackendCountersCpuRef.RegisterCounter(
3302 0, "testCategory", 0, 0, 1.f, "CpuRefCounter0", "Zeroth CpuRef Counter");
3303 BOOST_CHECK(currentNumGlobalCounterIds == initialNumGlobalCounterIds + 1);
3304 uint16_t mappedGlobalId = profilingService.GetCounterMappings().GetGlobalId(0, cpuRefId);
3305 BOOST_CHECK(mappedGlobalId == currentNumGlobalCounterIds);
3306 auto backendMapping = profilingService.GetCounterMappings().GetBackendId(currentNumGlobalCounterIds);
3307 BOOST_CHECK(backendMapping.first == 0);
3308 BOOST_CHECK(backendMapping.second == cpuRefId);
3309
3310 currentNumGlobalCounterIds = registerBackendCountersCpuRef.RegisterCounter(
3311 1, "testCategory", 0, 0, 1.f, "CpuRefCounter1", "First CpuRef Counter");
3312 BOOST_CHECK(currentNumGlobalCounterIds == initialNumGlobalCounterIds + 2);
3313 mappedGlobalId = profilingService.GetCounterMappings().GetGlobalId(1, cpuRefId);
3314 BOOST_CHECK(mappedGlobalId == currentNumGlobalCounterIds);
3315 backendMapping = profilingService.GetCounterMappings().GetBackendId(currentNumGlobalCounterIds);
3316 BOOST_CHECK(backendMapping.first == 1);
3317 BOOST_CHECK(backendMapping.second == cpuRefId);
3318
3319 // Create RegisterBackendCounters for CpuAcc
3320 RegisterBackendCounters registerBackendCountersCpuAcc(currentNumGlobalCounterIds, cpuAccId);
3321
3322 // Register the backend counter for CpuAcc and validate GetGlobalId and GetBackendId
3323 currentNumGlobalCounterIds = registerBackendCountersCpuAcc.RegisterCounter(
3324 0, "testCategory", 0, 0, 1.f, "CpuAccCounter0", "Zeroth CpuAcc Counter");
3325 BOOST_CHECK(currentNumGlobalCounterIds == initialNumGlobalCounterIds + 3);
3326 mappedGlobalId = profilingService.GetCounterMappings().GetGlobalId(0, cpuAccId);
3327 BOOST_CHECK(mappedGlobalId == currentNumGlobalCounterIds);
3328 backendMapping = profilingService.GetCounterMappings().GetBackendId(currentNumGlobalCounterIds);
3329 BOOST_CHECK(backendMapping.first == 0);
3330 BOOST_CHECK(backendMapping.second == cpuAccId);
3331
3332 // Create vectors for active counters
3333 const std::vector<uint16_t> activeGlobalCounterIds = {5}; // CpuRef(0) activated
3334 const std::vector<uint16_t> newActiveGlobalCounterIds = {6, 7}; // CpuRef(0) and CpuAcc(1) activated
3335
3336 const uint32_t capturePeriod = 200;
3337 const uint32_t newCapturePeriod = 100;
3338
3339 // Set capture period and active counters in CaptureData
3340 profilingService.SetCaptureData(capturePeriod, activeGlobalCounterIds);
3341
3342 // Get vector of active counters for CpuRef and CpuAcc backends
3343 std::vector<CounterStatus> cpuRefCounterStatus = backendProfilingCpuRef.GetActiveCounters();
3344 std::vector<CounterStatus> cpuAccCounterStatus = backendProfilingCpuAcc.GetActiveCounters();
3345 BOOST_CHECK_EQUAL(cpuRefCounterStatus.size(), 1);
3346 BOOST_CHECK_EQUAL(cpuAccCounterStatus.size(), 0);
3347
3348 // Check active CpuRef counter
3349 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_GlobalCounterId, activeGlobalCounterIds[0]);
3350 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_BackendCounterId, cpuRefCounters[0]);
3351 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_SamplingRateInMicroseconds, capturePeriod);
3352 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_Enabled, true);
3353
3354 // Check inactive CpuRef counter
3355 CounterStatus inactiveCpuRefCounter = backendProfilingCpuRef.GetCounterStatus(cpuRefCounters[1]);
3356 BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_GlobalCounterId, 6);
3357 BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_BackendCounterId, cpuRefCounters[1]);
3358 BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_SamplingRateInMicroseconds, 0);
3359 BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_Enabled, false);
3360
3361 // Check inactive CpuAcc counter
3362 CounterStatus inactiveCpuAccCounter = backendProfilingCpuAcc.GetCounterStatus(cpuAccCounters[0]);
3363 BOOST_CHECK_EQUAL(inactiveCpuAccCounter.m_GlobalCounterId, 7);
3364 BOOST_CHECK_EQUAL(inactiveCpuAccCounter.m_BackendCounterId, cpuAccCounters[0]);
3365 BOOST_CHECK_EQUAL(inactiveCpuAccCounter.m_SamplingRateInMicroseconds, 0);
3366 BOOST_CHECK_EQUAL(inactiveCpuAccCounter.m_Enabled, false);
3367
3368 // Set new capture period and new active counters in CaptureData
3369 profilingService.SetCaptureData(newCapturePeriod, newActiveGlobalCounterIds);
3370
3371 // Get vector of active counters for CpuRef and CpuAcc backends
3372 cpuRefCounterStatus = backendProfilingCpuRef.GetActiveCounters();
3373 cpuAccCounterStatus = backendProfilingCpuAcc.GetActiveCounters();
3374 BOOST_CHECK_EQUAL(cpuRefCounterStatus.size(), 1);
3375 BOOST_CHECK_EQUAL(cpuAccCounterStatus.size(), 1);
3376
3377 // Check active CpuRef counter
3378 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_GlobalCounterId, newActiveGlobalCounterIds[0]);
3379 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_BackendCounterId, cpuRefCounters[1]);
3380 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_SamplingRateInMicroseconds, newCapturePeriod);
3381 BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_Enabled, true);
3382
3383 // Check active CpuAcc counter
3384 BOOST_CHECK_EQUAL(cpuAccCounterStatus[0].m_GlobalCounterId, newActiveGlobalCounterIds[1]);
3385 BOOST_CHECK_EQUAL(cpuAccCounterStatus[0].m_BackendCounterId, cpuAccCounters[0]);
3386 BOOST_CHECK_EQUAL(cpuAccCounterStatus[0].m_SamplingRateInMicroseconds, newCapturePeriod);
3387 BOOST_CHECK_EQUAL(cpuAccCounterStatus[0].m_Enabled, true);
3388
3389 // Check inactive CpuRef counter
3390 inactiveCpuRefCounter = backendProfilingCpuRef.GetCounterStatus(cpuRefCounters[0]);
3391 BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_GlobalCounterId, 5);
3392 BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_BackendCounterId, cpuRefCounters[0]);
3393 BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_SamplingRateInMicroseconds, 0);
3394 BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_Enabled, false);
3395
3396 // Reset the profiling service to stop any running thread
3397 options.m_ProfilingOptions.m_EnableProfiling = false;
3398 profilingService.ResetExternalProfilingOptions(options.m_ProfilingOptions, true);
3399}
3400
Francis Murtagh1f7db452019-08-14 09:49:34 +01003401BOOST_AUTO_TEST_SUITE_END()