Commit 2441399f by Jamie Madill Committed by Commit Bot

Test Utils: Read available stream data on posix.

ANGLE would only read one chunk of stdout/stderr data at a time. We would end up slowing down reading one chunk every few hundred MS for tests with a very large output stream. Test: *debug_negative_coverage* Bug: angleproject:3162 Change-Id: I072cba147a6d86c02a2eda051ff61ed981990798 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2447040Reviewed-by: 's avatarShahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent 9413c402
......@@ -58,33 +58,36 @@ struct ScopedPipe
};
};
bool ReadFromFile(int fd, std::string *out)
enum class ReadResult
{
char buffer[256];
NoData,
GotData,
};
ReadResult ReadFromFile(int fd, std::string *out)
{
constexpr size_t kBufSize = 2048;
char buffer[kBufSize];
ssize_t bytesRead = read(fd, buffer, sizeof(buffer));
// If interrupted, retry.
if (bytesRead < 0 && errno == EINTR)
{
return true;
return ReadResult::GotData;
}
// If failed, or nothing to read, we are done.
if (bytesRead <= 0)
{
return false;
return ReadResult::NoData;
}
out->append(buffer, bytesRead);
return true;
return ReadResult::GotData;
}
void ReadEntireFile(int fd, std::string *out)
{
while (true)
while (ReadFromFile(fd, out) == ReadResult::GotData)
{
if (!ReadFromFile(fd, out))
break;
}
}
......@@ -244,12 +247,12 @@ class PosixProcess : public Process
if (mStdoutPipe.valid())
{
ReadFromFile(mStdoutPipe.fds[0], &mStdout);
ReadEntireFile(mStdoutPipe.fds[0], &mStdout);
}
if (mStderrPipe.valid())
{
ReadFromFile(mStderrPipe.fds[0], &mStderr);
ReadEntireFile(mStderrPipe.fds[0], &mStderr);
}
return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment