1 //===-- CommunicationTest.cpp ---------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "lldb/Core/Communication.h" 10 #include "lldb/Host/ConnectionFileDescriptor.h" 11 #include "lldb/Host/Pipe.h" 12 #include "llvm/Testing/Support/Error.h" 13 #include "gtest/gtest.h" 14 15 using namespace lldb_private; 16 17 #ifndef _WIN32 TEST(CommunicationTest,SynchronizeWhileClosing)18TEST(CommunicationTest, SynchronizeWhileClosing) { 19 // Set up a communication object reading from a pipe. 20 Pipe pipe; 21 ASSERT_THAT_ERROR(pipe.CreateNew(/*child_process_inherit=*/false).ToError(), 22 llvm::Succeeded()); 23 24 Communication comm("test"); 25 comm.SetConnection(std::make_unique<ConnectionFileDescriptor>( 26 pipe.ReleaseReadFileDescriptor(), /*owns_fd=*/true)); 27 comm.SetCloseOnEOF(true); 28 ASSERT_TRUE(comm.StartReadThread()); 29 30 // Ensure that we can safely synchronize with the read thread while it is 31 // closing the read end (in response to us closing the write end). 32 pipe.CloseWriteFileDescriptor(); 33 comm.SynchronizeWithReadThread(); 34 35 ASSERT_TRUE(comm.StopReadThread()); 36 } 37 #endif 38