ArmNN  NotReleased
ProfilingTests.cpp File Reference
#include "ProfilingTests.hpp"
#include <backends/BackendProfiling.hpp>
#include <CommandHandler.hpp>
#include <CommandHandlerKey.hpp>
#include <CommandHandlerRegistry.hpp>
#include <ConnectionAcknowledgedCommandHandler.hpp>
#include <CounterDirectory.hpp>
#include <CounterIdMap.hpp>
#include <EncodeVersion.hpp>
#include <Holder.hpp>
#include <ICounterValues.hpp>
#include <Packet.hpp>
#include <PacketVersionResolver.hpp>
#include <PeriodicCounterCapture.hpp>
#include <PeriodicCounterSelectionCommandHandler.hpp>
#include <ProfilingStateMachine.hpp>
#include <ProfilingUtils.hpp>
#include <RegisterBackendCounters.hpp>
#include <RequestCounterDirectoryCommandHandler.hpp>
#include <Runtime.hpp>
#include <SocketProfilingConnection.hpp>
#include <SendCounterPacket.hpp>
#include <SendThread.hpp>
#include <SendTimelinePacket.hpp>
#include <armnn/Conversion.hpp>
#include <armnn/Types.hpp>
#include <armnn/Utils.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <limits>
#include <map>
#include <random>

Go to the source code of this file.

Typedefs

using PacketType = MockProfilingConnection::PacketType
 

Functions

 BOOST_AUTO_TEST_CASE (CheckCommandHandlerKeyComparisons)
 
 BOOST_AUTO_TEST_CASE (CheckPacketKeyComparisons)
 
 BOOST_AUTO_TEST_CASE (CheckCommandHandler)
 
 BOOST_AUTO_TEST_CASE (CheckEncodeVersion)
 
 BOOST_AUTO_TEST_CASE (CheckPacketClass)
 
 BOOST_AUTO_TEST_CASE (CheckCommandHandlerFunctor)
 
 BOOST_AUTO_TEST_CASE (CheckCommandHandlerRegistry)
 
 BOOST_AUTO_TEST_CASE (CheckPacketVersionResolver)
 
void ProfilingCurrentStateThreadImpl (ProfilingStateMachine &states)
 
 BOOST_AUTO_TEST_CASE (CheckProfilingStateMachine)
 
void CaptureDataWriteThreadImpl (Holder &holder, uint32_t capturePeriod, const std::vector< uint16_t > &counterIds)
 
void CaptureDataReadThreadImpl (const Holder &holder, CaptureData &captureData)
 
 BOOST_AUTO_TEST_CASE (CheckCaptureDataHolder)
 
 BOOST_AUTO_TEST_CASE (CaptureDataMethods)
 
 BOOST_AUTO_TEST_CASE (CheckProfilingServiceDisabled)
 
 BOOST_AUTO_TEST_CASE (CheckProfilingServiceCounterDirectory)
 
 BOOST_AUTO_TEST_CASE (CheckProfilingServiceCounterValues)
 
 BOOST_AUTO_TEST_CASE (CheckProfilingObjectUids)
 
 BOOST_AUTO_TEST_CASE (CheckCounterDirectoryRegisterCategory)
 
 BOOST_AUTO_TEST_CASE (CheckCounterDirectoryRegisterDevice)
 
 BOOST_AUTO_TEST_CASE (CheckCounterDirectoryRegisterCounterSet)
 
 BOOST_AUTO_TEST_CASE (CheckCounterDirectoryRegisterCounter)
 
 BOOST_AUTO_TEST_CASE (CounterSelectionCommandHandlerParseData)
 
 BOOST_AUTO_TEST_CASE (CheckConnectionAcknowledged)
 
 BOOST_AUTO_TEST_CASE (CheckSocketProfilingConnection)
 
 BOOST_AUTO_TEST_CASE (SwTraceIsValidCharTest)
 
 BOOST_AUTO_TEST_CASE (SwTraceIsValidNameCharTest)
 
 BOOST_AUTO_TEST_CASE (IsValidSwTraceStringTest)
 
 BOOST_AUTO_TEST_CASE (IsValidSwTraceNameStringTest)
 
template<typename SwTracePolicy >
void StringToSwTraceStringTestHelper (const std::string &testString, std::vector< uint32_t > buffer, size_t expectedSize)
 
 BOOST_AUTO_TEST_CASE (StringToSwTraceStringTest)
 
 BOOST_AUTO_TEST_CASE (StringToSwTraceNameStringTest)
 
 BOOST_AUTO_TEST_CASE (CheckPeriodicCounterCaptureThread)
 
 BOOST_AUTO_TEST_CASE (RequestCounterDirectoryCommandHandlerTest1)
 
 BOOST_AUTO_TEST_CASE (RequestCounterDirectoryCommandHandlerTest2)
 
 BOOST_AUTO_TEST_CASE (CheckProfilingServiceGoodConnectionAcknowledgedPacket)
 
 BOOST_AUTO_TEST_CASE (CheckProfilingServiceGoodRequestCounterDirectoryPacket)
 
 BOOST_AUTO_TEST_CASE (CheckProfilingServiceBadPeriodicCounterSelectionPacketInvalidCounterUid)
 
 BOOST_AUTO_TEST_CASE (CheckProfilingServiceGoodPeriodicCounterSelectionPacketNoCounters)
 
 BOOST_AUTO_TEST_CASE (CheckProfilingServiceGoodPeriodicCounterSelectionPacketSingleCounter)
 
 BOOST_AUTO_TEST_CASE (CheckProfilingServiceGoodPeriodicCounterSelectionPacketMultipleCounters)
 
 BOOST_AUTO_TEST_CASE (CheckProfilingServiceDisconnect)
 
 BOOST_AUTO_TEST_CASE (CheckProfilingServiceGoodPerJobCounterSelectionPacket)
 
 BOOST_AUTO_TEST_CASE (CheckConfigureProfilingServiceOn)
 
 BOOST_AUTO_TEST_CASE (CheckConfigureProfilingServiceOff)
 
 BOOST_AUTO_TEST_CASE (CheckProfilingServiceEnabled)
 
 BOOST_AUTO_TEST_CASE (CheckProfilingServiceEnabledRuntime)
 
 BOOST_AUTO_TEST_CASE (CheckProfilingServiceBadConnectionAcknowledgedPacket)
 
 BOOST_AUTO_TEST_CASE (CheckProfilingServiceBadRequestCounterDirectoryPacket)
 
 BOOST_AUTO_TEST_CASE (CheckProfilingServiceBadPeriodicCounterSelectionPacket)
 
 BOOST_AUTO_TEST_CASE (CheckCounterIdMap)
 
 BOOST_AUTO_TEST_CASE (CheckRegisterBackendCounters)
 
 BOOST_AUTO_TEST_CASE (CheckCounterStatusQuery)
 
 BOOST_AUTO_TEST_CASE (CheckRegisterCounters)
 

Typedef Documentation

◆ PacketType

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/50]

BOOST_AUTO_TEST_CASE ( CheckCommandHandlerKeyComparisons  )

Definition at line 53 of file ProfilingTests.cpp.

References BOOST_CHECK(), CommandHandlerKey::GetPacketId(), and CommandHandlerKey::GetVersion().

54 {
55  CommandHandlerKey testKey1_0(1, 1, 1);
56  CommandHandlerKey testKey1_1(1, 1, 1);
57  CommandHandlerKey testKey1_2(1, 2, 1);
58 
59  CommandHandlerKey testKey0(0, 1, 1);
60  CommandHandlerKey testKey1(0, 1, 1);
61  CommandHandlerKey testKey2(0, 1, 1);
62  CommandHandlerKey testKey3(0, 0, 0);
63  CommandHandlerKey testKey4(0, 2, 2);
64  CommandHandlerKey testKey5(0, 0, 2);
65 
66  BOOST_CHECK(testKey1_0 > testKey0);
67  BOOST_CHECK(testKey1_0 == testKey1_1);
68  BOOST_CHECK(testKey1_0 < testKey1_2);
69 
70  BOOST_CHECK(testKey1 < testKey4);
71  BOOST_CHECK(testKey1 > testKey3);
72  BOOST_CHECK(testKey1 <= testKey4);
73  BOOST_CHECK(testKey1 >= testKey3);
74  BOOST_CHECK(testKey1 <= testKey2);
75  BOOST_CHECK(testKey1 >= testKey2);
76  BOOST_CHECK(testKey1 == testKey2);
77  BOOST_CHECK(testKey1 == testKey1);
78 
79  BOOST_CHECK(!(testKey1 == testKey5));
80  BOOST_CHECK(!(testKey1 != testKey1));
81  BOOST_CHECK(testKey1 != testKey5);
82 
83  BOOST_CHECK(testKey1 == testKey2 && testKey2 == testKey1);
84  BOOST_CHECK(testKey0 == testKey1 && testKey1 == testKey2 && testKey0 == testKey2);
85 
86  BOOST_CHECK(testKey1.GetPacketId() == 1);
87  BOOST_CHECK(testKey1.GetVersion() == 1);
88 
89  std::vector<CommandHandlerKey> vect = { CommandHandlerKey(0, 0, 1), CommandHandlerKey(0, 2, 0),
90  CommandHandlerKey(0, 1, 0), CommandHandlerKey(0, 2, 1),
91  CommandHandlerKey(0, 1, 1), CommandHandlerKey(0, 0, 1),
92  CommandHandlerKey(0, 2, 0), CommandHandlerKey(0, 0, 0) };
93 
94  std::sort(vect.begin(), vect.end());
95 
96  std::vector<CommandHandlerKey> expectedVect = { CommandHandlerKey(0, 0, 0), CommandHandlerKey(0, 0, 1),
97  CommandHandlerKey(0, 0, 1), CommandHandlerKey(0, 1, 0),
98  CommandHandlerKey(0, 1, 1), CommandHandlerKey(0, 2, 0),
99  CommandHandlerKey(0, 2, 0), CommandHandlerKey(0, 2, 1) };
100 
101  BOOST_CHECK(vect == expectedVect);
102 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)

◆ BOOST_AUTO_TEST_CASE() [2/50]

BOOST_AUTO_TEST_CASE ( CheckPacketKeyComparisons  )

Definition at line 104 of file ProfilingTests.cpp.

References BOOST_CHECK().

105 {
106  PacketKey key0(0, 0);
107  PacketKey key1(0, 0);
108  PacketKey key2(0, 1);
109  PacketKey key3(0, 2);
110  PacketKey key4(1, 0);
111  PacketKey key5(1, 0);
112  PacketKey key6(1, 1);
113 
114  BOOST_CHECK(!(key0 < key1));
115  BOOST_CHECK(!(key0 > key1));
116  BOOST_CHECK(key0 <= key1);
117  BOOST_CHECK(key0 >= key1);
118  BOOST_CHECK(key0 == key1);
119  BOOST_CHECK(key0 < key2);
120  BOOST_CHECK(key2 < key3);
121  BOOST_CHECK(key3 > key0);
122  BOOST_CHECK(key4 == key5);
123  BOOST_CHECK(key4 > key0);
124  BOOST_CHECK(key5 < key6);
125  BOOST_CHECK(key5 <= key6);
126  BOOST_CHECK(key5 != key6);
127 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)

◆ BOOST_AUTO_TEST_CASE() [3/50]

BOOST_AUTO_TEST_CASE ( CheckCommandHandler  )

Definition at line 129 of file ProfilingTests.cpp.

References armnn::profiling::Active, BOOST_CHECK(), ProfilingStateMachine::GetCurrentState(), CommandHandler::IsRunning(), armnn::profiling::NotConnected, TestProfilingConnectionTimeoutError::ReadCalledCount(), CommandHandlerRegistry::RegisterFunctor(), CommandHandler::SetStopAfterTimeout(), CommandHandler::Start(), CommandHandler::Stop(), ProfilingStateMachine::TransitionToState(), and armnn::profiling::WaitingForAck.

130 {
131  PacketVersionResolver packetVersionResolver;
132  ProfilingStateMachine profilingStateMachine;
133 
134  TestProfilingConnectionBase testProfilingConnectionBase;
135  TestProfilingConnectionTimeoutError testProfilingConnectionTimeOutError;
136  TestProfilingConnectionArmnnError testProfilingConnectionArmnnError;
137  CounterDirectory counterDirectory;
138  MockBufferManager mockBuffer(1024);
139  SendCounterPacket sendCounterPacket(mockBuffer);
140  SendThread sendThread(profilingStateMachine, mockBuffer, sendCounterPacket);
141  SendTimelinePacket sendTimelinePacket(mockBuffer);
142 
143  ConnectionAcknowledgedCommandHandler connectionAcknowledgedCommandHandler(0, 1, 4194304, counterDirectory,
144  sendCounterPacket, sendTimelinePacket,
145  profilingStateMachine);
146  CommandHandlerRegistry commandHandlerRegistry;
147 
148  commandHandlerRegistry.RegisterFunctor(&connectionAcknowledgedCommandHandler);
149 
150  profilingStateMachine.TransitionToState(ProfilingState::NotConnected);
151  profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck);
152 
153  CommandHandler commandHandler0(1, true, commandHandlerRegistry, packetVersionResolver);
154 
155  // This should start the command handler thread return the connection ack and put the profiling
156  // service into active state.
157  commandHandler0.Start(testProfilingConnectionBase);
158  // Try to start the send thread many times, it must only start once
159  commandHandler0.Start(testProfilingConnectionBase);
160 
161  // This could take up to 20mSec but we'll check often.
162  for (int i = 0; i < 10; i++)
163  {
164  if (profilingStateMachine.GetCurrentState() == ProfilingState::Active)
165  {
166  break;
167  }
168  std::this_thread::sleep_for(std::chrono::milliseconds(2));
169  }
170 
171  BOOST_CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::Active);
172 
173  // Close the thread again.
174  commandHandler0.Stop();
175 
176  profilingStateMachine.TransitionToState(ProfilingState::NotConnected);
177  profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck);
178 
179  // In this test we'll simulate a timeout without a connection ack packet being received.
180  // Stop after timeout is set so we expect the command handler to stop almost immediately.
181  CommandHandler commandHandler1(1, true, commandHandlerRegistry, packetVersionResolver);
182 
183  commandHandler1.Start(testProfilingConnectionTimeOutError);
184  // Wait until we know a timeout exception has been sent at least once.
185  for (int i = 0; i < 10; i++)
186  {
187  if (testProfilingConnectionTimeOutError.ReadCalledCount())
188  {
189  break;
190  }
191  std::this_thread::sleep_for(std::chrono::milliseconds(2));
192  }
193 
194  // The command handler loop should have stopped after the timeout.
195  // wait for the timeout exception to be processed and the loop to break.
196  uint32_t timeout = 50;
197  uint32_t timeSlept = 0;
198  while (commandHandler1.IsRunning())
199  {
200  if (timeSlept >= timeout)
201  {
202  BOOST_FAIL("Timeout: The command handler loop did not stop after the timeout");
203  }
204  std::this_thread::sleep_for(std::chrono::milliseconds(1));
205  timeSlept ++;
206  }
207 
208  commandHandler1.Stop();
209  // The state machine should never have received the ack so will still be in WaitingForAck.
210  BOOST_CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::WaitingForAck);
211 
212  // Now try sending a bad connection acknowledged packet
213  TestProfilingConnectionBadAckPacket testProfilingConnectionBadAckPacket;
214  commandHandler1.Start(testProfilingConnectionBadAckPacket);
215  commandHandler1.Stop();
216  // This should also not change the state machine
217  BOOST_CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::WaitingForAck);
218 
219  // Disable stop after timeout and now commandHandler1 should persist after a timeout
220  commandHandler1.SetStopAfterTimeout(false);
221  // Restart the thread.
222  commandHandler1.Start(testProfilingConnectionTimeOutError);
223 
224  // Wait for at the three timeouts and the ack to be sent.
225  for (int i = 0; i < 10; i++)
226  {
227  if (testProfilingConnectionTimeOutError.ReadCalledCount() > 3)
228  {
229  break;
230  }
231  std::this_thread::sleep_for(std::chrono::milliseconds(2));
232  }
233  commandHandler1.Stop();
234 
235  // Even after the 3 exceptions the ack packet should have transitioned the command handler to active.
236  BOOST_CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::Active);
237 
238  // A command handler that gets exceptions other than timeouts should keep going.
239  CommandHandler commandHandler2(1, false, commandHandlerRegistry, packetVersionResolver);
240 
241  commandHandler2.Start(testProfilingConnectionArmnnError);
242 
243  // Wait for two exceptions to be thrown.
244  for (int i = 0; i < 10; i++)
245  {
246  if (testProfilingConnectionTimeOutError.ReadCalledCount() >= 2)
247  {
248  break;
249  }
250  std::this_thread::sleep_for(std::chrono::milliseconds(2));
251  }
252 
253  BOOST_CHECK(commandHandler2.IsRunning());
254  commandHandler2.Stop();
255 }
void TransitionToState(ProfilingState newState)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
void RegisterFunctor(CommandHandlerFunctor *functor, uint32_t familyId, uint32_t packetId, uint32_t version)

◆ BOOST_AUTO_TEST_CASE() [4/50]

BOOST_AUTO_TEST_CASE ( CheckEncodeVersion  )

Definition at line 257 of file ProfilingTests.cpp.

References BOOST_CHECK(), Version::GetMajor(), Version::GetMinor(), and Version::GetPatch().

258 {
259  Version version1(12);
260 
261  BOOST_CHECK(version1.GetMajor() == 0);
262  BOOST_CHECK(version1.GetMinor() == 0);
263  BOOST_CHECK(version1.GetPatch() == 12);
264 
265  Version version2(4108);
266 
267  BOOST_CHECK(version2.GetMajor() == 0);
268  BOOST_CHECK(version2.GetMinor() == 1);
269  BOOST_CHECK(version2.GetPatch() == 12);
270 
271  Version version3(4198412);
272 
273  BOOST_CHECK(version3.GetMajor() == 1);
274  BOOST_CHECK(version3.GetMinor() == 1);
275  BOOST_CHECK(version3.GetPatch() == 12);
276 
277  Version version4(0);
278 
279  BOOST_CHECK(version4.GetMajor() == 0);
280  BOOST_CHECK(version4.GetMinor() == 0);
281  BOOST_CHECK(version4.GetPatch() == 0);
282 
283  Version version5(1, 0, 0);
284  BOOST_CHECK(version5.GetEncodedValue() == 4194304);
285 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)

◆ BOOST_AUTO_TEST_CASE() [5/50]

BOOST_AUTO_TEST_CASE ( CheckPacketClass  )

Definition at line 287 of file ProfilingTests.cpp.

References BOOST_CHECK(), Packet::GetData(), Packet::GetHeader(), Packet::GetLength(), Packet::GetPacketClass(), Packet::GetPacketFamily(), Packet::GetPacketId(), and Packet::GetPacketType().

288 {
289  uint32_t length = 4;
290  std::unique_ptr<unsigned char[]> packetData0 = std::make_unique<unsigned char[]>(length);
291  std::unique_ptr<unsigned char[]> packetData1 = std::make_unique<unsigned char[]>(0);
292  std::unique_ptr<unsigned char[]> nullPacketData;
293 
294  Packet packetTest0(472580096, length, packetData0);
295 
296  BOOST_CHECK(packetTest0.GetHeader() == 472580096);
297  BOOST_CHECK(packetTest0.GetPacketFamily() == 7);
298  BOOST_CHECK(packetTest0.GetPacketId() == 43);
299  BOOST_CHECK(packetTest0.GetLength() == length);
300  BOOST_CHECK(packetTest0.GetPacketType() == 3);
301  BOOST_CHECK(packetTest0.GetPacketClass() == 5);
302 
303  BOOST_CHECK_THROW(Packet packetTest1(472580096, 0, packetData1), armnn::Exception);
304  BOOST_CHECK_NO_THROW(Packet packetTest2(472580096, 0, nullPacketData));
305 
306  Packet packetTest3(472580096, 0, nullPacketData);
307  BOOST_CHECK(packetTest3.GetLength() == 0);
308  BOOST_CHECK(packetTest3.GetData() == nullptr);
309 
310  const unsigned char* packetTest0Data = packetTest0.GetData();
311  Packet packetTest4(std::move(packetTest0));
312 
313  BOOST_CHECK(packetTest0.GetData() == nullptr);
314  BOOST_CHECK(packetTest4.GetData() == packetTest0Data);
315 
316  BOOST_CHECK(packetTest4.GetHeader() == 472580096);
317  BOOST_CHECK(packetTest4.GetPacketFamily() == 7);
318  BOOST_CHECK(packetTest4.GetPacketId() == 43);
319  BOOST_CHECK(packetTest4.GetLength() == length);
320  BOOST_CHECK(packetTest4.GetPacketType() == 3);
321  BOOST_CHECK(packetTest4.GetPacketClass() == 5);
322 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46

◆ BOOST_AUTO_TEST_CASE() [6/50]

BOOST_AUTO_TEST_CASE ( CheckCommandHandlerFunctor  )

Definition at line 324 of file ProfilingTests.cpp.

References BOOST_CHECK(), TestFunctorA::GetCount(), CommandHandlerFunctor::GetFamilyId(), Packet::GetPacketFamily(), CommandHandlerFunctor::GetPacketId(), Packet::GetPacketId(), and CommandHandlerFunctor::GetVersion().

325 {
326  // Hard code the version as it will be the same during a single profiling session
327  uint32_t version = 1;
328 
329  TestFunctorA testFunctorA(7, 461, version);
330  TestFunctorB testFunctorB(8, 963, version);
331  TestFunctorC testFunctorC(5, 983, version);
332 
333  CommandHandlerKey keyA(testFunctorA.GetFamilyId(), testFunctorA.GetPacketId(), testFunctorA.GetVersion());
334  CommandHandlerKey keyB(testFunctorB.GetFamilyId(), testFunctorB.GetPacketId(), testFunctorB.GetVersion());
335  CommandHandlerKey keyC(testFunctorC.GetFamilyId(), testFunctorC.GetPacketId(), testFunctorC.GetVersion());
336 
337  // Create the unwrapped map to simulate the Command Handler Registry
338  std::map<CommandHandlerKey, CommandHandlerFunctor*> registry;
339 
340  registry.insert(std::make_pair(keyB, &testFunctorB));
341  registry.insert(std::make_pair(keyA, &testFunctorA));
342  registry.insert(std::make_pair(keyC, &testFunctorC));
343 
344  // Check the order of the map is correct
345  auto it = registry.begin();
346  BOOST_CHECK(it->first == keyC); // familyId == 5
347  it++;
348  BOOST_CHECK(it->first == keyA); // familyId == 7
349  it++;
350  BOOST_CHECK(it->first == keyB); // familyId == 8
351 
352  std::unique_ptr<unsigned char[]> packetDataA;
353  std::unique_ptr<unsigned char[]> packetDataB;
354  std::unique_ptr<unsigned char[]> packetDataC;
355 
356  Packet packetA(500000000, 0, packetDataA);
357  Packet packetB(600000000, 0, packetDataB);
358  Packet packetC(400000000, 0, packetDataC);
359 
360  // Check the correct operator of derived class is called
361  registry.at(CommandHandlerKey(packetA.GetPacketFamily(), packetA.GetPacketId(), version))->operator()(packetA);
362  BOOST_CHECK(testFunctorA.GetCount() == 1);
363  BOOST_CHECK(testFunctorB.GetCount() == 0);
364  BOOST_CHECK(testFunctorC.GetCount() == 0);
365 
366  registry.at(CommandHandlerKey(packetB.GetPacketFamily(), packetB.GetPacketId(), version))->operator()(packetB);
367  BOOST_CHECK(testFunctorA.GetCount() == 1);
368  BOOST_CHECK(testFunctorB.GetCount() == 1);
369  BOOST_CHECK(testFunctorC.GetCount() == 0);
370 
371  registry.at(CommandHandlerKey(packetC.GetPacketFamily(), packetC.GetPacketId(), version))->operator()(packetC);
372  BOOST_CHECK(testFunctorA.GetCount() == 1);
373  BOOST_CHECK(testFunctorB.GetCount() == 1);
374  BOOST_CHECK(testFunctorC.GetCount() == 1);
375 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)

◆ BOOST_AUTO_TEST_CASE() [7/50]

BOOST_AUTO_TEST_CASE ( CheckCommandHandlerRegistry  )

Definition at line 377 of file ProfilingTests.cpp.

References BOOST_CHECK(), TestFunctorA::GetCount(), CommandHandlerFunctor::GetFamilyId(), CommandHandlerRegistry::GetFunctor(), Packet::GetPacketFamily(), CommandHandlerFunctor::GetPacketId(), Packet::GetPacketId(), and CommandHandlerRegistry::RegisterFunctor().

378 {
379  // Hard code the version as it will be the same during a single profiling session
380  uint32_t version = 1;
381 
382  TestFunctorA testFunctorA(7, 461, version);
383  TestFunctorB testFunctorB(8, 963, version);
384  TestFunctorC testFunctorC(5, 983, version);
385 
386  // Create the Command Handler Registry
387  CommandHandlerRegistry registry;
388 
389  // Register multiple different derived classes
390  registry.RegisterFunctor(&testFunctorA);
391  registry.RegisterFunctor(&testFunctorB);
392  registry.RegisterFunctor(&testFunctorC);
393 
394  std::unique_ptr<unsigned char[]> packetDataA;
395  std::unique_ptr<unsigned char[]> packetDataB;
396  std::unique_ptr<unsigned char[]> packetDataC;
397 
398  Packet packetA(500000000, 0, packetDataA);
399  Packet packetB(600000000, 0, packetDataB);
400  Packet packetC(400000000, 0, packetDataC);
401 
402  // Check the correct operator of derived class is called
403  registry.GetFunctor(packetA.GetPacketFamily(), packetA.GetPacketId(), version)->operator()(packetA);
404  BOOST_CHECK(testFunctorA.GetCount() == 1);
405  BOOST_CHECK(testFunctorB.GetCount() == 0);
406  BOOST_CHECK(testFunctorC.GetCount() == 0);
407 
408  registry.GetFunctor(packetB.GetPacketFamily(), packetB.GetPacketId(), version)->operator()(packetB);
409  BOOST_CHECK(testFunctorA.GetCount() == 1);
410  BOOST_CHECK(testFunctorB.GetCount() == 1);
411  BOOST_CHECK(testFunctorC.GetCount() == 0);
412 
413  registry.GetFunctor(packetC.GetPacketFamily(), packetC.GetPacketId(), version)->operator()(packetC);
414  BOOST_CHECK(testFunctorA.GetCount() == 1);
415  BOOST_CHECK(testFunctorB.GetCount() == 1);
416  BOOST_CHECK(testFunctorC.GetCount() == 1);
417 
418  // Re-register an existing key with a new function
419  registry.RegisterFunctor(&testFunctorC, testFunctorA.GetFamilyId(), testFunctorA.GetPacketId(), version);
420  registry.GetFunctor(packetA.GetPacketFamily(), packetA.GetPacketId(), version)->operator()(packetC);
421  BOOST_CHECK(testFunctorA.GetCount() == 1);
422  BOOST_CHECK(testFunctorB.GetCount() == 1);
423  BOOST_CHECK(testFunctorC.GetCount() == 2);
424 
425  // Check that non-existent key returns nullptr for its functor
426  BOOST_CHECK_THROW(registry.GetFunctor(0, 0, 0), armnn::Exception);
427 }
CommandHandlerFunctor * GetFunctor(uint32_t familyId, uint32_t packetId, uint32_t version) const
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
void RegisterFunctor(CommandHandlerFunctor *functor, uint32_t familyId, uint32_t packetId, uint32_t version)
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46

◆ BOOST_AUTO_TEST_CASE() [8/50]

BOOST_AUTO_TEST_CASE ( CheckPacketVersionResolver  )

Definition at line 429 of file ProfilingTests.cpp.

References PacketVersionResolver::ResolvePacketVersion().

430 {
431  // Set up random number generator for generating packetId values
432  std::random_device device;
433  std::mt19937 generator(device());
434  std::uniform_int_distribution<uint32_t> distribution(std::numeric_limits<uint32_t>::min(),
435  std::numeric_limits<uint32_t>::max());
436 
437  // NOTE: Expected version is always 1.0.0, regardless of packetId
438  const Version expectedVersion(1, 0, 0);
439 
440  PacketVersionResolver packetVersionResolver;
441 
442  constexpr unsigned int numTests = 10u;
443 
444  for (unsigned int i = 0u; i < numTests; ++i)
445  {
446  const uint32_t familyId = distribution(generator);
447  const uint32_t packetId = distribution(generator);
448  Version resolvedVersion = packetVersionResolver.ResolvePacketVersion(familyId, packetId);
449 
450  BOOST_TEST(resolvedVersion == expectedVersion);
451  }
452 }
Version ResolvePacketVersion(uint32_t familyId, uint32_t packetId) const

◆ BOOST_AUTO_TEST_CASE() [9/50]

BOOST_AUTO_TEST_CASE ( CheckProfilingStateMachine  )

Definition at line 461 of file ProfilingTests.cpp.

References armnn::profiling::Active, BOOST_CHECK(), ProfilingStateMachine::GetCurrentState(), armnn::profiling::NotConnected, ProfilingCurrentStateThreadImpl(), ProfilingStateMachine::TransitionToState(), armnn::profiling::Uninitialised, and armnn::profiling::WaitingForAck.

462 {
463  ProfilingStateMachine profilingState1(ProfilingState::Uninitialised);
464  profilingState1.TransitionToState(ProfilingState::Uninitialised);
465  BOOST_CHECK(profilingState1.GetCurrentState() == ProfilingState::Uninitialised);
466 
467  ProfilingStateMachine profilingState2(ProfilingState::Uninitialised);
468  profilingState2.TransitionToState(ProfilingState::NotConnected);
469  BOOST_CHECK(profilingState2.GetCurrentState() == ProfilingState::NotConnected);
470 
471  ProfilingStateMachine profilingState3(ProfilingState::NotConnected);
472  profilingState3.TransitionToState(ProfilingState::NotConnected);
473  BOOST_CHECK(profilingState3.GetCurrentState() == ProfilingState::NotConnected);
474 
475  ProfilingStateMachine profilingState4(ProfilingState::NotConnected);
476  profilingState4.TransitionToState(ProfilingState::WaitingForAck);
477  BOOST_CHECK(profilingState4.GetCurrentState() == ProfilingState::WaitingForAck);
478 
479  ProfilingStateMachine profilingState5(ProfilingState::WaitingForAck);
480  profilingState5.TransitionToState(ProfilingState::WaitingForAck);
481  BOOST_CHECK(profilingState5.GetCurrentState() == ProfilingState::WaitingForAck);
482 
483  ProfilingStateMachine profilingState6(ProfilingState::WaitingForAck);
484  profilingState6.TransitionToState(ProfilingState::Active);
485  BOOST_CHECK(profilingState6.GetCurrentState() == ProfilingState::Active);
486 
487  ProfilingStateMachine profilingState7(ProfilingState::Active);
488  profilingState7.TransitionToState(ProfilingState::NotConnected);
489  BOOST_CHECK(profilingState7.GetCurrentState() == ProfilingState::NotConnected);
490 
491  ProfilingStateMachine profilingState8(ProfilingState::Active);
492  profilingState8.TransitionToState(ProfilingState::Active);
493  BOOST_CHECK(profilingState8.GetCurrentState() == ProfilingState::Active);
494 
495  ProfilingStateMachine profilingState9(ProfilingState::Uninitialised);
496  BOOST_CHECK_THROW(profilingState9.TransitionToState(ProfilingState::WaitingForAck), armnn::Exception);
497 
498  ProfilingStateMachine profilingState10(ProfilingState::Uninitialised);
499  BOOST_CHECK_THROW(profilingState10.TransitionToState(ProfilingState::Active), armnn::Exception);
500 
501  ProfilingStateMachine profilingState11(ProfilingState::NotConnected);
502  BOOST_CHECK_THROW(profilingState11.TransitionToState(ProfilingState::Uninitialised), armnn::Exception);
503 
504  ProfilingStateMachine profilingState12(ProfilingState::NotConnected);
505  BOOST_CHECK_THROW(profilingState12.TransitionToState(ProfilingState::Active), armnn::Exception);
506 
507  ProfilingStateMachine profilingState13(ProfilingState::WaitingForAck);
508  BOOST_CHECK_THROW(profilingState13.TransitionToState(ProfilingState::Uninitialised), armnn::Exception);
509 
510  ProfilingStateMachine profilingState14(ProfilingState::WaitingForAck);
511  profilingState14.TransitionToState(ProfilingState::NotConnected);
512  BOOST_CHECK(profilingState14.GetCurrentState() == ProfilingState::NotConnected);
513 
514  ProfilingStateMachine profilingState15(ProfilingState::Active);
515  BOOST_CHECK_THROW(profilingState15.TransitionToState(ProfilingState::Uninitialised), armnn::Exception);
516 
518  BOOST_CHECK_THROW(profilingState16.TransitionToState(ProfilingState::WaitingForAck), armnn::Exception);
519 
520  ProfilingStateMachine profilingState17(ProfilingState::Uninitialised);
521 
522  std::thread thread1(ProfilingCurrentStateThreadImpl, std::ref(profilingState17));
523  std::thread thread2(ProfilingCurrentStateThreadImpl, std::ref(profilingState17));
524  std::thread thread3(ProfilingCurrentStateThreadImpl, std::ref(profilingState17));
525  std::thread thread4(ProfilingCurrentStateThreadImpl, std::ref(profilingState17));
526  std::thread thread5(ProfilingCurrentStateThreadImpl, std::ref(profilingState17));
527 
528  thread1.join();
529  thread2.join();
530  thread3.join();
531  thread4.join();
532  thread5.join();
533 
534  BOOST_TEST((profilingState17.GetCurrentState() == ProfilingState::NotConnected));
535 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
void ProfilingCurrentStateThreadImpl(ProfilingStateMachine &states)

◆ BOOST_AUTO_TEST_CASE() [10/50]

BOOST_AUTO_TEST_CASE ( CheckCaptureDataHolder  )

Definition at line 547 of file ProfilingTests.cpp.

References BOOST_CHECK(), CaptureDataReadThreadImpl(), CaptureDataWriteThreadImpl(), Holder::GetCaptureData(), CaptureData::GetCapturePeriod(), and CaptureData::GetCounterIds().

548 {
549  std::map<uint32_t, std::vector<uint16_t>> periodIdMap;
550  std::vector<uint16_t> counterIds;
551  uint32_t numThreads = 10;
552  for (uint32_t i = 0; i < numThreads; ++i)
553  {
554  counterIds.emplace_back(i);
555  periodIdMap.insert(std::make_pair(i, counterIds));
556  }
557 
558  // Verify the read and write threads set the holder correctly
559  // and retrieve the expected values
560  Holder holder;
561  BOOST_CHECK((holder.GetCaptureData()).GetCapturePeriod() == 0);
562  BOOST_CHECK(((holder.GetCaptureData()).GetCounterIds()).empty());
563 
564  // Check Holder functions
565  std::thread thread1(CaptureDataWriteThreadImpl, std::ref(holder), 2, std::ref(periodIdMap[2]));
566  thread1.join();
567  BOOST_CHECK((holder.GetCaptureData()).GetCapturePeriod() == 2);
568  BOOST_CHECK((holder.GetCaptureData()).GetCounterIds() == periodIdMap[2]);
569  // NOTE: now that we have some initial values in the holder we don't have to worry
570  // in the multi-threaded section below about a read thread accessing the holder
571  // before any write thread has gotten to it so we read period = 0, counterIds empty
572  // instead of period = 0, counterIds = {0} as will the case when write thread 0
573  // has executed.
574 
575  CaptureData captureData;
576  std::thread thread2(CaptureDataReadThreadImpl, std::ref(holder), std::ref(captureData));
577  thread2.join();
578  BOOST_CHECK(captureData.GetCapturePeriod() == 2);
579  BOOST_CHECK(captureData.GetCounterIds() == periodIdMap[2]);
580 
581  std::map<uint32_t, CaptureData> captureDataIdMap;
582  for (uint32_t i = 0; i < numThreads; ++i)
583  {
584  CaptureData perThreadCaptureData;
585  captureDataIdMap.insert(std::make_pair(i, perThreadCaptureData));
586  }
587 
588  std::vector<std::thread> threadsVect;
589  std::vector<std::thread> readThreadsVect;
590  for (uint32_t i = 0; i < numThreads; ++i)
591  {
592  threadsVect.emplace_back(
593  std::thread(CaptureDataWriteThreadImpl, std::ref(holder), i, std::ref(periodIdMap[i])));
594 
595  // Verify that the CaptureData goes into the thread in a virgin state
596  BOOST_CHECK(captureDataIdMap.at(i).GetCapturePeriod() == 0);
597  BOOST_CHECK(captureDataIdMap.at(i).GetCounterIds().empty());
598  readThreadsVect.emplace_back(
599  std::thread(CaptureDataReadThreadImpl, std::ref(holder), std::ref(captureDataIdMap.at(i))));
600  }
601 
602  for (uint32_t i = 0; i < numThreads; ++i)
603  {
604  threadsVect[i].join();
605  readThreadsVect[i].join();
606  }
607 
608  // Look at the CaptureData that each read thread has filled
609  // the capture period it read should match the counter ids entry
610  for (uint32_t i = 0; i < numThreads; ++i)
611  {
612  CaptureData perThreadCaptureData = captureDataIdMap.at(i);
613  BOOST_CHECK(perThreadCaptureData.GetCounterIds() == periodIdMap.at(perThreadCaptureData.GetCapturePeriod()));
614  }
615 }
CaptureData GetCaptureData() const
Definition: Holder.cpp:54
void CaptureDataWriteThreadImpl(Holder &holder, uint32_t capturePeriod, const std::vector< uint16_t > &counterIds)
const std::vector< uint16_t > & GetCounterIds() const
Definition: Holder.cpp:49
uint32_t GetCapturePeriod() const
Definition: Holder.cpp:44
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
void CaptureDataReadThreadImpl(const Holder &holder, CaptureData &captureData)

◆ BOOST_AUTO_TEST_CASE() [11/50]

BOOST_AUTO_TEST_CASE ( CaptureDataMethods  )

Definition at line 617 of file ProfilingTests.cpp.

References BOOST_CHECK(), CaptureData::GetCapturePeriod(), CaptureData::GetCounterIds(), CaptureData::SetCapturePeriod(), and CaptureData::SetCounterIds().

618 {
619  // Check CaptureData setter and getter functions
620  std::vector<uint16_t> counterIds = { 42, 29, 13 };
621  CaptureData captureData;
622  BOOST_CHECK(captureData.GetCapturePeriod() == 0);
623  BOOST_CHECK((captureData.GetCounterIds()).empty());
624  captureData.SetCapturePeriod(150);
625  captureData.SetCounterIds(counterIds);
626  BOOST_CHECK(captureData.GetCapturePeriod() == 150);
627  BOOST_CHECK(captureData.GetCounterIds() == counterIds);
628 
629  // Check assignment operator
630  CaptureData secondCaptureData;
631 
632  secondCaptureData = captureData;
633  BOOST_CHECK(secondCaptureData.GetCapturePeriod() == 150);
634  BOOST_CHECK(secondCaptureData.GetCounterIds() == counterIds);
635 
636  // Check copy constructor
637  CaptureData copyConstructedCaptureData(captureData);
638 
639  BOOST_CHECK(copyConstructedCaptureData.GetCapturePeriod() == 150);
640  BOOST_CHECK(copyConstructedCaptureData.GetCounterIds() == counterIds);
641 }
const std::vector< uint16_t > & GetCounterIds() const
Definition: Holder.cpp:49
uint32_t GetCapturePeriod() const
Definition: Holder.cpp:44
void SetCapturePeriod(uint32_t capturePeriod)
Definition: Holder.cpp:29
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
void SetCounterIds(const std::vector< uint16_t > &counterIds)
Definition: Holder.cpp:34

◆ BOOST_AUTO_TEST_CASE() [12/50]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceDisabled  )

Definition at line 643 of file ProfilingTests.cpp.

References BOOST_CHECK(), ProfilingService::GetCurrentState(), ProfilingService::Instance(), options, profilingService, ProfilingService::ResetExternalProfilingOptions(), armnn::profiling::Uninitialised, and ProfilingService::Update().

644 {
645  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
646  ProfilingService& profilingService = ProfilingService::Instance();
647  profilingService.ResetExternalProfilingOptions(options, true);
648  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
649  profilingService.Update();
650  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
651 }
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
ProfilingState GetCurrentState() const
ProfilingService & profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [13/50]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceCounterDirectory  )

Definition at line 653 of file ProfilingTests.cpp.

References BOOST_CHECK(), ICounterDirectory::GetCounterCount(), ProfilingService::GetCounterDirectory(), ProfilingService::Instance(), options, profilingService, ProfilingService::ResetExternalProfilingOptions(), and ProfilingService::Update().

654 {
655  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
656  ProfilingService& profilingService = ProfilingService::Instance();
657  profilingService.ResetExternalProfilingOptions(options, true);
658 
659  const ICounterDirectory& counterDirectory0 = profilingService.GetCounterDirectory();
660  BOOST_CHECK(counterDirectory0.GetCounterCount() == 0);
661  profilingService.Update();
662  BOOST_CHECK(counterDirectory0.GetCounterCount() == 0);
663 
664  options.m_EnableProfiling = true;
665  profilingService.ResetExternalProfilingOptions(options);
666 
667  const ICounterDirectory& counterDirectory1 = profilingService.GetCounterDirectory();
668  BOOST_CHECK(counterDirectory1.GetCounterCount() == 0);
669  profilingService.Update();
670  BOOST_CHECK(counterDirectory1.GetCounterCount() != 0);
671  // Reset the profiling service to stop any running thread
672  options.m_EnableProfiling = false;
673  profilingService.ResetExternalProfilingOptions(options, true);
674 }
virtual uint16_t GetCounterCount() const =0
const ICounterDirectory & GetCounterDirectory() const
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
ProfilingService & profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [14/50]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceCounterValues  )

Definition at line 676 of file ProfilingTests.cpp.

References ProfilingService::AddCounterValue(), BOOST_CHECK(), ProfilingService::GetCounterDirectory(), ICounterDirectory::GetCounters(), ProfilingService::GetCounterValue(), ProfilingService::IncrementCounterValue(), ProfilingService::Instance(), options, profilingService, ProfilingService::ResetExternalProfilingOptions(), ProfilingService::SetCounterValue(), ProfilingService::SubtractCounterValue(), and ProfilingService::Update().

677 {
678  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
679  options.m_EnableProfiling = true;
680  ProfilingService& profilingService = ProfilingService::Instance();
681  profilingService.ResetExternalProfilingOptions(options, true);
682 
683  profilingService.Update();
684  const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory();
685  const Counters& counters = counterDirectory.GetCounters();
686  BOOST_CHECK(!counters.empty());
687 
688  // Get the UID of the first counter for testing;
689 
690  ProfilingService* profilingServicePtr = &profilingService;
691  std::vector<std::thread> writers;
692 
693  for (int i = 0; i < 100; ++i)
694  {
695  // Increment and decrement the first counter
696  writers.push_back(std::thread(&ProfilingService::IncrementCounterValue,
697  profilingServicePtr,
698  armnn::profiling::REGISTERED_BACKENDS));
699 
700  writers.push_back(std::thread(&ProfilingService::IncrementCounterValue,
701  profilingServicePtr,
702  armnn::profiling::UNREGISTERED_BACKENDS));
703 
704  // Add 10 and subtract 5 from the first counter
705  writers.push_back(std::thread(&ProfilingService::AddCounterValue,
706  profilingServicePtr,
707  armnn::profiling::INFERENCES_RUN,
708  10));
709  writers.push_back(std::thread(&ProfilingService::SubtractCounterValue,
710  profilingServicePtr,
711  armnn::profiling::INFERENCES_RUN,
712  5));
713  }
714  std::for_each(writers.begin(), writers.end(), mem_fn(&std::thread::join));
715 
716  uint32_t counterValue = 0;
717  BOOST_CHECK(counterValue ==
718  (profilingService.GetCounterValue(armnn::profiling::UNREGISTERED_BACKENDS)
719  - profilingService.GetCounterValue(armnn::profiling::REGISTERED_BACKENDS)));
720  BOOST_CHECK(profilingService.GetCounterValue(armnn::profiling::INFERENCES_RUN) == 500);
721 
722  BOOST_CHECK_NO_THROW(profilingService.SetCounterValue(armnn::profiling::UNREGISTERED_BACKENDS, 4));
723  BOOST_CHECK_NO_THROW(counterValue = profilingService.GetCounterValue(armnn::profiling::UNREGISTERED_BACKENDS));
724  BOOST_CHECK(counterValue == 4);
725  // Reset the profiling service to stop any running thread
726  options.m_EnableProfiling = false;
727  profilingService.ResetExternalProfilingOptions(options, true);
728 }
uint32_t GetCounterValue(uint16_t counterUid) const override
void SetCounterValue(uint16_t counterUid, uint32_t value) override
const ICounterDirectory & GetCounterDirectory() const
profilingService IncrementCounterValue(0)
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
virtual const Counters & GetCounters() const =0
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
std::unordered_map< uint16_t, CounterPtr > Counters
ProfilingService & profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [15/50]

BOOST_AUTO_TEST_CASE ( CheckProfilingObjectUids  )

Definition at line 730 of file ProfilingTests.cpp.

References BOOST_CHECK(), armnn::profiling::GetNextCounterUids(), and armnn::profiling::GetNextUid().

731 {
732  uint16_t uid = 0;
733  BOOST_CHECK_NO_THROW(uid = GetNextUid());
734  BOOST_CHECK(uid >= 1);
735 
736  uint16_t nextUid = 0;
737  BOOST_CHECK_NO_THROW(nextUid = GetNextUid());
738  BOOST_CHECK(nextUid > uid);
739 
740  std::vector<uint16_t> counterUids;
741  BOOST_CHECK_NO_THROW(counterUids = GetNextCounterUids(uid,0));
742  BOOST_CHECK(counterUids.size() == 1);
743 
744  std::vector<uint16_t> nextCounterUids;
745  BOOST_CHECK_NO_THROW(nextCounterUids = GetNextCounterUids(nextUid, 2));
746  BOOST_CHECK(nextCounterUids.size() == 2);
747  BOOST_CHECK(nextCounterUids[0] > counterUids[0]);
748 
749  std::vector<uint16_t> counterUidsMultiCore;
750  uint16_t thirdUid = 4;
751  uint16_t numberOfCores = 13;
752  BOOST_CHECK_NO_THROW(counterUidsMultiCore = GetNextCounterUids(thirdUid, numberOfCores));
753  BOOST_CHECK(counterUidsMultiCore.size() == numberOfCores);
754  BOOST_CHECK(counterUidsMultiCore.front() >= nextCounterUids[0]);
755  for (size_t i = 1; i < numberOfCores; i++)
756  {
757  BOOST_CHECK(counterUidsMultiCore[i] == counterUidsMultiCore[i - 1] + 1);
758  }
759  BOOST_CHECK(counterUidsMultiCore.back() == counterUidsMultiCore.front() + numberOfCores - 1);
760 }
uint16_t GetNextUid(bool peekOnly)
std::vector< uint16_t > GetNextCounterUids(uint16_t firstUid, uint16_t cores)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)

◆ BOOST_AUTO_TEST_CASE() [16/50]

BOOST_AUTO_TEST_CASE ( CheckCounterDirectoryRegisterCategory  )

Definition at line 762 of file ProfilingTests.cpp.

References ARMNN_NO_CONVERSION_WARN_BEGIN, ARMNN_NO_CONVERSION_WARN_END, BOOST_CHECK(), CounterDirectory::GetCategory(), CounterDirectory::GetCategoryCount(), CounterDirectory::GetCounterCount(), CounterDirectory::GetCounterSetCount(), CounterDirectory::GetDeviceCount(), Device::m_Cores, CounterSet::m_Count, Category::m_Counters, Category::m_CounterSetUid, Category::m_DeviceUid, Category::m_Name, Device::m_Name, CounterSet::m_Name, Device::m_Uid, CounterSet::m_Uid, CounterDirectory::RegisterCategory(), CounterDirectory::RegisterCounterSet(), and CounterDirectory::RegisterDevice().

763 {
764  CounterDirectory counterDirectory;
765  BOOST_CHECK(counterDirectory.GetCategoryCount() == 0);
766  BOOST_CHECK(counterDirectory.GetDeviceCount() == 0);
767  BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0);
768  BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
769 
770  // Register a category with an invalid name
771  const Category* noCategory = nullptr;
772  BOOST_CHECK_THROW(noCategory = counterDirectory.RegisterCategory(""), armnn::InvalidArgumentException);
773  BOOST_CHECK(counterDirectory.GetCategoryCount() == 0);
774  BOOST_CHECK(!noCategory);
775 
776  // Register a category with an invalid name
777  BOOST_CHECK_THROW(noCategory = counterDirectory.RegisterCategory("invalid category"),
779  BOOST_CHECK(counterDirectory.GetCategoryCount() == 0);
780  BOOST_CHECK(!noCategory);
781 
782  // Register a new category
783  const std::string categoryName = "some_category";
784  const Category* category = nullptr;
785  BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName));
786  BOOST_CHECK(counterDirectory.GetCategoryCount() == 1);
787  BOOST_CHECK(category);
788  BOOST_CHECK(category->m_Name == categoryName);
789  BOOST_CHECK(category->m_Counters.empty());
790  BOOST_CHECK(category->m_DeviceUid == 0);
791  BOOST_CHECK(category->m_CounterSetUid == 0);
792 
793  // Get the registered category
794  const Category* registeredCategory = counterDirectory.GetCategory(categoryName);
795  BOOST_CHECK(counterDirectory.GetCategoryCount() == 1);
796  BOOST_CHECK(registeredCategory);
797  BOOST_CHECK(registeredCategory == category);
798 
799  // Try to get a category not registered
800  const Category* notRegisteredCategory = counterDirectory.GetCategory("not_registered_category");
801  BOOST_CHECK(counterDirectory.GetCategoryCount() == 1);
802  BOOST_CHECK(!notRegisteredCategory);
803 
804  // Register a category already registered
805  const Category* anotherCategory = nullptr;
806  BOOST_CHECK_THROW(anotherCategory = counterDirectory.RegisterCategory(categoryName),
808  BOOST_CHECK(counterDirectory.GetCategoryCount() == 1);
809  BOOST_CHECK(!anotherCategory);
810 
811  // Register a device for testing
812  const std::string deviceName = "some_device";
813  const Device* device = nullptr;
814  BOOST_CHECK_NO_THROW(device = counterDirectory.RegisterDevice(deviceName));
815  BOOST_CHECK(counterDirectory.GetDeviceCount() == 1);
816  BOOST_CHECK(device);
817  BOOST_CHECK(device->m_Uid >= 1);
818  BOOST_CHECK(device->m_Name == deviceName);
819  BOOST_CHECK(device->m_Cores == 0);
820 
821  // Register a new category not associated to any device
822  const std::string categoryWoDeviceName = "some_category_without_device";
823  const Category* categoryWoDevice = nullptr;
824  BOOST_CHECK_NO_THROW(categoryWoDevice = counterDirectory.RegisterCategory(categoryWoDeviceName, 0));
825  BOOST_CHECK(counterDirectory.GetCategoryCount() == 2);
826  BOOST_CHECK(categoryWoDevice);
827  BOOST_CHECK(categoryWoDevice->m_Name == categoryWoDeviceName);
828  BOOST_CHECK(categoryWoDevice->m_Counters.empty());
829  BOOST_CHECK(categoryWoDevice->m_DeviceUid == 0);
830  BOOST_CHECK(categoryWoDevice->m_CounterSetUid == 0);
831 
832  // Register a new category associated to an invalid device
833  const std::string categoryWInvalidDeviceName = "some_category_with_invalid_device";
834 
836  uint16_t invalidDeviceUid = device->m_Uid + 10;
838 
839  const Category* categoryWInvalidDevice = nullptr;
840  BOOST_CHECK_THROW(categoryWInvalidDevice =
841  counterDirectory.RegisterCategory(categoryWInvalidDeviceName, invalidDeviceUid),
843  BOOST_CHECK(counterDirectory.GetCategoryCount() == 2);
844  BOOST_CHECK(!categoryWInvalidDevice);
845 
846  // Register a new category associated to a valid device
847  const std::string categoryWValidDeviceName = "some_category_with_valid_device";
848  const Category* categoryWValidDevice = nullptr;
849  BOOST_CHECK_NO_THROW(categoryWValidDevice =
850  counterDirectory.RegisterCategory(categoryWValidDeviceName, device->m_Uid));
851  BOOST_CHECK(counterDirectory.GetCategoryCount() == 3);
852  BOOST_CHECK(categoryWValidDevice);
853  BOOST_CHECK(categoryWValidDevice != category);
854  BOOST_CHECK(categoryWValidDevice->m_Name == categoryWValidDeviceName);
855  BOOST_CHECK(categoryWValidDevice->m_DeviceUid == device->m_Uid);
856  BOOST_CHECK(categoryWValidDevice->m_CounterSetUid == 0);
857 
858  // Register a counter set for testing
859  const std::string counterSetName = "some_counter_set";
860  const CounterSet* counterSet = nullptr;
861  BOOST_CHECK_NO_THROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName));
862  BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1);
863  BOOST_CHECK(counterSet);
864  BOOST_CHECK(counterSet->m_Uid >= 1);
865  BOOST_CHECK(counterSet->m_Name == counterSetName);
866  BOOST_CHECK(counterSet->m_Count == 0);
867 
868  // Register a new category not associated to any counter set
869  const std::string categoryWoCounterSetName = "some_category_without_counter_set";
870  const Category* categoryWoCounterSet = nullptr;
871  BOOST_CHECK_NO_THROW(categoryWoCounterSet =
872  counterDirectory.RegisterCategory(categoryWoCounterSetName, armnn::EmptyOptional(), 0));
873  BOOST_CHECK(counterDirectory.GetCategoryCount() == 4);
874  BOOST_CHECK(categoryWoCounterSet);
875  BOOST_CHECK(categoryWoCounterSet->m_Name == categoryWoCounterSetName);
876  BOOST_CHECK(categoryWoCounterSet->m_DeviceUid == 0);
877  BOOST_CHECK(categoryWoCounterSet->m_CounterSetUid == 0);
878 
879  // Register a new category associated to an invalid counter set
880  const std::string categoryWInvalidCounterSetName = "some_category_with_invalid_counter_set";
881 
883  uint16_t invalidCunterSetUid = counterSet->m_Uid + 10;
885 
886  const Category* categoryWInvalidCounterSet = nullptr;
887  BOOST_CHECK_THROW(categoryWInvalidCounterSet = counterDirectory.RegisterCategory(
888  categoryWInvalidCounterSetName, armnn::EmptyOptional(), invalidCunterSetUid),
890  BOOST_CHECK(counterDirectory.GetCategoryCount() == 4);
891  BOOST_CHECK(!categoryWInvalidCounterSet);
892 
893  // Register a new category associated to a valid counter set
894  const std::string categoryWValidCounterSetName = "some_category_with_valid_counter_set";
895  const Category* categoryWValidCounterSet = nullptr;
896  BOOST_CHECK_NO_THROW(categoryWValidCounterSet = counterDirectory.RegisterCategory(
897  categoryWValidCounterSetName, armnn::EmptyOptional(), counterSet->m_Uid));
898  BOOST_CHECK(counterDirectory.GetCategoryCount() == 5);
899  BOOST_CHECK(categoryWValidCounterSet);
900  BOOST_CHECK(categoryWValidCounterSet != category);
901  BOOST_CHECK(categoryWValidCounterSet->m_Name == categoryWValidCounterSetName);
902  BOOST_CHECK(categoryWValidCounterSet->m_DeviceUid == 0);
903  BOOST_CHECK(categoryWValidCounterSet->m_CounterSetUid == counterSet->m_Uid);
904 
905  // Register a new category associated to a valid device and counter set
906  const std::string categoryWValidDeviceAndValidCounterSetName = "some_category_with_valid_device_and_counter_set";
907  const Category* categoryWValidDeviceAndValidCounterSet = nullptr;
908  BOOST_CHECK_NO_THROW(categoryWValidDeviceAndValidCounterSet = counterDirectory.RegisterCategory(
909  categoryWValidDeviceAndValidCounterSetName, device->m_Uid, counterSet->m_Uid));
910  BOOST_CHECK(counterDirectory.GetCategoryCount() == 6);
911  BOOST_CHECK(categoryWValidDeviceAndValidCounterSet);
912  BOOST_CHECK(categoryWValidDeviceAndValidCounterSet != category);
913  BOOST_CHECK(categoryWValidDeviceAndValidCounterSet->m_Name == categoryWValidDeviceAndValidCounterSetName);
914  BOOST_CHECK(categoryWValidDeviceAndValidCounterSet->m_DeviceUid == device->m_Uid);
915  BOOST_CHECK(categoryWValidDeviceAndValidCounterSet->m_CounterSetUid == counterSet->m_Uid);
916 }
#define ARMNN_NO_CONVERSION_WARN_BEGIN
Definition: Conversion.hpp:36
const Category * RegisterCategory(const std::string &categoryName, const Optional< uint16_t > &deviceUid=EmptyOptional(), const Optional< uint16_t > &counterSetUid=EmptyOptional()) override
const Device * RegisterDevice(const std::string &deviceName, uint16_t cores=0, const Optional< std::string > &parentCategoryName=EmptyOptional()) override
std::vector< uint16_t > m_Counters
uint16_t GetCounterCount() const override
uint16_t GetCategoryCount() const override
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
uint16_t GetCounterSetCount() const override
#define ARMNN_NO_CONVERSION_WARN_END
Definition: Conversion.hpp:37
uint16_t GetDeviceCount() const override
const Category * GetCategory(const std::string &name) const override
const CounterSet * RegisterCounterSet(const std::string &counterSetName, uint16_t count=0, const Optional< std::string > &parentCategoryName=EmptyOptional()) override

◆ BOOST_AUTO_TEST_CASE() [17/50]

BOOST_AUTO_TEST_CASE ( CheckCounterDirectoryRegisterDevice  )

Definition at line 918 of file ProfilingTests.cpp.

References BOOST_CHECK(), CounterDirectory::GetCategoryCount(), CounterDirectory::GetCounterCount(), CounterDirectory::GetCounterSetCount(), CounterDirectory::GetDevice(), CounterDirectory::GetDeviceCount(), Device::m_Cores, Category::m_Counters, Category::m_CounterSetUid, Category::m_DeviceUid, Category::m_Name, Device::m_Name, Device::m_Uid, CounterDirectory::RegisterCategory(), and CounterDirectory::RegisterDevice().

919 {
920  CounterDirectory counterDirectory;
921  BOOST_CHECK(counterDirectory.GetCategoryCount() == 0);
922  BOOST_CHECK(counterDirectory.GetDeviceCount() == 0);
923  BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0);
924  BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
925 
926  // Register a device with an invalid name
927  const Device* noDevice = nullptr;
928  BOOST_CHECK_THROW(noDevice = counterDirectory.RegisterDevice(""), armnn::InvalidArgumentException);
929  BOOST_CHECK(counterDirectory.GetDeviceCount() == 0);
930  BOOST_CHECK(!noDevice);
931 
932  // Register a device with an invalid name
933  BOOST_CHECK_THROW(noDevice = counterDirectory.RegisterDevice("inv@lid nam€"), armnn::InvalidArgumentException);
934  BOOST_CHECK(counterDirectory.GetDeviceCount() == 0);
935  BOOST_CHECK(!noDevice);
936 
937  // Register a new device with no cores or parent category
938  const std::string deviceName = "some_device";
939  const Device* device = nullptr;
940  BOOST_CHECK_NO_THROW(device = counterDirectory.RegisterDevice(deviceName));
941  BOOST_CHECK(counterDirectory.GetDeviceCount() == 1);
942  BOOST_CHECK(device);
943  BOOST_CHECK(device->m_Name == deviceName);
944  BOOST_CHECK(device->m_Uid >= 1);
945  BOOST_CHECK(device->m_Cores == 0);
946 
947  // Try getting an unregistered device
948  const Device* unregisteredDevice = counterDirectory.GetDevice(9999);
949  BOOST_CHECK(!unregisteredDevice);
950 
951  // Get the registered device
952  const Device* registeredDevice = counterDirectory.GetDevice(device->m_Uid);
953  BOOST_CHECK(counterDirectory.GetDeviceCount() == 1);
954  BOOST_CHECK(registeredDevice);
955  BOOST_CHECK(registeredDevice == device);
956 
957  // Register a device with the name of a device already registered
958  const Device* deviceSameName = nullptr;
959  BOOST_CHECK_THROW(deviceSameName = counterDirectory.RegisterDevice(deviceName), armnn::InvalidArgumentException);
960  BOOST_CHECK(counterDirectory.GetDeviceCount() == 1);
961  BOOST_CHECK(!deviceSameName);
962 
963  // Register a new device with cores and no parent category
964  const std::string deviceWCoresName = "some_device_with_cores";
965  const Device* deviceWCores = nullptr;
966  BOOST_CHECK_NO_THROW(deviceWCores = counterDirectory.RegisterDevice(deviceWCoresName, 2));
967  BOOST_CHECK(counterDirectory.GetDeviceCount() == 2);
968  BOOST_CHECK(deviceWCores);
969  BOOST_CHECK(deviceWCores->m_Name == deviceWCoresName);
970  BOOST_CHECK(deviceWCores->m_Uid >= 1);
971  BOOST_CHECK(deviceWCores->m_Uid > device->m_Uid);
972  BOOST_CHECK(deviceWCores->m_Cores == 2);
973 
974  // Get the registered device
975  const Device* registeredDeviceWCores = counterDirectory.GetDevice(deviceWCores->m_Uid);
976  BOOST_CHECK(counterDirectory.GetDeviceCount() == 2);
977  BOOST_CHECK(registeredDeviceWCores);
978  BOOST_CHECK(registeredDeviceWCores == deviceWCores);
979  BOOST_CHECK(registeredDeviceWCores != device);
980 
981  // Register a new device with cores and invalid parent category
982  const std::string deviceWCoresWInvalidParentCategoryName = "some_device_with_cores_with_invalid_parent_category";
983  const Device* deviceWCoresWInvalidParentCategory = nullptr;
984  BOOST_CHECK_THROW(deviceWCoresWInvalidParentCategory =
985  counterDirectory.RegisterDevice(deviceWCoresWInvalidParentCategoryName, 3, std::string("")),
987  BOOST_CHECK(counterDirectory.GetDeviceCount() == 2);
988  BOOST_CHECK(!deviceWCoresWInvalidParentCategory);
989 
990  // Register a new device with cores and invalid parent category
991  const std::string deviceWCoresWInvalidParentCategoryName2 = "some_device_with_cores_with_invalid_parent_category2";
992  const Device* deviceWCoresWInvalidParentCategory2 = nullptr;
993  BOOST_CHECK_THROW(deviceWCoresWInvalidParentCategory2 = counterDirectory.RegisterDevice(
994  deviceWCoresWInvalidParentCategoryName2, 3, std::string("invalid_parent_category")),
996  BOOST_CHECK(counterDirectory.GetDeviceCount() == 2);
997  BOOST_CHECK(!deviceWCoresWInvalidParentCategory2);
998 
999  // Register a category for testing
1000  const std::string categoryName = "some_category";
1001  const Category* category = nullptr;
1002  BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName));
1003  BOOST_CHECK(counterDirectory.GetCategoryCount() == 1);
1004  BOOST_CHECK(category);
1005  BOOST_CHECK(category->m_Name == categoryName);
1006  BOOST_CHECK(category->m_Counters.empty());
1007  BOOST_CHECK(category->m_DeviceUid == 0);
1008  BOOST_CHECK(category->m_CounterSetUid == 0);
1009 
1010  // Register a new device with cores and valid parent category
1011  const std::string deviceWCoresWValidParentCategoryName = "some_device_with_cores_with_valid_parent_category";
1012  const Device* deviceWCoresWValidParentCategory = nullptr;
1013  BOOST_CHECK_NO_THROW(deviceWCoresWValidParentCategory =
1014  counterDirectory.RegisterDevice(deviceWCoresWValidParentCategoryName, 4, categoryName));
1015  BOOST_CHECK(counterDirectory.GetDeviceCount() == 3);
1016  BOOST_CHECK(deviceWCoresWValidParentCategory);
1017  BOOST_CHECK(deviceWCoresWValidParentCategory->m_Name == deviceWCoresWValidParentCategoryName);
1018  BOOST_CHECK(deviceWCoresWValidParentCategory->m_Uid >= 1);
1019  BOOST_CHECK(deviceWCoresWValidParentCategory->m_Uid > device->m_Uid);
1020  BOOST_CHECK(deviceWCoresWValidParentCategory->m_Uid > deviceWCores->m_Uid);
1021  BOOST_CHECK(deviceWCoresWValidParentCategory->m_Cores == 4);
1022  BOOST_CHECK(category->m_DeviceUid == deviceWCoresWValidParentCategory->m_Uid);
1023 
1024  // Register a device associated to a category already associated to a different device
1025  const std::string deviceSameCategoryName = "some_device_with_invalid_parent_category";
1026  const Device* deviceSameCategory = nullptr;
1027  BOOST_CHECK_THROW(deviceSameCategory = counterDirectory.RegisterDevice(deviceSameCategoryName, 0, categoryName),
1029  BOOST_CHECK(counterDirectory.GetDeviceCount() == 3);
1030  BOOST_CHECK(!deviceSameCategory);
1031 }
const Device * GetDevice(uint16_t uid) const override
const Category * RegisterCategory(const std::string &categoryName, const Optional< uint16_t > &deviceUid=EmptyOptional(), const Optional< uint16_t > &counterSetUid=EmptyOptional()) override
const Device * RegisterDevice(const std::string &deviceName, uint16_t cores=0, const Optional< std::string > &parentCategoryName=EmptyOptional()) override
std::vector< uint16_t > m_Counters
uint16_t GetCounterCount() const override
uint16_t GetCategoryCount() const override
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
uint16_t GetCounterSetCount() const override
uint16_t GetDeviceCount() const override

◆ BOOST_AUTO_TEST_CASE() [18/50]

BOOST_AUTO_TEST_CASE ( CheckCounterDirectoryRegisterCounterSet  )

Definition at line 1033 of file ProfilingTests.cpp.

References BOOST_CHECK(), CounterDirectory::GetCategoryCount(), CounterDirectory::GetCounterCount(), CounterDirectory::GetCounterSet(), CounterDirectory::GetCounterSetCount(), CounterDirectory::GetDeviceCount(), CounterSet::m_Count, Category::m_Counters, Category::m_CounterSetUid, Category::m_DeviceUid, Category::m_Name, CounterSet::m_Name, CounterSet::m_Uid, CounterDirectory::RegisterCategory(), and CounterDirectory::RegisterCounterSet().

1034 {
1035  CounterDirectory counterDirectory;
1036  BOOST_CHECK(counterDirectory.GetCategoryCount() == 0);
1037  BOOST_CHECK(counterDirectory.GetDeviceCount() == 0);
1038  BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0);
1039  BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1040 
1041  // Register a counter set with an invalid name
1042  const CounterSet* noCounterSet = nullptr;
1043  BOOST_CHECK_THROW(noCounterSet = counterDirectory.RegisterCounterSet(""), armnn::InvalidArgumentException);
1044  BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0);
1045  BOOST_CHECK(!noCounterSet);
1046 
1047  // Register a counter set with an invalid name
1048  BOOST_CHECK_THROW(noCounterSet = counterDirectory.RegisterCounterSet("invalid name"),
1050  BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0);
1051  BOOST_CHECK(!noCounterSet);
1052 
1053  // Register a new counter set with no count or parent category
1054  const std::string counterSetName = "some_counter_set";
1055  const CounterSet* counterSet = nullptr;
1056  BOOST_CHECK_NO_THROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName));
1057  BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1);
1058  BOOST_CHECK(counterSet);
1059  BOOST_CHECK(counterSet->m_Name == counterSetName);
1060  BOOST_CHECK(counterSet->m_Uid >= 1);
1061  BOOST_CHECK(counterSet->m_Count == 0);
1062 
1063  // Try getting an unregistered counter set
1064  const CounterSet* unregisteredCounterSet = counterDirectory.GetCounterSet(9999);
1065  BOOST_CHECK(!unregisteredCounterSet);
1066 
1067  // Get the registered counter set
1068  const CounterSet* registeredCounterSet = counterDirectory.GetCounterSet(counterSet->m_Uid);
1069  BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1);
1070  BOOST_CHECK(registeredCounterSet);
1071  BOOST_CHECK(registeredCounterSet == counterSet);
1072 
1073  // Register a counter set with the name of a counter set already registered
1074  const CounterSet* counterSetSameName = nullptr;
1075  BOOST_CHECK_THROW(counterSetSameName = counterDirectory.RegisterCounterSet(counterSetName),
1077  BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1);
1078  BOOST_CHECK(!counterSetSameName);
1079 
1080  // Register a new counter set with count and no parent category
1081  const std::string counterSetWCountName = "some_counter_set_with_count";
1082  const CounterSet* counterSetWCount = nullptr;
1083  BOOST_CHECK_NO_THROW(counterSetWCount = counterDirectory.RegisterCounterSet(counterSetWCountName, 37));
1084  BOOST_CHECK(counterDirectory.GetCounterSetCount() == 2);
1085  BOOST_CHECK(counterSetWCount);
1086  BOOST_CHECK(counterSetWCount->m_Name == counterSetWCountName);
1087  BOOST_CHECK(counterSetWCount->m_Uid >= 1);
1088  BOOST_CHECK(counterSetWCount->m_Uid > counterSet->m_Uid);
1089  BOOST_CHECK(counterSetWCount->m_Count == 37);
1090 
1091  // Get the registered counter set
1092  const CounterSet* registeredCounterSetWCount = counterDirectory.GetCounterSet(counterSetWCount->m_Uid);
1093  BOOST_CHECK(counterDirectory.GetCounterSetCount() == 2);
1094  BOOST_CHECK(registeredCounterSetWCount);
1095  BOOST_CHECK(registeredCounterSetWCount == counterSetWCount);
1096  BOOST_CHECK(registeredCounterSetWCount != counterSet);
1097 
1098  // Register a new counter set with count and invalid parent category
1099  const std::string counterSetWCountWInvalidParentCategoryName = "some_counter_set_with_count_"
1100  "with_invalid_parent_category";
1101  const CounterSet* counterSetWCountWInvalidParentCategory = nullptr;
1102  BOOST_CHECK_THROW(counterSetWCountWInvalidParentCategory = counterDirectory.RegisterCounterSet(
1103  counterSetWCountWInvalidParentCategoryName, 42, std::string("")),
1105  BOOST_CHECK(counterDirectory.GetCounterSetCount() == 2);
1106  BOOST_CHECK(!counterSetWCountWInvalidParentCategory);
1107 
1108  // Register a new counter set with count and invalid parent category
1109  const std::string counterSetWCountWInvalidParentCategoryName2 = "some_counter_set_with_count_"
1110  "with_invalid_parent_category2";
1111  const CounterSet* counterSetWCountWInvalidParentCategory2 = nullptr;
1112  BOOST_CHECK_THROW(counterSetWCountWInvalidParentCategory2 = counterDirectory.RegisterCounterSet(
1113  counterSetWCountWInvalidParentCategoryName2, 42, std::string("invalid_parent_category")),
1115  BOOST_CHECK(counterDirectory.GetCounterSetCount() == 2);
1116  BOOST_CHECK(!counterSetWCountWInvalidParentCategory2);
1117 
1118  // Register a category for testing
1119  const std::string categoryName = "some_category";
1120  const Category* category = nullptr;
1121  BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName));
1122  BOOST_CHECK(counterDirectory.GetCategoryCount() == 1);
1123  BOOST_CHECK(category);
1124  BOOST_CHECK(category->m_Name == categoryName);
1125  BOOST_CHECK(category->m_Counters.empty());
1126  BOOST_CHECK(category->m_DeviceUid == 0);
1127  BOOST_CHECK(category->m_CounterSetUid == 0);
1128 
1129  // Register a new counter set with count and valid parent category
1130  const std::string counterSetWCountWValidParentCategoryName = "some_counter_set_with_count_"
1131  "with_valid_parent_category";
1132  const CounterSet* counterSetWCountWValidParentCategory = nullptr;
1133  BOOST_CHECK_NO_THROW(counterSetWCountWValidParentCategory = counterDirectory.RegisterCounterSet(
1134  counterSetWCountWValidParentCategoryName, 42, categoryName));
1135  BOOST_CHECK(counterDirectory.GetCounterSetCount() == 3);
1136  BOOST_CHECK(counterSetWCountWValidParentCategory);
1137  BOOST_CHECK(counterSetWCountWValidParentCategory->m_Name == counterSetWCountWValidParentCategoryName);
1138  BOOST_CHECK(counterSetWCountWValidParentCategory->m_Uid >= 1);
1139  BOOST_CHECK(counterSetWCountWValidParentCategory->m_Uid > counterSet->m_Uid);
1140  BOOST_CHECK(counterSetWCountWValidParentCategory->m_Uid > counterSetWCount->m_Uid);
1141  BOOST_CHECK(counterSetWCountWValidParentCategory->m_Count == 42);
1142  BOOST_CHECK(category->m_CounterSetUid == counterSetWCountWValidParentCategory->m_Uid);
1143 
1144  // Register a counter set associated to a category already associated to a different counter set
1145  const std::string counterSetSameCategoryName = "some_counter_set_with_invalid_parent_category";
1146  const CounterSet* counterSetSameCategory = nullptr;
1147  BOOST_CHECK_THROW(counterSetSameCategory =
1148  counterDirectory.RegisterCounterSet(counterSetSameCategoryName, 0, categoryName),
1150  BOOST_CHECK(counterDirectory.GetCounterSetCount() == 3);
1151  BOOST_CHECK(!counterSetSameCategory);
1152 }
const CounterSet * GetCounterSet(uint16_t uid) const override
const Category * RegisterCategory(const std::string &categoryName, const Optional< uint16_t > &deviceUid=EmptyOptional(), const Optional< uint16_t > &counterSetUid=EmptyOptional()) override
std::vector< uint16_t > m_Counters
uint16_t GetCounterCount() const override
uint16_t GetCategoryCount() const override
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
uint16_t GetCounterSetCount() const override
uint16_t GetDeviceCount() const override
const CounterSet * RegisterCounterSet(const std::string &counterSetName, uint16_t count=0, const Optional< std::string > &parentCategoryName=EmptyOptional()) override

◆ BOOST_AUTO_TEST_CASE() [19/50]

BOOST_AUTO_TEST_CASE ( CheckCounterDirectoryRegisterCounter  )

Definition at line 1154 of file ProfilingTests.cpp.

References BOOST_CHECK(), CounterDirectory::GetCategoryCount(), CounterDirectory::GetCounter(), CounterDirectory::GetCounterCount(), CounterDirectory::GetCounterSetCount(), CounterDirectory::GetDeviceCount(), Counter::m_Class, Device::m_Cores, CounterSet::m_Count, Category::m_Counters, Category::m_CounterSetUid, Counter::m_CounterSetUid, Counter::m_Description, Category::m_DeviceUid, Counter::m_DeviceUid, Counter::m_Interpolation, Counter::m_MaxCounterUid, Counter::m_Multiplier, Category::m_Name, Device::m_Name, CounterSet::m_Name, Counter::m_Name, Device::m_Uid, CounterSet::m_Uid, Counter::m_Uid, Counter::m_Units, CounterDirectory::RegisterCategory(), CounterDirectory::RegisterCounter(), CounterDirectory::RegisterCounterSet(), and CounterDirectory::RegisterDevice().

1155 {
1156  CounterDirectory counterDirectory;
1157  BOOST_CHECK(counterDirectory.GetCategoryCount() == 0);
1158  BOOST_CHECK(counterDirectory.GetDeviceCount() == 0);
1159  BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0);
1160  BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1161 
1162  // Register a counter with an invalid parent category name
1163  const Counter* noCounter = nullptr;
1164  BOOST_CHECK_THROW(noCounter =
1165  counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1166  0,
1167  "",
1168  0,
1169  1,
1170  123.45f,
1171  "valid ",
1172  "name"),
1174  BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1175  BOOST_CHECK(!noCounter);
1176 
1177  // Register a counter with an invalid parent category name
1178  BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1179  1,
1180  "invalid parent category",
1181  0,
1182  1,
1183  123.45f,
1184  "valid name",
1185  "valid description"),
1187  BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1188  BOOST_CHECK(!noCounter);
1189 
1190  // Register a counter with an invalid class
1191  BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1192  2,
1193  "valid_parent_category",
1194  2,
1195  1,
1196  123.45f,
1197  "valid "
1198  "name",
1199  "valid description"),
1201  BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1202  BOOST_CHECK(!noCounter);
1203 
1204  // Register a counter with an invalid interpolation
1205  BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1206  4,
1207  "valid_parent_category",
1208  0,
1209  3,
1210  123.45f,
1211  "valid "
1212  "name",
1213  "valid description"),
1215  BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1216  BOOST_CHECK(!noCounter);
1217 
1218  // Register a counter with an invalid multiplier
1219  BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1220  5,
1221  "valid_parent_category",
1222  0,
1223  1,
1224  .0f,
1225  "valid "
1226  "name",
1227  "valid description"),
1229  BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1230  BOOST_CHECK(!noCounter);
1231 
1232  // Register a counter with an invalid name
1233  BOOST_CHECK_THROW(
1234  noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1235  6,
1236  "valid_parent_category",
1237  0,
1238  1,
1239  123.45f,
1240  "",
1241  "valid description"),
1243  BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1244  BOOST_CHECK(!noCounter);
1245 
1246  // Register a counter with an invalid name
1247  BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1248  7,
1249  "valid_parent_category",
1250  0,
1251  1,
1252  123.45f,
1253  "invalid nam€",
1254  "valid description"),
1256  BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1257  BOOST_CHECK(!noCounter);
1258 
1259  // Register a counter with an invalid description
1260  BOOST_CHECK_THROW(noCounter =
1261  counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1262  8,
1263  "valid_parent_category",
1264  0,
1265  1,
1266  123.45f,
1267  "valid name",
1268  ""),
1270  BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1271  BOOST_CHECK(!noCounter);
1272 
1273  // Register a counter with an invalid description
1274  BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1275  9,
1276  "valid_parent_category",
1277  0,
1278  1,
1279  123.45f,
1280  "valid "
1281  "name",
1282  "inv@lid description"),
1284  BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1285  BOOST_CHECK(!noCounter);
1286 
1287  // Register a counter with an invalid unit2
1288  BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1289  10,
1290  "valid_parent_category",
1291  0,
1292  1,
1293  123.45f,
1294  "valid name",
1295  "valid description",
1296  std::string("Mb/s2")),
1298  BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1299  BOOST_CHECK(!noCounter);
1300 
1301  // Register a counter with a non-existing parent category name
1302  BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1303  11,
1304  "invalid_parent_category",
1305  0,
1306  1,
1307  123.45f,
1308  "valid name",
1309  "valid description"),
1311  BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
1312  BOOST_CHECK(!noCounter);
1313 
1314  // Try getting an unregistered counter
1315  const Counter* unregisteredCounter = counterDirectory.GetCounter(9999);
1316  BOOST_CHECK(!unregisteredCounter);
1317 
1318  // Register a category for testing
1319  const std::string categoryName = "some_category";
1320  const Category* category = nullptr;
1321  BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName));
1322  BOOST_CHECK(counterDirectory.GetCategoryCount() == 1);
1323  BOOST_CHECK(category);
1324  BOOST_CHECK(category->m_Name == categoryName);
1325  BOOST_CHECK(category->m_Counters.empty());
1326  BOOST_CHECK(category->m_DeviceUid == 0);
1327  BOOST_CHECK(category->m_CounterSetUid == 0);
1328 
1329  // Register a counter with a valid parent category name
1330  const Counter* counter = nullptr;
1331  BOOST_CHECK_NO_THROW(
1332  counter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1333  12,
1334  categoryName,
1335  0,
1336  1,
1337  123.45f,
1338  "valid name",
1339  "valid description"));
1340  BOOST_CHECK(counterDirectory.GetCounterCount() == 1);
1341  BOOST_CHECK(counter);
1342  BOOST_CHECK(counter->m_MaxCounterUid == counter->m_Uid);
1343  BOOST_CHECK(counter->m_Class == 0);
1344  BOOST_CHECK(counter->m_Interpolation == 1);
1345  BOOST_CHECK(counter->m_Multiplier == 123.45f);
1346  BOOST_CHECK(counter->m_Name == "valid name");
1347  BOOST_CHECK(counter->m_Description == "valid description");
1348  BOOST_CHECK(counter->m_Units == "");
1349  BOOST_CHECK(counter->m_DeviceUid == 0);
1350  BOOST_CHECK(counter->m_CounterSetUid == 0);
1351  BOOST_CHECK(category->m_Counters.size() == 1);
1352  BOOST_CHECK(category->m_Counters.back() == counter->m_Uid);
1353 
1354  // Register a counter with a name of a counter already registered for the given parent category name
1355  const Counter* counterSameName = nullptr;
1356  BOOST_CHECK_THROW(counterSameName =
1357  counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1358  13,
1359  categoryName,
1360  0,
1361  0,
1362  1.0f,
1363  "valid name",
1364  "valid description",
1365  std::string("description")),
1367  BOOST_CHECK(counterDirectory.GetCounterCount() == 1);
1368  BOOST_CHECK(!counterSameName);
1369 
1370  // Register a counter with a valid parent category name and units
1371  const Counter* counterWUnits = nullptr;
1372  BOOST_CHECK_NO_THROW(counterWUnits = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1373  14,
1374  categoryName,
1375  0,
1376  1,
1377  123.45f,
1378  "valid name 2",
1379  "valid description",
1380  std::string("Mnnsq2"))); // Units
1381  BOOST_CHECK(counterDirectory.GetCounterCount() == 2);
1382  BOOST_CHECK(counterWUnits);
1383  BOOST_CHECK(counterWUnits->m_Uid > counter->m_Uid);
1384  BOOST_CHECK(counterWUnits->m_MaxCounterUid == counterWUnits->m_Uid);
1385  BOOST_CHECK(counterWUnits->m_Class == 0);
1386  BOOST_CHECK(counterWUnits->m_Interpolation == 1);
1387  BOOST_CHECK(counterWUnits->m_Multiplier == 123.45f);
1388  BOOST_CHECK(counterWUnits->m_Name == "valid name 2");
1389  BOOST_CHECK(counterWUnits->m_Description == "valid description");
1390  BOOST_CHECK(counterWUnits->m_Units == "Mnnsq2");
1391  BOOST_CHECK(counterWUnits->m_DeviceUid == 0);
1392  BOOST_CHECK(counterWUnits->m_CounterSetUid == 0);
1393  BOOST_CHECK(category->m_Counters.size() == 2);
1394  BOOST_CHECK(category->m_Counters.back() == counterWUnits->m_Uid);
1395 
1396  // Register a counter with a valid parent category name and not associated with a device
1397  const Counter* counterWoDevice = nullptr;
1398  BOOST_CHECK_NO_THROW(counterWoDevice = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1399  26,
1400  categoryName,
1401  0,
1402  1,
1403  123.45f,
1404  "valid name 3",
1405  "valid description",
1406  armnn::EmptyOptional(),// Units
1407  armnn::EmptyOptional(),// Number of cores
1408  0)); // Device UID
1409  BOOST_CHECK(counterDirectory.GetCounterCount() == 3);
1410  BOOST_CHECK(counterWoDevice);
1411  BOOST_CHECK(counterWoDevice->m_Uid > counter->m_Uid);
1412  BOOST_CHECK(counterWoDevice->m_MaxCounterUid == counterWoDevice->m_Uid);
1413  BOOST_CHECK(counterWoDevice->m_Class == 0);
1414  BOOST_CHECK(counterWoDevice->m_Interpolation == 1);
1415  BOOST_CHECK(counterWoDevice->m_Multiplier == 123.45f);
1416  BOOST_CHECK(counterWoDevice->m_Name == "valid name 3");
1417  BOOST_CHECK(counterWoDevice->m_Description == "valid description");
1418  BOOST_CHECK(counterWoDevice->m_Units == "");
1419  BOOST_CHECK(counterWoDevice->m_DeviceUid == 0);
1420  BOOST_CHECK(counterWoDevice->m_CounterSetUid == 0);
1421  BOOST_CHECK(category->m_Counters.size() == 3);
1422  BOOST_CHECK(category->m_Counters.back() == counterWoDevice->m_Uid);
1423 
1424  // Register a counter with a valid parent category name and associated to an invalid device
1425  BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1426  15,
1427  categoryName,
1428  0,
1429  1,
1430  123.45f,
1431  "valid name 4",
1432  "valid description",
1433  armnn::EmptyOptional(), // Units
1434  armnn::EmptyOptional(), // Number of cores
1435  100), // Device UID
1437  BOOST_CHECK(counterDirectory.GetCounterCount() == 3);
1438  BOOST_CHECK(!noCounter);
1439 
1440  // Register a device for testing
1441  const std::string deviceName = "some_device";
1442  const Device* device = nullptr;
1443  BOOST_CHECK_NO_THROW(device = counterDirectory.RegisterDevice(deviceName));
1444  BOOST_CHECK(counterDirectory.GetDeviceCount() == 1);
1445  BOOST_CHECK(device);
1446  BOOST_CHECK(device->m_Name == deviceName);
1447  BOOST_CHECK(device->m_Uid >= 1);
1448  BOOST_CHECK(device->m_Cores == 0);
1449 
1450  // Register a counter with a valid parent category name and associated to a device
1451  const Counter* counterWDevice = nullptr;
1452  BOOST_CHECK_NO_THROW(counterWDevice = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1453  16,
1454  categoryName,
1455  0,
1456  1,
1457  123.45f,
1458  "valid name 5",
1459  std::string("valid description"),
1460  armnn::EmptyOptional(), // Units
1461  armnn::EmptyOptional(), // Number of cores
1462  device->m_Uid)); // Device UID
1463  BOOST_CHECK(counterDirectory.GetCounterCount() == 4);
1464  BOOST_CHECK(counterWDevice);
1465  BOOST_CHECK(counterWDevice->m_Uid > counter->m_Uid);
1466  BOOST_CHECK(counterWDevice->m_MaxCounterUid == counterWDevice->m_Uid);
1467  BOOST_CHECK(counterWDevice->m_Class == 0);
1468  BOOST_CHECK(counterWDevice->m_Interpolation == 1);
1469  BOOST_CHECK(counterWDevice->m_Multiplier == 123.45f);
1470  BOOST_CHECK(counterWDevice->m_Name == "valid name 5");
1471  BOOST_CHECK(counterWDevice->m_Description == "valid description");
1472  BOOST_CHECK(counterWDevice->m_Units == "");
1473  BOOST_CHECK(counterWDevice->m_DeviceUid == device->m_Uid);
1474  BOOST_CHECK(counterWDevice->m_CounterSetUid == 0);
1475  BOOST_CHECK(category->m_Counters.size() == 4);
1476  BOOST_CHECK(category->m_Counters.back() == counterWDevice->m_Uid);
1477 
1478  // Register a counter with a valid parent category name and not associated with a counter set
1479  const Counter* counterWoCounterSet = nullptr;
1480  BOOST_CHECK_NO_THROW(counterWoCounterSet = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1481  17,
1482  categoryName,
1483  0,
1484  1,
1485  123.45f,
1486  "valid name 6",
1487  "valid description",
1488  armnn::EmptyOptional(),// Units
1489  armnn::EmptyOptional(),// No of cores
1490  armnn::EmptyOptional(),// Device UID
1491  0)); // CounterSet UID
1492  BOOST_CHECK(counterDirectory.GetCounterCount() == 5);
1493  BOOST_CHECK(counterWoCounterSet);
1494  BOOST_CHECK(counterWoCounterSet->m_Uid > counter->m_Uid);
1495  BOOST_CHECK(counterWoCounterSet->m_MaxCounterUid == counterWoCounterSet->m_Uid);
1496  BOOST_CHECK(counterWoCounterSet->m_Class == 0);
1497  BOOST_CHECK(counterWoCounterSet->m_Interpolation == 1);
1498  BOOST_CHECK(counterWoCounterSet->m_Multiplier == 123.45f);
1499  BOOST_CHECK(counterWoCounterSet->m_Name == "valid name 6");
1500  BOOST_CHECK(counterWoCounterSet->m_Description == "valid description");
1501  BOOST_CHECK(counterWoCounterSet->m_Units == "");
1502  BOOST_CHECK(counterWoCounterSet->m_DeviceUid == 0);
1503  BOOST_CHECK(counterWoCounterSet->m_CounterSetUid == 0);
1504  BOOST_CHECK(category->m_Counters.size() == 5);
1505  BOOST_CHECK(category->m_Counters.back() == counterWoCounterSet->m_Uid);
1506 
1507  // Register a counter with a valid parent category name and associated to an invalid counter set
1508  BOOST_CHECK_THROW(noCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1509  18,
1510  categoryName,
1511  0,
1512  1,
1513  123.45f,
1514  "valid ",
1515  "name 7",
1516  std::string("valid description"),
1517  armnn::EmptyOptional(), // Units
1518  armnn::EmptyOptional(), // Number of cores
1519  100), // Counter set UID
1521  BOOST_CHECK(counterDirectory.GetCounterCount() == 5);
1522  BOOST_CHECK(!noCounter);
1523 
1524  // Register a counter with a valid parent category name and with a given number of cores
1525  const Counter* counterWNumberOfCores = nullptr;
1526  uint16_t numberOfCores = 15;
1527  BOOST_CHECK_NO_THROW(counterWNumberOfCores = counterDirectory.RegisterCounter(
1528  armnn::profiling::BACKEND_ID, 50,
1529  categoryName, 0, 1, 123.45f, "valid name 8", "valid description",
1530  armnn::EmptyOptional(), // Units
1531  numberOfCores, // Number of cores
1532  armnn::EmptyOptional(), // Device UID
1533  armnn::EmptyOptional())); // Counter set UID
1534  BOOST_CHECK(counterDirectory.GetCounterCount() == 20);
1535  BOOST_CHECK(counterWNumberOfCores);
1536  BOOST_CHECK(counterWNumberOfCores->m_Uid > counter->m_Uid);
1537  BOOST_CHECK(counterWNumberOfCores->m_MaxCounterUid == counterWNumberOfCores->m_Uid + numberOfCores - 1);
1538  BOOST_CHECK(counterWNumberOfCores->m_Class == 0);
1539  BOOST_CHECK(counterWNumberOfCores->m_Interpolation == 1);
1540  BOOST_CHECK(counterWNumberOfCores->m_Multiplier == 123.45f);
1541  BOOST_CHECK(counterWNumberOfCores->m_Name == "valid name 8");
1542  BOOST_CHECK(counterWNumberOfCores->m_Description == "valid description");
1543  BOOST_CHECK(counterWNumberOfCores->m_Units == "");
1544  BOOST_CHECK(counterWNumberOfCores->m_DeviceUid == 0);
1545  BOOST_CHECK(counterWNumberOfCores->m_CounterSetUid == 0);
1546  BOOST_CHECK(category->m_Counters.size() == 20);
1547  for (size_t i = 0; i < numberOfCores; i++)
1548  {
1549  BOOST_CHECK(category->m_Counters[category->m_Counters.size() - numberOfCores + i] ==
1550  counterWNumberOfCores->m_Uid + i);
1551  }
1552 
1553  // Register a multi-core device for testing
1554  const std::string multiCoreDeviceName = "some_multi_core_device";
1555  const Device* multiCoreDevice = nullptr;
1556  BOOST_CHECK_NO_THROW(multiCoreDevice = counterDirectory.RegisterDevice(multiCoreDeviceName, 4));
1557  BOOST_CHECK(counterDirectory.GetDeviceCount() == 2);
1558  BOOST_CHECK(multiCoreDevice);
1559  BOOST_CHECK(multiCoreDevice->m_Name == multiCoreDeviceName);
1560  BOOST_CHECK(multiCoreDevice->m_Uid >= 1);
1561  BOOST_CHECK(multiCoreDevice->m_Cores == 4);
1562 
1563  // Register a counter with a valid parent category name and associated to the multi-core device
1564  const Counter* counterWMultiCoreDevice = nullptr;
1565  BOOST_CHECK_NO_THROW(counterWMultiCoreDevice = counterDirectory.RegisterCounter(
1566  armnn::profiling::BACKEND_ID, 19, categoryName, 0, 1,
1567  123.45f, "valid name 9", "valid description",
1568  armnn::EmptyOptional(), // Units
1569  armnn::EmptyOptional(), // Number of cores
1570  multiCoreDevice->m_Uid, // Device UID
1571  armnn::EmptyOptional())); // Counter set UID
1572  BOOST_CHECK(counterDirectory.GetCounterCount() == 24);
1573  BOOST_CHECK(counterWMultiCoreDevice);
1574  BOOST_CHECK(counterWMultiCoreDevice->m_Uid > counter->m_Uid);
1575  BOOST_CHECK(counterWMultiCoreDevice->m_MaxCounterUid ==
1576  counterWMultiCoreDevice->m_Uid + multiCoreDevice->m_Cores - 1);
1577  BOOST_CHECK(counterWMultiCoreDevice->m_Class == 0);
1578  BOOST_CHECK(counterWMultiCoreDevice->m_Interpolation == 1);
1579  BOOST_CHECK(counterWMultiCoreDevice->m_Multiplier == 123.45f);
1580  BOOST_CHECK(counterWMultiCoreDevice->m_Name == "valid name 9");
1581  BOOST_CHECK(counterWMultiCoreDevice->m_Description == "valid description");
1582  BOOST_CHECK(counterWMultiCoreDevice->m_Units == "");
1583  BOOST_CHECK(counterWMultiCoreDevice->m_DeviceUid == multiCoreDevice->m_Uid);
1584  BOOST_CHECK(counterWMultiCoreDevice->m_CounterSetUid == 0);
1585  BOOST_CHECK(category->m_Counters.size() == 24);
1586  for (size_t i = 0; i < 4; i++)
1587  {
1588  BOOST_CHECK(category->m_Counters[category->m_Counters.size() - 4 + i] == counterWMultiCoreDevice->m_Uid + i);
1589  }
1590 
1591  // Register a multi-core device associate to a parent category for testing
1592  const std::string multiCoreDeviceNameWParentCategory = "some_multi_core_device_with_parent_category";
1593  const Device* multiCoreDeviceWParentCategory = nullptr;
1594  BOOST_CHECK_NO_THROW(multiCoreDeviceWParentCategory =
1595  counterDirectory.RegisterDevice(multiCoreDeviceNameWParentCategory, 2, categoryName));
1596  BOOST_CHECK(counterDirectory.GetDeviceCount() == 3);
1597  BOOST_CHECK(multiCoreDeviceWParentCategory);
1598  BOOST_CHECK(multiCoreDeviceWParentCategory->m_Name == multiCoreDeviceNameWParentCategory);
1599  BOOST_CHECK(multiCoreDeviceWParentCategory->m_Uid >= 1);
1600  BOOST_CHECK(multiCoreDeviceWParentCategory->m_Cores == 2);
1601 
1602  // Register a counter with a valid parent category name and getting the number of cores of the multi-core device
1603  // associated to that category
1604  const Counter* counterWMultiCoreDeviceWParentCategory = nullptr;
1605  BOOST_CHECK_NO_THROW(counterWMultiCoreDeviceWParentCategory =
1606  counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID,
1607  100,
1608  categoryName,
1609  0,
1610  1,
1611  123.45f,
1612  "valid name 10",
1613  "valid description",
1614  armnn::EmptyOptional(),// Units
1615  armnn::EmptyOptional(),// Number of cores
1616  armnn::EmptyOptional(),// Device UID
1617  armnn::EmptyOptional()));// Counter set UID
1618  BOOST_CHECK(counterDirectory.GetCounterCount() == 26);
1619  BOOST_CHECK(counterWMultiCoreDeviceWParentCategory);
1620  BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Uid > counter->m_Uid);
1621  BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_MaxCounterUid ==
1622  counterWMultiCoreDeviceWParentCategory->m_Uid + multiCoreDeviceWParentCategory->m_Cores - 1);
1623  BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Class == 0);
1624  BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Interpolation == 1);
1625  BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Multiplier == 123.45f);
1626  BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Name == "valid name 10");
1627  BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Description == "valid description");
1628  BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_Units == "");
1629  BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_DeviceUid == 0);
1630  BOOST_CHECK(counterWMultiCoreDeviceWParentCategory->m_CounterSetUid == 0);
1631  BOOST_CHECK(category->m_Counters.size() == 26);
1632  for (size_t i = 0; i < 2; i++)
1633  {
1634  BOOST_CHECK(category->m_Counters[category->m_Counters.size() - 2 + i] ==
1635  counterWMultiCoreDeviceWParentCategory->m_Uid + i);
1636  }
1637 
1638  // Register a counter set for testing
1639  const std::string counterSetName = "some_counter_set";
1640  const CounterSet* counterSet = nullptr;
1641  BOOST_CHECK_NO_THROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName));
1642  BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1);
1643  BOOST_CHECK(counterSet);
1644  BOOST_CHECK(counterSet->m_Name == counterSetName);
1645  BOOST_CHECK(counterSet->m_Uid >= 1);
1646  BOOST_CHECK(counterSet->m_Count == 0);
1647 
1648  // Register a counter with a valid parent category name and associated to a counter set
1649  const Counter* counterWCounterSet = nullptr;
1650  BOOST_CHECK_NO_THROW(counterWCounterSet = counterDirectory.RegisterCounter(
1651  armnn::profiling::BACKEND_ID, 300,
1652  categoryName, 0, 1, 123.45f, "valid name 11", "valid description",
1653  armnn::EmptyOptional(), // Units
1654  0, // Number of cores
1655  armnn::EmptyOptional(), // Device UID
1656  counterSet->m_Uid)); // Counter set UID
1657  BOOST_CHECK(counterDirectory.GetCounterCount() == 27);
1658  BOOST_CHECK(counterWCounterSet);
1659  BOOST_CHECK(counterWCounterSet->m_Uid > counter->m_Uid);
1660  BOOST_CHECK(counterWCounterSet->m_MaxCounterUid == counterWCounterSet->m_Uid);
1661  BOOST_CHECK(counterWCounterSet->m_Class == 0);
1662  BOOST_CHECK(counterWCounterSet->m_Interpolation == 1);
1663  BOOST_CHECK(counterWCounterSet->m_Multiplier == 123.45f);
1664  BOOST_CHECK(counterWCounterSet->m_Name == "valid name 11");
1665  BOOST_CHECK(counterWCounterSet->m_Description == "valid description");
1666  BOOST_CHECK(counterWCounterSet->m_Units == "");
1667  BOOST_CHECK(counterWCounterSet->m_DeviceUid == 0);
1668  BOOST_CHECK(counterWCounterSet->m_CounterSetUid == counterSet->m_Uid);
1669  BOOST_CHECK(category->m_Counters.size() == 27);
1670  BOOST_CHECK(category->m_Counters.back() == counterWCounterSet->m_Uid);
1671 
1672  // Register a counter with a valid parent category name and associated to a device and a counter set
1673  const Counter* counterWDeviceWCounterSet = nullptr;
1674  BOOST_CHECK_NO_THROW(counterWDeviceWCounterSet = counterDirectory.RegisterCounter(
1675  armnn::profiling::BACKEND_ID, 23,
1676  categoryName, 0, 1, 123.45f, "valid name 12", "valid description",
1677  armnn::EmptyOptional(), // Units
1678  1, // Number of cores
1679  device->m_Uid, // Device UID
1680  counterSet->m_Uid)); // Counter set UID
1681  BOOST_CHECK(counterDirectory.GetCounterCount() == 28);
1682  BOOST_CHECK(counterWDeviceWCounterSet);
1683  BOOST_CHECK(counterWDeviceWCounterSet->m_Uid > counter->m_Uid);
1684  BOOST_CHECK(counterWDeviceWCounterSet->m_MaxCounterUid == counterWDeviceWCounterSet->m_Uid);
1685  BOOST_CHECK(counterWDeviceWCounterSet->m_Class == 0);
1686  BOOST_CHECK(counterWDeviceWCounterSet->m_Interpolation == 1);
1687  BOOST_CHECK(counterWDeviceWCounterSet->m_Multiplier == 123.45f);
1688  BOOST_CHECK(counterWDeviceWCounterSet->m_Name == "valid name 12");
1689  BOOST_CHECK(counterWDeviceWCounterSet->m_Description == "valid description");
1690  BOOST_CHECK(counterWDeviceWCounterSet->m_Units == "");
1691  BOOST_CHECK(counterWDeviceWCounterSet->m_DeviceUid == device->m_Uid);
1692  BOOST_CHECK(counterWDeviceWCounterSet->m_CounterSetUid == counterSet->m_Uid);
1693  BOOST_CHECK(category->m_Counters.size() == 28);
1694  BOOST_CHECK(category->m_Counters.back() == counterWDeviceWCounterSet->m_Uid);
1695 
1696  // Register another category for testing
1697  const std::string anotherCategoryName = "some_other_category";
1698  const Category* anotherCategory = nullptr;
1699  BOOST_CHECK_NO_THROW(anotherCategory = counterDirectory.RegisterCategory(anotherCategoryName));
1700  BOOST_CHECK(counterDirectory.GetCategoryCount() == 2);
1701  BOOST_CHECK(anotherCategory);
1702  BOOST_CHECK(anotherCategory != category);
1703  BOOST_CHECK(anotherCategory->m_Name == anotherCategoryName);
1704  BOOST_CHECK(anotherCategory->m_Counters.empty());
1705  BOOST_CHECK(anotherCategory->m_DeviceUid == 0);
1706  BOOST_CHECK(anotherCategory->m_CounterSetUid == 0);
1707 
1708  // Register a counter to the other category
1709  const Counter* anotherCounter = nullptr;
1710  BOOST_CHECK_NO_THROW(anotherCounter = counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, 24,
1711  anotherCategoryName, 1, 0, .00043f,
1712  "valid name", "valid description",
1713  armnn::EmptyOptional(), // Units
1714  armnn::EmptyOptional(), // Number of cores
1715  device->m_Uid, // Device UID
1716  counterSet->m_Uid)); // Counter set UID
1717  BOOST_CHECK(counterDirectory.GetCounterCount() == 29);
1718  BOOST_CHECK(anotherCounter);
1719  BOOST_CHECK(anotherCounter->m_MaxCounterUid == anotherCounter->m_Uid);
1720  BOOST_CHECK(anotherCounter->m_Class == 1);
1721  BOOST_CHECK(anotherCounter->m_Interpolation == 0);
1722  BOOST_CHECK(anotherCounter->m_Multiplier == .00043f);
1723  BOOST_CHECK(anotherCounter->m_Name == "valid name");
1724  BOOST_CHECK(anotherCounter->m_Description == "valid description");
1725  BOOST_CHECK(anotherCounter->m_Units == "");
1726  BOOST_CHECK(anotherCounter->m_DeviceUid == device->m_Uid);
1727  BOOST_CHECK(anotherCounter->m_CounterSetUid == counterSet->m_Uid);
1728  BOOST_CHECK(anotherCategory->m_Counters.size() == 1);
1729  BOOST_CHECK(anotherCategory->m_Counters.back() == anotherCounter->m_Uid);
1730 }
const Category * RegisterCategory(const std::string &categoryName, const Optional< uint16_t > &deviceUid=EmptyOptional(), const Optional< uint16_t > &counterSetUid=EmptyOptional()) override
const Device * RegisterDevice(const std::string &deviceName, uint16_t cores=0, const Optional< std::string > &parentCategoryName=EmptyOptional()) override
const Counter * GetCounter(uint16_t uid) const override
const Counter * RegisterCounter(const BackendId &backendId, const uint16_t uid, const std::string &parentCategoryName, uint16_t counterClass, uint16_t interpolation, double multiplier, const std::string &name, const std::string &description, const Optional< std::string > &units=EmptyOptional(), const Optional< uint16_t > &numberOfCores=EmptyOptional(), const Optional< uint16_t > &deviceUid=EmptyOptional(), const Optional< uint16_t > &counterSetUid=EmptyOptional()) override
std::vector< uint16_t > m_Counters
uint16_t GetCounterCount() const override
uint16_t GetCategoryCount() const override
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
uint16_t GetCounterSetCount() const override
uint16_t GetDeviceCount() const override
const CounterSet * RegisterCounterSet(const std::string &counterSetName, uint16_t count=0, const Optional< std::string > &parentCategoryName=EmptyOptional()) override

◆ BOOST_AUTO_TEST_CASE() [20/50]

BOOST_AUTO_TEST_CASE ( CounterSelectionCommandHandlerParseData  )

Definition at line 1732 of file ProfilingTests.cpp.

References armnn::profiling::Active, Holder::GetCaptureData(), CaptureData::GetCapturePeriod(), CaptureData::GetCounterIds(), MockBufferManager::GetReadableBuffer(), armnn::LOWEST_CAPTURE_PERIOD, MockBufferManager::MarkRead(), armnn::profiling::NotConnected, armnn::profiling::ReadUint16(), armnn::profiling::ReadUint32(), ProfilingStateMachine::TransitionToState(), armnn::profiling::Uninitialised, armnn::profiling::WaitingForAck, armnn::profiling::WriteUint16(), and armnn::profiling::WriteUint32().

1733 {
1734  using boost::numeric_cast;
1735 
1736  ProfilingStateMachine profilingStateMachine;
1737 
1738  class TestCaptureThread : public IPeriodicCounterCapture
1739  {
1740  void Start() override
1741  {}
1742  void Stop() override
1743  {}
1744  };
1745 
1746  class TestReadCounterValues : public IReadCounterValues
1747  {
1748  bool IsCounterRegistered(uint16_t counterUid) const override
1749  {
1750  boost::ignore_unused(counterUid);
1751  return true;
1752  }
1753  uint16_t GetCounterCount() const override
1754  {
1755  return 0;
1756  }
1757  uint32_t GetCounterValue(uint16_t counterUid) const override
1758  {
1759  boost::ignore_unused(counterUid);
1760  return 0;
1761  }
1762  };
1763  const uint32_t familyId = 0;
1764  const uint32_t packetId = 0x40000;
1765 
1766  uint32_t version = 1;
1767  const std::unordered_map<armnn::BackendId,
1768  std::shared_ptr<armnn::profiling::IBackendProfilingContext>> backendProfilingContext;
1769  CounterIdMap counterIdMap;
1770  Holder holder;
1771  TestCaptureThread captureThread;
1772  TestReadCounterValues readCounterValues;
1773  MockBufferManager mockBuffer(512);
1774  SendCounterPacket sendCounterPacket(mockBuffer);
1775  SendThread sendThread(profilingStateMachine, mockBuffer, sendCounterPacket);
1776 
1777  uint32_t sizeOfUint32 = numeric_cast<uint32_t>(sizeof(uint32_t));
1778  uint32_t sizeOfUint16 = numeric_cast<uint32_t>(sizeof(uint16_t));
1779 
1780  // Data with period and counters
1781  uint32_t period1 = armnn::LOWEST_CAPTURE_PERIOD;
1782  uint32_t dataLength1 = 8;
1783  uint32_t offset = 0;
1784 
1785  std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength1);
1786  unsigned char* data1 = reinterpret_cast<unsigned char*>(uniqueData1.get());
1787 
1788  WriteUint32(data1, offset, period1);
1789  offset += sizeOfUint32;
1790  WriteUint16(data1, offset, 4000);
1791  offset += sizeOfUint16;
1792  WriteUint16(data1, offset, 5000);
1793 
1794  Packet packetA(packetId, dataLength1, uniqueData1);
1795 
1796  PeriodicCounterSelectionCommandHandler commandHandler(familyId, packetId, version, backendProfilingContext,
1797  counterIdMap, holder, 10000u, captureThread,
1798  readCounterValues, sendCounterPacket, profilingStateMachine);
1799 
1800  profilingStateMachine.TransitionToState(ProfilingState::Uninitialised);
1801  BOOST_CHECK_THROW(commandHandler(packetA), armnn::RuntimeException);
1802  profilingStateMachine.TransitionToState(ProfilingState::NotConnected);
1803  BOOST_CHECK_THROW(commandHandler(packetA), armnn::RuntimeException);
1804  profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck);
1805  BOOST_CHECK_THROW(commandHandler(packetA), armnn::RuntimeException);
1806  profilingStateMachine.TransitionToState(ProfilingState::Active);
1807  BOOST_CHECK_NO_THROW(commandHandler(packetA));
1808 
1809  const std::vector<uint16_t> counterIdsA = holder.GetCaptureData().GetCounterIds();
1810 
1811  BOOST_TEST(holder.GetCaptureData().GetCapturePeriod() == period1);
1812  BOOST_TEST(counterIdsA.size() == 2);
1813  BOOST_TEST(counterIdsA[0] == 4000);
1814  BOOST_TEST(counterIdsA[1] == 5000);
1815 
1816  auto readBuffer = mockBuffer.GetReadableBuffer();
1817 
1818  offset = 0;
1819 
1820  uint32_t headerWord0 = ReadUint32(readBuffer, offset);
1821  offset += sizeOfUint32;
1822  uint32_t headerWord1 = ReadUint32(readBuffer, offset);
1823  offset += sizeOfUint32;
1824  uint32_t period = ReadUint32(readBuffer, offset);
1825 
1826  BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0); // packet family
1827  BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 4); // packet id
1828  BOOST_TEST(headerWord1 == 8); // data length
1829  BOOST_TEST(period == armnn::LOWEST_CAPTURE_PERIOD); // capture period
1830 
1831  uint16_t counterId = 0;
1832  offset += sizeOfUint32;
1833  counterId = ReadUint16(readBuffer, offset);
1834  BOOST_TEST(counterId == 4000);
1835  offset += sizeOfUint16;
1836  counterId = ReadUint16(readBuffer, offset);
1837  BOOST_TEST(counterId == 5000);
1838 
1839  mockBuffer.MarkRead(readBuffer);
1840 
1841  // Data with period only
1842  uint32_t period2 = 9000; // We'll specify a value below LOWEST_CAPTURE_PERIOD. It should be pulled upwards.
1843  uint32_t dataLength2 = 4;
1844 
1845  std::unique_ptr<unsigned char[]> uniqueData2 = std::make_unique<unsigned char[]>(dataLength2);
1846 
1847  WriteUint32(reinterpret_cast<unsigned char*>(uniqueData2.get()), 0, period2);
1848 
1849  Packet packetB(packetId, dataLength2, uniqueData2);
1850 
1851  commandHandler(packetB);
1852 
1853  const std::vector<uint16_t> counterIdsB = holder.GetCaptureData().GetCounterIds();
1854 
1855  // Value should have been pulled up from 9000 to LOWEST_CAPTURE_PERIOD.
1856  BOOST_TEST(holder.GetCaptureData().GetCapturePeriod() == armnn::LOWEST_CAPTURE_PERIOD);
1857  BOOST_TEST(counterIdsB.size() == 0);
1858 
1859  readBuffer = mockBuffer.GetReadableBuffer();
1860 
1861  offset = 0;
1862 
1863  headerWord0 = ReadUint32(readBuffer, offset);
1864  offset += sizeOfUint32;
1865  headerWord1 = ReadUint32(readBuffer, offset);
1866  offset += sizeOfUint32;
1867  period = ReadUint32(readBuffer, offset);
1868 
1869  BOOST_TEST(((headerWord0 >> 26) & 0x3F) == 0); // packet family
1870  BOOST_TEST(((headerWord0 >> 16) & 0x3FF) == 4); // packet id
1871  BOOST_TEST(headerWord1 == 4); // data length
1872  BOOST_TEST(period == armnn::LOWEST_CAPTURE_PERIOD); // capture period
1873 }
void WriteUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint16_t value)
uint16_t ReadUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset)
constexpr unsigned int LOWEST_CAPTURE_PERIOD
Definition: Types.hpp:21
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)
void WriteUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint32_t value)

◆ BOOST_AUTO_TEST_CASE() [21/50]

BOOST_AUTO_TEST_CASE ( CheckConnectionAcknowledged  )

Definition at line 1875 of file ProfilingTests.cpp.

References armnn::profiling::Active, BOOST_CHECK(), ProfilingStateMachine::GetCurrentState(), armnn::profiling::NotConnected, ProfilingStateMachine::TransitionToState(), armnn::profiling::Uninitialised, armnn::profiling::WaitingForAck, armnn::profiling::WriteUint16(), and armnn::profiling::WriteUint32().

1876 {
1877  using boost::numeric_cast;
1878 
1879  const uint32_t packetFamilyId = 0;
1880  const uint32_t connectionPacketId = 0x10000;
1881  const uint32_t version = 1;
1882 
1883  uint32_t sizeOfUint32 = numeric_cast<uint32_t>(sizeof(uint32_t));
1884  uint32_t sizeOfUint16 = numeric_cast<uint32_t>(sizeof(uint16_t));
1885 
1886  // Data with period and counters
1887  uint32_t period1 = 10;
1888  uint32_t dataLength1 = 8;
1889  uint32_t offset = 0;
1890 
1891  std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength1);
1892  unsigned char* data1 = reinterpret_cast<unsigned char*>(uniqueData1.get());
1893 
1894  WriteUint32(data1, offset, period1);
1895  offset += sizeOfUint32;
1896  WriteUint16(data1, offset, 4000);
1897  offset += sizeOfUint16;
1898  WriteUint16(data1, offset, 5000);
1899 
1900  Packet packetA(connectionPacketId, dataLength1, uniqueData1);
1901 
1902  ProfilingStateMachine profilingState(ProfilingState::Uninitialised);
1903  BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::Uninitialised);
1904  CounterDirectory counterDirectory;
1905  MockBufferManager mockBuffer(1024);
1906  SendCounterPacket sendCounterPacket(mockBuffer);
1907  SendThread sendThread(profilingState, mockBuffer, sendCounterPacket);
1908  SendTimelinePacket sendTimelinePacket(mockBuffer);
1909 
1910  ConnectionAcknowledgedCommandHandler commandHandler(packetFamilyId, connectionPacketId, version, counterDirectory,
1911  sendCounterPacket, sendTimelinePacket, profilingState);
1912 
1913  // command handler received packet on ProfilingState::Uninitialised
1914  BOOST_CHECK_THROW(commandHandler(packetA), armnn::Exception);
1915 
1916  profilingState.TransitionToState(ProfilingState::NotConnected);
1917  BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::NotConnected);
1918  // command handler received packet on ProfilingState::NotConnected
1919  BOOST_CHECK_THROW(commandHandler(packetA), armnn::Exception);
1920 
1921  profilingState.TransitionToState(ProfilingState::WaitingForAck);
1922  BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::WaitingForAck);
1923  // command handler received packet on ProfilingState::WaitingForAck
1924  BOOST_CHECK_NO_THROW(commandHandler(packetA));
1925  BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::Active);
1926 
1927  // command handler received packet on ProfilingState::Active
1928  BOOST_CHECK_NO_THROW(commandHandler(packetA));
1929  BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::Active);
1930 
1931  // command handler received different packet
1932  const uint32_t differentPacketId = 0x40000;
1933  Packet packetB(differentPacketId, dataLength1, uniqueData1);
1934  profilingState.TransitionToState(ProfilingState::NotConnected);
1935  profilingState.TransitionToState(ProfilingState::WaitingForAck);
1936  ConnectionAcknowledgedCommandHandler differentCommandHandler(packetFamilyId, differentPacketId, version,
1937  counterDirectory, sendCounterPacket,
1938  sendTimelinePacket, profilingState);
1939  BOOST_CHECK_THROW(differentCommandHandler(packetB), armnn::Exception);
1940 }
void WriteUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint16_t value)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
void WriteUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint32_t value)

◆ BOOST_AUTO_TEST_CASE() [22/50]

BOOST_AUTO_TEST_CASE ( CheckSocketProfilingConnection  )

Definition at line 1942 of file ProfilingTests.cpp.

1943 {
1944  // Check that creating a SocketProfilingConnection results in an exception as the Gator UDS doesn't exist.
1945  BOOST_CHECK_THROW(new SocketProfilingConnection(), armnn::Exception);
1946 }
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46

◆ BOOST_AUTO_TEST_CASE() [23/50]

BOOST_AUTO_TEST_CASE ( SwTraceIsValidCharTest  )

Definition at line 1948 of file ProfilingTests.cpp.

References BOOST_CHECK(), and SwTraceCharPolicy::IsValidChar().

1949 {
1950  // Only ASCII 7-bit encoding supported
1951  for (unsigned char c = 0; c < 128; c++)
1952  {
1953  BOOST_CHECK(SwTraceCharPolicy::IsValidChar(c));
1954  }
1955 
1956  // Not ASCII
1957  for (unsigned char c = 255; c >= 128; c++)
1958  {
1959  BOOST_CHECK(!SwTraceCharPolicy::IsValidChar(c));
1960  }
1961 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)

◆ BOOST_AUTO_TEST_CASE() [24/50]

BOOST_AUTO_TEST_CASE ( SwTraceIsValidNameCharTest  )

Definition at line 1963 of file ProfilingTests.cpp.

References BOOST_CHECK(), and SwTraceNameCharPolicy::IsValidChar().

1964 {
1965  // Only alpha-numeric and underscore ASCII 7-bit encoding supported
1966  const unsigned char validChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
1967  for (unsigned char i = 0; i < sizeof(validChars) / sizeof(validChars[0]) - 1; i++)
1968  {
1969  BOOST_CHECK(SwTraceNameCharPolicy::IsValidChar(validChars[i]));
1970  }
1971 
1972  // Non alpha-numeric chars
1973  for (unsigned char c = 0; c < 48; c++)
1974  {
1975  BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c));
1976  }
1977  for (unsigned char c = 58; c < 65; c++)
1978  {
1979  BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c));
1980  }
1981  for (unsigned char c = 91; c < 95; c++)
1982  {
1983  BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c));
1984  }
1985  for (unsigned char c = 96; c < 97; c++)
1986  {
1987  BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c));
1988  }
1989  for (unsigned char c = 123; c < 128; c++)
1990  {
1991  BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c));
1992  }
1993 
1994  // Not ASCII
1995  for (unsigned char c = 255; c >= 128; c++)
1996  {
1997  BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c));
1998  }
1999 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)

◆ BOOST_AUTO_TEST_CASE() [25/50]

BOOST_AUTO_TEST_CASE ( IsValidSwTraceStringTest  )

Definition at line 2001 of file ProfilingTests.cpp.

References BOOST_CHECK().

2002 {
2003  // Valid SWTrace strings
2004  BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>(""));
2005  BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("_"));
2006  BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("0123"));
2007  BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("valid_string"));
2008  BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("VALID_string_456"));
2009  BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>(" "));
2010  BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("valid string"));
2011  BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("!$%"));
2012  BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("valid|\\~string#123"));
2013 
2014  // Invalid SWTrace strings
2015  BOOST_CHECK(!IsValidSwTraceString<SwTraceCharPolicy>("€£"));
2016  BOOST_CHECK(!IsValidSwTraceString<SwTraceCharPolicy>("invalid‡string"));
2017  BOOST_CHECK(!IsValidSwTraceString<SwTraceCharPolicy>("12Ž34"));
2018 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)

◆ BOOST_AUTO_TEST_CASE() [26/50]

BOOST_AUTO_TEST_CASE ( IsValidSwTraceNameStringTest  )

Definition at line 2020 of file ProfilingTests.cpp.

References BOOST_CHECK().

2021 {
2022  // Valid SWTrace name strings
2023  BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>(""));
2024  BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("_"));
2025  BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("0123"));
2026  BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("valid_string"));
2027  BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("VALID_string_456"));
2028 
2029  // Invalid SWTrace name strings
2030  BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>(" "));
2031  BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("invalid string"));
2032  BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("!$%"));
2033  BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("invalid|\\~string#123"));
2034  BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("€£"));
2035  BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("invalid‡string"));
2036  BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("12Ž34"));
2037 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)

◆ BOOST_AUTO_TEST_CASE() [27/50]

BOOST_AUTO_TEST_CASE ( StringToSwTraceStringTest  )

Definition at line 2062 of file ProfilingTests.cpp.

References BOOST_CHECK().

2063 {
2064  std::vector<uint32_t> buffer;
2065 
2066  // Valid SWTrace strings (expected size in words)
2067  StringToSwTraceStringTestHelper<SwTraceCharPolicy>("", buffer, 2);
2068  StringToSwTraceStringTestHelper<SwTraceCharPolicy>("_", buffer, 2);
2069  StringToSwTraceStringTestHelper<SwTraceCharPolicy>("0123", buffer, 3);
2070  StringToSwTraceStringTestHelper<SwTraceCharPolicy>("valid_string", buffer, 5);
2071  StringToSwTraceStringTestHelper<SwTraceCharPolicy>("VALID_string_456", buffer, 6);
2072  StringToSwTraceStringTestHelper<SwTraceCharPolicy>(" ", buffer, 2);
2073  StringToSwTraceStringTestHelper<SwTraceCharPolicy>("valid string", buffer, 5);
2074  StringToSwTraceStringTestHelper<SwTraceCharPolicy>("!$%", buffer, 2);
2075  StringToSwTraceStringTestHelper<SwTraceCharPolicy>("valid|\\~string#123", buffer, 6);
2076 
2077  // Invalid SWTrace strings
2078  BOOST_CHECK(!StringToSwTraceString<SwTraceCharPolicy>("€£", buffer));
2079  BOOST_CHECK(buffer.empty());
2080  BOOST_CHECK(!StringToSwTraceString<SwTraceCharPolicy>("invalid‡string", buffer));
2081  BOOST_CHECK(buffer.empty());
2082  BOOST_CHECK(!StringToSwTraceString<SwTraceCharPolicy>("12Ž34", buffer));
2083  BOOST_CHECK(buffer.empty());
2084 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)

◆ BOOST_AUTO_TEST_CASE() [28/50]

BOOST_AUTO_TEST_CASE ( StringToSwTraceNameStringTest  )

Definition at line 2086 of file ProfilingTests.cpp.

References BOOST_CHECK().

2087 {
2088  std::vector<uint32_t> buffer;
2089 
2090  // Valid SWTrace namestrings (expected size in words)
2091  StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("", buffer, 2);
2092  StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("_", buffer, 2);
2093  StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("0123", buffer, 3);
2094  StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("valid_string", buffer, 5);
2095  StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("VALID_string_456", buffer, 6);
2096 
2097  // Invalid SWTrace namestrings
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>("!$%", buffer));
2103  BOOST_CHECK(buffer.empty());
2104  BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("invalid|\\~string#123", buffer));
2105  BOOST_CHECK(buffer.empty());
2106  BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("€£", buffer));
2107  BOOST_CHECK(buffer.empty());
2108  BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("invalid‡string", buffer));
2109  BOOST_CHECK(buffer.empty());
2110  BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("12Ž34", buffer));
2111  BOOST_CHECK(buffer.empty());
2112 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)

◆ BOOST_AUTO_TEST_CASE() [29/50]

BOOST_AUTO_TEST_CASE ( CheckPeriodicCounterCaptureThread  )

Definition at line 2114 of file ProfilingTests.cpp.

References MockBufferManager::GetReadableBuffer(), armnn::profiling::ReadUint16(), armnn::profiling::ReadUint32(), Holder::SetCaptureData(), PeriodicCounterCapture::Start(), and PeriodicCounterCapture::Stop().

2115 {
2116  class CaptureReader : public IReadCounterValues
2117  {
2118  public:
2119  CaptureReader(uint16_t counterSize)
2120  {
2121  for (uint16_t i = 0; i < counterSize; ++i)
2122  {
2123  m_Data[i] = 0;
2124  }
2125  m_CounterSize = counterSize;
2126  }
2127  //not used
2128  bool IsCounterRegistered(uint16_t counterUid) const override
2129  {
2130  boost::ignore_unused(counterUid);
2131  return false;
2132  }
2133 
2134  uint16_t GetCounterCount() const override
2135  {
2136  return m_CounterSize;
2137  }
2138 
2139  uint32_t GetCounterValue(uint16_t counterUid) const override
2140  {
2141  if (counterUid > m_CounterSize)
2142  {
2143  BOOST_FAIL("Invalid counter Uid");
2144  }
2145  return m_Data.at(counterUid).load();
2146  }
2147 
2148  void SetCounterValue(uint16_t counterUid, uint32_t value)
2149  {
2150  if (counterUid > m_CounterSize)
2151  {
2152  BOOST_FAIL("Invalid counter Uid");
2153  }
2154  m_Data.at(counterUid).store(value);
2155  }
2156 
2157  private:
2158  std::unordered_map<uint16_t, std::atomic<uint32_t>> m_Data;
2159  uint16_t m_CounterSize;
2160  };
2161 
2162  ProfilingStateMachine profilingStateMachine;
2163 
2164  const std::unordered_map<armnn::BackendId,
2165  std::shared_ptr<armnn::profiling::IBackendProfilingContext>> backendProfilingContext;
2166  CounterIdMap counterIdMap;
2167  Holder data;
2168  std::vector<uint16_t> captureIds1 = { 0, 1 };
2169  std::vector<uint16_t> captureIds2;
2170 
2171  MockBufferManager mockBuffer(512);
2172  SendCounterPacket sendCounterPacket(mockBuffer);
2173  SendThread sendThread(profilingStateMachine, mockBuffer, sendCounterPacket);
2174 
2175  std::vector<uint16_t> counterIds;
2176  CaptureReader captureReader(2);
2177 
2178  unsigned int valueA = 10;
2179  unsigned int valueB = 15;
2180  unsigned int numSteps = 5;
2181 
2182  PeriodicCounterCapture periodicCounterCapture(std::ref(data), std::ref(sendCounterPacket), captureReader,
2183  counterIdMap, backendProfilingContext);
2184 
2185  for (unsigned int i = 0; i < numSteps; ++i)
2186  {
2187  data.SetCaptureData(1, captureIds1, {});
2188  captureReader.SetCounterValue(0, valueA * (i + 1));
2189  captureReader.SetCounterValue(1, valueB * (i + 1));
2190 
2191  periodicCounterCapture.Start();
2192  periodicCounterCapture.Stop();
2193  }
2194 
2195  auto buffer = mockBuffer.GetReadableBuffer();
2196 
2197  uint32_t headerWord0 = ReadUint32(buffer, 0);
2198  uint32_t headerWord1 = ReadUint32(buffer, 4);
2199 
2200  BOOST_TEST(((headerWord0 >> 26) & 0x0000003F) == 3); // packet family
2201  BOOST_TEST(((headerWord0 >> 19) & 0x0000007F) == 0); // packet class
2202  BOOST_TEST(((headerWord0 >> 16) & 0x00000007) == 0); // packet type
2203  BOOST_TEST(headerWord1 == 20);
2204 
2205  uint32_t offset = 16;
2206  uint16_t readIndex = ReadUint16(buffer, offset);
2207  BOOST_TEST(0 == readIndex);
2208 
2209  offset += 2;
2210  uint32_t readValue = ReadUint32(buffer, offset);
2211  BOOST_TEST((valueA * numSteps) == readValue);
2212 
2213  offset += 4;
2214  readIndex = ReadUint16(buffer, offset);
2215  BOOST_TEST(1 == readIndex);
2216 
2217  offset += 2;
2218  readValue = ReadUint32(buffer, offset);
2219  BOOST_TEST((valueB * numSteps) == readValue);
2220 }
virtual bool IsCounterRegistered(uint16_t counterUid) const =0
uint16_t ReadUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset)
void SetCaptureData(uint32_t capturePeriod, const std::vector< uint16_t > &counterIds, const std::set< armnn::BackendId > &activeBackends)
Definition: Holder.cpp:74
virtual uint16_t GetCounterCount() const =0
virtual uint32_t GetCounterValue(uint16_t counterUid) const =0
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)

◆ BOOST_AUTO_TEST_CASE() [30/50]

BOOST_AUTO_TEST_CASE ( RequestCounterDirectoryCommandHandlerTest1  )

Definition at line 2222 of file ProfilingTests.cpp.

References armnn::profiling::Active, MockBufferManager::GetReadableBuffer(), armnn::profiling::NotConnected, armnn::profiling::ReadUint32(), ProfilingStateMachine::TransitionToState(), armnn::profiling::Uninitialised, and armnn::profiling::WaitingForAck.

2223 {
2224  using boost::numeric_cast;
2225 
2226  const uint32_t familyId = 0;
2227  const uint32_t packetId = 3;
2228  const uint32_t version = 1;
2229  ProfilingStateMachine profilingStateMachine;
2230  CounterDirectory counterDirectory;
2231  MockBufferManager mockBuffer1(1024);
2232  SendCounterPacket sendCounterPacket(mockBuffer1);
2233  SendThread sendThread(profilingStateMachine, mockBuffer1, sendCounterPacket);
2234  MockBufferManager mockBuffer2(1024);
2235  SendTimelinePacket sendTimelinePacket(mockBuffer2);
2236  RequestCounterDirectoryCommandHandler commandHandler(familyId, packetId, version, counterDirectory,
2237  sendCounterPacket, sendTimelinePacket, profilingStateMachine);
2238 
2239  const uint32_t wrongPacketId = 47;
2240  const uint32_t wrongHeader = (wrongPacketId & 0x000003FF) << 16;
2241 
2242  Packet wrongPacket(wrongHeader);
2243 
2244  profilingStateMachine.TransitionToState(ProfilingState::Uninitialised);
2245  BOOST_CHECK_THROW(commandHandler(wrongPacket), armnn::RuntimeException); // Wrong profiling state
2246  profilingStateMachine.TransitionToState(ProfilingState::NotConnected);
2247  BOOST_CHECK_THROW(commandHandler(wrongPacket), armnn::RuntimeException); // Wrong profiling state
2248  profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck);
2249  BOOST_CHECK_THROW(commandHandler(wrongPacket), armnn::RuntimeException); // Wrong profiling state
2250  profilingStateMachine.TransitionToState(ProfilingState::Active);
2251  BOOST_CHECK_THROW(commandHandler(wrongPacket), armnn::InvalidArgumentException); // Wrong packet
2252 
2253  const uint32_t rightHeader = (packetId & 0x000003FF) << 16;
2254 
2255  Packet rightPacket(rightHeader);
2256 
2257  BOOST_CHECK_NO_THROW(commandHandler(rightPacket)); // Right packet
2258 
2259  auto readBuffer1 = mockBuffer1.GetReadableBuffer();
2260 
2261  uint32_t header1Word0 = ReadUint32(readBuffer1, 0);
2262  uint32_t header1Word1 = ReadUint32(readBuffer1, 4);
2263 
2264  // Counter directory packet
2265  BOOST_TEST(((header1Word0 >> 26) & 0x0000003F) == 0); // packet family
2266  BOOST_TEST(((header1Word0 >> 16) & 0x000003FF) == 2); // packet id
2267  BOOST_TEST(header1Word1 == 24); // data length
2268 
2269  uint32_t bodyHeader1Word0 = ReadUint32(readBuffer1, 8);
2270  uint16_t deviceRecordCount = numeric_cast<uint16_t>(bodyHeader1Word0 >> 16);
2271  BOOST_TEST(deviceRecordCount == 0); // device_records_count
2272 
2273  auto readBuffer2 = mockBuffer2.GetReadableBuffer();
2274 
2275  uint32_t header2Word0 = ReadUint32(readBuffer2, 0);
2276  uint32_t header2Word1 = ReadUint32(readBuffer2, 4);
2277 
2278  // Timeline message directory packet
2279  BOOST_TEST(((header2Word0 >> 26) & 0x0000003F) == 1); // packet family
2280  BOOST_TEST(((header2Word0 >> 16) & 0x000003FF) == 0); // packet id
2281  BOOST_TEST(header2Word1 == 419); // data length
2282 }
void TransitionToState(ProfilingState newState)
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)

◆ BOOST_AUTO_TEST_CASE() [31/50]

BOOST_AUTO_TEST_CASE ( RequestCounterDirectoryCommandHandlerTest2  )

Definition at line 2284 of file ProfilingTests.cpp.

References armnn::profiling::Active, BOOST_CHECK(), MockBufferManager::GetReadableBuffer(), Device::m_Uid, CounterSet::m_Uid, armnn::profiling::NotConnected, armnn::profiling::ReadUint32(), CounterDirectory::RegisterCategory(), CounterDirectory::RegisterCounter(), CounterDirectory::RegisterCounterSet(), CounterDirectory::RegisterDevice(), ProfilingStateMachine::TransitionToState(), armnn::profiling::Uninitialised, and armnn::profiling::WaitingForAck.

2285 {
2286  using boost::numeric_cast;
2287 
2288  const uint32_t familyId = 0;
2289  const uint32_t packetId = 3;
2290  const uint32_t version = 1;
2291  ProfilingStateMachine profilingStateMachine;
2292  CounterDirectory counterDirectory;
2293  MockBufferManager mockBuffer1(1024);
2294  SendCounterPacket sendCounterPacket(mockBuffer1);
2295  SendThread sendThread(profilingStateMachine, mockBuffer1, sendCounterPacket);
2296  MockBufferManager mockBuffer2(1024);
2297  SendTimelinePacket sendTimelinePacket(mockBuffer2);
2298  RequestCounterDirectoryCommandHandler commandHandler(familyId, packetId, version, counterDirectory,
2299  sendCounterPacket, sendTimelinePacket, profilingStateMachine);
2300  const uint32_t header = (packetId & 0x000003FF) << 16;
2301  Packet packet(header);
2302 
2303  const Device* device = counterDirectory.RegisterDevice("deviceA", 1);
2304  BOOST_CHECK(device != nullptr);
2305  const CounterSet* counterSet = counterDirectory.RegisterCounterSet("countersetA");
2306  BOOST_CHECK(counterSet != nullptr);
2307  counterDirectory.RegisterCategory("categoryA", device->m_Uid, counterSet->m_Uid);
2308  counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, 24,
2309  "categoryA", 0, 1, 2.0f, "counterA", "descA");
2310  counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, 25,
2311  "categoryA", 1, 1, 3.0f, "counterB", "descB");
2312 
2313  profilingStateMachine.TransitionToState(ProfilingState::Uninitialised);
2314  BOOST_CHECK_THROW(commandHandler(packet), armnn::RuntimeException); // Wrong profiling state
2315  profilingStateMachine.TransitionToState(ProfilingState::NotConnected);
2316  BOOST_CHECK_THROW(commandHandler(packet), armnn::RuntimeException); // Wrong profiling state
2317  profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck);
2318  BOOST_CHECK_THROW(commandHandler(packet), armnn::RuntimeException); // Wrong profiling state
2319  profilingStateMachine.TransitionToState(ProfilingState::Active);
2320  BOOST_CHECK_NO_THROW(commandHandler(packet));
2321 
2322  auto readBuffer1 = mockBuffer1.GetReadableBuffer();
2323 
2324  uint32_t header1Word0 = ReadUint32(readBuffer1, 0);
2325  uint32_t header1Word1 = ReadUint32(readBuffer1, 4);
2326 
2327  BOOST_TEST(((header1Word0 >> 26) & 0x0000003F) == 0); // packet family
2328  BOOST_TEST(((header1Word0 >> 16) & 0x000003FF) == 2); // packet id
2329  BOOST_TEST(header1Word1 == 240); // data length
2330 
2331  uint32_t bodyHeader1Word0 = ReadUint32(readBuffer1, 8);
2332  uint32_t bodyHeader1Word1 = ReadUint32(readBuffer1, 12);
2333  uint32_t bodyHeader1Word2 = ReadUint32(readBuffer1, 16);
2334  uint32_t bodyHeader1Word3 = ReadUint32(readBuffer1, 20);
2335  uint32_t bodyHeader1Word4 = ReadUint32(readBuffer1, 24);
2336  uint32_t bodyHeader1Word5 = ReadUint32(readBuffer1, 28);
2337  uint16_t deviceRecordCount = numeric_cast<uint16_t>(bodyHeader1Word0 >> 16);
2338  uint16_t counterSetRecordCount = numeric_cast<uint16_t>(bodyHeader1Word2 >> 16);
2339  uint16_t categoryRecordCount = numeric_cast<uint16_t>(bodyHeader1Word4 >> 16);
2340  BOOST_TEST(deviceRecordCount == 1); // device_records_count
2341  BOOST_TEST(bodyHeader1Word1 == 0); // device_records_pointer_table_offset
2342  BOOST_TEST(counterSetRecordCount == 1); // counter_set_count
2343  BOOST_TEST(bodyHeader1Word3 == 4); // counter_set_pointer_table_offset
2344  BOOST_TEST(categoryRecordCount == 1); // categories_count
2345  BOOST_TEST(bodyHeader1Word5 == 8); // categories_pointer_table_offset
2346 
2347  uint32_t deviceRecordOffset = ReadUint32(readBuffer1, 32);
2348  BOOST_TEST(deviceRecordOffset == 0);
2349 
2350  uint32_t counterSetRecordOffset = ReadUint32(readBuffer1, 36);
2351  BOOST_TEST(counterSetRecordOffset == 20);
2352 
2353  uint32_t categoryRecordOffset = ReadUint32(readBuffer1, 40);
2354  BOOST_TEST(categoryRecordOffset == 44);
2355 
2356  auto readBuffer2 = mockBuffer2.GetReadableBuffer();
2357 
2358  uint32_t header2Word0 = ReadUint32(readBuffer2, 0);
2359  uint32_t header2Word1 = ReadUint32(readBuffer2, 4);
2360 
2361  // Timeline message directory packet
2362  BOOST_TEST(((header2Word0 >> 26) & 0x0000003F) == 1); // packet family
2363  BOOST_TEST(((header2Word0 >> 16) & 0x000003FF) == 0); // packet id
2364  BOOST_TEST(header2Word1 == 419); // data length
2365 }
const Category * RegisterCategory(const std::string &categoryName, const Optional< uint16_t > &deviceUid=EmptyOptional(), const Optional< uint16_t > &counterSetUid=EmptyOptional()) override
const Device * RegisterDevice(const std::string &deviceName, uint16_t cores=0, const Optional< std::string > &parentCategoryName=EmptyOptional()) override
void TransitionToState(ProfilingState newState)
const Counter * RegisterCounter(const BackendId &backendId, const uint16_t uid, const std::string &parentCategoryName, uint16_t counterClass, uint16_t interpolation, double multiplier, const std::string &name, const std::string &description, const Optional< std::string > &units=EmptyOptional(), const Optional< uint16_t > &numberOfCores=EmptyOptional(), const Optional< uint16_t > &deviceUid=EmptyOptional(), const Optional< uint16_t > &counterSetUid=EmptyOptional()) override
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)
const CounterSet * RegisterCounterSet(const std::string &counterSetName, uint16_t count=0, const Optional< std::string > &parentCategoryName=EmptyOptional()) override

◆ BOOST_AUTO_TEST_CASE() [32/50]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceGoodConnectionAcknowledgedPacket  )

Definition at line 2367 of file ProfilingTests.cpp.

References armnn::profiling::Active, BOOST_CHECK(), MockProfilingConnection::Clear(), armnn::profiling::CounterDirectory, ProfilingService::GetCurrentState(), SwapProfilingConnectionFactoryHelper::GetMockProfilingConnection(), armnn::profiling::GetProcessName(), helper, ProfilingService::Instance(), armnn::profiling::NotConnected, options, profilingService, ProfilingService::ResetExternalProfilingOptions(), armnn::profiling::StreamMetaData, armnn::profiling::Uninitialised, ProfilingService::Update(), SwapProfilingConnectionFactoryHelper::WaitForPacketsSent(), armnn::profiling::WaitingForAck, and MockProfilingConnection::WritePacket().

2368 {
2369  // Swap the profiling connection factory in the profiling service instance with our mock one
2371 
2372  // Calculate the size of a Stream Metadata packet
2373  std::string processName = GetProcessName().substr(0, 60);
2374  unsigned int processNameSize = processName.empty() ? 0 : boost::numeric_cast<unsigned int>(processName.size()) + 1;
2375  unsigned int streamMetadataPacketsize = 118 + processNameSize;
2376 
2377  // Reset the profiling service to the uninitialized state
2378  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2379  options.m_EnableProfiling = true;
2380  ProfilingService& profilingService = ProfilingService::Instance();
2381  profilingService.ResetExternalProfilingOptions(options, true);
2382 
2383  // Bring the profiling service to the "WaitingForAck" state
2384  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2385  profilingService.Update(); // Initialize the counter directory
2386  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2387  profilingService.Update(); // Create the profiling connection
2388 
2389  // Get the mock profiling connection
2390  MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
2391  BOOST_CHECK(mockProfilingConnection);
2392 
2393  // Remove the packets received so far
2394  mockProfilingConnection->Clear();
2395 
2396  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
2397  profilingService.Update(); // Start the command handler and the send thread
2398 
2399  // Wait for the Stream Metadata packet to be sent
2401  mockProfilingConnection, PacketType::StreamMetaData, streamMetadataPacketsize) >= 1);
2402 
2403  // Write a valid "Connection Acknowledged" packet into the mock profiling connection, to simulate a valid
2404  // reply from an external profiling service
2405 
2406  // Connection Acknowledged Packet header (word 0, word 1 is always zero):
2407  // 26:31 [6] packet_family: Control Packet Family, value 0b000000
2408  // 16:25 [10] packet_id: Packet identifier, value 0b0000000001
2409  // 8:15 [8] reserved: Reserved, value 0b00000000
2410  // 0:7 [8] reserved: Reserved, value 0b00000000
2411  uint32_t packetFamily = 0;
2412  uint32_t packetId = 1;
2413  uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2414 
2415  // Create the Connection Acknowledged Packet
2416  Packet connectionAcknowledgedPacket(header);
2417 
2418  // Write the packet to the mock profiling connection
2419  mockProfilingConnection->WritePacket(std::move(connectionAcknowledgedPacket));
2420 
2421  // Wait for the counter directory packet to ensure the ConnectionAcknowledgedCommandHandler has run.
2422  BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::CounterDirectory) == 1);
2423 
2424  // The Connection Acknowledged Command Handler should have updated the profiling state accordingly
2425  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2426 
2427  // Reset the profiling service to stop any running thread
2428  options.m_EnableProfiling = false;
2429  profilingService.ResetExternalProfilingOptions(options, true);
2430 }
std::string GetProcessName()
bool WritePacket(const unsigned char *buffer, uint32_t length) override
long WaitForPacketsSent(MockProfilingConnection *mockProfilingConnection, MockProfilingConnection::PacketType packetType, uint32_t length=0, uint32_t timeout=1000)
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
FileOnlyHelperService helper
ProfilingState GetCurrentState() const
ProfilingService & profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [33/50]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceGoodRequestCounterDirectoryPacket  )

Definition at line 2432 of file ProfilingTests.cpp.

References armnn::profiling::Active, BOOST_CHECK(), armnn::profiling::CounterDirectory, SwapProfilingConnectionFactoryHelper::ForceTransitionToState(), ProfilingService::GetCurrentState(), SwapProfilingConnectionFactoryHelper::GetMockProfilingConnection(), helper, ProfilingService::Instance(), armnn::profiling::NotConnected, options, profilingService, ProfilingService::ResetExternalProfilingOptions(), armnn::profiling::Uninitialised, ProfilingService::Update(), SwapProfilingConnectionFactoryHelper::WaitForPacketsSent(), armnn::profiling::WaitingForAck, and MockProfilingConnection::WritePacket().

2433 {
2434  // Swap the profiling connection factory in the profiling service instance with our mock one
2436 
2437  // Reset the profiling service to the uninitialized state
2438  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2439  options.m_EnableProfiling = true;
2440  ProfilingService& profilingService = ProfilingService::Instance();
2441  profilingService.ResetExternalProfilingOptions(options, true);
2442 
2443  // Bring the profiling service to the "Active" state
2444  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2445  profilingService.Update(); // Initialize the counter directory
2446  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2447  profilingService.Update(); // Create the profiling connection
2448  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
2449  profilingService.Update(); // Start the command handler and the send thread
2450 
2451  // Get the mock profiling connection
2452  MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
2453  BOOST_CHECK(mockProfilingConnection);
2454 
2455  // Force the profiling service to the "Active" state
2456  helper.ForceTransitionToState(ProfilingState::Active);
2457  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2458 
2459  // Write a valid "Request Counter Directory" packet into the mock profiling connection, to simulate a valid
2460  // reply from an external profiling service
2461 
2462  // Request Counter Directory packet header (word 0, word 1 is always zero):
2463  // 26:31 [6] packet_family: Control Packet Family, value 0b000000
2464  // 16:25 [10] packet_id: Packet identifier, value 0b0000000011
2465  // 8:15 [8] reserved: Reserved, value 0b00000000
2466  // 0:7 [8] reserved: Reserved, value 0b00000000
2467  uint32_t packetFamily = 0;
2468  uint32_t packetId = 3;
2469  uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2470 
2471  // Create the Request Counter Directory packet
2472  Packet requestCounterDirectoryPacket(header);
2473 
2474  // Write the packet to the mock profiling connection
2475  mockProfilingConnection->WritePacket(std::move(requestCounterDirectoryPacket));
2476 
2477  // Expecting one CounterDirectory Packet of length 656
2478  // and one TimelineMessageDirectory packet of length 427
2479  BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::CounterDirectory, 656) == 1);
2480  BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::TimelineMessageDirectory, 427) == 1);
2481 
2482  // The Request Counter Directory Command Handler should not have updated the profiling state
2483  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2484 
2485  // Reset the profiling service to stop any running thread
2486  options.m_EnableProfiling = false;
2487  profilingService.ResetExternalProfilingOptions(options, true);
2488 }
bool WritePacket(const unsigned char *buffer, uint32_t length) override
long WaitForPacketsSent(MockProfilingConnection *mockProfilingConnection, MockProfilingConnection::PacketType packetType, uint32_t length=0, uint32_t timeout=1000)
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
FileOnlyHelperService helper
ProfilingState GetCurrentState() const
ProfilingService & profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [34/50]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceBadPeriodicCounterSelectionPacketInvalidCounterUid  )

Definition at line 2490 of file ProfilingTests.cpp.

References armnn::profiling::Active, BOOST_CHECK(), MockProfilingConnection::Clear(), SwapProfilingConnectionFactoryHelper::ForceTransitionToState(), ProfilingService::GetCounterDirectory(), ICounterDirectory::GetCounters(), ProfilingService::GetCurrentState(), SwapProfilingConnectionFactoryHelper::GetMockProfilingConnection(), helper, ProfilingService::Instance(), armnn::profiling::NotConnected, options, profilingService, ProfilingService::ResetExternalProfilingOptions(), armnn::profiling::Uninitialised, ProfilingService::Update(), SwapProfilingConnectionFactoryHelper::WaitForPacketsSent(), armnn::profiling::WaitingForAck, MockProfilingConnection::WritePacket(), armnn::profiling::WriteUint16(), and armnn::profiling::WriteUint32().

2491 {
2492  // Swap the profiling connection factory in the profiling service instance with our mock one
2494 
2495  // Reset the profiling service to the uninitialized state
2496  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2497  options.m_EnableProfiling = true;
2498  ProfilingService& profilingService = ProfilingService::Instance();
2499  profilingService.ResetExternalProfilingOptions(options, true);
2500 
2501  // Bring the profiling service to the "Active" state
2502  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2503  profilingService.Update(); // Initialize the counter directory
2504  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2505  profilingService.Update(); // Create the profiling connection
2506  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
2507  profilingService.Update(); // Start the command handler and the send thread
2508 
2509  // Get the mock profiling connection
2510  MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
2511  BOOST_CHECK(mockProfilingConnection);
2512 
2513  // Force the profiling service to the "Active" state
2514  helper.ForceTransitionToState(ProfilingState::Active);
2515  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2516 
2517  // Remove the packets received so far
2518  mockProfilingConnection->Clear();
2519 
2520  // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an
2521  // external profiling service
2522 
2523  // Periodic Counter Selection packet header:
2524  // 26:31 [6] packet_family: Control Packet Family, value 0b000000
2525  // 16:25 [10] packet_id: Packet identifier, value 0b0000000100
2526  // 8:15 [8] reserved: Reserved, value 0b00000000
2527  // 0:7 [8] reserved: Reserved, value 0b00000000
2528  uint32_t packetFamily = 0;
2529  uint32_t packetId = 4;
2530  uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2531 
2532  uint32_t capturePeriod = 123456; // Some capture period (microseconds)
2533 
2534  // Get the first valid counter UID
2535  const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory();
2536  const Counters& counters = counterDirectory.GetCounters();
2537  BOOST_CHECK(counters.size() > 1);
2538  uint16_t counterUidA = counters.begin()->first; // First valid counter UID
2539  uint16_t counterUidB = 9999; // Second invalid counter UID
2540 
2541  uint32_t length = 8;
2542 
2543  auto data = std::make_unique<unsigned char[]>(length);
2544  WriteUint32(data.get(), 0, capturePeriod);
2545  WriteUint16(data.get(), 4, counterUidA);
2546  WriteUint16(data.get(), 6, counterUidB);
2547 
2548  // Create the Periodic Counter Selection packet
2549  Packet periodicCounterSelectionPacket(header, length, data); // Length > 0, this will start the Period Counter
2550  // Capture thread
2551 
2552  // Write the packet to the mock profiling connection
2553  mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket));
2554 
2555  // Expecting one Periodic Counter Selection packet of length 14
2556  // and at least one Periodic Counter Capture packet of length 22
2557  BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 14) == 1);
2558  BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 22) >= 1);
2559 
2560  // The Periodic Counter Selection Handler should not have updated the profiling state
2561  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2562 
2563  // Reset the profiling service to stop any running thread
2564  options.m_EnableProfiling = false;
2565  profilingService.ResetExternalProfilingOptions(options, true);
2566 }
void WriteUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint16_t value)
bool WritePacket(const unsigned char *buffer, uint32_t length) override
long WaitForPacketsSent(MockProfilingConnection *mockProfilingConnection, MockProfilingConnection::PacketType packetType, uint32_t length=0, uint32_t timeout=1000)
const ICounterDirectory & GetCounterDirectory() const
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
virtual const Counters & GetCounters() const =0
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
std::unordered_map< uint16_t, CounterPtr > Counters
FileOnlyHelperService helper
ProfilingState GetCurrentState() const
ProfilingService & profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
void WriteUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint32_t value)

◆ BOOST_AUTO_TEST_CASE() [35/50]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceGoodPeriodicCounterSelectionPacketNoCounters  )

Definition at line 2568 of file ProfilingTests.cpp.

References armnn::profiling::Active, BOOST_CHECK(), SwapProfilingConnectionFactoryHelper::ForceTransitionToState(), ProfilingService::GetCurrentState(), SwapProfilingConnectionFactoryHelper::GetMockProfilingConnection(), helper, ProfilingService::Instance(), armnn::profiling::NotConnected, options, profilingService, ProfilingService::ResetExternalProfilingOptions(), armnn::profiling::StreamMetaData, armnn::profiling::Uninitialised, ProfilingService::Update(), SwapProfilingConnectionFactoryHelper::WaitForPacketsSent(), armnn::profiling::WaitingForAck, and MockProfilingConnection::WritePacket().

2569 {
2570  // Swap the profiling connection factory in the profiling service instance with our mock one
2572 
2573  // Reset the profiling service to the uninitialized state
2574  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2575  options.m_EnableProfiling = true;
2576  ProfilingService& profilingService = ProfilingService::Instance();
2577  profilingService.ResetExternalProfilingOptions(options, true);
2578 
2579  // Bring the profiling service to the "Active" state
2580  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2581  profilingService.Update(); // Initialize the counter directory
2582  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2583  profilingService.Update(); // Create the profiling connection
2584  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
2585  profilingService.Update(); // Start the command handler and the send thread
2586 
2587  // Get the mock profiling connection
2588  MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
2589  BOOST_CHECK(mockProfilingConnection);
2590 
2591  // Wait for the Stream Metadata packet the be sent
2592  // (we are not testing the connection acknowledgement here so it will be ignored by this test)
2593  helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
2594 
2595  // Force the profiling service to the "Active" state
2596  helper.ForceTransitionToState(ProfilingState::Active);
2597  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2598 
2599  // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an
2600  // external profiling service
2601 
2602  // Periodic Counter Selection packet header:
2603  // 26:31 [6] packet_family: Control Packet Family, value 0b000000
2604  // 16:25 [10] packet_id: Packet identifier, value 0b0000000100
2605  // 8:15 [8] reserved: Reserved, value 0b00000000
2606  // 0:7 [8] reserved: Reserved, value 0b00000000
2607  uint32_t packetFamily = 0;
2608  uint32_t packetId = 4;
2609  uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2610 
2611  // Create the Periodic Counter Selection packet
2612  Packet periodicCounterSelectionPacket(header); // Length == 0, this will disable the collection of counters
2613 
2614  // Write the packet to the mock profiling connection
2615  mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket));
2616 
2617  // Wait for the Periodic Counter Selection packet of length 12 to be sent
2618  // The size of the expected Periodic Counter Selection (echos the sent one)
2619  BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 12) == 1);
2620 
2621  // The Periodic Counter Selection Handler should not have updated the profiling state
2622  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2623 
2624  // No Periodic Counter packets are expected
2625  BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 0, 0) == 0);
2626 
2627  // Reset the profiling service to stop any running thread
2628  options.m_EnableProfiling = false;
2629  profilingService.ResetExternalProfilingOptions(options, true);
2630 }
bool WritePacket(const unsigned char *buffer, uint32_t length) override
long WaitForPacketsSent(MockProfilingConnection *mockProfilingConnection, MockProfilingConnection::PacketType packetType, uint32_t length=0, uint32_t timeout=1000)
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
FileOnlyHelperService helper
ProfilingState GetCurrentState() const
ProfilingService & profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [36/50]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceGoodPeriodicCounterSelectionPacketSingleCounter  )

Definition at line 2632 of file ProfilingTests.cpp.

References armnn::profiling::Active, BOOST_CHECK(), SwapProfilingConnectionFactoryHelper::ForceTransitionToState(), ProfilingService::GetCounterDirectory(), ICounterDirectory::GetCounters(), ProfilingService::GetCurrentState(), SwapProfilingConnectionFactoryHelper::GetMockProfilingConnection(), helper, ProfilingService::Instance(), armnn::profiling::NotConnected, options, profilingService, ProfilingService::ResetExternalProfilingOptions(), armnn::profiling::StreamMetaData, armnn::profiling::Uninitialised, ProfilingService::Update(), SwapProfilingConnectionFactoryHelper::WaitForPacketsSent(), armnn::profiling::WaitingForAck, MockProfilingConnection::WritePacket(), armnn::profiling::WriteUint16(), and armnn::profiling::WriteUint32().

2633 {
2634  // Swap the profiling connection factory in the profiling service instance with our mock one
2636 
2637  // Reset the profiling service to the uninitialized state
2638  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2639  options.m_EnableProfiling = true;
2640  ProfilingService& profilingService = ProfilingService::Instance();
2641  profilingService.ResetExternalProfilingOptions(options, true);
2642 
2643  // Bring the profiling service to the "Active" state
2644  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2645  profilingService.Update(); // Initialize the counter directory
2646  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2647  profilingService.Update(); // Create the profiling connection
2648  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
2649  profilingService.Update(); // Start the command handler and the send thread
2650 
2651  // Get the mock profiling connection
2652  MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
2653  BOOST_CHECK(mockProfilingConnection);
2654 
2655  // Wait for the Stream Metadata packet to be sent
2656  // (we are not testing the connection acknowledgement here so it will be ignored by this test)
2657  helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
2658 
2659  // Force the profiling service to the "Active" state
2660  helper.ForceTransitionToState(ProfilingState::Active);
2661  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2662 
2663  // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an
2664  // external profiling service
2665 
2666  // Periodic Counter Selection packet header:
2667  // 26:31 [6] packet_family: Control Packet Family, value 0b000000
2668  // 16:25 [10] packet_id: Packet identifier, value 0b0000000100
2669  // 8:15 [8] reserved: Reserved, value 0b00000000
2670  // 0:7 [8] reserved: Reserved, value 0b00000000
2671  uint32_t packetFamily = 0;
2672  uint32_t packetId = 4;
2673  uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2674 
2675  uint32_t capturePeriod = 123456; // Some capture period (microseconds)
2676 
2677  // Get the first valid counter UID
2678  const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory();
2679  const Counters& counters = counterDirectory.GetCounters();
2680  BOOST_CHECK(!counters.empty());
2681  uint16_t counterUid = counters.begin()->first; // Valid counter UID
2682 
2683  uint32_t length = 6;
2684 
2685  auto data = std::make_unique<unsigned char[]>(length);
2686  WriteUint32(data.get(), 0, capturePeriod);
2687  WriteUint16(data.get(), 4, counterUid);
2688 
2689  // Create the Periodic Counter Selection packet
2690  Packet periodicCounterSelectionPacket(header, length, data); // Length > 0, this will start the Period Counter
2691  // Capture thread
2692 
2693  // Write the packet to the mock profiling connection
2694  mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket));
2695 
2696  // Expecting one Periodic Counter Selection packet of length 14
2697  // and at least one Periodic Counter Capture packet of length 22
2698  BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 14) == 1);
2699  BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 22) >= 1);
2700 
2701  // The Periodic Counter Selection Handler should not have updated the profiling state
2702  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2703 
2704  // Reset the profiling service to stop any running thread
2705  options.m_EnableProfiling = false;
2706  profilingService.ResetExternalProfilingOptions(options, true);
2707 }
void WriteUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint16_t value)
bool WritePacket(const unsigned char *buffer, uint32_t length) override
long WaitForPacketsSent(MockProfilingConnection *mockProfilingConnection, MockProfilingConnection::PacketType packetType, uint32_t length=0, uint32_t timeout=1000)
const ICounterDirectory & GetCounterDirectory() const
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
virtual const Counters & GetCounters() const =0
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
std::unordered_map< uint16_t, CounterPtr > Counters
FileOnlyHelperService helper
ProfilingState GetCurrentState() const
ProfilingService & profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
void WriteUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint32_t value)

◆ BOOST_AUTO_TEST_CASE() [37/50]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceGoodPeriodicCounterSelectionPacketMultipleCounters  )

Definition at line 2709 of file ProfilingTests.cpp.

References armnn::profiling::Active, BOOST_CHECK(), SwapProfilingConnectionFactoryHelper::ForceTransitionToState(), ProfilingService::GetCounterDirectory(), ICounterDirectory::GetCounters(), ProfilingService::GetCurrentState(), SwapProfilingConnectionFactoryHelper::GetMockProfilingConnection(), helper, ProfilingService::Instance(), armnn::profiling::NotConnected, options, profilingService, ProfilingService::ResetExternalProfilingOptions(), armnn::profiling::StreamMetaData, armnn::profiling::Uninitialised, ProfilingService::Update(), SwapProfilingConnectionFactoryHelper::WaitForPacketsSent(), armnn::profiling::WaitingForAck, MockProfilingConnection::WritePacket(), armnn::profiling::WriteUint16(), and armnn::profiling::WriteUint32().

2710 {
2711  // Swap the profiling connection factory in the profiling service instance with our mock one
2713  // Reset the profiling service to the uninitialized state
2714  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2715  options.m_EnableProfiling = true;
2716  ProfilingService& profilingService = ProfilingService::Instance();
2717  profilingService.ResetExternalProfilingOptions(options, true);
2718 
2719  // Bring the profiling service to the "Active" state
2720  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2721  profilingService.Update(); // Initialize the counter directory
2722  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2723  profilingService.Update(); // Create the profiling connection
2724  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
2725  profilingService.Update(); // Start the command handler and the send thread
2726 
2727  // Get the mock profiling connection
2728  MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
2729  BOOST_CHECK(mockProfilingConnection);
2730 
2731  // Wait for the Stream Metadata packet the be sent
2732  // (we are not testing the connection acknowledgement here so it will be ignored by this test)
2733  helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
2734 
2735  // Force the profiling service to the "Active" state
2736  helper.ForceTransitionToState(ProfilingState::Active);
2737  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2738 
2739  // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an
2740  // external profiling service
2741 
2742  // Periodic Counter Selection packet header:
2743  // 26:31 [6] packet_family: Control Packet Family, value 0b000000
2744  // 16:25 [10] packet_id: Packet identifier, value 0b0000000100
2745  // 8:15 [8] reserved: Reserved, value 0b00000000
2746  // 0:7 [8] reserved: Reserved, value 0b00000000
2747  uint32_t packetFamily = 0;
2748  uint32_t packetId = 4;
2749  uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2750 
2751  uint32_t capturePeriod = 123456; // Some capture period (microseconds)
2752 
2753  // Get the first valid counter UID
2754  const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory();
2755  const Counters& counters = counterDirectory.GetCounters();
2756  BOOST_CHECK(counters.size() > 1);
2757  uint16_t counterUidA = counters.begin()->first; // First valid counter UID
2758  uint16_t counterUidB = (counters.begin()++)->first; // Second valid counter UID
2759 
2760  uint32_t length = 8;
2761 
2762  auto data = std::make_unique<unsigned char[]>(length);
2763  WriteUint32(data.get(), 0, capturePeriod);
2764  WriteUint16(data.get(), 4, counterUidA);
2765  WriteUint16(data.get(), 6, counterUidB);
2766 
2767  // Create the Periodic Counter Selection packet
2768  Packet periodicCounterSelectionPacket(header, length, data); // Length > 0, this will start the Period Counter
2769  // Capture thread
2770 
2771  // Write the packet to the mock profiling connection
2772  mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket));
2773 
2774  // Expecting one PeriodicCounterSelection Packet with a length of 16
2775  // And at least one PeriodicCounterCapture Packet with a length of 28
2776  BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 16) == 1);
2777  BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 28) >= 1);
2778 
2779  // The Periodic Counter Selection Handler should not have updated the profiling state
2780  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2781 
2782  // Reset the profiling service to stop any running thread
2783  options.m_EnableProfiling = false;
2784  profilingService.ResetExternalProfilingOptions(options, true);
2785 }
void WriteUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint16_t value)
bool WritePacket(const unsigned char *buffer, uint32_t length) override
long WaitForPacketsSent(MockProfilingConnection *mockProfilingConnection, MockProfilingConnection::PacketType packetType, uint32_t length=0, uint32_t timeout=1000)
const ICounterDirectory & GetCounterDirectory() const
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
virtual const Counters & GetCounters() const =0
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
std::unordered_map< uint16_t, CounterPtr > Counters
FileOnlyHelperService helper
ProfilingState GetCurrentState() const
ProfilingService & profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
void WriteUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint32_t value)

◆ BOOST_AUTO_TEST_CASE() [38/50]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceDisconnect  )

Definition at line 2787 of file ProfilingTests.cpp.

References armnn::profiling::Active, BOOST_CHECK(), ProfilingService::Disconnect(), SwapProfilingConnectionFactoryHelper::ForceTransitionToState(), ProfilingService::GetCurrentState(), SwapProfilingConnectionFactoryHelper::GetMockProfilingConnection(), helper, ProfilingService::Instance(), MockProfilingConnection::IsOpen(), armnn::profiling::NotConnected, options, profilingService, ProfilingService::ResetExternalProfilingOptions(), armnn::profiling::StreamMetaData, armnn::profiling::Uninitialised, ProfilingService::Update(), SwapProfilingConnectionFactoryHelper::WaitForPacketsSent(), and armnn::profiling::WaitingForAck.

2788 {
2789  // Swap the profiling connection factory in the profiling service instance with our mock one
2791  // Reset the profiling service to the uninitialized state
2792  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2793  options.m_EnableProfiling = true;
2794  ProfilingService& profilingService = ProfilingService::Instance();
2795  profilingService.ResetExternalProfilingOptions(options, true);
2796 
2797  // Try to disconnect the profiling service while in the "Uninitialised" state
2798  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2799  profilingService.Disconnect();
2800  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); // The state should not change
2801 
2802  // Try to disconnect the profiling service while in the "NotConnected" state
2803  profilingService.Update(); // Initialize the counter directory
2804  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2805  profilingService.Disconnect();
2806  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); // The state should not change
2807 
2808  // Try to disconnect the profiling service while in the "WaitingForAck" state
2809  profilingService.Update(); // Create the profiling connection
2810  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
2811  profilingService.Disconnect();
2812  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); // The state should not change
2813 
2814  // Try to disconnect the profiling service while in the "Active" state
2815  profilingService.Update(); // Start the command handler and the send thread
2816 
2817  // Get the mock profiling connection
2818  MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
2819  BOOST_CHECK(mockProfilingConnection);
2820 
2821  // Wait for the Stream Metadata packet the be sent
2822  // (we are not testing the connection acknowledgement here so it will be ignored by this test)
2823  helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
2824 
2825  // Force the profiling service to the "Active" state
2826  helper.ForceTransitionToState(ProfilingState::Active);
2827  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2828 
2829  // Check that the profiling connection is open
2830  BOOST_CHECK(mockProfilingConnection->IsOpen());
2831 
2832  profilingService.Disconnect();
2833  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); // The state should have changed
2834 
2835  // Check that the profiling connection has been reset
2836  mockProfilingConnection = helper.GetMockProfilingConnection();
2837  BOOST_CHECK(mockProfilingConnection == nullptr);
2838 
2839  // Reset the profiling service to stop any running thread
2840  options.m_EnableProfiling = false;
2841  profilingService.ResetExternalProfilingOptions(options, true);
2842 }
long WaitForPacketsSent(MockProfilingConnection *mockProfilingConnection, MockProfilingConnection::PacketType packetType, uint32_t length=0, uint32_t timeout=1000)
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
FileOnlyHelperService helper
ProfilingState GetCurrentState() const
ProfilingService & profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [39/50]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceGoodPerJobCounterSelectionPacket  )

Definition at line 2844 of file ProfilingTests.cpp.

References armnn::profiling::Active, BOOST_CHECK(), SwapProfilingConnectionFactoryHelper::ForceTransitionToState(), ProfilingService::GetCurrentState(), SwapProfilingConnectionFactoryHelper::GetMockProfilingConnection(), MockProfilingConnection::GetWrittenDataSize(), helper, ProfilingService::Instance(), armnn::profiling::NotConnected, options, profilingService, ProfilingService::ResetExternalProfilingOptions(), armnn::profiling::StreamMetaData, armnn::profiling::Uninitialised, ProfilingService::Update(), SwapProfilingConnectionFactoryHelper::WaitForPacketsSent(), armnn::profiling::WaitingForAck, and MockProfilingConnection::WritePacket().

2845 {
2846  // Swap the profiling connection factory in the profiling service instance with our mock one
2848  // Reset the profiling service to the uninitialized state
2849  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2850  options.m_EnableProfiling = true;
2851  ProfilingService& profilingService = ProfilingService::Instance();
2852  profilingService.ResetExternalProfilingOptions(options, true);
2853 
2854  // Bring the profiling service to the "Active" state
2855  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2856  profilingService.Update(); // Initialize the counter directory
2857  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2858  profilingService.Update(); // Create the profiling connection
2859  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
2860  profilingService.Update(); // Start the command handler and the send thread
2861 
2862  // Get the mock profiling connection
2863  MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
2864  BOOST_CHECK(mockProfilingConnection);
2865 
2866  // Wait for the Stream Metadata packet the be sent
2867  // (we are not testing the connection acknowledgement here so it will be ignored by this test)
2868  helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
2869 
2870  // Force the profiling service to the "Active" state
2871  helper.ForceTransitionToState(ProfilingState::Active);
2872  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2873 
2874  // Write a "Per-Job Counter Selection" packet into the mock profiling connection, to simulate an input from an
2875  // external profiling service
2876 
2877  // Per-Job Counter Selection packet header:
2878  // 26:31 [6] packet_family: Control Packet Family, value 0b000000
2879  // 16:25 [10] packet_id: Packet identifier, value 0b0000000100
2880  // 8:15 [8] reserved: Reserved, value 0b00000000
2881  // 0:7 [8] reserved: Reserved, value 0b00000000
2882  uint32_t packetFamily = 0;
2883  uint32_t packetId = 5;
2884  uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2885 
2886  // Create the Per-Job Counter Selection packet
2887  Packet periodicCounterSelectionPacket(header); // Length == 0, this will disable the collection of counters
2888 
2889  // Write the packet to the mock profiling connection
2890  mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket));
2891 
2892  // Wait for a bit (must at least be the delay value of the mock profiling connection) to make sure that
2893  // the Per-Job Counter Selection packet gets processed by the profiling service
2894  std::this_thread::sleep_for(std::chrono::milliseconds(5));
2895 
2896  // The Per-Job Counter Selection Command Handler should not have updated the profiling state
2897  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2898 
2899  // The Per-Job Counter Selection packets are dropped silently, so there should be no reply coming
2900  // from the profiling service
2901  const auto StreamMetaDataSize = static_cast<unsigned long>(
2902  helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData, 0, 0));
2903  BOOST_CHECK(StreamMetaDataSize == mockProfilingConnection->GetWrittenDataSize());
2904 
2905  // Reset the profiling service to stop any running thread
2906  options.m_EnableProfiling = false;
2907  profilingService.ResetExternalProfilingOptions(options, true);
2908 }
bool WritePacket(const unsigned char *buffer, uint32_t length) override
long WaitForPacketsSent(MockProfilingConnection *mockProfilingConnection, MockProfilingConnection::PacketType packetType, uint32_t length=0, uint32_t timeout=1000)
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
FileOnlyHelperService helper
ProfilingState GetCurrentState() const
ProfilingService & profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [40/50]

BOOST_AUTO_TEST_CASE ( CheckConfigureProfilingServiceOn  )

Definition at line 2910 of file ProfilingTests.cpp.

References BOOST_CHECK(), ProfilingService::ConfigureProfilingService(), ProfilingService::GetCurrentState(), ProfilingService::Instance(), armnn::profiling::NotConnected, options, profilingService, ProfilingService::ResetExternalProfilingOptions(), and armnn::profiling::Uninitialised.

2911 {
2912  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2913  options.m_EnableProfiling = true;
2914  ProfilingService& profilingService = ProfilingService::Instance();
2915  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2916  profilingService.ConfigureProfilingService(options);
2917  // should get as far as NOT_CONNECTED
2918  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2919  // Reset the profiling service to stop any running thread
2920  options.m_EnableProfiling = false;
2921  profilingService.ResetExternalProfilingOptions(options, true);
2922 }
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
ProfilingState GetCurrentState() const
ProfilingService & profilingService
ProfilingState ConfigureProfilingService(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [41/50]

BOOST_AUTO_TEST_CASE ( CheckConfigureProfilingServiceOff  )

Definition at line 2924 of file ProfilingTests.cpp.

References BOOST_CHECK(), ProfilingService::ConfigureProfilingService(), ProfilingService::GetCurrentState(), ProfilingService::Instance(), options, profilingService, ProfilingService::ResetExternalProfilingOptions(), and armnn::profiling::Uninitialised.

2925 {
2926  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2927  ProfilingService& profilingService = ProfilingService::Instance();
2928  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2929  profilingService.ConfigureProfilingService(options);
2930  // should not move from Uninitialised
2931  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2932  // Reset the profiling service to stop any running thread
2933  options.m_EnableProfiling = false;
2934  profilingService.ResetExternalProfilingOptions(options, true);
2935 }
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
ProfilingState GetCurrentState() const
ProfilingService & profilingService
ProfilingState ConfigureProfilingService(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [42/50]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceEnabled  )

Definition at line 2937 of file ProfilingTests.cpp.

References BOOST_CHECK(), ProfilingService::GetCurrentState(), ProfilingService::Instance(), armnn::profiling::NotConnected, options, profilingService, ProfilingService::ResetExternalProfilingOptions(), armnn::profiling::Uninitialised, ProfilingService::Update(), and armnn::Warning.

2938 {
2939  // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
2941  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2942  options.m_EnableProfiling = true;
2943  ProfilingService& profilingService = ProfilingService::Instance();
2944  profilingService.ResetExternalProfilingOptions(options, true);
2945  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2946  profilingService.Update();
2947  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2948 
2949  // Redirect the output to a local stream so that we can parse the warning message
2950  std::stringstream ss;
2951  StreamRedirector streamRedirector(std::cout, ss.rdbuf());
2952  profilingService.Update();
2953 
2954  // Reset the profiling service to stop any running thread
2955  options.m_EnableProfiling = false;
2956  profilingService.ResetExternalProfilingOptions(options, true);
2957 
2958  streamRedirector.CancelRedirect();
2959 
2960  // Check that the expected error has occurred and logged to the standard output
2961  if (!boost::contains(ss.str(), "Cannot connect to stream socket: Connection refused"))
2962  {
2963  std::cout << ss.str();
2964  BOOST_FAIL("Expected string not found.");
2965  }
2966 }
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
ProfilingState GetCurrentState() const
ProfilingService & profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [43/50]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceEnabledRuntime  )

Definition at line 2968 of file ProfilingTests.cpp.

References BOOST_CHECK(), ProfilingService::GetCurrentState(), ProfilingService::Instance(), armnn::profiling::NotConnected, options, profilingService, ProfilingService::ResetExternalProfilingOptions(), armnn::profiling::Uninitialised, ProfilingService::Update(), and armnn::Warning.

2969 {
2970  // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
2972  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2973  ProfilingService& profilingService = ProfilingService::Instance();
2974  profilingService.ResetExternalProfilingOptions(options, true);
2975  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2976  profilingService.Update();
2977  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2978  options.m_EnableProfiling = true;
2979  profilingService.ResetExternalProfilingOptions(options);
2980  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2981  profilingService.Update();
2982  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2983 
2984  // Redirect the output to a local stream so that we can parse the warning message
2985  std::stringstream ss;
2986  StreamRedirector streamRedirector(std::cout, ss.rdbuf());
2987  profilingService.Update();
2988 
2989  // Reset the profiling service to stop any running thread
2990  options.m_EnableProfiling = false;
2991  profilingService.ResetExternalProfilingOptions(options, true);
2992 
2993  streamRedirector.CancelRedirect();
2994 
2995  // Check that the expected error has occurred and logged to the standard output
2996  if (!boost::contains(ss.str(), "Cannot connect to stream socket: Connection refused"))
2997  {
2998  std::cout << ss.str();
2999  BOOST_FAIL("Expected string not found.");
3000  }
3001 }
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
ProfilingState GetCurrentState() const
ProfilingService & profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [44/50]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceBadConnectionAcknowledgedPacket  )

Definition at line 3003 of file ProfilingTests.cpp.

References BOOST_CHECK(), ProfilingService::GetCurrentState(), SwapProfilingConnectionFactoryHelper::GetMockProfilingConnection(), helper, ProfilingService::Instance(), armnn::profiling::NotConnected, options, profilingService, ProfilingService::ResetExternalProfilingOptions(), armnn::profiling::Uninitialised, ProfilingService::Update(), armnn::profiling::WaitingForAck, armnn::Warning, and MockProfilingConnection::WritePacket().

3004 {
3005  // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
3007  // Swap the profiling connection factory in the profiling service instance with our mock one
3009 
3010  // Redirect the standard output to a local stream so that we can parse the warning message
3011  std::stringstream ss;
3012  StreamRedirector streamRedirector(std::cout, ss.rdbuf());
3013 
3014  // Reset the profiling service to the uninitialized state
3015  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3016  options.m_EnableProfiling = true;
3017  ProfilingService& profilingService = ProfilingService::Instance();
3018  profilingService.ResetExternalProfilingOptions(options, true);
3019 
3020  // Bring the profiling service to the "WaitingForAck" state
3021  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3022  profilingService.Update(); // Initialize the counter directory
3023  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
3024  profilingService.Update(); // Create the profiling connection
3025 
3026  // Get the mock profiling connection
3027  MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
3028  BOOST_CHECK(mockProfilingConnection);
3029 
3030  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
3031 
3032  // Connection Acknowledged Packet header (word 0, word 1 is always zero):
3033  // 26:31 [6] packet_family: Control Packet Family, value 0b000000
3034  // 16:25 [10] packet_id: Packet identifier, value 0b0000000001
3035  // 8:15 [8] reserved: Reserved, value 0b00000000
3036  // 0:7 [8] reserved: Reserved, value 0b00000000
3037  uint32_t packetFamily = 0;
3038  uint32_t packetId = 37; // Wrong packet id!!!
3039  uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3040 
3041  // Create the Connection Acknowledged Packet
3042  Packet connectionAcknowledgedPacket(header);
3043  // Write an invalid "Connection Acknowledged" packet into the mock profiling connection, to simulate an invalid
3044  // reply from an external profiling service
3045  mockProfilingConnection->WritePacket(std::move(connectionAcknowledgedPacket));
3046 
3047  // Start the command thread
3048  profilingService.Update();
3049 
3050  // Wait for the command thread to join
3051  options.m_EnableProfiling = false;
3052  profilingService.ResetExternalProfilingOptions(options, true);
3053 
3054  streamRedirector.CancelRedirect();
3055 
3056  // Check that the expected error has occurred and logged to the standard output
3057  if (!boost::contains(ss.str(), "Functor with requested PacketId=37 and Version=4194304 does not exist"))
3058  {
3059  std::cout << ss.str();
3060  BOOST_FAIL("Expected string not found.");
3061  }
3062 }
bool WritePacket(const unsigned char *buffer, uint32_t length) override
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
FileOnlyHelperService helper
ProfilingState GetCurrentState() const
ProfilingService & profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [45/50]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceBadRequestCounterDirectoryPacket  )

Definition at line 3064 of file ProfilingTests.cpp.

References BOOST_CHECK(), SwapProfilingConnectionFactoryHelper::ForceTransitionToState(), ProfilingService::GetCurrentState(), SwapProfilingConnectionFactoryHelper::GetMockProfilingConnection(), helper, ProfilingService::Instance(), armnn::profiling::NotConnected, options, profilingService, ProfilingService::ResetExternalProfilingOptions(), armnn::profiling::Uninitialised, ProfilingService::Update(), armnn::profiling::WaitingForAck, and armnn::Warning.

3065 {
3066  // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
3068  // Swap the profiling connection factory in the profiling service instance with our mock one
3070 
3071  // Redirect the standard output to a local stream so that we can parse the warning message
3072  std::stringstream ss;
3073  StreamRedirector streamRedirector(std::cout, ss.rdbuf());
3074 
3075  // Reset the profiling service to the uninitialized state
3076  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3077  options.m_EnableProfiling = true;
3078  ProfilingService& profilingService = ProfilingService::Instance();
3079  profilingService.ResetExternalProfilingOptions(options, true);
3080 
3081  // Bring the profiling service to the "Active" state
3082  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3083  helper.ForceTransitionToState(ProfilingState::NotConnected);
3084  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
3085  profilingService.Update(); // Create the profiling connection
3086  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
3087 
3088  // Get the mock profiling connection
3089  MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
3090  BOOST_CHECK(mockProfilingConnection);
3091 
3092  // Write a valid "Request Counter Directory" packet into the mock profiling connection, to simulate a valid
3093  // reply from an external profiling service
3094 
3095  // Request Counter Directory packet header (word 0, word 1 is always zero):
3096  // 26:31 [6] packet_family: Control Packet Family, value 0b000000
3097  // 16:25 [10] packet_id: Packet identifier, value 0b0000000011
3098  // 8:15 [8] reserved: Reserved, value 0b00000000
3099  // 0:7 [8] reserved: Reserved, value 0b00000000
3100  uint32_t packetFamily = 0;
3101  uint32_t packetId = 123; // Wrong packet id!!!
3102  uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3103 
3104  // Create the Request Counter Directory packet
3105  Packet requestCounterDirectoryPacket(header);
3106 
3107  // Write the packet to the mock profiling connection
3108  mockProfilingConnection->WritePacket(std::move(requestCounterDirectoryPacket));
3109 
3110  // Start the command handler and the send thread
3111  profilingService.Update();
3112 
3113  // Reset the profiling service to stop and join any running thread
3114  options.m_EnableProfiling = false;
3115  profilingService.ResetExternalProfilingOptions(options, true);
3116 
3117  streamRedirector.CancelRedirect();
3118 
3119  // Check that the expected error has occurred and logged to the standard output
3120  if (!boost::contains(ss.str(), "Functor with requested PacketId=123 and Version=4194304 does not exist"))
3121  {
3122  std::cout << ss.str();
3123  BOOST_FAIL("Expected string not found.");
3124  }
3125 }
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
FileOnlyHelperService helper
ProfilingState GetCurrentState() const
ProfilingService & profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [46/50]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceBadPeriodicCounterSelectionPacket  )

Definition at line 3127 of file ProfilingTests.cpp.

References BOOST_CHECK(), ProfilingService::GetCurrentState(), SwapProfilingConnectionFactoryHelper::GetMockProfilingConnection(), helper, ProfilingService::Instance(), armnn::profiling::NotConnected, options, profilingService, ProfilingService::ResetExternalProfilingOptions(), armnn::profiling::Uninitialised, ProfilingService::Update(), armnn::profiling::WaitingForAck, armnn::Warning, and MockProfilingConnection::WritePacket().

3128 {
3129  // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
3131  // Swap the profiling connection factory in the profiling service instance with our mock one
3133 
3134  // Redirect the standard output to a local stream so that we can parse the warning message
3135  std::stringstream ss;
3136  StreamRedirector streamRedirector(std::cout, ss.rdbuf());
3137 
3138  // Reset the profiling service to the uninitialized state
3139  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3140  options.m_EnableProfiling = true;
3141  ProfilingService& profilingService = ProfilingService::Instance();
3142  profilingService.ResetExternalProfilingOptions(options, true);
3143 
3144  // Bring the profiling service to the "Active" state
3145  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3146  profilingService.Update(); // Initialize the counter directory
3147  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
3148  profilingService.Update(); // Create the profiling connection
3149  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
3150  profilingService.Update(); // Start the command handler and the send thread
3151 
3152  // Get the mock profiling connection
3153  MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
3154  BOOST_CHECK(mockProfilingConnection);
3155 
3156  // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an
3157  // external profiling service
3158 
3159  // Periodic Counter Selection packet header:
3160  // 26:31 [6] packet_family: Control Packet Family, value 0b000000
3161  // 16:25 [10] packet_id: Packet identifier, value 0b0000000100
3162  // 8:15 [8] reserved: Reserved, value 0b00000000
3163  // 0:7 [8] reserved: Reserved, value 0b00000000
3164  uint32_t packetFamily = 0;
3165  uint32_t packetId = 999; // Wrong packet id!!!
3166  uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3167 
3168  // Create the Periodic Counter Selection packet
3169  Packet periodicCounterSelectionPacket(header); // Length == 0, this will disable the collection of counters
3170 
3171  // Write the packet to the mock profiling connection
3172  mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket));
3173  profilingService.Update();
3174 
3175  // Reset the profiling service to stop any running thread
3176  options.m_EnableProfiling = false;
3177  profilingService.ResetExternalProfilingOptions(options, true);
3178 
3179  // Check that the expected error has occurred and logged to the standard output
3180  streamRedirector.CancelRedirect();
3181 
3182  // Check that the expected error has occurred and logged to the standard output
3183  if (!boost::contains(ss.str(), "Functor with requested PacketId=999 and Version=4194304 does not exist"))
3184  {
3185  std::cout << ss.str();
3186  BOOST_FAIL("Expected string not found.");
3187  }
3188 }
bool WritePacket(const unsigned char *buffer, uint32_t length) override
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
FileOnlyHelperService helper
ProfilingState GetCurrentState() const
ProfilingService & profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [47/50]

BOOST_AUTO_TEST_CASE ( CheckCounterIdMap  )

Definition at line 3190 of file ProfilingTests.cpp.

References BOOST_CHECK(), armnn::CpuAcc, armnn::CpuRef, CounterIdMap::GetBackendId(), CounterIdMap::GetGlobalId(), and CounterIdMap::RegisterMapping().

3191 {
3192  CounterIdMap counterIdMap;
3193  BOOST_CHECK_THROW(counterIdMap.GetBackendId(0), armnn::Exception);
3194  BOOST_CHECK_THROW(counterIdMap.GetGlobalId(0, armnn::profiling::BACKEND_ID), armnn::Exception);
3195 
3196  uint16_t globalCounterIds = 0;
3197 
3200 
3201  std::vector<uint16_t> cpuRefCounters = {0, 1, 2, 3};
3202  std::vector<uint16_t> cpuAccCounters = {0, 1};
3203 
3204  for (uint16_t backendCounterId : cpuRefCounters)
3205  {
3206  counterIdMap.RegisterMapping(globalCounterIds, backendCounterId, cpuRefId);
3207  ++globalCounterIds;
3208  }
3209  for (uint16_t backendCounterId : cpuAccCounters)
3210  {
3211  counterIdMap.RegisterMapping(globalCounterIds, backendCounterId, cpuAccId);
3212  ++globalCounterIds;
3213  }
3214 
3215  BOOST_CHECK(counterIdMap.GetBackendId(0) == (std::pair<uint16_t, armnn::BackendId>(0, cpuRefId)));
3216  BOOST_CHECK(counterIdMap.GetBackendId(1) == (std::pair<uint16_t, armnn::BackendId>(1, cpuRefId)));
3217  BOOST_CHECK(counterIdMap.GetBackendId(2) == (std::pair<uint16_t, armnn::BackendId>(2, cpuRefId)));
3218  BOOST_CHECK(counterIdMap.GetBackendId(3) == (std::pair<uint16_t, armnn::BackendId>(3, cpuRefId)));
3219  BOOST_CHECK(counterIdMap.GetBackendId(4) == (std::pair<uint16_t, armnn::BackendId>(0, cpuAccId)));
3220  BOOST_CHECK(counterIdMap.GetBackendId(5) == (std::pair<uint16_t, armnn::BackendId>(1, cpuAccId)));
3221 
3222  BOOST_CHECK(counterIdMap.GetGlobalId(0, cpuRefId) == 0);
3223  BOOST_CHECK(counterIdMap.GetGlobalId(1, cpuRefId) == 1);
3224  BOOST_CHECK(counterIdMap.GetGlobalId(2, cpuRefId) == 2);
3225  BOOST_CHECK(counterIdMap.GetGlobalId(3, cpuRefId) == 3);
3226  BOOST_CHECK(counterIdMap.GetGlobalId(0, cpuAccId) == 4);
3227  BOOST_CHECK(counterIdMap.GetGlobalId(1, cpuAccId) == 5);
3228 }
void RegisterMapping(uint16_t globalCounterId, uint16_t backendCounterId, const armnn::BackendId &backendId) override
uint16_t GetGlobalId(uint16_t backendCounterId, const armnn::BackendId &backendId) const override
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
CPU Execution: Reference C++ kernels.
CPU Execution: NEON: ArmCompute.
const std::pair< uint16_t, armnn::BackendId > & GetBackendId(uint16_t globalCounterId) const override

◆ BOOST_AUTO_TEST_CASE() [48/50]

BOOST_AUTO_TEST_CASE ( CheckRegisterBackendCounters  )

Definition at line 3230 of file ProfilingTests.cpp.

References BOOST_CHECK(), armnn::CpuRef, ICounterMappings::GetBackendId(), ICounterDirectory::GetCategories(), ICounterDirectory::GetCategory(), ProfilingService::GetCounterDirectory(), ProfilingService::GetCounterMappings(), ICounterDirectory::GetCounterSet(), ICounterDirectory::GetCounterSets(), ICounterDirectory::GetDevice(), ICounterDirectory::GetDevices(), ICounterMappings::GetGlobalId(), ProfilingService::Instance(), options, profilingService, RegisterBackendCounters::RegisterCategory(), RegisterBackendCounters::RegisterCounter(), RegisterBackendCounters::RegisterCounterSet(), RegisterBackendCounters::RegisterDevice(), and ProfilingService::ResetExternalProfilingOptions().

3231 {
3232  uint16_t globalCounterIds = armnn::profiling::INFERENCES_RUN;
3234 
3235  RegisterBackendCounters registerBackendCounters(globalCounterIds, cpuRefId);
3236 
3237  // Reset the profiling service to the uninitialized state
3238  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3239  options.m_EnableProfiling = true;
3240  ProfilingService& profilingService = ProfilingService::Instance();
3241  profilingService.ResetExternalProfilingOptions(options, true);
3242 
3243  BOOST_CHECK(profilingService.GetCounterDirectory().GetCategories().empty());
3244  registerBackendCounters.RegisterCategory("categoryOne");
3245  auto categoryOnePtr = profilingService.GetCounterDirectory().GetCategory("categoryOne");
3246  BOOST_CHECK(categoryOnePtr);
3247 
3248  BOOST_CHECK(profilingService.GetCounterDirectory().GetDevices().empty());
3249  globalCounterIds = registerBackendCounters.RegisterDevice("deviceOne");
3250  auto deviceOnePtr = profilingService.GetCounterDirectory().GetDevice(globalCounterIds);
3251  BOOST_CHECK(deviceOnePtr);
3252  BOOST_CHECK(deviceOnePtr->m_Name == "deviceOne");
3253 
3254  BOOST_CHECK(profilingService.GetCounterDirectory().GetCounterSets().empty());
3255  globalCounterIds = registerBackendCounters.RegisterCounterSet("counterSetOne");
3256  auto counterSetOnePtr = profilingService.GetCounterDirectory().GetCounterSet(globalCounterIds);
3257  BOOST_CHECK(counterSetOnePtr);
3258  BOOST_CHECK(counterSetOnePtr->m_Name == "counterSetOne");
3259 
3260  uint16_t newGlobalCounterId = registerBackendCounters.RegisterCounter(0,
3261  "categoryOne",
3262  0,
3263  0,
3264  1.f,
3265  "CounterOne",
3266  "first test counter");
3267  BOOST_CHECK(newGlobalCounterId = armnn::profiling::INFERENCES_RUN + 1);
3268  uint16_t mappedGlobalId = profilingService.GetCounterMappings().GetGlobalId(0, cpuRefId);
3269  BOOST_CHECK(mappedGlobalId == newGlobalCounterId);
3270  auto backendMapping = profilingService.GetCounterMappings().GetBackendId(newGlobalCounterId);
3271  BOOST_CHECK(backendMapping.first == 0);
3272  BOOST_CHECK(backendMapping.second == cpuRefId);
3273 
3274  // Reset the profiling service to stop any running thread
3275  options.m_EnableProfiling = false;
3276  profilingService.ResetExternalProfilingOptions(options, true);
3277 }
virtual const Devices & GetDevices() const =0
const ICounterMappings & GetCounterMappings() const override
virtual const Categories & GetCategories() const =0
virtual const CounterSets & GetCounterSets() const =0
virtual const CounterSet * GetCounterSet(uint16_t uid) const =0
virtual const Device * GetDevice(uint16_t uid) const =0
virtual uint16_t GetGlobalId(uint16_t backendCounterId, const armnn::BackendId &backendId) const =0
const ICounterDirectory & GetCounterDirectory() const
virtual const Category * GetCategory(const std::string &name) const =0
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
virtual const std::pair< uint16_t, armnn::BackendId > & GetBackendId(uint16_t globalCounterId) const =0
CPU Execution: Reference C++ kernels.
ProfilingService & profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [49/50]

BOOST_AUTO_TEST_CASE ( CheckCounterStatusQuery  )

Definition at line 3279 of file ProfilingTests.cpp.

References BOOST_CHECK(), armnn::CpuAcc, armnn::CpuRef, BackendProfiling::GetActiveCounters(), ICounterMappings::GetBackendId(), ICounterDirectory::GetCategories(), ICounterDirectory::GetCategory(), ProfilingService::GetCounterDirectory(), ProfilingService::GetCounterMappings(), BackendProfiling::GetCounterStatus(), ICounterMappings::GetGlobalId(), ProfilingService::Instance(), CounterStatus::m_BackendCounterId, CounterStatus::m_Enabled, IRuntime::CreationOptions::ExternalProfilingOptions::m_EnableProfiling, CounterStatus::m_GlobalCounterId, IRuntime::CreationOptions::m_ProfilingOptions, CounterStatus::m_SamplingRateInMicroseconds, options, profilingService, RegisterBackendCounters::RegisterCategory(), RegisterBackendCounters::RegisterCounter(), ProfilingService::ResetExternalProfilingOptions(), and ProfilingService::SetCaptureData().

3280 {
3282  options.m_ProfilingOptions.m_EnableProfiling = true;
3283 
3284  // Reset the profiling service to the uninitialized state
3285  ProfilingService& profilingService = ProfilingService::Instance();
3286  profilingService.ResetExternalProfilingOptions(options.m_ProfilingOptions, true);
3287 
3288  const armnn::BackendId cpuRefId(armnn::Compute::CpuRef);
3289  const armnn::BackendId cpuAccId(armnn::Compute::CpuAcc);
3290 
3291  // Create BackendProfiling for each backend
3292  BackendProfiling backendProfilingCpuRef(options, profilingService, cpuRefId);
3293  BackendProfiling backendProfilingCpuAcc(options, profilingService, cpuAccId);
3294 
3295  uint16_t initialNumGlobalCounterIds = armnn::profiling::INFERENCES_RUN;
3296 
3297  // Create RegisterBackendCounters for CpuRef
3298  RegisterBackendCounters registerBackendCountersCpuRef(initialNumGlobalCounterIds, cpuRefId);
3299 
3300  // Create 'testCategory' in CounterDirectory (backend agnostic)
3301  BOOST_CHECK(profilingService.GetCounterDirectory().GetCategories().empty());
3302  registerBackendCountersCpuRef.RegisterCategory("testCategory");
3303  auto categoryOnePtr = profilingService.GetCounterDirectory().GetCategory("testCategory");
3304  BOOST_CHECK(categoryOnePtr);
3305 
3306  // Counters:
3307  // Global | Local | Backend
3308  // 5 | 0 | CpuRef
3309  // 6 | 1 | CpuRef
3310  // 7 | 1 | CpuAcc
3311 
3312  std::vector<uint16_t> cpuRefCounters = {0, 1};
3313  std::vector<uint16_t> cpuAccCounters = {0};
3314 
3315  // Register the backend counters for CpuRef and validate GetGlobalId and GetBackendId
3316  uint16_t currentNumGlobalCounterIds = registerBackendCountersCpuRef.RegisterCounter(
3317  0, "testCategory", 0, 0, 1.f, "CpuRefCounter0", "Zeroth CpuRef Counter");
3318  BOOST_CHECK(currentNumGlobalCounterIds == initialNumGlobalCounterIds + 1);
3319  uint16_t mappedGlobalId = profilingService.GetCounterMappings().GetGlobalId(0, cpuRefId);
3320  BOOST_CHECK(mappedGlobalId == currentNumGlobalCounterIds);
3321  auto backendMapping = profilingService.GetCounterMappings().GetBackendId(currentNumGlobalCounterIds);
3322  BOOST_CHECK(backendMapping.first == 0);
3323  BOOST_CHECK(backendMapping.second == cpuRefId);
3324 
3325  currentNumGlobalCounterIds = registerBackendCountersCpuRef.RegisterCounter(
3326  1, "testCategory", 0, 0, 1.f, "CpuRefCounter1", "First CpuRef Counter");
3327  BOOST_CHECK(currentNumGlobalCounterIds == initialNumGlobalCounterIds + 2);
3328  mappedGlobalId = profilingService.GetCounterMappings().GetGlobalId(1, cpuRefId);
3329  BOOST_CHECK(mappedGlobalId == currentNumGlobalCounterIds);
3330  backendMapping = profilingService.GetCounterMappings().GetBackendId(currentNumGlobalCounterIds);
3331  BOOST_CHECK(backendMapping.first == 1);
3332  BOOST_CHECK(backendMapping.second == cpuRefId);
3333 
3334  // Create RegisterBackendCounters for CpuAcc
3335  RegisterBackendCounters registerBackendCountersCpuAcc(currentNumGlobalCounterIds, cpuAccId);
3336 
3337  // Register the backend counter for CpuAcc and validate GetGlobalId and GetBackendId
3338  currentNumGlobalCounterIds = registerBackendCountersCpuAcc.RegisterCounter(
3339  0, "testCategory", 0, 0, 1.f, "CpuAccCounter0", "Zeroth CpuAcc Counter");
3340  BOOST_CHECK(currentNumGlobalCounterIds == initialNumGlobalCounterIds + 3);
3341  mappedGlobalId = profilingService.GetCounterMappings().GetGlobalId(0, cpuAccId);
3342  BOOST_CHECK(mappedGlobalId == currentNumGlobalCounterIds);
3343  backendMapping = profilingService.GetCounterMappings().GetBackendId(currentNumGlobalCounterIds);
3344  BOOST_CHECK(backendMapping.first == 0);
3345  BOOST_CHECK(backendMapping.second == cpuAccId);
3346 
3347  // Create vectors for active counters
3348  const std::vector<uint16_t> activeGlobalCounterIds = {5}; // CpuRef(0) activated
3349  const std::vector<uint16_t> newActiveGlobalCounterIds = {6, 7}; // CpuRef(0) and CpuAcc(1) activated
3350 
3351  const uint32_t capturePeriod = 200;
3352  const uint32_t newCapturePeriod = 100;
3353 
3354  // Set capture period and active counters in CaptureData
3355  profilingService.SetCaptureData(capturePeriod, activeGlobalCounterIds, {});
3356 
3357  // Get vector of active counters for CpuRef and CpuAcc backends
3358  std::vector<CounterStatus> cpuRefCounterStatus = backendProfilingCpuRef.GetActiveCounters();
3359  std::vector<CounterStatus> cpuAccCounterStatus = backendProfilingCpuAcc.GetActiveCounters();
3360  BOOST_CHECK_EQUAL(cpuRefCounterStatus.size(), 1);
3361  BOOST_CHECK_EQUAL(cpuAccCounterStatus.size(), 0);
3362 
3363  // Check active CpuRef counter
3364  BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_GlobalCounterId, activeGlobalCounterIds[0]);
3365  BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_BackendCounterId, cpuRefCounters[0]);
3366  BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_SamplingRateInMicroseconds, capturePeriod);
3367  BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_Enabled, true);
3368 
3369  // Check inactive CpuRef counter
3370  CounterStatus inactiveCpuRefCounter = backendProfilingCpuRef.GetCounterStatus(cpuRefCounters[1]);
3371  BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_GlobalCounterId, 6);
3372  BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_BackendCounterId, cpuRefCounters[1]);
3373  BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_SamplingRateInMicroseconds, 0);
3374  BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_Enabled, false);
3375 
3376  // Check inactive CpuAcc counter
3377  CounterStatus inactiveCpuAccCounter = backendProfilingCpuAcc.GetCounterStatus(cpuAccCounters[0]);
3378  BOOST_CHECK_EQUAL(inactiveCpuAccCounter.m_GlobalCounterId, 7);
3379  BOOST_CHECK_EQUAL(inactiveCpuAccCounter.m_BackendCounterId, cpuAccCounters[0]);
3380  BOOST_CHECK_EQUAL(inactiveCpuAccCounter.m_SamplingRateInMicroseconds, 0);
3381  BOOST_CHECK_EQUAL(inactiveCpuAccCounter.m_Enabled, false);
3382 
3383  // Set new capture period and new active counters in CaptureData
3384  profilingService.SetCaptureData(newCapturePeriod, newActiveGlobalCounterIds, {});
3385 
3386  // Get vector of active counters for CpuRef and CpuAcc backends
3387  cpuRefCounterStatus = backendProfilingCpuRef.GetActiveCounters();
3388  cpuAccCounterStatus = backendProfilingCpuAcc.GetActiveCounters();
3389  BOOST_CHECK_EQUAL(cpuRefCounterStatus.size(), 1);
3390  BOOST_CHECK_EQUAL(cpuAccCounterStatus.size(), 1);
3391 
3392  // Check active CpuRef counter
3393  BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_GlobalCounterId, newActiveGlobalCounterIds[0]);
3394  BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_BackendCounterId, cpuRefCounters[1]);
3395  BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_SamplingRateInMicroseconds, newCapturePeriod);
3396  BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_Enabled, true);
3397 
3398  // Check active CpuAcc counter
3399  BOOST_CHECK_EQUAL(cpuAccCounterStatus[0].m_GlobalCounterId, newActiveGlobalCounterIds[1]);
3400  BOOST_CHECK_EQUAL(cpuAccCounterStatus[0].m_BackendCounterId, cpuAccCounters[0]);
3401  BOOST_CHECK_EQUAL(cpuAccCounterStatus[0].m_SamplingRateInMicroseconds, newCapturePeriod);
3402  BOOST_CHECK_EQUAL(cpuAccCounterStatus[0].m_Enabled, true);
3403 
3404  // Check inactive CpuRef counter
3405  inactiveCpuRefCounter = backendProfilingCpuRef.GetCounterStatus(cpuRefCounters[0]);
3406  BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_GlobalCounterId, 5);
3407  BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_BackendCounterId, cpuRefCounters[0]);
3408  BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_SamplingRateInMicroseconds, 0);
3409  BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_Enabled, false);
3410 
3411  // Reset the profiling service to stop any running thread
3412  options.m_ProfilingOptions.m_EnableProfiling = false;
3413  profilingService.ResetExternalProfilingOptions(options.m_ProfilingOptions, true);
3414 }
const ICounterMappings & GetCounterMappings() const override
virtual const Categories & GetCategories() const =0
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:76
virtual uint16_t GetGlobalId(uint16_t backendCounterId, const armnn::BackendId &backendId) const =0
const ICounterDirectory & GetCounterDirectory() const
virtual const Category * GetCategory(const std::string &name) const =0
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
virtual const std::pair< uint16_t, armnn::BackendId > & GetBackendId(uint16_t globalCounterId) const =0
CPU Execution: Reference C++ kernels.
CPU Execution: NEON: ArmCompute.
ProfilingService & profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
void SetCaptureData(uint32_t capturePeriod, const std::vector< uint16_t > &counterIds, const std::set< BackendId > &activeBackends)

◆ BOOST_AUTO_TEST_CASE() [50/50]

BOOST_AUTO_TEST_CASE ( CheckRegisterCounters  )

Definition at line 3416 of file ProfilingTests.cpp.

References BOOST_AUTO_TEST_SUITE_END(), Timestamp::counterValues, armnn::CpuRef, MockBufferManager::GetReadableBuffer(), IRuntime::CreationOptions::ExternalProfilingOptions::m_EnableProfiling, IRuntime::CreationOptions::m_ProfilingOptions, options, armnn::profiling::ReadUint16(), armnn::profiling::ReadUint32(), armnn::profiling::ReadUint64(), MockProfilingService::RegisterMapping(), BackendProfiling::ReportCounters(), and Timestamp::timestamp.

3417 {
3419  options.m_ProfilingOptions.m_EnableProfiling = true;
3420  MockBufferManager mockBuffer(1024);
3421  CaptureData captureData;
3422  MockProfilingService mockProfilingService(
3423  mockBuffer, options.m_ProfilingOptions.m_EnableProfiling, captureData);
3425 
3426  mockProfilingService.RegisterMapping(6, 0, cpuRefId);
3427  mockProfilingService.RegisterMapping(7, 1, cpuRefId);
3428  mockProfilingService.RegisterMapping(8, 2, cpuRefId);
3429 
3430  armnn::profiling::BackendProfiling backendProfiling(options,
3431  mockProfilingService,
3432  cpuRefId);
3433 
3434  armnn::profiling::Timestamp timestamp;
3435  timestamp.timestamp = 1000998;
3436  timestamp.counterValues.emplace_back(0, 700);
3437  timestamp.counterValues.emplace_back(2, 93);
3438  std::vector<armnn::profiling::Timestamp> timestamps;
3439  timestamps.push_back(timestamp);
3440  backendProfiling.ReportCounters(timestamps);
3441 
3442  auto readBuffer = mockBuffer.GetReadableBuffer();
3443 
3444  uint32_t headerWord0 = ReadUint32(readBuffer, 0);
3445  uint32_t headerWord1 = ReadUint32(readBuffer, 4);
3446  uint64_t readTimestamp = ReadUint64(readBuffer, 8);
3447 
3448  BOOST_TEST(((headerWord0 >> 26) & 0x0000003F) == 3); // packet family
3449  BOOST_TEST(((headerWord0 >> 19) & 0x0000007F) == 0); // packet class
3450  BOOST_TEST(((headerWord0 >> 16) & 0x00000007) == 0); // packet type
3451  BOOST_TEST(headerWord1 == 20); // data length
3452  BOOST_TEST(1000998 == readTimestamp); // capture period
3453 
3454  uint32_t offset = 16;
3455  // Check Counter Index
3456  uint16_t readIndex = ReadUint16(readBuffer, offset);
3457  BOOST_TEST(6 == readIndex);
3458 
3459  // Check Counter Value
3460  offset += 2;
3461  uint32_t readValue = ReadUint32(readBuffer, offset);
3462  BOOST_TEST(700 == readValue);
3463 
3464  // Check Counter Index
3465  offset += 4;
3466  readIndex = ReadUint16(readBuffer, offset);
3467  BOOST_TEST(8 == readIndex);
3468 
3469  // Check Counter Value
3470  offset += 2;
3471  readValue = ReadUint32(readBuffer, offset);
3472  BOOST_TEST(93 == readValue);
3473 }
uint64_t ReadUint64(const IPacketBufferPtr &packetBuffer, unsigned int offset)
uint16_t ReadUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset)
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:76
CPU Execution: Reference C++ kernels.
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)
std::vector< CounterValue > counterValues
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ CaptureDataReadThreadImpl()

void CaptureDataReadThreadImpl ( const Holder holder,
CaptureData captureData 
)

Definition at line 542 of file ProfilingTests.cpp.

References Holder::GetCaptureData().

Referenced by BOOST_AUTO_TEST_CASE().

543 {
544  captureData = holder.GetCaptureData();
545 }
CaptureData GetCaptureData() const
Definition: Holder.cpp:54

◆ CaptureDataWriteThreadImpl()

void CaptureDataWriteThreadImpl ( Holder holder,
uint32_t  capturePeriod,
const std::vector< uint16_t > &  counterIds 
)

Definition at line 537 of file ProfilingTests.cpp.

References Holder::SetCaptureData().

Referenced by BOOST_AUTO_TEST_CASE().

538 {
539  holder.SetCaptureData(capturePeriod, counterIds, {});
540 }
void SetCaptureData(uint32_t capturePeriod, const std::vector< uint16_t > &counterIds, const std::set< armnn::BackendId > &activeBackends)
Definition: Holder.cpp:74

◆ ProfilingCurrentStateThreadImpl()

void ProfilingCurrentStateThreadImpl ( ProfilingStateMachine states)

Definition at line 454 of file ProfilingTests.cpp.

References ProfilingStateMachine::GetCurrentState(), armnn::profiling::NotConnected, and ProfilingStateMachine::TransitionToState().

Referenced by BOOST_AUTO_TEST_CASE().

455 {
456  ProfilingState newState = ProfilingState::NotConnected;
457  states.GetCurrentState();
458  states.TransitionToState(newState);
459 }
void TransitionToState(ProfilingState newState)

◆ StringToSwTraceStringTestHelper()

void StringToSwTraceStringTestHelper ( const std::string &  testString,
std::vector< uint32_t >  buffer,
size_t  expectedSize 
)

Definition at line 2040 of file ProfilingTests.cpp.

References BOOST_CHECK().

2041 {
2042  // Convert the test string to a SWTrace string
2043  BOOST_CHECK(StringToSwTraceString<SwTracePolicy>(testString, buffer));
2044 
2045  // The buffer must contain at least the length of the string
2046  BOOST_CHECK(!buffer.empty());
2047 
2048  // The buffer must be of the expected size (in words)
2049  BOOST_CHECK(buffer.size() == expectedSize);
2050 
2051  // The first word of the byte must be the length of the string including the null-terminator
2052  BOOST_CHECK(buffer[0] == testString.size() + 1);
2053 
2054  // The contents of the buffer must match the test string
2055  BOOST_CHECK(std::memcmp(testString.data(), buffer.data() + 1, testString.size()) == 0);
2056 
2057  // The buffer must include the null-terminator at the end of the string
2058  size_t nullTerminatorIndex = sizeof(uint32_t) + testString.size();
2059  BOOST_CHECK(reinterpret_cast<unsigned char*>(buffer.data())[nullTerminatorIndex] == '\0');
2060 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)