aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTianjie Xu2018-02-22 17:40:39 -0600
committerTianjie Xu2018-02-23 12:44:05 -0600
commit572abbb81cfa12cddf742fa35cd8a4b9eebdc7d1 (patch)
treeacef858937e69879b8d122c2d20834347c095e3f /tests
parentbf52b7e00b63397d9c81b7f7ffa7a8b8799edd4a (diff)
downloadplatform-bootable-recovery-572abbb81cfa12cddf742fa35cd8a4b9eebdc7d1.tar.gz
platform-bootable-recovery-572abbb81cfa12cddf742fa35cd8a4b9eebdc7d1.tar.xz
platform-bootable-recovery-572abbb81cfa12cddf742fa35cd8a4b9eebdc7d1.zip
Remove the assumption of target chunk size in imgdiff
In the split mode of imgdiff, we used to assume that the size of a split target chunk is always greater than the blocksize i.e. 4096. This may lead to the following assertion failure: I0221 04:57:33.451323 818464 common.py:205 imgdiff F 02-21 04:57:33 821203 821203 imgdiff.cpp:999] Check failed: tgt_size >= BLOCK_SIZE (tgt_size=476, BLOCK_SIZE=4096) This CL removes the assumption and handles the edge cases. Test: generate and verify the incremental update for TFs in the bug; unit test passes Bug: 73757557 Bug: 73711365 Change-Id: Iadbb4ee658995f5856cd488f3793980881a59620
Diffstat (limited to 'tests')
-rw-r--r--tests/component/imgdiff_test.cpp101
1 files changed, 101 insertions, 0 deletions
diff --git a/tests/component/imgdiff_test.cpp b/tests/component/imgdiff_test.cpp
index 728b6cc7..6c23def0 100644
--- a/tests/component/imgdiff_test.cpp
+++ b/tests/component/imgdiff_test.cpp
@@ -969,3 +969,104 @@ TEST(ImgdiffTest, zip_mode_large_enough_limit) {
969 // Expect 1 piece of patch since limit is larger than the zip file size. 969 // Expect 1 piece of patch since limit is larger than the zip file size.
970 GenerateAndCheckSplitTarget(debug_dir.path, 1, tgt); 970 GenerateAndCheckSplitTarget(debug_dir.path, 1, tgt);
971} 971}
972
973TEST(ImgdiffTest, zip_mode_large_apk_small_target_chunk) {
974 TemporaryFile tgt_file;
975 FILE* tgt_file_ptr = fdopen(tgt_file.release(), "wb");
976 ZipWriter tgt_writer(tgt_file_ptr);
977
978 // The first entry is less than 4096 bytes, followed immediately by an entry that has a very
979 // large counterpart in the source file. Therefore the first entry will be patched separately.
980 std::string small_chunk("a", 2000);
981 ASSERT_EQ(0, tgt_writer.StartEntry("a", 0));
982 ASSERT_EQ(0, tgt_writer.WriteBytes(small_chunk.data(), small_chunk.size()));
983 ASSERT_EQ(0, tgt_writer.FinishEntry());
984 construct_store_entry(
985 {
986 { "b", 12, 'b' }, { "c", 3, 'c' },
987 },
988 &tgt_writer);
989 ASSERT_EQ(0, tgt_writer.Finish());
990 ASSERT_EQ(0, fclose(tgt_file_ptr));
991
992 TemporaryFile src_file;
993 FILE* src_file_ptr = fdopen(src_file.release(), "wb");
994 ZipWriter src_writer(src_file_ptr);
995 construct_store_entry({ { "a", 1, 'a' }, { "b", 13, 'b' }, { "c", 1, 'c' } }, &src_writer);
996 ASSERT_EQ(0, src_writer.Finish());
997 ASSERT_EQ(0, fclose(src_file_ptr));
998
999 // Compute patch.
1000 TemporaryFile patch_file;
1001 TemporaryFile split_info_file;
1002 TemporaryDir debug_dir;
1003 std::string split_info_arg = android::base::StringPrintf("--split-info=%s", split_info_file.path);
1004 std::string debug_dir_arg = android::base::StringPrintf("--debug-dir=%s", debug_dir.path);
1005 std::vector<const char*> args = {
1006 "imgdiff", "-z", "--block-limit=10", split_info_arg.c_str(), debug_dir_arg.c_str(),
1007 src_file.path, tgt_file.path, patch_file.path,
1008 };
1009 ASSERT_EQ(0, imgdiff(args.size(), args.data()));
1010
1011 std::string tgt;
1012 ASSERT_TRUE(android::base::ReadFileToString(tgt_file.path, &tgt));
1013
1014 // Expect three split src images:
1015 // src_piece 0: a 1 blocks
1016 // src_piece 1: b-0 10 blocks
1017 // src_piece 2: b-1 3 blocks, c 1 blocks, CD
1018 GenerateAndCheckSplitTarget(debug_dir.path, 3, tgt);
1019}
1020
1021TEST(ImgdiffTest, zip_mode_large_apk_skipped_small_target_chunk) {
1022 TemporaryFile tgt_file;
1023 FILE* tgt_file_ptr = fdopen(tgt_file.release(), "wb");
1024 ZipWriter tgt_writer(tgt_file_ptr);
1025
1026 construct_store_entry(
1027 {
1028 { "a", 11, 'a' },
1029 },
1030 &tgt_writer);
1031
1032 // Construct a tiny target entry of 1 byte, which will be skipped due to the tail alignment of
1033 // the previous entry.
1034 std::string small_chunk("b", 1);
1035 ASSERT_EQ(0, tgt_writer.StartEntry("b", 0));
1036 ASSERT_EQ(0, tgt_writer.WriteBytes(small_chunk.data(), small_chunk.size()));
1037 ASSERT_EQ(0, tgt_writer.FinishEntry());
1038
1039 ASSERT_EQ(0, tgt_writer.Finish());
1040 ASSERT_EQ(0, fclose(tgt_file_ptr));
1041
1042 TemporaryFile src_file;
1043 FILE* src_file_ptr = fdopen(src_file.release(), "wb");
1044 ZipWriter src_writer(src_file_ptr);
1045 construct_store_entry(
1046 {
1047 { "a", 11, 'a' }, { "b", 11, 'b' },
1048 },
1049 &src_writer);
1050 ASSERT_EQ(0, src_writer.Finish());
1051 ASSERT_EQ(0, fclose(src_file_ptr));
1052
1053 // Compute patch.
1054 TemporaryFile patch_file;
1055 TemporaryFile split_info_file;
1056 TemporaryDir debug_dir;
1057 std::string split_info_arg = android::base::StringPrintf("--split-info=%s", split_info_file.path);
1058 std::string debug_dir_arg = android::base::StringPrintf("--debug-dir=%s", debug_dir.path);
1059 std::vector<const char*> args = {
1060 "imgdiff", "-z", "--block-limit=10", split_info_arg.c_str(), debug_dir_arg.c_str(),
1061 src_file.path, tgt_file.path, patch_file.path,
1062 };
1063 ASSERT_EQ(0, imgdiff(args.size(), args.data()));
1064
1065 std::string tgt;
1066 ASSERT_TRUE(android::base::ReadFileToString(tgt_file.path, &tgt));
1067
1068 // Expect two split src images:
1069 // src_piece 0: a-0 10 blocks
1070 // src_piece 1: a-0 1 block, CD
1071 GenerateAndCheckSplitTarget(debug_dir.path, 2, tgt);
1072}