AU: support for generating new style full updates.

New style full updates are full updates that use the delta upload file
format. A full update consists of sequential operations to write the
full kernel/rootfs in chunks (currently 128KiB).

Because these full updates use the new file format, they get benefits
over the old type of full update:
- support for embedded signatures
- (eventual) support for resuming installation across reboot
- help reduce code needed in the updater client software

BUG=7248
TEST=generated/applied full update on host; unittests

Review URL: http://codereview.chromium.org/3550020
diff --git a/delta_performer_unittest.cc b/delta_performer_unittest.cc
index 12de8a9..4a11c69 100755
--- a/delta_performer_unittest.cc
+++ b/delta_performer_unittest.cc
@@ -34,6 +34,11 @@
 extern const char* kUnittestPrivateKeyPath;
 extern const char* kUnittestPublicKeyPath;
 
+namespace {
+  const size_t kBlockSize = 4096;
+}  // namespace {}
+
+
 class DeltaPerformerTest : public ::testing::Test { };
 
 TEST(DeltaPerformerTest, ExtentsToByteStringTest) {
@@ -85,7 +90,6 @@
   EXPECT_TRUE(utils::ReadFile(b_file, &b_data)) << "file failed: " << b_file;
 
   EXPECT_EQ(a_data.size(), b_data.size());
-  size_t kBlockSize = 4096;
   EXPECT_EQ(0, a_data.size() % kBlockSize);
   for (size_t i = 0; i < a_data.size(); i += kBlockSize) {
     EXPECT_EQ(0, i % kBlockSize);
@@ -277,4 +281,65 @@
   EXPECT_TRUE(performer.VerifyPayload(kUnittestPublicKeyPath));
 }
 
+TEST(DeltaPerformerTest, NewFullUpdateTest) {
+  vector<char> new_root(20 * 1024 * 1024);
+  vector<char> new_kern(16 * 1024 * 1024);
+  const off_t kChunkSize = 128 * 1024;
+  FillWithData(&new_root);
+  FillWithData(&new_kern);
+  
+  string new_root_path;
+  EXPECT_TRUE(utils::MakeTempFile("/tmp/NewFullUpdateTest_R.XXXXXX",
+                                  &new_root_path,
+                                  NULL));
+  ScopedPathUnlinker new_root_path_unlinker(new_root_path);
+  EXPECT_TRUE(WriteFileVector(new_root_path, new_root));
+
+  string new_kern_path;
+  EXPECT_TRUE(utils::MakeTempFile("/tmp/NewFullUpdateTest_K.XXXXXX",
+                                  &new_kern_path,
+                                  NULL));
+  ScopedPathUnlinker new_kern_path_unlinker(new_kern_path);
+  EXPECT_TRUE(WriteFileVector(new_kern_path, new_kern));
+
+  string out_blobs_path;
+  int out_blobs_fd;
+  EXPECT_TRUE(utils::MakeTempFile("/tmp/NewFullUpdateTest_D.XXXXXX",
+                                  &out_blobs_path,
+                                  &out_blobs_fd));
+  ScopedPathUnlinker out_blobs_path_unlinker(out_blobs_path);
+  ScopedFdCloser out_blobs_fd_closer(&out_blobs_fd);
+  
+  off_t out_blobs_length = 0;
+  
+  Graph graph;
+  vector<DeltaArchiveManifest_InstallOperation> kernel_ops;
+  vector<Vertex::Index> final_order;
+  
+  EXPECT_TRUE(DeltaDiffGenerator::ReadFullUpdateFromDisk(&graph,
+                                                         new_kern_path,
+                                                         new_root_path,
+                                                         out_blobs_fd,
+                                                         &out_blobs_length,
+                                                         kChunkSize,
+                                                         &kernel_ops,
+                                                         &final_order));
+  EXPECT_EQ(new_root.size() / kChunkSize, graph.size());
+  EXPECT_EQ(new_root.size() / kChunkSize, final_order.size());
+  EXPECT_EQ(new_kern.size() / kChunkSize, kernel_ops.size());
+  for (size_t i = 0; i < (new_root.size() / kChunkSize); ++i) {
+    EXPECT_EQ(i, final_order[i]);
+    EXPECT_EQ(1, graph[i].op.dst_extents_size());
+    EXPECT_EQ(i * kChunkSize / kBlockSize,
+              graph[i].op.dst_extents(0).start_block()) << "i = " << i;
+    EXPECT_EQ(kChunkSize / kBlockSize,
+              graph[i].op.dst_extents(0).num_blocks());
+    if (graph[i].op.type() !=
+        DeltaArchiveManifest_InstallOperation_Type_REPLACE) {
+      EXPECT_EQ(DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ,
+                graph[i].op.type());
+    }
+  }
+}
+
 }  // namespace chromeos_update_engine