diff options
author | Alex Deymo <deymo@chromium.org> | 2015-06-13 03:37:08 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-07-01 09:35:37 +0000 |
commit | 14158570d3995008dc93a628004118b87a6bca01 (patch) | |
tree | 575271d90c0bdfc105dafa43413d80d66975d723 /payload_generator/payload_file_unittest.cc | |
parent | 6c396a9b3020df9b0b58886fd6f36523bec29d3a (diff) |
update_engine: Split delta_diff_generator file.
The DeltaDiffGenerator class includes both an OperationsGenerator using the
A-to-B operations and a set of common methods used also by the inplace generator.
The delta_diff_generator.{h,cc} files also include a single function to generate
the payload (GenerateUpdatePayloadFile) that centralizes the logic of generating
the operations and writing the payload.
This patch splits these three parts in different files. The common delta diff
function are moved to the delta_diff_utils.{h,cc} files. The operations generator
class that uses A-to-B operations is now in a new ab_generator.{h,cc} pair of files
that implement the ABGenerator() class. Finally, the payload file writing methods
are now in a single PayloadFile class.
This allow us to create payload files without the need to generate images and
their deltas. This will be used in a follow up CL to remove the image generation
logic from the unittests.
BUG=chromium:351589
TEST=Ran unittests. Regenerate a payload with and without this patch; got the same results.
Change-Id: I6816d2c805ba8c0c5c9423c720131a100a15ebaa
Reviewed-on: https://chromium-review.googlesource.com/280838
Reviewed-by: Alex Deymo <deymo@chromium.org>
Commit-Queue: Alex Deymo <deymo@chromium.org>
Trybot-Ready: Alex Deymo <deymo@chromium.org>
Tested-by: Alex Deymo <deymo@chromium.org>
Diffstat (limited to 'payload_generator/payload_file_unittest.cc')
-rw-r--r-- | payload_generator/payload_file_unittest.cc | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/payload_generator/payload_file_unittest.cc b/payload_generator/payload_file_unittest.cc new file mode 100644 index 00000000..1d9661f0 --- /dev/null +++ b/payload_generator/payload_file_unittest.cc @@ -0,0 +1,84 @@ +// Copyright 2015 The Chromium OS Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "update_engine/payload_generator/payload_file.h" + +#include <string> +#include <utility> +#include <vector> + +#include <gtest/gtest.h> + +#include "update_engine/payload_constants.h" +#include "update_engine/payload_generator/extent_ranges.h" +#include "update_engine/test_utils.h" + +using std::string; +using std::vector; + +namespace chromeos_update_engine { + +class PayloadFileTest : public ::testing::Test { + protected: + PayloadFile payload_; +}; + +TEST_F(PayloadFileTest, ReorderBlobsTest) { + string orig_blobs; + EXPECT_TRUE(utils::MakeTempFile("ReorderBlobsTest.orig.XXXXXX", &orig_blobs, + nullptr)); + ScopedPathUnlinker orig_blobs_unlinker(orig_blobs); + + // The operations have three blob and one gap (the whitespace): + // Rootfs operation 1: [8, 3] bcd + // Rootfs operation 2: [7, 1] a + // Kernel operation 1: [0, 6] kernel + string orig_data = "kernel abcd"; + EXPECT_TRUE( + utils::WriteFile(orig_blobs.c_str(), orig_data.data(), orig_data.size())); + + string new_blobs; + EXPECT_TRUE( + utils::MakeTempFile("ReorderBlobsTest.new.XXXXXX", &new_blobs, nullptr)); + ScopedPathUnlinker new_blobs_unlinker(new_blobs); + + vector<AnnotatedOperation> aops; + AnnotatedOperation aop; + aop.op.set_data_offset(8); + aop.op.set_data_length(3); + aops.push_back(aop); + + aop.op.set_data_offset(7); + aop.op.set_data_length(1); + aops.push_back(aop); + payload_.AddPartitionOperations(PartitionName::kRootfs, aops); + + aop.op.set_data_offset(0); + aop.op.set_data_length(6); + aops = {aop}; + payload_.AddPartitionOperations(PartitionName::kKernel, aops); + + EXPECT_TRUE(payload_.ReorderDataBlobs(orig_blobs, new_blobs)); + + const vector<AnnotatedOperation>& rootfs_aops = + payload_.aops_map_[PartitionName::kRootfs]; + const vector<AnnotatedOperation>& kernel_aops = + payload_.aops_map_[PartitionName::kKernel]; + string new_data; + EXPECT_TRUE(utils::ReadFile(new_blobs, &new_data)); + // Kernel blobs should appear at the end. + EXPECT_EQ("bcdakernel", new_data); + + EXPECT_EQ(2, rootfs_aops.size()); + EXPECT_EQ(0, rootfs_aops[0].op.data_offset()); + EXPECT_EQ(3, rootfs_aops[0].op.data_length()); + EXPECT_EQ(3, rootfs_aops[1].op.data_offset()); + EXPECT_EQ(1, rootfs_aops[1].op.data_length()); + + EXPECT_EQ(1, kernel_aops.size()); + EXPECT_EQ(4, kernel_aops[0].op.data_offset()); + EXPECT_EQ(6, kernel_aops[0].op.data_length()); +} + +} // namespace chromeos_update_engine |