AU: Add support for reading the output of synchronous exec calls.
This will be used in a subsequent patch to invoke 'crossystem hwid' to read the
HWID.
BUG=chromium-os:15255
TEST=unit tests, tested AU on device
Change-Id: Ie26bae3621626d40f92f08e8549eefda77151102
Reviewed-on: http://gerrit.chromium.org/gerrit/1047
Reviewed-by: Thieu Le <thieule@chromium.org>
Tested-by: Darin Petkov <petkov@chromium.org>
diff --git a/subprocess_unittest.cc b/subprocess_unittest.cc
index 37deba9..6c0dcb2 100644
--- a/subprocess_unittest.cc
+++ b/subprocess_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -72,6 +72,28 @@
g_main_loop_unref(loop);
}
+TEST(SubprocessTest, SynchronousEchoTest) {
+ vector<string> cmd;
+ cmd.push_back("/bin/sh");
+ cmd.push_back("-c");
+ cmd.push_back("echo -n stdout-here; echo -n stderr-there > /dev/stderr");
+ int rc = -1;
+ string stdout;
+ ASSERT_TRUE(Subprocess::SynchronousExec(cmd, &rc, &stdout));
+ EXPECT_EQ(0, rc);
+ EXPECT_EQ("stdout-herestderr-there", stdout);
+}
+
+TEST(SubprocessTest, SynchronousEchoNoOutputTest) {
+ vector<string> cmd;
+ cmd.push_back("/bin/sh");
+ cmd.push_back("-c");
+ cmd.push_back("echo test");
+ int rc = -1;
+ ASSERT_TRUE(Subprocess::SynchronousExec(cmd, &rc, NULL));
+ EXPECT_EQ(0, rc);
+}
+
namespace {
void CallbackBad(int return_code, const string& output, void *p) {
CHECK(false) << "should never be called.";