Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(336)

Side by Side Diff: graph_utils_unittest.cc

Issue 3596007: AU: More graph utilities (Closed) Base URL: ssh://git@chromiumos-git/update_engine.git
Patch Set: fixes for review and merge origin/master Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « graph_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <utility> 5 #include <utility>
6 #include <vector> 6 #include <vector>
7
7 #include <gtest/gtest.h> 8 #include <gtest/gtest.h>
9
8 #include "update_engine/graph_utils.h" 10 #include "update_engine/graph_utils.h"
11 #include "update_engine/extent_ranges.h"
9 12
10 using std::make_pair; 13 using std::make_pair;
11 using std::vector; 14 using std::vector;
12 15
13 namespace chromeos_update_engine { 16 namespace chromeos_update_engine {
14 17
15 class GraphUtilsTest : public ::testing::Test {}; 18 class GraphUtilsTest : public ::testing::Test {};
16 19
17 TEST(GraphUtilsTest, SimpleTest) { 20 TEST(GraphUtilsTest, SimpleTest) {
18 Graph graph(2); 21 Graph graph(2);
(...skipping 12 matching lines...) Expand all
31 34
32 EXPECT_EQ(2, extents.size()); 35 EXPECT_EQ(2, extents.size());
33 EXPECT_EQ(0, extents[0].start_block()); 36 EXPECT_EQ(0, extents[0].start_block());
34 EXPECT_EQ(3, extents[0].num_blocks()); 37 EXPECT_EQ(3, extents[0].num_blocks());
35 EXPECT_EQ(4, extents[1].start_block()); 38 EXPECT_EQ(4, extents[1].start_block());
36 EXPECT_EQ(1, extents[1].num_blocks()); 39 EXPECT_EQ(1, extents[1].num_blocks());
37 40
38 EXPECT_EQ(4, graph_utils::EdgeWeight(graph, make_pair(0, 1))); 41 EXPECT_EQ(4, graph_utils::EdgeWeight(graph, make_pair(0, 1)));
39 } 42 }
40 43
44 TEST(GraphUtilsTest, BlocksInExtentsTest) {
45 {
46 vector<Extent> extents;
47 EXPECT_EQ(0, graph_utils::BlocksInExtents(extents));
48 extents.push_back(ExtentForRange(0, 1));
49 EXPECT_EQ(1, graph_utils::BlocksInExtents(extents));
50 extents.push_back(ExtentForRange(23, 55));
51 EXPECT_EQ(56, graph_utils::BlocksInExtents(extents));
52 extents.push_back(ExtentForRange(1, 2));
53 EXPECT_EQ(58, graph_utils::BlocksInExtents(extents));
54 }
55 {
56 google::protobuf::RepeatedPtrField<Extent> extents;
57 EXPECT_EQ(0, graph_utils::BlocksInExtents(extents));
58 *extents.Add() = ExtentForRange(0, 1);
59 EXPECT_EQ(1, graph_utils::BlocksInExtents(extents));
60 *extents.Add() = ExtentForRange(23, 55);
61 EXPECT_EQ(56, graph_utils::BlocksInExtents(extents));
62 *extents.Add() = ExtentForRange(1, 2);
63 EXPECT_EQ(58, graph_utils::BlocksInExtents(extents));
64 }
65 }
66
67 TEST(GraphUtilsTest, DepsTest) {
68 Graph graph(3);
69
70 graph_utils::AddReadBeforeDep(&graph[0], 1, 3);
71 EXPECT_EQ(1, graph[0].out_edges.size());
72 {
73 Extent& extent = graph[0].out_edges[1].extents[0];
74 EXPECT_EQ(3, extent.start_block());
75 EXPECT_EQ(1, extent.num_blocks());
76 }
77 graph_utils::AddReadBeforeDep(&graph[0], 1, 4);
78 EXPECT_EQ(1, graph[0].out_edges.size());
79 {
80 Extent& extent = graph[0].out_edges[1].extents[0];
81 EXPECT_EQ(3, extent.start_block());
82 EXPECT_EQ(2, extent.num_blocks());
83 }
84 graph_utils::AddReadBeforeDepExtents(&graph[2], 1,
85 vector<Extent>(1, ExtentForRange(5, 2)));
86 EXPECT_EQ(1, graph[2].out_edges.size());
87 {
88 Extent& extent = graph[2].out_edges[1].extents[0];
89 EXPECT_EQ(5, extent.start_block());
90 EXPECT_EQ(2, extent.num_blocks());
91 }
92 // Change most recent edge from read-before to write-before
93 graph[2].out_edges[1].write_extents.swap(graph[2].out_edges[1].extents);
94 graph_utils::DropWriteBeforeDeps(&graph[2].out_edges);
95 EXPECT_EQ(0, graph[2].out_edges.size());
96
97 EXPECT_EQ(1, graph[0].out_edges.size());
98 graph_utils::DropIncomingEdgesTo(&graph, 1);
99 EXPECT_EQ(0, graph[0].out_edges.size());
100 }
101
41 } // namespace chromeos_update_engine 102 } // namespace chromeos_update_engine
OLDNEW
« no previous file with comments | « graph_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698