[Lldb-commits] [lldb] [lldb] Adding pipe support to lldb_private::MainLoopWindows. (PR #145621)
Pavel Labath via lldb-commits
lldb-commits at lists.llvm.org
Mon Jun 30 02:45:52 PDT 2025
================
@@ -79,7 +79,68 @@ TEST_F(MainLoopTest, ReadObject) {
ASSERT_EQ(1u, callback_count);
}
-TEST_F(MainLoopTest, NoSpuriousReads) {
+TEST_F(MainLoopTest, ReadPipeObject) {
+ Pipe pipe;
+
+ ASSERT_TRUE(pipe.CreateNew().Success());
+
+ MainLoop loop;
+
+ char X = 'X';
+ size_t len = sizeof(X);
+ ASSERT_THAT_EXPECTED(pipe.Write(&X, len), llvm::Succeeded());
+
+ Status error;
+ auto handle = loop.RegisterReadObject(
+ std::make_shared<NativeFile>(pipe.GetReadFileDescriptor(),
+ File::eOpenOptionReadOnly, false),
+ make_callback(), error);
+ ASSERT_TRUE(error.Success());
+ ASSERT_TRUE(handle);
+ ASSERT_TRUE(loop.Run().Success());
+ ASSERT_EQ(1u, callback_count);
+}
+
+TEST_F(MainLoopTest, NoSpuriousPipeReads) {
+ Pipe pipe;
+
+ ASSERT_TRUE(pipe.CreateNew().Success());
+
+ char X = 'X';
+ size_t len = sizeof(X);
+ ASSERT_THAT_EXPECTED(pipe.Write(&X, len), llvm::Succeeded());
+
+ lldb::IOObjectSP r = std::make_shared<NativeFile>(
+ pipe.GetReadFileDescriptor(), File::eOpenOptionReadOnly, false);
+
+ MainLoop loop;
+
+ Status error;
+ auto handle = loop.RegisterReadObject(
+ r,
+ [&](MainLoopBase &) {
+ if (callback_count == 0) {
+ // Read the byte back the first time we're called. After that, the
+ // pipe is empty, and we should not be called anymore.
+ char X;
+ size_t len = sizeof(X);
+ EXPECT_THAT_ERROR(r->Read(&X, len).ToError(), llvm::Succeeded());
+ EXPECT_EQ(len, sizeof(X));
----------------
labath wrote:
```suggestion
EXPECT_THAT_EXPECTED(r->Read(&X, len).ToError(), llvm::HasValue(1));
```
https://github.com/llvm/llvm-project/pull/145621
More information about the lldb-commits
mailing list