1 | //===-- GDBRemoteCommunicationServerTest.cpp ------------------------------===// |
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 | #include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h" |
13 | #include "lldb/Utility/Connection.h" |
14 | #include "lldb/Utility/UnimplementedError.h" |
15 | |
16 | namespace lldb_private { |
17 | namespace process_gdb_remote { |
18 | |
19 | TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_ErrorNumber) { |
20 | MockServerWithMockConnection server; |
21 | server.SendErrorResponse(error: 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(err: 0x42, type: lldb::eErrorTypeGeneric); |
31 | status.SetErrorString("Test error message" ); |
32 | server.SendErrorResponse(error: 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 = llvm::make_error<UnimplementedError>(); |
43 | server.SendErrorResponse(error: std::move(error)); |
44 | |
45 | EXPECT_THAT(server.GetPackets(), testing::ElementsAre("$#00" )); |
46 | } |
47 | |
48 | TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_StringError) { |
49 | MockServerWithMockConnection server; |
50 | |
51 | auto error = llvm::createStringError(EC: llvm::inconvertibleErrorCode(), |
52 | Msg: "String error test" ); |
53 | server.SendErrorResponse(error: std::move(error)); |
54 | |
55 | EXPECT_THAT( |
56 | server.GetPackets(), |
57 | testing::ElementsAre("$Eff;537472696e67206572726f722074657374#b0" )); |
58 | } |
59 | |
60 | TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_ErrorList) { |
61 | MockServerWithMockConnection server; |
62 | |
63 | auto error = llvm::joinErrors(E1: llvm::make_error<UnimplementedError>(), |
64 | E2: llvm::make_error<UnimplementedError>()); |
65 | |
66 | server.SendErrorResponse(error: std::move(error)); |
67 | // Make sure only one packet is sent even when there are multiple errors. |
68 | EXPECT_EQ(server.GetPackets().size(), 1UL); |
69 | } |
70 | |
71 | } // namespace process_gdb_remote |
72 | } // namespace lldb_private |
73 | |