reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
//===-- 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;
  };

  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