Fix PipeClosedWhenNotRedirectedTest.
When checking for a file descriptor open on the child, we now execute a
simple test program that just runs fstat on that file descriptor. This
is more reliable than calling sh on different platforms.
Bug: 26955860
TEST=Ran unittests on edison-eng and Chromium OS.
Change-Id: I5d5d87095564159df1a75e78b0aed29c16bc7eb8
diff --git a/common/subprocess_unittest.cc b/common/subprocess_unittest.cc
index 5ca44e8..cc1f353 100644
--- a/common/subprocess_unittest.cc
+++ b/common/subprocess_unittest.cc
@@ -171,13 +171,15 @@
// Test that a pipe file descriptor open in the parent is not open in the child.
TEST_F(SubprocessTest, PipeClosedWhenNotRedirectedTest) {
brillo::ScopedPipe pipe;
- const vector<string> cmd = {kBinPath "/sh", "-c",
- base::StringPrintf("echo on pipe >/proc/self/fd/%d", pipe.writer)};
+
+ // test_subprocess will return with the errno of fstat, which should be EBADF
+ // if the passed file descriptor is closed in the child.
+ const vector<string> cmd = {
+ test_utils::GetBuildArtifactsPath("test_subprocess"),
+ "fstat",
+ std::to_string(pipe.writer)};
EXPECT_TRUE(subprocess_.ExecFlags(
- cmd,
- 0,
- {},
- base::Bind(&ExpectedResults, 1, "")));
+ cmd, 0, {}, base::Bind(&ExpectedResults, EBADF, "")));
loop_.Run();
}