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 16 matching lines...) Expand all Loading... |
27 | 27 |
28 using std::min; | 28 using std::min; |
29 using std::string; | 29 using std::string; |
30 using std::vector; | 30 using std::vector; |
31 using testing::_; | 31 using testing::_; |
32 using testing::Return; | 32 using testing::Return; |
33 | 33 |
34 extern const char* kUnittestPrivateKeyPath; | 34 extern const char* kUnittestPrivateKeyPath; |
35 extern const char* kUnittestPublicKeyPath; | 35 extern const char* kUnittestPublicKeyPath; |
36 | 36 |
| 37 namespace { |
| 38 const size_t kBlockSize = 4096; |
| 39 } // namespace {} |
| 40 |
| 41 |
37 class DeltaPerformerTest : public ::testing::Test { }; | 42 class DeltaPerformerTest : public ::testing::Test { }; |
38 | 43 |
39 TEST(DeltaPerformerTest, ExtentsToByteStringTest) { | 44 TEST(DeltaPerformerTest, ExtentsToByteStringTest) { |
40 uint64_t test[] = {1, 1, 4, 2, kSparseHole, 1, 0, 1}; | 45 uint64_t test[] = {1, 1, 4, 2, kSparseHole, 1, 0, 1}; |
41 COMPILE_ASSERT(arraysize(test) % 2 == 0, array_size_uneven); | 46 COMPILE_ASSERT(arraysize(test) % 2 == 0, array_size_uneven); |
42 const uint64_t block_size = 4096; | 47 const uint64_t block_size = 4096; |
43 const uint64_t file_length = 5 * block_size - 13; | 48 const uint64_t file_length = 5 * block_size - 13; |
44 | 49 |
45 google::protobuf::RepeatedPtrField<Extent> extents; | 50 google::protobuf::RepeatedPtrField<Extent> extents; |
46 for (size_t i = 0; i < arraysize(test); i += 2) { | 51 for (size_t i = 0; i < arraysize(test); i += 2) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 scoped_ptr<ScopedLoopbackDeviceReleaser> loop_releaser_; | 83 scoped_ptr<ScopedLoopbackDeviceReleaser> loop_releaser_; |
79 scoped_ptr<ScopedFilesystemUnmounter> unmounter_; | 84 scoped_ptr<ScopedFilesystemUnmounter> unmounter_; |
80 }; | 85 }; |
81 | 86 |
82 void CompareFilesByBlock(const string& a_file, const string& b_file) { | 87 void CompareFilesByBlock(const string& a_file, const string& b_file) { |
83 vector<char> a_data, b_data; | 88 vector<char> a_data, b_data; |
84 EXPECT_TRUE(utils::ReadFile(a_file, &a_data)) << "file failed: " << a_file; | 89 EXPECT_TRUE(utils::ReadFile(a_file, &a_data)) << "file failed: " << a_file; |
85 EXPECT_TRUE(utils::ReadFile(b_file, &b_data)) << "file failed: " << b_file; | 90 EXPECT_TRUE(utils::ReadFile(b_file, &b_data)) << "file failed: " << b_file; |
86 | 91 |
87 EXPECT_EQ(a_data.size(), b_data.size()); | 92 EXPECT_EQ(a_data.size(), b_data.size()); |
88 size_t kBlockSize = 4096; | |
89 EXPECT_EQ(0, a_data.size() % kBlockSize); | 93 EXPECT_EQ(0, a_data.size() % kBlockSize); |
90 for (size_t i = 0; i < a_data.size(); i += kBlockSize) { | 94 for (size_t i = 0; i < a_data.size(); i += kBlockSize) { |
91 EXPECT_EQ(0, i % kBlockSize); | 95 EXPECT_EQ(0, i % kBlockSize); |
92 vector<char> a_sub(&a_data[i], &a_data[i + kBlockSize]); | 96 vector<char> a_sub(&a_data[i], &a_data[i + kBlockSize]); |
93 vector<char> b_sub(&b_data[i], &b_data[i + kBlockSize]); | 97 vector<char> b_sub(&b_data[i], &b_data[i + kBlockSize]); |
94 EXPECT_TRUE(a_sub == b_sub) << "Block " << (i/kBlockSize) << " differs"; | 98 EXPECT_TRUE(a_sub == b_sub) << "Block " << (i/kBlockSize) << " differs"; |
95 } | 99 } |
96 } | 100 } |
97 | 101 |
98 namespace { | 102 namespace { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 274 |
271 vector<char> updated_kernel_partition; | 275 vector<char> updated_kernel_partition; |
272 EXPECT_TRUE(utils::ReadFile(old_kernel, &updated_kernel_partition)); | 276 EXPECT_TRUE(utils::ReadFile(old_kernel, &updated_kernel_partition)); |
273 EXPECT_EQ(0, strncmp(&updated_kernel_partition[0], new_data_string, | 277 EXPECT_EQ(0, strncmp(&updated_kernel_partition[0], new_data_string, |
274 strlen(new_data_string))); | 278 strlen(new_data_string))); |
275 | 279 |
276 EXPECT_TRUE(utils::FileExists(kUnittestPublicKeyPath)); | 280 EXPECT_TRUE(utils::FileExists(kUnittestPublicKeyPath)); |
277 EXPECT_TRUE(performer.VerifyPayload(kUnittestPublicKeyPath)); | 281 EXPECT_TRUE(performer.VerifyPayload(kUnittestPublicKeyPath)); |
278 } | 282 } |
279 | 283 |
| 284 TEST(DeltaPerformerTest, NewFullUpdateTest) { |
| 285 vector<char> new_root(20 * 1024 * 1024); |
| 286 vector<char> new_kern(16 * 1024 * 1024); |
| 287 const off_t kChunkSize = 128 * 1024; |
| 288 FillWithData(&new_root); |
| 289 FillWithData(&new_kern); |
| 290 |
| 291 string new_root_path; |
| 292 EXPECT_TRUE(utils::MakeTempFile("/tmp/NewFullUpdateTest_R.XXXXXX", |
| 293 &new_root_path, |
| 294 NULL)); |
| 295 ScopedPathUnlinker new_root_path_unlinker(new_root_path); |
| 296 EXPECT_TRUE(WriteFileVector(new_root_path, new_root)); |
| 297 |
| 298 string new_kern_path; |
| 299 EXPECT_TRUE(utils::MakeTempFile("/tmp/NewFullUpdateTest_K.XXXXXX", |
| 300 &new_kern_path, |
| 301 NULL)); |
| 302 ScopedPathUnlinker new_kern_path_unlinker(new_kern_path); |
| 303 EXPECT_TRUE(WriteFileVector(new_kern_path, new_kern)); |
| 304 |
| 305 string out_blobs_path; |
| 306 int out_blobs_fd; |
| 307 EXPECT_TRUE(utils::MakeTempFile("/tmp/NewFullUpdateTest_D.XXXXXX", |
| 308 &out_blobs_path, |
| 309 &out_blobs_fd)); |
| 310 ScopedPathUnlinker out_blobs_path_unlinker(out_blobs_path); |
| 311 ScopedFdCloser out_blobs_fd_closer(&out_blobs_fd); |
| 312 |
| 313 off_t out_blobs_length = 0; |
| 314 |
| 315 Graph graph; |
| 316 vector<DeltaArchiveManifest_InstallOperation> kernel_ops; |
| 317 vector<Vertex::Index> final_order; |
| 318 |
| 319 EXPECT_TRUE(DeltaDiffGenerator::ReadFullUpdateFromDisk(&graph, |
| 320 new_kern_path, |
| 321 new_root_path, |
| 322 out_blobs_fd, |
| 323 &out_blobs_length, |
| 324 kChunkSize, |
| 325 &kernel_ops, |
| 326 &final_order)); |
| 327 EXPECT_EQ(new_root.size() / kChunkSize, graph.size()); |
| 328 EXPECT_EQ(new_root.size() / kChunkSize, final_order.size()); |
| 329 EXPECT_EQ(new_kern.size() / kChunkSize, kernel_ops.size()); |
| 330 for (size_t i = 0; i < (new_root.size() / kChunkSize); ++i) { |
| 331 EXPECT_EQ(i, final_order[i]); |
| 332 EXPECT_EQ(1, graph[i].op.dst_extents_size()); |
| 333 EXPECT_EQ(i * kChunkSize / kBlockSize, |
| 334 graph[i].op.dst_extents(0).start_block()) << "i = " << i; |
| 335 EXPECT_EQ(kChunkSize / kBlockSize, |
| 336 graph[i].op.dst_extents(0).num_blocks()); |
| 337 if (graph[i].op.type() != |
| 338 DeltaArchiveManifest_InstallOperation_Type_REPLACE) { |
| 339 EXPECT_EQ(DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ, |
| 340 graph[i].op.type()); |
| 341 } |
| 342 } |
| 343 } |
| 344 |
280 } // namespace chromeos_update_engine | 345 } // namespace chromeos_update_engine |
OLD | NEW |