17 #include <boost/cast.hpp> 18 #include <boost/test/test_tools.hpp> 19 #include <boost/test/unit_test_suite.hpp> 23 using namespace armnn;
34 std::vector<std::pair<uint16_t, uint32_t>> indexValuePairs;
35 indexValuePairs.reserve(5);
36 indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(0, 100));
37 indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(1, 200));
38 indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(2, 300));
39 indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(3, 400));
40 indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(4, 500));
43 uint32_t dataLength = 38;
46 uint64_t time =
static_cast<uint64_t
>(
47 std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now().time_since_epoch())
50 uint64_t time2 = time + 5000;
53 std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength);
54 unsigned char* data1 =
reinterpret_cast<unsigned char*
>(uniqueData1.get());
56 std::unique_ptr<unsigned char[]> uniqueData2 = std::make_unique<unsigned char[]>(dataLength);
57 unsigned char* data2 =
reinterpret_cast<unsigned char*
>(uniqueData2.get());
59 uint32_t sizeOfUint64 =
numeric_cast<uint32_t>(
sizeof(uint64_t));
60 uint32_t sizeOfUint32 =
numeric_cast<uint32_t>(
sizeof(uint32_t));
61 uint32_t sizeOfUint16 =
numeric_cast<uint32_t>(
sizeof(uint16_t));
66 offset += sizeOfUint64;
67 for (
const auto& pair : indexValuePairs)
70 offset += sizeOfUint16;
72 offset += sizeOfUint32;
78 offset += sizeOfUint64;
79 for (
const auto& pair : indexValuePairs)
82 offset += sizeOfUint16;
84 offset += sizeOfUint32;
95 commandHandler(packet1);
96 commandHandler(packet2);
112 uint32_t timeout = 2000;
113 uint32_t sleepTime = 50;
114 uint32_t timeSlept = 0;
140 std::string udsNamespace =
"gatord_namespace";
152 profilingService.
Update();
154 profilingService.
Update();
160 BOOST_FAIL(
"Failed to connect client");
166 if (timeSlept >= timeout)
168 BOOST_FAIL(
"Timeout: Profiling service did not switch to WaitingForAck state");
170 std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime));
171 timeSlept += sleepTime;
174 profilingService.
Update();
178 BOOST_FAIL(
"Failed to receive StreamMetaData");
186 if (timeSlept >= timeout)
188 BOOST_FAIL(
"Timeout: Profiling service did not switch to Active state");
190 std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime));
191 timeSlept += sleepTime;
197 while (!directoryCaptureCommandHandler.ParsedCounterDirectory())
199 if (timeSlept >= timeout)
201 BOOST_FAIL(
"Timeout: MockGatord did not receive counter directory packet");
203 std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime));
204 timeSlept += sleepTime;
220 for (
auto& device : serviceDevices)
223 auto foundDevice = receivedCounterDirectory.
GetDevices().find(device.second->m_Uid);
225 BOOST_CHECK(device.second->m_Name.compare((*foundDevice).second->m_Name) == 0);
226 BOOST_CHECK(device.second->m_Cores == (*foundDevice).second->m_Cores);
230 for (
auto& counterSet : serviceCounterSets)
233 auto foundCounterSet = receivedCounterDirectory.
GetCounterSets().find(counterSet.second->m_Uid);
235 BOOST_CHECK(counterSet.second->m_Name.compare((*foundCounterSet).second->m_Name) == 0);
236 BOOST_CHECK(counterSet.second->m_Count == (*foundCounterSet).second->m_Count);
240 for (
auto& category : serviceCategories)
242 for (
auto& receivedCategory : receivedCounterDirectory.
GetCategories())
244 if (receivedCategory->m_Name.compare(category->m_Name) == 0)
248 std::sort(category->m_Counters.begin(), category->m_Counters.end());
249 std::sort(receivedCategory->m_Counters.begin(), receivedCategory->m_Counters.end());
251 std::function<bool(const uint16_t&, const uint16_t&)> comparator =
252 [&directoryCaptureCommandHandler](
const uint16_t& first,
const uint16_t& second) {
253 uint16_t translated = directoryCaptureCommandHandler.TranslateUIDCopyToOriginal(second);
254 if (translated == first)
261 BOOST_CHECK(std::equal(category->m_Counters.begin(), category->m_Counters.end(),
262 receivedCategory->m_Counters.begin(), comparator));
270 for (
auto& receivedCounter : receivedCounters)
274 uint16_t translated = directoryCaptureCommandHandler.TranslateUIDCopyToOriginal(receivedCounter.first);
277 BOOST_CHECK(serviceCounter->
m_Name.compare(receivedCounter.second->m_Name) == 0);
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
static ProfilingService & Instance()
uint32_t GetEncodedValue()
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
Version ResolvePacketVersion(uint32_t familyId, uint32_t packetId) const
bool OpenListeningSocket(std::string udsNamespace)
Establish the Unix domain socket and set it to listen for connections.
virtual uint16_t GetCounterCount() const =0
Copyright (c) 2020 ARM Limited.
virtual const CounterSets & GetCounterSets() const =0
ProfilingService & profilingService
virtual uint16_t GetCategoryCount() const =0
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
std::unordered_map< uint16_t, CounterSetPtr > CounterSets
virtual const Categories & GetCategories() const =0
bool WaitForStreamMetaData()
Once the connection is open wait to receive the stream meta data packet from the client.
virtual const Devices & GetDevices() const =0
void RegisterFunctor(CommandHandlerFunctor *functor, uint32_t familyId, uint32_t packetId, uint32_t version)
uint64_t m_CurrentPeriodValue
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
virtual uint16_t GetDeviceCount() const =0
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
BOOST_AUTO_TEST_CASE(CheckConvolution2dLayer)
bool LaunchReceivingThread()
Start the thread that will receive all packets and print them nicely to stdout.
CounterCaptureValues m_CounterCaptureValues
virtual const Counter * GetCounter(uint16_t uid) const =0
std::vector< uint16_t > m_Uids
void WriteUint64(const std::unique_ptr< IPacketBuffer > &packetBuffer, unsigned int offset, uint64_t value)
std::unordered_set< CategoryPtr > Categories
virtual uint16_t GetCounterSetCount() const =0
A class that implements a Mock Gatord server.
BOOST_AUTO_TEST_SUITE_END()
std::string m_Description
virtual const Counters & GetCounters() const =0
std::unordered_map< uint16_t, DevicePtr > Devices
void WaitForReceivingThread()
This is a placeholder method to prevent main exiting.
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
const ICounterDirectory & GetCounterDirectory() const
armnnUtils::Sockets::Socket BlockForOneClient()
Block waiting to accept one client to connect to the UDS.
void SendConnectionAck()
Send a connection acknowledged packet back to the client.