summaryrefslogtreecommitdiffstats
path: root/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp')
-rw-r--r--lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp225
1 files changed, 225 insertions, 0 deletions
diff --git a/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp b/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
index 56a7e74269a..71aeb789016 100644
--- a/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
+++ b/lldb/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
@@ -13,6 +13,7 @@
#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h"
#include "lldb/Core/ModuleSpec.h"
#include "lldb/Core/StructuredData.h"
+#include "lldb/Core/TraceOptions.h"
#include "lldb/Target/MemoryRegionInfo.h"
#include "lldb/Utility/DataBuffer.h"
@@ -370,3 +371,227 @@ TEST_F(GDBRemoteCommunicationClientTest, GetMemoryRegionInfoInvalidResponse) {
HandlePacket(server, "qMemoryRegionInfo:4000", "start:4000;size:0000;");
EXPECT_FALSE(result.get().Success());
}
+
+TEST_F(GDBRemoteCommunicationClientTest, SendStartTracePacket) {
+ TestClient client;
+ MockServer server;
+ Connect(client, server);
+ if (HasFailure())
+ return;
+
+ TraceOptions options;
+ Status error;
+
+ options.setType(lldb::TraceType::eTraceTypeProcessorTrace);
+ options.setMetaDataBufferSize(8192);
+ options.setTraceBufferSize(8192);
+ options.setThreadID(0x23);
+
+ StructuredData::DictionarySP custom_params =
+ std::make_shared<StructuredData::Dictionary>();
+ custom_params->AddStringItem("tracetech", "intel-pt");
+ custom_params->AddIntegerItem("psb", 0x01);
+
+ options.setTraceParams(custom_params);
+
+ std::future<lldb::user_id_t> result = std::async(std::launch::async, [&] {
+ return client.SendStartTracePacket(options, error);
+ });
+
+ // Since the line is exceeding 80 characters.
+ std::string expected_packet1 =
+ R"(jTraceStart:{"buffersize" : 8192,"metabuffersize" : 8192,"params" :)";
+ std::string expected_packet2 =
+ R"( {"psb" : 1,"tracetech" : "intel-pt"},"threadid" : 35,"type" : 1})";
+ HandlePacket(server, (expected_packet1 + expected_packet2), "1");
+ ASSERT_TRUE(error.Success());
+ ASSERT_EQ(result.get(), 1);
+
+ error.Clear();
+ result = std::async(std::launch::async, [&] {
+ return client.SendStartTracePacket(options, error);
+ });
+
+ HandlePacket(server, (expected_packet1 + expected_packet2), "E23");
+ ASSERT_EQ(result.get(), LLDB_INVALID_UID);
+ ASSERT_FALSE(error.Success());
+}
+
+TEST_F(GDBRemoteCommunicationClientTest, SendStopTracePacket) {
+ TestClient client;
+ MockServer server;
+ Connect(client, server);
+ if (HasFailure())
+ return;
+
+ lldb::tid_t thread_id = 0x23;
+ lldb::user_id_t trace_id = 3;
+
+ std::future<Status> result = std::async(std::launch::async, [&] {
+ return client.SendStopTracePacket(trace_id, thread_id);
+ });
+
+ const char *expected_packet =
+ R"(jTraceStop:{"threadid" : 35,"traceid" : 3})";
+ HandlePacket(server, expected_packet, "OK");
+ ASSERT_TRUE(result.get().Success());
+
+ result = std::async(std::launch::async, [&] {
+ return client.SendStopTracePacket(trace_id, thread_id);
+ });
+
+ HandlePacket(server, expected_packet, "E23");
+ ASSERT_FALSE(result.get().Success());
+}
+
+TEST_F(GDBRemoteCommunicationClientTest, SendGetDataPacket) {
+ TestClient client;
+ MockServer server;
+ Connect(client, server);
+ if (HasFailure())
+ return;
+
+ lldb::tid_t thread_id = 0x23;
+ lldb::user_id_t trace_id = 3;
+
+ uint8_t buf[32] = {};
+ llvm::MutableArrayRef<uint8_t> buffer(buf, 32);
+ size_t offset = 0;
+
+ std::future<Status> result = std::async(std::launch::async, [&] {
+ return client.SendGetDataPacket(trace_id, thread_id, buffer, offset);
+ });
+
+ std::string expected_packet1 =
+ R"(jTraceBufferRead:{"buffersize" : 32,"offset" : 0,"threadid" : 35,)";
+ std::string expected_packet2 = R"("traceid" : 3})";
+ HandlePacket(server, expected_packet1+expected_packet2, "123456");
+ ASSERT_TRUE(result.get().Success());
+ ASSERT_EQ(buffer.size(), 3);
+ ASSERT_EQ(buf[0], 0x12);
+ ASSERT_EQ(buf[1], 0x34);
+ ASSERT_EQ(buf[2], 0x56);
+
+ llvm::MutableArrayRef<uint8_t> buffer2(buf, 32);
+ result = std::async(std::launch::async, [&] {
+ return client.SendGetDataPacket(trace_id, thread_id, buffer2, offset);
+ });
+
+ HandlePacket(server, expected_packet1+expected_packet2, "E23");
+ ASSERT_FALSE(result.get().Success());
+ ASSERT_EQ(buffer2.size(), 0);
+}
+
+TEST_F(GDBRemoteCommunicationClientTest, SendGetMetaDataPacket) {
+ TestClient client;
+ MockServer server;
+ Connect(client, server);
+ if (HasFailure())
+ return;
+
+ lldb::tid_t thread_id = 0x23;
+ lldb::user_id_t trace_id = 3;
+
+ uint8_t buf[32] = {};
+ llvm::MutableArrayRef<uint8_t> buffer(buf, 32);
+ size_t offset = 0;
+
+ std::future<Status> result = std::async(std::launch::async, [&] {
+ return client.SendGetMetaDataPacket(trace_id, thread_id, buffer, offset);
+ });
+
+ std::string expected_packet1 =
+ R"(jTraceMetaRead:{"buffersize" : 32,"offset" : 0,"threadid" : 35,)";
+ std::string expected_packet2 = R"("traceid" : 3})";
+ HandlePacket(server, expected_packet1+expected_packet2, "123456");
+ ASSERT_TRUE(result.get().Success());
+ ASSERT_EQ(buffer.size(), 3);
+ ASSERT_EQ(buf[0], 0x12);
+ ASSERT_EQ(buf[1], 0x34);
+ ASSERT_EQ(buf[2], 0x56);
+
+ llvm::MutableArrayRef<uint8_t> buffer2(buf, 32);
+ result = std::async(std::launch::async, [&] {
+ return client.SendGetMetaDataPacket(trace_id, thread_id, buffer2, offset);
+ });
+
+ HandlePacket(server, expected_packet1+expected_packet2, "E23");
+ ASSERT_FALSE(result.get().Success());
+ ASSERT_EQ(buffer2.size(), 0);
+}
+
+TEST_F(GDBRemoteCommunicationClientTest, SendGetTraceConfigPacket) {
+ TestClient client;
+ MockServer server;
+ Connect(client, server);
+ if (HasFailure())
+ return;
+
+ lldb::tid_t thread_id = 0x23;
+ lldb::user_id_t trace_id = 3;
+ TraceOptions options;
+ options.setThreadID(thread_id);
+
+ std::future<Status> result = std::async(std::launch::async, [&] {
+ return client.SendGetTraceConfigPacket(trace_id, options);
+ });
+
+ const char *expected_packet =
+ R"(jTraceConfigRead:{"threadid" : 35,"traceid" : 3})";
+ std::string response1 =
+ R"({"buffersize" : 8192,"params" : {"psb" : 1,"tracetech" : "intel-pt"})";
+ std::string response2 =
+ R"(],"metabuffersize" : 8192,"threadid" : 35,"type" : 1}])";
+ HandlePacket(server, expected_packet, response1+response2);
+ ASSERT_TRUE(result.get().Success());
+ ASSERT_EQ(options.getTraceBufferSize(), 8192);
+ ASSERT_EQ(options.getMetaDataBufferSize(), 8192);
+ ASSERT_EQ(options.getType(), 1);
+
+ auto custom_params = options.getTraceParams();
+
+ uint64_t psb_value;
+ llvm::StringRef trace_tech_value;
+
+ ASSERT_TRUE(custom_params);
+ ASSERT_EQ(custom_params->GetType(), StructuredData::Type::eTypeDictionary);
+ ASSERT_TRUE(
+ custom_params->GetValueForKeyAsInteger<uint64_t>("psb", psb_value));
+ ASSERT_EQ(psb_value, 1);
+ ASSERT_TRUE(
+ custom_params->GetValueForKeyAsString("tracetech", trace_tech_value));
+ ASSERT_STREQ(trace_tech_value.data(), "intel-pt");
+
+ // Checking error response.
+ std::future<Status> result2 = std::async(std::launch::async, [&] {
+ return client.SendGetTraceConfigPacket(trace_id, options);
+ });
+
+ HandlePacket(server, expected_packet, "E23");
+ ASSERT_FALSE(result2.get().Success());
+
+ // Wrong JSON as response.
+ std::future<Status> result3 = std::async(std::launch::async, [&] {
+ return client.SendGetTraceConfigPacket(trace_id, options);
+ });
+
+ std::string incorrect_json1 =
+ R"("buffersize" : 8192,"params" : {"psb" : 1,"tracetech" : "intel-pt"})";
+ std::string incorrect_json2 =
+ R"(],"metabuffersize" : 8192,"threadid" : 35,"type" : 1}])";
+ HandlePacket(server, expected_packet, incorrect_json1+incorrect_json2);
+ ASSERT_FALSE(result3.get().Success());
+
+ // Wrong JSON as custom_params.
+ std::future<Status> result4 = std::async(std::launch::async, [&] {
+ return client.SendGetTraceConfigPacket(trace_id, options);
+ });
+
+ std::string incorrect_custom_params1 =
+ R"({"buffersize" : 8192,"params" : "psb" : 1,"tracetech" : "intel-pt"})";
+ std::string incorrect_custom_params2 =
+ R"(],"metabuffersize" : 8192,"threadid" : 35,"type" : 1}])";
+ HandlePacket(server, expected_packet, incorrect_custom_params1+
+ incorrect_custom_params2);
+ ASSERT_FALSE(result4.get().Success());
+} \ No newline at end of file
OpenPOWER on IntegriCloud