[Lldb-commits] [lldb] r306013 - Simplify the gdb-remote unit tests
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Thu Jun 22 08:54:21 PDT 2017
Author: labath
Date: Thu Jun 22 10:54:21 2017
New Revision: 306013
URL: http://llvm.org/viewvc/llvm-project?rev=306013&view=rev
Log:
Simplify the gdb-remote unit tests
Instead of every test creating a client-server combo, do that in the
SetUp method of the test fixture. This also means that we can rely on
gtest to not run the test if the SetUp method fails and delete the
if(HasFailure) calls.
Modified:
lldb/trunk/unittests/Process/gdb-remote/CMakeLists.txt
lldb/trunk/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp
lldb/trunk/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
lldb/trunk/unittests/Process/gdb-remote/GDBRemoteTestUtils.cpp
lldb/trunk/unittests/Process/gdb-remote/GDBRemoteTestUtils.h
Modified: lldb/trunk/unittests/Process/gdb-remote/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Process/gdb-remote/CMakeLists.txt?rev=306013&r1=306012&r2=306013&view=diff
==============================================================================
--- lldb/trunk/unittests/Process/gdb-remote/CMakeLists.txt (original)
+++ lldb/trunk/unittests/Process/gdb-remote/CMakeLists.txt Thu Jun 22 10:54:21 2017
@@ -9,6 +9,9 @@ add_lldb_unittest(ProcessGdbRemoteTests
lldbPluginPlatformMacOSX
lldbPluginProcessUtility
lldbPluginProcessGDBRemote
+
+ LLVMTestingSupport
+
LINK_COMPONENTS
Support
)
Modified: lldb/trunk/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp?rev=306013&r1=306012&r2=306013&view=diff
==============================================================================
--- lldb/trunk/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp (original)
+++ lldb/trunk/unittests/Process/gdb-remote/GDBRemoteClientBaseTest.cpp Thu Jun 22 10:54:21 2017
@@ -14,8 +14,8 @@
#include "Plugins/Process/gdb-remote/GDBRemoteClientBase.h"
#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationServer.h"
#include "lldb/Utility/StreamGDBRemote.h"
-
#include "llvm/ADT/STLExtras.h"
+#include "llvm/Testing/Support/Error.h"
using namespace lldb_private::process_gdb_remote;
using namespace lldb_private;
@@ -45,13 +45,20 @@ struct TestClient : public GDBRemoteClie
}
};
-struct ContinueFixture {
- MockDelegate delegate;
+class GDBRemoteClientBaseTest : public GDBRemoteTest {
+public:
+ void SetUp() override {
+ ASSERT_THAT_ERROR(Connect(client, server), llvm::Succeeded());
+ ASSERT_EQ(TestClient::eBroadcastBitRunPacketSent,
+ listener_sp->StartListeningForEvents(
+ &client, TestClient::eBroadcastBitRunPacketSent));
+ }
+
+protected:
TestClient client;
MockServer server;
- ListenerSP listener_sp;
-
- ContinueFixture();
+ MockDelegate delegate;
+ ListenerSP listener_sp = Listener::MakeListener("listener");
StateType SendCPacket(StringExtractorGDBRemote &response) {
return client.SendContinuePacketAndWaitForResponse(delegate, LinuxSignals(),
@@ -65,76 +72,61 @@ struct ContinueFixture {
}
};
-ContinueFixture::ContinueFixture()
- : listener_sp(Listener::MakeListener("listener")) {
- Connect(client, server);
- listener_sp->StartListeningForEvents(&client,
- TestClient::eBroadcastBitRunPacketSent);
-}
-
} // end anonymous namespace
-class GDBRemoteClientBaseTest : public GDBRemoteTest {};
-
TEST_F(GDBRemoteClientBaseTest, SendContinueAndWait) {
StringExtractorGDBRemote response;
- ContinueFixture fix;
- if (HasFailure())
- return;
// Continue. The inferior will stop with a signal.
- ASSERT_EQ(PacketResult::Success, fix.server.SendPacket("T01"));
- ASSERT_EQ(eStateStopped, fix.SendCPacket(response));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("T01"));
+ ASSERT_EQ(eStateStopped, SendCPacket(response));
ASSERT_EQ("T01", response.GetStringRef());
- ASSERT_EQ(PacketResult::Success, fix.server.GetPacket(response));
+ ASSERT_EQ(PacketResult::Success, server.GetPacket(response));
ASSERT_EQ("c", response.GetStringRef());
// Continue. The inferior will exit.
- ASSERT_EQ(PacketResult::Success, fix.server.SendPacket("W01"));
- ASSERT_EQ(eStateExited, fix.SendCPacket(response));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("W01"));
+ ASSERT_EQ(eStateExited, SendCPacket(response));
ASSERT_EQ("W01", response.GetStringRef());
- ASSERT_EQ(PacketResult::Success, fix.server.GetPacket(response));
+ ASSERT_EQ(PacketResult::Success, server.GetPacket(response));
ASSERT_EQ("c", response.GetStringRef());
// Continue. The inferior will get killed.
- ASSERT_EQ(PacketResult::Success, fix.server.SendPacket("X01"));
- ASSERT_EQ(eStateExited, fix.SendCPacket(response));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("X01"));
+ ASSERT_EQ(eStateExited, SendCPacket(response));
ASSERT_EQ("X01", response.GetStringRef());
- ASSERT_EQ(PacketResult::Success, fix.server.GetPacket(response));
+ ASSERT_EQ(PacketResult::Success, server.GetPacket(response));
ASSERT_EQ("c", response.GetStringRef());
}
TEST_F(GDBRemoteClientBaseTest, SendContinueAndAsyncSignal) {
StringExtractorGDBRemote continue_response, response;
- ContinueFixture fix;
- if (HasFailure())
- return;
// SendAsyncSignal should do nothing when we are not running.
- ASSERT_FALSE(fix.client.SendAsyncSignal(0x47));
+ ASSERT_FALSE(client.SendAsyncSignal(0x47));
// Continue. After the run packet is sent, send an async signal.
std::future<StateType> continue_state = std::async(
- std::launch::async, [&] { return fix.SendCPacket(continue_response); });
- ASSERT_EQ(PacketResult::Success, fix.server.GetPacket(response));
+ std::launch::async, [&] { return SendCPacket(continue_response); });
+ ASSERT_EQ(PacketResult::Success, server.GetPacket(response));
ASSERT_EQ("c", response.GetStringRef());
- fix.WaitForRunEvent();
+ WaitForRunEvent();
std::future<bool> async_result = std::async(
- std::launch::async, [&] { return fix.client.SendAsyncSignal(0x47); });
+ std::launch::async, [&] { return client.SendAsyncSignal(0x47); });
// First we'll get interrupted.
- ASSERT_EQ(PacketResult::Success, fix.server.GetPacket(response));
+ ASSERT_EQ(PacketResult::Success, server.GetPacket(response));
ASSERT_EQ("\x03", response.GetStringRef());
- ASSERT_EQ(PacketResult::Success, fix.server.SendPacket("T13"));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("T13"));
// Then we get the signal packet.
- ASSERT_EQ(PacketResult::Success, fix.server.GetPacket(response));
+ ASSERT_EQ(PacketResult::Success, server.GetPacket(response));
ASSERT_EQ("C47", response.GetStringRef());
ASSERT_TRUE(async_result.get());
// And we report back a signal stop.
- ASSERT_EQ(PacketResult::Success, fix.server.SendPacket("T47"));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("T47"));
ASSERT_EQ(eStateStopped, continue_state.get());
ASSERT_EQ("T47", continue_response.GetStringRef());
}
@@ -142,72 +134,66 @@ TEST_F(GDBRemoteClientBaseTest, SendCont
TEST_F(GDBRemoteClientBaseTest, SendContinueAndAsyncPacket) {
StringExtractorGDBRemote continue_response, async_response, response;
const bool send_async = true;
- ContinueFixture fix;
- if (HasFailure())
- return;
// Continue. After the run packet is sent, send an async packet.
std::future<StateType> continue_state = std::async(
- std::launch::async, [&] { return fix.SendCPacket(continue_response); });
- ASSERT_EQ(PacketResult::Success, fix.server.GetPacket(response));
+ std::launch::async, [&] { return SendCPacket(continue_response); });
+ ASSERT_EQ(PacketResult::Success, server.GetPacket(response));
ASSERT_EQ("c", response.GetStringRef());
- fix.WaitForRunEvent();
+ WaitForRunEvent();
// Sending without async enabled should fail.
ASSERT_EQ(
PacketResult::ErrorSendFailed,
- fix.client.SendPacketAndWaitForResponse("qTest1", response, !send_async));
+ client.SendPacketAndWaitForResponse("qTest1", response, !send_async));
std::future<PacketResult> async_result = std::async(std::launch::async, [&] {
- return fix.client.SendPacketAndWaitForResponse("qTest2", async_response,
- send_async);
+ return client.SendPacketAndWaitForResponse("qTest2", async_response,
+ send_async);
});
// First we'll get interrupted.
- ASSERT_EQ(PacketResult::Success, fix.server.GetPacket(response));
+ ASSERT_EQ(PacketResult::Success, server.GetPacket(response));
ASSERT_EQ("\x03", response.GetStringRef());
- ASSERT_EQ(PacketResult::Success, fix.server.SendPacket("T13"));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("T13"));
// Then we get the async packet.
- ASSERT_EQ(PacketResult::Success, fix.server.GetPacket(response));
+ ASSERT_EQ(PacketResult::Success, server.GetPacket(response));
ASSERT_EQ("qTest2", response.GetStringRef());
// Send the response and receive it.
- ASSERT_EQ(PacketResult::Success, fix.server.SendPacket("QTest2"));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("QTest2"));
ASSERT_EQ(PacketResult::Success, async_result.get());
ASSERT_EQ("QTest2", async_response.GetStringRef());
// And we get resumed again.
- ASSERT_EQ(PacketResult::Success, fix.server.GetPacket(response));
+ ASSERT_EQ(PacketResult::Success, server.GetPacket(response));
ASSERT_EQ("c", response.GetStringRef());
- ASSERT_EQ(PacketResult::Success, fix.server.SendPacket("T01"));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("T01"));
ASSERT_EQ(eStateStopped, continue_state.get());
ASSERT_EQ("T01", continue_response.GetStringRef());
}
TEST_F(GDBRemoteClientBaseTest, SendContinueAndInterrupt) {
StringExtractorGDBRemote continue_response, response;
- ContinueFixture fix;
- if (HasFailure())
- return;
// Interrupt should do nothing when we're not running.
- ASSERT_FALSE(fix.client.Interrupt());
+ ASSERT_FALSE(client.Interrupt());
// Continue. After the run packet is sent, send an interrupt.
std::future<StateType> continue_state = std::async(
- std::launch::async, [&] { return fix.SendCPacket(continue_response); });
- ASSERT_EQ(PacketResult::Success, fix.server.GetPacket(response));
+ std::launch::async, [&] { return SendCPacket(continue_response); });
+ ASSERT_EQ(PacketResult::Success, server.GetPacket(response));
ASSERT_EQ("c", response.GetStringRef());
- fix.WaitForRunEvent();
+ WaitForRunEvent();
std::future<bool> async_result =
- std::async(std::launch::async, [&] { return fix.client.Interrupt(); });
+ std::async(std::launch::async, [&] { return client.Interrupt(); });
// We get interrupted.
- ASSERT_EQ(PacketResult::Success, fix.server.GetPacket(response));
+ ASSERT_EQ(PacketResult::Success, server.GetPacket(response));
ASSERT_EQ("\x03", response.GetStringRef());
- ASSERT_EQ(PacketResult::Success, fix.server.SendPacket("T13"));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("T13"));
// And that's it.
ASSERT_EQ(eStateStopped, continue_state.get());
@@ -217,62 +203,56 @@ TEST_F(GDBRemoteClientBaseTest, SendCont
TEST_F(GDBRemoteClientBaseTest, SendContinueAndLateInterrupt) {
StringExtractorGDBRemote continue_response, response;
- ContinueFixture fix;
- if (HasFailure())
- return;
// Continue. After the run packet is sent, send an interrupt.
std::future<StateType> continue_state = std::async(
- std::launch::async, [&] { return fix.SendCPacket(continue_response); });
- ASSERT_EQ(PacketResult::Success, fix.server.GetPacket(response));
+ std::launch::async, [&] { return SendCPacket(continue_response); });
+ ASSERT_EQ(PacketResult::Success, server.GetPacket(response));
ASSERT_EQ("c", response.GetStringRef());
- fix.WaitForRunEvent();
+ WaitForRunEvent();
std::future<bool> async_result =
- std::async(std::launch::async, [&] { return fix.client.Interrupt(); });
+ std::async(std::launch::async, [&] { return client.Interrupt(); });
// However, the target stops due to a different reason than the original
// interrupt.
- ASSERT_EQ(PacketResult::Success, fix.server.GetPacket(response));
+ ASSERT_EQ(PacketResult::Success, server.GetPacket(response));
ASSERT_EQ("\x03", response.GetStringRef());
- ASSERT_EQ(PacketResult::Success, fix.server.SendPacket("T01"));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("T01"));
ASSERT_EQ(eStateStopped, continue_state.get());
ASSERT_EQ("T01", continue_response.GetStringRef());
ASSERT_TRUE(async_result.get());
// The subsequent continue packet should work normally.
- ASSERT_EQ(PacketResult::Success, fix.server.SendPacket("T01"));
- ASSERT_EQ(eStateStopped, fix.SendCPacket(response));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("T01"));
+ ASSERT_EQ(eStateStopped, SendCPacket(response));
ASSERT_EQ("T01", response.GetStringRef());
- ASSERT_EQ(PacketResult::Success, fix.server.GetPacket(response));
+ ASSERT_EQ(PacketResult::Success, server.GetPacket(response));
ASSERT_EQ("c", response.GetStringRef());
}
TEST_F(GDBRemoteClientBaseTest, SendContinueAndInterrupt2PacketBug) {
StringExtractorGDBRemote continue_response, async_response, response;
const bool send_async = true;
- ContinueFixture fix;
- if (HasFailure())
- return;
// Interrupt should do nothing when we're not running.
- ASSERT_FALSE(fix.client.Interrupt());
+ ASSERT_FALSE(client.Interrupt());
// Continue. After the run packet is sent, send an async signal.
std::future<StateType> continue_state = std::async(
- std::launch::async, [&] { return fix.SendCPacket(continue_response); });
- ASSERT_EQ(PacketResult::Success, fix.server.GetPacket(response));
+ std::launch::async, [&] { return SendCPacket(continue_response); });
+ ASSERT_EQ(PacketResult::Success, server.GetPacket(response));
ASSERT_EQ("c", response.GetStringRef());
- fix.WaitForRunEvent();
+ WaitForRunEvent();
std::future<bool> interrupt_result =
- std::async(std::launch::async, [&] { return fix.client.Interrupt(); });
+ std::async(std::launch::async, [&] { return client.Interrupt(); });
// We get interrupted. We'll send two packets to simulate a buggy stub.
- ASSERT_EQ(PacketResult::Success, fix.server.GetPacket(response));
+ ASSERT_EQ(PacketResult::Success, server.GetPacket(response));
ASSERT_EQ("\x03", response.GetStringRef());
- ASSERT_EQ(PacketResult::Success, fix.server.SendPacket("T13"));
- ASSERT_EQ(PacketResult::Success, fix.server.SendPacket("T13"));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("T13"));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("T13"));
// We should stop.
ASSERT_EQ(eStateStopped, continue_state.get());
@@ -281,37 +261,34 @@ TEST_F(GDBRemoteClientBaseTest, SendCont
// Packet stream should remain synchronized.
std::future<PacketResult> send_result = std::async(std::launch::async, [&] {
- return fix.client.SendPacketAndWaitForResponse("qTest", async_response,
- !send_async);
+ return client.SendPacketAndWaitForResponse("qTest", async_response,
+ !send_async);
});
- ASSERT_EQ(PacketResult::Success, fix.server.GetPacket(response));
+ ASSERT_EQ(PacketResult::Success, server.GetPacket(response));
ASSERT_EQ("qTest", response.GetStringRef());
- ASSERT_EQ(PacketResult::Success, fix.server.SendPacket("QTest"));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("QTest"));
ASSERT_EQ(PacketResult::Success, send_result.get());
ASSERT_EQ("QTest", async_response.GetStringRef());
}
TEST_F(GDBRemoteClientBaseTest, SendContinueDelegateInterface) {
StringExtractorGDBRemote response;
- ContinueFixture fix;
- if (HasFailure())
- return;
// Continue. We'll have the server send a bunch of async packets before it
// stops.
- ASSERT_EQ(PacketResult::Success, fix.server.SendPacket("O4142"));
- ASSERT_EQ(PacketResult::Success, fix.server.SendPacket("Apro"));
- ASSERT_EQ(PacketResult::Success, fix.server.SendPacket("O4344"));
- ASSERT_EQ(PacketResult::Success, fix.server.SendPacket("Afile"));
- ASSERT_EQ(PacketResult::Success, fix.server.SendPacket("T01"));
- ASSERT_EQ(eStateStopped, fix.SendCPacket(response));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("O4142"));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("Apro"));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("O4344"));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("Afile"));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("T01"));
+ ASSERT_EQ(eStateStopped, SendCPacket(response));
ASSERT_EQ("T01", response.GetStringRef());
- ASSERT_EQ(PacketResult::Success, fix.server.GetPacket(response));
+ ASSERT_EQ(PacketResult::Success, server.GetPacket(response));
ASSERT_EQ("c", response.GetStringRef());
- EXPECT_EQ("ABCD", fix.delegate.output);
- EXPECT_EQ("profile", fix.delegate.misc_data);
- EXPECT_EQ(1u, fix.delegate.stop_reply_called);
+ EXPECT_EQ("ABCD", delegate.output);
+ EXPECT_EQ("profile", delegate.misc_data);
+ EXPECT_EQ(1u, delegate.stop_reply_called);
}
TEST_F(GDBRemoteClientBaseTest, SendContinueDelegateStructuredDataReceipt) {
@@ -327,42 +304,35 @@ TEST_F(GDBRemoteClientBaseTest, SendCont
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(PacketResult::Success, server.SendPacket(stream.GetData()));
+ ASSERT_EQ(PacketResult::Success, server.SendPacket("T01"));
+ ASSERT_EQ(eStateStopped, SendCPacket(response));
ASSERT_EQ("T01", response.GetStringRef());
- ASSERT_EQ(1ul, fix.delegate.structured_data_packets.size());
+ ASSERT_EQ(1ul, 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]);
+ ASSERT_EQ(json_packet, delegate.structured_data_packets[0]);
}
TEST_F(GDBRemoteClientBaseTest, InterruptNoResponse) {
StringExtractorGDBRemote continue_response, response;
- ContinueFixture fix;
- if (HasFailure())
- return;
// Continue. After the run packet is sent, send an interrupt.
std::future<StateType> continue_state = std::async(
- std::launch::async, [&] { return fix.SendCPacket(continue_response); });
- ASSERT_EQ(PacketResult::Success, fix.server.GetPacket(response));
+ std::launch::async, [&] { return SendCPacket(continue_response); });
+ ASSERT_EQ(PacketResult::Success, server.GetPacket(response));
ASSERT_EQ("c", response.GetStringRef());
- fix.WaitForRunEvent();
+ WaitForRunEvent();
std::future<bool> async_result =
- std::async(std::launch::async, [&] { return fix.client.Interrupt(); });
+ std::async(std::launch::async, [&] { return client.Interrupt(); });
// We get interrupted, but we don't send a stop packet.
- ASSERT_EQ(PacketResult::Success, fix.server.GetPacket(response));
+ ASSERT_EQ(PacketResult::Success, server.GetPacket(response));
ASSERT_EQ("\x03", response.GetStringRef());
// The functions should still terminate (after a timeout).
Modified: lldb/trunk/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp?rev=306013&r1=306012&r2=306013&view=diff
==============================================================================
--- lldb/trunk/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp (original)
+++ lldb/trunk/unittests/Process/gdb-remote/GDBRemoteCommunicationClientTest.cpp Thu Jun 22 10:54:21 2017
@@ -11,14 +11,14 @@
#include "GDBRemoteTestUtils.h"
#include "Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.h"
-#include "lldb/lldb-enumerations.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"
-
+#include "lldb/lldb-enumerations.h"
#include "llvm/ADT/ArrayRef.h"
+#include "llvm/Testing/Support/Error.h"
using namespace lldb_private::process_gdb_remote;
using namespace lldb_private;
@@ -58,15 +58,18 @@ std::string one_register_hex = "41424344
} // end anonymous namespace
-class GDBRemoteCommunicationClientTest : public GDBRemoteTest {};
+class GDBRemoteCommunicationClientTest : public GDBRemoteTest {
+public:
+ void SetUp() override {
+ ASSERT_THAT_ERROR(Connect(client, server), llvm::Succeeded());
+ }
-TEST_F(GDBRemoteCommunicationClientTest, WriteRegister) {
+protected:
TestClient client;
MockServer server;
- Connect(client, server);
- if (HasFailure())
- return;
+};
+TEST_F(GDBRemoteCommunicationClientTest, WriteRegister) {
const lldb::tid_t tid = 0x47;
const uint32_t reg_num = 4;
std::future<bool> write_result = std::async(std::launch::async, [&] {
@@ -87,12 +90,6 @@ TEST_F(GDBRemoteCommunicationClientTest,
}
TEST_F(GDBRemoteCommunicationClientTest, WriteRegisterNoSuffix) {
- TestClient client;
- MockServer server;
- Connect(client, server);
- if (HasFailure())
- return;
-
const lldb::tid_t tid = 0x47;
const uint32_t reg_num = 4;
std::future<bool> write_result = std::async(std::launch::async, [&] {
@@ -113,12 +110,6 @@ TEST_F(GDBRemoteCommunicationClientTest,
}
TEST_F(GDBRemoteCommunicationClientTest, ReadRegister) {
- TestClient client;
- MockServer server;
- Connect(client, server);
- if (HasFailure())
- return;
-
const lldb::tid_t tid = 0x47;
const uint32_t reg_num = 4;
std::future<bool> async_result = std::async(
@@ -145,12 +136,6 @@ TEST_F(GDBRemoteCommunicationClientTest,
}
TEST_F(GDBRemoteCommunicationClientTest, SaveRestoreRegistersNoSuffix) {
- TestClient client;
- MockServer server;
- Connect(client, server);
- if (HasFailure())
- return;
-
const lldb::tid_t tid = 0x47;
uint32_t save_id;
std::future<bool> async_result = std::async(std::launch::async, [&] {
@@ -170,12 +155,6 @@ TEST_F(GDBRemoteCommunicationClientTest,
}
TEST_F(GDBRemoteCommunicationClientTest, SyncThreadState) {
- TestClient client;
- MockServer server;
- Connect(client, server);
- if (HasFailure())
- return;
-
const lldb::tid_t tid = 0x47;
std::future<bool> async_result = std::async(
std::launch::async, [&] { return client.SyncThreadState(tid); });
@@ -185,12 +164,6 @@ TEST_F(GDBRemoteCommunicationClientTest,
}
TEST_F(GDBRemoteCommunicationClientTest, GetModulesInfo) {
- TestClient client;
- MockServer server;
- Connect(client, server);
- if (HasFailure())
- return;
-
llvm::Triple triple("i386-pc-linux");
FileSpec file_specs[] = {
@@ -225,12 +198,6 @@ TEST_F(GDBRemoteCommunicationClientTest,
}
TEST_F(GDBRemoteCommunicationClientTest, GetModulesInfoInvalidResponse) {
- TestClient client;
- MockServer server;
- Connect(client, server);
- if (HasFailure())
- return;
-
llvm::Triple triple("i386-pc-linux");
FileSpec file_spec("/foo/bar.so", false, FileSpec::ePathSyntaxPosix);
@@ -267,13 +234,7 @@ TEST_F(GDBRemoteCommunicationClientTest,
}
TEST_F(GDBRemoteCommunicationClientTest, TestPacketSpeedJSON) {
- TestClient client;
- MockServer server;
- Connect(client, server);
- if (HasFailure())
- return;
-
- std::thread server_thread([&server] {
+ std::thread server_thread([this] {
for (;;) {
StringExtractorGDBRemote request;
PacketResult result = server.GetPacket(request);
@@ -312,12 +273,6 @@ TEST_F(GDBRemoteCommunicationClientTest,
}
TEST_F(GDBRemoteCommunicationClientTest, SendSignalsToIgnore) {
- TestClient client;
- MockServer server;
- Connect(client, server);
- if (HasFailure())
- return;
-
std::future<Status> result = std::async(std::launch::async, [&] {
return client.SendSignalsToIgnore({2, 3, 5, 7, 0xB, 0xD, 0x11});
});
@@ -334,12 +289,6 @@ TEST_F(GDBRemoteCommunicationClientTest,
}
TEST_F(GDBRemoteCommunicationClientTest, GetMemoryRegionInfo) {
- TestClient client;
- MockServer server;
- Connect(client, server);
- if (HasFailure())
- return;
-
const lldb::addr_t addr = 0xa000;
MemoryRegionInfo region_info;
std::future<Status> result = std::async(std::launch::async, [&] {
@@ -355,12 +304,6 @@ TEST_F(GDBRemoteCommunicationClientTest,
}
TEST_F(GDBRemoteCommunicationClientTest, GetMemoryRegionInfoInvalidResponse) {
- TestClient client;
- MockServer server;
- Connect(client, server);
- if (HasFailure())
- return;
-
const lldb::addr_t addr = 0x4000;
MemoryRegionInfo region_info;
std::future<Status> result = std::async(std::launch::async, [&] {
@@ -372,12 +315,6 @@ TEST_F(GDBRemoteCommunicationClientTest,
}
TEST_F(GDBRemoteCommunicationClientTest, SendStartTracePacket) {
- TestClient client;
- MockServer server;
- Connect(client, server);
- if (HasFailure())
- return;
-
TraceOptions options;
Status error;
@@ -417,12 +354,6 @@ TEST_F(GDBRemoteCommunicationClientTest,
}
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;
@@ -444,12 +375,6 @@ TEST_F(GDBRemoteCommunicationClientTest,
}
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;
@@ -482,12 +407,6 @@ TEST_F(GDBRemoteCommunicationClientTest,
}
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;
@@ -520,12 +439,6 @@ TEST_F(GDBRemoteCommunicationClientTest,
}
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;
Modified: lldb/trunk/unittests/Process/gdb-remote/GDBRemoteTestUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Process/gdb-remote/GDBRemoteTestUtils.cpp?rev=306013&r1=306012&r2=306013&view=diff
==============================================================================
--- lldb/trunk/unittests/Process/gdb-remote/GDBRemoteTestUtils.cpp (original)
+++ lldb/trunk/unittests/Process/gdb-remote/GDBRemoteTestUtils.cpp Thu Jun 22 10:54:21 2017
@@ -30,30 +30,33 @@ void GDBRemoteTest::TearDownTestCase() {
#endif
}
-void Connect(GDBRemoteCommunication &client, GDBRemoteCommunication &server) {
+llvm::Error GDBRemoteTest::Connect(GDBRemoteCommunication &client,
+ GDBRemoteCommunication &server) {
bool child_processes_inherit = false;
- Status error;
TCPSocket listen_socket(true, child_processes_inherit);
- ASSERT_FALSE(error.Fail());
- error = listen_socket.Listen("127.0.0.1:0", 5);
- ASSERT_FALSE(error.Fail());
+ if (llvm::Error error = listen_socket.Listen("127.0.0.1:0", 5).ToError())
+ return error;
Socket *accept_socket;
- std::future<Status> accept_error = std::async(
+ std::future<Status> accept_status = std::async(
std::launch::async, [&] { return listen_socket.Accept(accept_socket); });
- char connect_remote_address[64];
- snprintf(connect_remote_address, sizeof(connect_remote_address),
- "connect://localhost:%u", listen_socket.GetLocalPortNumber());
+ llvm::SmallString<32> remote_addr;
+ llvm::raw_svector_ostream(remote_addr)
+ << "connect://localhost:" << listen_socket.GetLocalPortNumber();
- std::unique_ptr<ConnectionFileDescriptor> conn_ap(
+ std::unique_ptr<ConnectionFileDescriptor> conn_up(
new ConnectionFileDescriptor());
- ASSERT_EQ(conn_ap->Connect(connect_remote_address, nullptr),
- lldb::eConnectionStatusSuccess);
+ if (conn_up->Connect(remote_addr, nullptr) != lldb::eConnectionStatusSuccess)
+ return llvm::make_error<llvm::StringError>("Unable to connect",
+ llvm::inconvertibleErrorCode());
+
+ client.SetConnection(conn_up.release());
+ if (llvm::Error error = accept_status.get().ToError())
+ return error;
- client.SetConnection(conn_ap.release());
- ASSERT_TRUE(accept_error.get().Success());
server.SetConnection(new ConnectionFileDescriptor(accept_socket));
+ return llvm::Error::success();
}
} // namespace process_gdb_remote
Modified: lldb/trunk/unittests/Process/gdb-remote/GDBRemoteTestUtils.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Process/gdb-remote/GDBRemoteTestUtils.h?rev=306013&r1=306012&r2=306013&view=diff
==============================================================================
--- lldb/trunk/unittests/Process/gdb-remote/GDBRemoteTestUtils.h (original)
+++ lldb/trunk/unittests/Process/gdb-remote/GDBRemoteTestUtils.h Thu Jun 22 10:54:21 2017
@@ -19,11 +19,12 @@ namespace process_gdb_remote {
class GDBRemoteTest : public testing::Test {
public:
static void SetUpTestCase();
-
static void TearDownTestCase();
-};
-void Connect(GDBRemoteCommunication &client, GDBRemoteCommunication &server);
+protected:
+ llvm::Error Connect(GDBRemoteCommunication &client,
+ GDBRemoteCommunication &server);
+};
struct MockServer : public GDBRemoteCommunicationServer {
MockServer()
More information about the lldb-commits
mailing list