summaryrefslogtreecommitdiff
path: root/common/subprocess_unittest.cc
diff options
context:
space:
mode:
authorAlex Deymo <deymo@google.com>2016-04-07 16:22:13 -0700
committerAlex Deymo <deymo@google.com>2016-04-08 14:21:23 -0700
commit279d57295a39add08d719db4cebe950d56c35164 (patch)
tree8b7bbab363475ebce901a301ff7ff1b532e059f4 /common/subprocess_unittest.cc
parentc5081a85c015af09411a8f2b9343e70dcd08d7af (diff)
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
Diffstat (limited to 'common/subprocess_unittest.cc')
-rw-r--r--common/subprocess_unittest.cc14
1 files changed, 8 insertions, 6 deletions
diff --git a/common/subprocess_unittest.cc b/common/subprocess_unittest.cc
index 5ca44e80..cc1f3537 100644
--- a/common/subprocess_unittest.cc
+++ b/common/subprocess_unittest.cc
@@ -171,13 +171,15 @@ TEST_F(SubprocessTest, PipeRedirectFdTest) {
// 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();
}