Fixes to utility / unit test related code.
* Eliminated bugs related to reading content from pipes/files, including
general cleanup/refactoring of these code pieces and API.
* Eliminated bugs related binding/unbinding of loopback devices, which
are used in unit testing.
BUG=chromium-os:31082
TEST=Builds and runs unit tests
CQ-DEPEND=Ib7b3552e98ca40b6141688e2dea5a1407db12b2a
Change-Id: Ifaab8697602a35ce7d7fb9384fdcb1ca64b72515
Reviewed-on: https://gerrit.chromium.org/gerrit/27911
Reviewed-by: Don Garrett <dgarrett@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
Commit-Ready: Gilad Arnold <garnold@chromium.org>
diff --git a/omaha_request_params_unittest.cc b/omaha_request_params_unittest.cc
index 090c514..ecaa682 100644
--- a/omaha_request_params_unittest.cc
+++ b/omaha_request_params_unittest.cc
@@ -55,22 +55,14 @@
namespace {
string GetMachineType() {
- FILE* fp = popen("uname -m", "r");
- if (!fp)
+ string machine_type;
+ if (!utils::ReadPipe("uname -m", &machine_type))
return "";
- string ret;
- for (;;) {
- char buffer[10];
- size_t r = fread(buffer, 1, sizeof(buffer), fp);
- if (r == 0)
- break;
- ret.insert(ret.begin(), buffer, buffer + r);
- }
- // strip trailing '\n' if it exists
- if ((*ret.rbegin()) == '\n')
- ret.resize(ret.size() - 1);
- fclose(fp);
- return ret;
+ // Strip anything from the first newline char.
+ size_t newline_pos = machine_type.find('\n');
+ if (newline_pos != string::npos)
+ machine_type.erase(newline_pos);
+ return machine_type;
}
} // namespace {}