summaryrefslogtreecommitdiff
path: root/unittests/Process/gdb-remote
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2018-07-28 11:09:23 +0000
committerDimitry Andric <dim@FreeBSD.org>2018-07-28 11:09:23 +0000
commitf73363f1dd94996356cefbf24388f561891acf0b (patch)
treee3c31248bdb36eaec5fd833490d4278162dba2a0 /unittests/Process/gdb-remote
parent160ee69dd7ae18978f4068116777639ea98dc951 (diff)
Notes
Diffstat (limited to 'unittests/Process/gdb-remote')
-rw-r--r--unittests/Process/gdb-remote/CMakeLists.txt1
-rw-r--r--unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp20
-rw-r--r--unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp50
-rw-r--r--unittests/Process/gdb-remote/GDBRemoteCommunicationTest.cpp67
4 files changed, 123 insertions, 15 deletions
diff --git a/unittests/Process/gdb-remote/CMakeLists.txt b/unittests/Process/gdb-remote/CMakeLists.txt
index 0ec5554a3d8d..a9951abb37f1 100644
--- a/unittests/Process/gdb-remote/CMakeLists.txt
+++ b/unittests/Process/gdb-remote/CMakeLists.txt
@@ -1,6 +1,7 @@
add_lldb_unittest(ProcessGdbRemoteTests
GDBRemoteClientBaseTest.cpp
GDBRemoteCommunicationClientTest.cpp
+ GDBRemoteCommunicationTest.cpp
GDBRemoteTestUtils.cpp
LINK_LIBS
diff --git a/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp b/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp
index 22b7148af5ba..8ab0afdb9bea 100644
--- a/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp
+++ b/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp
@@ -339,3 +339,23 @@ TEST_F(GDBRemoteClientBaseTest, InterruptNoResponse) {
ASSERT_TRUE(async_result.get());
ASSERT_EQ(eStateInvalid, continue_state.get());
}
+
+TEST_F(GDBRemoteClientBaseTest, SendPacketAndReceiveResponseWithOutputSupport) {
+ StringExtractorGDBRemote response;
+ StreamString command_output;
+
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("O"));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("O48656c6c6f2c"));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("O20"));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("O"));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("O776f726c64"));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("OK"));
+
+ PacketResult result = client.SendPacketAndReceiveResponseWithOutputSupport(
+ "qRcmd,test", response, true,
+ [&command_output](llvm::StringRef output) { command_output << output; });
+
+ ASSERT_EQ(PacketResult::Success, result);
+ ASSERT_EQ("OK", response.GetStringRef());
+ ASSERT_EQ("Hello, world", command_output.GetString().str());
+}
diff --git a/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp b/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
index 1d7632a67a30..41ca091c8f10 100644
--- a/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
+++ b/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
@@ -6,12 +6,10 @@
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
-#include <future>
-
-#include "GDBRemoteTestUtils.h"
-
#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h"
+#include "GDBRemoteTestUtils.h"
#include "lldb/Core/ModuleSpec.h"
+#include "lldb/Host/XML.h"
#include "lldb/Target/MemoryRegionInfo.h"
#include "lldb/Utility/DataBuffer.h"
#include "lldb/Utility/StructuredData.h"
@@ -19,6 +17,8 @@
#include "lldb/lldb-enumerations.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/Testing/Support/Error.h"
+#include "gmock/gmock.h"
+#include <future>
using namespace lldb_private::process_gdb_remote;
using namespace lldb_private;
@@ -43,10 +43,12 @@ void Handle_QThreadSuffixSupported(MockServer &server, bool supported) {
ASSERT_EQ(PacketResult::Success, server.SendUnimplementedResponse(nullptr));
}
-void HandlePacket(MockServer &server, StringRef expected, StringRef response) {
+void HandlePacket(MockServer &server,
+ const testing::Matcher<const std::string &> &expected,
+ StringRef response) {
StringExtractorGDBRemote request;
ASSERT_EQ(PacketResult::Success, server.GetPacket(request));
- ASSERT_EQ(expected, request.GetStringRef());
+ ASSERT_THAT(request.GetStringRef(), expected);
ASSERT_EQ(PacketResult::Success, server.SendPacket(response));
}
@@ -167,14 +169,14 @@ TEST_F(GDBRemoteCommunicationClientTest, GetModulesInfo) {
llvm::Triple triple("i386-pc-linux");
FileSpec file_specs[] = {
- FileSpec("/foo/bar.so", false, FileSpec::ePathSyntaxPosix),
- FileSpec("/foo/baz.so", false, FileSpec::ePathSyntaxPosix),
+ FileSpec("/foo/bar.so", false, FileSpec::Style::posix),
+ FileSpec("/foo/baz.so", false, FileSpec::Style::posix),
// This is a bit dodgy but we currently depend on GetModulesInfo not
// performing denormalization. It can go away once the users
// (DynamicLoaderPOSIXDYLD, at least) correctly set the path syntax for
// the FileSpecs they create.
- FileSpec("/foo/baw.so", false, FileSpec::ePathSyntaxWindows),
+ FileSpec("/foo/baw.so", false, FileSpec::Style::windows),
};
std::future<llvm::Optional<std::vector<ModuleSpec>>> async_result =
std::async(std::launch::async,
@@ -192,7 +194,8 @@ TEST_F(GDBRemoteCommunicationClientTest, GetModulesInfo) {
ASSERT_EQ(1u, result->size());
EXPECT_EQ("/foo/bar.so", result.getValue()[0].GetFileSpec().GetPath());
EXPECT_EQ(triple, result.getValue()[0].GetArchitecture().GetTriple());
- EXPECT_EQ(UUID("@ABCDEFGHIJKLMNO", 16), result.getValue()[0].GetUUID());
+ EXPECT_EQ(UUID::fromData("@ABCDEFGHIJKLMNO", 16),
+ result.getValue()[0].GetUUID());
EXPECT_EQ(0u, result.getValue()[0].GetObjectOffset());
EXPECT_EQ(1234u, result.getValue()[0].GetObjectSize());
}
@@ -200,7 +203,7 @@ TEST_F(GDBRemoteCommunicationClientTest, GetModulesInfo) {
TEST_F(GDBRemoteCommunicationClientTest, GetModulesInfo_UUID20) {
llvm::Triple triple("i386-pc-linux");
- FileSpec file_spec("/foo/bar.so", false, FileSpec::ePathSyntaxPosix);
+ FileSpec file_spec("/foo/bar.so", false, FileSpec::Style::posix);
std::future<llvm::Optional<std::vector<ModuleSpec>>> async_result =
std::async(std::launch::async,
[&] { return client.GetModulesInfo(file_spec, triple); });
@@ -216,14 +219,15 @@ TEST_F(GDBRemoteCommunicationClientTest, GetModulesInfo_UUID20) {
ASSERT_EQ(1u, result->size());
EXPECT_EQ("/foo/bar.so", result.getValue()[0].GetFileSpec().GetPath());
EXPECT_EQ(triple, result.getValue()[0].GetArchitecture().GetTriple());
- EXPECT_EQ(UUID("@ABCDEFGHIJKLMNOPQRS", 20), result.getValue()[0].GetUUID());
+ EXPECT_EQ(UUID::fromData("@ABCDEFGHIJKLMNOPQRS", 20),
+ result.getValue()[0].GetUUID());
EXPECT_EQ(0u, result.getValue()[0].GetObjectOffset());
EXPECT_EQ(1234u, result.getValue()[0].GetObjectSize());
}
TEST_F(GDBRemoteCommunicationClientTest, GetModulesInfoInvalidResponse) {
llvm::Triple triple("i386-pc-linux");
- FileSpec file_spec("/foo/bar.so", false, FileSpec::ePathSyntaxPosix);
+ FileSpec file_spec("/foo/bar.so", false, FileSpec::Style::posix);
const char *invalid_responses[] = {
// no UUID
@@ -323,12 +327,22 @@ TEST_F(GDBRemoteCommunicationClientTest, GetMemoryRegionInfo) {
return client.GetMemoryRegionInfo(addr, region_info);
});
- // name is: /foo/bar.so
HandlePacket(server,
"qMemoryRegionInfo:a000",
"start:a000;size:2000;permissions:rx;name:2f666f6f2f6261722e736f;");
+ if (XMLDocument::XMLEnabled()) {
+ // In case we have XML support, this will also do a "qXfer:memory-map".
+ // Preceeded by a query for supported extensions. Pretend we don't support
+ // that.
+ HandlePacket(server, testing::StartsWith("qSupported:"), "");
+ }
EXPECT_TRUE(result.get().Success());
-
+ EXPECT_EQ(addr, region_info.GetRange().GetRangeBase());
+ EXPECT_EQ(0x2000u, region_info.GetRange().GetByteSize());
+ EXPECT_EQ(MemoryRegionInfo::eYes, region_info.GetReadable());
+ EXPECT_EQ(MemoryRegionInfo::eNo, region_info.GetWritable());
+ EXPECT_EQ(MemoryRegionInfo::eYes, region_info.GetExecutable());
+ EXPECT_EQ("/foo/bar.so", region_info.GetName().GetStringRef());
}
TEST_F(GDBRemoteCommunicationClientTest, GetMemoryRegionInfoInvalidResponse) {
@@ -339,6 +353,12 @@ TEST_F(GDBRemoteCommunicationClientTest, GetMemoryRegionInfoInvalidResponse) {
});
HandlePacket(server, "qMemoryRegionInfo:4000", "start:4000;size:0000;");
+ if (XMLDocument::XMLEnabled()) {
+ // In case we have XML support, this will also do a "qXfer:memory-map".
+ // Preceeded by a query for supported extensions. Pretend we don't support
+ // that.
+ HandlePacket(server, testing::StartsWith("qSupported:"), "");
+ }
EXPECT_FALSE(result.get().Success());
}
diff --git a/unittests/Process/gdb-remote/GDBRemoteCommunicationTest.cpp b/unittests/Process/gdb-remote/GDBRemoteCommunicationTest.cpp
new file mode 100644
index 000000000000..5ae8e700757c
--- /dev/null
+++ b/unittests/Process/gdb-remote/GDBRemoteCommunicationTest.cpp
@@ -0,0 +1,67 @@
+//===-- GDBRemoteCommunicationTest.cpp --------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include "GDBRemoteTestUtils.h"
+#include "llvm/Testing/Support/Error.h"
+
+using namespace lldb_private::process_gdb_remote;
+using namespace lldb_private;
+using namespace lldb;
+typedef GDBRemoteCommunication::PacketResult PacketResult;
+
+namespace {
+
+class TestClient : public GDBRemoteCommunication {
+public:
+ TestClient()
+ : GDBRemoteCommunication("test.client", "test.client.listener") {}
+
+ PacketResult ReadPacket(StringExtractorGDBRemote &response) {
+ return GDBRemoteCommunication::ReadPacket(response, std::chrono::seconds(1),
+ /*sync_on_timeout*/ false);
+ }
+};
+
+class GDBRemoteCommunicationTest : public GDBRemoteTest {
+public:
+ void SetUp() override {
+ ASSERT_THAT_ERROR(Connect(client, server), llvm::Succeeded());
+ }
+
+protected:
+ TestClient client;
+ MockServer server;
+
+ bool Write(llvm::StringRef packet) {
+ ConnectionStatus status;
+ return server.Write(packet.data(), packet.size(), status, nullptr) ==
+ packet.size();
+ }
+};
+} // end anonymous namespace
+
+TEST_F(GDBRemoteCommunicationTest, ReadPacket_checksum) {
+ struct TestCase {
+ llvm::StringLiteral Packet;
+ llvm::StringLiteral Payload;
+ };
+ static constexpr TestCase Tests[] = {
+ {{"$#00"}, {""}},
+ {{"$foobar#79"}, {"foobar"}},
+ {{"$}}#fa"}, {"]"}},
+ {{"$x*%#c7"}, {"xxxxxxxxx"}},
+ };
+ for (const auto &Test : Tests) {
+ SCOPED_TRACE(Test.Packet + " -> " + Test.Payload);
+ StringExtractorGDBRemote response;
+ ASSERT_TRUE(Write(Test.Packet));
+ ASSERT_EQ(PacketResult::Success, client.ReadPacket(response));
+ ASSERT_EQ(Test.Payload, response.GetStringRef());
+ ASSERT_EQ(PacketResult::Success, server.GetAck());
+ }
+}