Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include <sys/mount.h> |
| 6 | #include <inttypes.h> |
| 7 | |
| 8 | #include <algorithm> |
| 9 | #include <string> |
| 10 | #include <vector> |
| 11 | |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 12 | #include <base/scoped_ptr.h> |
| 13 | #include <base/string_util.h> |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 14 | #include <google/protobuf/repeated_field.h> |
| 15 | #include <gtest/gtest.h> |
| 16 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 17 | #include "update_engine/delta_diff_generator.h" |
| 18 | #include "update_engine/delta_performer.h" |
| 19 | #include "update_engine/graph_types.h" |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 20 | #include "update_engine/payload_signer.h" |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 21 | #include "update_engine/prefs_mock.h" |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 22 | #include "update_engine/test_utils.h" |
| 23 | #include "update_engine/update_metadata.pb.h" |
| 24 | #include "update_engine/utils.h" |
| 25 | |
| 26 | namespace chromeos_update_engine { |
| 27 | |
| 28 | using std::min; |
| 29 | using std::string; |
| 30 | using std::vector; |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 31 | using testing::_; |
| 32 | using testing::Return; |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 33 | |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 34 | extern const char* kUnittestPrivateKeyPath; |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 35 | extern const char* kUnittestPublicKeyPath; |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 36 | |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 37 | namespace { |
| 38 | const size_t kBlockSize = 4096; |
| 39 | } // namespace {} |
| 40 | |
| 41 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 42 | class DeltaPerformerTest : public ::testing::Test { }; |
| 43 | |
| 44 | TEST(DeltaPerformerTest, ExtentsToByteStringTest) { |
| 45 | uint64_t test[] = {1, 1, 4, 2, kSparseHole, 1, 0, 1}; |
| 46 | COMPILE_ASSERT(arraysize(test) % 2 == 0, array_size_uneven); |
| 47 | const uint64_t block_size = 4096; |
| 48 | const uint64_t file_length = 5 * block_size - 13; |
| 49 | |
| 50 | google::protobuf::RepeatedPtrField<Extent> extents; |
| 51 | for (size_t i = 0; i < arraysize(test); i += 2) { |
| 52 | Extent* extent = extents.Add(); |
| 53 | extent->set_start_block(test[i]); |
| 54 | extent->set_num_blocks(test[i + 1]); |
| 55 | } |
| 56 | |
| 57 | string expected_output = "4096:4096,16384:8192,-1:4096,0:4083"; |
| 58 | string actual_output; |
| 59 | EXPECT_TRUE(DeltaPerformer::ExtentsToBsdiffPositionsString(extents, |
| 60 | block_size, |
| 61 | file_length, |
| 62 | &actual_output)); |
| 63 | EXPECT_EQ(expected_output, actual_output); |
| 64 | } |
| 65 | |
| 66 | class ScopedLoopMounter { |
| 67 | public: |
| 68 | explicit ScopedLoopMounter(const string& file_path, string* mnt_path, |
| 69 | unsigned long flags) { |
| 70 | EXPECT_TRUE(utils::MakeTempDirectory("/tmp/mnt.XXXXXX", mnt_path)); |
| 71 | dir_remover_.reset(new ScopedDirRemover(*mnt_path)); |
| 72 | |
| 73 | string loop_dev = GetUnusedLoopDevice(); |
| 74 | EXPECT_EQ(0, system(StringPrintf("losetup %s %s", loop_dev.c_str(), |
| 75 | file_path.c_str()).c_str())); |
| 76 | loop_releaser_.reset(new ScopedLoopbackDeviceReleaser(loop_dev)); |
| 77 | |
| 78 | EXPECT_TRUE(utils::MountFilesystem(loop_dev, *mnt_path, flags)); |
| 79 | unmounter_.reset(new ScopedFilesystemUnmounter(*mnt_path)); |
| 80 | } |
| 81 | private: |
| 82 | scoped_ptr<ScopedDirRemover> dir_remover_; |
| 83 | scoped_ptr<ScopedLoopbackDeviceReleaser> loop_releaser_; |
| 84 | scoped_ptr<ScopedFilesystemUnmounter> unmounter_; |
| 85 | }; |
| 86 | |
| 87 | void CompareFilesByBlock(const string& a_file, const string& b_file) { |
| 88 | vector<char> a_data, b_data; |
Andrew de los Reyes | 3270f74 | 2010-07-15 22:28:14 -0700 | [diff] [blame] | 89 | EXPECT_TRUE(utils::ReadFile(a_file, &a_data)) << "file failed: " << a_file; |
| 90 | EXPECT_TRUE(utils::ReadFile(b_file, &b_data)) << "file failed: " << b_file; |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 91 | |
| 92 | EXPECT_EQ(a_data.size(), b_data.size()); |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 93 | EXPECT_EQ(0, a_data.size() % kBlockSize); |
| 94 | for (size_t i = 0; i < a_data.size(); i += kBlockSize) { |
| 95 | EXPECT_EQ(0, i % kBlockSize); |
| 96 | vector<char> a_sub(&a_data[i], &a_data[i + kBlockSize]); |
| 97 | vector<char> b_sub(&b_data[i], &b_data[i + kBlockSize]); |
| 98 | EXPECT_TRUE(a_sub == b_sub) << "Block " << (i/kBlockSize) << " differs"; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | namespace { |
| 103 | bool WriteSparseFile(const string& path, off_t size) { |
| 104 | int fd = open(path.c_str(), O_CREAT | O_TRUNC | O_WRONLY, 0644); |
| 105 | TEST_AND_RETURN_FALSE_ERRNO(fd >= 0); |
| 106 | ScopedFdCloser fd_closer(&fd); |
| 107 | off_t rc = lseek(fd, size + 1, SEEK_SET); |
| 108 | TEST_AND_RETURN_FALSE_ERRNO(rc != static_cast<off_t>(-1)); |
| 109 | int return_code = ftruncate(fd, size); |
| 110 | TEST_AND_RETURN_FALSE_ERRNO(return_code == 0); |
| 111 | return true; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | TEST(DeltaPerformerTest, RunAsRootSmallImageTest) { |
| 116 | string a_img, b_img; |
| 117 | EXPECT_TRUE(utils::MakeTempFile("/tmp/a_img.XXXXXX", &a_img, NULL)); |
| 118 | ScopedPathUnlinker a_img_unlinker(a_img); |
| 119 | EXPECT_TRUE(utils::MakeTempFile("/tmp/b_img.XXXXXX", &b_img, NULL)); |
| 120 | ScopedPathUnlinker b_img_unlinker(b_img); |
| 121 | |
| 122 | CreateExtImageAtPath(a_img, NULL); |
| 123 | CreateExtImageAtPath(b_img, NULL); |
| 124 | |
| 125 | // Make some changes to the A image. |
| 126 | { |
| 127 | string a_mnt; |
| 128 | ScopedLoopMounter b_mounter(a_img, &a_mnt, 0); |
| 129 | |
| 130 | EXPECT_TRUE(utils::WriteFile(StringPrintf("%s/hardtocompress", |
| 131 | a_mnt.c_str()).c_str(), |
| 132 | reinterpret_cast<const char*>(kRandomString), |
| 133 | sizeof(kRandomString) - 1)); |
| 134 | // Write 1 MiB of 0xff to try to catch the case where writing a bsdiff |
| 135 | // patch fails to zero out the final block. |
| 136 | vector<char> ones(1024 * 1024, 0xff); |
| 137 | EXPECT_TRUE(utils::WriteFile(StringPrintf("%s/ones", |
| 138 | a_mnt.c_str()).c_str(), |
| 139 | &ones[0], |
| 140 | ones.size())); |
| 141 | } |
| 142 | |
| 143 | // Make some changes to the B image. |
| 144 | { |
| 145 | string b_mnt; |
| 146 | ScopedLoopMounter b_mounter(b_img, &b_mnt, 0); |
| 147 | |
| 148 | EXPECT_EQ(0, system(StringPrintf("cp %s/hello %s/hello2", b_mnt.c_str(), |
| 149 | b_mnt.c_str()).c_str())); |
| 150 | EXPECT_EQ(0, system(StringPrintf("rm %s/hello", b_mnt.c_str()).c_str())); |
| 151 | EXPECT_EQ(0, system(StringPrintf("mv %s/hello2 %s/hello", b_mnt.c_str(), |
| 152 | b_mnt.c_str()).c_str())); |
| 153 | EXPECT_EQ(0, system(StringPrintf("echo foo > %s/foo", |
| 154 | b_mnt.c_str()).c_str())); |
| 155 | EXPECT_EQ(0, system(StringPrintf("touch %s/emptyfile", |
| 156 | b_mnt.c_str()).c_str())); |
| 157 | EXPECT_TRUE(WriteSparseFile(StringPrintf("%s/fullsparse", b_mnt.c_str()), |
| 158 | 1024 * 1024)); |
| 159 | EXPECT_EQ(0, system(StringPrintf("dd if=/dev/zero of=%s/partsparese bs=1 " |
| 160 | "seek=4096 count=1", |
| 161 | b_mnt.c_str()).c_str())); |
| 162 | EXPECT_TRUE(utils::WriteFile(StringPrintf("%s/hardtocompress", |
| 163 | b_mnt.c_str()).c_str(), |
| 164 | reinterpret_cast<const char*>(kRandomString), |
| 165 | sizeof(kRandomString))); |
| 166 | } |
| 167 | |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 168 | string old_kernel; |
| 169 | EXPECT_TRUE(utils::MakeTempFile("/tmp/old_kernel.XXXXXX", &old_kernel, NULL)); |
| 170 | ScopedPathUnlinker old_kernel_unlinker(old_kernel); |
| 171 | |
| 172 | string new_kernel; |
| 173 | EXPECT_TRUE(utils::MakeTempFile("/tmp/new_kernel.XXXXXX", &new_kernel, NULL)); |
| 174 | ScopedPathUnlinker new_kernel_unlinker(new_kernel); |
| 175 | |
| 176 | vector<char> old_kernel_data(4096); // Something small for a test |
| 177 | vector<char> new_kernel_data(old_kernel_data.size()); |
| 178 | FillWithData(&old_kernel_data); |
| 179 | FillWithData(&new_kernel_data); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 180 | |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 181 | // change the new kernel data |
| 182 | const char* new_data_string = "This is new data."; |
| 183 | strcpy(&new_kernel_data[0], new_data_string); |
| 184 | |
| 185 | // Write kernels to disk |
| 186 | EXPECT_TRUE(utils::WriteFile( |
| 187 | old_kernel.c_str(), &old_kernel_data[0], old_kernel_data.size())); |
| 188 | EXPECT_TRUE(utils::WriteFile( |
| 189 | new_kernel.c_str(), &new_kernel_data[0], new_kernel_data.size())); |
| 190 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 191 | string delta_path; |
| 192 | EXPECT_TRUE(utils::MakeTempFile("/tmp/delta.XXXXXX", &delta_path, NULL)); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 193 | LOG(INFO) << "delta path: " << delta_path; |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 194 | ScopedPathUnlinker delta_path_unlinker(delta_path); |
| 195 | { |
| 196 | string a_mnt, b_mnt; |
| 197 | ScopedLoopMounter a_mounter(a_img, &a_mnt, MS_RDONLY); |
| 198 | ScopedLoopMounter b_mounter(b_img, &b_mnt, MS_RDONLY); |
| 199 | |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 200 | EXPECT_TRUE( |
| 201 | DeltaDiffGenerator::GenerateDeltaUpdateFile(a_mnt, |
| 202 | a_img, |
| 203 | b_mnt, |
| 204 | b_img, |
| 205 | old_kernel, |
| 206 | new_kernel, |
| 207 | delta_path, |
| 208 | kUnittestPrivateKeyPath)); |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | // Read delta into memory. |
| 212 | vector<char> delta; |
| 213 | EXPECT_TRUE(utils::ReadFile(delta_path, &delta)); |
| 214 | |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 215 | uint64_t manifest_metadata_size; |
| 216 | |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 217 | // Check that the null signature blob exists |
| 218 | { |
| 219 | LOG(INFO) << "delta size: " << delta.size(); |
| 220 | DeltaArchiveManifest manifest; |
| 221 | const int kManifestSizeOffset = 12; |
| 222 | const int kManifestOffset = 20; |
| 223 | uint64_t manifest_size = 0; |
| 224 | memcpy(&manifest_size, &delta[kManifestSizeOffset], sizeof(manifest_size)); |
| 225 | manifest_size = be64toh(manifest_size); |
| 226 | LOG(INFO) << "manifest size: " << manifest_size; |
| 227 | EXPECT_TRUE(manifest.ParseFromArray(&delta[kManifestOffset], |
| 228 | manifest_size)); |
| 229 | EXPECT_TRUE(manifest.has_signatures_offset()); |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 230 | manifest_metadata_size = kManifestOffset + manifest_size; |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 231 | |
| 232 | Signatures sigs_message; |
| 233 | EXPECT_TRUE(sigs_message.ParseFromArray( |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 234 | &delta[manifest_metadata_size + manifest.signatures_offset()], |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 235 | manifest.signatures_size())); |
| 236 | EXPECT_EQ(1, sigs_message.signatures_size()); |
| 237 | const Signatures_Signature& signature = sigs_message.signatures(0); |
| 238 | EXPECT_EQ(1, signature.version()); |
| 239 | |
| 240 | uint64_t expected_sig_data_length = 0; |
| 241 | EXPECT_TRUE(PayloadSigner::SignatureBlobLength(kUnittestPrivateKeyPath, |
| 242 | &expected_sig_data_length)); |
| 243 | EXPECT_EQ(expected_sig_data_length, manifest.signatures_size()); |
| 244 | EXPECT_FALSE(signature.data().empty()); |
| 245 | } |
| 246 | |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 247 | PrefsMock prefs; |
| 248 | EXPECT_CALL(prefs, SetInt64(kPrefsManifestMetadataSize, |
| 249 | manifest_metadata_size)).WillOnce(Return(true)); |
| 250 | EXPECT_CALL(prefs, SetInt64(kPrefsUpdateStateNextOperation, _)) |
| 251 | .WillRepeatedly(Return(true)); |
| 252 | EXPECT_CALL(prefs, SetInt64(kPrefsUpdateStateNextDataOffset, _)) |
| 253 | .WillRepeatedly(Return(true)); |
Darin Petkov | 437adc4 | 2010-10-07 13:12:24 -0700 | [diff] [blame^] | 254 | EXPECT_CALL(prefs, SetString(kPrefsUpdateStateSHA256Context, _)) |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 255 | .WillRepeatedly(Return(true)); |
Darin Petkov | 437adc4 | 2010-10-07 13:12:24 -0700 | [diff] [blame^] | 256 | EXPECT_CALL(prefs, SetString(kPrefsUpdateStateSignedSHA256Context, _)) |
| 257 | .WillOnce(Return(true)); |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 258 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 259 | // Update the A image in place. |
Darin Petkov | 73058b4 | 2010-10-06 16:32:19 -0700 | [diff] [blame] | 260 | DeltaPerformer performer(&prefs); |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 261 | |
| 262 | EXPECT_EQ(0, performer.Open(a_img.c_str(), 0, 0)); |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 263 | EXPECT_TRUE(performer.OpenKernel(old_kernel.c_str())); |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 264 | |
| 265 | // Write at some number of bytes per operation. Arbitrarily chose 5. |
| 266 | const size_t kBytesPerWrite = 5; |
| 267 | for (size_t i = 0; i < delta.size(); i += kBytesPerWrite) { |
| 268 | size_t count = min(delta.size() - i, kBytesPerWrite); |
| 269 | EXPECT_EQ(count, performer.Write(&delta[i], count)); |
| 270 | } |
| 271 | |
| 272 | // Wrapper around close. Returns 0 on success or -errno on error. |
| 273 | EXPECT_EQ(0, performer.Close()); |
| 274 | |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 275 | CompareFilesByBlock(old_kernel, new_kernel); |
Andrew de los Reyes | 932bc4c | 2010-08-23 18:14:09 -0700 | [diff] [blame] | 276 | |
Andrew de los Reyes | f4c7ef1 | 2010-04-30 10:37:00 -0700 | [diff] [blame] | 277 | vector<char> updated_kernel_partition; |
| 278 | EXPECT_TRUE(utils::ReadFile(old_kernel, &updated_kernel_partition)); |
| 279 | EXPECT_EQ(0, strncmp(&updated_kernel_partition[0], new_data_string, |
| 280 | strlen(new_data_string))); |
Darin Petkov | d7061ab | 2010-10-06 14:37:09 -0700 | [diff] [blame] | 281 | |
| 282 | EXPECT_TRUE(utils::FileExists(kUnittestPublicKeyPath)); |
Darin Petkov | 437adc4 | 2010-10-07 13:12:24 -0700 | [diff] [blame^] | 283 | EXPECT_TRUE(performer.VerifyPayload( |
| 284 | kUnittestPublicKeyPath, |
| 285 | OmahaHashCalculator::OmahaHashOfData(delta), |
| 286 | delta.size())); |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 289 | TEST(DeltaPerformerTest, NewFullUpdateTest) { |
| 290 | vector<char> new_root(20 * 1024 * 1024); |
| 291 | vector<char> new_kern(16 * 1024 * 1024); |
| 292 | const off_t kChunkSize = 128 * 1024; |
| 293 | FillWithData(&new_root); |
| 294 | FillWithData(&new_kern); |
Darin Petkov | 437adc4 | 2010-10-07 13:12:24 -0700 | [diff] [blame^] | 295 | |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 296 | string new_root_path; |
| 297 | EXPECT_TRUE(utils::MakeTempFile("/tmp/NewFullUpdateTest_R.XXXXXX", |
| 298 | &new_root_path, |
| 299 | NULL)); |
| 300 | ScopedPathUnlinker new_root_path_unlinker(new_root_path); |
| 301 | EXPECT_TRUE(WriteFileVector(new_root_path, new_root)); |
| 302 | |
| 303 | string new_kern_path; |
| 304 | EXPECT_TRUE(utils::MakeTempFile("/tmp/NewFullUpdateTest_K.XXXXXX", |
| 305 | &new_kern_path, |
| 306 | NULL)); |
| 307 | ScopedPathUnlinker new_kern_path_unlinker(new_kern_path); |
| 308 | EXPECT_TRUE(WriteFileVector(new_kern_path, new_kern)); |
| 309 | |
| 310 | string out_blobs_path; |
| 311 | int out_blobs_fd; |
| 312 | EXPECT_TRUE(utils::MakeTempFile("/tmp/NewFullUpdateTest_D.XXXXXX", |
| 313 | &out_blobs_path, |
| 314 | &out_blobs_fd)); |
| 315 | ScopedPathUnlinker out_blobs_path_unlinker(out_blobs_path); |
| 316 | ScopedFdCloser out_blobs_fd_closer(&out_blobs_fd); |
Darin Petkov | 437adc4 | 2010-10-07 13:12:24 -0700 | [diff] [blame^] | 317 | |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 318 | off_t out_blobs_length = 0; |
Darin Petkov | 437adc4 | 2010-10-07 13:12:24 -0700 | [diff] [blame^] | 319 | |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 320 | Graph graph; |
| 321 | vector<DeltaArchiveManifest_InstallOperation> kernel_ops; |
| 322 | vector<Vertex::Index> final_order; |
Darin Petkov | 437adc4 | 2010-10-07 13:12:24 -0700 | [diff] [blame^] | 323 | |
Andrew de los Reyes | 27f7d37 | 2010-10-07 11:26:07 -0700 | [diff] [blame] | 324 | EXPECT_TRUE(DeltaDiffGenerator::ReadFullUpdateFromDisk(&graph, |
| 325 | new_kern_path, |
| 326 | new_root_path, |
| 327 | out_blobs_fd, |
| 328 | &out_blobs_length, |
| 329 | kChunkSize, |
| 330 | &kernel_ops, |
| 331 | &final_order)); |
| 332 | EXPECT_EQ(new_root.size() / kChunkSize, graph.size()); |
| 333 | EXPECT_EQ(new_root.size() / kChunkSize, final_order.size()); |
| 334 | EXPECT_EQ(new_kern.size() / kChunkSize, kernel_ops.size()); |
| 335 | for (size_t i = 0; i < (new_root.size() / kChunkSize); ++i) { |
| 336 | EXPECT_EQ(i, final_order[i]); |
| 337 | EXPECT_EQ(1, graph[i].op.dst_extents_size()); |
| 338 | EXPECT_EQ(i * kChunkSize / kBlockSize, |
| 339 | graph[i].op.dst_extents(0).start_block()) << "i = " << i; |
| 340 | EXPECT_EQ(kChunkSize / kBlockSize, |
| 341 | graph[i].op.dst_extents(0).num_blocks()); |
| 342 | if (graph[i].op.type() != |
| 343 | DeltaArchiveManifest_InstallOperation_Type_REPLACE) { |
| 344 | EXPECT_EQ(DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ, |
| 345 | graph[i].op.type()); |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | |
Andrew de los Reyes | 09e56d6 | 2010-04-23 13:45:53 -0700 | [diff] [blame] | 350 | } // namespace chromeos_update_engine |