ArmNN
 20.05
ProfilingTests.cpp File Reference
#include "ProfilingTests.hpp"
#include "ProfilingTestUtils.hpp"
#include <backends/BackendProfiling.hpp>
#include <CommandHandler.hpp>
#include <CommandHandlerKey.hpp>
#include <CommandHandlerRegistry.hpp>
#include <common/include/SocketConnectionException.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 <armnn/utility/IgnoreUnused.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 (CheckTimelineActivationAndDeactivation)
 
 BOOST_AUTO_TEST_CASE (CheckProfilingServiceNotActive)
 
 BOOST_AUTO_TEST_CASE (CheckConnectionAcknowledged)
 
 BOOST_AUTO_TEST_CASE (CheckSocketConnectionException)
 
 BOOST_AUTO_TEST_CASE (CheckSocketConnectionException2)
 
 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)
 
 BOOST_AUTO_TEST_CASE (CheckFileFormat)
 

Typedef Documentation

◆ PacketType

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/54]

BOOST_AUTO_TEST_CASE ( CheckCommandHandlerKeyComparisons  )

Definition at line 55 of file ProfilingTests.cpp.

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

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

◆ BOOST_AUTO_TEST_CASE() [2/54]

BOOST_AUTO_TEST_CASE ( CheckPacketKeyComparisons  )

Definition at line 106 of file ProfilingTests.cpp.

References BOOST_CHECK().

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

◆ BOOST_AUTO_TEST_CASE() [3/54]

BOOST_AUTO_TEST_CASE ( CheckCommandHandler  )

Definition at line 131 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.

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

◆ BOOST_AUTO_TEST_CASE() [4/54]

BOOST_AUTO_TEST_CASE ( CheckEncodeVersion  )

Definition at line 259 of file ProfilingTests.cpp.

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

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

◆ BOOST_AUTO_TEST_CASE() [5/54]

BOOST_AUTO_TEST_CASE ( CheckPacketClass  )

Definition at line 289 of file ProfilingTests.cpp.

References BOOST_CHECK().

290 {
291  uint32_t length = 4;
292  std::unique_ptr<unsigned char[]> packetData0 = std::make_unique<unsigned char[]>(length);
293  std::unique_ptr<unsigned char[]> packetData1 = std::make_unique<unsigned char[]>(0);
294  std::unique_ptr<unsigned char[]> nullPacketData;
295 
296  Packet packetTest0(472580096, length, packetData0);
297 
298  BOOST_CHECK(packetTest0.GetHeader() == 472580096);
299  BOOST_CHECK(packetTest0.GetPacketFamily() == 7);
300  BOOST_CHECK(packetTest0.GetPacketId() == 43);
301  BOOST_CHECK(packetTest0.GetLength() == length);
302  BOOST_CHECK(packetTest0.GetPacketType() == 3);
303  BOOST_CHECK(packetTest0.GetPacketClass() == 5);
304 
305  BOOST_CHECK_THROW(Packet packetTest1(472580096, 0, packetData1), armnn::Exception);
306  BOOST_CHECK_NO_THROW(Packet packetTest2(472580096, 0, nullPacketData));
307 
308  Packet packetTest3(472580096, 0, nullPacketData);
309  BOOST_CHECK(packetTest3.GetLength() == 0);
310  BOOST_CHECK(packetTest3.GetData() == nullptr);
311 
312  const unsigned char* packetTest0Data = packetTest0.GetData();
313  Packet packetTest4(std::move(packetTest0));
314 
315  BOOST_CHECK(packetTest0.GetData() == nullptr);
316  BOOST_CHECK(packetTest4.GetData() == packetTest0Data);
317 
318  BOOST_CHECK(packetTest4.GetHeader() == 472580096);
319  BOOST_CHECK(packetTest4.GetPacketFamily() == 7);
320  BOOST_CHECK(packetTest4.GetPacketId() == 43);
321  BOOST_CHECK(packetTest4.GetLength() == length);
322  BOOST_CHECK(packetTest4.GetPacketType() == 3);
323  BOOST_CHECK(packetTest4.GetPacketClass() == 5);
324 }
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/54]

BOOST_AUTO_TEST_CASE ( CheckCommandHandlerFunctor  )

Definition at line 326 of file ProfilingTests.cpp.

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

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

◆ BOOST_AUTO_TEST_CASE() [7/54]

BOOST_AUTO_TEST_CASE ( CheckCommandHandlerRegistry  )

Definition at line 379 of file ProfilingTests.cpp.

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

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

BOOST_AUTO_TEST_CASE ( CheckPacketVersionResolver  )

Definition at line 431 of file ProfilingTests.cpp.

References PacketVersionResolver::ResolvePacketVersion().

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

◆ BOOST_AUTO_TEST_CASE() [9/54]

BOOST_AUTO_TEST_CASE ( CheckProfilingStateMachine  )

Definition at line 463 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.

464 {
465  ProfilingStateMachine profilingState1(ProfilingState::Uninitialised);
466  profilingState1.TransitionToState(ProfilingState::Uninitialised);
467  BOOST_CHECK(profilingState1.GetCurrentState() == ProfilingState::Uninitialised);
468 
469  ProfilingStateMachine profilingState2(ProfilingState::Uninitialised);
470  profilingState2.TransitionToState(ProfilingState::NotConnected);
471  BOOST_CHECK(profilingState2.GetCurrentState() == ProfilingState::NotConnected);
472 
473  ProfilingStateMachine profilingState3(ProfilingState::NotConnected);
474  profilingState3.TransitionToState(ProfilingState::NotConnected);
475  BOOST_CHECK(profilingState3.GetCurrentState() == ProfilingState::NotConnected);
476 
477  ProfilingStateMachine profilingState4(ProfilingState::NotConnected);
478  profilingState4.TransitionToState(ProfilingState::WaitingForAck);
479  BOOST_CHECK(profilingState4.GetCurrentState() == ProfilingState::WaitingForAck);
480 
481  ProfilingStateMachine profilingState5(ProfilingState::WaitingForAck);
482  profilingState5.TransitionToState(ProfilingState::WaitingForAck);
483  BOOST_CHECK(profilingState5.GetCurrentState() == ProfilingState::WaitingForAck);
484 
485  ProfilingStateMachine profilingState6(ProfilingState::WaitingForAck);
486  profilingState6.TransitionToState(ProfilingState::Active);
487  BOOST_CHECK(profilingState6.GetCurrentState() == ProfilingState::Active);
488 
489  ProfilingStateMachine profilingState7(ProfilingState::Active);
490  profilingState7.TransitionToState(ProfilingState::NotConnected);
491  BOOST_CHECK(profilingState7.GetCurrentState() == ProfilingState::NotConnected);
492 
493  ProfilingStateMachine profilingState8(ProfilingState::Active);
494  profilingState8.TransitionToState(ProfilingState::Active);
495  BOOST_CHECK(profilingState8.GetCurrentState() == ProfilingState::Active);
496 
497  ProfilingStateMachine profilingState9(ProfilingState::Uninitialised);
498  BOOST_CHECK_THROW(profilingState9.TransitionToState(ProfilingState::WaitingForAck), armnn::Exception);
499 
500  ProfilingStateMachine profilingState10(ProfilingState::Uninitialised);
501  BOOST_CHECK_THROW(profilingState10.TransitionToState(ProfilingState::Active), armnn::Exception);
502 
503  ProfilingStateMachine profilingState11(ProfilingState::NotConnected);
504  BOOST_CHECK_THROW(profilingState11.TransitionToState(ProfilingState::Uninitialised), armnn::Exception);
505 
506  ProfilingStateMachine profilingState12(ProfilingState::NotConnected);
507  BOOST_CHECK_THROW(profilingState12.TransitionToState(ProfilingState::Active), armnn::Exception);
508 
509  ProfilingStateMachine profilingState13(ProfilingState::WaitingForAck);
510  BOOST_CHECK_THROW(profilingState13.TransitionToState(ProfilingState::Uninitialised), armnn::Exception);
511 
512  ProfilingStateMachine profilingState14(ProfilingState::WaitingForAck);
513  profilingState14.TransitionToState(ProfilingState::NotConnected);
514  BOOST_CHECK(profilingState14.GetCurrentState() == ProfilingState::NotConnected);
515 
516  ProfilingStateMachine profilingState15(ProfilingState::Active);
517  BOOST_CHECK_THROW(profilingState15.TransitionToState(ProfilingState::Uninitialised), armnn::Exception);
518 
520  BOOST_CHECK_THROW(profilingState16.TransitionToState(ProfilingState::WaitingForAck), armnn::Exception);
521 
522  ProfilingStateMachine profilingState17(ProfilingState::Uninitialised);
523 
524  std::thread thread1(ProfilingCurrentStateThreadImpl, std::ref(profilingState17));
525  std::thread thread2(ProfilingCurrentStateThreadImpl, std::ref(profilingState17));
526  std::thread thread3(ProfilingCurrentStateThreadImpl, std::ref(profilingState17));
527  std::thread thread4(ProfilingCurrentStateThreadImpl, std::ref(profilingState17));
528  std::thread thread5(ProfilingCurrentStateThreadImpl, std::ref(profilingState17));
529 
530  thread1.join();
531  thread2.join();
532  thread3.join();
533  thread4.join();
534  thread5.join();
535 
536  BOOST_TEST((profilingState17.GetCurrentState() == ProfilingState::NotConnected));
537 }
void ProfilingCurrentStateThreadImpl(ProfilingStateMachine &states)
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() [10/54]

BOOST_AUTO_TEST_CASE ( CheckCaptureDataHolder  )

Definition at line 549 of file ProfilingTests.cpp.

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

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

◆ BOOST_AUTO_TEST_CASE() [11/54]

BOOST_AUTO_TEST_CASE ( CaptureDataMethods  )

Definition at line 619 of file ProfilingTests.cpp.

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

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

◆ BOOST_AUTO_TEST_CASE() [12/54]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceDisabled  )

Definition at line 645 of file ProfilingTests.cpp.

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

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

◆ BOOST_AUTO_TEST_CASE() [13/54]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceCounterDirectory  )

Definition at line 655 of file ProfilingTests.cpp.

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

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

◆ BOOST_AUTO_TEST_CASE() [14/54]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceCounterValues  )

Definition at line 678 of file ProfilingTests.cpp.

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

679 {
680  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
681  options.m_EnableProfiling = true;
683  profilingService.ResetExternalProfilingOptions(options, true);
684 
685  profilingService.Update();
686  const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory();
687  const Counters& counters = counterDirectory.GetCounters();
688  BOOST_CHECK(!counters.empty());
689 
690  std::vector<std::thread> writers;
691 
692  BOOST_CHECK(!counters.empty());
693 
694  // Test GetAbsoluteCounterValue
695  for (int i = 0; i < 4; ++i)
696  {
697  // Increment and decrement the INFERENCES_RUN counter 250 times
698  writers.push_back(std::thread([&profilingService]()
699  {
700  for (int i = 0; i < 250; ++i)
701  {
702  profilingService.IncrementCounterValue(INFERENCES_RUN);
703  }
704  }));
705  // Add 10 to the INFERENCES_RUN counter 200 times
706  writers.push_back(std::thread([&profilingService]()
707  {
708  for (int i = 0; i < 200; ++i)
709  {
710  profilingService.AddCounterValue(INFERENCES_RUN, 10);
711  }
712  }));
713  // Subtract 5 from the INFERENCES_RUN counter 200 times
714  writers.push_back(std::thread([&profilingService]()
715  {
716  for (int i = 0; i < 200; ++i)
717  {
718  profilingService.SubtractCounterValue(INFERENCES_RUN, 5);
719  }
720  }));
721  }
722 
723  std::for_each(writers.begin(), writers.end(), mem_fn(&std::thread::join));
724 
725  uint32_t absoluteCounterValue = 0;
726 
727  BOOST_CHECK_NO_THROW(absoluteCounterValue = profilingService.GetAbsoluteCounterValue(INFERENCES_RUN));
728  BOOST_CHECK(absoluteCounterValue = 5000);
729 
730  // Test SetCounterValue
731  BOOST_CHECK_NO_THROW(profilingService.SetCounterValue(INFERENCES_RUN, 0));
732  BOOST_CHECK_NO_THROW(absoluteCounterValue = profilingService.GetAbsoluteCounterValue(INFERENCES_RUN));
733  BOOST_CHECK(absoluteCounterValue == 0);
734 
735  // Test GetDeltaCounterValue
736  writers.clear();
737  uint32_t deltaCounterValue = 0;
738  //Start a reading thread to randomly read the INFERENCES_RUN counter value
739  std::thread reader([&profilingService](uint32_t& deltaCounterValue)
740  {
741  for (int i = 0; i < 300; ++i)
742  {
743  deltaCounterValue += profilingService.GetDeltaCounterValue(INFERENCES_RUN);
744  }
745  }, std::ref(deltaCounterValue));
746 
747  for (int i = 0; i < 4; ++i)
748  {
749  // Increment and decrement the INFERENCES_RUN counter 250 times
750  writers.push_back(std::thread([&profilingService]()
751  {
752  for (int i = 0; i < 250; ++i)
753  {
754  profilingService.IncrementCounterValue(INFERENCES_RUN);
755  }
756  }));
757  // Add 10 to the INFERENCES_RUN counter 200 times
758  writers.push_back(std::thread([&profilingService]()
759  {
760  for (int i = 0; i < 200; ++i)
761  {
762  profilingService.AddCounterValue(INFERENCES_RUN, 10);
763  }
764  }));
765  // Subtract 5 from the INFERENCES_RUN counter 200 times
766  writers.push_back(std::thread([&profilingService]()
767  {
768  for (int i = 0; i < 200; ++i)
769  {
770  profilingService.SubtractCounterValue(INFERENCES_RUN, 5);
771  }
772  }));
773  }
774 
775  std::for_each(writers.begin(), writers.end(), mem_fn(&std::thread::join));
776  reader.join();
777 
778  // Do one last read in case the reader stopped early
779  deltaCounterValue += profilingService.GetDeltaCounterValue(INFERENCES_RUN);
780  BOOST_CHECK(deltaCounterValue == 5000);
781 
782  // Reset the profiling service to stop any running thread
783  options.m_EnableProfiling = false;
784  profilingService.ResetExternalProfilingOptions(options, true);
785 }
uint32_t GetAbsoluteCounterValue(uint16_t counterUid) const override
std::unordered_map< uint16_t, CounterPtr > Counters
uint32_t IncrementCounterValue(uint16_t counterUid) override
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
uint32_t GetDeltaCounterValue(uint16_t counterUid) override
uint32_t SubtractCounterValue(uint16_t counterUid, uint32_t value) override
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
uint32_t AddCounterValue(uint16_t counterUid, uint32_t value) override
armnn::profiling::ProfilingService profilingService
void SetCounterValue(uint16_t counterUid, uint32_t value) override
virtual const Counters & GetCounters() const =0
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
const ICounterDirectory & GetCounterDirectory() const

◆ BOOST_AUTO_TEST_CASE() [15/54]

BOOST_AUTO_TEST_CASE ( CheckProfilingObjectUids  )

Definition at line 787 of file ProfilingTests.cpp.

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

788 {
789  uint16_t uid = 0;
790  BOOST_CHECK_NO_THROW(uid = GetNextUid());
791  BOOST_CHECK(uid >= 1);
792 
793  uint16_t nextUid = 0;
794  BOOST_CHECK_NO_THROW(nextUid = GetNextUid());
795  BOOST_CHECK(nextUid > uid);
796 
797  std::vector<uint16_t> counterUids;
798  BOOST_CHECK_NO_THROW(counterUids = GetNextCounterUids(uid,0));
799  BOOST_CHECK(counterUids.size() == 1);
800 
801  std::vector<uint16_t> nextCounterUids;
802  BOOST_CHECK_NO_THROW(nextCounterUids = GetNextCounterUids(nextUid, 2));
803  BOOST_CHECK(nextCounterUids.size() == 2);
804  BOOST_CHECK(nextCounterUids[0] > counterUids[0]);
805 
806  std::vector<uint16_t> counterUidsMultiCore;
807  uint16_t thirdUid = 4;
808  uint16_t numberOfCores = 13;
809  BOOST_CHECK_NO_THROW(counterUidsMultiCore = GetNextCounterUids(thirdUid, numberOfCores));
810  BOOST_CHECK(counterUidsMultiCore.size() == numberOfCores);
811  BOOST_CHECK(counterUidsMultiCore.front() >= nextCounterUids[0]);
812  for (size_t i = 1; i < numberOfCores; i++)
813  {
814  BOOST_CHECK(counterUidsMultiCore[i] == counterUidsMultiCore[i - 1] + 1);
815  }
816  BOOST_CHECK(counterUidsMultiCore.back() == counterUidsMultiCore.front() + numberOfCores - 1);
817 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
uint16_t GetNextUid(bool peekOnly)
std::vector< uint16_t > GetNextCounterUids(uint16_t firstUid, uint16_t cores)

◆ BOOST_AUTO_TEST_CASE() [16/54]

BOOST_AUTO_TEST_CASE ( CheckCounterDirectoryRegisterCategory  )

Definition at line 819 of file ProfilingTests.cpp.

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

820 {
821  CounterDirectory counterDirectory;
822  BOOST_CHECK(counterDirectory.GetCategoryCount() == 0);
823  BOOST_CHECK(counterDirectory.GetDeviceCount() == 0);
824  BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0);
825  BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
826 
827  // Register a category with an invalid name
828  const Category* noCategory = nullptr;
829  BOOST_CHECK_THROW(noCategory = counterDirectory.RegisterCategory(""), armnn::InvalidArgumentException);
830  BOOST_CHECK(counterDirectory.GetCategoryCount() == 0);
831  BOOST_CHECK(!noCategory);
832 
833  // Register a category with an invalid name
834  BOOST_CHECK_THROW(noCategory = counterDirectory.RegisterCategory("invalid category"),
836  BOOST_CHECK(counterDirectory.GetCategoryCount() == 0);
837  BOOST_CHECK(!noCategory);
838 
839  // Register a new category
840  const std::string categoryName = "some_category";
841  const Category* category = nullptr;
842  BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName));
843  BOOST_CHECK(counterDirectory.GetCategoryCount() == 1);
844  BOOST_CHECK(category);
845  BOOST_CHECK(category->m_Name == categoryName);
846  BOOST_CHECK(category->m_Counters.empty());
847 
848  // Get the registered category
849  const Category* registeredCategory = counterDirectory.GetCategory(categoryName);
850  BOOST_CHECK(counterDirectory.GetCategoryCount() == 1);
851  BOOST_CHECK(registeredCategory);
852  BOOST_CHECK(registeredCategory == category);
853 
854  // Try to get a category not registered
855  const Category* notRegisteredCategory = counterDirectory.GetCategory("not_registered_category");
856  BOOST_CHECK(counterDirectory.GetCategoryCount() == 1);
857  BOOST_CHECK(!notRegisteredCategory);
858 
859  // Register a category already registered
860  const Category* anotherCategory = nullptr;
861  BOOST_CHECK_THROW(anotherCategory = counterDirectory.RegisterCategory(categoryName),
863  BOOST_CHECK(counterDirectory.GetCategoryCount() == 1);
864  BOOST_CHECK(!anotherCategory);
865 
866  // Register a device for testing
867  const std::string deviceName = "some_device";
868  const Device* device = nullptr;
869  BOOST_CHECK_NO_THROW(device = counterDirectory.RegisterDevice(deviceName));
870  BOOST_CHECK(counterDirectory.GetDeviceCount() == 1);
871  BOOST_CHECK(device);
872  BOOST_CHECK(device->m_Uid >= 1);
873  BOOST_CHECK(device->m_Name == deviceName);
874  BOOST_CHECK(device->m_Cores == 0);
875 
876  // Register a new category not associated to any device
877  const std::string categoryWoDeviceName = "some_category_without_device";
878  const Category* categoryWoDevice = nullptr;
879  BOOST_CHECK_NO_THROW(categoryWoDevice = counterDirectory.RegisterCategory(categoryWoDeviceName));
880  BOOST_CHECK(counterDirectory.GetCategoryCount() == 2);
881  BOOST_CHECK(categoryWoDevice);
882  BOOST_CHECK(categoryWoDevice->m_Name == categoryWoDeviceName);
883  BOOST_CHECK(categoryWoDevice->m_Counters.empty());
884 
885  // Register a new category associated to an invalid device name (already exist)
886  const Category* categoryInvalidDeviceName = nullptr;
887  BOOST_CHECK_THROW(categoryInvalidDeviceName =
888  counterDirectory.RegisterCategory(categoryWoDeviceName),
890  BOOST_CHECK(counterDirectory.GetCategoryCount() == 2);
891  BOOST_CHECK(!categoryInvalidDeviceName);
892 
893  // Register a new category associated to a valid device
894  const std::string categoryWValidDeviceName = "some_category_with_valid_device";
895  const Category* categoryWValidDevice = nullptr;
896  BOOST_CHECK_NO_THROW(categoryWValidDevice =
897  counterDirectory.RegisterCategory(categoryWValidDeviceName));
898  BOOST_CHECK(counterDirectory.GetCategoryCount() == 3);
899  BOOST_CHECK(categoryWValidDevice);
900  BOOST_CHECK(categoryWValidDevice != category);
901  BOOST_CHECK(categoryWValidDevice->m_Name == categoryWValidDeviceName);
902 
903  // Register a counter set for testing
904  const std::string counterSetName = "some_counter_set";
905  const CounterSet* counterSet = nullptr;
906  BOOST_CHECK_NO_THROW(counterSet = counterDirectory.RegisterCounterSet(counterSetName));
907  BOOST_CHECK(counterDirectory.GetCounterSetCount() == 1);
908  BOOST_CHECK(counterSet);
909  BOOST_CHECK(counterSet->m_Uid >= 1);
910  BOOST_CHECK(counterSet->m_Name == counterSetName);
911  BOOST_CHECK(counterSet->m_Count == 0);
912 
913  // Register a new category not associated to any counter set
914  const std::string categoryWoCounterSetName = "some_category_without_counter_set";
915  const Category* categoryWoCounterSet = nullptr;
916  BOOST_CHECK_NO_THROW(categoryWoCounterSet =
917  counterDirectory.RegisterCategory(categoryWoCounterSetName));
918  BOOST_CHECK(counterDirectory.GetCategoryCount() == 4);
919  BOOST_CHECK(categoryWoCounterSet);
920  BOOST_CHECK(categoryWoCounterSet->m_Name == categoryWoCounterSetName);
921 
922  // Register a new category associated to a valid counter set
923  const std::string categoryWValidCounterSetName = "some_category_with_valid_counter_set";
924  const Category* categoryWValidCounterSet = nullptr;
925  BOOST_CHECK_NO_THROW(categoryWValidCounterSet = counterDirectory.RegisterCategory(categoryWValidCounterSetName));
926  BOOST_CHECK(counterDirectory.GetCategoryCount() == 5);
927  BOOST_CHECK(categoryWValidCounterSet);
928  BOOST_CHECK(categoryWValidCounterSet != category);
929  BOOST_CHECK(categoryWValidCounterSet->m_Name == categoryWValidCounterSetName);
930 
931  // Register a new category associated to a valid device and counter set
932  const std::string categoryWValidDeviceAndValidCounterSetName = "some_category_with_valid_device_and_counter_set";
933  const Category* categoryWValidDeviceAndValidCounterSet = nullptr;
934  BOOST_CHECK_NO_THROW(categoryWValidDeviceAndValidCounterSet = counterDirectory.RegisterCategory(
935  categoryWValidDeviceAndValidCounterSetName));
936  BOOST_CHECK(counterDirectory.GetCategoryCount() == 6);
937  BOOST_CHECK(categoryWValidDeviceAndValidCounterSet);
938  BOOST_CHECK(categoryWValidDeviceAndValidCounterSet != category);
939  BOOST_CHECK(categoryWValidDeviceAndValidCounterSet->m_Name == categoryWValidDeviceAndValidCounterSetName);
940 }
const Category * RegisterCategory(const std::string &categoryName) override
uint16_t GetCounterSetCount() const override
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
uint16_t GetDeviceCount() const override
uint16_t GetCategoryCount() const override
std::vector< uint16_t > m_Counters
const Category * GetCategory(const std::string &name) const override
const Device * RegisterDevice(const std::string &deviceName, uint16_t cores=0, const Optional< std::string > &parentCategoryName=EmptyOptional()) override
uint16_t GetCounterCount() 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/54]

BOOST_AUTO_TEST_CASE ( CheckCounterDirectoryRegisterDevice  )

Definition at line 942 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_Name, Device::m_Name, Device::m_Uid, CounterDirectory::RegisterCategory(), and CounterDirectory::RegisterDevice().

943 {
944  CounterDirectory counterDirectory;
945  BOOST_CHECK(counterDirectory.GetCategoryCount() == 0);
946  BOOST_CHECK(counterDirectory.GetDeviceCount() == 0);
947  BOOST_CHECK(counterDirectory.GetCounterSetCount() == 0);
948  BOOST_CHECK(counterDirectory.GetCounterCount() == 0);
949 
950  // Register a device with an invalid name
951  const Device* noDevice = nullptr;
952  BOOST_CHECK_THROW(noDevice = counterDirectory.RegisterDevice(""), armnn::InvalidArgumentException);
953  BOOST_CHECK(counterDirectory.GetDeviceCount() == 0);
954  BOOST_CHECK(!noDevice);
955 
956  // Register a device with an invalid name
957  BOOST_CHECK_THROW(noDevice = counterDirectory.RegisterDevice("inv@lid nam€"), armnn::InvalidArgumentException);
958  BOOST_CHECK(counterDirectory.GetDeviceCount() == 0);
959  BOOST_CHECK(!noDevice);
960 
961  // Register a new device with no cores or parent category
962  const std::string deviceName = "some_device";
963  const Device* device = nullptr;
964  BOOST_CHECK_NO_THROW(device = counterDirectory.RegisterDevice(deviceName));
965  BOOST_CHECK(counterDirectory.GetDeviceCount() == 1);
966  BOOST_CHECK(device);
967  BOOST_CHECK(device->m_Name == deviceName);
968  BOOST_CHECK(device->m_Uid >= 1);
969  BOOST_CHECK(device->m_Cores == 0);
970 
971  // Try getting an unregistered device
972  const Device* unregisteredDevice = counterDirectory.GetDevice(9999);
973  BOOST_CHECK(!unregisteredDevice);
974 
975  // Get the registered device
976  const Device* registeredDevice = counterDirectory.GetDevice(device->m_Uid);
977  BOOST_CHECK(counterDirectory.GetDeviceCount() == 1);
978  BOOST_CHECK(registeredDevice);
979  BOOST_CHECK(registeredDevice == device);
980 
981  // Register a device with the name of a device already registered
982  const Device* deviceSameName = nullptr;
983  BOOST_CHECK_THROW(deviceSameName = counterDirectory.RegisterDevice(deviceName), armnn::InvalidArgumentException);
984  BOOST_CHECK(counterDirectory.GetDeviceCount() == 1);
985  BOOST_CHECK(!deviceSameName);
986 
987  // Register a new device with cores and no parent category
988  const std::string deviceWCoresName = "some_device_with_cores";
989  const Device* deviceWCores = nullptr;
990  BOOST_CHECK_NO_THROW(deviceWCores = counterDirectory.RegisterDevice(deviceWCoresName, 2));
991  BOOST_CHECK(counterDirectory.GetDeviceCount() == 2);
992  BOOST_CHECK(deviceWCores);
993  BOOST_CHECK(deviceWCores->m_Name == deviceWCoresName);
994  BOOST_CHECK(deviceWCores->m_Uid >= 1);
995  BOOST_CHECK(deviceWCores->m_Uid > device->m_Uid);
996  BOOST_CHECK(deviceWCores->m_Cores == 2);
997 
998  // Get the registered device
999  const Device* registeredDeviceWCores = counterDirectory.GetDevice(deviceWCores->m_Uid);
1000  BOOST_CHECK(counterDirectory.GetDeviceCount() == 2);
1001  BOOST_CHECK(registeredDeviceWCores);
1002  BOOST_CHECK(registeredDeviceWCores == deviceWCores);
1003  BOOST_CHECK(registeredDeviceWCores != device);
1004 
1005  // Register a new device with cores and invalid parent category
1006  const std::string deviceWCoresWInvalidParentCategoryName = "some_device_with_cores_with_invalid_parent_category";
1007  const Device* deviceWCoresWInvalidParentCategory = nullptr;
1008  BOOST_CHECK_THROW(deviceWCoresWInvalidParentCategory =
1009  counterDirectory.RegisterDevice(deviceWCoresWInvalidParentCategoryName, 3, std::string("")),
1011  BOOST_CHECK(counterDirectory.GetDeviceCount() == 2);
1012  BOOST_CHECK(!deviceWCoresWInvalidParentCategory);
1013 
1014  // Register a new device with cores and invalid parent category
1015  const std::string deviceWCoresWInvalidParentCategoryName2 = "some_device_with_cores_with_invalid_parent_category2";
1016  const Device* deviceWCoresWInvalidParentCategory2 = nullptr;
1017  BOOST_CHECK_THROW(deviceWCoresWInvalidParentCategory2 = counterDirectory.RegisterDevice(
1018  deviceWCoresWInvalidParentCategoryName2, 3, std::string("invalid_parent_category")),
1020  BOOST_CHECK(counterDirectory.GetDeviceCount() == 2);
1021  BOOST_CHECK(!deviceWCoresWInvalidParentCategory2);
1022 
1023  // Register a category for testing
1024  const std::string categoryName = "some_category";
1025  const Category* category = nullptr;
1026  BOOST_CHECK_NO_THROW(category = counterDirectory.RegisterCategory(categoryName));
1027  BOOST_CHECK(counterDirectory.GetCategoryCount() == 1);
1028  BOOST_CHECK(category);
1029  BOOST_CHECK(category->m_Name == categoryName);
1030  BOOST_CHECK(category->m_Counters.empty());
1031 
1032  // Register a new device with cores and valid parent category
1033  const std::string deviceWCoresWValidParentCategoryName = "some_device_with_cores_with_valid_parent_category";
1034  const Device* deviceWCoresWValidParentCategory = nullptr;
1035  BOOST_CHECK_NO_THROW(deviceWCoresWValidParentCategory =
1036  counterDirectory.RegisterDevice(deviceWCoresWValidParentCategoryName, 4, categoryName));
1037  BOOST_CHECK(counterDirectory.GetDeviceCount() == 3);
1038  BOOST_CHECK(deviceWCoresWValidParentCategory);
1039  BOOST_CHECK(deviceWCoresWValidParentCategory->m_Name == deviceWCoresWValidParentCategoryName);
1040  BOOST_CHECK(deviceWCoresWValidParentCategory->m_Uid >= 1);
1041  BOOST_CHECK(deviceWCoresWValidParentCategory->m_Uid > device->m_Uid);
1042  BOOST_CHECK(deviceWCoresWValidParentCategory->m_Uid > deviceWCores->m_Uid);
1043  BOOST_CHECK(deviceWCoresWValidParentCategory->m_Cores == 4);
1044 }
const Category * RegisterCategory(const std::string &categoryName) override
const Device * GetDevice(uint16_t uid) const override
uint16_t GetCounterSetCount() const override
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
uint16_t GetDeviceCount() const override
uint16_t GetCategoryCount() const override
std::vector< uint16_t > m_Counters
const Device * RegisterDevice(const std::string &deviceName, uint16_t cores=0, const Optional< std::string > &parentCategoryName=EmptyOptional()) override
uint16_t GetCounterCount() const override

◆ BOOST_AUTO_TEST_CASE() [18/54]

BOOST_AUTO_TEST_CASE ( CheckCounterDirectoryRegisterCounterSet  )

Definition at line 1046 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_Name, CounterSet::m_Name, CounterSet::m_Uid, CounterDirectory::RegisterCategory(), and CounterDirectory::RegisterCounterSet().

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

◆ BOOST_AUTO_TEST_CASE() [19/54]

BOOST_AUTO_TEST_CASE ( CheckCounterDirectoryRegisterCounter  )

Definition at line 1165 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, Counter::m_CounterSetUid, Counter::m_Description, 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().

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

BOOST_AUTO_TEST_CASE ( CounterSelectionCommandHandlerParseData  )

Definition at line 1738 of file ProfilingTests.cpp.

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

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

◆ BOOST_AUTO_TEST_CASE() [21/54]

BOOST_AUTO_TEST_CASE ( CheckTimelineActivationAndDeactivation  )

Definition at line 1886 of file ProfilingTests.cpp.

References armnn::profiling::Active, BOOST_CHECK(), armnn::profiling::ConstructHeader(), Version::GetEncodedValue(), armnn::profiling::NotConnected, PacketVersionResolver::ResolvePacketVersion(), and armnn::profiling::WaitingForAck.

1887 {
1888  class TestReportStructure : public IReportStructure
1889  {
1890  public:
1891  virtual void ReportStructure() override
1892  {
1893  m_ReportStructureCalled = true;
1894  }
1895 
1896  bool m_ReportStructureCalled = false;
1897  };
1898 
1899  class TestNotifyBackends : public INotifyBackends
1900  {
1901  public:
1902  TestNotifyBackends() : m_timelineReporting(false) {}
1903  virtual void NotifyBackendsForTimelineReporting() override
1904  {
1905  m_TestNotifyBackendsCalled = m_timelineReporting.load();
1906  }
1907 
1908  bool m_TestNotifyBackendsCalled = false;
1909  std::atomic<bool> m_timelineReporting;
1910  };
1911 
1912  PacketVersionResolver packetVersionResolver;
1913 
1914  BufferManager bufferManager(512);
1915  SendTimelinePacket sendTimelinePacket(bufferManager);
1916  ProfilingStateMachine stateMachine;
1917  TestReportStructure testReportStructure;
1918  TestNotifyBackends testNotifyBackends;
1919 
1920  profiling::ActivateTimelineReportingCommandHandler activateTimelineReportingCommandHandler(0,
1921  6,
1922  packetVersionResolver.ResolvePacketVersion(0, 6)
1923  .GetEncodedValue(),
1924  sendTimelinePacket,
1925  stateMachine,
1926  testReportStructure,
1927  testNotifyBackends.m_timelineReporting,
1928  testNotifyBackends);
1929 
1930  // Write an "ActivateTimelineReporting" packet into the mock profiling connection, to simulate an input from an
1931  // external profiling service
1932  const uint32_t packetFamily1 = 0;
1933  const uint32_t packetId1 = 6;
1934  uint32_t packetHeader1 = ConstructHeader(packetFamily1, packetId1);
1935 
1936  // Create the ActivateTimelineReportingPacket
1937  Packet ActivateTimelineReportingPacket(packetHeader1); // Length == 0
1938 
1939  BOOST_CHECK_THROW(
1940  activateTimelineReportingCommandHandler.operator()(ActivateTimelineReportingPacket), armnn::Exception);
1941 
1942  stateMachine.TransitionToState(ProfilingState::NotConnected);
1943  BOOST_CHECK_THROW(
1944  activateTimelineReportingCommandHandler.operator()(ActivateTimelineReportingPacket), armnn::Exception);
1945 
1946  stateMachine.TransitionToState(ProfilingState::WaitingForAck);
1947  BOOST_CHECK_THROW(
1948  activateTimelineReportingCommandHandler.operator()(ActivateTimelineReportingPacket), armnn::Exception);
1949 
1950  stateMachine.TransitionToState(ProfilingState::Active);
1951  activateTimelineReportingCommandHandler.operator()(ActivateTimelineReportingPacket);
1952 
1953  BOOST_CHECK(testReportStructure.m_ReportStructureCalled);
1954  BOOST_CHECK(testNotifyBackends.m_TestNotifyBackendsCalled);
1955  BOOST_CHECK(testNotifyBackends.m_timelineReporting.load());
1956 
1957  DeactivateTimelineReportingCommandHandler deactivateTimelineReportingCommandHandler(0,
1958  7,
1959  packetVersionResolver.ResolvePacketVersion(0, 7).GetEncodedValue(),
1960  testNotifyBackends.m_timelineReporting,
1961  stateMachine,
1962  testNotifyBackends);
1963 
1964  const uint32_t packetFamily2 = 0;
1965  const uint32_t packetId2 = 7;
1966  uint32_t packetHeader2 = ConstructHeader(packetFamily2, packetId2);
1967 
1968  // Create the DeactivateTimelineReportingPacket
1969  Packet deactivateTimelineReportingPacket(packetHeader2); // Length == 0
1970 
1971  stateMachine.Reset();
1972  BOOST_CHECK_THROW(
1973  deactivateTimelineReportingCommandHandler.operator()(deactivateTimelineReportingPacket), armnn::Exception);
1974 
1975  stateMachine.TransitionToState(ProfilingState::NotConnected);
1976  BOOST_CHECK_THROW(
1977  deactivateTimelineReportingCommandHandler.operator()(deactivateTimelineReportingPacket), armnn::Exception);
1978 
1979  stateMachine.TransitionToState(ProfilingState::WaitingForAck);
1980  BOOST_CHECK_THROW(
1981  deactivateTimelineReportingCommandHandler.operator()(deactivateTimelineReportingPacket), armnn::Exception);
1982 
1983  stateMachine.TransitionToState(ProfilingState::Active);
1984  deactivateTimelineReportingCommandHandler.operator()(deactivateTimelineReportingPacket);
1985 
1986  BOOST_CHECK(!testNotifyBackends.m_TestNotifyBackendsCalled);
1987  BOOST_CHECK(!testNotifyBackends.m_timelineReporting.load());
1988 }
DataLayout::NHWC false
Version ResolvePacketVersion(uint32_t familyId, uint32_t packetId) const
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
uint32_t ConstructHeader(uint32_t packetFamily, uint32_t packetId)
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46

◆ BOOST_AUTO_TEST_CASE() [22/54]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceNotActive  )

Definition at line 1990 of file ProfilingTests.cpp.

References armnn::profiling::Active, BOOST_CHECK(), ProfilingServiceRuntimeHelper::ForceTransitionToState(), ProfilingServiceRuntimeHelper::GetProfilingBufferManager(), armnn::GetProfilingService(), BufferManager::GetReadableBuffer(), IRuntime::CreationOptions::ExternalProfilingOptions::m_EnableProfiling, IRuntime::CreationOptions::m_ProfilingOptions, armnn::profiling::NotConnected, options, and armnn::profiling::WaitingForAck.

1991 {
1992  using namespace armnn;
1993  using namespace armnn::profiling;
1994 
1995  // Create runtime in which the test will run
1997  options.m_ProfilingOptions.m_EnableProfiling = true;
1998 
1999  armnn::Runtime runtime(options);
2000  profiling::ProfilingServiceRuntimeHelper profilingServiceHelper(GetProfilingService(&runtime));
2001  profilingServiceHelper.ForceTransitionToState(ProfilingState::NotConnected);
2002  profilingServiceHelper.ForceTransitionToState(ProfilingState::WaitingForAck);
2003  profilingServiceHelper.ForceTransitionToState(ProfilingState::Active);
2004 
2005  profiling::BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager();
2006  auto readableBuffer = bufferManager.GetReadableBuffer();
2007 
2008  // Profiling is enabled, the post-optimisation structure should be created
2009  BOOST_CHECK(readableBuffer == nullptr);
2010 }
Copyright (c) 2020 ARM Limited.
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
profiling::ProfilingService & GetProfilingService(armnn::Runtime *runtime)
Definition: TestUtils.cpp:25
IPacketBufferPtr GetReadableBuffer() override
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:83

◆ BOOST_AUTO_TEST_CASE() [23/54]

BOOST_AUTO_TEST_CASE ( CheckConnectionAcknowledged  )

Definition at line 2012 of file ProfilingTests.cpp.

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

2013 {
2014  using boost::numeric_cast;
2015 
2016  const uint32_t packetFamilyId = 0;
2017  const uint32_t connectionPacketId = 0x10000;
2018  const uint32_t version = 1;
2019 
2020  uint32_t sizeOfUint32 = numeric_cast<uint32_t>(sizeof(uint32_t));
2021  uint32_t sizeOfUint16 = numeric_cast<uint32_t>(sizeof(uint16_t));
2022 
2023  // Data with period and counters
2024  uint32_t period1 = 10;
2025  uint32_t dataLength1 = 8;
2026  uint32_t offset = 0;
2027 
2028  std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength1);
2029  unsigned char* data1 = reinterpret_cast<unsigned char*>(uniqueData1.get());
2030 
2031  WriteUint32(data1, offset, period1);
2032  offset += sizeOfUint32;
2033  WriteUint16(data1, offset, 4000);
2034  offset += sizeOfUint16;
2035  WriteUint16(data1, offset, 5000);
2036 
2037  Packet packetA(connectionPacketId, dataLength1, uniqueData1);
2038 
2039  ProfilingStateMachine profilingState(ProfilingState::Uninitialised);
2040  BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::Uninitialised);
2041  CounterDirectory counterDirectory;
2042  MockBufferManager mockBuffer(1024);
2043  SendCounterPacket sendCounterPacket(mockBuffer);
2044  SendThread sendThread(profilingState, mockBuffer, sendCounterPacket);
2045  SendTimelinePacket sendTimelinePacket(mockBuffer);
2046 
2047  ConnectionAcknowledgedCommandHandler commandHandler(packetFamilyId, connectionPacketId, version, counterDirectory,
2048  sendCounterPacket, sendTimelinePacket, profilingState);
2049 
2050  // command handler received packet on ProfilingState::Uninitialised
2051  BOOST_CHECK_THROW(commandHandler(packetA), armnn::Exception);
2052 
2053  profilingState.TransitionToState(ProfilingState::NotConnected);
2054  BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::NotConnected);
2055  // command handler received packet on ProfilingState::NotConnected
2056  BOOST_CHECK_THROW(commandHandler(packetA), armnn::Exception);
2057 
2058  profilingState.TransitionToState(ProfilingState::WaitingForAck);
2059  BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::WaitingForAck);
2060  // command handler received packet on ProfilingState::WaitingForAck
2061  BOOST_CHECK_NO_THROW(commandHandler(packetA));
2062  BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::Active);
2063 
2064  // command handler received packet on ProfilingState::Active
2065  BOOST_CHECK_NO_THROW(commandHandler(packetA));
2066  BOOST_CHECK(profilingState.GetCurrentState() == ProfilingState::Active);
2067 
2068  // command handler received different packet
2069  const uint32_t differentPacketId = 0x40000;
2070  Packet packetB(differentPacketId, dataLength1, uniqueData1);
2071  profilingState.TransitionToState(ProfilingState::NotConnected);
2072  profilingState.TransitionToState(ProfilingState::WaitingForAck);
2073  ConnectionAcknowledgedCommandHandler differentCommandHandler(packetFamilyId, differentPacketId, version,
2074  counterDirectory, sendCounterPacket,
2075  sendTimelinePacket, profilingState);
2076  BOOST_CHECK_THROW(differentCommandHandler(packetB), armnn::Exception);
2077 }
void WriteUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint16_t value)
void WriteUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint32_t value)
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:33
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46

◆ BOOST_AUTO_TEST_CASE() [24/54]

BOOST_AUTO_TEST_CASE ( CheckSocketConnectionException  )

Definition at line 2079 of file ProfilingTests.cpp.

2080 {
2081  // Check that creating a SocketProfilingConnection armnnProfiling in an exception as the Gator UDS doesn't exist.
2082  BOOST_CHECK_THROW(new SocketProfilingConnection(), armnnProfiling::SocketConnectionException);
2083 }

◆ BOOST_AUTO_TEST_CASE() [25/54]

BOOST_AUTO_TEST_CASE ( CheckSocketConnectionException2  )

Definition at line 2085 of file ProfilingTests.cpp.

References BOOST_CHECK().

2086 {
2087  try
2088  {
2090  }
2091  catch (armnnProfiling::SocketConnectionException& ex)
2092  {
2093  BOOST_CHECK(ex.GetSocketFd() == 0);
2094  BOOST_CHECK(ex.GetErrorNo() == 111);
2095  BOOST_CHECK(ex.what()
2096  == std::string("SocketProfilingConnection: Cannot connect to stream socket: Connection refused"));
2097  }
2098 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)

◆ BOOST_AUTO_TEST_CASE() [26/54]

BOOST_AUTO_TEST_CASE ( SwTraceIsValidCharTest  )

Definition at line 2100 of file ProfilingTests.cpp.

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

2101 {
2102  // Only ASCII 7-bit encoding supported
2103  for (unsigned char c = 0; c < 128; c++)
2104  {
2105  BOOST_CHECK(SwTraceCharPolicy::IsValidChar(c));
2106  }
2107 
2108  // Not ASCII
2109  for (unsigned char c = 255; c >= 128; c++)
2110  {
2111  BOOST_CHECK(!SwTraceCharPolicy::IsValidChar(c));
2112  }
2113 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)

◆ BOOST_AUTO_TEST_CASE() [27/54]

BOOST_AUTO_TEST_CASE ( SwTraceIsValidNameCharTest  )

Definition at line 2115 of file ProfilingTests.cpp.

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

2116 {
2117  // Only alpha-numeric and underscore ASCII 7-bit encoding supported
2118  const unsigned char validChars[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_";
2119  for (unsigned char i = 0; i < sizeof(validChars) / sizeof(validChars[0]) - 1; i++)
2120  {
2121  BOOST_CHECK(SwTraceNameCharPolicy::IsValidChar(validChars[i]));
2122  }
2123 
2124  // Non alpha-numeric chars
2125  for (unsigned char c = 0; c < 48; c++)
2126  {
2127  BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c));
2128  }
2129  for (unsigned char c = 58; c < 65; c++)
2130  {
2131  BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c));
2132  }
2133  for (unsigned char c = 91; c < 95; c++)
2134  {
2135  BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c));
2136  }
2137  for (unsigned char c = 96; c < 97; c++)
2138  {
2139  BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c));
2140  }
2141  for (unsigned char c = 123; c < 128; c++)
2142  {
2143  BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c));
2144  }
2145 
2146  // Not ASCII
2147  for (unsigned char c = 255; c >= 128; c++)
2148  {
2149  BOOST_CHECK(!SwTraceNameCharPolicy::IsValidChar(c));
2150  }
2151 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)

◆ BOOST_AUTO_TEST_CASE() [28/54]

BOOST_AUTO_TEST_CASE ( IsValidSwTraceStringTest  )

Definition at line 2153 of file ProfilingTests.cpp.

References BOOST_CHECK().

2154 {
2155  // Valid SWTrace strings
2156  BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>(""));
2157  BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("_"));
2158  BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("0123"));
2159  BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("valid_string"));
2160  BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("VALID_string_456"));
2161  BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>(" "));
2162  BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("valid string"));
2163  BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("!$%"));
2164  BOOST_CHECK(IsValidSwTraceString<SwTraceCharPolicy>("valid|\\~string#123"));
2165 
2166  // Invalid SWTrace strings
2167  BOOST_CHECK(!IsValidSwTraceString<SwTraceCharPolicy>("€£"));
2168  BOOST_CHECK(!IsValidSwTraceString<SwTraceCharPolicy>("invalid‡string"));
2169  BOOST_CHECK(!IsValidSwTraceString<SwTraceCharPolicy>("12Ž34"));
2170 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)

◆ BOOST_AUTO_TEST_CASE() [29/54]

BOOST_AUTO_TEST_CASE ( IsValidSwTraceNameStringTest  )

Definition at line 2172 of file ProfilingTests.cpp.

References BOOST_CHECK().

2173 {
2174  // Valid SWTrace name strings
2175  BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>(""));
2176  BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("_"));
2177  BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("0123"));
2178  BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("valid_string"));
2179  BOOST_CHECK(IsValidSwTraceString<SwTraceNameCharPolicy>("VALID_string_456"));
2180 
2181  // Invalid SWTrace name strings
2182  BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>(" "));
2183  BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("invalid string"));
2184  BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("!$%"));
2185  BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("invalid|\\~string#123"));
2186  BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("€£"));
2187  BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("invalid‡string"));
2188  BOOST_CHECK(!IsValidSwTraceString<SwTraceNameCharPolicy>("12Ž34"));
2189 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)

◆ BOOST_AUTO_TEST_CASE() [30/54]

BOOST_AUTO_TEST_CASE ( StringToSwTraceStringTest  )

Definition at line 2214 of file ProfilingTests.cpp.

References BOOST_CHECK().

2215 {
2216  std::vector<uint32_t> buffer;
2217 
2218  // Valid SWTrace strings (expected size in words)
2219  StringToSwTraceStringTestHelper<SwTraceCharPolicy>("", buffer, 2);
2220  StringToSwTraceStringTestHelper<SwTraceCharPolicy>("_", buffer, 2);
2221  StringToSwTraceStringTestHelper<SwTraceCharPolicy>("0123", buffer, 3);
2222  StringToSwTraceStringTestHelper<SwTraceCharPolicy>("valid_string", buffer, 5);
2223  StringToSwTraceStringTestHelper<SwTraceCharPolicy>("VALID_string_456", buffer, 6);
2224  StringToSwTraceStringTestHelper<SwTraceCharPolicy>(" ", buffer, 2);
2225  StringToSwTraceStringTestHelper<SwTraceCharPolicy>("valid string", buffer, 5);
2226  StringToSwTraceStringTestHelper<SwTraceCharPolicy>("!$%", buffer, 2);
2227  StringToSwTraceStringTestHelper<SwTraceCharPolicy>("valid|\\~string#123", buffer, 6);
2228 
2229  // Invalid SWTrace strings
2230  BOOST_CHECK(!StringToSwTraceString<SwTraceCharPolicy>("€£", buffer));
2231  BOOST_CHECK(buffer.empty());
2232  BOOST_CHECK(!StringToSwTraceString<SwTraceCharPolicy>("invalid‡string", buffer));
2233  BOOST_CHECK(buffer.empty());
2234  BOOST_CHECK(!StringToSwTraceString<SwTraceCharPolicy>("12Ž34", buffer));
2235  BOOST_CHECK(buffer.empty());
2236 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)

◆ BOOST_AUTO_TEST_CASE() [31/54]

BOOST_AUTO_TEST_CASE ( StringToSwTraceNameStringTest  )

Definition at line 2238 of file ProfilingTests.cpp.

References BOOST_CHECK().

2239 {
2240  std::vector<uint32_t> buffer;
2241 
2242  // Valid SWTrace namestrings (expected size in words)
2243  StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("", buffer, 2);
2244  StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("_", buffer, 2);
2245  StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("0123", buffer, 3);
2246  StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("valid_string", buffer, 5);
2247  StringToSwTraceStringTestHelper<SwTraceNameCharPolicy>("VALID_string_456", buffer, 6);
2248 
2249  // Invalid SWTrace namestrings
2250  BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>(" ", buffer));
2251  BOOST_CHECK(buffer.empty());
2252  BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("invalid string", buffer));
2253  BOOST_CHECK(buffer.empty());
2254  BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("!$%", buffer));
2255  BOOST_CHECK(buffer.empty());
2256  BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("invalid|\\~string#123", buffer));
2257  BOOST_CHECK(buffer.empty());
2258  BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("€£", buffer));
2259  BOOST_CHECK(buffer.empty());
2260  BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("invalid‡string", buffer));
2261  BOOST_CHECK(buffer.empty());
2262  BOOST_CHECK(!StringToSwTraceString<SwTraceNameCharPolicy>("12Ž34", buffer));
2263  BOOST_CHECK(buffer.empty());
2264 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)

◆ BOOST_AUTO_TEST_CASE() [32/54]

BOOST_AUTO_TEST_CASE ( CheckPeriodicCounterCaptureThread  )

Definition at line 2266 of file ProfilingTests.cpp.

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

2267 {
2268  class CaptureReader : public IReadCounterValues
2269  {
2270  public:
2271  CaptureReader(uint16_t counterSize)
2272  {
2273  for (uint16_t i = 0; i < counterSize; ++i)
2274  {
2275  m_Data[i] = 0;
2276  }
2277  m_CounterSize = counterSize;
2278  }
2279  //not used
2280  bool IsCounterRegistered(uint16_t counterUid) const override
2281  {
2282  armnn::IgnoreUnused(counterUid);
2283  return false;
2284  }
2285 
2286  uint16_t GetCounterCount() const override
2287  {
2288  return m_CounterSize;
2289  }
2290 
2291  uint32_t GetAbsoluteCounterValue(uint16_t counterUid) const override
2292  {
2293  if (counterUid > m_CounterSize)
2294  {
2295  BOOST_FAIL("Invalid counter Uid");
2296  }
2297  return m_Data.at(counterUid).load();
2298  }
2299 
2300  uint32_t GetDeltaCounterValue(uint16_t counterUid) override
2301  {
2302  if (counterUid > m_CounterSize)
2303  {
2304  BOOST_FAIL("Invalid counter Uid");
2305  }
2306  return m_Data.at(counterUid).load();
2307  }
2308 
2309  void SetCounterValue(uint16_t counterUid, uint32_t value)
2310  {
2311  if (counterUid > m_CounterSize)
2312  {
2313  BOOST_FAIL("Invalid counter Uid");
2314  }
2315  m_Data.at(counterUid).store(value);
2316  }
2317 
2318  private:
2319  std::unordered_map<uint16_t, std::atomic<uint32_t>> m_Data;
2320  uint16_t m_CounterSize;
2321  };
2322 
2323  ProfilingStateMachine profilingStateMachine;
2324 
2325  const std::unordered_map<armnn::BackendId,
2326  std::shared_ptr<armnn::profiling::IBackendProfilingContext>> backendProfilingContext;
2327  CounterIdMap counterIdMap;
2328  Holder data;
2329  std::vector<uint16_t> captureIds1 = { 0, 1 };
2330  std::vector<uint16_t> captureIds2;
2331 
2332  MockBufferManager mockBuffer(512);
2333  SendCounterPacket sendCounterPacket(mockBuffer);
2334  SendThread sendThread(profilingStateMachine, mockBuffer, sendCounterPacket);
2335 
2336  std::vector<uint16_t> counterIds;
2337  CaptureReader captureReader(2);
2338 
2339  unsigned int valueA = 10;
2340  unsigned int valueB = 15;
2341  unsigned int numSteps = 5;
2342 
2343  PeriodicCounterCapture periodicCounterCapture(std::ref(data), std::ref(sendCounterPacket), captureReader,
2344  counterIdMap, backendProfilingContext);
2345 
2346  for (unsigned int i = 0; i < numSteps; ++i)
2347  {
2348  data.SetCaptureData(1, captureIds1, {});
2349  captureReader.SetCounterValue(0, valueA * (i + 1));
2350  captureReader.SetCounterValue(1, valueB * (i + 1));
2351 
2352  periodicCounterCapture.Start();
2353  periodicCounterCapture.Stop();
2354  }
2355 
2356  auto buffer = mockBuffer.GetReadableBuffer();
2357 
2358  uint32_t headerWord0 = ReadUint32(buffer, 0);
2359  uint32_t headerWord1 = ReadUint32(buffer, 4);
2360 
2361  BOOST_TEST(((headerWord0 >> 26) & 0x0000003F) == 3); // packet family
2362  BOOST_TEST(((headerWord0 >> 19) & 0x0000007F) == 0); // packet class
2363  BOOST_TEST(((headerWord0 >> 16) & 0x00000007) == 0); // packet type
2364  BOOST_TEST(headerWord1 == 20);
2365 
2366  uint32_t offset = 16;
2367  uint16_t readIndex = ReadUint16(buffer, offset);
2368  BOOST_TEST(0 == readIndex);
2369 
2370  offset += 2;
2371  uint32_t readValue = ReadUint32(buffer, offset);
2372  BOOST_TEST((valueA * numSteps) == readValue);
2373 
2374  offset += 4;
2375  readIndex = ReadUint16(buffer, offset);
2376  BOOST_TEST(1 == readIndex);
2377 
2378  offset += 2;
2379  readValue = ReadUint32(buffer, offset);
2380  BOOST_TEST((valueB * numSteps) == readValue);
2381 }
uint16_t ReadUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset)
void IgnoreUnused(Ts &&...)
virtual uint32_t GetAbsoluteCounterValue(uint16_t counterUid) const =0
void SetCaptureData(uint32_t capturePeriod, const std::vector< uint16_t > &counterIds, const std::set< armnn::BackendId > &activeBackends)
Definition: Holder.cpp:74
virtual uint32_t GetDeltaCounterValue(uint16_t counterUid)=0
virtual uint16_t GetCounterCount() const =0
virtual bool IsCounterRegistered(uint16_t counterUid) const =0
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)

◆ BOOST_AUTO_TEST_CASE() [33/54]

BOOST_AUTO_TEST_CASE ( RequestCounterDirectoryCommandHandlerTest1  )

Definition at line 2383 of file ProfilingTests.cpp.

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

2384 {
2385  using boost::numeric_cast;
2386 
2387  const uint32_t familyId = 0;
2388  const uint32_t packetId = 3;
2389  const uint32_t version = 1;
2390  ProfilingStateMachine profilingStateMachine;
2391  CounterDirectory counterDirectory;
2392  MockBufferManager mockBuffer1(1024);
2393  SendCounterPacket sendCounterPacket(mockBuffer1);
2394  SendThread sendThread(profilingStateMachine, mockBuffer1, sendCounterPacket);
2395  MockBufferManager mockBuffer2(1024);
2396  SendTimelinePacket sendTimelinePacket(mockBuffer2);
2397  RequestCounterDirectoryCommandHandler commandHandler(familyId, packetId, version, counterDirectory,
2398  sendCounterPacket, sendTimelinePacket, profilingStateMachine);
2399 
2400  const uint32_t wrongPacketId = 47;
2401  const uint32_t wrongHeader = (wrongPacketId & 0x000003FF) << 16;
2402 
2403  Packet wrongPacket(wrongHeader);
2404 
2405  profilingStateMachine.TransitionToState(ProfilingState::Uninitialised);
2406  BOOST_CHECK_THROW(commandHandler(wrongPacket), armnn::RuntimeException); // Wrong profiling state
2407  profilingStateMachine.TransitionToState(ProfilingState::NotConnected);
2408  BOOST_CHECK_THROW(commandHandler(wrongPacket), armnn::RuntimeException); // Wrong profiling state
2409  profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck);
2410  BOOST_CHECK_THROW(commandHandler(wrongPacket), armnn::RuntimeException); // Wrong profiling state
2411  profilingStateMachine.TransitionToState(ProfilingState::Active);
2412  BOOST_CHECK_THROW(commandHandler(wrongPacket), armnn::InvalidArgumentException); // Wrong packet
2413 
2414  const uint32_t rightHeader = (packetId & 0x000003FF) << 16;
2415 
2416  Packet rightPacket(rightHeader);
2417 
2418  BOOST_CHECK_NO_THROW(commandHandler(rightPacket)); // Right packet
2419 
2420  auto readBuffer1 = mockBuffer1.GetReadableBuffer();
2421 
2422  uint32_t header1Word0 = ReadUint32(readBuffer1, 0);
2423  uint32_t header1Word1 = ReadUint32(readBuffer1, 4);
2424 
2425  // Counter directory packet
2426  BOOST_TEST(((header1Word0 >> 26) & 0x0000003F) == 0); // packet family
2427  BOOST_TEST(((header1Word0 >> 16) & 0x000003FF) == 2); // packet id
2428  BOOST_TEST(header1Word1 == 24); // data length
2429 
2430  uint32_t bodyHeader1Word0 = ReadUint32(readBuffer1, 8);
2431  uint16_t deviceRecordCount = numeric_cast<uint16_t>(bodyHeader1Word0 >> 16);
2432  BOOST_TEST(deviceRecordCount == 0); // device_records_count
2433 
2434  auto readBuffer2 = mockBuffer2.GetReadableBuffer();
2435 
2436  uint32_t header2Word0 = ReadUint32(readBuffer2, 0);
2437  uint32_t header2Word1 = ReadUint32(readBuffer2, 4);
2438 
2439  // Timeline message directory packet
2440  BOOST_TEST(((header2Word0 >> 26) & 0x0000003F) == 1); // packet family
2441  BOOST_TEST(((header2Word0 >> 16) & 0x000003FF) == 0); // packet id
2442  BOOST_TEST(header2Word1 == 419); // data length
2443 }
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:33
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)
void TransitionToState(ProfilingState newState)

◆ BOOST_AUTO_TEST_CASE() [34/54]

BOOST_AUTO_TEST_CASE ( RequestCounterDirectoryCommandHandlerTest2  )

Definition at line 2445 of file ProfilingTests.cpp.

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

2446 {
2447  using boost::numeric_cast;
2448 
2449  const uint32_t familyId = 0;
2450  const uint32_t packetId = 3;
2451  const uint32_t version = 1;
2452  ProfilingStateMachine profilingStateMachine;
2453  CounterDirectory counterDirectory;
2454  MockBufferManager mockBuffer1(1024);
2455  SendCounterPacket sendCounterPacket(mockBuffer1);
2456  SendThread sendThread(profilingStateMachine, mockBuffer1, sendCounterPacket);
2457  MockBufferManager mockBuffer2(1024);
2458  SendTimelinePacket sendTimelinePacket(mockBuffer2);
2459  RequestCounterDirectoryCommandHandler commandHandler(familyId, packetId, version, counterDirectory,
2460  sendCounterPacket, sendTimelinePacket, profilingStateMachine);
2461  const uint32_t header = (packetId & 0x000003FF) << 16;
2462  const Packet packet(header);
2463 
2464  const Device* device = counterDirectory.RegisterDevice("deviceA", 1);
2465  BOOST_CHECK(device != nullptr);
2466  const CounterSet* counterSet = counterDirectory.RegisterCounterSet("countersetA");
2467  BOOST_CHECK(counterSet != nullptr);
2468  counterDirectory.RegisterCategory("categoryA");
2469  counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, 24,
2470  "categoryA", 0, 1, 2.0f, "counterA", "descA");
2471  counterDirectory.RegisterCounter(armnn::profiling::BACKEND_ID, 25,
2472  "categoryA", 1, 1, 3.0f, "counterB", "descB");
2473 
2474  profilingStateMachine.TransitionToState(ProfilingState::Uninitialised);
2475  BOOST_CHECK_THROW(commandHandler(packet), armnn::RuntimeException); // Wrong profiling state
2476  profilingStateMachine.TransitionToState(ProfilingState::NotConnected);
2477  BOOST_CHECK_THROW(commandHandler(packet), armnn::RuntimeException); // Wrong profiling state
2478  profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck);
2479  BOOST_CHECK_THROW(commandHandler(packet), armnn::RuntimeException); // Wrong profiling state
2480  profilingStateMachine.TransitionToState(ProfilingState::Active);
2481  BOOST_CHECK_NO_THROW(commandHandler(packet));
2482 
2483  auto readBuffer1 = mockBuffer1.GetReadableBuffer();
2484 
2485  const uint32_t header1Word0 = ReadUint32(readBuffer1, 0);
2486  const uint32_t header1Word1 = ReadUint32(readBuffer1, 4);
2487 
2488  BOOST_TEST(((header1Word0 >> 26) & 0x0000003F) == 0); // packet family
2489  BOOST_TEST(((header1Word0 >> 16) & 0x000003FF) == 2); // packet id
2490  BOOST_TEST(header1Word1 == 236); // data length
2491 
2492  const uint32_t bodyHeaderSizeBytes = bodyHeaderSize * sizeof(uint32_t);
2493 
2494  const uint32_t bodyHeader1Word0 = ReadUint32(readBuffer1, 8);
2495  const uint32_t bodyHeader1Word1 = ReadUint32(readBuffer1, 12);
2496  const uint32_t bodyHeader1Word2 = ReadUint32(readBuffer1, 16);
2497  const uint32_t bodyHeader1Word3 = ReadUint32(readBuffer1, 20);
2498  const uint32_t bodyHeader1Word4 = ReadUint32(readBuffer1, 24);
2499  const uint32_t bodyHeader1Word5 = ReadUint32(readBuffer1, 28);
2500  const uint16_t deviceRecordCount = numeric_cast<uint16_t>(bodyHeader1Word0 >> 16);
2501  const uint16_t counterSetRecordCount = numeric_cast<uint16_t>(bodyHeader1Word2 >> 16);
2502  const uint16_t categoryRecordCount = numeric_cast<uint16_t>(bodyHeader1Word4 >> 16);
2503  BOOST_TEST(deviceRecordCount == 1); // device_records_count
2504  BOOST_TEST(bodyHeader1Word1 == 0 + bodyHeaderSizeBytes); // device_records_pointer_table_offset
2505  BOOST_TEST(counterSetRecordCount == 1); // counter_set_count
2506  BOOST_TEST(bodyHeader1Word3 == 4 + bodyHeaderSizeBytes); // counter_set_pointer_table_offset
2507  BOOST_TEST(categoryRecordCount == 1); // categories_count
2508  BOOST_TEST(bodyHeader1Word5 == 8 + bodyHeaderSizeBytes); // categories_pointer_table_offset
2509 
2510  const uint32_t deviceRecordOffset = ReadUint32(readBuffer1, 32);
2511  BOOST_TEST(deviceRecordOffset == 12);
2512 
2513  const uint32_t counterSetRecordOffset = ReadUint32(readBuffer1, 36);
2514  BOOST_TEST(counterSetRecordOffset == 28);
2515 
2516  const uint32_t categoryRecordOffset = ReadUint32(readBuffer1, 40);
2517  BOOST_TEST(categoryRecordOffset == 48);
2518 
2519  auto readBuffer2 = mockBuffer2.GetReadableBuffer();
2520 
2521  const uint32_t header2Word0 = ReadUint32(readBuffer2, 0);
2522  const uint32_t header2Word1 = ReadUint32(readBuffer2, 4);
2523 
2524  // Timeline message directory packet
2525  BOOST_TEST(((header2Word0 >> 26) & 0x0000003F) == 1); // packet family
2526  BOOST_TEST(((header2Word0 >> 16) & 0x000003FF) == 0); // packet id
2527  BOOST_TEST(header2Word1 == 419); // data length
2528 }
const Category * RegisterCategory(const std::string &categoryName) 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
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:33
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)
const Device * RegisterDevice(const std::string &deviceName, uint16_t cores=0, const Optional< std::string > &parentCategoryName=EmptyOptional()) override
void TransitionToState(ProfilingState newState)
const CounterSet * RegisterCounterSet(const std::string &counterSetName, uint16_t count=0, const Optional< std::string > &parentCategoryName=EmptyOptional()) override

◆ BOOST_AUTO_TEST_CASE() [35/54]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceGoodConnectionAcknowledgedPacket  )

Definition at line 2530 of file ProfilingTests.cpp.

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

2531 {
2532  unsigned int streamMetadataPacketsize = GetStreamMetaDataPacketSize();
2533 
2534  // Reset the profiling service to the uninitialized state
2535  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2536  options.m_EnableProfiling = true;
2538  profilingService.ResetExternalProfilingOptions(options, true);
2539 
2540  // Swap the profiling connection factory in the profiling service instance with our mock one
2541  SwapProfilingConnectionFactoryHelper helper(profilingService);
2542 
2543  // Bring the profiling service to the "WaitingForAck" state
2544  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2545  profilingService.Update(); // Initialize the counter directory
2546  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2547  profilingService.Update(); // Create the profiling connection
2548 
2549  // Get the mock profiling connection
2550  MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
2551  BOOST_CHECK(mockProfilingConnection);
2552 
2553  // Remove the packets received so far
2554  mockProfilingConnection->Clear();
2555 
2556  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
2557  profilingService.Update(); // Start the command handler and the send thread
2558 
2559  // Wait for the Stream Metadata packet to be sent
2560  BOOST_CHECK(helper.WaitForPacketsSent(
2561  mockProfilingConnection, PacketType::StreamMetaData, streamMetadataPacketsize) >= 1);
2562 
2563  // Write a valid "Connection Acknowledged" packet into the mock profiling connection, to simulate a valid
2564  // reply from an external profiling service
2565 
2566  // Connection Acknowledged Packet header (word 0, word 1 is always zero):
2567  // 26:31 [6] packet_family: Control Packet Family, value 0b000000
2568  // 16:25 [10] packet_id: Packet identifier, value 0b0000000001
2569  // 8:15 [8] reserved: Reserved, value 0b00000000
2570  // 0:7 [8] reserved: Reserved, value 0b00000000
2571  uint32_t packetFamily = 0;
2572  uint32_t packetId = 1;
2573  uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2574 
2575  // Create the Connection Acknowledged Packet
2576  Packet connectionAcknowledgedPacket(header);
2577 
2578  // Write the packet to the mock profiling connection
2579  mockProfilingConnection->WritePacket(std::move(connectionAcknowledgedPacket));
2580 
2581  // Wait for the counter directory packet to ensure the ConnectionAcknowledgedCommandHandler has run.
2582  BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::CounterDirectory) == 1);
2583 
2584  // The Connection Acknowledged Command Handler should have updated the profiling state accordingly
2585  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2586 
2587  // Reset the profiling service to stop any running thread
2588  options.m_EnableProfiling = false;
2589  profilingService.ResetExternalProfilingOptions(options, true);
2590 }
ProfilingState GetCurrentState() const
uint32_t GetStreamMetaDataPacketSize()
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::profiling::ProfilingService profilingService
bool WritePacket(const unsigned char *buffer, uint32_t length) override
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
FileOnlyHelperService helper

◆ BOOST_AUTO_TEST_CASE() [36/54]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceGoodRequestCounterDirectoryPacket  )

Definition at line 2592 of file ProfilingTests.cpp.

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

2593 {
2594  // Reset the profiling service to the uninitialized state
2595  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2596  options.m_EnableProfiling = true;
2598  profilingService.ResetExternalProfilingOptions(options, true);
2599 
2600  // Swap the profiling connection factory in the profiling service instance with our mock one
2601  SwapProfilingConnectionFactoryHelper helper(profilingService);
2602 
2603  // Bring the profiling service to the "Active" state
2604  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2605  profilingService.Update(); // Initialize the counter directory
2606  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2607  profilingService.Update(); // Create the profiling connection
2608  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
2609  profilingService.Update(); // Start the command handler and the send thread
2610 
2611  // Get the mock profiling connection
2612  MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
2613  BOOST_CHECK(mockProfilingConnection);
2614 
2615  // Force the profiling service to the "Active" state
2616  helper.ForceTransitionToState(ProfilingState::Active);
2617  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2618 
2619  // Write a valid "Request Counter Directory" packet into the mock profiling connection, to simulate a valid
2620  // reply from an external profiling service
2621 
2622  // Request Counter Directory packet header (word 0, word 1 is always zero):
2623  // 26:31 [6] packet_family: Control Packet Family, value 0b000000
2624  // 16:25 [10] packet_id: Packet identifier, value 0b0000000011
2625  // 8:15 [8] reserved: Reserved, value 0b00000000
2626  // 0:7 [8] reserved: Reserved, value 0b00000000
2627  uint32_t packetFamily = 0;
2628  uint32_t packetId = 3;
2629  uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2630 
2631  // Create the Request Counter Directory packet
2632  Packet requestCounterDirectoryPacket(header);
2633 
2634  // Write the packet to the mock profiling connection
2635  mockProfilingConnection->WritePacket(std::move(requestCounterDirectoryPacket));
2636 
2637  // Expecting one CounterDirectory Packet of length 652
2638  // and one TimelineMessageDirectory packet of length 427
2639  BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::CounterDirectory, 652) == 1);
2640  BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::TimelineMessageDirectory, 427) == 1);
2641 
2642  // The Request Counter Directory Command Handler should not have updated the profiling state
2643  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2644 
2645  // Reset the profiling service to stop any running thread
2646  options.m_EnableProfiling = false;
2647  profilingService.ResetExternalProfilingOptions(options, true);
2648 }
ProfilingState GetCurrentState() const
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::profiling::ProfilingService profilingService
bool WritePacket(const unsigned char *buffer, uint32_t length) override
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
FileOnlyHelperService helper

◆ BOOST_AUTO_TEST_CASE() [37/54]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceBadPeriodicCounterSelectionPacketInvalidCounterUid  )

Definition at line 2650 of file ProfilingTests.cpp.

References armnn::profiling::Active, BOOST_CHECK(), MockProfilingConnection::Clear(), SwapProfilingConnectionFactoryHelper::ForceTransitionToState(), ProfilingService::GetCounterDirectory(), ICounterDirectory::GetCounters(), ProfilingService::GetCurrentState(), SwapProfilingConnectionFactoryHelper::GetMockProfilingConnection(), helper, 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().

2651 {
2652  // Reset the profiling service to the uninitialized state
2653  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2654  options.m_EnableProfiling = true;
2656  profilingService.ResetExternalProfilingOptions(options, true);
2657 
2658  // Swap the profiling connection factory in the profiling service instance with our mock one
2659  SwapProfilingConnectionFactoryHelper helper(profilingService);
2660 
2661  // Bring the profiling service to the "Active" state
2662  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2663  profilingService.Update(); // Initialize the counter directory
2664  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2665  profilingService.Update(); // Create the profiling connection
2666  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
2667  profilingService.Update(); // Start the command handler and the send thread
2668 
2669  // Get the mock profiling connection
2670  MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
2671  BOOST_CHECK(mockProfilingConnection);
2672 
2673  // Force the profiling service to the "Active" state
2674  helper.ForceTransitionToState(ProfilingState::Active);
2675  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2676 
2677  // Remove the packets received so far
2678  mockProfilingConnection->Clear();
2679 
2680  // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an
2681  // external profiling service
2682 
2683  // Periodic Counter Selection packet header:
2684  // 26:31 [6] packet_family: Control Packet Family, value 0b000000
2685  // 16:25 [10] packet_id: Packet identifier, value 0b0000000100
2686  // 8:15 [8] reserved: Reserved, value 0b00000000
2687  // 0:7 [8] reserved: Reserved, value 0b00000000
2688  uint32_t packetFamily = 0;
2689  uint32_t packetId = 4;
2690  uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2691 
2692  uint32_t capturePeriod = 123456; // Some capture period (microseconds)
2693 
2694  // Get the first valid counter UID
2695  const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory();
2696  const Counters& counters = counterDirectory.GetCounters();
2697  BOOST_CHECK(counters.size() > 1);
2698  uint16_t counterUidA = counters.begin()->first; // First valid counter UID
2699  uint16_t counterUidB = 9999; // Second invalid counter UID
2700 
2701  uint32_t length = 8;
2702 
2703  auto data = std::make_unique<unsigned char[]>(length);
2704  WriteUint32(data.get(), 0, capturePeriod);
2705  WriteUint16(data.get(), 4, counterUidA);
2706  WriteUint16(data.get(), 6, counterUidB);
2707 
2708  // Create the Periodic Counter Selection packet
2709  Packet periodicCounterSelectionPacket(header, length, data); // Length > 0, this will start the Period Counter
2710  // Capture thread
2711 
2712  // Write the packet to the mock profiling connection
2713  mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket));
2714 
2715  // Expecting one Periodic Counter Selection packet of length 14
2716  // and at least one Periodic Counter Capture packet of length 22
2717  BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 14) == 1);
2718  BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 22) >= 1);
2719 
2720  // The Periodic Counter Selection Handler should not have updated the profiling state
2721  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2722 
2723  // Reset the profiling service to stop any running thread
2724  options.m_EnableProfiling = false;
2725  profilingService.ResetExternalProfilingOptions(options, true);
2726 }
ProfilingState GetCurrentState() const
void WriteUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint16_t value)
void WriteUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint32_t value)
std::unordered_map< uint16_t, CounterPtr > Counters
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::profiling::ProfilingService profilingService
bool WritePacket(const unsigned char *buffer, uint32_t length) override
virtual const Counters & GetCounters() const =0
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
const ICounterDirectory & GetCounterDirectory() const
FileOnlyHelperService helper

◆ BOOST_AUTO_TEST_CASE() [38/54]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceGoodPeriodicCounterSelectionPacketNoCounters  )

Definition at line 2728 of file ProfilingTests.cpp.

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

2729 {
2730  // Reset the profiling service to the uninitialized state
2731  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2732  options.m_EnableProfiling = true;
2734  profilingService.ResetExternalProfilingOptions(options, true);
2735 
2736  // Swap the profiling connection factory in the profiling service instance with our mock one
2737  SwapProfilingConnectionFactoryHelper helper(profilingService);
2738 
2739  // Bring the profiling service to the "Active" state
2740  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2741  profilingService.Update(); // Initialize the counter directory
2742  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2743  profilingService.Update(); // Create the profiling connection
2744  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
2745  profilingService.Update(); // Start the command handler and the send thread
2746 
2747  // Get the mock profiling connection
2748  MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
2749  BOOST_CHECK(mockProfilingConnection);
2750 
2751  // Wait for the Stream Metadata packet the be sent
2752  // (we are not testing the connection acknowledgement here so it will be ignored by this test)
2753  helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
2754 
2755  // Force the profiling service to the "Active" state
2756  helper.ForceTransitionToState(ProfilingState::Active);
2757  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2758 
2759  // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an
2760  // external profiling service
2761 
2762  // Periodic Counter Selection packet header:
2763  // 26:31 [6] packet_family: Control Packet Family, value 0b000000
2764  // 16:25 [10] packet_id: Packet identifier, value 0b0000000100
2765  // 8:15 [8] reserved: Reserved, value 0b00000000
2766  // 0:7 [8] reserved: Reserved, value 0b00000000
2767  uint32_t packetFamily = 0;
2768  uint32_t packetId = 4;
2769  uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2770 
2771  // Create the Periodic Counter Selection packet
2772  Packet periodicCounterSelectionPacket(header); // Length == 0, this will disable the collection of counters
2773 
2774  // Write the packet to the mock profiling connection
2775  mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket));
2776 
2777  // Wait for the Periodic Counter Selection packet of length 12 to be sent
2778  // The size of the expected Periodic Counter Selection (echos the sent one)
2779  BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 12) == 1);
2780 
2781  // The Periodic Counter Selection Handler should not have updated the profiling state
2782  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2783 
2784  // No Periodic Counter packets are expected
2785  BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 0, 0) == 0);
2786 
2787  // Reset the profiling service to stop any running thread
2788  options.m_EnableProfiling = false;
2789  profilingService.ResetExternalProfilingOptions(options, true);
2790 }
ProfilingState GetCurrentState() const
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::profiling::ProfilingService profilingService
bool WritePacket(const unsigned char *buffer, uint32_t length) override
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
FileOnlyHelperService helper

◆ BOOST_AUTO_TEST_CASE() [39/54]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceGoodPeriodicCounterSelectionPacketSingleCounter  )

Definition at line 2792 of file ProfilingTests.cpp.

References armnn::profiling::Active, BOOST_CHECK(), SwapProfilingConnectionFactoryHelper::ForceTransitionToState(), ProfilingService::GetCounterDirectory(), ICounterDirectory::GetCounters(), ProfilingService::GetCurrentState(), SwapProfilingConnectionFactoryHelper::GetMockProfilingConnection(), helper, 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().

2793 {
2794  // Reset the profiling service to the uninitialized state
2795  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2796  options.m_EnableProfiling = true;
2798  profilingService.ResetExternalProfilingOptions(options, true);
2799 
2800  // Swap the profiling connection factory in the profiling service instance with our mock one
2801  SwapProfilingConnectionFactoryHelper helper(profilingService);
2802 
2803  // Bring the profiling service to the "Active" state
2804  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2805  profilingService.Update(); // Initialize the counter directory
2806  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2807  profilingService.Update(); // Create the profiling connection
2808  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
2809  profilingService.Update(); // Start the command handler and the send thread
2810 
2811  // Get the mock profiling connection
2812  MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
2813  BOOST_CHECK(mockProfilingConnection);
2814 
2815  // Wait for the Stream Metadata packet to be sent
2816  // (we are not testing the connection acknowledgement here so it will be ignored by this test)
2817  helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
2818 
2819  // Force the profiling service to the "Active" state
2820  helper.ForceTransitionToState(ProfilingState::Active);
2821  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2822 
2823  // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an
2824  // external profiling service
2825 
2826  // Periodic Counter Selection packet header:
2827  // 26:31 [6] packet_family: Control Packet Family, value 0b000000
2828  // 16:25 [10] packet_id: Packet identifier, value 0b0000000100
2829  // 8:15 [8] reserved: Reserved, value 0b00000000
2830  // 0:7 [8] reserved: Reserved, value 0b00000000
2831  uint32_t packetFamily = 0;
2832  uint32_t packetId = 4;
2833  uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2834 
2835  uint32_t capturePeriod = 123456; // Some capture period (microseconds)
2836 
2837  // Get the first valid counter UID
2838  const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory();
2839  const Counters& counters = counterDirectory.GetCounters();
2840  BOOST_CHECK(!counters.empty());
2841  uint16_t counterUid = counters.begin()->first; // Valid counter UID
2842 
2843  uint32_t length = 6;
2844 
2845  auto data = std::make_unique<unsigned char[]>(length);
2846  WriteUint32(data.get(), 0, capturePeriod);
2847  WriteUint16(data.get(), 4, counterUid);
2848 
2849  // Create the Periodic Counter Selection packet
2850  Packet periodicCounterSelectionPacket(header, length, data); // Length > 0, this will start the Period Counter
2851  // Capture thread
2852 
2853  // Write the packet to the mock profiling connection
2854  mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket));
2855 
2856  // Expecting one Periodic Counter Selection packet of length 14
2857  // and at least one Periodic Counter Capture packet of length 22
2858  BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 14) == 1);
2859  BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 22) >= 1);
2860 
2861  // The Periodic Counter Selection Handler should not have updated the profiling state
2862  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2863 
2864  // Reset the profiling service to stop any running thread
2865  options.m_EnableProfiling = false;
2866  profilingService.ResetExternalProfilingOptions(options, true);
2867 }
ProfilingState GetCurrentState() const
void WriteUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint16_t value)
void WriteUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint32_t value)
std::unordered_map< uint16_t, CounterPtr > Counters
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::profiling::ProfilingService profilingService
bool WritePacket(const unsigned char *buffer, uint32_t length) override
virtual const Counters & GetCounters() const =0
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
const ICounterDirectory & GetCounterDirectory() const
FileOnlyHelperService helper

◆ BOOST_AUTO_TEST_CASE() [40/54]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceGoodPeriodicCounterSelectionPacketMultipleCounters  )

Definition at line 2869 of file ProfilingTests.cpp.

References armnn::profiling::Active, BOOST_CHECK(), SwapProfilingConnectionFactoryHelper::ForceTransitionToState(), ProfilingService::GetCounterDirectory(), ICounterDirectory::GetCounters(), ProfilingService::GetCurrentState(), SwapProfilingConnectionFactoryHelper::GetMockProfilingConnection(), helper, 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().

2870 {
2871  // Reset the profiling service to the uninitialized state
2872  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2873  options.m_EnableProfiling = true;
2875  profilingService.ResetExternalProfilingOptions(options, true);
2876 
2877  // Swap the profiling connection factory in the profiling service instance with our mock one
2878  SwapProfilingConnectionFactoryHelper helper(profilingService);
2879 
2880  // Bring the profiling service to the "Active" state
2881  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2882  profilingService.Update(); // Initialize the counter directory
2883  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2884  profilingService.Update(); // Create the profiling connection
2885  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
2886  profilingService.Update(); // Start the command handler and the send thread
2887 
2888  // Get the mock profiling connection
2889  MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
2890  BOOST_CHECK(mockProfilingConnection);
2891 
2892  // Wait for the Stream Metadata packet the be sent
2893  // (we are not testing the connection acknowledgement here so it will be ignored by this test)
2894  helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
2895 
2896  // Force the profiling service to the "Active" state
2897  helper.ForceTransitionToState(ProfilingState::Active);
2898  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2899 
2900  // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an
2901  // external profiling service
2902 
2903  // Periodic Counter Selection packet header:
2904  // 26:31 [6] packet_family: Control Packet Family, value 0b000000
2905  // 16:25 [10] packet_id: Packet identifier, value 0b0000000100
2906  // 8:15 [8] reserved: Reserved, value 0b00000000
2907  // 0:7 [8] reserved: Reserved, value 0b00000000
2908  uint32_t packetFamily = 0;
2909  uint32_t packetId = 4;
2910  uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
2911 
2912  uint32_t capturePeriod = 123456; // Some capture period (microseconds)
2913 
2914  // Get the first valid counter UID
2915  const ICounterDirectory& counterDirectory = profilingService.GetCounterDirectory();
2916  const Counters& counters = counterDirectory.GetCounters();
2917  BOOST_CHECK(counters.size() > 1);
2918  uint16_t counterUidA = counters.begin()->first; // First valid counter UID
2919  uint16_t counterUidB = (counters.begin()++)->first; // Second valid counter UID
2920 
2921  uint32_t length = 8;
2922 
2923  auto data = std::make_unique<unsigned char[]>(length);
2924  WriteUint32(data.get(), 0, capturePeriod);
2925  WriteUint16(data.get(), 4, counterUidA);
2926  WriteUint16(data.get(), 6, counterUidB);
2927 
2928  // Create the Periodic Counter Selection packet
2929  Packet periodicCounterSelectionPacket(header, length, data); // Length > 0, this will start the Period Counter
2930  // Capture thread
2931 
2932  // Write the packet to the mock profiling connection
2933  mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket));
2934 
2935  // Expecting one PeriodicCounterSelection Packet with a length of 16
2936  // And at least one PeriodicCounterCapture Packet with a length of 28
2937  BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterSelection, 16) == 1);
2938  BOOST_CHECK(helper.WaitForPacketsSent(mockProfilingConnection, PacketType::PeriodicCounterCapture, 28) >= 1);
2939 
2940  // The Periodic Counter Selection Handler should not have updated the profiling state
2941  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2942 
2943  // Reset the profiling service to stop any running thread
2944  options.m_EnableProfiling = false;
2945  profilingService.ResetExternalProfilingOptions(options, true);
2946 }
ProfilingState GetCurrentState() const
void WriteUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint16_t value)
void WriteUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint32_t value)
std::unordered_map< uint16_t, CounterPtr > Counters
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::profiling::ProfilingService profilingService
bool WritePacket(const unsigned char *buffer, uint32_t length) override
virtual const Counters & GetCounters() const =0
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
const ICounterDirectory & GetCounterDirectory() const
FileOnlyHelperService helper

◆ BOOST_AUTO_TEST_CASE() [41/54]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceDisconnect  )

Definition at line 2948 of file ProfilingTests.cpp.

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

2949 {
2950  // Reset the profiling service to the uninitialized state
2951  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
2952  options.m_EnableProfiling = true;
2954  profilingService.ResetExternalProfilingOptions(options, true);
2955 
2956  // Swap the profiling connection factory in the profiling service instance with our mock one
2957  SwapProfilingConnectionFactoryHelper helper(profilingService);
2958 
2959  // Try to disconnect the profiling service while in the "Uninitialised" state
2960  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
2961  profilingService.Disconnect();
2962  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised); // The state should not change
2963 
2964  // Try to disconnect the profiling service while in the "NotConnected" state
2965  profilingService.Update(); // Initialize the counter directory
2966  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
2967  profilingService.Disconnect();
2968  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); // The state should not change
2969 
2970  // Try to disconnect the profiling service while in the "WaitingForAck" state
2971  profilingService.Update(); // Create the profiling connection
2972  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
2973  profilingService.Disconnect();
2974  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck); // The state should not change
2975 
2976  // Try to disconnect the profiling service while in the "Active" state
2977  profilingService.Update(); // Start the command handler and the send thread
2978 
2979  // Get the mock profiling connection
2980  MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
2981  BOOST_CHECK(mockProfilingConnection);
2982 
2983  // Wait for the Stream Metadata packet the be sent
2984  // (we are not testing the connection acknowledgement here so it will be ignored by this test)
2985  helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
2986 
2987  // Force the profiling service to the "Active" state
2988  helper.ForceTransitionToState(ProfilingState::Active);
2989  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
2990 
2991  // Check that the profiling connection is open
2992  BOOST_CHECK(mockProfilingConnection->IsOpen());
2993 
2994  profilingService.Disconnect();
2995  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected); // The state should have changed
2996 
2997  // Check that the profiling connection has been reset
2998  mockProfilingConnection = helper.GetMockProfilingConnection();
2999  BOOST_CHECK(mockProfilingConnection == nullptr);
3000 
3001  // Reset the profiling service to stop any running thread
3002  options.m_EnableProfiling = false;
3003  profilingService.ResetExternalProfilingOptions(options, true);
3004 }
ProfilingState GetCurrentState() const
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::profiling::ProfilingService profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
FileOnlyHelperService helper

◆ BOOST_AUTO_TEST_CASE() [42/54]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceGoodPerJobCounterSelectionPacket  )

Definition at line 3006 of file ProfilingTests.cpp.

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

3007 {
3008  // Reset the profiling service to the uninitialized state
3009  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3010  options.m_EnableProfiling = true;
3012  profilingService.ResetExternalProfilingOptions(options, true);
3013 
3014  // Swap the profiling connection factory in the profiling service instance with our mock one
3015  SwapProfilingConnectionFactoryHelper helper(profilingService);
3016 
3017  // Bring the profiling service to the "Active" state
3018  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3019  profilingService.Update(); // Initialize the counter directory
3020  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
3021  profilingService.Update(); // Create the profiling connection
3022  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
3023  profilingService.Update(); // Start the command handler and the send thread
3024 
3025  // Get the mock profiling connection
3026  MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
3027  BOOST_CHECK(mockProfilingConnection);
3028 
3029  // Wait for the Stream Metadata packet the be sent
3030  // (we are not testing the connection acknowledgement here so it will be ignored by this test)
3031  helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData);
3032 
3033  // Force the profiling service to the "Active" state
3034  helper.ForceTransitionToState(ProfilingState::Active);
3035  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
3036 
3037  // Write a "Per-Job Counter Selection" packet into the mock profiling connection, to simulate an input from an
3038  // external profiling service
3039 
3040  // Per-Job Counter Selection packet header:
3041  // 26:31 [6] packet_family: Control Packet Family, value 0b000000
3042  // 16:25 [10] packet_id: Packet identifier, value 0b0000000100
3043  // 8:15 [8] reserved: Reserved, value 0b00000000
3044  // 0:7 [8] reserved: Reserved, value 0b00000000
3045  uint32_t packetFamily = 0;
3046  uint32_t packetId = 5;
3047  uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3048 
3049  // Create the Per-Job Counter Selection packet
3050  Packet periodicCounterSelectionPacket(header); // Length == 0, this will disable the collection of counters
3051 
3052  // Write the packet to the mock profiling connection
3053  mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket));
3054 
3055  // Wait for a bit (must at least be the delay value of the mock profiling connection) to make sure that
3056  // the Per-Job Counter Selection packet gets processed by the profiling service
3057  std::this_thread::sleep_for(std::chrono::milliseconds(5));
3058 
3059  // The Per-Job Counter Selection Command Handler should not have updated the profiling state
3060  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Active);
3061 
3062  // The Per-Job Counter Selection packets are dropped silently, so there should be no reply coming
3063  // from the profiling service
3064  const auto StreamMetaDataSize = static_cast<unsigned long>(
3065  helper.WaitForPacketsSent(mockProfilingConnection, PacketType::StreamMetaData, 0, 0));
3066  BOOST_CHECK(StreamMetaDataSize == mockProfilingConnection->GetWrittenDataSize());
3067 
3068  // Reset the profiling service to stop any running thread
3069  options.m_EnableProfiling = false;
3070  profilingService.ResetExternalProfilingOptions(options, true);
3071 }
ProfilingState GetCurrentState() const
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::profiling::ProfilingService profilingService
bool WritePacket(const unsigned char *buffer, uint32_t length) override
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
FileOnlyHelperService helper

◆ BOOST_AUTO_TEST_CASE() [43/54]

BOOST_AUTO_TEST_CASE ( CheckConfigureProfilingServiceOn  )

Definition at line 3073 of file ProfilingTests.cpp.

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

3074 {
3075  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3076  options.m_EnableProfiling = true;
3078  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3079  profilingService.ConfigureProfilingService(options);
3080  // should get as far as NOT_CONNECTED
3081  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
3082  // Reset the profiling service to stop any running thread
3083  options.m_EnableProfiling = false;
3084  profilingService.ResetExternalProfilingOptions(options, true);
3085 }
ProfilingState GetCurrentState() const
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::profiling::ProfilingService profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
ProfilingState ConfigureProfilingService(const ExternalProfilingOptions &options, bool resetProfilingService=false)

◆ BOOST_AUTO_TEST_CASE() [44/54]

BOOST_AUTO_TEST_CASE ( CheckConfigureProfilingServiceOff  )

Definition at line 3087 of file ProfilingTests.cpp.

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

3088 {
3089  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3091  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3092  profilingService.ConfigureProfilingService(options);
3093  // should not move from Uninitialised
3094  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3095  // Reset the profiling service to stop any running thread
3096  options.m_EnableProfiling = false;
3097  profilingService.ResetExternalProfilingOptions(options, true);
3098 }
ProfilingState GetCurrentState() const
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::profiling::ProfilingService profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
ProfilingState ConfigureProfilingService(const ExternalProfilingOptions &options, bool resetProfilingService=false)

◆ BOOST_AUTO_TEST_CASE() [45/54]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceEnabled  )

Definition at line 3100 of file ProfilingTests.cpp.

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

3101 {
3102  // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
3104  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3105  options.m_EnableProfiling = true;
3107  profilingService.ResetExternalProfilingOptions(options, true);
3108  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3109  profilingService.Update();
3110  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
3111 
3112  // Redirect the output to a local stream so that we can parse the warning message
3113  std::stringstream ss;
3114  StreamRedirector streamRedirector(std::cout, ss.rdbuf());
3115  profilingService.Update();
3116 
3117  // Reset the profiling service to stop any running thread
3118  options.m_EnableProfiling = false;
3119  profilingService.ResetExternalProfilingOptions(options, true);
3120 
3121  streamRedirector.CancelRedirect();
3122 
3123  // Check that the expected error has occurred and logged to the standard output
3124  if (ss.str().find("Cannot connect to stream socket: Connection refused") == std::string::npos)
3125  {
3126  std::cout << ss.str();
3127  BOOST_FAIL("Expected string not found.");
3128  }
3129 }
ProfilingState GetCurrentState() const
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::profiling::ProfilingService profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [46/54]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceEnabledRuntime  )

Definition at line 3131 of file ProfilingTests.cpp.

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

3132 {
3133  // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
3135  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3137  profilingService.ResetExternalProfilingOptions(options, true);
3138  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3139  profilingService.Update();
3140  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3141  options.m_EnableProfiling = true;
3142  profilingService.ResetExternalProfilingOptions(options);
3143  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3144  profilingService.Update();
3145  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
3146 
3147  // Redirect the output to a local stream so that we can parse the warning message
3148  std::stringstream ss;
3149  StreamRedirector streamRedirector(std::cout, ss.rdbuf());
3150  profilingService.Update();
3151 
3152  // Reset the profiling service to stop any running thread
3153  options.m_EnableProfiling = false;
3154  profilingService.ResetExternalProfilingOptions(options, true);
3155 
3156  streamRedirector.CancelRedirect();
3157 
3158  // Check that the expected error has occurred and logged to the standard output
3159  if (ss.str().find("Cannot connect to stream socket: Connection refused") == std::string::npos)
3160  {
3161  std::cout << ss.str();
3162  BOOST_FAIL("Expected string not found.");
3163  }
3164 }
ProfilingState GetCurrentState() const
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::profiling::ProfilingService profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ BOOST_AUTO_TEST_CASE() [47/54]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceBadConnectionAcknowledgedPacket  )

Definition at line 3166 of file ProfilingTests.cpp.

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

3167 {
3168  // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
3170 
3171 
3172  // Redirect the standard output to a local stream so that we can parse the warning message
3173  std::stringstream ss;
3174  StreamRedirector streamRedirector(std::cout, ss.rdbuf());
3175 
3176  // Reset the profiling service to the uninitialized state
3177  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3178  options.m_EnableProfiling = true;
3180  profilingService.ResetExternalProfilingOptions(options, true);
3181 
3182  // Swap the profiling connection factory in the profiling service instance with our mock one
3183  SwapProfilingConnectionFactoryHelper helper(profilingService);
3184 
3185  // Bring the profiling service to the "WaitingForAck" state
3186  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3187  profilingService.Update(); // Initialize the counter directory
3188  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
3189  profilingService.Update(); // Create the profiling connection
3190 
3191  // Get the mock profiling connection
3192  MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
3193  BOOST_CHECK(mockProfilingConnection);
3194 
3195  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
3196 
3197  // Connection Acknowledged Packet header (word 0, word 1 is always zero):
3198  // 26:31 [6] packet_family: Control Packet Family, value 0b000000
3199  // 16:25 [10] packet_id: Packet identifier, value 0b0000000001
3200  // 8:15 [8] reserved: Reserved, value 0b00000000
3201  // 0:7 [8] reserved: Reserved, value 0b00000000
3202  uint32_t packetFamily = 0;
3203  uint32_t packetId = 37; // Wrong packet id!!!
3204  uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3205 
3206  // Create the Connection Acknowledged Packet
3207  Packet connectionAcknowledgedPacket(header);
3208  // Write an invalid "Connection Acknowledged" packet into the mock profiling connection, to simulate an invalid
3209  // reply from an external profiling service
3210  mockProfilingConnection->WritePacket(std::move(connectionAcknowledgedPacket));
3211 
3212  // Start the command thread
3213  profilingService.Update();
3214 
3215  // Wait for the command thread to join
3216  options.m_EnableProfiling = false;
3217  profilingService.ResetExternalProfilingOptions(options, true);
3218 
3219  streamRedirector.CancelRedirect();
3220 
3221  // Check that the expected error has occurred and logged to the standard output
3222  if (ss.str().find("Functor with requested PacketId=37 and Version=4194304 does not exist") == std::string::npos)
3223  {
3224  std::cout << ss.str();
3225  BOOST_FAIL("Expected string not found.");
3226  }
3227 }
ProfilingState GetCurrentState() const
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::profiling::ProfilingService profilingService
bool WritePacket(const unsigned char *buffer, uint32_t length) override
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
FileOnlyHelperService helper

◆ BOOST_AUTO_TEST_CASE() [48/54]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceBadRequestCounterDirectoryPacket  )

Definition at line 3229 of file ProfilingTests.cpp.

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

3230 {
3231  // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
3233 
3234  // Redirect the standard output to a local stream so that we can parse the warning message
3235  std::stringstream ss;
3236  StreamRedirector streamRedirector(std::cout, ss.rdbuf());
3237 
3238  // Reset the profiling service to the uninitialized state
3239  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3240  options.m_EnableProfiling = true;
3242  profilingService.ResetExternalProfilingOptions(options, true);
3243 
3244  // Swap the profiling connection factory in the profiling service instance with our mock one
3245  SwapProfilingConnectionFactoryHelper helper(profilingService);
3246 
3247  // Bring the profiling service to the "Active" state
3248  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3249  helper.ForceTransitionToState(ProfilingState::NotConnected);
3250  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
3251  profilingService.Update(); // Create the profiling connection
3252  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
3253 
3254  // Get the mock profiling connection
3255  MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
3256  BOOST_CHECK(mockProfilingConnection);
3257 
3258  // Write a valid "Request Counter Directory" packet into the mock profiling connection, to simulate a valid
3259  // reply from an external profiling service
3260 
3261  // Request Counter Directory packet header (word 0, word 1 is always zero):
3262  // 26:31 [6] packet_family: Control Packet Family, value 0b000000
3263  // 16:25 [10] packet_id: Packet identifier, value 0b0000000011
3264  // 8:15 [8] reserved: Reserved, value 0b00000000
3265  // 0:7 [8] reserved: Reserved, value 0b00000000
3266  uint32_t packetFamily = 0;
3267  uint32_t packetId = 123; // Wrong packet id!!!
3268  uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3269 
3270  // Create the Request Counter Directory packet
3271  Packet requestCounterDirectoryPacket(header);
3272 
3273  // Write the packet to the mock profiling connection
3274  mockProfilingConnection->WritePacket(std::move(requestCounterDirectoryPacket));
3275 
3276  // Start the command handler and the send thread
3277  profilingService.Update();
3278 
3279  // Reset the profiling service to stop and join any running thread
3280  options.m_EnableProfiling = false;
3281  profilingService.ResetExternalProfilingOptions(options, true);
3282 
3283  streamRedirector.CancelRedirect();
3284 
3285  // Check that the expected error has occurred and logged to the standard output
3286  if (ss.str().find("Functor with requested PacketId=123 and Version=4194304 does not exist") == std::string::npos)
3287  {
3288  std::cout << ss.str();
3289  BOOST_FAIL("Expected string not found.");
3290  }
3291 }
ProfilingState GetCurrentState() const
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::profiling::ProfilingService profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
FileOnlyHelperService helper

◆ BOOST_AUTO_TEST_CASE() [49/54]

BOOST_AUTO_TEST_CASE ( CheckProfilingServiceBadPeriodicCounterSelectionPacket  )

Definition at line 3293 of file ProfilingTests.cpp.

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

3294 {
3295  // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
3297 
3298  // Redirect the standard output to a local stream so that we can parse the warning message
3299  std::stringstream ss;
3300  StreamRedirector streamRedirector(std::cout, ss.rdbuf());
3301 
3302  // Reset the profiling service to the uninitialized state
3303  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3304  options.m_EnableProfiling = true;
3306  profilingService.ResetExternalProfilingOptions(options, true);
3307 
3308  // Swap the profiling connection factory in the profiling service instance with our mock one
3309  SwapProfilingConnectionFactoryHelper helper(profilingService);
3310 
3311  // Bring the profiling service to the "Active" state
3312  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::Uninitialised);
3313  profilingService.Update(); // Initialize the counter directory
3314  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::NotConnected);
3315  profilingService.Update(); // Create the profiling connection
3316  BOOST_CHECK(profilingService.GetCurrentState() == ProfilingState::WaitingForAck);
3317  profilingService.Update(); // Start the command handler and the send thread
3318 
3319  // Get the mock profiling connection
3320  MockProfilingConnection* mockProfilingConnection = helper.GetMockProfilingConnection();
3321  BOOST_CHECK(mockProfilingConnection);
3322 
3323  // Write a "Periodic Counter Selection" packet into the mock profiling connection, to simulate an input from an
3324  // external profiling service
3325 
3326  // Periodic Counter Selection packet header:
3327  // 26:31 [6] packet_family: Control Packet Family, value 0b000000
3328  // 16:25 [10] packet_id: Packet identifier, value 0b0000000100
3329  // 8:15 [8] reserved: Reserved, value 0b00000000
3330  // 0:7 [8] reserved: Reserved, value 0b00000000
3331  uint32_t packetFamily = 0;
3332  uint32_t packetId = 999; // Wrong packet id!!!
3333  uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
3334 
3335  // Create the Periodic Counter Selection packet
3336  Packet periodicCounterSelectionPacket(header); // Length == 0, this will disable the collection of counters
3337 
3338  // Write the packet to the mock profiling connection
3339  mockProfilingConnection->WritePacket(std::move(periodicCounterSelectionPacket));
3340  profilingService.Update();
3341 
3342  // Reset the profiling service to stop any running thread
3343  options.m_EnableProfiling = false;
3344  profilingService.ResetExternalProfilingOptions(options, true);
3345 
3346  // Check that the expected error has occurred and logged to the standard output
3347  streamRedirector.CancelRedirect();
3348 
3349  // Check that the expected error has occurred and logged to the standard output
3350  if (ss.str().find("Functor with requested PacketId=999 and Version=4194304 does not exist") == std::string::npos)
3351  {
3352  std::cout << ss.str();
3353  BOOST_FAIL("Expected string not found.");
3354  }
3355 }
ProfilingState GetCurrentState() const
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::profiling::ProfilingService profilingService
bool WritePacket(const unsigned char *buffer, uint32_t length) override
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
FileOnlyHelperService helper

◆ BOOST_AUTO_TEST_CASE() [50/54]

BOOST_AUTO_TEST_CASE ( CheckCounterIdMap  )

Definition at line 3357 of file ProfilingTests.cpp.

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

3358 {
3359  CounterIdMap counterIdMap;
3360  BOOST_CHECK_THROW(counterIdMap.GetBackendId(0), armnn::Exception);
3361  BOOST_CHECK_THROW(counterIdMap.GetGlobalId(0, armnn::profiling::BACKEND_ID), armnn::Exception);
3362 
3363  uint16_t globalCounterIds = 0;
3364 
3367 
3368  std::vector<uint16_t> cpuRefCounters = {0, 1, 2, 3};
3369  std::vector<uint16_t> cpuAccCounters = {0, 1};
3370 
3371  for (uint16_t backendCounterId : cpuRefCounters)
3372  {
3373  counterIdMap.RegisterMapping(globalCounterIds, backendCounterId, cpuRefId);
3374  ++globalCounterIds;
3375  }
3376  for (uint16_t backendCounterId : cpuAccCounters)
3377  {
3378  counterIdMap.RegisterMapping(globalCounterIds, backendCounterId, cpuAccId);
3379  ++globalCounterIds;
3380  }
3381 
3382  BOOST_CHECK(counterIdMap.GetBackendId(0) == (std::pair<uint16_t, armnn::BackendId>(0, cpuRefId)));
3383  BOOST_CHECK(counterIdMap.GetBackendId(1) == (std::pair<uint16_t, armnn::BackendId>(1, cpuRefId)));
3384  BOOST_CHECK(counterIdMap.GetBackendId(2) == (std::pair<uint16_t, armnn::BackendId>(2, cpuRefId)));
3385  BOOST_CHECK(counterIdMap.GetBackendId(3) == (std::pair<uint16_t, armnn::BackendId>(3, cpuRefId)));
3386  BOOST_CHECK(counterIdMap.GetBackendId(4) == (std::pair<uint16_t, armnn::BackendId>(0, cpuAccId)));
3387  BOOST_CHECK(counterIdMap.GetBackendId(5) == (std::pair<uint16_t, armnn::BackendId>(1, cpuAccId)));
3388 
3389  BOOST_CHECK(counterIdMap.GetGlobalId(0, cpuRefId) == 0);
3390  BOOST_CHECK(counterIdMap.GetGlobalId(1, cpuRefId) == 1);
3391  BOOST_CHECK(counterIdMap.GetGlobalId(2, cpuRefId) == 2);
3392  BOOST_CHECK(counterIdMap.GetGlobalId(3, cpuRefId) == 3);
3393  BOOST_CHECK(counterIdMap.GetGlobalId(0, cpuAccId) == 4);
3394  BOOST_CHECK(counterIdMap.GetGlobalId(1, cpuAccId) == 5);
3395 }
uint16_t GetGlobalId(uint16_t backendCounterId, const armnn::BackendId &backendId) const override
CPU Execution: Reference C++ kernels.
void RegisterMapping(uint16_t globalCounterId, uint16_t backendCounterId, const armnn::BackendId &backendId) override
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
const std::pair< uint16_t, armnn::BackendId > & GetBackendId(uint16_t globalCounterId) const override
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
CPU Execution: NEON: ArmCompute.

◆ BOOST_AUTO_TEST_CASE() [51/54]

BOOST_AUTO_TEST_CASE ( CheckRegisterBackendCounters  )

Definition at line 3397 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(), options, profilingService, RegisterBackendCounters::RegisterCategory(), RegisterBackendCounters::RegisterCounter(), RegisterBackendCounters::RegisterCounterSet(), RegisterBackendCounters::RegisterDevice(), and ProfilingService::ResetExternalProfilingOptions().

3398 {
3399  uint16_t globalCounterIds = armnn::profiling::INFERENCES_RUN;
3401 
3402  // Reset the profiling service to the uninitialized state
3403  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3404  options.m_EnableProfiling = true;
3406  profilingService.ResetExternalProfilingOptions(options, true);
3407 
3408  RegisterBackendCounters registerBackendCounters(globalCounterIds, cpuRefId, profilingService);
3409 
3410 
3411 
3412  BOOST_CHECK(profilingService.GetCounterDirectory().GetCategories().empty());
3413  registerBackendCounters.RegisterCategory("categoryOne");
3414  auto categoryOnePtr = profilingService.GetCounterDirectory().GetCategory("categoryOne");
3415  BOOST_CHECK(categoryOnePtr);
3416 
3417  BOOST_CHECK(profilingService.GetCounterDirectory().GetDevices().empty());
3418  globalCounterIds = registerBackendCounters.RegisterDevice("deviceOne");
3419  auto deviceOnePtr = profilingService.GetCounterDirectory().GetDevice(globalCounterIds);
3420  BOOST_CHECK(deviceOnePtr);
3421  BOOST_CHECK(deviceOnePtr->m_Name == "deviceOne");
3422 
3423  BOOST_CHECK(profilingService.GetCounterDirectory().GetCounterSets().empty());
3424  globalCounterIds = registerBackendCounters.RegisterCounterSet("counterSetOne");
3425  auto counterSetOnePtr = profilingService.GetCounterDirectory().GetCounterSet(globalCounterIds);
3426  BOOST_CHECK(counterSetOnePtr);
3427  BOOST_CHECK(counterSetOnePtr->m_Name == "counterSetOne");
3428 
3429  uint16_t newGlobalCounterId = registerBackendCounters.RegisterCounter(0,
3430  "categoryOne",
3431  0,
3432  0,
3433  1.f,
3434  "CounterOne",
3435  "first test counter");
3436  BOOST_CHECK(newGlobalCounterId = armnn::profiling::INFERENCES_RUN + 1);
3437  uint16_t mappedGlobalId = profilingService.GetCounterMappings().GetGlobalId(0, cpuRefId);
3438  BOOST_CHECK(mappedGlobalId == newGlobalCounterId);
3439  auto backendMapping = profilingService.GetCounterMappings().GetBackendId(newGlobalCounterId);
3440  BOOST_CHECK(backendMapping.first == 0);
3441  BOOST_CHECK(backendMapping.second == cpuRefId);
3442 
3443  // Reset the profiling service to stop any running thread
3444  options.m_EnableProfiling = false;
3445  profilingService.ResetExternalProfilingOptions(options, true);
3446 }
CPU Execution: Reference C++ kernels.
virtual const Category * GetCategory(const std::string &name) const =0
virtual const Device * GetDevice(uint16_t uid) const =0
virtual const CounterSets & GetCounterSets() const =0
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
virtual const Categories & GetCategories() const =0
virtual const Devices & GetDevices() const =0
virtual const CounterSet * GetCounterSet(uint16_t uid) const =0
const ICounterMappings & GetCounterMappings() const override
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::profiling::ProfilingService profilingService
virtual const std::pair< uint16_t, armnn::BackendId > & GetBackendId(uint16_t globalCounterId) const =0
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
const ICounterDirectory & GetCounterDirectory() const
virtual uint16_t GetGlobalId(uint16_t backendCounterId, const armnn::BackendId &backendId) const =0

◆ BOOST_AUTO_TEST_CASE() [52/54]

BOOST_AUTO_TEST_CASE ( CheckCounterStatusQuery  )

Definition at line 3448 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(), 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().

3449 {
3451  options.m_ProfilingOptions.m_EnableProfiling = true;
3452 
3453  // Reset the profiling service to the uninitialized state
3455  profilingService.ResetExternalProfilingOptions(options.m_ProfilingOptions, true);
3456 
3457  const armnn::BackendId cpuRefId(armnn::Compute::CpuRef);
3458  const armnn::BackendId cpuAccId(armnn::Compute::CpuAcc);
3459 
3460  // Create BackendProfiling for each backend
3461  BackendProfiling backendProfilingCpuRef(options, profilingService, cpuRefId);
3462  BackendProfiling backendProfilingCpuAcc(options, profilingService, cpuAccId);
3463 
3464  uint16_t initialNumGlobalCounterIds = armnn::profiling::INFERENCES_RUN;
3465 
3466  // Create RegisterBackendCounters for CpuRef
3467  RegisterBackendCounters registerBackendCountersCpuRef(initialNumGlobalCounterIds, cpuRefId, profilingService);
3468 
3469  // Create 'testCategory' in CounterDirectory (backend agnostic)
3470  BOOST_CHECK(profilingService.GetCounterDirectory().GetCategories().empty());
3471  registerBackendCountersCpuRef.RegisterCategory("testCategory");
3472  auto categoryOnePtr = profilingService.GetCounterDirectory().GetCategory("testCategory");
3473  BOOST_CHECK(categoryOnePtr);
3474 
3475  // Counters:
3476  // Global | Local | Backend
3477  // 5 | 0 | CpuRef
3478  // 6 | 1 | CpuRef
3479  // 7 | 1 | CpuAcc
3480 
3481  std::vector<uint16_t> cpuRefCounters = {0, 1};
3482  std::vector<uint16_t> cpuAccCounters = {0};
3483 
3484  // Register the backend counters for CpuRef and validate GetGlobalId and GetBackendId
3485  uint16_t currentNumGlobalCounterIds = registerBackendCountersCpuRef.RegisterCounter(
3486  0, "testCategory", 0, 0, 1.f, "CpuRefCounter0", "Zeroth CpuRef Counter");
3487  BOOST_CHECK(currentNumGlobalCounterIds == initialNumGlobalCounterIds + 1);
3488  uint16_t mappedGlobalId = profilingService.GetCounterMappings().GetGlobalId(0, cpuRefId);
3489  BOOST_CHECK(mappedGlobalId == currentNumGlobalCounterIds);
3490  auto backendMapping = profilingService.GetCounterMappings().GetBackendId(currentNumGlobalCounterIds);
3491  BOOST_CHECK(backendMapping.first == 0);
3492  BOOST_CHECK(backendMapping.second == cpuRefId);
3493 
3494  currentNumGlobalCounterIds = registerBackendCountersCpuRef.RegisterCounter(
3495  1, "testCategory", 0, 0, 1.f, "CpuRefCounter1", "First CpuRef Counter");
3496  BOOST_CHECK(currentNumGlobalCounterIds == initialNumGlobalCounterIds + 2);
3497  mappedGlobalId = profilingService.GetCounterMappings().GetGlobalId(1, cpuRefId);
3498  BOOST_CHECK(mappedGlobalId == currentNumGlobalCounterIds);
3499  backendMapping = profilingService.GetCounterMappings().GetBackendId(currentNumGlobalCounterIds);
3500  BOOST_CHECK(backendMapping.first == 1);
3501  BOOST_CHECK(backendMapping.second == cpuRefId);
3502 
3503  // Create RegisterBackendCounters for CpuAcc
3504  RegisterBackendCounters registerBackendCountersCpuAcc(currentNumGlobalCounterIds, cpuAccId, profilingService);
3505 
3506  // Register the backend counter for CpuAcc and validate GetGlobalId and GetBackendId
3507  currentNumGlobalCounterIds = registerBackendCountersCpuAcc.RegisterCounter(
3508  0, "testCategory", 0, 0, 1.f, "CpuAccCounter0", "Zeroth CpuAcc Counter");
3509  BOOST_CHECK(currentNumGlobalCounterIds == initialNumGlobalCounterIds + 3);
3510  mappedGlobalId = profilingService.GetCounterMappings().GetGlobalId(0, cpuAccId);
3511  BOOST_CHECK(mappedGlobalId == currentNumGlobalCounterIds);
3512  backendMapping = profilingService.GetCounterMappings().GetBackendId(currentNumGlobalCounterIds);
3513  BOOST_CHECK(backendMapping.first == 0);
3514  BOOST_CHECK(backendMapping.second == cpuAccId);
3515 
3516  // Create vectors for active counters
3517  const std::vector<uint16_t> activeGlobalCounterIds = {5}; // CpuRef(0) activated
3518  const std::vector<uint16_t> newActiveGlobalCounterIds = {6, 7}; // CpuRef(0) and CpuAcc(1) activated
3519 
3520  const uint32_t capturePeriod = 200;
3521  const uint32_t newCapturePeriod = 100;
3522 
3523  // Set capture period and active counters in CaptureData
3524  profilingService.SetCaptureData(capturePeriod, activeGlobalCounterIds, {});
3525 
3526  // Get vector of active counters for CpuRef and CpuAcc backends
3527  std::vector<CounterStatus> cpuRefCounterStatus = backendProfilingCpuRef.GetActiveCounters();
3528  std::vector<CounterStatus> cpuAccCounterStatus = backendProfilingCpuAcc.GetActiveCounters();
3529  BOOST_CHECK_EQUAL(cpuRefCounterStatus.size(), 1);
3530  BOOST_CHECK_EQUAL(cpuAccCounterStatus.size(), 0);
3531 
3532  // Check active CpuRef counter
3533  BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_GlobalCounterId, activeGlobalCounterIds[0]);
3534  BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_BackendCounterId, cpuRefCounters[0]);
3535  BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_SamplingRateInMicroseconds, capturePeriod);
3536  BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_Enabled, true);
3537 
3538  // Check inactive CpuRef counter
3539  CounterStatus inactiveCpuRefCounter = backendProfilingCpuRef.GetCounterStatus(cpuRefCounters[1]);
3540  BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_GlobalCounterId, 6);
3541  BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_BackendCounterId, cpuRefCounters[1]);
3542  BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_SamplingRateInMicroseconds, 0);
3543  BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_Enabled, false);
3544 
3545  // Check inactive CpuAcc counter
3546  CounterStatus inactiveCpuAccCounter = backendProfilingCpuAcc.GetCounterStatus(cpuAccCounters[0]);
3547  BOOST_CHECK_EQUAL(inactiveCpuAccCounter.m_GlobalCounterId, 7);
3548  BOOST_CHECK_EQUAL(inactiveCpuAccCounter.m_BackendCounterId, cpuAccCounters[0]);
3549  BOOST_CHECK_EQUAL(inactiveCpuAccCounter.m_SamplingRateInMicroseconds, 0);
3550  BOOST_CHECK_EQUAL(inactiveCpuAccCounter.m_Enabled, false);
3551 
3552  // Set new capture period and new active counters in CaptureData
3553  profilingService.SetCaptureData(newCapturePeriod, newActiveGlobalCounterIds, {});
3554 
3555  // Get vector of active counters for CpuRef and CpuAcc backends
3556  cpuRefCounterStatus = backendProfilingCpuRef.GetActiveCounters();
3557  cpuAccCounterStatus = backendProfilingCpuAcc.GetActiveCounters();
3558  BOOST_CHECK_EQUAL(cpuRefCounterStatus.size(), 1);
3559  BOOST_CHECK_EQUAL(cpuAccCounterStatus.size(), 1);
3560 
3561  // Check active CpuRef counter
3562  BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_GlobalCounterId, newActiveGlobalCounterIds[0]);
3563  BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_BackendCounterId, cpuRefCounters[1]);
3564  BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_SamplingRateInMicroseconds, newCapturePeriod);
3565  BOOST_CHECK_EQUAL(cpuRefCounterStatus[0].m_Enabled, true);
3566 
3567  // Check active CpuAcc counter
3568  BOOST_CHECK_EQUAL(cpuAccCounterStatus[0].m_GlobalCounterId, newActiveGlobalCounterIds[1]);
3569  BOOST_CHECK_EQUAL(cpuAccCounterStatus[0].m_BackendCounterId, cpuAccCounters[0]);
3570  BOOST_CHECK_EQUAL(cpuAccCounterStatus[0].m_SamplingRateInMicroseconds, newCapturePeriod);
3571  BOOST_CHECK_EQUAL(cpuAccCounterStatus[0].m_Enabled, true);
3572 
3573  // Check inactive CpuRef counter
3574  inactiveCpuRefCounter = backendProfilingCpuRef.GetCounterStatus(cpuRefCounters[0]);
3575  BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_GlobalCounterId, 5);
3576  BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_BackendCounterId, cpuRefCounters[0]);
3577  BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_SamplingRateInMicroseconds, 0);
3578  BOOST_CHECK_EQUAL(inactiveCpuRefCounter.m_Enabled, false);
3579 
3580  // Reset the profiling service to stop any running thread
3581  options.m_ProfilingOptions.m_EnableProfiling = false;
3582  profilingService.ResetExternalProfilingOptions(options.m_ProfilingOptions, true);
3583 }
CPU Execution: Reference C++ kernels.
virtual const Category * GetCategory(const std::string &name) const =0
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
virtual const Categories & GetCategories() const =0
void SetCaptureData(uint32_t capturePeriod, const std::vector< uint16_t > &counterIds, const std::set< BackendId > &activeBackends)
const ICounterMappings & GetCounterMappings() const override
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::profiling::ProfilingService profilingService
CPU Execution: NEON: ArmCompute.
virtual const std::pair< uint16_t, armnn::BackendId > & GetBackendId(uint16_t globalCounterId) const =0
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:83
const ICounterDirectory & GetCounterDirectory() const
virtual uint16_t GetGlobalId(uint16_t backendCounterId, const armnn::BackendId &backendId) const =0

◆ BOOST_AUTO_TEST_CASE() [53/54]

BOOST_AUTO_TEST_CASE ( CheckRegisterCounters  )

Definition at line 3585 of file ProfilingTests.cpp.

References 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.

3586 {
3588  options.m_ProfilingOptions.m_EnableProfiling = true;
3589  MockBufferManager mockBuffer(1024);
3590 
3591  CaptureData captureData;
3592  MockProfilingService mockProfilingService(mockBuffer, options.m_ProfilingOptions.m_EnableProfiling, captureData);
3594 
3595  mockProfilingService.RegisterMapping(6, 0, cpuRefId);
3596  mockProfilingService.RegisterMapping(7, 1, cpuRefId);
3597  mockProfilingService.RegisterMapping(8, 2, cpuRefId);
3598 
3599  armnn::profiling::BackendProfiling backendProfiling(options,
3600  mockProfilingService,
3601  cpuRefId);
3602 
3603  armnn::profiling::Timestamp timestamp;
3604  timestamp.timestamp = 1000998;
3605  timestamp.counterValues.emplace_back(0, 700);
3606  timestamp.counterValues.emplace_back(2, 93);
3607  std::vector<armnn::profiling::Timestamp> timestamps;
3608  timestamps.push_back(timestamp);
3609  backendProfiling.ReportCounters(timestamps);
3610 
3611  auto readBuffer = mockBuffer.GetReadableBuffer();
3612 
3613  uint32_t headerWord0 = ReadUint32(readBuffer, 0);
3614  uint32_t headerWord1 = ReadUint32(readBuffer, 4);
3615  uint64_t readTimestamp = ReadUint64(readBuffer, 8);
3616 
3617  BOOST_TEST(((headerWord0 >> 26) & 0x0000003F) == 3); // packet family
3618  BOOST_TEST(((headerWord0 >> 19) & 0x0000007F) == 0); // packet class
3619  BOOST_TEST(((headerWord0 >> 16) & 0x00000007) == 0); // packet type
3620  BOOST_TEST(headerWord1 == 20); // data length
3621  BOOST_TEST(1000998 == readTimestamp); // capture period
3622 
3623  uint32_t offset = 16;
3624  // Check Counter Index
3625  uint16_t readIndex = ReadUint16(readBuffer, offset);
3626  BOOST_TEST(6 == readIndex);
3627 
3628  // Check Counter Value
3629  offset += 2;
3630  uint32_t readValue = ReadUint32(readBuffer, offset);
3631  BOOST_TEST(700 == readValue);
3632 
3633  // Check Counter Index
3634  offset += 4;
3635  readIndex = ReadUint16(readBuffer, offset);
3636  BOOST_TEST(8 == readIndex);
3637 
3638  // Check Counter Value
3639  offset += 2;
3640  readValue = ReadUint32(readBuffer, offset);
3641  BOOST_TEST(93 == readValue);
3642 }
CPU Execution: Reference C++ kernels.
uint64_t ReadUint64(const IPacketBufferPtr &packetBuffer, unsigned int offset)
uint16_t ReadUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset)
std::vector< CounterValue > counterValues
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:83

◆ BOOST_AUTO_TEST_CASE() [54/54]

BOOST_AUTO_TEST_CASE ( CheckFileFormat  )

Definition at line 3644 of file ProfilingTests.cpp.

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

3644  {
3645  // Locally reduce log level to "Warning", as this test needs to parse a warning message from the standard output
3647 
3648  // Create profiling options.
3649  armnn::Runtime::CreationOptions::ExternalProfilingOptions options;
3650  options.m_EnableProfiling = true;
3651  // Check the default value set to binary
3652  BOOST_CHECK(options.m_FileFormat == "binary");
3653 
3654  // Change file format to an unsupported value
3655  options.m_FileFormat = "json";
3656  // Enable the profiling service
3658  profilingService.ResetExternalProfilingOptions(options, true);
3659  // Start the command handler and the send thread
3660  profilingService.Update();
3661  BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::NotConnected);
3662 
3663  // Redirect the output to a local stream so that we can parse the warning message
3664  std::stringstream ss;
3665  StreamRedirector streamRedirector(std::cout, ss.rdbuf());
3666 
3667  // When Update is called and the current state is ProfilingState::NotConnected
3668  // an exception will be raised from GetProfilingConnection and displayed as warning in the output local stream
3669  profilingService.Update();
3670 
3671  streamRedirector.CancelRedirect();
3672 
3673  // Check that the expected error has occurred and logged to the standard output
3674  if (ss.str().find("Unsupported profiling file format, only binary is supported") == std::string::npos)
3675  {
3676  std::cout << ss.str();
3677  BOOST_FAIL("Expected string not found.");
3678  }
3679 }
ProfilingState GetCurrentState() const
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
armnn::profiling::ProfilingService profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options

◆ CaptureDataReadThreadImpl()

void CaptureDataReadThreadImpl ( const Holder holder,
CaptureData captureData 
)

Definition at line 544 of file ProfilingTests.cpp.

References Holder::GetCaptureData().

Referenced by BOOST_AUTO_TEST_CASE().

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

◆ CaptureDataWriteThreadImpl()

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

Definition at line 539 of file ProfilingTests.cpp.

References Holder::SetCaptureData().

Referenced by BOOST_AUTO_TEST_CASE().

540 {
541  holder.SetCaptureData(capturePeriod, counterIds, {});
542 }
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 456 of file ProfilingTests.cpp.

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

Referenced by BOOST_AUTO_TEST_CASE().

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

◆ StringToSwTraceStringTestHelper()

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

Definition at line 2192 of file ProfilingTests.cpp.

References BOOST_CHECK().

2193 {
2194  // Convert the test string to a SWTrace string
2195  BOOST_CHECK(StringToSwTraceString<SwTracePolicy>(testString, buffer));
2196 
2197  // The buffer must contain at least the length of the string
2198  BOOST_CHECK(!buffer.empty());
2199 
2200  // The buffer must be of the expected size (in words)
2201  BOOST_CHECK(buffer.size() == expectedSize);
2202 
2203  // The first word of the byte must be the length of the string including the null-terminator
2204  BOOST_CHECK(buffer[0] == testString.size() + 1);
2205 
2206  // The contents of the buffer must match the test string
2207  BOOST_CHECK(std::memcmp(testString.data(), buffer.data() + 1, testString.size()) == 0);
2208 
2209  // The buffer must include the null-terminator at the end of the string
2210  size_t nullTerminatorIndex = sizeof(uint32_t) + testString.size();
2211  BOOST_CHECK(reinterpret_cast<unsigned char*>(buffer.data())[nullTerminatorIndex] == '\0');
2212 }
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)