| 58 | class SubprocessTest : public KuduTest {}; |
| 59 | |
| 60 | TEST_F(SubprocessTest, TestSimplePipe) { |
| 61 | Subprocess p({ "/usr/bin/tr", "a-z", "A-Z" }); |
| 62 | p.ShareParentStdout(false); |
| 63 | ASSERT_OK(p.Start()); |
| 64 | |
| 65 | FILE* out = fdopen(p.ReleaseChildStdinFd(), "w"); |
| 66 | PCHECK(out); |
| 67 | FILE* in = fdopen(p.from_child_stdout_fd(), "r"); |
| 68 | PCHECK(in); |
| 69 | |
| 70 | fprintf(out, "hello world\n"); |
| 71 | // We have to close 'out' or else tr won't write any output, since |
| 72 | // it enters a buffered mode if it detects that its input is a FIFO. |
| 73 | int err; |
| 74 | RETRY_ON_EINTR(err, fclose(out)); |
| 75 | |
| 76 | char buf[1024]; |
| 77 | ASSERT_EQ(buf, fgets(buf, sizeof(buf), in)); |
| 78 | ASSERT_STREQ("HELLO WORLD\n", &buf[0]); |
| 79 | |
| 80 | int wait_status = 0; |
| 81 | ASSERT_OK(p.Wait(&wait_status)); |
| 82 | ASSERT_TRUE(WIFEXITED(wait_status)); |
| 83 | ASSERT_EQ(0, WEXITSTATUS(wait_status)); |
| 84 | } |
| 85 | |
| 86 | TEST_F(SubprocessTest, TestErrPipe) { |
| 87 | Subprocess p({ "/usr/bin/tee", "/dev/stderr" }); |
nothing calls this directly
no test coverage detected