diff options
author | Colm Donelan <Colm.Donelan@arm.com> | 2019-09-09 11:59:08 +0100 |
---|---|---|
committer | Matteo Martincigh <matteo.martincigh@arm.com> | 2019-09-09 16:24:39 +0000 |
commit | a85e215dd1b027c5ef88621d1b4d5f6e078605da (patch) | |
tree | 2c5b1046788ad231daaecdedad08519ee8ae1a39 /tests/profiling/GatordMockService.cpp | |
parent | 8fccd86b95be418d1b0397bfd5f48a319f210180 (diff) | |
download | armnn-a85e215dd1b027c5ef88621d1b4d5f6e078605da.tar.gz |
IVGCVSW-3720 Start a UDS server that accepts connections.
* Add a CLI paramter to the Gatord mock client to specify a namespace.
* Open a listening socket on that namespace.
* Wait for one connection on the socket.
Signed-off-by: Colm Donelan <Colm.Donelan@arm.com>
Change-Id: Ic85b4defd5ad2010bb255472c030a91a23cec1d9
Diffstat (limited to 'tests/profiling/GatordMockService.cpp')
-rw-r--r-- | tests/profiling/GatordMockService.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/profiling/GatordMockService.cpp b/tests/profiling/GatordMockService.cpp new file mode 100644 index 0000000000..c774ab0b45 --- /dev/null +++ b/tests/profiling/GatordMockService.cpp @@ -0,0 +1,71 @@ +// +// Copyright © 2019 Arm Ltd. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "GatordMockService.hpp" + +#include <cerrno> +#include <fcntl.h> +#include <iostream> +#include <string> +#include <sys/socket.h> +#include <sys/un.h> + +namespace armnn +{ + +namespace gatordmock +{ + + +bool GatordMockService::OpenListeningSocket(std::string udsNamespace) +{ + m_ListeningSocket = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); + if (-1 == m_ListeningSocket) + { + std::cerr << ": Socket construction failed: " << strerror(errno) << std::endl; + return false; + } + + sockaddr_un udsAddress; + memset(&udsAddress, 0, sizeof(sockaddr_un)); + // We've set the first element of sun_path to be 0, skip over it and copy the namespace after it. + memcpy(udsAddress.sun_path + 1, udsNamespace.c_str(), strlen(udsNamespace.c_str())); + udsAddress.sun_family = AF_UNIX; + + // Bind the socket to the UDS namespace. + if (-1 == bind(m_ListeningSocket, reinterpret_cast<const sockaddr *>(&udsAddress), sizeof(sockaddr_un))) + { + std::cerr << ": Binding on socket failed: " << strerror(errno) << std::endl; + return false; + } + // Listen for 1 connection. + if (-1 == listen(m_ListeningSocket, 1)) + { + std::cerr << ": Listen call on socket failed: " << strerror(errno) << std::endl; + return false; + } + std::cout << "Bound to UDS namespace: \\0" << udsNamespace << std::endl; + return true; +} + +int GatordMockService::BlockForOneClient() +{ + std::cout << "Waiting for client connection." << std::endl; + + int accepted = accept4(m_ListeningSocket, nullptr, nullptr, SOCK_CLOEXEC); + if (-1 == accepted) + { + std::cerr << ": Failure when waiting for a client connection: " << strerror(errno) << std::endl; + return -1; + } + + std::cout << "Client connection established." << std::endl; + return accepted; +} + + +} // namespace gatordmock + +} // namespace armnn |