diff options
author | Matteo Martincigh <matteo.martincigh@arm.com> | 2019-10-04 17:01:07 +0100 |
---|---|---|
committer | Matteo Martincigh <matteo.martincigh@arm.com> | 2019-10-07 10:08:44 +0000 |
commit | 8a837179ad883e9b5dd982a25cc5e94f245f79ed (patch) | |
tree | 08c798ca632850e0f339ab6b9d50adedd0701c75 /src/profiling | |
parent | 88813936232bc47fc7768800c6895191585570e8 (diff) | |
download | armnn-8a837179ad883e9b5dd982a25cc5e94f245f79ed.tar.gz |
IVGCVSW-3937 Rename CommandThread to CommandHandler
* Renamed files, class name and methods accordingly
* Updated unit tests accordingly
Signed-off-by: Matteo Martincigh <matteo.martincigh@arm.com>
Change-Id: Ifb88aa61edb93b852a07b1bd59bd259213677b44
Diffstat (limited to 'src/profiling')
-rw-r--r-- | src/profiling/CommandHandler.cpp (renamed from src/profiling/CommandThread.cpp) | 20 | ||||
-rw-r--r-- | src/profiling/CommandHandler.hpp (renamed from src/profiling/CommandThread.hpp) | 16 | ||||
-rw-r--r-- | src/profiling/test/ProfilingTests.cpp | 146 |
3 files changed, 84 insertions, 98 deletions
diff --git a/src/profiling/CommandThread.cpp b/src/profiling/CommandHandler.cpp index 320e4bcf5c..5eddfd5ec3 100644 --- a/src/profiling/CommandThread.cpp +++ b/src/profiling/CommandHandler.cpp @@ -3,8 +3,7 @@ // SPDX-License-Identifier: MIT // -#include <atomic> -#include "CommandThread.hpp" +#include "CommandHandler.hpp" namespace armnn { @@ -12,7 +11,7 @@ namespace armnn namespace profiling { -void CommandThread::Start() +void CommandHandler::Start(IProfilingConnection& profilingConnection) { if (IsRunning()) { @@ -21,10 +20,10 @@ void CommandThread::Start() m_IsRunning.store(true, std::memory_order_relaxed); m_KeepRunning.store(true, std::memory_order_relaxed); - m_CommandThread = std::thread(&CommandThread::WaitForPacket, this); + m_CommandThread = std::thread(&CommandHandler::HandleCommands, this, std::ref(profilingConnection)); } -void CommandThread::Stop() +void CommandHandler::Stop() { m_KeepRunning.store(false, std::memory_order_relaxed); @@ -34,28 +33,28 @@ void CommandThread::Stop() } } -bool CommandThread::IsRunning() const +bool CommandHandler::IsRunning() const { return m_IsRunning.load(std::memory_order_relaxed); } -void CommandThread::SetTimeout(uint32_t timeout) +void CommandHandler::SetTimeout(uint32_t timeout) { m_Timeout.store(timeout, std::memory_order_relaxed); } -void CommandThread::SetStopAfterTimeout(bool stopAfterTimeout) +void CommandHandler::SetStopAfterTimeout(bool stopAfterTimeout) { m_StopAfterTimeout.store(stopAfterTimeout, std::memory_order_relaxed); } -void CommandThread::WaitForPacket() +void CommandHandler::HandleCommands(IProfilingConnection& profilingConnection) { do { try { - Packet packet = m_SocketProfilingConnection.ReadPacket(m_Timeout); + Packet packet = profilingConnection.ReadPacket(m_Timeout); Version version = m_PacketVersionResolver.ResolvePacketVersion(packet.GetPacketId()); CommandHandlerFunctor* commandHandlerFunctor = @@ -75,7 +74,6 @@ void CommandThread::WaitForPacket() // Might want to differentiate the errors more m_KeepRunning.store(false, std::memory_order_relaxed); } - } while (m_KeepRunning.load(std::memory_order_relaxed)); diff --git a/src/profiling/CommandThread.hpp b/src/profiling/CommandHandler.hpp index 0456ba4372..598eabde76 100644 --- a/src/profiling/CommandThread.hpp +++ b/src/profiling/CommandHandler.hpp @@ -8,7 +8,6 @@ #include "CommandHandlerRegistry.hpp" #include "IProfilingConnection.hpp" #include "PacketVersionResolver.hpp" -#include "ProfilingService.hpp" #include <atomic> #include <thread> @@ -19,14 +18,13 @@ namespace armnn namespace profiling { -class CommandThread +class CommandHandler { public: - CommandThread(uint32_t timeout, + CommandHandler(uint32_t timeout, bool stopAfterTimeout, CommandHandlerRegistry& commandHandlerRegistry, - PacketVersionResolver& packetVersionResolver, - IProfilingConnection& socketProfilingConnection) + PacketVersionResolver& packetVersionResolver) : m_Timeout(timeout) , m_StopAfterTimeout(stopAfterTimeout) , m_IsRunning(false) @@ -34,11 +32,10 @@ public: , m_CommandThread() , m_CommandHandlerRegistry(commandHandlerRegistry) , m_PacketVersionResolver(packetVersionResolver) - , m_SocketProfilingConnection(socketProfilingConnection) {} - ~CommandThread() { Stop(); } + ~CommandHandler() { Stop(); } - void Start(); + void Start(IProfilingConnection& profilingConnection); void Stop(); bool IsRunning() const; @@ -47,7 +44,7 @@ public: void SetStopAfterTimeout(bool stopAfterTimeout); private: - void WaitForPacket(); + void HandleCommands(IProfilingConnection& profilingConnection); std::atomic<uint32_t> m_Timeout; std::atomic<bool> m_StopAfterTimeout; @@ -57,7 +54,6 @@ private: CommandHandlerRegistry& m_CommandHandlerRegistry; PacketVersionResolver& m_PacketVersionResolver; - IProfilingConnection& m_SocketProfilingConnection; }; } // namespace profiling diff --git a/src/profiling/test/ProfilingTests.cpp b/src/profiling/test/ProfilingTests.cpp index 9dd7cd3d64..bc962e3b17 100644 --- a/src/profiling/test/ProfilingTests.cpp +++ b/src/profiling/test/ProfilingTests.cpp @@ -4,8 +4,8 @@ // #include "SendCounterPacketTests.hpp" -#include "../CommandThread.hpp" +#include <CommandHandler.hpp> #include <CommandHandlerKey.hpp> #include <CommandHandlerFunctor.hpp> #include <CommandHandlerRegistry.hpp> @@ -40,10 +40,10 @@ #include <thread> #include <chrono> -BOOST_AUTO_TEST_SUITE(ExternalProfiling) - using namespace armnn::profiling; +BOOST_AUTO_TEST_SUITE(ExternalProfiling) + BOOST_AUTO_TEST_CASE(CheckCommandHandlerKeyComparisons) { CommandHandlerKey testKey0(1, 1); @@ -97,17 +97,11 @@ public: TestProfilingConnectionBase() = default; ~TestProfilingConnectionBase() = default; - bool IsOpen() - { - return true; - } + bool IsOpen() { return true; } - void Close(){} + void Close() {} - bool WritePacket(const unsigned char* buffer, uint32_t length) - { - return false; - } + bool WritePacket(const unsigned char* buffer, uint32_t length) { return false; } Packet ReadPacket(uint32_t timeout) { @@ -118,9 +112,8 @@ public: } }; -class TestProfilingConnectionTimeoutError :public TestProfilingConnectionBase +class TestProfilingConnectionTimeoutError : public TestProfilingConnectionBase { - int readRequests = 0; public: Packet ReadPacket(uint32_t timeout) { if (readRequests < 3) @@ -133,6 +126,9 @@ public: //Return connection acknowledged packet after three timeouts return {65536 ,0 , packetData}; } + +private: + int readRequests = 0; }; class TestProfilingConnectionArmnnError :public TestProfilingConnectionBase @@ -146,94 +142,90 @@ public: } }; -BOOST_AUTO_TEST_CASE(CheckCommandThread) +BOOST_AUTO_TEST_CASE(CheckCommandHandler) { - PacketVersionResolver packetVersionResolver; - ProfilingStateMachine profilingStateMachine; + PacketVersionResolver packetVersionResolver; + ProfilingStateMachine profilingStateMachine; - TestProfilingConnectionBase testProfilingConnectionBase; - TestProfilingConnectionTimeoutError testProfilingConnectionTimeOutError; - TestProfilingConnectionArmnnError testProfilingConnectionArmnnError; + TestProfilingConnectionBase testProfilingConnectionBase; + TestProfilingConnectionTimeoutError testProfilingConnectionTimeOutError; + TestProfilingConnectionArmnnError testProfilingConnectionArmnnError; - ConnectionAcknowledgedCommandHandler connectionAcknowledgedCommandHandler(1, 4194304, profilingStateMachine); - CommandHandlerRegistry commandHandlerRegistry; + ConnectionAcknowledgedCommandHandler connectionAcknowledgedCommandHandler(1, 4194304, profilingStateMachine); + CommandHandlerRegistry commandHandlerRegistry; - commandHandlerRegistry.RegisterFunctor(&connectionAcknowledgedCommandHandler, 1, 4194304); + commandHandlerRegistry.RegisterFunctor(&connectionAcknowledgedCommandHandler, 1, 4194304); - profilingStateMachine.TransitionToState(ProfilingState::NotConnected); - profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck); + profilingStateMachine.TransitionToState(ProfilingState::NotConnected); + profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck); - CommandThread commandThread0(1, - true, - commandHandlerRegistry, - packetVersionResolver, - testProfilingConnectionBase); + CommandHandler commandHandler0(1, + true, + commandHandlerRegistry, + packetVersionResolver); - commandThread0.Start(); - commandThread0.Start(); - commandThread0.Start(); + commandHandler0.Start(testProfilingConnectionBase); + commandHandler0.Start(testProfilingConnectionBase); + commandHandler0.Start(testProfilingConnectionBase); - commandThread0.Stop(); + commandHandler0.Stop(); - BOOST_CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::Active); + BOOST_CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::Active); - profilingStateMachine.TransitionToState(ProfilingState::NotConnected); - profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck); - //commandThread1 should give up after one timeout - CommandThread commandThread1(1, - true, - commandHandlerRegistry, - packetVersionResolver, - testProfilingConnectionTimeOutError); + profilingStateMachine.TransitionToState(ProfilingState::NotConnected); + profilingStateMachine.TransitionToState(ProfilingState::WaitingForAck); + // commandHandler1 should give up after one timeout + CommandHandler commandHandler1(1, + true, + commandHandlerRegistry, + packetVersionResolver); - commandThread1.Start(); + commandHandler1.Start(testProfilingConnectionTimeOutError); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); - BOOST_CHECK(!commandThread1.IsRunning()); - commandThread1.Stop(); + BOOST_CHECK(!commandHandler1.IsRunning()); + commandHandler1.Stop(); - BOOST_CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::WaitingForAck); - //now commandThread1 should persist after a timeout - commandThread1.SetStopAfterTimeout(false); - commandThread1.Start(); + BOOST_CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::WaitingForAck); + // Now commandHandler1 should persist after a timeout + commandHandler1.SetStopAfterTimeout(false); + commandHandler1.Start(testProfilingConnectionTimeOutError); - for (int i = 0; i < 100; i++) + for (int i = 0; i < 100; i++) + { + if (profilingStateMachine.GetCurrentState() == ProfilingState::Active) { - if (profilingStateMachine.GetCurrentState() == ProfilingState::Active) - { - break; - } - else - { - std::this_thread::sleep_for(std::chrono::milliseconds(5)); - } + break; } - commandThread1.Stop(); + std::this_thread::sleep_for(std::chrono::milliseconds(5)); + } - BOOST_CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::Active); + commandHandler1.Stop(); - CommandThread commandThread2(1, - false, - commandHandlerRegistry, - packetVersionResolver, - testProfilingConnectionArmnnError); + BOOST_CHECK(profilingStateMachine.GetCurrentState() == ProfilingState::Active); - commandThread2.Start(); + CommandHandler commandHandler2(1, + false, + commandHandlerRegistry, + packetVersionResolver); - for (int i = 0; i < 100; i++) + commandHandler2.Start(testProfilingConnectionArmnnError); + + for (int i = 0; i < 100; i++) + { + if (!commandHandler2.IsRunning()) { - if (!commandThread2.IsRunning()) - { - //commandThread2 should stop once it encounters a non timing error - return; - } - std::this_thread::sleep_for(std::chrono::milliseconds(5)); + // commandHandler2 should stop once it encounters a non timing error + return; } - BOOST_ERROR("commandThread2 has failed to stop"); - commandThread2.Stop(); + std::this_thread::sleep_for(std::chrono::milliseconds(5)); + } + + BOOST_ERROR("commandHandler2 has failed to stop"); + commandHandler2.Stop(); } BOOST_AUTO_TEST_CASE(CheckEncodeVersion) |