OLD | NEW |
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "update_engine/test_utils.h" | 5 #include "update_engine/test_utils.h" |
6 #include <sys/stat.h> | 6 #include <sys/stat.h> |
7 #include <sys/types.h> | 7 #include <sys/types.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <stdio.h> | 9 #include <stdio.h> |
10 #include <stdlib.h> | 10 #include <stdlib.h> |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 EXPECT_TRUE(feof(find_dev_cmd)); | 158 EXPECT_TRUE(feof(find_dev_cmd)); |
159 fclose(find_dev_cmd); | 159 fclose(find_dev_cmd); |
160 | 160 |
161 // strip trailing \n on dev | 161 // strip trailing \n on dev |
162 if (*ret.rbegin() == '\n') | 162 if (*ret.rbegin() == '\n') |
163 ret.resize(ret.size() - 1); | 163 ret.resize(ret.size() - 1); |
164 | 164 |
165 return ret; | 165 return ret; |
166 } | 166 } |
167 | 167 |
168 bool ExpectVectorsEq(const vector<char>& a, const vector<char>& b) { | 168 bool ExpectVectorsEq(const vector<char>& expected, const vector<char>& actual) { |
169 EXPECT_EQ(a.size(), b.size()); | 169 EXPECT_EQ(expected.size(), actual.size()); |
170 if (a.size() != b.size()) | 170 if (expected.size() != actual.size()) |
171 return false; | 171 return false; |
172 for (unsigned int i = 0; i < a.size(); i++) { | 172 for (unsigned int i = 0; i < expected.size(); i++) { |
173 EXPECT_EQ(a[i], b[i]) << "offset: " << i; | 173 EXPECT_EQ(expected[i], actual[i]) << "offset: " << i; |
174 } | 174 } |
175 return true; | 175 return true; |
176 } | 176 } |
177 | 177 |
| 178 void FillWithData(vector<char>* buffer) { |
| 179 size_t input_counter = 0; |
| 180 for (vector<char>::iterator it = buffer->begin(); it != buffer->end(); ++it) { |
| 181 *it = kRandomString[input_counter]; |
| 182 input_counter++; |
| 183 input_counter %= sizeof(kRandomString); |
| 184 } |
| 185 } |
| 186 |
178 void CreateExtImageAtPath(const string& path, vector<string>* out_paths) { | 187 void CreateExtImageAtPath(const string& path, vector<string>* out_paths) { |
179 // create 10MiB sparse file | 188 // create 10MiB sparse file |
180 EXPECT_EQ(0, System(StringPrintf("dd if=/dev/zero of=%s" | 189 EXPECT_EQ(0, System(StringPrintf("dd if=/dev/zero of=%s" |
181 " seek=10485759 bs=1 count=1", | 190 " seek=10485759 bs=1 count=1", |
182 path.c_str()))); | 191 path.c_str()))); |
183 EXPECT_EQ(0, System(StringPrintf("mkfs.ext3 -F %s", path.c_str()))); | 192 EXPECT_EQ(0, System(StringPrintf("mkfs.ext3 -F %s", path.c_str()))); |
184 EXPECT_EQ(0, System(StringPrintf("mkdir -p %s", kMountPath))); | 193 EXPECT_EQ(0, System(StringPrintf("mkdir -p %s", kMountPath))); |
185 EXPECT_EQ(0, System(StringPrintf("mount -o loop %s %s", path.c_str(), | 194 EXPECT_EQ(0, System(StringPrintf("mount -o loop %s %s", path.c_str(), |
186 kMountPath))); | 195 kMountPath))); |
187 EXPECT_EQ(0, System(StringPrintf("echo hi > %s/hi", kMountPath))); | 196 EXPECT_EQ(0, System(StringPrintf("echo hi > %s/hi", kMountPath))); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 EXPECT_TRUE(expected_paths.empty()); | 263 EXPECT_TRUE(expected_paths.empty()); |
255 if (!expected_paths.empty()) { | 264 if (!expected_paths.empty()) { |
256 for (set<string>::const_iterator it = expected_paths.begin(); | 265 for (set<string>::const_iterator it = expected_paths.begin(); |
257 it != expected_paths.end(); ++it) { | 266 it != expected_paths.end(); ++it) { |
258 LOG(INFO) << "extra path: " << *it; | 267 LOG(INFO) << "extra path: " << *it; |
259 } | 268 } |
260 } | 269 } |
261 } | 270 } |
262 | 271 |
263 } // namespace chromeos_update_engine | 272 } // namespace chromeos_update_engine |
OLD | NEW |