xref: /llvm-project/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationServerTest.cpp (revision 57e2da4f325f707bcde5ad42a1c8586c17ac360d)
1 //===-- GDBRemoteCommunicationServerTest.cpp --------------------*- 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 #include "gmock/gmock.h"
9 #include "gtest/gtest.h"
10 
11 #include "GDBRemoteTestUtils.h"
12 
13 #include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h"
14 #include "lldb/Utility/Connection.h"
15 
16 namespace lldb_private {
17 namespace process_gdb_remote {
18 
19 TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_ErrorNumber) {
20   MockServerWithMockConnection server;
21   server.SendErrorResponse(0x42);
22 
23   EXPECT_THAT(server.GetPackets(), testing::ElementsAre("$E42#ab"));
24 }
25 
26 TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_Status) {
27   MockServerWithMockConnection server;
28   Status status;
29 
30   status.SetError(0x42, lldb::eErrorTypeGeneric);
31   status.SetErrorString("Test error message");
32   server.SendErrorResponse(status);
33 
34   EXPECT_THAT(
35       server.GetPackets(),
36       testing::ElementsAre("$E42;54657374206572726f72206d657373616765#ad"));
37 }
38 
39 TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_UnimplementedError) {
40   MockServerWithMockConnection server;
41 
42   auto error =
43       llvm::make_error<PacketUnimplementedError>("Test unimplemented error");
44   server.SendErrorResponse(std::move(error));
45 
46   EXPECT_THAT(server.GetPackets(), testing::ElementsAre("$#00"));
47 }
48 
49 TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_StringError) {
50   MockServerWithMockConnection server;
51 
52   auto error = llvm::createStringError(llvm::inconvertibleErrorCode(),
53                                        "String error test");
54   server.SendErrorResponse(std::move(error));
55 
56   EXPECT_THAT(
57       server.GetPackets(),
58       testing::ElementsAre("$Eff;537472696e67206572726f722074657374#b0"));
59 }
60 
61 TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_ErrorList) {
62   MockServerWithMockConnection server;
63 
64   auto error = llvm::joinErrors(llvm::make_error<PacketUnimplementedError>(),
65                                 llvm::make_error<PacketUnimplementedError>());
66 
67   server.SendErrorResponse(std::move(error));
68   // Make sure only one packet is sent even when there are multiple errors.
69   EXPECT_EQ(server.GetPackets().size(), 1UL);
70 }
71 
72 } // namespace process_gdb_remote
73 } // namespace lldb_private
74