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 | 6 |
7 #include <sys/stat.h> | 7 #include <sys/stat.h> |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 #include <errno.h> | 9 #include <errno.h> |
10 #include <stdio.h> | 10 #include <stdio.h> |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 | 171 |
172 void FillWithData(vector<char>* buffer) { | 172 void FillWithData(vector<char>* buffer) { |
173 size_t input_counter = 0; | 173 size_t input_counter = 0; |
174 for (vector<char>::iterator it = buffer->begin(); it != buffer->end(); ++it) { | 174 for (vector<char>::iterator it = buffer->begin(); it != buffer->end(); ++it) { |
175 *it = kRandomString[input_counter]; | 175 *it = kRandomString[input_counter]; |
176 input_counter++; | 176 input_counter++; |
177 input_counter %= sizeof(kRandomString); | 177 input_counter %= sizeof(kRandomString); |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
| 181 void CreateEmptyExtImageAtPath(const string& path, |
| 182 size_t size, |
| 183 int block_size) { |
| 184 EXPECT_EQ(0, System(StringPrintf("dd if=/dev/zero of=%s" |
| 185 " seek=%zu bs=1 count=1", |
| 186 path.c_str(), size))); |
| 187 EXPECT_EQ(0, System(StringPrintf("mkfs.ext3 -b %d -F %s", |
| 188 block_size, path.c_str()))); |
| 189 } |
| 190 |
181 void CreateExtImageAtPath(const string& path, vector<string>* out_paths) { | 191 void CreateExtImageAtPath(const string& path, vector<string>* out_paths) { |
182 // create 10MiB sparse file | 192 // create 10MiB sparse file |
183 EXPECT_EQ(0, System(StringPrintf("dd if=/dev/zero of=%s" | 193 EXPECT_EQ(0, System(StringPrintf("dd if=/dev/zero of=%s" |
184 " seek=10485759 bs=1 count=1", | 194 " seek=10485759 bs=1 count=1", |
185 path.c_str()))); | 195 path.c_str()))); |
186 EXPECT_EQ(0, System(StringPrintf("mkfs.ext3 -b 4096 -F %s", path.c_str()))); | 196 EXPECT_EQ(0, System(StringPrintf("mkfs.ext3 -b 4096 -F %s", path.c_str()))); |
187 EXPECT_EQ(0, System(StringPrintf("mkdir -p %s", kMountPath))); | 197 EXPECT_EQ(0, System(StringPrintf("mkdir -p %s", kMountPath))); |
188 EXPECT_EQ(0, System(StringPrintf("mount -o loop %s %s", path.c_str(), | 198 EXPECT_EQ(0, System(StringPrintf("mount -o loop %s %s", path.c_str(), |
189 kMountPath))); | 199 kMountPath))); |
190 EXPECT_EQ(0, System(StringPrintf("echo hi > %s/hi", kMountPath))); | 200 EXPECT_EQ(0, System(StringPrintf("echo hi > %s/hi", kMountPath))); |
191 EXPECT_EQ(0, System(StringPrintf("echo hello > %s/hello", kMountPath))); | 201 EXPECT_EQ(0, System(StringPrintf("echo hello > %s/hello", kMountPath))); |
192 EXPECT_EQ(0, System(StringPrintf("mkdir %s/some_dir", kMountPath))); | 202 EXPECT_EQ(0, System(StringPrintf("mkdir %s/some_dir", kMountPath))); |
193 EXPECT_EQ(0, System(StringPrintf("mkdir %s/some_dir/empty_dir", kMountPath))); | 203 EXPECT_EQ(0, System(StringPrintf("mkdir %s/some_dir/empty_dir", kMountPath))); |
194 EXPECT_EQ(0, System(StringPrintf("mkdir %s/some_dir/mnt", kMountPath))); | 204 EXPECT_EQ(0, System(StringPrintf("mkdir %s/some_dir/mnt", kMountPath))); |
195 EXPECT_EQ(0, System(StringPrintf("echo T > %s/some_dir/test", kMountPath))); | 205 EXPECT_EQ(0, System(StringPrintf("echo T > %s/some_dir/test", kMountPath))); |
196 EXPECT_EQ(0, System(StringPrintf("mkfifo %s/some_dir/fifo", kMountPath))); | 206 EXPECT_EQ(0, System(StringPrintf("mkfifo %s/some_dir/fifo", kMountPath))); |
197 EXPECT_EQ(0, System(StringPrintf("mknod %s/cdev c 2 3", kMountPath))); | 207 EXPECT_EQ(0, System(StringPrintf("mknod %s/cdev c 2 3", kMountPath))); |
198 EXPECT_EQ(0, System(StringPrintf("ln -s /some/target %s/sym", kMountPath))); | 208 EXPECT_EQ(0, System(StringPrintf("ln -s /some/target %s/sym", kMountPath))); |
199 EXPECT_EQ(0, System(StringPrintf("ln %s/some_dir/test %s/testlink", | 209 EXPECT_EQ(0, System(StringPrintf("ln %s/some_dir/test %s/testlink", |
200 kMountPath, kMountPath))); | 210 kMountPath, kMountPath))); |
201 EXPECT_EQ(0, System(StringPrintf("umount -d %s", kMountPath))); | 211 EXPECT_EQ(0, System(StringPrintf("umount -d %s", kMountPath))); |
202 | 212 |
203 if (out_paths) { | 213 if (out_paths) { |
204 out_paths->clear(); | 214 out_paths->clear(); |
205 out_paths->push_back(""); | 215 out_paths->push_back(""); |
206 out_paths->push_back("/hi"); | 216 out_paths->push_back("/hi"); |
207 out_paths->push_back("/hello"); | 217 out_paths->push_back("/hello"); |
208 out_paths->push_back("/some_dir"); | 218 out_paths->push_back("/some_dir"); |
209 out_paths->push_back("/some_dir/empty_dir"); | 219 out_paths->push_back("/some_dir/empty_dir"); |
210 out_paths->push_back("/some_dir/mnt"); | 220 out_paths->push_back("/some_dir/mnt"); |
211 out_paths->push_back("/some_dir/test"); | 221 out_paths->push_back("/some_dir/test"); |
212 out_paths->push_back("/some_dir/fifo"); | 222 out_paths->push_back("/some_dir/fifo"); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 EXPECT_FALSE(iter.IsErr()); | 266 EXPECT_FALSE(iter.IsErr()); |
257 EXPECT_TRUE(expected_paths.empty()); | 267 EXPECT_TRUE(expected_paths.empty()); |
258 if (!expected_paths.empty()) { | 268 if (!expected_paths.empty()) { |
259 for (set<string>::const_iterator it = expected_paths.begin(); | 269 for (set<string>::const_iterator it = expected_paths.begin(); |
260 it != expected_paths.end(); ++it) { | 270 it != expected_paths.end(); ++it) { |
261 LOG(INFO) << "extra path: " << *it; | 271 LOG(INFO) << "extra path: " << *it; |
262 } | 272 } |
263 } | 273 } |
264 } | 274 } |
265 | 275 |
| 276 ScopedLoopMounter::ScopedLoopMounter(const std::string& file_path, |
| 277 std::string* mnt_path, |
| 278 unsigned long flags) { |
| 279 EXPECT_TRUE(utils::MakeTempDirectory("/tmp/mnt.XXXXXX", mnt_path)); |
| 280 dir_remover_.reset(new ScopedDirRemover(*mnt_path)); |
| 281 |
| 282 std::string loop_dev = GetUnusedLoopDevice(); |
| 283 EXPECT_EQ(0, system(StringPrintf("losetup %s %s", loop_dev.c_str(), |
| 284 file_path.c_str()).c_str())); |
| 285 loop_releaser_.reset(new ScopedLoopbackDeviceReleaser(loop_dev)); |
| 286 |
| 287 EXPECT_TRUE(utils::MountFilesystem(loop_dev, *mnt_path, flags)); |
| 288 unmounter_.reset(new ScopedFilesystemUnmounter(*mnt_path)); |
| 289 } |
| 290 |
266 } // namespace chromeos_update_engine | 291 } // namespace chromeos_update_engine |
OLD | NEW |