[mlir][IntRangeInference] Fix `arith.ceildivsi` range inference when it includes...
[llvm-project.git] / lldb / unittests / Process / gdb-remote / GDBRemoteCommunicationTest.cpp
blob425f6cfcd5bc9ed66714db8877d539b8635f5eff
1 //===-- GDBRemoteCommunicationTest.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 "GDBRemoteTestUtils.h"
9 #include "llvm/Testing/Support/Error.h"
11 using namespace lldb_private::process_gdb_remote;
12 using namespace lldb_private;
13 using namespace lldb;
14 typedef GDBRemoteCommunication::PacketResult PacketResult;
16 namespace {
18 class TestClient : public GDBRemoteCommunication {
19 public:
20 TestClient() : GDBRemoteCommunication() {}
22 PacketResult ReadPacket(StringExtractorGDBRemote &response) {
23 return GDBRemoteCommunication::ReadPacket(response, std::chrono::seconds(1),
24 /*sync_on_timeout*/ false);
28 class GDBRemoteCommunicationTest : public GDBRemoteTest {
29 public:
30 void SetUp() override {
31 ASSERT_THAT_ERROR(GDBRemoteCommunication::ConnectLocally(client, server),
32 llvm::Succeeded());
35 protected:
36 TestClient client;
37 MockServer server;
39 bool Write(llvm::StringRef packet) {
40 ConnectionStatus status;
41 return server.WriteAll(packet.data(), packet.size(), status, nullptr) ==
42 packet.size();
45 } // end anonymous namespace
47 // Test that we can decode packets correctly. In particular, verify that
48 // checksum calculation works.
49 TEST_F(GDBRemoteCommunicationTest, ReadPacket) {
50 struct TestCase {
51 llvm::StringLiteral Packet;
52 llvm::StringLiteral Payload;
54 static constexpr TestCase Tests[] = {
55 {{"$#00"}, {""}},
56 {{"$foobar#79"}, {"foobar"}},
57 {{"$}]#da"}, {"}"}}, // Escaped }
58 {{"$x*%#c7"}, {"xxxxxxxxx"}}, // RLE
59 {{"+$#00"}, {""}}, // Spurious ACK
60 {{"-$#00"}, {""}}, // Spurious NAK
62 for (const auto &Test : Tests) {
63 SCOPED_TRACE(Test.Packet + " -> " + Test.Payload);
64 StringExtractorGDBRemote response;
65 ASSERT_TRUE(Write(Test.Packet));
66 ASSERT_EQ(PacketResult::Success, client.ReadPacket(response));
67 ASSERT_EQ(Test.Payload, response.GetStringRef());
68 ASSERT_EQ(PacketResult::Success, server.GetAck());