diff options
author | 2020-08-03 14:33:06 +0000 | |
---|---|---|
committer | 2020-08-03 14:33:06 +0000 | |
commit | 061da546b983eb767bad15e67af1174fb0bcf31c (patch) | |
tree | 83c78b820819d70aa40c36d90447978b300078c5 /gnu/llvm/lldb/unittests/Process/gdb-remote/GDBRemoteTestUtils.h | |
parent | Import LLVM 10.0.0 release including clang, lld and lldb. (diff) | |
download | wireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.tar.xz wireguard-openbsd-061da546b983eb767bad15e67af1174fb0bcf31c.zip |
Import LLVM 10.0.0 release including clang, lld and lldb.
ok hackroom
tested by plenty
Diffstat (limited to 'gnu/llvm/lldb/unittests/Process/gdb-remote/GDBRemoteTestUtils.h')
-rw-r--r-- | gnu/llvm/lldb/unittests/Process/gdb-remote/GDBRemoteTestUtils.h | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/gnu/llvm/lldb/unittests/Process/gdb-remote/GDBRemoteTestUtils.h b/gnu/llvm/lldb/unittests/Process/gdb-remote/GDBRemoteTestUtils.h new file mode 100644 index 00000000000..53e94a39e8b --- /dev/null +++ b/gnu/llvm/lldb/unittests/Process/gdb-remote/GDBRemoteTestUtils.h @@ -0,0 +1,91 @@ +//===-- GDBRemoteTestUtils.h ------------------------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +#ifndef lldb_unittests_Process_gdb_remote_GDBRemoteTestUtils_h +#define lldb_unittests_Process_gdb_remote_GDBRemoteTestUtils_h + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h" +#include "lldb/Utility/Connection.h" + +namespace lldb_private { +namespace process_gdb_remote { + +class GDBRemoteTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); +}; + +class MockConnection : public lldb_private::Connection { +public: + MockConnection(std::vector<std::string> &packets) { m_packets = &packets; }; + + MOCK_METHOD2(Connect, + lldb::ConnectionStatus(llvm::StringRef url, Status *error_ptr)); + MOCK_METHOD5(Read, size_t(void *dst, size_t dst_len, + const Timeout<std::micro> &timeout, + lldb::ConnectionStatus &status, Status *error_ptr)); + MOCK_METHOD0(GetURI, std::string()); + MOCK_METHOD0(InterruptRead, bool()); + + lldb::ConnectionStatus Disconnect(Status *error_ptr) { + return lldb::eConnectionStatusSuccess; + }; + + bool IsConnected() const { return true; }; + size_t Write(const void *dst, size_t dst_len, lldb::ConnectionStatus &status, + Status *error_ptr) { + m_packets->emplace_back(static_cast<const char *>(dst), dst_len); + return dst_len; + }; + + lldb::IOObjectSP GetReadObject() { return lldb::IOObjectSP(); } + + std::vector<std::string> *m_packets; +}; + +class MockServer : public GDBRemoteCommunicationServer { +public: + MockServer() + : GDBRemoteCommunicationServer("mock-server", "mock-server.listener") { + m_send_acks = false; + m_send_error_strings = true; + } + + PacketResult SendPacket(llvm::StringRef payload) { + return GDBRemoteCommunicationServer::SendPacketNoLock(payload); + } + + PacketResult GetPacket(StringExtractorGDBRemote &response) { + const bool sync_on_timeout = false; + return WaitForPacketNoLock(response, std::chrono::seconds(1), + sync_on_timeout); + } + + using GDBRemoteCommunicationServer::SendErrorResponse; + using GDBRemoteCommunicationServer::SendOKResponse; + using GDBRemoteCommunicationServer::SendUnimplementedResponse; +}; + +class MockServerWithMockConnection : public MockServer { +public: + MockServerWithMockConnection() : MockServer() { + SetConnection(new MockConnection(m_packets)); + } + + llvm::ArrayRef<std::string> GetPackets() { return m_packets; }; + + std::vector<std::string> m_packets; +}; + +} // namespace process_gdb_remote +} // namespace lldb_private + +#endif // lldb_unittests_Process_gdb_remote_GDBRemoteTestUtils_h |