blob: 6ab37599ae36bbdc45a53c0dcdbabc8c41068f64 [file] [log] [blame]
Raphael Isemann80814282020-01-24 08:23:27 +01001//===-- GDBRemoteCommunicationServerTest.cpp ------------------------------===//
Antonio Afonso57e2da42019-06-10 20:59:58 +00002//
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"
Antonio Afonso57e2da42019-06-10 20:59:58 +000012#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h"
13#include "lldb/Utility/Connection.h"
Pavel Labathe2f1fe32020-10-09 11:23:17 +020014#include "lldb/Utility/UnimplementedError.h"
Antonio Afonso57e2da42019-06-10 20:59:58 +000015
16namespace lldb_private {
17namespace process_gdb_remote {
18
19TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_ErrorNumber) {
20 MockServerWithMockConnection server;
21 server.SendErrorResponse(0x42);
22
23 EXPECT_THAT(server.GetPackets(), testing::ElementsAre("$E42#ab"));
24}
25
26TEST(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
39TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_UnimplementedError) {
40 MockServerWithMockConnection server;
41
Pavel Labathe2f1fe32020-10-09 11:23:17 +020042 auto error = llvm::make_error<UnimplementedError>();
Antonio Afonso57e2da42019-06-10 20:59:58 +000043 server.SendErrorResponse(std::move(error));
44
45 EXPECT_THAT(server.GetPackets(), testing::ElementsAre("$#00"));
46}
47
48TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_StringError) {
49 MockServerWithMockConnection server;
50
51 auto error = llvm::createStringError(llvm::inconvertibleErrorCode(),
52 "String error test");
53 server.SendErrorResponse(std::move(error));
54
55 EXPECT_THAT(
56 server.GetPackets(),
57 testing::ElementsAre("$Eff;537472696e67206572726f722074657374#b0"));
58}
59
60TEST(GDBRemoteCommunicationServerTest, SendErrorResponse_ErrorList) {
61 MockServerWithMockConnection server;
62
Pavel Labathe2f1fe32020-10-09 11:23:17 +020063 auto error = llvm::joinErrors(llvm::make_error<UnimplementedError>(),
64 llvm::make_error<UnimplementedError>());
Antonio Afonso57e2da42019-06-10 20:59:58 +000065
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);
69}
70
71} // namespace process_gdb_remote
72} // namespace lldb_private