| 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 | #include "lldb/lldb-enumerations.h" |
| 16 | |
| 17 | namespace lldb_private { |
| 18 | namespace process_gdb_remote { |
| 19 | |
| 20 | TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_ErrorNumber) { |
| 21 | MockServerWithMockConnection server; |
| 22 | server.SendErrorResponse(error: 0x42); |
| 23 | |
| 24 | EXPECT_THAT(server.GetPackets(), testing::ElementsAre("$E42#ab" )); |
| 25 | } |
| 26 | |
| 27 | TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_Status) { |
| 28 | MockServerWithMockConnection server; |
| 29 | Status status(0x42, lldb::eErrorTypePOSIX, "Test error message" ); |
| 30 | server.SendErrorResponse(error: status); |
| 31 | |
| 32 | EXPECT_THAT( |
| 33 | server.GetPackets(), |
| 34 | testing::ElementsAre("$E42;54657374206572726f72206d657373616765#ad" )); |
| 35 | } |
| 36 | |
| 37 | TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_UnimplementedError) { |
| 38 | MockServerWithMockConnection server; |
| 39 | |
| 40 | auto error = llvm::make_error<UnimplementedError>(); |
| 41 | server.SendErrorResponse(error: std::move(error)); |
| 42 | |
| 43 | EXPECT_THAT(server.GetPackets(), testing::ElementsAre("$#00" )); |
| 44 | } |
| 45 | |
| 46 | TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_StringError) { |
| 47 | MockServerWithMockConnection server; |
| 48 | |
| 49 | auto error = llvm::createStringError(EC: llvm::inconvertibleErrorCode(), |
| 50 | S: "String error test" ); |
| 51 | server.SendErrorResponse(error: std::move(error)); |
| 52 | |
| 53 | EXPECT_THAT( |
| 54 | server.GetPackets(), |
| 55 | testing::ElementsAre("$Eff;537472696e67206572726f722074657374#b0" )); |
| 56 | } |
| 57 | |
| 58 | TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_ErrorList) { |
| 59 | MockServerWithMockConnection server; |
| 60 | |
| 61 | auto error = llvm::joinErrors(E1: llvm::make_error<UnimplementedError>(), |
| 62 | E2: llvm::make_error<UnimplementedError>()); |
| 63 | |
| 64 | server.SendErrorResponse(error: std::move(error)); |
| 65 | // Make sure only one packet is sent even when there are multiple errors. |
| 66 | EXPECT_EQ(server.GetPackets().size(), 1UL); |
| 67 | } |
| 68 | |
| 69 | } // namespace process_gdb_remote |
| 70 | } // namespace lldb_private |
| 71 | |