full_update_generator_unittest.cc revision d2779df63aaad8b65fc5d4badee7dbc9bed7f2b6
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 <string>
6#include <vector>
7
8#include <gtest/gtest.h>
9
10#include "update_engine/payload_generator/full_update_generator.h"
11#include "update_engine/test_utils.h"
12
13using std::string;
14using std::vector;
15
16namespace chromeos_update_engine {
17
18namespace {
19  const size_t kBlockSize = 4096;
20}  // namespace
21
22
23class FullUpdateGeneratorTest : public ::testing::Test { };
24
25
26TEST(FullUpdateGeneratorTest, RunTest) {
27  vector<char> new_root(20 * 1024 * 1024);
28  vector<char> new_kern(16 * 1024 * 1024);
29  const off_t kChunkSize = 128 * 1024;
30  FillWithData(&new_root);
31  FillWithData(&new_kern);
32  // Assume hashes take 2 MiB beyond the rootfs.
33  off_t new_rootfs_size = new_root.size() - 2 * 1024 * 1024;
34
35  string new_root_path;
36  EXPECT_TRUE(utils::MakeTempFile("NewFullUpdateTest_R.XXXXXX",
37                                  &new_root_path,
38                                  NULL));
39  ScopedPathUnlinker new_root_path_unlinker(new_root_path);
40  EXPECT_TRUE(WriteFileVector(new_root_path, new_root));
41
42  string new_kern_path;
43  EXPECT_TRUE(utils::MakeTempFile("NewFullUpdateTest_K.XXXXXX",
44                                  &new_kern_path,
45                                  NULL));
46  ScopedPathUnlinker new_kern_path_unlinker(new_kern_path);
47  EXPECT_TRUE(WriteFileVector(new_kern_path, new_kern));
48
49  string out_blobs_path;
50  int out_blobs_fd;
51  EXPECT_TRUE(utils::MakeTempFile("NewFullUpdateTest_D.XXXXXX",
52                                  &out_blobs_path,
53                                  &out_blobs_fd));
54  ScopedPathUnlinker out_blobs_path_unlinker(out_blobs_path);
55  ScopedFdCloser out_blobs_fd_closer(&out_blobs_fd);
56
57  off_t out_blobs_length = 0;
58
59  Graph graph;
60  vector<DeltaArchiveManifest_InstallOperation> kernel_ops;
61  vector<Vertex::Index> final_order;
62
63  EXPECT_TRUE(FullUpdateGenerator::Run(&graph,
64                                       new_kern_path,
65                                       new_root_path,
66                                       new_rootfs_size,
67                                       out_blobs_fd,
68                                       &out_blobs_length,
69                                       kChunkSize,
70                                       kBlockSize,
71                                       &kernel_ops,
72                                       &final_order));
73  EXPECT_EQ(new_rootfs_size / kChunkSize, graph.size());
74  EXPECT_EQ(new_rootfs_size / kChunkSize, final_order.size());
75  EXPECT_EQ(new_kern.size() / kChunkSize, kernel_ops.size());
76  for (off_t i = 0; i < (new_rootfs_size / kChunkSize); ++i) {
77    EXPECT_EQ(i, final_order[i]);
78    EXPECT_EQ(1, graph[i].op.dst_extents_size());
79    EXPECT_EQ(i * kChunkSize / kBlockSize,
80              graph[i].op.dst_extents(0).start_block()) << "i = " << i;
81    EXPECT_EQ(kChunkSize / kBlockSize,
82              graph[i].op.dst_extents(0).num_blocks());
83    if (graph[i].op.type() !=
84        DeltaArchiveManifest_InstallOperation_Type_REPLACE) {
85      EXPECT_EQ(DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ,
86                graph[i].op.type());
87    }
88  }
89}
90
91}  // namespace chromeos_update_engine
92