diff options
Diffstat (limited to 'compiler-rt/lib/sanitizer_common/tests/sanitizer_linux_test.cc')
-rw-r--r-- | compiler-rt/lib/sanitizer_common/tests/sanitizer_linux_test.cc | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_linux_test.cc b/compiler-rt/lib/sanitizer_common/tests/sanitizer_linux_test.cc index eef71010afe..92d495e10b4 100644 --- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_linux_test.cc +++ b/compiler-rt/lib/sanitizer_common/tests/sanitizer_linux_test.cc @@ -263,6 +263,36 @@ TEST(SanitizerLinux, ThreadSelfTest) { } #endif +TEST(SanitizerCommon, StartSubprocessTest) { + int pipe_fds[2]; + ASSERT_EQ(0, pipe(pipe_fds)); + const char *argv[] = {"/bin/sh", "-c", "echo -n 'hello'"}; + int pid = StartSubprocess("/bin/sh", const_cast<char **>(&argv[0]), + kInvalidFd /* stdin */, pipe_fds[1] /* stdout */); + ASSERT_GT(pid, 0); + + // wait for process to finish. + while (IsProcessRunning(pid)) { + } + ASSERT_FALSE(IsProcessRunning(pid)); + + char buffer[256]; + { + char *ptr = buffer; + uptr bytes_read; + while (ReadFromFile(pipe_fds[0], ptr, 256, &bytes_read)) { + if (!bytes_read) { + break; + } + ptr += bytes_read; + } + ASSERT_EQ(5, ptr - buffer); + *ptr = 0; + } + ASSERT_EQ(0, strcmp(buffer, "hello")) << "Buffer: " << buffer; + internal_close(pipe_fds[0]); +} + } // namespace __sanitizer #endif // SANITIZER_LINUX |