1 //===-- GDBRemoteCommunicationClientTest.cpp --------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 #include "Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h" 10 #include "GDBRemoteTestUtils.h" 11 #include "lldb/Core/ModuleSpec.h" 12 #include "lldb/Host/XML.h" 13 #include "lldb/Target/MemoryRegionInfo.h" 14 #include "lldb/Utility/DataBuffer.h" 15 #include "lldb/Utility/StructuredData.h" 16 #include "lldb/Utility/TraceOptions.h" 17 #include "lldb/lldb-enumerations.h" 18 #include "llvm/ADT/ArrayRef.h" 19 #include "llvm/Testing/Support/Error.h" 20 #include "gmock/gmock.h" 21 #include <future> 22 23 using namespace lldb_private::process_gdb_remote; 24 using namespace lldb_private; 25 using namespace lldb; 26 using namespace llvm; 27 28 namespace { 29 30 typedef GDBRemoteCommunication::PacketResult PacketResult; 31 32 struct TestClient : public GDBRemoteCommunicationClient { 33 TestClient() { m_send_acks = false; } 34 }; 35 36 void Handle_QThreadSuffixSupported(MockServer &server, bool supported) { 37 StringExtractorGDBRemote request; 38 ASSERT_EQ(PacketResult::Success, server.GetPacket(request)); 39 ASSERT_EQ("QThreadSuffixSupported", request.GetStringRef()); 40 if (supported) 41 ASSERT_EQ(PacketResult::Success, server.SendOKResponse()); 42 else 43 ASSERT_EQ(PacketResult::Success, server.SendUnimplementedResponse(nullptr)); 44 } 45 46 void HandlePacket(MockServer &server, 47 const testing::Matcher<const std::string &> &expected, 48 StringRef response) { 49 StringExtractorGDBRemote request; 50 ASSERT_EQ(PacketResult::Success, server.GetPacket(request)); 51 ASSERT_THAT(request.GetStringRef(), expected); 52 ASSERT_EQ(PacketResult::Success, server.SendPacket(response)); 53 } 54 55 uint8_t all_registers[] = {'@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 56 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O'}; 57 std::string all_registers_hex = "404142434445464748494a4b4c4d4e4f"; 58 uint8_t one_register[] = {'A', 'B', 'C', 'D'}; 59 std::string one_register_hex = "41424344"; 60 61 } // end anonymous namespace 62 63 class GDBRemoteCommunicationClientTest : public GDBRemoteTest { 64 public: 65 void SetUp() override { 66 ASSERT_THAT_ERROR(GDBRemoteCommunication::ConnectLocally(client, server), 67 llvm::Succeeded()); 68 } 69 70 protected: 71 TestClient client; 72 MockServer server; 73 }; 74 75 TEST_F(GDBRemoteCommunicationClientTest, WriteRegister) { 76 const lldb::tid_t tid = 0x47; 77 const uint32_t reg_num = 4; 78 std::future<bool> write_result = std::async(std::launch::async, [&] { 79 return client.WriteRegister(tid, reg_num, one_register); 80 }); 81 82 Handle_QThreadSuffixSupported(server, true); 83 84 HandlePacket(server, "P4=" + one_register_hex + ";thread:0047;", "OK"); 85 ASSERT_TRUE(write_result.get()); 86 87 write_result = std::async(std::launch::async, [&] { 88 return client.WriteAllRegisters(tid, all_registers); 89 }); 90 91 HandlePacket(server, "G" + all_registers_hex + ";thread:0047;", "OK"); 92 ASSERT_TRUE(write_result.get()); 93 } 94 95 TEST_F(GDBRemoteCommunicationClientTest, WriteRegisterNoSuffix) { 96 const lldb::tid_t tid = 0x47; 97 const uint32_t reg_num = 4; 98 std::future<bool> write_result = std::async(std::launch::async, [&] { 99 return client.WriteRegister(tid, reg_num, one_register); 100 }); 101 102 Handle_QThreadSuffixSupported(server, false); 103 HandlePacket(server, "Hg47", "OK"); 104 HandlePacket(server, "P4=" + one_register_hex, "OK"); 105 ASSERT_TRUE(write_result.get()); 106 107 write_result = std::async(std::launch::async, [&] { 108 return client.WriteAllRegisters(tid, all_registers); 109 }); 110 111 HandlePacket(server, "G" + all_registers_hex, "OK"); 112 ASSERT_TRUE(write_result.get()); 113 } 114 115 TEST_F(GDBRemoteCommunicationClientTest, ReadRegister) { 116 const lldb::tid_t tid = 0x47; 117 const uint32_t reg_num = 4; 118 std::future<bool> async_result = std::async( 119 std::launch::async, [&] { return client.GetpPacketSupported(tid); }); 120 Handle_QThreadSuffixSupported(server, true); 121 HandlePacket(server, "p0;thread:0047;", one_register_hex); 122 ASSERT_TRUE(async_result.get()); 123 124 std::future<DataBufferSP> read_result = std::async( 125 std::launch::async, [&] { return client.ReadRegister(tid, reg_num); }); 126 HandlePacket(server, "p4;thread:0047;", "41424344"); 127 auto buffer_sp = read_result.get(); 128 ASSERT_TRUE(bool(buffer_sp)); 129 ASSERT_EQ(0, 130 memcmp(buffer_sp->GetBytes(), one_register, sizeof one_register)); 131 132 read_result = std::async(std::launch::async, 133 [&] { return client.ReadAllRegisters(tid); }); 134 HandlePacket(server, "g;thread:0047;", all_registers_hex); 135 buffer_sp = read_result.get(); 136 ASSERT_TRUE(bool(buffer_sp)); 137 ASSERT_EQ(0, 138 memcmp(buffer_sp->GetBytes(), all_registers, sizeof all_registers)); 139 } 140 141 TEST_F(GDBRemoteCommunicationClientTest, SaveRestoreRegistersNoSuffix) { 142 const lldb::tid_t tid = 0x47; 143 uint32_t save_id; 144 std::future<bool> async_result = std::async(std::launch::async, [&] { 145 return client.SaveRegisterState(tid, save_id); 146 }); 147 Handle_QThreadSuffixSupported(server, false); 148 HandlePacket(server, "Hg47", "OK"); 149 HandlePacket(server, "QSaveRegisterState", "1"); 150 ASSERT_TRUE(async_result.get()); 151 EXPECT_EQ(1u, save_id); 152 153 async_result = std::async(std::launch::async, [&] { 154 return client.RestoreRegisterState(tid, save_id); 155 }); 156 HandlePacket(server, "QRestoreRegisterState:1", "OK"); 157 ASSERT_TRUE(async_result.get()); 158 } 159 160 TEST_F(GDBRemoteCommunicationClientTest, SyncThreadState) { 161 const lldb::tid_t tid = 0x47; 162 std::future<bool> async_result = std::async( 163 std::launch::async, [&] { return client.SyncThreadState(tid); }); 164 HandlePacket(server, "qSyncThreadStateSupported", "OK"); 165 HandlePacket(server, "QSyncThreadState:0047;", "OK"); 166 ASSERT_TRUE(async_result.get()); 167 } 168 169 TEST_F(GDBRemoteCommunicationClientTest, GetModulesInfo) { 170 llvm::Triple triple("i386-pc-linux"); 171 172 FileSpec file_specs[] = { 173 FileSpec("/foo/bar.so", FileSpec::Style::posix), 174 FileSpec("/foo/baz.so", FileSpec::Style::posix), 175 176 // This is a bit dodgy but we currently depend on GetModulesInfo not 177 // performing denormalization. It can go away once the users 178 // (DynamicLoaderPOSIXDYLD, at least) correctly set the path syntax for 179 // the FileSpecs they create. 180 FileSpec("/foo/baw.so", FileSpec::Style::windows), 181 }; 182 std::future<llvm::Optional<std::vector<ModuleSpec>>> async_result = 183 std::async(std::launch::async, 184 [&] { return client.GetModulesInfo(file_specs, triple); }); 185 HandlePacket( 186 server, "jModulesInfo:[" 187 R"({"file":"/foo/bar.so","triple":"i386-pc-linux"},)" 188 R"({"file":"/foo/baz.so","triple":"i386-pc-linux"},)" 189 R"({"file":"/foo/baw.so","triple":"i386-pc-linux"}])", 190 R"([{"uuid":"404142434445464748494a4b4c4d4e4f","triple":"i386-pc-linux",)" 191 R"("file_path":"/foo/bar.so","file_offset":0,"file_size":1234}]])"); 192 193 auto result = async_result.get(); 194 ASSERT_TRUE(result.hasValue()); 195 ASSERT_EQ(1u, result->size()); 196 EXPECT_EQ("/foo/bar.so", result.getValue()[0].GetFileSpec().GetPath()); 197 EXPECT_EQ(triple, result.getValue()[0].GetArchitecture().GetTriple()); 198 EXPECT_EQ(UUID::fromData("@ABCDEFGHIJKLMNO", 16), 199 result.getValue()[0].GetUUID()); 200 EXPECT_EQ(0u, result.getValue()[0].GetObjectOffset()); 201 EXPECT_EQ(1234u, result.getValue()[0].GetObjectSize()); 202 } 203 204 TEST_F(GDBRemoteCommunicationClientTest, GetModulesInfo_UUID20) { 205 llvm::Triple triple("i386-pc-linux"); 206 207 FileSpec file_spec("/foo/bar.so", FileSpec::Style::posix); 208 std::future<llvm::Optional<std::vector<ModuleSpec>>> async_result = 209 std::async(std::launch::async, 210 [&] { return client.GetModulesInfo(file_spec, triple); }); 211 HandlePacket( 212 server, 213 "jModulesInfo:[" 214 R"({"file":"/foo/bar.so","triple":"i386-pc-linux"}])", 215 R"([{"uuid":"404142434445464748494a4b4c4d4e4f50515253","triple":"i386-pc-linux",)" 216 R"("file_path":"/foo/bar.so","file_offset":0,"file_size":1234}]])"); 217 218 auto result = async_result.get(); 219 ASSERT_TRUE(result.hasValue()); 220 ASSERT_EQ(1u, result->size()); 221 EXPECT_EQ("/foo/bar.so", result.getValue()[0].GetFileSpec().GetPath()); 222 EXPECT_EQ(triple, result.getValue()[0].GetArchitecture().GetTriple()); 223 EXPECT_EQ(UUID::fromData("@ABCDEFGHIJKLMNOPQRS", 20), 224 result.getValue()[0].GetUUID()); 225 EXPECT_EQ(0u, result.getValue()[0].GetObjectOffset()); 226 EXPECT_EQ(1234u, result.getValue()[0].GetObjectSize()); 227 } 228 229 TEST_F(GDBRemoteCommunicationClientTest, GetModulesInfoInvalidResponse) { 230 llvm::Triple triple("i386-pc-linux"); 231 FileSpec file_spec("/foo/bar.so", FileSpec::Style::posix); 232 233 const char *invalid_responses[] = { 234 // no UUID 235 R"([{"triple":"i386-pc-linux",)" 236 R"("file_path":"/foo/bar.so","file_offset":0,"file_size":1234}]])", 237 // invalid UUID 238 R"([{"uuid":"XXXXXX","triple":"i386-pc-linux",)" 239 R"("file_path":"/foo/bar.so","file_offset":0,"file_size":1234}]])", 240 // no triple 241 R"([{"uuid":"404142434445464748494a4b4c4d4e4f",)" 242 R"("file_path":"/foo/bar.so","file_offset":0,"file_size":1234}]])", 243 // no file_path 244 R"([{"uuid":"404142434445464748494a4b4c4d4e4f","triple":"i386-pc-linux",)" 245 R"("file_offset":0,"file_size":1234}]])", 246 // no file_offset 247 R"([{"uuid":"404142434445464748494a4b4c4d4e4f","triple":"i386-pc-linux",)" 248 R"("file_path":"/foo/bar.so","file_size":1234}]])", 249 // no file_size 250 R"([{"uuid":"404142434445464748494a4b4c4d4e4f","triple":"i386-pc-linux",)" 251 R"("file_path":"/foo/bar.so","file_offset":0}]])", 252 }; 253 254 for (const char *response : invalid_responses) { 255 std::future<llvm::Optional<std::vector<ModuleSpec>>> async_result = 256 std::async(std::launch::async, 257 [&] { return client.GetModulesInfo(file_spec, triple); }); 258 HandlePacket( 259 server, 260 R"(jModulesInfo:[{"file":"/foo/bar.so","triple":"i386-pc-linux"}])", 261 response); 262 263 auto result = async_result.get(); 264 ASSERT_TRUE(result); 265 ASSERT_EQ(0u, result->size()) << "response was: " << response; 266 } 267 } 268 269 TEST_F(GDBRemoteCommunicationClientTest, TestPacketSpeedJSON) { 270 std::thread server_thread([this] { 271 for (;;) { 272 StringExtractorGDBRemote request; 273 PacketResult result = server.GetPacket(request); 274 if (result == PacketResult::ErrorDisconnected) 275 return; 276 ASSERT_EQ(PacketResult::Success, result); 277 StringRef ref = request.GetStringRef(); 278 ASSERT_TRUE(ref.consume_front("qSpeedTest:response_size:")); 279 int size; 280 ASSERT_FALSE(ref.consumeInteger(10, size)) << "ref: " << ref; 281 std::string response(size, 'X'); 282 ASSERT_EQ(PacketResult::Success, server.SendPacket(response)); 283 } 284 }); 285 286 StreamString ss; 287 client.TestPacketSpeed(10, 32, 32, 4096, true, ss); 288 client.Disconnect(); 289 server_thread.join(); 290 291 GTEST_LOG_(INFO) << "Formatted output: " << ss.GetData(); 292 auto object_sp = StructuredData::ParseJSON(ss.GetString()); 293 ASSERT_TRUE(bool(object_sp)); 294 auto dict_sp = object_sp->GetAsDictionary(); 295 ASSERT_TRUE(bool(dict_sp)); 296 297 object_sp = dict_sp->GetValueForKey("packet_speeds"); 298 ASSERT_TRUE(bool(object_sp)); 299 dict_sp = object_sp->GetAsDictionary(); 300 ASSERT_TRUE(bool(dict_sp)); 301 302 int num_packets; 303 ASSERT_TRUE(dict_sp->GetValueForKeyAsInteger("num_packets", num_packets)) 304 << ss.GetString(); 305 ASSERT_EQ(10, num_packets); 306 } 307 308 TEST_F(GDBRemoteCommunicationClientTest, SendSignalsToIgnore) { 309 std::future<Status> result = std::async(std::launch::async, [&] { 310 return client.SendSignalsToIgnore({2, 3, 5, 7, 0xB, 0xD, 0x11}); 311 }); 312 313 HandlePacket(server, "QPassSignals:02;03;05;07;0b;0d;11", "OK"); 314 EXPECT_TRUE(result.get().Success()); 315 316 result = std::async(std::launch::async, [&] { 317 return client.SendSignalsToIgnore(std::vector<int32_t>()); 318 }); 319 320 HandlePacket(server, "QPassSignals:", "OK"); 321 EXPECT_TRUE(result.get().Success()); 322 } 323 324 TEST_F(GDBRemoteCommunicationClientTest, GetMemoryRegionInfo) { 325 const lldb::addr_t addr = 0xa000; 326 MemoryRegionInfo region_info; 327 std::future<Status> result = std::async(std::launch::async, [&] { 328 return client.GetMemoryRegionInfo(addr, region_info); 329 }); 330 331 HandlePacket(server, 332 "qMemoryRegionInfo:a000", 333 "start:a000;size:2000;permissions:rx;name:2f666f6f2f6261722e736f;"); 334 if (XMLDocument::XMLEnabled()) { 335 // In case we have XML support, this will also do a "qXfer:memory-map". 336 // Preceeded by a query for supported extensions. Pretend we don't support 337 // that. 338 HandlePacket(server, testing::StartsWith("qSupported:"), ""); 339 } 340 EXPECT_TRUE(result.get().Success()); 341 EXPECT_EQ(addr, region_info.GetRange().GetRangeBase()); 342 EXPECT_EQ(0x2000u, region_info.GetRange().GetByteSize()); 343 EXPECT_EQ(MemoryRegionInfo::eYes, region_info.GetReadable()); 344 EXPECT_EQ(MemoryRegionInfo::eNo, region_info.GetWritable()); 345 EXPECT_EQ(MemoryRegionInfo::eYes, region_info.GetExecutable()); 346 EXPECT_EQ("/foo/bar.so", region_info.GetName().GetStringRef()); 347 } 348 349 TEST_F(GDBRemoteCommunicationClientTest, GetMemoryRegionInfoInvalidResponse) { 350 const lldb::addr_t addr = 0x4000; 351 MemoryRegionInfo region_info; 352 std::future<Status> result = std::async(std::launch::async, [&] { 353 return client.GetMemoryRegionInfo(addr, region_info); 354 }); 355 356 HandlePacket(server, "qMemoryRegionInfo:4000", "start:4000;size:0000;"); 357 if (XMLDocument::XMLEnabled()) { 358 // In case we have XML support, this will also do a "qXfer:memory-map". 359 // Preceeded by a query for supported extensions. Pretend we don't support 360 // that. 361 HandlePacket(server, testing::StartsWith("qSupported:"), ""); 362 } 363 EXPECT_FALSE(result.get().Success()); 364 } 365 366 TEST_F(GDBRemoteCommunicationClientTest, SendStartTracePacket) { 367 TraceOptions options; 368 Status error; 369 370 options.setType(lldb::TraceType::eTraceTypeProcessorTrace); 371 options.setMetaDataBufferSize(8192); 372 options.setTraceBufferSize(8192); 373 options.setThreadID(0x23); 374 375 StructuredData::DictionarySP custom_params = 376 std::make_shared<StructuredData::Dictionary>(); 377 custom_params->AddStringItem("tracetech", "intel-pt"); 378 custom_params->AddIntegerItem("psb", 0x01); 379 380 options.setTraceParams(custom_params); 381 382 std::future<lldb::user_id_t> result = std::async(std::launch::async, [&] { 383 return client.SendStartTracePacket(options, error); 384 }); 385 386 // Since the line is exceeding 80 characters. 387 std::string expected_packet1 = 388 R"(jTraceStart:{"buffersize" : 8192,"metabuffersize" : 8192,"params" :)"; 389 std::string expected_packet2 = 390 R"( {"psb" : 1,"tracetech" : "intel-pt"},"threadid" : 35,"type" : 1})"; 391 HandlePacket(server, (expected_packet1 + expected_packet2), "1"); 392 ASSERT_TRUE(error.Success()); 393 ASSERT_EQ(result.get(), 1u); 394 395 error.Clear(); 396 result = std::async(std::launch::async, [&] { 397 return client.SendStartTracePacket(options, error); 398 }); 399 400 HandlePacket(server, (expected_packet1 + expected_packet2), "E23"); 401 ASSERT_EQ(result.get(), LLDB_INVALID_UID); 402 ASSERT_FALSE(error.Success()); 403 } 404 405 TEST_F(GDBRemoteCommunicationClientTest, SendStopTracePacket) { 406 lldb::tid_t thread_id = 0x23; 407 lldb::user_id_t trace_id = 3; 408 409 std::future<Status> result = std::async(std::launch::async, [&] { 410 return client.SendStopTracePacket(trace_id, thread_id); 411 }); 412 413 const char *expected_packet = 414 R"(jTraceStop:{"threadid" : 35,"traceid" : 3})"; 415 HandlePacket(server, expected_packet, "OK"); 416 ASSERT_TRUE(result.get().Success()); 417 418 result = std::async(std::launch::async, [&] { 419 return client.SendStopTracePacket(trace_id, thread_id); 420 }); 421 422 HandlePacket(server, expected_packet, "E23"); 423 ASSERT_FALSE(result.get().Success()); 424 } 425 426 TEST_F(GDBRemoteCommunicationClientTest, SendGetDataPacket) { 427 lldb::tid_t thread_id = 0x23; 428 lldb::user_id_t trace_id = 3; 429 430 uint8_t buf[32] = {}; 431 llvm::MutableArrayRef<uint8_t> buffer(buf, 32); 432 size_t offset = 0; 433 434 std::future<Status> result = std::async(std::launch::async, [&] { 435 return client.SendGetDataPacket(trace_id, thread_id, buffer, offset); 436 }); 437 438 std::string expected_packet1 = 439 R"(jTraceBufferRead:{"buffersize" : 32,"offset" : 0,"threadid" : 35,)"; 440 std::string expected_packet2 = R"("traceid" : 3})"; 441 HandlePacket(server, expected_packet1+expected_packet2, "123456"); 442 ASSERT_TRUE(result.get().Success()); 443 ASSERT_EQ(buffer.size(), 3u); 444 ASSERT_EQ(buf[0], 0x12); 445 ASSERT_EQ(buf[1], 0x34); 446 ASSERT_EQ(buf[2], 0x56); 447 448 llvm::MutableArrayRef<uint8_t> buffer2(buf, 32); 449 result = std::async(std::launch::async, [&] { 450 return client.SendGetDataPacket(trace_id, thread_id, buffer2, offset); 451 }); 452 453 HandlePacket(server, expected_packet1+expected_packet2, "E23"); 454 ASSERT_FALSE(result.get().Success()); 455 ASSERT_EQ(buffer2.size(), 0u); 456 } 457 458 TEST_F(GDBRemoteCommunicationClientTest, SendGetMetaDataPacket) { 459 lldb::tid_t thread_id = 0x23; 460 lldb::user_id_t trace_id = 3; 461 462 uint8_t buf[32] = {}; 463 llvm::MutableArrayRef<uint8_t> buffer(buf, 32); 464 size_t offset = 0; 465 466 std::future<Status> result = std::async(std::launch::async, [&] { 467 return client.SendGetMetaDataPacket(trace_id, thread_id, buffer, offset); 468 }); 469 470 std::string expected_packet1 = 471 R"(jTraceMetaRead:{"buffersize" : 32,"offset" : 0,"threadid" : 35,)"; 472 std::string expected_packet2 = R"("traceid" : 3})"; 473 HandlePacket(server, expected_packet1+expected_packet2, "123456"); 474 ASSERT_TRUE(result.get().Success()); 475 ASSERT_EQ(buffer.size(), 3u); 476 ASSERT_EQ(buf[0], 0x12); 477 ASSERT_EQ(buf[1], 0x34); 478 ASSERT_EQ(buf[2], 0x56); 479 480 llvm::MutableArrayRef<uint8_t> buffer2(buf, 32); 481 result = std::async(std::launch::async, [&] { 482 return client.SendGetMetaDataPacket(trace_id, thread_id, buffer2, offset); 483 }); 484 485 HandlePacket(server, expected_packet1+expected_packet2, "E23"); 486 ASSERT_FALSE(result.get().Success()); 487 ASSERT_EQ(buffer2.size(), 0u); 488 } 489 490 TEST_F(GDBRemoteCommunicationClientTest, SendGetTraceConfigPacket) { 491 lldb::tid_t thread_id = 0x23; 492 lldb::user_id_t trace_id = 3; 493 TraceOptions options; 494 options.setThreadID(thread_id); 495 496 std::future<Status> result = std::async(std::launch::async, [&] { 497 return client.SendGetTraceConfigPacket(trace_id, options); 498 }); 499 500 const char *expected_packet = 501 R"(jTraceConfigRead:{"threadid" : 35,"traceid" : 3})"; 502 std::string response1 = 503 R"({"buffersize" : 8192,"params" : {"psb" : 1,"tracetech" : "intel-pt"})"; 504 std::string response2 = 505 R"(],"metabuffersize" : 8192,"threadid" : 35,"type" : 1}])"; 506 HandlePacket(server, expected_packet, response1+response2); 507 ASSERT_TRUE(result.get().Success()); 508 ASSERT_EQ(options.getTraceBufferSize(), 8192u); 509 ASSERT_EQ(options.getMetaDataBufferSize(), 8192u); 510 ASSERT_EQ(options.getType(), 1); 511 512 auto custom_params = options.getTraceParams(); 513 514 uint64_t psb_value; 515 llvm::StringRef trace_tech_value; 516 517 ASSERT_TRUE(custom_params); 518 ASSERT_EQ(custom_params->GetType(), eStructuredDataTypeDictionary); 519 ASSERT_TRUE(custom_params->GetValueForKeyAsInteger("psb", psb_value)); 520 ASSERT_EQ(psb_value, 1u); 521 ASSERT_TRUE( 522 custom_params->GetValueForKeyAsString("tracetech", trace_tech_value)); 523 ASSERT_STREQ(trace_tech_value.data(), "intel-pt"); 524 525 // Checking error response. 526 std::future<Status> result2 = std::async(std::launch::async, [&] { 527 return client.SendGetTraceConfigPacket(trace_id, options); 528 }); 529 530 HandlePacket(server, expected_packet, "E23"); 531 ASSERT_FALSE(result2.get().Success()); 532 533 // Wrong JSON as response. 534 std::future<Status> result3 = std::async(std::launch::async, [&] { 535 return client.SendGetTraceConfigPacket(trace_id, options); 536 }); 537 538 std::string incorrect_json1 = 539 R"("buffersize" : 8192,"params" : {"psb" : 1,"tracetech" : "intel-pt"})"; 540 std::string incorrect_json2 = 541 R"(],"metabuffersize" : 8192,"threadid" : 35,"type" : 1}])"; 542 HandlePacket(server, expected_packet, incorrect_json1+incorrect_json2); 543 ASSERT_FALSE(result3.get().Success()); 544 545 // Wrong JSON as custom_params. 546 std::future<Status> result4 = std::async(std::launch::async, [&] { 547 return client.SendGetTraceConfigPacket(trace_id, options); 548 }); 549 550 std::string incorrect_custom_params1 = 551 R"({"buffersize" : 8192,"params" : "psb" : 1,"tracetech" : "intel-pt"})"; 552 std::string incorrect_custom_params2 = 553 R"(],"metabuffersize" : 8192,"threadid" : 35,"type" : 1}])"; 554 HandlePacket(server, expected_packet, incorrect_custom_params1+ 555 incorrect_custom_params2); 556 ASSERT_FALSE(result4.get().Success()); 557 } 558