summaryrefslogtreecommitdiffstats
path: root/lldb/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp
diff options
context:
space:
mode:
authorTodd Fiala <todd.fiala@gmail.com>2016-09-10 00:06:29 +0000
committerTodd Fiala <todd.fiala@gmail.com>2016-09-10 00:06:29 +0000
commitfcdb1af655a80b4f1b4f17929235613216ebaaf5 (patch)
treee1fd91a5b83d1e68fb2821b7021d91daf372eb58 /lldb/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp
parent99b555709e69348af3e23be8e8ed6686264998a5 (diff)
downloadbcm5719-llvm-fcdb1af655a80b4f1b4f17929235613216ebaaf5.tar.gz
bcm5719-llvm-fcdb1af655a80b4f1b4f17929235613216ebaaf5.zip
async structured data packet handling improvements
This change does the following: * Changes the signature for the continuation delegate method that handles async structured data from accepting an already-parsed structured data element to taking just the packet contents. * Moves the conversion of the JSON-async: packet contents from GDBRemoteClientBase to the continuation delegate method. * Adds a new unit test for verifying that the $JSON-asyc: packets get decoded and that the decoded packets get forwarded on to the delegate for further processing. Thanks to Pavel for making that whole section of code easily unit testable! * Tightens up the packet verification on reception of a $JSON-async: packet contents. The code prior to this change is susceptible to a segfault if a packet is carefully crafted that starts with $J but has a total length shorter than the length of "$JSON-async:". Reviewers: labath, clayborg, zturner Differential Revision: https://reviews.llvm.org/D23884 llvm-svn: 281121
Diffstat (limited to 'lldb/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp')
-rw-r--r--lldb/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp38
1 files changed, 35 insertions, 3 deletions
diff --git a/lldb/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp b/lldb/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp
index c9d4544add2..0e74d88f2cd 100644
--- a/lldb/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp
+++ b/lldb/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp
@@ -20,6 +20,7 @@
#include "Plugins/Process/Utility/LinuxSignals.h"
#include "Plugins/Process/gdb-remote/GDBRemoteClientBase.h"
#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h"
+#include "lldb/Core/StreamGDBRemote.h"
#include "llvm/ADT/STLExtras.h"
@@ -34,14 +35,14 @@ struct MockDelegate : public GDBRemoteClientBase::ContinueDelegate {
std::string output;
std::string misc_data;
unsigned stop_reply_called = 0;
+ std::vector<std::string> structured_data_packets;
void HandleAsyncStdout(llvm::StringRef out) { output += out; }
void HandleAsyncMisc(llvm::StringRef data) { misc_data += data; }
void HandleStopReply() { ++stop_reply_called; }
- bool HandleAsyncStructuredData(const StructuredData::ObjectSP &object_sp) {
- // TODO work in a test here after I fix the gtest breakage.
- return true;
+ void HandleAsyncStructuredDataPacket(llvm::StringRef data) {
+ structured_data_packets.push_back(data);
}
};
@@ -321,6 +322,37 @@ TEST_F(GDBRemoteClientBaseTest, SendContinueDelegateInterface) {
EXPECT_EQ(1u, fix.delegate.stop_reply_called);
}
+TEST_F(GDBRemoteClientBaseTest, SendContinueDelegateStructuredDataReceipt) {
+ // Build the plain-text version of the JSON data we will have the
+ // server send.
+ const std::string json_payload =
+ "{ \"type\": \"MyFeatureType\", "
+ " \"elements\": [ \"entry1\", \"entry2\" ] }";
+ const std::string json_packet = "JSON-async:" + json_payload;
+
+ // Escape it properly for transit.
+ StreamGDBRemote stream;
+ stream.PutEscapedBytes(json_packet.c_str(), json_packet.length());
+ stream.Flush();
+
+ // Set up the
+ StringExtractorGDBRemote response;
+ ContinueFixture fix;
+ if (HasFailure())
+ return;
+
+ // Send async structured data packet, then stop.
+ ASSERT_EQ(PacketResult::Success, fix.server.SendPacket(stream.GetData()));
+ ASSERT_EQ(PacketResult::Success, fix.server.SendPacket("T01"));
+ ASSERT_EQ(eStateStopped, fix.SendCPacket(response));
+ ASSERT_EQ("T01", response.GetStringRef());
+ ASSERT_EQ(1, fix.delegate.structured_data_packets.size());
+
+ // Verify the packet contents. It should have been unescaped upon packet
+ // reception.
+ ASSERT_EQ(json_packet, fix.delegate.structured_data_packets[0]);
+}
+
TEST_F(GDBRemoteClientBaseTest, InterruptNoResponse) {
StringExtractorGDBRemote continue_response, response;
ContinueFixture fix;
OpenPOWER on IntegriCloud