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

Side by Side Diff: delta_diff_generator_unittest.cc

Issue 3997007: AU: fix delta generation when running out of scratch. (Closed) Base URL: http://git.chromium.org/git/update_engine.git
Patch Set: 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 | Annotate | Revision Log
« delta_diff_generator.cc ('K') | « delta_diff_generator.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) 2010 The Chromium OS 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>
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 out->op.set_type(type); 422 out->op.set_type(type);
423 out->file_name = path; 423 out->file_name = path;
424 DeltaDiffGenerator::StoreExtents(src_extents, out->op.mutable_src_extents()); 424 DeltaDiffGenerator::StoreExtents(src_extents, out->op.mutable_src_extents());
425 DeltaDiffGenerator::StoreExtents(dst_extents, out->op.mutable_dst_extents()); 425 DeltaDiffGenerator::StoreExtents(dst_extents, out->op.mutable_dst_extents());
426 } 426 }
427 427
428 vector<Extent> VectOfExt(uint64_t start_block, uint64_t num_blocks) { 428 vector<Extent> VectOfExt(uint64_t start_block, uint64_t num_blocks) {
429 return vector<Extent>(1, ExtentForRange(start_block, num_blocks)); 429 return vector<Extent>(1, ExtentForRange(start_block, num_blocks));
430 } 430 }
431 431
432 vector<Extent> VectOfExts(uint64_t start_block1, uint64_t num_blocks1,
433 uint64_t start_block2, uint64_t num_blocks2) {
434 vector<Extent> ret(1, ExtentForRange(start_block1, num_blocks1));
435 ret.push_back(ExtentForRange(start_block2, num_blocks2));
436 return ret;
437 }
438
432 EdgeProperties EdgeWithReadDep(const vector<Extent>& extents) { 439 EdgeProperties EdgeWithReadDep(const vector<Extent>& extents) {
433 EdgeProperties ret; 440 EdgeProperties ret;
434 ret.extents = extents; 441 ret.extents = extents;
435 return ret; 442 return ret;
436 } 443 }
437 444
438 EdgeProperties EdgeWithWriteDep(const vector<Extent>& extents) { 445 EdgeProperties EdgeWithWriteDep(const vector<Extent>& extents) {
439 EdgeProperties ret; 446 EdgeProperties ret;
440 ret.write_extents = extents; 447 ret.write_extents = extents;
441 return ret; 448 return ret;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 EXPECT_TRUE(DeltaDiffGenerator::IsNoopOperation(op)); 613 EXPECT_TRUE(DeltaDiffGenerator::IsNoopOperation(op));
607 *(op.add_src_extents()) = ExtentForRange(kSparseHole, 2); 614 *(op.add_src_extents()) = ExtentForRange(kSparseHole, 2);
608 *(op.add_src_extents()) = ExtentForRange(kSparseHole, 1); 615 *(op.add_src_extents()) = ExtentForRange(kSparseHole, 1);
609 *(op.add_dst_extents()) = ExtentForRange(kSparseHole, 3); 616 *(op.add_dst_extents()) = ExtentForRange(kSparseHole, 3);
610 EXPECT_TRUE(DeltaDiffGenerator::IsNoopOperation(op)); 617 EXPECT_TRUE(DeltaDiffGenerator::IsNoopOperation(op));
611 *(op.add_src_extents()) = ExtentForRange(24, 1); 618 *(op.add_src_extents()) = ExtentForRange(24, 1);
612 *(op.add_dst_extents()) = ExtentForRange(25, 1); 619 *(op.add_dst_extents()) = ExtentForRange(25, 1);
613 EXPECT_FALSE(DeltaDiffGenerator::IsNoopOperation(op)); 620 EXPECT_FALSE(DeltaDiffGenerator::IsNoopOperation(op));
614 } 621 }
615 622
623 TEST_F(DeltaDiffGeneratorTest, RunAsRootAssignTempBlocksReuseTest) {
624 // AssignTempBlocks(Graph* graph,
625 // const string& new_root,
626 // int data_fd,
627 // off_t* data_file_size,
628 // vector<Vertex::Index>* op_indexes,
629 // vector<vector<Vertex::Index>::size_type>* reverse_op_indexes,
630 // const vector<CutEdgeVertexes>& cuts
631 Graph graph(9);
632
633 const vector<Extent> empt;
634 uint64_t tmp = kTempBlockStart;
635 const string kFilename = "/foo";
636
637 vector<CutEdgeVertexes> cuts;
638 cuts.resize(3);
639
640 // Simple broken loop:
641 GenVertex(&graph[0], VectOfExt(0, 1), VectOfExt(1, 1), "", OP_MOVE);
642 GenVertex(&graph[1], VectOfExt(tmp, 1), VectOfExt(0, 1), "", OP_MOVE);
643 GenVertex(&graph[2], VectOfExt(1, 1), VectOfExt(tmp, 1), "", OP_MOVE);
644 // Corresponding edges:
645 graph[0].out_edges[2] = EdgeWithReadDep(VectOfExt(1, 1));
646 graph[1].out_edges[2] = EdgeWithWriteDep(VectOfExt(tmp, 1));
647 graph[1].out_edges[0] = EdgeWithReadDep(VectOfExt(0, 1));
648 // Store the cut:
649 cuts[0].old_dst = 1;
650 cuts[0].old_src = 0;
651 cuts[0].new_vertex = 2;
652 cuts[0].tmp_extents = VectOfExt(tmp, 1);
653 tmp++;
654
655 // Slightly more complex pair of loops:
656 GenVertex(&graph[3], VectOfExt(4, 2), VectOfExt(2, 2), "", OP_MOVE);
657 GenVertex(&graph[4], VectOfExt(6, 1), VectOfExt(7, 1), "", OP_MOVE);
658 GenVertex(&graph[5], VectOfExt(tmp, 3), VectOfExt(4, 3), kFilename, OP_MOVE);
659 GenVertex(&graph[6], VectOfExt(2, 2), VectOfExt(tmp, 2), "", OP_MOVE);
660 GenVertex(&graph[7], VectOfExt(7, 1), VectOfExt(tmp + 2, 1), "", OP_MOVE);
661 // Corresponding edges:
662 graph[3].out_edges[6] = EdgeWithReadDep(VectOfExt(2, 2));
663 graph[4].out_edges[7] = EdgeWithReadDep(VectOfExt(7, 1));
664 graph[5].out_edges[6] = EdgeWithWriteDep(VectOfExt(tmp, 2));
665 graph[5].out_edges[7] = EdgeWithWriteDep(VectOfExt(tmp + 2, 1));
666 graph[5].out_edges[3] = EdgeWithReadDep(VectOfExt(4, 2));
667 graph[5].out_edges[4] = EdgeWithReadDep(VectOfExt(6, 1));
668 // Store the cuts:
669 cuts[1].old_dst = 5;
670 cuts[1].old_src = 3;
671 cuts[1].new_vertex = 6;
672 cuts[1].tmp_extents = VectOfExt(tmp, 2);
673 cuts[2].old_dst = 5;
674 cuts[2].old_src = 4;
675 cuts[2].new_vertex = 7;
676 cuts[2].tmp_extents = VectOfExt(tmp + 2, 1);
677
678 // Supplier of temp block:
679 GenVertex(&graph[8], empt, VectOfExt(8, 1), "", OP_REPLACE);
680
681 // Specify the final order:
682 vector<Vertex::Index> op_indexes;
683 op_indexes.push_back(2);
684 op_indexes.push_back(0);
685 op_indexes.push_back(1);
686 op_indexes.push_back(6);
687 op_indexes.push_back(3);
688 op_indexes.push_back(7);
689 op_indexes.push_back(4);
690 op_indexes.push_back(5);
691 op_indexes.push_back(8);
692
693 vector<vector<Vertex::Index>::size_type> reverse_op_indexes;
694 DeltaDiffGenerator::GenerateReverseTopoOrderMap(op_indexes,
695 &reverse_op_indexes);
696
697 // Prepare the filesystem with the minimum required for this to work
698 string temp_dir;
699 EXPECT_TRUE(utils::MakeTempDirectory("/tmp/AssignTempBlocksReuseTest.XXXXXX",
700 &temp_dir));
701 ScopedDirRemover temp_dir_remover(temp_dir);
702
703 const size_t kBlockSize = 4096;
704 vector<char> temp_data(kBlockSize * 3);
705 FillWithData(&temp_data);
706 EXPECT_TRUE(WriteFileVector(temp_dir + kFilename, temp_data));
707 ScopedPathUnlinker filename_unlinker(temp_dir + kFilename);
708
709 int fd;
710 EXPECT_TRUE(utils::MakeTempFile("/tmp/AssignTempBlocksReuseTest.XXXXXX",
711 NULL,
712 &fd));
713 ScopedFdCloser fd_closer(&fd);
714 off_t data_file_size = 0;
715
716 EXPECT_TRUE(DeltaDiffGenerator::AssignTempBlocks(&graph,
717 temp_dir,
718 fd,
719 &data_file_size,
720 &op_indexes,
721 &reverse_op_indexes,
722 cuts));
723 EXPECT_FALSE(graph[6].valid);
724 EXPECT_FALSE(graph[7].valid);
725 EXPECT_EQ(1, graph[1].op.src_extents_size());
726 EXPECT_EQ(2, graph[1].op.src_extents(0).start_block());
727 EXPECT_EQ(1, graph[1].op.src_extents(0).num_blocks());
728 EXPECT_EQ(OP_REPLACE_BZ, graph[5].op.type());
729 }
730
616 } // namespace chromeos_update_engine 731 } // namespace chromeos_update_engine
OLDNEW
« delta_diff_generator.cc ('K') | « delta_diff_generator.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698