OLD | NEW |
---|---|
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 <gtest/gtest.h> | |
petkov
2010/12/10 00:46:55
style is as below, with blank lines between groups
thieule
2010/12/14 23:11:21
Done.
| |
9 #include <set> | 10 #include <set> |
10 #include <sstream> | 11 #include <sstream> |
11 #include <string> | 12 #include <string> |
12 #include <utility> | 13 #include <utility> |
13 #include <vector> | 14 #include <vector> |
14 #include <gtest/gtest.h> | |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/string_util.h" | |
16 #include "update_engine/cycle_breaker.h" | 17 #include "update_engine/cycle_breaker.h" |
17 #include "update_engine/delta_diff_generator.h" | 18 #include "update_engine/delta_diff_generator.h" |
18 #include "update_engine/delta_performer.h" | 19 #include "update_engine/delta_performer.h" |
19 #include "update_engine/extent_ranges.h" | 20 #include "update_engine/extent_ranges.h" |
20 #include "update_engine/graph_types.h" | 21 #include "update_engine/graph_types.h" |
21 #include "update_engine/graph_utils.h" | 22 #include "update_engine/graph_utils.h" |
22 #include "update_engine/subprocess.h" | 23 #include "update_engine/subprocess.h" |
23 #include "update_engine/test_utils.h" | 24 #include "update_engine/test_utils.h" |
24 #include "update_engine/topological_sort.h" | 25 #include "update_engine/topological_sort.h" |
25 #include "update_engine/utils.h" | 26 #include "update_engine/utils.h" |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
722 &reverse_op_indexes, | 723 &reverse_op_indexes, |
723 cuts)); | 724 cuts)); |
724 EXPECT_FALSE(graph[6].valid); | 725 EXPECT_FALSE(graph[6].valid); |
725 EXPECT_FALSE(graph[7].valid); | 726 EXPECT_FALSE(graph[7].valid); |
726 EXPECT_EQ(1, graph[1].op.src_extents_size()); | 727 EXPECT_EQ(1, graph[1].op.src_extents_size()); |
727 EXPECT_EQ(2, graph[1].op.src_extents(0).start_block()); | 728 EXPECT_EQ(2, graph[1].op.src_extents(0).start_block()); |
728 EXPECT_EQ(1, graph[1].op.src_extents(0).num_blocks()); | 729 EXPECT_EQ(1, graph[1].op.src_extents(0).num_blocks()); |
729 EXPECT_EQ(OP_REPLACE_BZ, graph[5].op.type()); | 730 EXPECT_EQ(OP_REPLACE_BZ, graph[5].op.type()); |
730 } | 731 } |
731 | 732 |
733 TEST_F(DeltaDiffGeneratorTest, RunAsRootReadMetadataDissimilarFileSystems) { | |
734 string a_img, b_img; | |
735 EXPECT_TRUE(utils::MakeTempFile("/tmp/a_img.XXXXXX", &a_img, NULL)); | |
736 ScopedPathUnlinker a_img_unlinker(a_img); | |
737 EXPECT_TRUE(utils::MakeTempFile("/tmp/b_img.XXXXXX", &b_img, NULL)); | |
738 ScopedPathUnlinker b_img_unlinker(b_img); | |
739 | |
740 CreateEmptyExtImageAtPath(a_img, 10485759, 4096); | |
741 CreateEmptyExtImageAtPath(b_img, 11534336, 4096); | |
742 | |
743 Graph graph; | |
744 vector<Block> blocks; | |
745 EXPECT_TRUE(DeltaDiffGenerator::DeltaReadMetadata(&graph, | |
746 &blocks, | |
747 a_img, | |
748 b_img, | |
749 0, | |
750 NULL)); | |
751 EXPECT_EQ(graph.size(), 0); | |
752 | |
753 CreateEmptyExtImageAtPath(a_img, 10485759, 4096); | |
754 CreateEmptyExtImageAtPath(b_img, 10485759, 8192); | |
755 | |
756 graph.clear(); | |
757 blocks.clear(); | |
758 EXPECT_TRUE(DeltaDiffGenerator::DeltaReadMetadata(&graph, | |
759 &blocks, | |
760 a_img, | |
761 b_img, | |
762 0, | |
763 NULL)); | |
764 EXPECT_EQ(graph.size(), 0); | |
765 } | |
766 | |
767 TEST_F(DeltaDiffGeneratorTest, RunAsRootReadMetadata) { | |
768 string a_img, b_img, data_file; | |
769 EXPECT_TRUE(utils::MakeTempFile("/tmp/a_img.XXXXXX", &a_img, NULL)); | |
770 ScopedPathUnlinker a_img_unlinker(a_img); | |
771 EXPECT_TRUE(utils::MakeTempFile("/tmp/b_img.XXXXXX", &b_img, NULL)); | |
772 ScopedPathUnlinker b_img_unlinker(b_img); | |
773 EXPECT_TRUE(utils::MakeTempFile("/tmp/data_file.XXXXXX", &data_file, NULL)); | |
774 ScopedPathUnlinker data_file_unlinker(data_file); | |
775 | |
776 const size_t image_size = (256 * 1024 * 1024); // Enough for 2 block groups | |
777 const int block_size = 4096; | |
778 CreateEmptyExtImageAtPath(a_img, image_size, block_size); | |
779 | |
780 // Create a file large enough to create an indirect block | |
781 { | |
782 string a_img_mnt; | |
783 ScopedLoopMounter a_img_mount(a_img, &a_img_mnt, 0); | |
784 System(StringPrintf("dd if=/dev/zero of=%s/test_file bs=%d count=%d", | |
785 a_img_mnt.c_str(), block_size, EXT2_NDIR_BLOCKS + 1)); | |
786 } | |
787 | |
788 System(StringPrintf("cp %s %s", a_img.c_str(), b_img.c_str())); | |
789 | |
790 int fd = open(data_file.c_str(), O_RDWR | O_CREAT, S_IRWXU); | |
791 EXPECT_NE(fd, -1); | |
792 ScopedFdCloser fd_closer(&fd); | |
793 | |
794 Graph graph; | |
795 vector<Block> blocks(image_size / block_size); | |
796 off_t data_file_size; | |
797 EXPECT_TRUE(DeltaDiffGenerator::DeltaReadMetadata(&graph, | |
798 &blocks, | |
799 a_img, | |
800 b_img, | |
801 fd, | |
802 &data_file_size)); | |
803 | |
804 // There are 12 metadata that we look for: | |
805 // - Block group 0 metadata (superblock, group descriptor, bitmaps, etc) | |
806 // - Chunk 0, 1, 2, 3 | |
807 // - Block group 1 metadata | |
808 // - Chunk 0, 1, 2, 3 | |
809 // - Root directory (inode 2) | |
810 // - Journal (inode 8) | |
811 // - lost+found directory (inode 11) | |
812 // - test_file indirect block (inode 12) | |
813 struct { | |
814 string metadata_name; | |
815 off_t start_block; // Set to -1 to skip start block verification | |
816 off_t num_blocks; // Set to -1 to skip num blocks verification | |
817 } exp_results[] = | |
818 {{"<rootfs-bg-0-0-metadata>", 0, 260}, | |
819 {"<rootfs-bg-0-1-metadata>", 260, 260}, | |
820 {"<rootfs-bg-0-2-metadata>", 520, 260}, | |
821 {"<rootfs-bg-0-3-metadata>", 780, 263}, | |
822 {"<rootfs-bg-1-0-metadata>", 32768, 260}, | |
823 {"<rootfs-bg-1-1-metadata>", 33028, 260}, | |
824 {"<rootfs-bg-1-2-metadata>", 33288, 260}, | |
825 {"<rootfs-bg-1-3-metadata>", 33548, 263}, | |
826 {"<rootfs-inode-2-metadata>", -1, 1}, | |
827 {"<rootfs-inode-8-metadata>", -1, 4101}, | |
828 {"<rootfs-inode-11-metadata>", -1, 4}, | |
829 {"<rootfs-inode-12-metadata>", -1, 1}}; | |
830 | |
831 int num_exp_results = sizeof(exp_results) / sizeof(exp_results[0]); | |
832 EXPECT_EQ(graph.size(), num_exp_results); | |
833 | |
834 for (int i = 0; i < num_exp_results; i++) { | |
835 Vertex& vertex = graph[i]; | |
836 DeltaArchiveManifest_InstallOperation& op = vertex.op; | |
837 | |
838 EXPECT_STRCASEEQ(vertex.file_name.c_str(), | |
839 exp_results[i].metadata_name.c_str()); | |
840 | |
841 EXPECT_EQ(op.src_extents().size(), op.dst_extents().size()); | |
842 for (int e = 0; e < op.src_extents().size(); e++) { | |
843 EXPECT_EQ(op.src_extents(e).start_block(), | |
844 op.dst_extents(e).start_block()); | |
845 EXPECT_EQ(op.src_extents(e).num_blocks(), | |
846 op.dst_extents(e).num_blocks()); | |
847 } | |
848 | |
849 if (exp_results[i].start_block != -1) { | |
850 EXPECT_EQ(op.src_extents(0).start_block(), exp_results[i].start_block); | |
851 } | |
852 | |
853 if (exp_results[i].num_blocks != -1) { | |
854 EXPECT_EQ(op.src_extents(0).num_blocks(), exp_results[i].num_blocks); | |
855 } | |
856 } | |
857 } | |
858 | |
732 TEST_F(DeltaDiffGeneratorTest, CreateScratchNodeTest) { | 859 TEST_F(DeltaDiffGeneratorTest, CreateScratchNodeTest) { |
733 Vertex vertex; | 860 Vertex vertex; |
734 DeltaDiffGenerator::CreateScratchNode(12, 34, &vertex); | 861 DeltaDiffGenerator::CreateScratchNode(12, 34, &vertex); |
735 EXPECT_EQ(DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ, | 862 EXPECT_EQ(DeltaArchiveManifest_InstallOperation_Type_REPLACE_BZ, |
736 vertex.op.type()); | 863 vertex.op.type()); |
737 EXPECT_EQ(0, vertex.op.data_offset()); | 864 EXPECT_EQ(0, vertex.op.data_offset()); |
738 EXPECT_EQ(0, vertex.op.data_length()); | 865 EXPECT_EQ(0, vertex.op.data_length()); |
739 EXPECT_EQ(1, vertex.op.dst_extents_size()); | 866 EXPECT_EQ(1, vertex.op.dst_extents_size()); |
740 EXPECT_EQ(12, vertex.op.dst_extents(0).start_block()); | 867 EXPECT_EQ(12, vertex.op.dst_extents(0).start_block()); |
741 EXPECT_EQ(34, vertex.op.dst_extents(0).num_blocks()); | 868 EXPECT_EQ(34, vertex.op.dst_extents(0).num_blocks()); |
742 } | 869 } |
743 | 870 |
744 } // namespace chromeos_update_engine | 871 } // namespace chromeos_update_engine |
OLD | NEW |