From 2ed809cb4765306b7af9b6968e2ec609d143979b Mon Sep 17 00:00:00 2001 From: Finn Williams Date: Mon, 20 Apr 2020 21:21:07 +0100 Subject: IVGCVSW-4594 Refactor the GatordMockService and GatordMockMain to extract a BasePipeServer Signed-off-by: Finn Williams Change-Id: I03c1b46104dadc491dba6075865e486f78aa60fa --- tests/profiling/gatordmock/GatordMockService.hpp | 83 +++--------------------- 1 file changed, 10 insertions(+), 73 deletions(-) (limited to 'tests/profiling/gatordmock/GatordMockService.hpp') diff --git a/tests/profiling/gatordmock/GatordMockService.hpp b/tests/profiling/gatordmock/GatordMockService.hpp index 232d2565e3..8bad41cdfb 100644 --- a/tests/profiling/gatordmock/GatordMockService.hpp +++ b/tests/profiling/gatordmock/GatordMockService.hpp @@ -7,7 +7,6 @@ #include #include -#include #include #include @@ -20,6 +19,8 @@ #include "PeriodicCounterCaptureCommandHandler.hpp" #include "StreamMetadataCommandHandler.hpp" +#include + #include "PacketVersionResolver.hpp" #include "StubCommandHandler.hpp" @@ -29,19 +30,6 @@ namespace armnn namespace gatordmock { -enum class TargetEndianness -{ - BeWire, - LeWire -}; - -enum class PacketDirection -{ - Sending, - ReceivedHeader, - ReceivedData -}; - /// A class that implements a Mock Gatord server. It will listen on a specified Unix domain socket (UDS) /// namespace for client connections. It will then allow opertaions to manage coutners while receiving counter data. class GatordMockService @@ -49,9 +37,8 @@ class GatordMockService public: /// @param registry reference to a command handler registry. /// @param echoPackets if true the raw packets will be printed to stdout. - GatordMockService(armnnUtils::Sockets::Socket clientConnection, bool echoPackets) - : m_ClientConnection(clientConnection) - , m_PacketsReceivedCount(0) + GatordMockService(std::unique_ptr clientConnection, bool echoPackets) + : m_BasePipeServer(std::move(clientConnection)) , m_EchoPackets(echoPackets) , m_CloseReceivingThread(false) , m_PacketVersionResolver() @@ -81,18 +68,11 @@ public: m_HandlerRegistry.RegisterFunctor(&m_TimelineCaptureCommandHandler); } - ~GatordMockService() - { - // We have set SOCK_CLOEXEC on these sockets but we'll close them to be good citizens. - armnnUtils::Sockets::Close(m_ClientConnection); - } + GatordMockService(const GatordMockService&) = delete; + GatordMockService& operator=(const GatordMockService&) = delete; - /// Establish the Unix domain socket and set it to listen for connections. - /// @param udsNamespace the namespace (socket address) associated with the listener. - /// @return true only if the socket has been correctly setup. - static bool OpenListeningSocket(armnnUtils::Sockets::Socket listeningSocket, - const std::string udsNamespace, - const int numOfConnections = 1); + GatordMockService(GatordMockService&&) = delete; + GatordMockService& operator=(GatordMockService&&) = delete; /// Once the connection is open wait to receive the stream meta data packet from the client. Reading this /// packet differs from others as we need to determine endianness. @@ -137,21 +117,6 @@ public: /// Execute the WAIT command from the comamnd file. void WaitCommand(uint32_t timeout); - uint32_t GetStreamMetadataVersion() - { - return m_StreamMetaDataVersion; - } - - uint32_t GetStreamMetadataMaxDataLen() - { - return m_StreamMetaDataMaxDataLen; - } - - uint32_t GetStreamMetadataPid() - { - return m_StreamMetaDataPid; - } - profiling::DirectoryCaptureCommandHandler& GetDirectoryCaptureCommandHandler() { return m_DirectoryCaptureCommandHandler; @@ -167,39 +132,11 @@ public: return m_TimelineDirectoryCaptureCommandHandler; } - private: - void ReceiveLoop(GatordMockService& mockService); - - int MainLoop(armnn::profiling::CommandHandlerRegistry& registry, armnnUtils::Sockets::Socket m_ClientConnection); - - /// Block on the client connection until a complete packet has been received. This is a placeholder function to - /// enable early testing of the tool. - /// @return true if a valid packet has been received. - armnn::profiling::Packet WaitForPacket(uint32_t timeoutMs); - - armnn::profiling::Packet ReceivePacket(); - - bool SendPacket(uint32_t packetFamily, uint32_t packetId, const uint8_t* data, uint32_t dataLength); - - void EchoPacket(PacketDirection direction, uint8_t* packet, size_t lengthInBytes); - - bool ReadHeader(uint32_t headerAsWords[2]); - - bool ReadFromSocket(uint8_t* packetData, uint32_t expectedLength); - - uint32_t ToUint32(uint8_t* data, TargetEndianness endianness); - - void InsertU32(uint32_t value, uint8_t* data, TargetEndianness endianness); - - static const uint32_t PIPE_MAGIC = 0x45495434; + void ReceiveLoop(); - TargetEndianness m_Endianness; - uint32_t m_StreamMetaDataVersion; - uint32_t m_StreamMetaDataMaxDataLen; - uint32_t m_StreamMetaDataPid; + std::unique_ptr m_BasePipeServer; - armnnUtils::Sockets::Socket m_ClientConnection; std::atomic m_PacketsReceivedCount; bool m_EchoPackets; -- cgit v1.2.1