[Lldb-commits] [lldb] [lldb] Fixed PipeWindows bugs; added Pipe::WriteWithTimeout() (PR #101383)

Pavel Labath via lldb-commits lldb-commits at lists.llvm.org
Mon Aug 5 06:27:50 PDT 2024


================
@@ -47,5 +50,92 @@ TEST_F(PipeTest, OpenAsReader) {
   ASSERT_THAT_ERROR(
       pipe.OpenAsReader(name_ref, /*child_process_inherit=*/false).ToError(),
       llvm::Succeeded());
+
+  ASSERT_TRUE(pipe.CanRead());
 }
 #endif
+
+TEST_F(PipeTest, WriteWithTimeout) {
+  Pipe pipe;
+  ASSERT_THAT_ERROR(pipe.CreateNew(false).ToError(), llvm::Succeeded());
+  // Note write_chunk_size must be less than the pipe buffer.
+  // The pipe buffer is 1024 for PipeWindows and at least 512 on Darwin.
+  const size_t buf_size = 8192;
+  const size_t write_chunk_size = 234;
+
+  std::vector<int32_t> write_buf(buf_size / sizeof(int32_t));
+  std::iota(write_buf.begin(), write_buf.end(), 0);
+  std::vector<int32_t> read_buf(write_buf.size() + 100, -1);
+
+  char *write_ptr = (char *)&write_buf.front();
+  char *read_ptr = (char *)&read_buf.front();
+  size_t write_bytes = 0;
+  size_t read_bytes = 0;
+  size_t num_bytes = 0;
+
+  // Write to the pipe until it is full.
+  while (write_bytes < buf_size) {
+    Status error =
+        pipe.WriteWithTimeout(write_ptr + write_bytes, write_chunk_size,
+                              std::chrono::milliseconds(10), num_bytes);
+    if (error.Fail())
+      break; // The write buffer is full
+    write_bytes += num_bytes;
+  }
+  ASSERT_TRUE(write_bytes + write_chunk_size <= buf_size);
+
+  // Attempt a write with a long timeout.
+  auto start_time = std::chrono::steady_clock::now();
+  ASSERT_THAT_ERROR(
+      pipe.WriteWithTimeout(write_ptr + write_bytes, write_chunk_size,
+                            std::chrono::milliseconds(2000), num_bytes)
----------------
labath wrote:

```suggestion
                            std::chrono::seconds(2), num_bytes)
```

https://github.com/llvm/llvm-project/pull/101383


More information about the lldb-commits mailing list