[AArch64,ELF] Restrict MOVZ/MOVK to non-PIC large code model (#70178)
[llvm-project.git] / lldb / unittests / Process / gdb-remote / GDBRemoteTestUtils.h
blobef7593dc4443258cc67ac90356304279b9d361c2
1 //===-- GDBRemoteTestUtils.h ------------------------------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 #ifndef LLDB_UNITTESTS_PROCESS_GDB_REMOTE_GDBREMOTETESTUTILS_H
9 #define LLDB_UNITTESTS_PROCESS_GDB_REMOTE_GDBREMOTETESTUTILS_H
11 #include "gmock/gmock.h"
12 #include "gtest/gtest.h"
14 #include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h"
15 #include "lldb/Utility/Connection.h"
17 namespace lldb_private {
18 namespace process_gdb_remote {
20 class GDBRemoteTest : public testing::Test {
21 public:
22 static void SetUpTestCase();
23 static void TearDownTestCase();
26 class MockConnection : public lldb_private::Connection {
27 public:
28 MockConnection(std::vector<std::string> &packets) { m_packets = &packets; };
30 MOCK_METHOD2(Connect,
31 lldb::ConnectionStatus(llvm::StringRef url, Status *error_ptr));
32 MOCK_METHOD5(Read, size_t(void *dst, size_t dst_len,
33 const Timeout<std::micro> &timeout,
34 lldb::ConnectionStatus &status, Status *error_ptr));
35 MOCK_METHOD0(GetURI, std::string());
36 MOCK_METHOD0(InterruptRead, bool());
38 lldb::ConnectionStatus Disconnect(Status *error_ptr) {
39 return lldb::eConnectionStatusSuccess;
42 bool IsConnected() const { return true; };
43 size_t Write(const void *dst, size_t dst_len, lldb::ConnectionStatus &status,
44 Status *error_ptr) {
45 m_packets->emplace_back(static_cast<const char *>(dst), dst_len);
46 return dst_len;
49 lldb::IOObjectSP GetReadObject() { return lldb::IOObjectSP(); }
51 std::vector<std::string> *m_packets;
54 class MockServer : public GDBRemoteCommunicationServer {
55 public:
56 MockServer() : GDBRemoteCommunicationServer() {
57 m_send_acks = false;
58 m_send_error_strings = true;
61 PacketResult SendPacket(llvm::StringRef payload) {
62 return GDBRemoteCommunicationServer::SendPacketNoLock(payload);
65 PacketResult GetPacket(StringExtractorGDBRemote &response) {
66 const bool sync_on_timeout = false;
67 return ReadPacket(response, std::chrono::seconds(1), sync_on_timeout);
70 using GDBRemoteCommunicationServer::SendErrorResponse;
71 using GDBRemoteCommunicationServer::SendOKResponse;
72 using GDBRemoteCommunicationServer::SendUnimplementedResponse;
75 class MockServerWithMockConnection : public MockServer {
76 public:
77 MockServerWithMockConnection() : MockServer() {
78 SetConnection(std::make_unique<MockConnection>(m_packets));
81 llvm::ArrayRef<std::string> GetPackets() { return m_packets; };
83 std::vector<std::string> m_packets;
86 } // namespace process_gdb_remote
87 } // namespace lldb_private
89 #endif // LLDB_UNITTESTS_PROCESS_GDB_REMOTE_GDBREMOTETESTUTILS_H