ArmNN
 21.02
GatordMockTests.cpp File Reference
#include <common/include/CommandHandlerRegistry.hpp>
#include <server/include/basePipeServer/ConnectionHandler.hpp>
#include <DirectoryCaptureCommandHandler.hpp>
#include <GatordMockService.hpp>
#include <LabelsAndEventClasses.hpp>
#include <ProfilingService.hpp>
#include <TimelinePacketWriterFactory.hpp>
#include <armnn/utility/NumericCast.hpp>
#include <server/include/timelineDecoder/TimelineDirectoryCaptureCommandHandler.hpp>
#include <server/include/timelineDecoder/TimelineDecoder.hpp>
#include <Runtime.hpp>
#include <MockBackend.hpp>
#include <boost/test/test_tools.hpp>
#include <boost/test/unit_test_suite.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (CounterCaptureHandlingTest)
 
void WaitFor (std::function< bool()> predicate, std::string errorMsg, uint32_t timeout=2000, uint32_t sleepTime=50)
 
void CheckTimelineDirectory (arm::pipe::TimelineDirectoryCaptureCommandHandler &commandHandler)
 
void CheckTimelinePackets (arm::pipe::TimelineDecoder &timelineDecoder)
 
 BOOST_AUTO_TEST_CASE (GatorDMockEndToEnd)
 
 BOOST_AUTO_TEST_CASE (GatorDMockTimeLineActivation)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/3]

BOOST_AUTO_TEST_CASE ( CounterCaptureHandlingTest  )

Definition at line 32 of file GatordMockTests.cpp.

References ARMNN_ASSERT, PeriodicCounterCaptureCommandHandler::m_CounterCaptureValues, PeriodicCounterCaptureCommandHandler::m_CurrentPeriodValue, CounterCaptureValues::m_Uids, armnn::numeric_cast(), armnn::profiling::WriteUint16(), armnn::profiling::WriteUint32(), and armnn::profiling::WriteUint64().

33 {
34  arm::pipe::PacketVersionResolver packetVersionResolver;
35 
36  // Data with timestamp, counter idx & counter values
37  std::vector<std::pair<uint16_t, uint32_t>> indexValuePairs;
38  indexValuePairs.reserve(5);
39  indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(0, 100));
40  indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(1, 200));
41  indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(2, 300));
42  indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(3, 400));
43  indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(4, 500));
44 
45  // ((uint16_t (2 bytes) + uint32_t (4 bytes)) * 5) + word1 + word2
46  uint32_t dataLength = 38;
47 
48  // Simulate two different packets incoming 500 ms apart
49  uint64_t time = static_cast<uint64_t>(
50  std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now().time_since_epoch())
51  .count());
52 
53  uint64_t time2 = time + 5000;
54 
55  // UniqueData required for Packet class
56  std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength);
57  unsigned char* data1 = reinterpret_cast<unsigned char*>(uniqueData1.get());
58 
59  std::unique_ptr<unsigned char[]> uniqueData2 = std::make_unique<unsigned char[]>(dataLength);
60  unsigned char* data2 = reinterpret_cast<unsigned char*>(uniqueData2.get());
61 
62  uint32_t sizeOfUint64 = armnn::numeric_cast<uint32_t>(sizeof(uint64_t));
63  uint32_t sizeOfUint32 = armnn::numeric_cast<uint32_t>(sizeof(uint32_t));
64  uint32_t sizeOfUint16 = armnn::numeric_cast<uint32_t>(sizeof(uint16_t));
65  // Offset index to point to mem address
66  uint32_t offset = 0;
67 
68  profiling::WriteUint64(data1, offset, time);
69  offset += sizeOfUint64;
70  for (const auto& pair : indexValuePairs)
71  {
72  profiling::WriteUint16(data1, offset, pair.first);
73  offset += sizeOfUint16;
74  profiling::WriteUint32(data1, offset, pair.second);
75  offset += sizeOfUint32;
76  }
77 
78  offset = 0;
79 
80  profiling::WriteUint64(data2, offset, time2);
81  offset += sizeOfUint64;
82  for (const auto& pair : indexValuePairs)
83  {
84  profiling::WriteUint16(data2, offset, pair.first);
85  offset += sizeOfUint16;
86  profiling::WriteUint32(data2, offset, pair.second);
87  offset += sizeOfUint32;
88  }
89 
90  uint32_t headerWord1 = packetVersionResolver.ResolvePacketVersion(0, 4).GetEncodedValue();
91  // Create packet to send through to the command functor
92  arm::pipe::Packet packet1(headerWord1, dataLength, uniqueData1);
93  arm::pipe::Packet packet2(headerWord1, dataLength, uniqueData2);
94 
95  gatordmock::PeriodicCounterCaptureCommandHandler commandHandler(0, 4, headerWord1, true);
96 
97  // Simulate two separate packets coming in to calculate period
98  commandHandler(packet1);
99  commandHandler(packet2);
100 
101  ARMNN_ASSERT(commandHandler.m_CurrentPeriodValue == 5000);
102 
103  for (size_t i = 0; i < commandHandler.m_CounterCaptureValues.m_Uids.size(); ++i)
104  {
105  ARMNN_ASSERT(commandHandler.m_CounterCaptureValues.m_Uids[i] == i);
106  }
107 }
void WriteUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint16_t value)
void WriteUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint32_t value)
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
void WriteUint64(const std::unique_ptr< IPacketBuffer > &packetBuffer, unsigned int offset, uint64_t value)
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:35

◆ BOOST_AUTO_TEST_CASE() [2/3]

BOOST_AUTO_TEST_CASE ( GatorDMockEndToEnd  )

Definition at line 239 of file GatordMockTests.cpp.

References armnn::profiling::Active, CheckTimelineDirectory(), CheckTimelinePackets(), ICounterDirectory::GetCategories(), ICounterDirectory::GetCategoryCount(), ICounterDirectory::GetCounter(), ICounterDirectory::GetCounterCount(), DirectoryCaptureCommandHandler::GetCounterDirectory(), ProfilingService::GetCounterDirectory(), ICounterDirectory::GetCounters(), ICounterDirectory::GetCounterSetCount(), ICounterDirectory::GetCounterSets(), ProfilingService::GetCurrentState(), ICounterDirectory::GetDeviceCount(), ICounterDirectory::GetDevices(), GatordMockService::GetDirectoryCaptureCommandHandler(), GatordMockService::GetTimelineDecoder(), GatordMockService::GetTimelineDirectoryCaptureCommandHandler(), GatordMockService::LaunchReceivingThread(), Counter::m_Class, Counter::m_CounterSetUid, Counter::m_Description, Counter::m_DeviceUid, IRuntime::CreationOptions::ExternalProfilingOptions::m_EnableProfiling, Counter::m_Interpolation, Counter::m_Multiplier, Counter::m_Name, IRuntime::CreationOptions::ExternalProfilingOptions::m_TimelineEnabled, Counter::m_Units, armnn::profiling::NotConnected, DirectoryCaptureCommandHandler::ParsedCounterDirectory(), ProfilingService::ResetExternalProfilingOptions(), GatordMockService::SendConnectionAck(), DirectoryCaptureCommandHandler::TranslateUIDCopyToOriginal(), armnn::profiling::Uninitialised, ProfilingService::Update(), WaitFor(), GatordMockService::WaitForReceivingThread(), GatordMockService::WaitForStreamMetaData(), and armnn::profiling::WaitingForAck.

240 {
241  // The purpose of this test is to setup both sides of the profiling service and get to the point of receiving
242  // performance data.
243 
244  // Setup the mock service to bind to the UDS.
245  std::string udsNamespace = "gatord_namespace";
246 
247  BOOST_CHECK_NO_THROW(arm::pipe::ConnectionHandler connectionHandler(udsNamespace, false));
248 
249  arm::pipe::ConnectionHandler connectionHandler(udsNamespace, false);
250 
251  // Enable the profiling service.
253  options.m_EnableProfiling = true;
254  options.m_TimelineEnabled = true;
255 
256  armnn::profiling::ProfilingService profilingService;
257  profilingService.ResetExternalProfilingOptions(options, true);
258 
259  // Bring the profiling service to the "WaitingForAck" state
260  BOOST_CHECK(profilingService.GetCurrentState() == profiling::ProfilingState::Uninitialised);
261  profilingService.Update();
262  BOOST_CHECK(profilingService.GetCurrentState() == profiling::ProfilingState::NotConnected);
263  profilingService.Update();
264 
265  // Connect the profiling service
266  auto basePipeServer = connectionHandler.GetNewBasePipeServer(false);
267 
268  // Connect the profiling service to the mock Gatord.
269  gatordmock::GatordMockService mockService(std::move(basePipeServer), false);
270 
271  arm::pipe::TimelineDecoder& timelineDecoder = mockService.GetTimelineDecoder();
272  profiling::DirectoryCaptureCommandHandler& directoryCaptureCommandHandler =
273  mockService.GetDirectoryCaptureCommandHandler();
274 
275  // Give the profiling service sending thread time start executing and send the stream metadata.
276  WaitFor([&](){return profilingService.GetCurrentState() == profiling::ProfilingState::WaitingForAck;},
277  "Profiling service did not switch to WaitingForAck state");
278 
279  profilingService.Update();
280  // Read the stream metadata on the mock side.
281  if (!mockService.WaitForStreamMetaData())
282  {
283  BOOST_FAIL("Failed to receive StreamMetaData");
284  }
285  // Send Ack from GatorD
286  mockService.SendConnectionAck();
287  // And start to listen for packets
288  mockService.LaunchReceivingThread();
289 
290  WaitFor([&](){return profilingService.GetCurrentState() == profiling::ProfilingState::Active;},
291  "Profiling service did not switch to Active state");
292 
293  // As part of the default startup of the profiling service a counter directory packet will be sent.
294  WaitFor([&](){return directoryCaptureCommandHandler.ParsedCounterDirectory();},
295  "MockGatord did not receive counter directory packet");
296 
297  // Following that we will receive a collection of well known timeline labels and event classes
298  WaitFor([&](){return timelineDecoder.GetModel().m_EventClasses.size() >= 2;},
299  "MockGatord did not receive well known timeline labels and event classes");
300 
301  CheckTimelineDirectory(mockService.GetTimelineDirectoryCaptureCommandHandler());
302  // Verify the commonly used timeline packets sent when the profiling service enters the active state
303  CheckTimelinePackets(timelineDecoder);
304 
305  const profiling::ICounterDirectory& serviceCounterDirectory = profilingService.GetCounterDirectory();
306  const profiling::ICounterDirectory& receivedCounterDirectory = directoryCaptureCommandHandler.GetCounterDirectory();
307 
308  // Compare the basics of the counter directory from the service and the one we received over the wire.
309  BOOST_CHECK(serviceCounterDirectory.GetDeviceCount() == receivedCounterDirectory.GetDeviceCount());
310  BOOST_CHECK(serviceCounterDirectory.GetCounterSetCount() == receivedCounterDirectory.GetCounterSetCount());
311  BOOST_CHECK(serviceCounterDirectory.GetCategoryCount() == receivedCounterDirectory.GetCategoryCount());
312  BOOST_CHECK(serviceCounterDirectory.GetCounterCount() == receivedCounterDirectory.GetCounterCount());
313 
314  receivedCounterDirectory.GetDeviceCount();
315  serviceCounterDirectory.GetDeviceCount();
316 
317  const profiling::Devices& serviceDevices = serviceCounterDirectory.GetDevices();
318  for (auto& device : serviceDevices)
319  {
320  // Find the same device in the received counter directory.
321  auto foundDevice = receivedCounterDirectory.GetDevices().find(device.second->m_Uid);
322  BOOST_CHECK(foundDevice != receivedCounterDirectory.GetDevices().end());
323  BOOST_CHECK(device.second->m_Name.compare((*foundDevice).second->m_Name) == 0);
324  BOOST_CHECK(device.second->m_Cores == (*foundDevice).second->m_Cores);
325  }
326 
327  const profiling::CounterSets& serviceCounterSets = serviceCounterDirectory.GetCounterSets();
328  for (auto& counterSet : serviceCounterSets)
329  {
330  // Find the same counter set in the received counter directory.
331  auto foundCounterSet = receivedCounterDirectory.GetCounterSets().find(counterSet.second->m_Uid);
332  BOOST_CHECK(foundCounterSet != receivedCounterDirectory.GetCounterSets().end());
333  BOOST_CHECK(counterSet.second->m_Name.compare((*foundCounterSet).second->m_Name) == 0);
334  BOOST_CHECK(counterSet.second->m_Count == (*foundCounterSet).second->m_Count);
335  }
336 
337  const profiling::Categories& serviceCategories = serviceCounterDirectory.GetCategories();
338  for (auto& category : serviceCategories)
339  {
340  for (auto& receivedCategory : receivedCounterDirectory.GetCategories())
341  {
342  if (receivedCategory->m_Name.compare(category->m_Name) == 0)
343  {
344  // We've found the matching category.
345  // Now look at the interiors of the counters. Start by sorting them.
346  std::sort(category->m_Counters.begin(), category->m_Counters.end());
347  std::sort(receivedCategory->m_Counters.begin(), receivedCategory->m_Counters.end());
348  // When comparing uid's here we need to translate them.
349  std::function<bool(const uint16_t&, const uint16_t&)> comparator =
350  [&directoryCaptureCommandHandler](const uint16_t& first, const uint16_t& second) {
351  uint16_t translated = directoryCaptureCommandHandler.TranslateUIDCopyToOriginal(second);
352  if (translated == first)
353  {
354  return true;
355  }
356  return false;
357  };
358  // Then let vector == do the work.
359  BOOST_CHECK(std::equal(category->m_Counters.begin(), category->m_Counters.end(),
360  receivedCategory->m_Counters.begin(), comparator));
361  break;
362  }
363  }
364  }
365 
366  // Finally check the content of the counters.
367  const profiling::Counters& receivedCounters = receivedCounterDirectory.GetCounters();
368  for (auto& receivedCounter : receivedCounters)
369  {
370  // Translate the Uid and find the corresponding counter in the original counter directory.
371  // Note we can't check m_MaxCounterUid here as it will likely differ between the two counter directories.
372  uint16_t translated = directoryCaptureCommandHandler.TranslateUIDCopyToOriginal(receivedCounter.first);
373  const profiling::Counter* serviceCounter = serviceCounterDirectory.GetCounter(translated);
374  BOOST_CHECK(serviceCounter->m_DeviceUid == receivedCounter.second->m_DeviceUid);
375  BOOST_CHECK(serviceCounter->m_Name.compare(receivedCounter.second->m_Name) == 0);
376  BOOST_CHECK(serviceCounter->m_CounterSetUid == receivedCounter.second->m_CounterSetUid);
377  BOOST_CHECK(serviceCounter->m_Multiplier == receivedCounter.second->m_Multiplier);
378  BOOST_CHECK(serviceCounter->m_Interpolation == receivedCounter.second->m_Interpolation);
379  BOOST_CHECK(serviceCounter->m_Class == receivedCounter.second->m_Class);
380  BOOST_CHECK(serviceCounter->m_Units.compare(receivedCounter.second->m_Units) == 0);
381  BOOST_CHECK(serviceCounter->m_Description.compare(receivedCounter.second->m_Description) == 0);
382  }
383 
384  mockService.WaitForReceivingThread();
385  options.m_EnableProfiling = false;
386  profilingService.ResetExternalProfilingOptions(options, true);
387  // Future tests here will add counters to the ProfilingService, increment values and examine
388  // PeriodicCounterCapture data received. These are yet to be integrated.
389 }
ProfilingState GetCurrentState() const
uint16_t TranslateUIDCopyToOriginal(uint16_t copyUid)
Given a Uid that came from a copy of the counter directory translate it to the original.
std::unordered_map< uint16_t, CounterPtr > Counters
void CheckTimelinePackets(arm::pipe::TimelineDecoder &timelineDecoder)
virtual uint16_t GetCounterCount() const =0
virtual const CounterSets & GetCounterSets() const =0
virtual uint16_t GetCategoryCount() const =0
void CheckTimelineDirectory(arm::pipe::TimelineDirectoryCaptureCommandHandler &commandHandler)
std::unordered_map< uint16_t, CounterSetPtr > CounterSets
virtual const Categories & GetCategories() const =0
virtual const Devices & GetDevices() const =0
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
virtual uint16_t GetDeviceCount() const =0
virtual const Counter * GetCounter(uint16_t uid) const =0
std::unordered_set< CategoryPtr > Categories
virtual uint16_t GetCounterSetCount() const =0
A class that implements a Mock Gatord server.
virtual const Counters & GetCounters() const =0
void WaitFor(std::function< bool()> predicate, std::string errorMsg, uint32_t timeout=2000, uint32_t sleepTime=50)
std::unordered_map< uint16_t, DevicePtr > Devices
const ICounterDirectory & GetCounterDirectory() const

◆ BOOST_AUTO_TEST_CASE() [3/3]

BOOST_AUTO_TEST_CASE ( GatorDMockTimeLineActivation  )

Definition at line 391 of file GatordMockTests.cpp.

References armnn::BackendRegistryInstance(), BOOST_AUTO_TEST_SUITE_END(), IOutputSlot::Connect(), armnn::CpuRef, INetwork::Create(), ProfilingService::Disconnect(), armnn::Float32, MockBackendProfilingService::GetContext(), RuntimeImpl::GetDeviceSpec(), GatordMockService::GetDirectoryCaptureCommandHandler(), IConnectableLayer::GetInputSlot(), IConnectableLayer::GetOutputSlot(), armnn::GetProfilingService(), GatordMockService::GetTimelineDecoder(), MockBackendProfilingService::Instance(), GatordMockService::LaunchReceivingThread(), RuntimeImpl::LoadNetwork(), IRuntime::CreationOptions::ExternalProfilingOptions::m_EnableProfiling, IRuntime::CreationOptions::m_ProfilingOptions, IRuntime::CreationOptions::ExternalProfilingOptions::m_TimelineEnabled, armnn::Optimize(), DirectoryCaptureCommandHandler::ParsedCounterDirectory(), GatordMockService::SendActivateTimelinePacket(), GatordMockService::SendConnectionAck(), GatordMockService::SendDeactivateTimelinePacket(), IOutputSlot::SetTensorInfo(), MockBackendProfilingContext::TimelineReportingEnabled(), WaitFor(), GatordMockService::WaitForReceivingThread(), and GatordMockService::WaitForStreamMetaData().

392 {
393  // This test requires the CpuRef backend to be enabled
394  if(!BackendRegistryInstance().IsBackendRegistered("CpuRef"))
395  {
396  return;
397  }
398  armnn::MockBackendInitialiser initialiser;
399  // Setup the mock service to bind to the UDS.
400  std::string udsNamespace = "gatord_namespace";
401 
402  arm::pipe::ConnectionHandler connectionHandler(udsNamespace, false);
403 
405  options.m_ProfilingOptions.m_EnableProfiling = true;
406  options.m_ProfilingOptions.m_TimelineEnabled = true;
407  armnn::RuntimeImpl runtime(options);
408 
409  auto basePipeServer = connectionHandler.GetNewBasePipeServer(false);
410  gatordmock::GatordMockService mockService(std::move(basePipeServer), false);
411 
412  // Read the stream metadata on the mock side.
413  if (!mockService.WaitForStreamMetaData())
414  {
415  BOOST_FAIL("Failed to receive StreamMetaData");
416  }
417 
419  armnn::MockBackendProfilingContext *mockBackEndProfilingContext = mockProfilingService.GetContext();
420 
421  // Send Ack from GatorD
422  mockService.SendConnectionAck();
423  // And start to listen for packets
424  mockService.LaunchReceivingThread();
425 
426  // Build and optimize a simple network while we wait
427  INetworkPtr net(INetwork::Create());
428 
429  IConnectableLayer* input = net->AddInputLayer(0, "input");
430 
431  NormalizationDescriptor descriptor;
432  IConnectableLayer* normalize = net->AddNormalizationLayer(descriptor, "normalization");
433 
434  IConnectableLayer* output = net->AddOutputLayer(0, "output");
435 
436  input->GetOutputSlot(0).Connect(normalize->GetInputSlot(0));
437  normalize->GetOutputSlot(0).Connect(output->GetInputSlot(0));
438 
439  input->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
440  normalize->GetOutputSlot(0).SetTensorInfo(TensorInfo({ 1, 1, 4, 4 }, DataType::Float32));
441 
442  std::vector<armnn::BackendId> backends = { armnn::Compute::CpuRef };
443  IOptimizedNetworkPtr optNet = Optimize(*net, backends, runtime.GetDeviceSpec());
444 
445  WaitFor([&](){return mockService.GetDirectoryCaptureCommandHandler().ParsedCounterDirectory();},
446  "MockGatord did not receive counter directory packet");
447 
448  arm::pipe::TimelineDecoder& timelineDecoder = mockService.GetTimelineDecoder();
449 
450  WaitFor([&](){return timelineDecoder.GetModel().m_EventClasses.size() >= 2;},
451  "MockGatord did not receive well known timeline labels");
452 
453  WaitFor([&](){return timelineDecoder.GetModel().m_Entities.size() >= 1;},
454  "MockGatord did not receive mock backend test entity");
455 
456  // Packets we expect from SendWellKnownLabelsAndEventClassesTest
457  BOOST_CHECK(timelineDecoder.GetModel().m_Entities.size() == 1);
458  BOOST_CHECK(timelineDecoder.GetModel().m_EventClasses.size() == 2);
459  BOOST_CHECK(timelineDecoder.GetModel().m_Labels.size() == 15);
460  BOOST_CHECK(timelineDecoder.GetModel().m_Relationships.size() == 0);
461  BOOST_CHECK(timelineDecoder.GetModel().m_Events.size() == 0);
462 
463  mockService.SendDeactivateTimelinePacket();
464 
465  WaitFor([&](){return !mockBackEndProfilingContext->TimelineReportingEnabled();},
466  "Timeline packets were not deactivated");
467 
468  // Load the network into runtime now that timeline reporting is disabled
469  armnn::NetworkId netId;
470  runtime.LoadNetwork(netId, std::move(optNet));
471 
472  // Now activate timeline packets
473  mockService.SendActivateTimelinePacket();
474 
475  WaitFor([&](){return mockBackEndProfilingContext->TimelineReportingEnabled();},
476  "Timeline packets were not activated");
477 
478  // Once TimelineReporting is Enabled additional activateTimelinePackets should be ignored
479  mockService.SendActivateTimelinePacket();
480  mockService.SendActivateTimelinePacket();
481 
482  // Once timeline packets have been reactivated the ActivateTimelineReportingCommandHandler will resend the
483  // SendWellKnownLabelsAndEventClasses and then send the structure of any loaded networks
484  WaitFor([&](){return timelineDecoder.GetModel().m_Labels.size() >= 24;},
485  "MockGatord did not receive well known timeline labels");
486 
487  // Packets we expect from SendWellKnownLabelsAndEventClassesTest * 2 + network above (input, norm, backend, output)
488  BOOST_CHECK(timelineDecoder.GetModel().m_Entities.size() == 6);
489  BOOST_CHECK(timelineDecoder.GetModel().m_EventClasses.size() == 4);
490  BOOST_CHECK(timelineDecoder.GetModel().m_Labels.size() == 34);
491  BOOST_CHECK(timelineDecoder.GetModel().m_Relationships.size() == 15);
492  BOOST_CHECK(timelineDecoder.GetModel().m_Events.size() == 0);
493 
494  mockService.WaitForReceivingThread();
495  GetProfilingService(&runtime).Disconnect();
496 }
profiling::ProfilingService & GetProfilingService(armnn::RuntimeImpl *runtime)
Definition: TestUtils.cpp:35
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:62
CPU Execution: Reference C++ kernels.
BackendRegistry & BackendRegistryInstance()
int NetworkId
Definition: IRuntime.hpp:20
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
IOptimizedNetworkPtr Optimize(const INetwork &network, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptions &options=OptimizerOptions(), Optional< std::vector< std::string > &> messages=EmptyOptional())
Create an optimized version of the network.
Definition: Network.cpp:1502
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
Definition: INetwork.hpp:174
static MockBackendProfilingService & Instance()
A class that implements a Mock Gatord server.
MockBackendProfilingContext * GetContext()
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
void WaitFor(std::function< bool()> predicate, std::string errorMsg, uint32_t timeout=2000, uint32_t sleepTime=50)
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:173
virtual int Connect(IInputSlot &destination)=0
A NormalizationDescriptor for the NormalizationLayer.
ExternalProfilingOptions m_ProfilingOptions
Definition: IRuntime.hpp:84

◆ CheckTimelineDirectory()

void CheckTimelineDirectory ( arm::pipe::TimelineDirectoryCaptureCommandHandler &  commandHandler)

Definition at line 123 of file GatordMockTests.cpp.

References BufferManager::GetReadableBuffer(), TimelinePacketWriterFactory::GetSendTimelinePacket(), armnn::profiling::ReadUint32(), armnn::profiling::ReadUint8(), and armnn::profiling::uint32_t_size.

Referenced by BOOST_AUTO_TEST_CASE().

124 {
125  uint32_t uint8_t_size = sizeof(uint8_t);
126  uint32_t uint32_t_size = sizeof(uint32_t);
127  uint32_t uint64_t_size = sizeof(uint64_t);
128  uint32_t threadId_size = sizeof(int);
129 
130  profiling::BufferManager bufferManager(5);
131  profiling::TimelinePacketWriterFactory timelinePacketWriterFactory(bufferManager);
132 
133  std::unique_ptr<profiling::ISendTimelinePacket> sendTimelinePacket =
134  timelinePacketWriterFactory.GetSendTimelinePacket();
135 
136  sendTimelinePacket->SendTimelineMessageDirectoryPackage();
137  sendTimelinePacket->Commit();
138 
139  std::vector<arm::pipe::SwTraceMessage> swTraceBufferMessages;
140 
141  unsigned int offset = uint32_t_size * 2;
142 
143  std::unique_ptr<profiling::IPacketBuffer> packetBuffer = bufferManager.GetReadableBuffer();
144 
145  uint8_t readStreamVersion = ReadUint8(packetBuffer, offset);
146  BOOST_CHECK(readStreamVersion == 4);
147  offset += uint8_t_size;
148  uint8_t readPointerBytes = ReadUint8(packetBuffer, offset);
149  BOOST_CHECK(readPointerBytes == uint64_t_size);
150  offset += uint8_t_size;
151  uint8_t readThreadIdBytes = ReadUint8(packetBuffer, offset);
152  BOOST_CHECK(readThreadIdBytes == threadId_size);
153  offset += uint8_t_size;
154 
155  uint32_t declarationSize = profiling::ReadUint32(packetBuffer, offset);
156  offset += uint32_t_size;
157  for(uint32_t i = 0; i < declarationSize; ++i)
158  {
159  swTraceBufferMessages.push_back(arm::pipe::ReadSwTraceMessage(packetBuffer->GetReadableData(),
160  offset,
161  packetBuffer->GetSize()));
162  }
163 
164  for(uint32_t index = 0; index < declarationSize; ++index)
165  {
166  arm::pipe::SwTraceMessage& bufferMessage = swTraceBufferMessages[index];
167  arm::pipe::SwTraceMessage& handlerMessage = commandHandler.m_SwTraceMessages[index];
168 
169  BOOST_CHECK(bufferMessage.m_Name == handlerMessage.m_Name);
170  BOOST_CHECK(bufferMessage.m_UiName == handlerMessage.m_UiName);
171  BOOST_CHECK(bufferMessage.m_Id == handlerMessage.m_Id);
172 
173  BOOST_CHECK(bufferMessage.m_ArgTypes.size() == handlerMessage.m_ArgTypes.size());
174  for(uint32_t i = 0; i < bufferMessage.m_ArgTypes.size(); ++i)
175  {
176  BOOST_CHECK(bufferMessage.m_ArgTypes[i] == handlerMessage.m_ArgTypes[i]);
177  }
178 
179  BOOST_CHECK(bufferMessage.m_ArgNames.size() == handlerMessage.m_ArgNames.size());
180  for(uint32_t i = 0; i < bufferMessage.m_ArgNames.size(); ++i)
181  {
182  BOOST_CHECK(bufferMessage.m_ArgNames[i] == handlerMessage.m_ArgNames[i]);
183  }
184  }
185 }
uint8_t ReadUint8(const IPacketBufferPtr &packetBuffer, unsigned int offset)
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)

◆ CheckTimelinePackets()

void CheckTimelinePackets ( arm::pipe::TimelineDecoder &  timelineDecoder)

Definition at line 187 of file GatordMockTests.cpp.

References LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS, LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS, LabelsAndEventClasses::BACKENDID_GUID, LabelsAndEventClasses::BACKENDID_LABEL, LabelsAndEventClasses::CHILD_GUID, LabelsAndEventClasses::CHILD_LABEL, LabelsAndEventClasses::CONNECTION, LabelsAndEventClasses::CONNECTION_GUID, LabelsAndEventClasses::EXECUTION_OF_GUID, LabelsAndEventClasses::EXECUTION_OF_LABEL, LabelsAndEventClasses::INDEX_GUID, LabelsAndEventClasses::INDEX_LABEL, LabelsAndEventClasses::INFERENCE, LabelsAndEventClasses::INFERENCE_GUID, LabelsAndEventClasses::LAYER, LabelsAndEventClasses::LAYER_GUID, LabelsAndEventClasses::NAME_GUID, LabelsAndEventClasses::NAME_LABEL, LabelsAndEventClasses::NETWORK, LabelsAndEventClasses::NETWORK_GUID, LabelsAndEventClasses::PROCESS_ID_GUID, LabelsAndEventClasses::PROCESS_ID_LABEL, LabelsAndEventClasses::TYPE_GUID, LabelsAndEventClasses::TYPE_LABEL, LabelsAndEventClasses::WORKLOAD, LabelsAndEventClasses::WORKLOAD_EXECUTION, LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID, and LabelsAndEventClasses::WORKLOAD_GUID.

Referenced by BOOST_AUTO_TEST_CASE().

188 {
189  unsigned int i = 0; // Use a postfix increment to avoid changing indexes each time the packet gets updated.
190  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::NAME_GUID);
191  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::NAME_LABEL);
192 
193  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::TYPE_GUID);
194  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::TYPE_LABEL);
195 
196  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::INDEX_GUID);
197  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::INDEX_LABEL);
198 
199  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::BACKENDID_GUID);
200  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::BACKENDID_LABEL);
201 
202  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::CHILD_GUID);
203  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::CHILD_LABEL);
204 
205  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::EXECUTION_OF_GUID);
206  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name ==
207  profiling::LabelsAndEventClasses::EXECUTION_OF_LABEL);
208 
209  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::PROCESS_ID_GUID);
210  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name ==
211  profiling::LabelsAndEventClasses::PROCESS_ID_LABEL);
212 
213  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::LAYER_GUID);
214  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::LAYER);
215 
216  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::WORKLOAD_GUID);
217  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::WORKLOAD);
218 
219  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::NETWORK_GUID);
220  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::NETWORK);
221 
222  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::CONNECTION_GUID);
223  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::CONNECTION);
224 
225  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid == profiling::LabelsAndEventClasses::INFERENCE_GUID);
226  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name == profiling::LabelsAndEventClasses::INFERENCE);
227 
228  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i].m_Guid ==
229  profiling::LabelsAndEventClasses::WORKLOAD_EXECUTION_GUID);
230  BOOST_CHECK(timelineDecoder.GetModel().m_Labels[i++].m_Name ==
231  profiling::LabelsAndEventClasses::WORKLOAD_EXECUTION);
232 
233  BOOST_CHECK(timelineDecoder.GetModel().m_EventClasses[0].m_Guid ==
234  profiling::LabelsAndEventClasses::ARMNN_PROFILING_SOL_EVENT_CLASS);
235  BOOST_CHECK(timelineDecoder.GetModel().m_EventClasses[1].m_Guid ==
236  profiling::LabelsAndEventClasses::ARMNN_PROFILING_EOL_EVENT_CLASS);
237 }

◆ WaitFor()

void WaitFor ( std::function< bool()>  predicate,
std::string  errorMsg,
uint32_t  timeout = 2000,
uint32_t  sleepTime = 50 
)

Definition at line 109 of file GatordMockTests.cpp.

Referenced by BOOST_AUTO_TEST_CASE().

110 {
111  uint32_t timeSlept = 0;
112  while (!predicate())
113  {
114  if (timeSlept >= timeout)
115  {
116  BOOST_FAIL("Timeout: " + errorMsg);
117  }
118  std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime));
119  timeSlept += sleepTime;
120  }
121 }