full_update_generator_unittest.cc revision 9b244df41f1bdaddd87b7dbd8e1559556059ed1b
1// Copyright (c) 2010 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 "update_engine/payload_generator/full_update_generator.h"
6
7#include <string>
8#include <vector>
9
10#include <gtest/gtest.h>
11
12#include "update_engine/delta_performer.h"
13#include "update_engine/test_utils.h"
14
15using chromeos_update_engine::test_utils::FillWithData;
16using std::string;
17using std::vector;
18
19namespace chromeos_update_engine {
20
21class FullUpdateGeneratorTest : public ::testing::Test {
22 protected:
23  void SetUp() override {
24    config_.is_delta = false;
25    config_.minor_version = DeltaPerformer::kFullPayloadMinorVersion;
26    config_.chunk_size = 128 * 1024;
27    config_.block_size = 4096;
28  }
29
30  PayloadGenerationConfig config_;
31};
32
33
34TEST_F(FullUpdateGeneratorTest, RunTest) {
35  chromeos::Blob new_root(20 * 1024 * 1024);
36  chromeos::Blob new_kern(16 * 1024 * 1024);
37  FillWithData(&new_root);
38  FillWithData(&new_kern);
39
40  // Assume hashes take 2 MiB beyond the rootfs.
41  config_.rootfs_partition_size = new_root.size();
42  config_.target.rootfs_size = new_root.size() - 2 * 1024 * 1024;
43  config_.target.kernel_size = new_kern.size();
44
45  EXPECT_TRUE(utils::MakeTempFile("NewFullUpdateTest_R.XXXXXX",
46                                  &config_.target.rootfs_part,
47                                  nullptr));
48  ScopedPathUnlinker rootfs_part_unlinker(config_.target.rootfs_part);
49  EXPECT_TRUE(test_utils::WriteFileVector(config_.target.rootfs_part,
50                                          new_root));
51
52  EXPECT_TRUE(utils::MakeTempFile("NewFullUpdateTest_K.XXXXXX",
53                                  &config_.target.kernel_part,
54                                  nullptr));
55  ScopedPathUnlinker kernel_path_unlinker(config_.target.kernel_part);
56  EXPECT_TRUE(test_utils::WriteFileVector(config_.target.kernel_part,
57                                          new_kern));
58
59  string out_blobs_path;
60  int out_blobs_fd;
61  EXPECT_TRUE(utils::MakeTempFile("NewFullUpdateTest_D.XXXXXX",
62                                  &out_blobs_path,
63                                  &out_blobs_fd));
64  ScopedPathUnlinker out_blobs_path_unlinker(out_blobs_path);
65  ScopedFdCloser out_blobs_fd_closer(&out_blobs_fd);
66
67  off_t out_blobs_length = 0;
68  Graph graph;
69  vector<DeltaArchiveManifest_InstallOperation> kernel_ops;
70  vector<Vertex::Index> final_order;
71
72  EXPECT_TRUE(FullUpdateGenerator::Run(config_,
73                                       out_blobs_fd,
74                                       &out_blobs_length,
75                                       &graph,
76                                       &kernel_ops,
77                                       &final_order));
78  int64_t target_rootfs_chucks =
79      config_.target.rootfs_size / config_.chunk_size;
80  EXPECT_EQ(target_rootfs_chucks, graph.size());
81  EXPECT_EQ(target_rootfs_chucks, final_order.size());
82  EXPECT_EQ(new_kern.size() / config_.chunk_size, kernel_ops.size());
83  for (off_t i = 0; i < target_rootfs_chucks; ++i) {
84    EXPECT_EQ(i, final_order[i]);
85    EXPECT_EQ(1, graph[i].op.dst_extents_size());
86    EXPECT_EQ(i * config_.chunk_size / config_.block_size,
87              graph[i].op.dst_extents(0).start_block()) << "i = " << i;
88    EXPECT_EQ(config_.chunk_size / config_.block_size,
89              graph[i].op.dst_extents(0).num_blocks());
90    if (graph[i].op.type() !=
91        DeltaArchiveManifest_InstallOperation_Type_REPLACE) {
92      EXPECT_EQ(DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ,
93                graph[i].op.type());
94    }
95  }
96}
97
98}  // namespace chromeos_update_engine
99