| 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 <sys/mount.h> | 5 #include <sys/mount.h> |
| 6 #include <inttypes.h> | 6 #include <inttypes.h> |
| 7 | 7 |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 | 59 |
| 60 string expected_output = "4096:4096,16384:8192,-1:4096,0:4083"; | 60 string expected_output = "4096:4096,16384:8192,-1:4096,0:4083"; |
| 61 string actual_output; | 61 string actual_output; |
| 62 EXPECT_TRUE(DeltaPerformer::ExtentsToBsdiffPositionsString(extents, | 62 EXPECT_TRUE(DeltaPerformer::ExtentsToBsdiffPositionsString(extents, |
| 63 block_size, | 63 block_size, |
| 64 file_length, | 64 file_length, |
| 65 &actual_output)); | 65 &actual_output)); |
| 66 EXPECT_EQ(expected_output, actual_output); | 66 EXPECT_EQ(expected_output, actual_output); |
| 67 } | 67 } |
| 68 | 68 |
| 69 class ScopedLoopMounter { | |
| 70 public: | |
| 71 explicit ScopedLoopMounter(const string& file_path, string* mnt_path, | |
| 72 unsigned long flags) { | |
| 73 EXPECT_TRUE(utils::MakeTempDirectory("/tmp/mnt.XXXXXX", mnt_path)); | |
| 74 dir_remover_.reset(new ScopedDirRemover(*mnt_path)); | |
| 75 | |
| 76 string loop_dev = GetUnusedLoopDevice(); | |
| 77 EXPECT_EQ(0, system(StringPrintf("losetup %s %s", loop_dev.c_str(), | |
| 78 file_path.c_str()).c_str())); | |
| 79 loop_releaser_.reset(new ScopedLoopbackDeviceReleaser(loop_dev)); | |
| 80 | |
| 81 EXPECT_TRUE(utils::MountFilesystem(loop_dev, *mnt_path, flags)); | |
| 82 unmounter_.reset(new ScopedFilesystemUnmounter(*mnt_path)); | |
| 83 } | |
| 84 private: | |
| 85 scoped_ptr<ScopedDirRemover> dir_remover_; | |
| 86 scoped_ptr<ScopedLoopbackDeviceReleaser> loop_releaser_; | |
| 87 scoped_ptr<ScopedFilesystemUnmounter> unmounter_; | |
| 88 }; | |
| 89 | |
| 90 void CompareFilesByBlock(const string& a_file, const string& b_file) { | 69 void CompareFilesByBlock(const string& a_file, const string& b_file) { |
| 91 vector<char> a_data, b_data; | 70 vector<char> a_data, b_data; |
| 92 EXPECT_TRUE(utils::ReadFile(a_file, &a_data)) << "file failed: " << a_file; | 71 EXPECT_TRUE(utils::ReadFile(a_file, &a_data)) << "file failed: " << a_file; |
| 93 EXPECT_TRUE(utils::ReadFile(b_file, &b_data)) << "file failed: " << b_file; | 72 EXPECT_TRUE(utils::ReadFile(b_file, &b_data)) << "file failed: " << b_file; |
| 94 | 73 |
| 95 EXPECT_EQ(a_data.size(), b_data.size()); | 74 EXPECT_EQ(a_data.size(), b_data.size()); |
| 96 EXPECT_EQ(0, a_data.size() % kBlockSize); | 75 EXPECT_EQ(0, a_data.size() % kBlockSize); |
| 97 for (size_t i = 0; i < a_data.size(); i += kBlockSize) { | 76 for (size_t i = 0; i < a_data.size(); i += kBlockSize) { |
| 98 EXPECT_EQ(0, i % kBlockSize); | 77 EXPECT_EQ(0, i % kBlockSize); |
| 99 vector<char> a_sub(&a_data[i], &a_data[i + kBlockSize]); | 78 vector<char> a_sub(&a_data[i], &a_data[i + kBlockSize]); |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 op.clear_src_extents(); | 387 op.clear_src_extents(); |
| 409 *(op.add_src_extents()) = ExtentForRange(5, 3); | 388 *(op.add_src_extents()) = ExtentForRange(5, 3); |
| 410 EXPECT_TRUE(DeltaPerformer::IsIdempotentOperation(op)); | 389 EXPECT_TRUE(DeltaPerformer::IsIdempotentOperation(op)); |
| 411 *(op.add_dst_extents()) = ExtentForRange(20, 6); | 390 *(op.add_dst_extents()) = ExtentForRange(20, 6); |
| 412 EXPECT_TRUE(DeltaPerformer::IsIdempotentOperation(op)); | 391 EXPECT_TRUE(DeltaPerformer::IsIdempotentOperation(op)); |
| 413 *(op.add_src_extents()) = ExtentForRange(19, 2); | 392 *(op.add_src_extents()) = ExtentForRange(19, 2); |
| 414 EXPECT_FALSE(DeltaPerformer::IsIdempotentOperation(op)); | 393 EXPECT_FALSE(DeltaPerformer::IsIdempotentOperation(op)); |
| 415 } | 394 } |
| 416 | 395 |
| 417 } // namespace chromeos_update_engine | 396 } // namespace chromeos_update_engine |
| OLD | NEW |