[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 04:22:25 PDT 2024
================
@@ -44,8 +42,70 @@ TEST_F(PipeTest, OpenAsReader) {
size_t name_len = name.size();
name += "foobar";
llvm::StringRef name_ref(name.data(), name_len);
+ // Note OpenAsReader() do nothing on Windows, the pipe is already opened for
+ // read and write.
ASSERT_THAT_ERROR(
pipe.OpenAsReader(name_ref, /*child_process_inherit=*/false).ToError(),
llvm::Succeeded());
+
+ ASSERT_TRUE(pipe.CanRead());
+}
+
+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 4096 for PipePosix.
+ const size_t buf_size = 8192;
+ const size_t write_chunk_size = 256;
+ const size_t read_chunk_size = 300;
+ std::unique_ptr<int32_t[]> write_buf_ptr(
+ new int32_t[buf_size / sizeof(int32_t)]);
+ int32_t *write_buf = write_buf_ptr.get();
+ std::unique_ptr<int32_t[]> read_buf_ptr(
+ new int32_t[(buf_size + 100) / sizeof(int32_t)]);
+ int32_t *read_buf = read_buf_ptr.get();
+ for (int i = 0; i < buf_size / sizeof(int32_t); ++i) {
+ write_buf[i] = i;
+ read_buf[i] = -i;
+ }
----------------
labath wrote:
```
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);
```
or something similar, depending on how the rest of the test ends up looking like.
The result is shorter, and there's only `/sizeof` in the entire snippet.
https://github.com/llvm/llvm-project/pull/101383
More information about the lldb-commits
mailing list