77// ===----------------------------------------------------------------------===//
88
99#include " lldb/Core/Communication.h"
10+ #include " TestingSupport/SubsystemRAII.h"
1011#include " lldb/Core/ThreadedCommunication.h"
1112#include " lldb/Host/Config.h"
1213#include " lldb/Host/ConnectionFileDescriptor.h"
1314#include " lldb/Host/Pipe.h"
15+ #include " lldb/Host/Socket.h"
1416#include " llvm/Testing/Support/Error.h"
1517#include " gtest/gtest.h"
16- #include " TestingSupport/Host/SocketTestUtilities.h"
17- #include " TestingSupport/SubsystemRAII.h"
1818
1919#include < chrono>
2020#include < thread>
@@ -31,15 +31,17 @@ class CommunicationTest : public testing::Test {
3131};
3232
3333static void CommunicationReadTest (bool use_read_thread) {
34- std::unique_ptr<TCPSocket> a, b;
35- ASSERT_TRUE (CreateTCPConnectedSockets (" localhost" , &a, &b));
34+ llvm::Expected<Socket::Pair> pair = Socket::CreatePair ();
35+ ASSERT_THAT_EXPECTED (pair, llvm::Succeeded ());
36+ Socket &a = *pair->first ;
3637
3738 size_t num_bytes = 4 ;
38- ASSERT_THAT_ERROR (a-> Write (" test" , num_bytes).ToError (), llvm::Succeeded ());
39+ ASSERT_THAT_ERROR (a. Write (" test" , num_bytes).ToError (), llvm::Succeeded ());
3940 ASSERT_EQ (num_bytes, 4U );
4041
4142 ThreadedCommunication comm (" test" );
42- comm.SetConnection (std::make_unique<ConnectionFileDescriptor>(b.release ()));
43+ comm.SetConnection (
44+ std::make_unique<ConnectionFileDescriptor>(pair->second .release ()));
4345 comm.SetCloseOnEOF (true );
4446
4547 if (use_read_thread) {
@@ -73,7 +75,7 @@ static void CommunicationReadTest(bool use_read_thread) {
7375 EXPECT_THAT_ERROR (error.ToError (), llvm::Failed ());
7476
7577 // This read should return EOF.
76- ASSERT_THAT_ERROR (a-> Close ().ToError (), llvm::Succeeded ());
78+ ASSERT_THAT_ERROR (a. Close ().ToError (), llvm::Succeeded ());
7779 error.Clear ();
7880 EXPECT_EQ (
7981 comm.Read (buf, sizeof (buf), std::chrono::seconds (5 ), status, &error), 0U );
@@ -118,17 +120,19 @@ TEST_F(CommunicationTest, ReadThread) {
118120}
119121
120122TEST_F (CommunicationTest, SynchronizeWhileClosing) {
121- std::unique_ptr<TCPSocket> a, b;
122- ASSERT_TRUE (CreateTCPConnectedSockets (" localhost" , &a, &b));
123+ llvm::Expected<Socket::Pair> pair = Socket::CreatePair ();
124+ ASSERT_THAT_EXPECTED (pair, llvm::Succeeded ());
125+ Socket &a = *pair->first ;
123126
124127 ThreadedCommunication comm (" test" );
125- comm.SetConnection (std::make_unique<ConnectionFileDescriptor>(b.release ()));
128+ comm.SetConnection (
129+ std::make_unique<ConnectionFileDescriptor>(pair->second .release ()));
126130 comm.SetCloseOnEOF (true );
127131 ASSERT_TRUE (comm.StartReadThread ());
128132
129133 // Ensure that we can safely synchronize with the read thread while it is
130134 // closing the read end (in response to us closing the write end).
131- ASSERT_THAT_ERROR (a-> Close ().ToError (), llvm::Succeeded ());
135+ ASSERT_THAT_ERROR (a. Close ().ToError (), llvm::Succeeded ());
132136 comm.SynchronizeWithReadThread ();
133137
134138 ASSERT_TRUE (comm.StopReadThread ());
0 commit comments