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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 EXPECT_EQ(1, sigs_message.signatures_size()); | 251 EXPECT_EQ(1, sigs_message.signatures_size()); |
252 const Signatures_Signature& signature = sigs_message.signatures(0); | 252 const Signatures_Signature& signature = sigs_message.signatures(0); |
253 EXPECT_EQ(1, signature.version()); | 253 EXPECT_EQ(1, signature.version()); |
254 | 254 |
255 uint64_t expected_sig_data_length = 0; | 255 uint64_t expected_sig_data_length = 0; |
256 EXPECT_TRUE(PayloadSigner::SignatureBlobLength(kUnittestPrivateKeyPath, | 256 EXPECT_TRUE(PayloadSigner::SignatureBlobLength(kUnittestPrivateKeyPath, |
257 &expected_sig_data_length)); | 257 &expected_sig_data_length)); |
258 EXPECT_EQ(expected_sig_data_length, manifest.signatures_size()); | 258 EXPECT_EQ(expected_sig_data_length, manifest.signatures_size()); |
259 EXPECT_FALSE(signature.data().empty()); | 259 EXPECT_FALSE(signature.data().empty()); |
260 | 260 |
261 EXPECT_EQ(old_kernel_data.size(), manifest.old_kernel_info().size()); | 261 // TODO(petkov): Add a test once the generator start sending old kernel |
| 262 // info. |
| 263 EXPECT_FALSE(manifest.has_old_kernel_info()); |
| 264 |
262 EXPECT_EQ(new_kernel_data.size(), manifest.new_kernel_info().size()); | 265 EXPECT_EQ(new_kernel_data.size(), manifest.new_kernel_info().size()); |
263 EXPECT_EQ(image_size, manifest.old_rootfs_info().size()); | 266 EXPECT_EQ(image_size, manifest.old_rootfs_info().size()); |
264 EXPECT_EQ(image_size, manifest.new_rootfs_info().size()); | 267 EXPECT_EQ(image_size, manifest.new_rootfs_info().size()); |
265 | 268 |
266 EXPECT_FALSE(manifest.old_kernel_info().hash().empty()); | |
267 EXPECT_FALSE(manifest.new_kernel_info().hash().empty()); | 269 EXPECT_FALSE(manifest.new_kernel_info().hash().empty()); |
268 EXPECT_FALSE(manifest.old_rootfs_info().hash().empty()); | 270 EXPECT_FALSE(manifest.old_rootfs_info().hash().empty()); |
269 EXPECT_FALSE(manifest.new_rootfs_info().hash().empty()); | 271 EXPECT_FALSE(manifest.new_rootfs_info().hash().empty()); |
270 } | 272 } |
271 | 273 |
272 PrefsMock prefs; | 274 PrefsMock prefs; |
273 EXPECT_CALL(prefs, SetInt64(kPrefsManifestMetadataSize, | 275 EXPECT_CALL(prefs, SetInt64(kPrefsManifestMetadataSize, |
274 manifest_metadata_size)).WillOnce(Return(true)); | 276 manifest_metadata_size)).WillOnce(Return(true)); |
275 EXPECT_CALL(prefs, SetInt64(kPrefsUpdateStateNextOperation, _)) | 277 EXPECT_CALL(prefs, SetInt64(kPrefsUpdateStateNextOperation, _)) |
276 .WillRepeatedly(Return(true)); | 278 .WillRepeatedly(Return(true)); |
277 EXPECT_CALL(prefs, GetInt64(kPrefsUpdateStateNextOperation, _)) | 279 EXPECT_CALL(prefs, GetInt64(kPrefsUpdateStateNextOperation, _)) |
278 .WillOnce(Return(false)); | 280 .WillOnce(Return(false)); |
279 EXPECT_CALL(prefs, SetInt64(kPrefsUpdateStateNextDataOffset, _)) | 281 EXPECT_CALL(prefs, SetInt64(kPrefsUpdateStateNextDataOffset, _)) |
280 .WillRepeatedly(Return(true)); | 282 .WillRepeatedly(Return(true)); |
281 EXPECT_CALL(prefs, SetString(kPrefsUpdateStateSHA256Context, _)) | 283 EXPECT_CALL(prefs, SetString(kPrefsUpdateStateSHA256Context, _)) |
282 .WillRepeatedly(Return(true)); | 284 .WillRepeatedly(Return(true)); |
283 EXPECT_CALL(prefs, SetString(kPrefsUpdateStateSignedSHA256Context, _)) | 285 EXPECT_CALL(prefs, SetString(kPrefsUpdateStateSignedSHA256Context, _)) |
284 .WillOnce(Return(true)); | 286 .WillOnce(Return(true)); |
285 | 287 |
286 // Update the A image in place. | 288 // Update the A image in place. |
287 DeltaPerformer performer(&prefs); | 289 DeltaPerformer performer(&prefs); |
288 | 290 |
289 EXPECT_EQ(0, performer.Open(a_img.c_str(), 0, 0)); | 291 EXPECT_EQ(0, performer.Open(a_img.c_str(), 0, 0)); |
290 EXPECT_TRUE(performer.OpenKernel(old_kernel.c_str())); | 292 EXPECT_TRUE(performer.OpenKernel(old_kernel.c_str())); |
291 | 293 |
| 294 vector<char> rootfs_hash; |
| 295 CHECK_EQ(image_size, |
| 296 OmahaHashCalculator::RawHashOfFile(a_img, image_size, &rootfs_hash)); |
| 297 performer.set_current_rootfs_hash(&rootfs_hash); |
| 298 |
292 // Write at some number of bytes per operation. Arbitrarily chose 5. | 299 // Write at some number of bytes per operation. Arbitrarily chose 5. |
293 const size_t kBytesPerWrite = 5; | 300 const size_t kBytesPerWrite = 5; |
294 for (size_t i = 0; i < delta.size(); i += kBytesPerWrite) { | 301 for (size_t i = 0; i < delta.size(); i += kBytesPerWrite) { |
295 size_t count = min(delta.size() - i, kBytesPerWrite); | 302 size_t count = min(delta.size() - i, kBytesPerWrite); |
296 EXPECT_EQ(count, performer.Write(&delta[i], count)); | 303 EXPECT_EQ(count, performer.Write(&delta[i], count)); |
297 } | 304 } |
298 | 305 |
299 // Wrapper around close. Returns 0 on success or -errno on error. | 306 // Wrapper around close. Returns 0 on success or -errno on error. |
300 EXPECT_EQ(0, performer.Close()); | 307 EXPECT_EQ(0, performer.Close()); |
301 | 308 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 op.clear_src_extents(); | 396 op.clear_src_extents(); |
390 *(op.add_src_extents()) = ExtentForRange(5, 3); | 397 *(op.add_src_extents()) = ExtentForRange(5, 3); |
391 EXPECT_TRUE(DeltaPerformer::IsIdempotentOperation(op)); | 398 EXPECT_TRUE(DeltaPerformer::IsIdempotentOperation(op)); |
392 *(op.add_dst_extents()) = ExtentForRange(20, 6); | 399 *(op.add_dst_extents()) = ExtentForRange(20, 6); |
393 EXPECT_TRUE(DeltaPerformer::IsIdempotentOperation(op)); | 400 EXPECT_TRUE(DeltaPerformer::IsIdempotentOperation(op)); |
394 *(op.add_src_extents()) = ExtentForRange(19, 2); | 401 *(op.add_src_extents()) = ExtentForRange(19, 2); |
395 EXPECT_FALSE(DeltaPerformer::IsIdempotentOperation(op)); | 402 EXPECT_FALSE(DeltaPerformer::IsIdempotentOperation(op)); |
396 } | 403 } |
397 | 404 |
398 } // namespace chromeos_update_engine | 405 } // namespace chromeos_update_engine |
OLD | NEW |