16 #include <boost/cast.hpp> 17 #include <boost/test/test_tools.hpp> 18 #include <boost/test/unit_test_suite.hpp> 22 using namespace armnn;
28 using boost::numeric_cast;
33 std::vector<std::pair<uint16_t, uint32_t>> indexValuePairs;
34 indexValuePairs.reserve(5);
35 indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(0, 100));
36 indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(1, 200));
37 indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(2, 300));
38 indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(3, 400));
39 indexValuePairs.emplace_back(std::make_pair<uint16_t, uint32_t>(4, 500));
42 uint32_t dataLength = 38;
45 uint64_t time =
static_cast<uint64_t
>(
46 std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::steady_clock::now().time_since_epoch())
49 uint64_t time2 = time + 5000;
52 std::unique_ptr<unsigned char[]> uniqueData1 = std::make_unique<unsigned char[]>(dataLength);
53 unsigned char* data1 =
reinterpret_cast<unsigned char*
>(uniqueData1.get());
55 std::unique_ptr<unsigned char[]> uniqueData2 = std::make_unique<unsigned char[]>(dataLength);
56 unsigned char* data2 =
reinterpret_cast<unsigned char*
>(uniqueData2.get());
58 uint32_t sizeOfUint64 = numeric_cast<uint32_t>(
sizeof(uint64_t));
59 uint32_t sizeOfUint32 = numeric_cast<uint32_t>(
sizeof(uint32_t));
60 uint32_t sizeOfUint16 = numeric_cast<uint32_t>(
sizeof(uint16_t));
65 offset += sizeOfUint64;
66 for (
const auto& pair : indexValuePairs)
69 offset += sizeOfUint16;
71 offset += sizeOfUint32;
77 offset += sizeOfUint64;
78 for (
const auto& pair : indexValuePairs)
81 offset += sizeOfUint16;
83 offset += sizeOfUint32;
94 commandHandler(packet1);
95 commandHandler(packet2);
111 uint32_t timeout = 2000;
112 uint32_t sleepTime = 50;
113 uint32_t timeSlept = 0;
139 std::string udsNamespace =
"gatord_namespace";
151 profilingService.
Update();
153 profilingService.
Update();
159 BOOST_FAIL(
"Failed to connect client");
165 if (timeSlept >= timeout)
167 BOOST_FAIL(
"Timeout: Profiling service did not switch to WaitingForAck state");
169 std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime));
170 timeSlept += sleepTime;
173 profilingService.
Update();
177 BOOST_FAIL(
"Failed to receive StreamMetaData");
185 if (timeSlept >= timeout)
187 BOOST_FAIL(
"Timeout: Profiling service did not switch to Active state");
189 std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime));
190 timeSlept += sleepTime;
196 while (!directoryCaptureCommandHandler.ParsedCounterDirectory())
198 if (timeSlept >= timeout)
200 BOOST_FAIL(
"Timeout: MockGatord did not receive counter directory packet");
202 std::this_thread::sleep_for(std::chrono::milliseconds(sleepTime));
203 timeSlept += sleepTime;
219 for (
auto& device : serviceDevices)
222 auto foundDevice = receivedCounterDirectory.
GetDevices().find(device.second->m_Uid);
224 BOOST_CHECK(device.second->m_Name.compare((*foundDevice).second->m_Name) == 0);
225 BOOST_CHECK(device.second->m_Cores == (*foundDevice).second->m_Cores);
229 for (
auto& counterSet : serviceCounterSets)
232 auto foundCounterSet = receivedCounterDirectory.
GetCounterSets().find(counterSet.second->m_Uid);
234 BOOST_CHECK(counterSet.second->m_Name.compare((*foundCounterSet).second->m_Name) == 0);
235 BOOST_CHECK(counterSet.second->m_Count == (*foundCounterSet).second->m_Count);
239 for (
auto& category : serviceCategories)
241 for (
auto& receivedCategory : receivedCounterDirectory.
GetCategories())
243 if (receivedCategory->m_Name.compare(category->m_Name) == 0)
246 BOOST_CHECK(category->m_DeviceUid == receivedCategory->m_DeviceUid);
247 BOOST_CHECK(category->m_CounterSetUid == receivedCategory->m_CounterSetUid);
249 std::sort(category->m_Counters.begin(), category->m_Counters.end());
250 std::sort(receivedCategory->m_Counters.begin(), receivedCategory->m_Counters.end());
252 std::function<bool(const uint16_t&, const uint16_t&)> comparator =
253 [&directoryCaptureCommandHandler](
const uint16_t& first,
const uint16_t& second) {
254 uint16_t translated = directoryCaptureCommandHandler.TranslateUIDCopyToOriginal(second);
255 if (translated == first)
262 BOOST_CHECK(std::equal(category->m_Counters.begin(), category->m_Counters.end(),
263 receivedCategory->m_Counters.begin(), comparator));
271 for (
auto& receivedCounter : receivedCounters)
275 uint16_t translated = directoryCaptureCommandHandler.TranslateUIDCopyToOriginal(receivedCounter.first);
278 BOOST_CHECK(serviceCounter->
m_Name.compare(receivedCounter.second->m_Name) == 0);
virtual const Devices & GetDevices() const =0
std::unordered_set< CategoryPtr > Categories
armnnUtils::Sockets::Socket BlockForOneClient()
Version ResolvePacketVersion(uint32_t familyId, uint32_t packetId) const
uint32_t GetEncodedValue()
uint64_t m_CurrentPeriodValue
std::unordered_map< uint16_t, DevicePtr > Devices
void WriteUint64(const std::unique_ptr< IPacketBuffer > &packetBuffer, unsigned int offset, uint64_t value)
bool OpenListeningSocket(std::string udsNamespace)
std::unordered_map< uint16_t, CounterSetPtr > CounterSets
void WriteUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint16_t value)
virtual uint16_t GetCategoryCount() const =0
std::vector< uint16_t > m_Uids
virtual const Categories & GetCategories() const =0
BOOST_AUTO_TEST_CASE(CheckConvolution2dLayer)
void SendConnectionAck()
Send a connection acknowledged packet back to the client.
virtual uint16_t GetDeviceCount() const =0
virtual const CounterSets & GetCounterSets() const =0
std::string m_Description
virtual uint16_t GetCounterCount() const =0
const ICounterDirectory & GetCounterDirectory() const
virtual const Counter * GetCounter(uint16_t uid) const =0
void ResetExternalProfilingOptions(const ExternalProfilingOptions &options, bool resetProfilingService=false)
void WaitForReceivingThread()
virtual const Counters & GetCounters() const =0
BOOST_CHECK(profilingService.GetCurrentState()==ProfilingState::WaitingForAck)
void RegisterFunctor(CommandHandlerFunctor *functor, uint32_t familyId, uint32_t packetId, uint32_t version)
bool LaunchReceivingThread()
Start the thread that will receive all packets and print them nicely to stdout.
static ProfilingService & Instance()
BOOST_AUTO_TEST_SUITE_END()
virtual uint16_t GetCounterSetCount() const =0
bool WaitForStreamMetaData()
CounterCaptureValues m_CounterCaptureValues
std::unordered_map< uint16_t, CounterPtr > Counters
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
ProfilingState GetCurrentState() const
ProfilingService & profilingService
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
void WriteUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint32_t value)