summaryrefslogtreecommitdiffstats
path: root/lldb/unittests/Process
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/unittests/Process')
-rw-r--r--lldb/unittests/Process/gdb-remote/CMakeLists.txt1
-rw-r--r--lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationServerTest.cpp73
-rw-r--r--lldb/unittests/Process/gdb-remote/GDBRemoteTestUtils.h44
3 files changed, 117 insertions, 1 deletions
diff --git a/lldb/unittests/Process/gdb-remote/CMakeLists.txt b/lldb/unittests/Process/gdb-remote/CMakeLists.txt
index a9951abb37f..abb30e022e4 100644
--- a/lldb/unittests/Process/gdb-remote/CMakeLists.txt
+++ b/lldb/unittests/Process/gdb-remote/CMakeLists.txt
@@ -1,6 +1,7 @@
add_lldb_unittest(ProcessGdbRemoteTests
GDBRemoteClientBaseTest.cpp
GDBRemoteCommunicationClientTest.cpp
+ GDBRemoteCommunicationServerTest.cpp
GDBRemoteCommunicationTest.cpp
GDBRemoteTestUtils.cpp
diff --git a/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationServerTest.cpp b/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationServerTest.cpp
new file mode 100644
index 00000000000..a73f7b462a8
--- /dev/null
+++ b/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationServerTest.cpp
@@ -0,0 +1,73 @@
+//===-- GDBRemoteCommunicationServerTest.cpp --------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+#include "gmock/gmock.h"
+#include "gtest/gtest.h"
+
+#include "GDBRemoteTestUtils.h"
+
+#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h"
+#include "lldb/Utility/Connection.h"
+
+namespace lldb_private {
+namespace process_gdb_remote {
+
+TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_ErrorNumber) {
+ MockServerWithMockConnection server;
+ server.SendErrorResponse(0x42);
+
+ EXPECT_THAT(server.GetPackets(), testing::ElementsAre("$E42#ab"));
+}
+
+TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_Status) {
+ MockServerWithMockConnection server;
+ Status status;
+
+ status.SetError(0x42, lldb::eErrorTypeGeneric);
+ status.SetErrorString("Test error message");
+ server.SendErrorResponse(status);
+
+ EXPECT_THAT(
+ server.GetPackets(),
+ testing::ElementsAre("$E42;54657374206572726f72206d657373616765#ad"));
+}
+
+TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_UnimplementedError) {
+ MockServerWithMockConnection server;
+
+ auto error =
+ llvm::make_error<PacketUnimplementedError>("Test unimplemented error");
+ server.SendErrorResponse(std::move(error));
+
+ EXPECT_THAT(server.GetPackets(), testing::ElementsAre("$#00"));
+}
+
+TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_StringError) {
+ MockServerWithMockConnection server;
+
+ auto error = llvm::createStringError(llvm::inconvertibleErrorCode(),
+ "String error test");
+ server.SendErrorResponse(std::move(error));
+
+ EXPECT_THAT(
+ server.GetPackets(),
+ testing::ElementsAre("$Eff;537472696e67206572726f722074657374#b0"));
+}
+
+TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_ErrorList) {
+ MockServerWithMockConnection server;
+
+ auto error = llvm::joinErrors(llvm::make_error<PacketUnimplementedError>(),
+ llvm::make_error<PacketUnimplementedError>());
+
+ server.SendErrorResponse(std::move(error));
+ // Make sure only one packet is sent even when there are multiple errors.
+ EXPECT_EQ(server.GetPackets().size(), 1UL);
+}
+
+} // namespace process_gdb_remote
+} // namespace lldb_private
diff --git a/lldb/unittests/Process/gdb-remote/GDBRemoteTestUtils.h b/lldb/unittests/Process/gdb-remote/GDBRemoteTestUtils.h
index 0f021442a2c..76f92d84be0 100644
--- a/lldb/unittests/Process/gdb-remote/GDBRemoteTestUtils.h
+++ b/lldb/unittests/Process/gdb-remote/GDBRemoteTestUtils.h
@@ -8,9 +8,11 @@
#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 {
@@ -21,10 +23,38 @@ public:
static void TearDownTestCase();
};
-struct MockServer : public GDBRemoteCommunicationServer {
+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) {
@@ -37,10 +67,22 @@ struct MockServer : public GDBRemoteCommunicationServer {
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
OpenPOWER on IntegriCloud