1 //===-- GDBRemoteCommunicationServerTest.cpp ------------------------------===//
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
7 //===----------------------------------------------------------------------===//
8 #include "gmock/gmock.h"
9 #include "gtest/gtest.h"
11 #include "GDBRemoteTestUtils.h"
12 #include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h"
13 #include "lldb/Utility/Connection.h"
14 #include "lldb/Utility/UnimplementedError.h"
16 namespace lldb_private
{
17 namespace process_gdb_remote
{
19 TEST(GDBRemoteCommunicationServerTest
, SendErrorResponse_ErrorNumber
) {
20 MockServerWithMockConnection server
;
21 server
.SendErrorResponse(0x42);
23 EXPECT_THAT(server
.GetPackets(), testing::ElementsAre("$E42#ab"));
26 TEST(GDBRemoteCommunicationServerTest
, SendErrorResponse_Status
) {
27 MockServerWithMockConnection server
;
30 status
.SetError(0x42, lldb::eErrorTypeGeneric
);
31 status
.SetErrorString("Test error message");
32 server
.SendErrorResponse(status
);
36 testing::ElementsAre("$E42;54657374206572726f72206d657373616765#ad"));
39 TEST(GDBRemoteCommunicationServerTest
, SendErrorResponse_UnimplementedError
) {
40 MockServerWithMockConnection server
;
42 auto error
= llvm::make_error
<UnimplementedError
>();
43 server
.SendErrorResponse(std::move(error
));
45 EXPECT_THAT(server
.GetPackets(), testing::ElementsAre("$#00"));
48 TEST(GDBRemoteCommunicationServerTest
, SendErrorResponse_StringError
) {
49 MockServerWithMockConnection server
;
51 auto error
= llvm::createStringError(llvm::inconvertibleErrorCode(),
53 server
.SendErrorResponse(std::move(error
));
57 testing::ElementsAre("$Eff;537472696e67206572726f722074657374#b0"));
60 TEST(GDBRemoteCommunicationServerTest
, SendErrorResponse_ErrorList
) {
61 MockServerWithMockConnection server
;
63 auto error
= llvm::joinErrors(llvm::make_error
<UnimplementedError
>(),
64 llvm::make_error
<UnimplementedError
>());
66 server
.SendErrorResponse(std::move(error
));
67 // Make sure only one packet is sent even when there are multiple errors.
68 EXPECT_EQ(server
.GetPackets().size(), 1UL);
71 } // namespace process_gdb_remote
72 } // namespace lldb_private