16 #include <common/include/CommandHandlerFunctor.hpp> 19 #include <boost/test/unit_test.hpp> 50 , m_BackupBuffer(m_Stream.rdbuf(newStreamBuffer))
58 if (m_BackupBuffer !=
nullptr )
60 m_Stream.rdbuf(m_BackupBuffer);
61 m_BackupBuffer =
nullptr;
66 std::ostream& m_Stream;
67 std::streambuf* m_BackupBuffer;
76 bool IsOpen()
const override {
return true; }
80 bool WritePacket(
const unsigned char* buffer, uint32_t length)
override 94 return arm::pipe::Packet(65536);
98 std::this_thread::sleep_for(std::chrono::milliseconds(timeout));
103 bool m_FirstCall =
true;
116 if (m_ReadRequests % 3 == 0)
118 std::this_thread::sleep_for(std::chrono::milliseconds(timeout));
123 return arm::pipe::Packet(65536);
128 return m_ReadRequests.load();
132 std::atomic<int> m_ReadRequests;
151 return m_ReadRequests.load();
155 std::atomic<int> m_ReadRequests;
169 uint32_t packetFamily = 0;
170 uint32_t packetId = 37;
171 uint32_t header = ((packetFamily & 0x0000003F) << 26) | ((packetId & 0x000003FF) << 16);
173 return arm::pipe::Packet(header);
180 using CommandHandlerFunctor::CommandHandlerFunctor;
196 using TestFunctorA::TestFunctorA;
201 using TestFunctorA::TestFunctorA;
211 , m_ProfilingService(profilingService)
213 , m_BackupProfilingConnectionFactory(nullptr)
216 BOOST_CHECK(m_MockProfilingConnectionFactory);
217 SwapProfilingConnectionFactory(m_ProfilingService,
218 m_MockProfilingConnectionFactory.get(),
219 m_BackupProfilingConnectionFactory);
220 BOOST_CHECK(m_BackupProfilingConnectionFactory);
224 BOOST_CHECK(m_BackupProfilingConnectionFactory);
226 SwapProfilingConnectionFactory(m_ProfilingService,
227 m_BackupProfilingConnectionFactory,
234 return PolymorphicDowncast<MockProfilingConnection*>(profilingConnection);
239 TransitionToState(m_ProfilingService, newState);
245 uint32_t timeout = 1000)
247 long packetCount = mockProfilingConnection->
CheckForPacket({ packetType, length });
250 while(packetCount == 0 && timeout != 0)
252 std::chrono::steady_clock::time_point start = std::chrono::steady_clock::now();
256 std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
259 uint32_t elapsedTime =
static_cast<uint32_t
>(
260 std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count());
262 packetCount = mockProfilingConnection->
CheckForPacket({packetType, length});
264 if (elapsedTime > timeout)
269 timeout -= elapsedTime;
LogLevelSwapper(armnn::LogSeverity severity)
SwapProfilingConnectionFactoryHelper(armnn::profiling::ProfilingService &profilingService)
long WaitForPacketsSent(MockProfilingConnection *mockProfilingConnection, MockProfilingConnection::PacketType packetType, uint32_t length=0, uint32_t timeout=1000)
StreamRedirector(std::ostream &stream, std::streambuf *newStreamBuffer)
void ConfigureLogging(bool printToStandardOutput, bool printToDebugOutput, LogSeverity severity)
Configures the logging behaviour of the ARMNN library.
arm::pipe::Packet ReadPacket(uint32_t timeout) override
void ForceTransitionToState(ProfilingState newState)
Copyright (c) 2021 ARM Limited and Contributors.
void IgnoreUnused(Ts &&...)
bool WaitForPacketSent(ProfilingService &instance, uint32_t timeout=1000)
bool IsOpen() const override
arm::pipe::Packet ReadPacket(uint32_t timeout) override
TestProfilingConnectionArmnnError()
TestProfilingConnectionTimeoutError()
bool WritePacket(const unsigned char *buffer, uint32_t length) override
MockProfilingConnection * GetMockProfilingConnection()
void operator()(const arm::pipe::Packet &packet) override
Base class for all ArmNN exceptions so that users can filter to just those.
~SwapProfilingConnectionFactoryHelper()
long CheckForPacket(const std::pair< PacketType, uint32_t > packetInfo)
arm::pipe::Packet ReadPacket(uint32_t timeout) override
arm::pipe::Packet ReadPacket(uint32_t timeout) override
std::unique_ptr< MockProfilingConnectionFactory > MockProfilingConnectionFactoryPtr