| 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 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 TEST(DeltaPerformerTest, RunAsRootSmallImageTest) { | 116 TEST(DeltaPerformerTest, RunAsRootSmallImageTest) { |
| 117 string a_img, b_img; | 117 string a_img, b_img; |
| 118 EXPECT_TRUE(utils::MakeTempFile("/tmp/a_img.XXXXXX", &a_img, NULL)); | 118 EXPECT_TRUE(utils::MakeTempFile("/tmp/a_img.XXXXXX", &a_img, NULL)); |
| 119 ScopedPathUnlinker a_img_unlinker(a_img); | 119 ScopedPathUnlinker a_img_unlinker(a_img); |
| 120 EXPECT_TRUE(utils::MakeTempFile("/tmp/b_img.XXXXXX", &b_img, NULL)); | 120 EXPECT_TRUE(utils::MakeTempFile("/tmp/b_img.XXXXXX", &b_img, NULL)); |
| 121 ScopedPathUnlinker b_img_unlinker(b_img); | 121 ScopedPathUnlinker b_img_unlinker(b_img); |
| 122 | 122 |
| 123 CreateExtImageAtPath(a_img, NULL); | 123 CreateExtImageAtPath(a_img, NULL); |
| 124 CreateExtImageAtPath(b_img, NULL); | 124 CreateExtImageAtPath(b_img, NULL); |
| 125 | 125 |
| 126 int image_size = static_cast<int>(utils::FileSize(a_img)); |
| 127 |
| 128 // Extend the "partitions" holding the file system a bit. |
| 129 EXPECT_EQ(0, System(base::StringPrintf( |
| 130 "dd if=/dev/zero of=%s seek=%d bs=1 count=1", |
| 131 a_img.c_str(), |
| 132 image_size + 1024 * 1024 - 1))); |
| 133 EXPECT_EQ(0, System(base::StringPrintf( |
| 134 "dd if=/dev/zero of=%s seek=%d bs=1 count=1", |
| 135 b_img.c_str(), |
| 136 image_size + 1024 * 1024 - 1))); |
| 137 EXPECT_EQ(image_size + 1024 * 1024, utils::FileSize(a_img)); |
| 138 EXPECT_EQ(image_size + 1024 * 1024, utils::FileSize(b_img)); |
| 139 |
| 126 // Make some changes to the A image. | 140 // Make some changes to the A image. |
| 127 { | 141 { |
| 128 string a_mnt; | 142 string a_mnt; |
| 129 ScopedLoopMounter b_mounter(a_img, &a_mnt, 0); | 143 ScopedLoopMounter b_mounter(a_img, &a_mnt, 0); |
| 130 | 144 |
| 131 EXPECT_TRUE(utils::WriteFile(StringPrintf("%s/hardtocompress", | 145 EXPECT_TRUE(utils::WriteFile(StringPrintf("%s/hardtocompress", |
| 132 a_mnt.c_str()).c_str(), | 146 a_mnt.c_str()).c_str(), |
| 133 reinterpret_cast<const char*>(kRandomString), | 147 reinterpret_cast<const char*>(kRandomString), |
| 134 sizeof(kRandomString) - 1)); | 148 sizeof(kRandomString) - 1)); |
| 135 // Write 1 MiB of 0xff to try to catch the case where writing a bsdiff | 149 // Write 1 MiB of 0xff to try to catch the case where writing a bsdiff |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 EXPECT_EQ(1, signature.version()); | 253 EXPECT_EQ(1, signature.version()); |
| 240 | 254 |
| 241 uint64_t expected_sig_data_length = 0; | 255 uint64_t expected_sig_data_length = 0; |
| 242 EXPECT_TRUE(PayloadSigner::SignatureBlobLength(kUnittestPrivateKeyPath, | 256 EXPECT_TRUE(PayloadSigner::SignatureBlobLength(kUnittestPrivateKeyPath, |
| 243 &expected_sig_data_length)); | 257 &expected_sig_data_length)); |
| 244 EXPECT_EQ(expected_sig_data_length, manifest.signatures_size()); | 258 EXPECT_EQ(expected_sig_data_length, manifest.signatures_size()); |
| 245 EXPECT_FALSE(signature.data().empty()); | 259 EXPECT_FALSE(signature.data().empty()); |
| 246 | 260 |
| 247 EXPECT_EQ(old_kernel_data.size(), manifest.old_kernel_info().size()); | 261 EXPECT_EQ(old_kernel_data.size(), manifest.old_kernel_info().size()); |
| 248 EXPECT_EQ(new_kernel_data.size(), manifest.new_kernel_info().size()); | 262 EXPECT_EQ(new_kernel_data.size(), manifest.new_kernel_info().size()); |
| 249 EXPECT_EQ(utils::FileSize(a_img), manifest.old_rootfs_info().size()); | 263 EXPECT_EQ(image_size, manifest.old_rootfs_info().size()); |
| 250 EXPECT_EQ(utils::FileSize(b_img), manifest.new_rootfs_info().size()); | 264 EXPECT_EQ(image_size, manifest.new_rootfs_info().size()); |
| 251 | 265 |
| 252 EXPECT_FALSE(manifest.old_kernel_info().hash().empty()); | 266 EXPECT_FALSE(manifest.old_kernel_info().hash().empty()); |
| 253 EXPECT_FALSE(manifest.new_kernel_info().hash().empty()); | 267 EXPECT_FALSE(manifest.new_kernel_info().hash().empty()); |
| 254 EXPECT_FALSE(manifest.old_rootfs_info().hash().empty()); | 268 EXPECT_FALSE(manifest.old_rootfs_info().hash().empty()); |
| 255 EXPECT_FALSE(manifest.new_rootfs_info().hash().empty()); | 269 EXPECT_FALSE(manifest.new_rootfs_info().hash().empty()); |
| 256 } | 270 } |
| 257 | 271 |
| 258 PrefsMock prefs; | 272 PrefsMock prefs; |
| 259 EXPECT_CALL(prefs, SetInt64(kPrefsManifestMetadataSize, | 273 EXPECT_CALL(prefs, SetInt64(kPrefsManifestMetadataSize, |
| 260 manifest_metadata_size)).WillOnce(Return(true)); | 274 manifest_metadata_size)).WillOnce(Return(true)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 delta.size())); | 314 delta.size())); |
| 301 EXPECT_TRUE(performer.VerifyAppliedUpdate(a_img, old_kernel)); | 315 EXPECT_TRUE(performer.VerifyAppliedUpdate(a_img, old_kernel)); |
| 302 } | 316 } |
| 303 | 317 |
| 304 TEST(DeltaPerformerTest, NewFullUpdateTest) { | 318 TEST(DeltaPerformerTest, NewFullUpdateTest) { |
| 305 vector<char> new_root(20 * 1024 * 1024); | 319 vector<char> new_root(20 * 1024 * 1024); |
| 306 vector<char> new_kern(16 * 1024 * 1024); | 320 vector<char> new_kern(16 * 1024 * 1024); |
| 307 const off_t kChunkSize = 128 * 1024; | 321 const off_t kChunkSize = 128 * 1024; |
| 308 FillWithData(&new_root); | 322 FillWithData(&new_root); |
| 309 FillWithData(&new_kern); | 323 FillWithData(&new_kern); |
| 324 // Assume hashes take 2 MiB beyond the rootfs. |
| 325 off_t new_rootfs_size = new_root.size() - 2 * 1024 * 1024; |
| 310 | 326 |
| 311 string new_root_path; | 327 string new_root_path; |
| 312 EXPECT_TRUE(utils::MakeTempFile("/tmp/NewFullUpdateTest_R.XXXXXX", | 328 EXPECT_TRUE(utils::MakeTempFile("/tmp/NewFullUpdateTest_R.XXXXXX", |
| 313 &new_root_path, | 329 &new_root_path, |
| 314 NULL)); | 330 NULL)); |
| 315 ScopedPathUnlinker new_root_path_unlinker(new_root_path); | 331 ScopedPathUnlinker new_root_path_unlinker(new_root_path); |
| 316 EXPECT_TRUE(WriteFileVector(new_root_path, new_root)); | 332 EXPECT_TRUE(WriteFileVector(new_root_path, new_root)); |
| 317 | 333 |
| 318 string new_kern_path; | 334 string new_kern_path; |
| 319 EXPECT_TRUE(utils::MakeTempFile("/tmp/NewFullUpdateTest_K.XXXXXX", | 335 EXPECT_TRUE(utils::MakeTempFile("/tmp/NewFullUpdateTest_K.XXXXXX", |
| (...skipping 12 matching lines...) Expand all Loading... |
| 332 | 348 |
| 333 off_t out_blobs_length = 0; | 349 off_t out_blobs_length = 0; |
| 334 | 350 |
| 335 Graph graph; | 351 Graph graph; |
| 336 vector<DeltaArchiveManifest_InstallOperation> kernel_ops; | 352 vector<DeltaArchiveManifest_InstallOperation> kernel_ops; |
| 337 vector<Vertex::Index> final_order; | 353 vector<Vertex::Index> final_order; |
| 338 | 354 |
| 339 EXPECT_TRUE(DeltaDiffGenerator::ReadFullUpdateFromDisk(&graph, | 355 EXPECT_TRUE(DeltaDiffGenerator::ReadFullUpdateFromDisk(&graph, |
| 340 new_kern_path, | 356 new_kern_path, |
| 341 new_root_path, | 357 new_root_path, |
| 358 new_rootfs_size, |
| 342 out_blobs_fd, | 359 out_blobs_fd, |
| 343 &out_blobs_length, | 360 &out_blobs_length, |
| 344 kChunkSize, | 361 kChunkSize, |
| 345 &kernel_ops, | 362 &kernel_ops, |
| 346 &final_order)); | 363 &final_order)); |
| 347 EXPECT_EQ(new_root.size() / kChunkSize, graph.size()); | 364 EXPECT_EQ(new_rootfs_size / kChunkSize, graph.size()); |
| 348 EXPECT_EQ(new_root.size() / kChunkSize, final_order.size()); | 365 EXPECT_EQ(new_rootfs_size / kChunkSize, final_order.size()); |
| 349 EXPECT_EQ(new_kern.size() / kChunkSize, kernel_ops.size()); | 366 EXPECT_EQ(new_kern.size() / kChunkSize, kernel_ops.size()); |
| 350 for (size_t i = 0; i < (new_root.size() / kChunkSize); ++i) { | 367 for (off_t i = 0; i < (new_rootfs_size / kChunkSize); ++i) { |
| 351 EXPECT_EQ(i, final_order[i]); | 368 EXPECT_EQ(i, final_order[i]); |
| 352 EXPECT_EQ(1, graph[i].op.dst_extents_size()); | 369 EXPECT_EQ(1, graph[i].op.dst_extents_size()); |
| 353 EXPECT_EQ(i * kChunkSize / kBlockSize, | 370 EXPECT_EQ(i * kChunkSize / kBlockSize, |
| 354 graph[i].op.dst_extents(0).start_block()) << "i = " << i; | 371 graph[i].op.dst_extents(0).start_block()) << "i = " << i; |
| 355 EXPECT_EQ(kChunkSize / kBlockSize, | 372 EXPECT_EQ(kChunkSize / kBlockSize, |
| 356 graph[i].op.dst_extents(0).num_blocks()); | 373 graph[i].op.dst_extents(0).num_blocks()); |
| 357 if (graph[i].op.type() != | 374 if (graph[i].op.type() != |
| 358 DeltaArchiveManifest_InstallOperation_Type_REPLACE) { | 375 DeltaArchiveManifest_InstallOperation_Type_REPLACE) { |
| 359 EXPECT_EQ(DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ, | 376 EXPECT_EQ(DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ, |
| 360 graph[i].op.type()); | 377 graph[i].op.type()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 372 op.clear_src_extents(); | 389 op.clear_src_extents(); |
| 373 *(op.add_src_extents()) = ExtentForRange(5, 3); | 390 *(op.add_src_extents()) = ExtentForRange(5, 3); |
| 374 EXPECT_TRUE(DeltaPerformer::IsIdempotentOperation(op)); | 391 EXPECT_TRUE(DeltaPerformer::IsIdempotentOperation(op)); |
| 375 *(op.add_dst_extents()) = ExtentForRange(20, 6); | 392 *(op.add_dst_extents()) = ExtentForRange(20, 6); |
| 376 EXPECT_TRUE(DeltaPerformer::IsIdempotentOperation(op)); | 393 EXPECT_TRUE(DeltaPerformer::IsIdempotentOperation(op)); |
| 377 *(op.add_src_extents()) = ExtentForRange(19, 2); | 394 *(op.add_src_extents()) = ExtentForRange(19, 2); |
| 378 EXPECT_FALSE(DeltaPerformer::IsIdempotentOperation(op)); | 395 EXPECT_FALSE(DeltaPerformer::IsIdempotentOperation(op)); |
| 379 } | 396 } |
| 380 | 397 |
| 381 } // namespace chromeos_update_engine | 398 } // namespace chromeos_update_engine |
| OLD | NEW |