summaryrefslogtreecommitdiff
path: root/payload_generator/graph_utils_unittest.cc
diff options
context:
space:
mode:
authorAlex Deymo <deymo@chromium.org>2014-05-16 15:56:21 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-05-19 23:06:17 +0000
commit161c4a132743f15fc4757112b673085c2a7a7f29 (patch)
tree97af3e16c8c6c553fc2aa364df26c91f84bfb1a8 /payload_generator/graph_utils_unittest.cc
parentbcee2ca34ebcd3b0abc7bc611370d323e55fa62c (diff)
Move payload generator files to payload_generator/ directory.
This creates a new subdirectory payload_generator/ with all the payload generator specific files. The SConstruct file is updated to continue building all the files together, including those in the subdirectories, since some parts of the update_engine are using parts of the payload generation code. To reduce this code coupling, a new payload_constants.h file is introduced, with few constants used on the payload definition by both the payload generation and the payload performer. Finally, includes are updated and in some cases removed when they weren't used. Order of includes is also fixed to comply with the style guide. BUG=chromium:374377 TEST=Build and unittests still pass. delta_generator still present on base directory. Change-Id: I454bbc7a66c70ebb19fd596c352c7be40a081f3d Reviewed-on: https://chromium-review.googlesource.com/200325 Reviewed-by: Alex Deymo <deymo@chromium.org> Commit-Queue: Alex Deymo <deymo@chromium.org> Tested-by: Alex Deymo <deymo@chromium.org>
Diffstat (limited to 'payload_generator/graph_utils_unittest.cc')
-rw-r--r--payload_generator/graph_utils_unittest.cc123
1 files changed, 123 insertions, 0 deletions
diff --git a/payload_generator/graph_utils_unittest.cc b/payload_generator/graph_utils_unittest.cc
new file mode 100644
index 00000000..0aed78d8
--- /dev/null
+++ b/payload_generator/graph_utils_unittest.cc
@@ -0,0 +1,123 @@
+// Copyright (c) 2009 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 <utility>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+#include "update_engine/extent_ranges.h"
+#include "update_engine/payload_constants.h"
+#include "update_engine/payload_generator/graph_utils.h"
+
+using std::make_pair;
+using std::vector;
+
+namespace chromeos_update_engine {
+
+class GraphUtilsTest : public ::testing::Test {};
+
+TEST(GraphUtilsTest, SimpleTest) {
+ Graph graph(2);
+
+ graph[0].out_edges.insert(make_pair(1, EdgeProperties()));
+
+ vector<Extent>& extents = graph[0].out_edges[1].extents;
+
+ EXPECT_EQ(0, extents.size());
+ graph_utils::AppendBlockToExtents(&extents, 0);
+ EXPECT_EQ(1, extents.size());
+ graph_utils::AppendBlockToExtents(&extents, 1);
+ graph_utils::AppendBlockToExtents(&extents, 2);
+ EXPECT_EQ(1, extents.size());
+ graph_utils::AppendBlockToExtents(&extents, 4);
+
+ EXPECT_EQ(2, extents.size());
+ EXPECT_EQ(0, extents[0].start_block());
+ EXPECT_EQ(3, extents[0].num_blocks());
+ EXPECT_EQ(4, extents[1].start_block());
+ EXPECT_EQ(1, extents[1].num_blocks());
+
+ EXPECT_EQ(4, graph_utils::EdgeWeight(graph, make_pair(0, 1)));
+}
+
+TEST(GraphUtilsTest, AppendSparseToExtentsTest) {
+ vector<Extent> extents;
+
+ EXPECT_EQ(0, extents.size());
+ graph_utils::AppendBlockToExtents(&extents, kSparseHole);
+ EXPECT_EQ(1, extents.size());
+ graph_utils::AppendBlockToExtents(&extents, 0);
+ EXPECT_EQ(2, extents.size());
+ graph_utils::AppendBlockToExtents(&extents, kSparseHole);
+ graph_utils::AppendBlockToExtents(&extents, kSparseHole);
+
+ ASSERT_EQ(3, extents.size());
+ EXPECT_EQ(kSparseHole, extents[0].start_block());
+ EXPECT_EQ(1, extents[0].num_blocks());
+ EXPECT_EQ(0, extents[1].start_block());
+ EXPECT_EQ(1, extents[1].num_blocks());
+ EXPECT_EQ(kSparseHole, extents[2].start_block());
+ EXPECT_EQ(2, extents[2].num_blocks());
+}
+
+TEST(GraphUtilsTest, BlocksInExtentsTest) {
+ {
+ vector<Extent> extents;
+ EXPECT_EQ(0, graph_utils::BlocksInExtents(extents));
+ extents.push_back(ExtentForRange(0, 1));
+ EXPECT_EQ(1, graph_utils::BlocksInExtents(extents));
+ extents.push_back(ExtentForRange(23, 55));
+ EXPECT_EQ(56, graph_utils::BlocksInExtents(extents));
+ extents.push_back(ExtentForRange(1, 2));
+ EXPECT_EQ(58, graph_utils::BlocksInExtents(extents));
+ }
+ {
+ google::protobuf::RepeatedPtrField<Extent> extents;
+ EXPECT_EQ(0, graph_utils::BlocksInExtents(extents));
+ *extents.Add() = ExtentForRange(0, 1);
+ EXPECT_EQ(1, graph_utils::BlocksInExtents(extents));
+ *extents.Add() = ExtentForRange(23, 55);
+ EXPECT_EQ(56, graph_utils::BlocksInExtents(extents));
+ *extents.Add() = ExtentForRange(1, 2);
+ EXPECT_EQ(58, graph_utils::BlocksInExtents(extents));
+ }
+}
+
+TEST(GraphUtilsTest, DepsTest) {
+ Graph graph(3);
+
+ graph_utils::AddReadBeforeDep(&graph[0], 1, 3);
+ EXPECT_EQ(1, graph[0].out_edges.size());
+ {
+ Extent& extent = graph[0].out_edges[1].extents[0];
+ EXPECT_EQ(3, extent.start_block());
+ EXPECT_EQ(1, extent.num_blocks());
+ }
+ graph_utils::AddReadBeforeDep(&graph[0], 1, 4);
+ EXPECT_EQ(1, graph[0].out_edges.size());
+ {
+ Extent& extent = graph[0].out_edges[1].extents[0];
+ EXPECT_EQ(3, extent.start_block());
+ EXPECT_EQ(2, extent.num_blocks());
+ }
+ graph_utils::AddReadBeforeDepExtents(&graph[2], 1,
+ vector<Extent>(1, ExtentForRange(5, 2)));
+ EXPECT_EQ(1, graph[2].out_edges.size());
+ {
+ Extent& extent = graph[2].out_edges[1].extents[0];
+ EXPECT_EQ(5, extent.start_block());
+ EXPECT_EQ(2, extent.num_blocks());
+ }
+ // Change most recent edge from read-before to write-before
+ graph[2].out_edges[1].write_extents.swap(graph[2].out_edges[1].extents);
+ graph_utils::DropWriteBeforeDeps(&graph[2].out_edges);
+ EXPECT_EQ(0, graph[2].out_edges.size());
+
+ EXPECT_EQ(1, graph[0].out_edges.size());
+ graph_utils::DropIncomingEdgesTo(&graph, 1);
+ EXPECT_EQ(0, graph[0].out_edges.size());
+}
+
+} // namespace chromeos_update_engine