OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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 <sys/types.h> | 5 #include <sys/types.h> |
6 #include <sys/stat.h> | 6 #include <sys/stat.h> |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <unistd.h> | 8 #include <unistd.h> |
9 #include <set> | 9 #include <set> |
10 #include <sstream> | 10 #include <sstream> |
11 #include <string> | 11 #include <string> |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 reinterpret_cast<const char*>(kRandomString), | 60 reinterpret_cast<const char*>(kRandomString), |
61 sizeof(kRandomString))); | 61 sizeof(kRandomString))); |
62 EXPECT_TRUE(utils::WriteFile(new_path().c_str(), | 62 EXPECT_TRUE(utils::WriteFile(new_path().c_str(), |
63 reinterpret_cast<const char*>(kRandomString), | 63 reinterpret_cast<const char*>(kRandomString), |
64 sizeof(kRandomString))); | 64 sizeof(kRandomString))); |
65 vector<char> data; | 65 vector<char> data; |
66 DeltaArchiveManifest_InstallOperation op; | 66 DeltaArchiveManifest_InstallOperation op; |
67 EXPECT_TRUE(DeltaDiffGenerator::ReadFileToDiff(old_path(), | 67 EXPECT_TRUE(DeltaDiffGenerator::ReadFileToDiff(old_path(), |
68 new_path(), | 68 new_path(), |
69 &data, | 69 &data, |
70 &op)); | 70 &op, |
| 71 true)); |
71 EXPECT_TRUE(data.empty()); | 72 EXPECT_TRUE(data.empty()); |
72 | 73 |
73 EXPECT_TRUE(op.has_type()); | 74 EXPECT_TRUE(op.has_type()); |
74 EXPECT_EQ(DeltaArchiveManifest_InstallOperation_Type_MOVE, op.type()); | 75 EXPECT_EQ(DeltaArchiveManifest_InstallOperation_Type_MOVE, op.type()); |
75 EXPECT_FALSE(op.has_data_offset()); | 76 EXPECT_FALSE(op.has_data_offset()); |
76 EXPECT_FALSE(op.has_data_length()); | 77 EXPECT_FALSE(op.has_data_length()); |
77 EXPECT_EQ(1, op.src_extents_size()); | 78 EXPECT_EQ(1, op.src_extents_size()); |
78 EXPECT_EQ(sizeof(kRandomString), op.src_length()); | 79 EXPECT_EQ(sizeof(kRandomString), op.src_length()); |
79 EXPECT_EQ(1, op.dst_extents_size()); | 80 EXPECT_EQ(1, op.dst_extents_size()); |
80 EXPECT_EQ(sizeof(kRandomString), op.dst_length()); | 81 EXPECT_EQ(sizeof(kRandomString), op.dst_length()); |
81 EXPECT_EQ(BlocksInExtents(op.src_extents()), | 82 EXPECT_EQ(BlocksInExtents(op.src_extents()), |
82 BlocksInExtents(op.dst_extents())); | 83 BlocksInExtents(op.dst_extents())); |
83 EXPECT_EQ(1, BlocksInExtents(op.dst_extents())); | 84 EXPECT_EQ(1, BlocksInExtents(op.dst_extents())); |
84 } | 85 } |
85 | 86 |
86 TEST_F(DeltaDiffGeneratorTest, RunAsRootBsdiffSmallTest) { | 87 TEST_F(DeltaDiffGeneratorTest, RunAsRootBsdiffSmallTest) { |
87 EXPECT_TRUE(utils::WriteFile(old_path().c_str(), | 88 EXPECT_TRUE(utils::WriteFile(old_path().c_str(), |
88 reinterpret_cast<const char*>(kRandomString), | 89 reinterpret_cast<const char*>(kRandomString), |
89 sizeof(kRandomString) - 1)); | 90 sizeof(kRandomString) - 1)); |
90 EXPECT_TRUE(utils::WriteFile(new_path().c_str(), | 91 EXPECT_TRUE(utils::WriteFile(new_path().c_str(), |
91 reinterpret_cast<const char*>(kRandomString), | 92 reinterpret_cast<const char*>(kRandomString), |
92 sizeof(kRandomString))); | 93 sizeof(kRandomString))); |
93 vector<char> data; | 94 vector<char> data; |
94 DeltaArchiveManifest_InstallOperation op; | 95 DeltaArchiveManifest_InstallOperation op; |
95 EXPECT_TRUE(DeltaDiffGenerator::ReadFileToDiff(old_path(), | 96 EXPECT_TRUE(DeltaDiffGenerator::ReadFileToDiff(old_path(), |
96 new_path(), | 97 new_path(), |
97 &data, | 98 &data, |
98 &op)); | 99 &op, |
| 100 true)); |
99 EXPECT_FALSE(data.empty()); | 101 EXPECT_FALSE(data.empty()); |
100 | 102 |
101 EXPECT_TRUE(op.has_type()); | 103 EXPECT_TRUE(op.has_type()); |
102 EXPECT_EQ(DeltaArchiveManifest_InstallOperation_Type_BSDIFF, op.type()); | 104 EXPECT_EQ(DeltaArchiveManifest_InstallOperation_Type_BSDIFF, op.type()); |
103 EXPECT_FALSE(op.has_data_offset()); | 105 EXPECT_FALSE(op.has_data_offset()); |
104 EXPECT_FALSE(op.has_data_length()); | 106 EXPECT_FALSE(op.has_data_length()); |
105 EXPECT_EQ(1, op.src_extents_size()); | 107 EXPECT_EQ(1, op.src_extents_size()); |
106 EXPECT_EQ(sizeof(kRandomString) - 1, op.src_length()); | 108 EXPECT_EQ(sizeof(kRandomString) - 1, op.src_length()); |
107 EXPECT_EQ(1, op.dst_extents_size()); | 109 EXPECT_EQ(1, op.dst_extents_size()); |
108 EXPECT_EQ(sizeof(kRandomString), op.dst_length()); | 110 EXPECT_EQ(sizeof(kRandomString), op.dst_length()); |
109 EXPECT_EQ(BlocksInExtents(op.src_extents()), | 111 EXPECT_EQ(BlocksInExtents(op.src_extents()), |
110 BlocksInExtents(op.dst_extents())); | 112 BlocksInExtents(op.dst_extents())); |
111 EXPECT_EQ(1, BlocksInExtents(op.dst_extents())); | 113 EXPECT_EQ(1, BlocksInExtents(op.dst_extents())); |
112 } | 114 } |
113 | 115 |
114 TEST_F(DeltaDiffGeneratorTest, RunAsRootReplaceSmallTest) { | 116 TEST_F(DeltaDiffGeneratorTest, RunAsRootReplaceSmallTest) { |
115 vector<char> new_data; | 117 vector<char> new_data; |
116 for (int i = 0; i < 2; i++) { | 118 for (int i = 0; i < 2; i++) { |
117 new_data.insert(new_data.end(), | 119 new_data.insert(new_data.end(), |
118 kRandomString, | 120 kRandomString, |
119 kRandomString + sizeof(kRandomString)); | 121 kRandomString + sizeof(kRandomString)); |
120 EXPECT_TRUE(utils::WriteFile(new_path().c_str(), | 122 EXPECT_TRUE(utils::WriteFile(new_path().c_str(), |
121 &new_data[0], | 123 &new_data[0], |
122 new_data.size())); | 124 new_data.size())); |
123 vector<char> data; | 125 vector<char> data; |
124 DeltaArchiveManifest_InstallOperation op; | 126 DeltaArchiveManifest_InstallOperation op; |
125 EXPECT_TRUE(DeltaDiffGenerator::ReadFileToDiff(old_path(), | 127 EXPECT_TRUE(DeltaDiffGenerator::ReadFileToDiff(old_path(), |
126 new_path(), | 128 new_path(), |
127 &data, | 129 &data, |
128 &op)); | 130 &op, |
| 131 true)); |
129 EXPECT_FALSE(data.empty()); | 132 EXPECT_FALSE(data.empty()); |
130 | 133 |
131 EXPECT_TRUE(op.has_type()); | 134 EXPECT_TRUE(op.has_type()); |
132 const DeltaArchiveManifest_InstallOperation_Type expected_type = | 135 const DeltaArchiveManifest_InstallOperation_Type expected_type = |
133 (i == 0 ? DeltaArchiveManifest_InstallOperation_Type_REPLACE : | 136 (i == 0 ? DeltaArchiveManifest_InstallOperation_Type_REPLACE : |
134 DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ); | 137 DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ); |
135 EXPECT_EQ(expected_type, op.type()); | 138 EXPECT_EQ(expected_type, op.type()); |
136 EXPECT_FALSE(op.has_data_offset()); | 139 EXPECT_FALSE(op.has_data_offset()); |
137 EXPECT_FALSE(op.has_data_length()); | 140 EXPECT_FALSE(op.has_data_length()); |
138 EXPECT_EQ(0, op.src_extents_size()); | 141 EXPECT_EQ(0, op.src_extents_size()); |
139 EXPECT_FALSE(op.has_src_length()); | 142 EXPECT_FALSE(op.has_src_length()); |
140 EXPECT_EQ(1, op.dst_extents_size()); | 143 EXPECT_EQ(1, op.dst_extents_size()); |
141 EXPECT_EQ(new_data.size(), op.dst_length()); | 144 EXPECT_EQ(new_data.size(), op.dst_length()); |
142 EXPECT_EQ(1, BlocksInExtents(op.dst_extents())); | 145 EXPECT_EQ(1, BlocksInExtents(op.dst_extents())); |
143 } | 146 } |
144 } | 147 } |
145 | 148 |
| 149 TEST_F(DeltaDiffGeneratorTest, RunAsRootBsdiffNoGatherExtentsSmallTest) { |
| 150 EXPECT_TRUE(utils::WriteFile(old_path().c_str(), |
| 151 reinterpret_cast<const char*>(kRandomString), |
| 152 sizeof(kRandomString) - 1)); |
| 153 EXPECT_TRUE(utils::WriteFile(new_path().c_str(), |
| 154 reinterpret_cast<const char*>(kRandomString), |
| 155 sizeof(kRandomString))); |
| 156 vector<char> data; |
| 157 DeltaArchiveManifest_InstallOperation op; |
| 158 EXPECT_TRUE(DeltaDiffGenerator::ReadFileToDiff(old_path(), |
| 159 new_path(), |
| 160 &data, |
| 161 &op, |
| 162 false)); |
| 163 EXPECT_FALSE(data.empty()); |
| 164 |
| 165 EXPECT_TRUE(op.has_type()); |
| 166 EXPECT_EQ(DeltaArchiveManifest_InstallOperation_Type_BSDIFF, op.type()); |
| 167 EXPECT_FALSE(op.has_data_offset()); |
| 168 EXPECT_FALSE(op.has_data_length()); |
| 169 EXPECT_EQ(1, op.src_extents_size()); |
| 170 EXPECT_EQ(0, op.src_extents().Get(0).start_block()); |
| 171 EXPECT_EQ(1, op.src_extents().Get(0).num_blocks()); |
| 172 EXPECT_EQ(sizeof(kRandomString) - 1, op.src_length()); |
| 173 EXPECT_EQ(1, op.dst_extents_size()); |
| 174 EXPECT_EQ(0, op.dst_extents().Get(0).start_block()); |
| 175 EXPECT_EQ(1, op.dst_extents().Get(0).num_blocks()); |
| 176 EXPECT_EQ(sizeof(kRandomString), op.dst_length()); |
| 177 } |
| 178 |
146 namespace { | 179 namespace { |
147 void AppendExtent(vector<Extent>* vect, uint64_t start, uint64_t length) { | 180 void AppendExtent(vector<Extent>* vect, uint64_t start, uint64_t length) { |
148 vect->resize(vect->size() + 1); | 181 vect->resize(vect->size() + 1); |
149 vect->back().set_start_block(start); | 182 vect->back().set_start_block(start); |
150 vect->back().set_num_blocks(length); | 183 vect->back().set_num_blocks(length); |
151 } | 184 } |
152 void OpAppendExtent(DeltaArchiveManifest_InstallOperation* op, | 185 void OpAppendExtent(DeltaArchiveManifest_InstallOperation* op, |
153 uint64_t start, | 186 uint64_t start, |
154 uint64_t length) { | 187 uint64_t length) { |
155 Extent* extent = op->add_src_extents(); | 188 Extent* extent = op->add_src_extents(); |
156 extent->set_start_block(start); | 189 extent->set_start_block(start); |
157 extent->set_num_blocks(length); | 190 extent->set_num_blocks(length); |
158 } | 191 } |
159 } | 192 } |
160 | 193 |
161 TEST_F(DeltaDiffGeneratorTest, SubstituteBlocksTest) { | 194 TEST_F(DeltaDiffGeneratorTest, SubstituteBlocksTest) { |
162 vector<Extent> remove_blocks; | 195 vector<Extent> remove_blocks; |
163 AppendExtent(&remove_blocks, 3, 3); | 196 AppendExtent(&remove_blocks, 3, 3); |
164 AppendExtent(&remove_blocks, 7, 1); | 197 AppendExtent(&remove_blocks, 7, 1); |
165 vector<Extent> replace_blocks; | 198 vector<Extent> replace_blocks; |
166 AppendExtent(&replace_blocks, 10, 2); | 199 AppendExtent(&replace_blocks, 10, 2); |
167 AppendExtent(&replace_blocks, 13, 2); | 200 AppendExtent(&replace_blocks, 13, 2); |
168 Vertex vertex; | 201 Vertex vertex; |
169 DeltaArchiveManifest_InstallOperation& op = vertex.op; | 202 DeltaArchiveManifest_InstallOperation& op = vertex.op; |
170 OpAppendExtent(&op, 4, 3); | 203 OpAppendExtent(&op, 4, 3); |
171 OpAppendExtent(&op, kSparseHole, 4); // Sparse hole in file | 204 OpAppendExtent(&op, kSparseHole, 4); // Sparse hole in file |
172 OpAppendExtent(&op, 3, 1); | 205 OpAppendExtent(&op, 3, 1); |
173 OpAppendExtent(&op, 7, 3); | 206 OpAppendExtent(&op, 7, 3); |
174 | 207 |
175 DeltaDiffGenerator::SubstituteBlocks(&vertex, remove_blocks, replace_blocks); | 208 DeltaDiffGenerator::SubstituteBlocks(&vertex, remove_blocks, replace_blocks); |
176 | 209 |
177 EXPECT_EQ(7, op.src_extents_size()); | 210 EXPECT_EQ(7, op.src_extents_size()); |
178 EXPECT_EQ(11, op.src_extents(0).start_block()); | 211 EXPECT_EQ(11, op.src_extents(0).start_block()); |
179 EXPECT_EQ(1, op.src_extents(0).num_blocks()); | 212 EXPECT_EQ(1, op.src_extents(0).num_blocks()); |
180 EXPECT_EQ(13, op.src_extents(1).start_block()); | 213 EXPECT_EQ(13, op.src_extents(1).start_block()); |
181 EXPECT_EQ(1, op.src_extents(1).num_blocks()); | 214 EXPECT_EQ(1, op.src_extents(1).num_blocks()); |
182 EXPECT_EQ(6, op.src_extents(2).start_block()); | 215 EXPECT_EQ(6, op.src_extents(2).start_block()); |
183 EXPECT_EQ(1, op.src_extents(2).num_blocks()); | 216 EXPECT_EQ(1, op.src_extents(2).num_blocks()); |
184 EXPECT_EQ(kSparseHole, op.src_extents(3).start_block()); | 217 EXPECT_EQ(kSparseHole, op.src_extents(3).start_block()); |
185 EXPECT_EQ(4, op.src_extents(3).num_blocks()); | 218 EXPECT_EQ(4, op.src_extents(3).num_blocks()); |
186 EXPECT_EQ(10, op.src_extents(4).start_block()); | 219 EXPECT_EQ(10, op.src_extents(4).start_block()); |
187 EXPECT_EQ(1, op.src_extents(4).num_blocks()); | 220 EXPECT_EQ(1, op.src_extents(4).num_blocks()); |
188 EXPECT_EQ(14, op.src_extents(5).start_block()); | 221 EXPECT_EQ(14, op.src_extents(5).start_block()); |
189 EXPECT_EQ(1, op.src_extents(5).num_blocks()); | 222 EXPECT_EQ(1, op.src_extents(5).num_blocks()); |
190 EXPECT_EQ(8, op.src_extents(6).start_block()); | 223 EXPECT_EQ(8, op.src_extents(6).start_block()); |
191 EXPECT_EQ(2, op.src_extents(6).num_blocks()); | 224 EXPECT_EQ(2, op.src_extents(6).num_blocks()); |
192 } | 225 } |
193 | 226 |
194 TEST_F(DeltaDiffGeneratorTest, CutEdgesTest) { | 227 TEST_F(DeltaDiffGeneratorTest, CutEdgesTest) { |
195 Graph graph; | 228 Graph graph; |
196 vector<Block> blocks(9); | 229 vector<Block> blocks(9); |
197 | 230 |
198 // Create nodes in graph | 231 // Create nodes in graph |
199 { | 232 { |
200 graph.resize(graph.size() + 1); | 233 graph.resize(graph.size() + 1); |
201 graph.back().op.set_type(DeltaArchiveManifest_InstallOperation_Type_MOVE); | 234 graph.back().op.set_type(DeltaArchiveManifest_InstallOperation_Type_MOVE); |
202 // Reads from blocks 3, 5, 7 | 235 // Reads from blocks 3, 5, 7 |
203 vector<Extent> extents; | 236 vector<Extent> extents; |
204 graph_utils::AppendBlockToExtents(&extents, 3); | 237 graph_utils::AppendBlockToExtents(&extents, 3); |
205 graph_utils::AppendBlockToExtents(&extents, 5); | 238 graph_utils::AppendBlockToExtents(&extents, 5); |
206 graph_utils::AppendBlockToExtents(&extents, 7); | 239 graph_utils::AppendBlockToExtents(&extents, 7); |
207 DeltaDiffGenerator::StoreExtents(extents, | 240 DeltaDiffGenerator::StoreExtents(extents, |
208 graph.back().op.mutable_src_extents()); | 241 graph.back().op.mutable_src_extents()); |
209 blocks[3].reader = graph.size() - 1; | 242 blocks[3].reader = graph.size() - 1; |
210 blocks[5].reader = graph.size() - 1; | 243 blocks[5].reader = graph.size() - 1; |
211 blocks[7].reader = graph.size() - 1; | 244 blocks[7].reader = graph.size() - 1; |
212 | 245 |
213 // Writes to blocks 1, 2, 4 | 246 // Writes to blocks 1, 2, 4 |
214 extents.clear(); | 247 extents.clear(); |
215 graph_utils::AppendBlockToExtents(&extents, 1); | 248 graph_utils::AppendBlockToExtents(&extents, 1); |
216 graph_utils::AppendBlockToExtents(&extents, 2); | 249 graph_utils::AppendBlockToExtents(&extents, 2); |
217 graph_utils::AppendBlockToExtents(&extents, 4); | 250 graph_utils::AppendBlockToExtents(&extents, 4); |
218 DeltaDiffGenerator::StoreExtents(extents, | 251 DeltaDiffGenerator::StoreExtents(extents, |
219 graph.back().op.mutable_dst_extents()); | 252 graph.back().op.mutable_dst_extents()); |
220 blocks[1].writer = graph.size() - 1; | 253 blocks[1].writer = graph.size() - 1; |
221 blocks[2].writer = graph.size() - 1; | 254 blocks[2].writer = graph.size() - 1; |
222 blocks[4].writer = graph.size() - 1; | 255 blocks[4].writer = graph.size() - 1; |
223 } | 256 } |
224 { | 257 { |
225 graph.resize(graph.size() + 1); | 258 graph.resize(graph.size() + 1); |
226 graph.back().op.set_type(DeltaArchiveManifest_InstallOperation_Type_MOVE); | 259 graph.back().op.set_type(DeltaArchiveManifest_InstallOperation_Type_MOVE); |
227 // Reads from blocks 1, 2, 4 | 260 // Reads from blocks 1, 2, 4 |
228 vector<Extent> extents; | 261 vector<Extent> extents; |
229 graph_utils::AppendBlockToExtents(&extents, 1); | 262 graph_utils::AppendBlockToExtents(&extents, 1); |
230 graph_utils::AppendBlockToExtents(&extents, 2); | 263 graph_utils::AppendBlockToExtents(&extents, 2); |
231 graph_utils::AppendBlockToExtents(&extents, 4); | 264 graph_utils::AppendBlockToExtents(&extents, 4); |
232 DeltaDiffGenerator::StoreExtents(extents, | 265 DeltaDiffGenerator::StoreExtents(extents, |
233 graph.back().op.mutable_src_extents()); | 266 graph.back().op.mutable_src_extents()); |
234 blocks[1].reader = graph.size() - 1; | 267 blocks[1].reader = graph.size() - 1; |
235 blocks[2].reader = graph.size() - 1; | 268 blocks[2].reader = graph.size() - 1; |
236 blocks[4].reader = graph.size() - 1; | 269 blocks[4].reader = graph.size() - 1; |
237 | 270 |
238 // Writes to blocks 3, 5, 6 | 271 // Writes to blocks 3, 5, 6 |
239 extents.clear(); | 272 extents.clear(); |
240 graph_utils::AppendBlockToExtents(&extents, 3); | 273 graph_utils::AppendBlockToExtents(&extents, 3); |
241 graph_utils::AppendBlockToExtents(&extents, 5); | 274 graph_utils::AppendBlockToExtents(&extents, 5); |
242 graph_utils::AppendBlockToExtents(&extents, 6); | 275 graph_utils::AppendBlockToExtents(&extents, 6); |
243 DeltaDiffGenerator::StoreExtents(extents, | 276 DeltaDiffGenerator::StoreExtents(extents, |
244 graph.back().op.mutable_dst_extents()); | 277 graph.back().op.mutable_dst_extents()); |
245 blocks[3].writer = graph.size() - 1; | 278 blocks[3].writer = graph.size() - 1; |
246 blocks[5].writer = graph.size() - 1; | 279 blocks[5].writer = graph.size() - 1; |
247 blocks[6].writer = graph.size() - 1; | 280 blocks[6].writer = graph.size() - 1; |
248 } | 281 } |
249 | 282 |
250 // Create edges | 283 // Create edges |
251 DeltaDiffGenerator::CreateEdges(&graph, blocks); | 284 DeltaDiffGenerator::CreateEdges(&graph, blocks); |
252 | 285 |
253 // Find cycles | 286 // Find cycles |
254 CycleBreaker cycle_breaker; | 287 CycleBreaker cycle_breaker; |
255 set<Edge> cut_edges; | 288 set<Edge> cut_edges; |
256 cycle_breaker.BreakCycles(graph, &cut_edges); | 289 cycle_breaker.BreakCycles(graph, &cut_edges); |
257 | 290 |
258 EXPECT_EQ(1, cut_edges.size()); | 291 EXPECT_EQ(1, cut_edges.size()); |
259 EXPECT_TRUE(cut_edges.end() != cut_edges.find(make_pair<Vertex::Index>(1, | 292 EXPECT_TRUE(cut_edges.end() != cut_edges.find(make_pair<Vertex::Index>(1, |
260 0))); | 293 0))); |
261 | 294 |
262 vector<CutEdgeVertexes> cuts; | 295 vector<CutEdgeVertexes> cuts; |
263 EXPECT_TRUE(DeltaDiffGenerator::CutEdges(&graph, cut_edges, &cuts)); | 296 EXPECT_TRUE(DeltaDiffGenerator::CutEdges(&graph, cut_edges, &cuts)); |
264 | 297 |
265 EXPECT_EQ(3, graph.size()); | 298 EXPECT_EQ(3, graph.size()); |
266 | 299 |
267 // Check new node in graph: | 300 // Check new node in graph: |
268 EXPECT_EQ(DeltaArchiveManifest_InstallOperation_Type_MOVE, | 301 EXPECT_EQ(DeltaArchiveManifest_InstallOperation_Type_MOVE, |
269 graph.back().op.type()); | 302 graph.back().op.type()); |
270 EXPECT_EQ(2, graph.back().op.src_extents_size()); | 303 EXPECT_EQ(2, graph.back().op.src_extents_size()); |
271 EXPECT_EQ(1, graph.back().op.dst_extents_size()); | 304 EXPECT_EQ(1, graph.back().op.dst_extents_size()); |
272 EXPECT_EQ(kTempBlockStart, graph.back().op.dst_extents(0).start_block()); | 305 EXPECT_EQ(kTempBlockStart, graph.back().op.dst_extents(0).start_block()); |
273 EXPECT_EQ(2, graph.back().op.dst_extents(0).num_blocks()); | 306 EXPECT_EQ(2, graph.back().op.dst_extents(0).num_blocks()); |
274 EXPECT_TRUE(graph.back().out_edges.empty()); | 307 EXPECT_TRUE(graph.back().out_edges.empty()); |
275 | 308 |
276 // Check that old node reads from new blocks | 309 // Check that old node reads from new blocks |
277 EXPECT_EQ(2, graph[0].op.src_extents_size()); | 310 EXPECT_EQ(2, graph[0].op.src_extents_size()); |
278 EXPECT_EQ(kTempBlockStart, graph[0].op.src_extents(0).start_block()); | 311 EXPECT_EQ(kTempBlockStart, graph[0].op.src_extents(0).start_block()); |
279 EXPECT_EQ(2, graph[0].op.src_extents(0).num_blocks()); | 312 EXPECT_EQ(2, graph[0].op.src_extents(0).num_blocks()); |
280 EXPECT_EQ(7, graph[0].op.src_extents(1).start_block()); | 313 EXPECT_EQ(7, graph[0].op.src_extents(1).start_block()); |
281 EXPECT_EQ(1, graph[0].op.src_extents(1).num_blocks()); | 314 EXPECT_EQ(1, graph[0].op.src_extents(1).num_blocks()); |
282 | 315 |
283 // And that the old dst extents haven't changed | 316 // And that the old dst extents haven't changed |
284 EXPECT_EQ(2, graph[0].op.dst_extents_size()); | 317 EXPECT_EQ(2, graph[0].op.dst_extents_size()); |
285 EXPECT_EQ(1, graph[0].op.dst_extents(0).start_block()); | 318 EXPECT_EQ(1, graph[0].op.dst_extents(0).start_block()); |
(...skipping 12 matching lines...) Expand all Loading... |
298 EXPECT_EQ(1, graph[1].op.src_extents(0).start_block()); | 331 EXPECT_EQ(1, graph[1].op.src_extents(0).start_block()); |
299 EXPECT_EQ(2, graph[1].op.src_extents(0).num_blocks()); | 332 EXPECT_EQ(2, graph[1].op.src_extents(0).num_blocks()); |
300 EXPECT_EQ(4, graph[1].op.src_extents(1).start_block()); | 333 EXPECT_EQ(4, graph[1].op.src_extents(1).start_block()); |
301 EXPECT_EQ(1, graph[1].op.src_extents(1).num_blocks()); | 334 EXPECT_EQ(1, graph[1].op.src_extents(1).num_blocks()); |
302 | 335 |
303 EXPECT_EQ(2, graph[1].op.dst_extents_size()); | 336 EXPECT_EQ(2, graph[1].op.dst_extents_size()); |
304 EXPECT_EQ(3, graph[1].op.dst_extents(0).start_block()); | 337 EXPECT_EQ(3, graph[1].op.dst_extents(0).start_block()); |
305 EXPECT_EQ(1, graph[1].op.dst_extents(0).num_blocks()); | 338 EXPECT_EQ(1, graph[1].op.dst_extents(0).num_blocks()); |
306 EXPECT_EQ(5, graph[1].op.dst_extents(1).start_block()); | 339 EXPECT_EQ(5, graph[1].op.dst_extents(1).start_block()); |
307 EXPECT_EQ(2, graph[1].op.dst_extents(1).num_blocks()); | 340 EXPECT_EQ(2, graph[1].op.dst_extents(1).num_blocks()); |
308 | 341 |
309 // Ensure it only depends on the next node | 342 // Ensure it only depends on the next node |
310 EXPECT_EQ(1, graph[1].out_edges.size()); | 343 EXPECT_EQ(1, graph[1].out_edges.size()); |
311 EXPECT_TRUE(graph[1].out_edges.end() != graph[1].out_edges.find(2)); | 344 EXPECT_TRUE(graph[1].out_edges.end() != graph[1].out_edges.find(2)); |
312 } | 345 } |
313 | 346 |
314 TEST_F(DeltaDiffGeneratorTest, ReorderBlobsTest) { | 347 TEST_F(DeltaDiffGeneratorTest, ReorderBlobsTest) { |
315 string orig_blobs; | 348 string orig_blobs; |
316 EXPECT_TRUE( | 349 EXPECT_TRUE( |
317 utils::MakeTempFile("ReorderBlobsTest.orig.XXXXXX", &orig_blobs, NULL)); | 350 utils::MakeTempFile("ReorderBlobsTest.orig.XXXXXX", &orig_blobs, NULL)); |
318 | 351 |
319 string orig_data = "abcd"; | 352 string orig_data = "abcd"; |
320 EXPECT_TRUE( | 353 EXPECT_TRUE( |
321 utils::WriteFile(orig_blobs.c_str(), orig_data.data(), orig_data.size())); | 354 utils::WriteFile(orig_blobs.c_str(), orig_data.data(), orig_data.size())); |
322 | 355 |
323 string new_blobs; | 356 string new_blobs; |
324 EXPECT_TRUE( | 357 EXPECT_TRUE( |
325 utils::MakeTempFile("ReorderBlobsTest.new.XXXXXX", &new_blobs, NULL)); | 358 utils::MakeTempFile("ReorderBlobsTest.new.XXXXXX", &new_blobs, NULL)); |
326 | 359 |
327 DeltaArchiveManifest manifest; | 360 DeltaArchiveManifest manifest; |
328 DeltaArchiveManifest_InstallOperation* op = | 361 DeltaArchiveManifest_InstallOperation* op = |
329 manifest.add_install_operations(); | 362 manifest.add_install_operations(); |
330 op->set_data_offset(1); | 363 op->set_data_offset(1); |
331 op->set_data_length(3); | 364 op->set_data_length(3); |
332 op = manifest.add_install_operations(); | 365 op = manifest.add_install_operations(); |
333 op->set_data_offset(0); | 366 op->set_data_offset(0); |
334 op->set_data_length(1); | 367 op->set_data_length(1); |
335 | 368 |
336 EXPECT_TRUE(DeltaDiffGenerator::ReorderDataBlobs(&manifest, | 369 EXPECT_TRUE(DeltaDiffGenerator::ReorderDataBlobs(&manifest, |
337 orig_blobs, | 370 orig_blobs, |
338 new_blobs)); | 371 new_blobs)); |
339 | 372 |
340 string new_data; | 373 string new_data; |
341 EXPECT_TRUE(utils::ReadFileToString(new_blobs, &new_data)); | 374 EXPECT_TRUE(utils::ReadFileToString(new_blobs, &new_data)); |
342 EXPECT_EQ("bcda", new_data); | 375 EXPECT_EQ("bcda", new_data); |
343 EXPECT_EQ(2, manifest.install_operations_size()); | 376 EXPECT_EQ(2, manifest.install_operations_size()); |
344 EXPECT_EQ(0, manifest.install_operations(0).data_offset()); | 377 EXPECT_EQ(0, manifest.install_operations(0).data_offset()); |
345 EXPECT_EQ(3, manifest.install_operations(0).data_length()); | 378 EXPECT_EQ(3, manifest.install_operations(0).data_length()); |
346 EXPECT_EQ(3, manifest.install_operations(1).data_offset()); | 379 EXPECT_EQ(3, manifest.install_operations(1).data_offset()); |
347 EXPECT_EQ(1, manifest.install_operations(1).data_length()); | 380 EXPECT_EQ(1, manifest.install_operations(1).data_length()); |
348 | 381 |
349 unlink(orig_blobs.c_str()); | 382 unlink(orig_blobs.c_str()); |
350 unlink(new_blobs.c_str()); | 383 unlink(new_blobs.c_str()); |
351 } | 384 } |
352 | 385 |
353 TEST_F(DeltaDiffGeneratorTest, MoveFullOpsToBackTest) { | 386 TEST_F(DeltaDiffGeneratorTest, MoveFullOpsToBackTest) { |
354 Graph graph(4); | 387 Graph graph(4); |
355 graph[0].file_name = "A"; | 388 graph[0].file_name = "A"; |
356 graph[0].op.set_type(DeltaArchiveManifest_InstallOperation_Type_REPLACE); | 389 graph[0].op.set_type(DeltaArchiveManifest_InstallOperation_Type_REPLACE); |
357 graph[1].file_name = "B"; | 390 graph[1].file_name = "B"; |
358 graph[1].op.set_type(DeltaArchiveManifest_InstallOperation_Type_BSDIFF); | 391 graph[1].op.set_type(DeltaArchiveManifest_InstallOperation_Type_BSDIFF); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 } | 450 } |
418 LOG(INFO) << "{" << ss.str() << "}"; | 451 LOG(INFO) << "{" << ss.str() << "}"; |
419 } | 452 } |
420 | 453 |
421 } // namespace {} | 454 } // namespace {} |
422 | 455 |
423 TEST_F(DeltaDiffGeneratorTest, RunAsRootAssignTempBlocksTest) { | 456 TEST_F(DeltaDiffGeneratorTest, RunAsRootAssignTempBlocksTest) { |
424 Graph graph(9); | 457 Graph graph(9); |
425 const vector<Extent> empt; // empty | 458 const vector<Extent> empt; // empty |
426 const string kFilename = "/foo"; | 459 const string kFilename = "/foo"; |
427 | 460 |
428 // Some scratch space: | 461 // Some scratch space: |
429 GenVertex(&graph[0], empt, VectOfExt(200, 1), "", OP_REPLACE); | 462 GenVertex(&graph[0], empt, VectOfExt(200, 1), "", OP_REPLACE); |
430 GenVertex(&graph[1], empt, VectOfExt(210, 10), "", OP_REPLACE); | 463 GenVertex(&graph[1], empt, VectOfExt(210, 10), "", OP_REPLACE); |
431 GenVertex(&graph[2], empt, VectOfExt(220, 1), "", OP_REPLACE); | 464 GenVertex(&graph[2], empt, VectOfExt(220, 1), "", OP_REPLACE); |
432 | 465 |
433 // A cycle that requires 10 blocks to break: | 466 // A cycle that requires 10 blocks to break: |
434 GenVertex(&graph[3], VectOfExt(10, 11), VectOfExt(0, 9), "", OP_BSDIFF); | 467 GenVertex(&graph[3], VectOfExt(10, 11), VectOfExt(0, 9), "", OP_BSDIFF); |
435 graph[3].out_edges[4] = EdgeWithReadDep(VectOfExt(0, 9)); | 468 graph[3].out_edges[4] = EdgeWithReadDep(VectOfExt(0, 9)); |
436 GenVertex(&graph[4], VectOfExt(0, 9), VectOfExt(10, 11), "", OP_BSDIFF); | 469 GenVertex(&graph[4], VectOfExt(0, 9), VectOfExt(10, 11), "", OP_BSDIFF); |
437 graph[4].out_edges[3] = EdgeWithReadDep(VectOfExt(10, 11)); | 470 graph[4].out_edges[3] = EdgeWithReadDep(VectOfExt(10, 11)); |
(...skipping 10 matching lines...) Expand all Loading... |
448 VectOfExt(60, 40), | 481 VectOfExt(60, 40), |
449 "", | 482 "", |
450 OP_BSDIFF); | 483 OP_BSDIFF); |
451 graph[7].out_edges[8] = EdgeWithReadDep(VectOfExt(60, 40)); | 484 graph[7].out_edges[8] = EdgeWithReadDep(VectOfExt(60, 40)); |
452 GenVertex(&graph[8], | 485 GenVertex(&graph[8], |
453 VectOfExt(60, 40), | 486 VectOfExt(60, 40), |
454 VectOfExt(120, 50), | 487 VectOfExt(120, 50), |
455 kFilename, | 488 kFilename, |
456 OP_BSDIFF); | 489 OP_BSDIFF); |
457 graph[8].out_edges[7] = EdgeWithReadDep(VectOfExt(120, 50)); | 490 graph[8].out_edges[7] = EdgeWithReadDep(VectOfExt(120, 50)); |
458 | 491 |
459 graph_utils::DumpGraph(graph); | 492 graph_utils::DumpGraph(graph); |
460 | 493 |
461 vector<Vertex::Index> final_order; | 494 vector<Vertex::Index> final_order; |
462 | 495 |
463 | 496 |
464 // Prepare the filesystem with the minimum required for this to work | 497 // Prepare the filesystem with the minimum required for this to work |
465 string temp_dir; | 498 string temp_dir; |
466 EXPECT_TRUE(utils::MakeTempDirectory("/tmp/AssignTempBlocksTest.XXXXXX", | 499 EXPECT_TRUE(utils::MakeTempDirectory("/tmp/AssignTempBlocksTest.XXXXXX", |
467 &temp_dir)); | 500 &temp_dir)); |
468 ScopedDirRemover temp_dir_remover(temp_dir); | 501 ScopedDirRemover temp_dir_remover(temp_dir); |
469 | 502 |
470 const size_t kBlockSize = 4096; | 503 const size_t kBlockSize = 4096; |
471 vector<char> temp_data(kBlockSize * 50); | 504 vector<char> temp_data(kBlockSize * 50); |
472 FillWithData(&temp_data); | 505 FillWithData(&temp_data); |
473 EXPECT_TRUE(WriteFileVector(temp_dir + kFilename, temp_data)); | 506 EXPECT_TRUE(WriteFileVector(temp_dir + kFilename, temp_data)); |
474 ScopedPathUnlinker filename_unlinker(temp_dir + kFilename); | 507 ScopedPathUnlinker filename_unlinker(temp_dir + kFilename); |
475 | 508 |
476 int fd; | 509 int fd; |
477 EXPECT_TRUE(utils::MakeTempFile("/tmp/AssignTempBlocksTestData.XXXXXX", | 510 EXPECT_TRUE(utils::MakeTempFile("/tmp/AssignTempBlocksTestData.XXXXXX", |
478 NULL, | 511 NULL, |
479 &fd)); | 512 &fd)); |
480 ScopedFdCloser fd_closer(&fd); | 513 ScopedFdCloser fd_closer(&fd); |
481 off_t data_file_size = 0; | 514 off_t data_file_size = 0; |
482 | 515 |
483 | 516 |
484 EXPECT_TRUE(DeltaDiffGenerator::ConvertGraphToDag(&graph, | 517 EXPECT_TRUE(DeltaDiffGenerator::ConvertGraphToDag(&graph, |
485 temp_dir, | 518 temp_dir, |
486 fd, | 519 fd, |
487 &data_file_size, | 520 &data_file_size, |
488 &final_order)); | 521 &final_order)); |
489 | 522 |
490 | 523 |
491 Graph expected_graph(12); | 524 Graph expected_graph(12); |
492 GenVertex(&expected_graph[0], empt, VectOfExt(200, 1), "", OP_REPLACE); | 525 GenVertex(&expected_graph[0], empt, VectOfExt(200, 1), "", OP_REPLACE); |
493 GenVertex(&expected_graph[1], empt, VectOfExt(210, 10), "", OP_REPLACE); | 526 GenVertex(&expected_graph[1], empt, VectOfExt(210, 10), "", OP_REPLACE); |
494 GenVertex(&expected_graph[2], empt, VectOfExt(220, 1), "", OP_REPLACE); | 527 GenVertex(&expected_graph[2], empt, VectOfExt(220, 1), "", OP_REPLACE); |
495 GenVertex(&expected_graph[3], | 528 GenVertex(&expected_graph[3], |
496 VectOfExt(10, 11), | 529 VectOfExt(10, 11), |
497 VectOfExt(0, 9), | 530 VectOfExt(0, 9), |
498 "", | 531 "", |
499 OP_BSDIFF); | 532 OP_BSDIFF); |
500 expected_graph[3].out_edges[9] = EdgeWithReadDep(VectOfExt(0, 9)); | 533 expected_graph[3].out_edges[9] = EdgeWithReadDep(VectOfExt(0, 9)); |
(...skipping 11 matching lines...) Expand all Loading... |
512 OP_BSDIFF); | 545 OP_BSDIFF); |
513 expected_graph[5].out_edges[10] = EdgeWithReadDep(VectOfExt(30, 10)); | 546 expected_graph[5].out_edges[10] = EdgeWithReadDep(VectOfExt(30, 10)); |
514 | 547 |
515 GenVertex(&expected_graph[6], | 548 GenVertex(&expected_graph[6], |
516 VectOfExt(60, 10), | 549 VectOfExt(60, 10), |
517 VectOfExt(40, 11), | 550 VectOfExt(40, 11), |
518 "", | 551 "", |
519 OP_BSDIFF); | 552 OP_BSDIFF); |
520 expected_graph[6].out_edges[5] = EdgeWithReadDep(VectOfExt(40, 11)); | 553 expected_graph[6].out_edges[5] = EdgeWithReadDep(VectOfExt(40, 11)); |
521 expected_graph[6].out_edges[10] = EdgeWithWriteDep(VectOfExt(60, 10)); | 554 expected_graph[6].out_edges[10] = EdgeWithWriteDep(VectOfExt(60, 10)); |
522 | 555 |
523 GenVertex(&expected_graph[7], | 556 GenVertex(&expected_graph[7], |
524 VectOfExt(120, 50), | 557 VectOfExt(120, 50), |
525 VectOfExt(60, 40), | 558 VectOfExt(60, 40), |
526 "", | 559 "", |
527 OP_BSDIFF); | 560 OP_BSDIFF); |
528 expected_graph[7].out_edges[6] = EdgeWithReadDep(VectOfExt(60, 10)); | 561 expected_graph[7].out_edges[6] = EdgeWithReadDep(VectOfExt(60, 10)); |
529 | 562 |
530 GenVertex(&expected_graph[8], empt, VectOfExt(0, 50), "/foo", OP_REPLACE_BZ); | 563 GenVertex(&expected_graph[8], empt, VectOfExt(0, 50), "/foo", OP_REPLACE_BZ); |
531 expected_graph[8].out_edges[7] = EdgeWithReadDep(VectOfExt(120, 50)); | 564 expected_graph[8].out_edges[7] = EdgeWithReadDep(VectOfExt(120, 50)); |
532 | 565 |
533 GenVertex(&expected_graph[9], | 566 GenVertex(&expected_graph[9], |
534 VectOfExt(0, 9), | 567 VectOfExt(0, 9), |
535 VectOfExt(60, 9), | 568 VectOfExt(60, 9), |
536 "", | 569 "", |
537 OP_MOVE); | 570 OP_MOVE); |
538 | 571 |
539 GenVertex(&expected_graph[10], | 572 GenVertex(&expected_graph[10], |
540 VectOfExt(30, 10), | 573 VectOfExt(30, 10), |
541 VectOfExt(60, 10), | 574 VectOfExt(60, 10), |
542 "", | 575 "", |
543 OP_MOVE); | 576 OP_MOVE); |
544 expected_graph[10].out_edges[4] = EdgeWithReadDep(VectOfExt(60, 9)); | 577 expected_graph[10].out_edges[4] = EdgeWithReadDep(VectOfExt(60, 9)); |
545 | 578 |
546 EXPECT_EQ(12, graph.size()); | 579 EXPECT_EQ(12, graph.size()); |
547 EXPECT_FALSE(graph.back().valid); | 580 EXPECT_FALSE(graph.back().valid); |
548 for (Graph::size_type i = 0; i < graph.size() - 1; i++) { | 581 for (Graph::size_type i = 0; i < graph.size() - 1; i++) { |
549 EXPECT_TRUE(graph[i].out_edges == expected_graph[i].out_edges); | 582 EXPECT_TRUE(graph[i].out_edges == expected_graph[i].out_edges); |
550 if (i == 8) { | 583 if (i == 8) { |
551 // special case | 584 // special case |
552 } else { | 585 } else { |
553 // EXPECT_TRUE(graph[i] == expected_graph[i]) << "i = " << i; | 586 // EXPECT_TRUE(graph[i] == expected_graph[i]) << "i = " << i; |
554 } | 587 } |
555 } | 588 } |
556 } | 589 } |
557 | 590 |
558 } // namespace chromeos_update_engine | 591 } // namespace chromeos_update_engine |
OLD | NEW |