aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTianjie Xu2017-10-24 18:12:35 -0500
committerTianjie Xu2017-11-01 01:31:02 -0500
commit113fe05ee0d33dbafd0923be97d448feb27d8f4b (patch)
treed665193af5ff0664341e63e28173ef959900546c /tests
parent166479b259e73a89836797ac3e2db2ccc89221e0 (diff)
downloadplatform-bootable-recovery-113fe05ee0d33dbafd0923be97d448feb27d8f4b.tar.gz
platform-bootable-recovery-113fe05ee0d33dbafd0923be97d448feb27d8f4b.tar.xz
platform-bootable-recovery-113fe05ee0d33dbafd0923be97d448feb27d8f4b.zip
Fix the size mismatch in imgdiff
As we construct the deflate entries of the target zip file with random data, the total size of the zip file may vary from case to case. This leads to occasional failures in the split test for deflate large apk files. This CL fixes the issue by adding two static zip files in the testdata instead of generating them dynamically. Bug: 67849209 Test: run the deflate_large_test repeatedly Change-Id: Iaeffad9205adefa10c9f62f9f088c33c4360a650
Diffstat (limited to 'tests')
-rw-r--r--tests/common/test_constants.h12
-rw-r--r--tests/component/imgdiff_test.cpp77
-rw-r--r--tests/testdata/deflate_src.zipbin0 -> 164491 bytes
-rw-r--r--tests/testdata/deflate_tgt.zipbin0 -> 160385 bytes
4 files changed, 36 insertions, 53 deletions
diff --git a/tests/common/test_constants.h b/tests/common/test_constants.h
index f6b6922a..514818e0 100644
--- a/tests/common/test_constants.h
+++ b/tests/common/test_constants.h
@@ -19,6 +19,8 @@
19 19
20#include <stdlib.h> 20#include <stdlib.h>
21 21
22#include <string>
23
22// Zip entries in ziptest_valid.zip. 24// Zip entries in ziptest_valid.zip.
23static const std::string kATxtContents("abcdefghabcdefgh\n"); 25static const std::string kATxtContents("abcdefghabcdefgh\n");
24static const std::string kBTxtContents("abcdefgh\n"); 26static const std::string kBTxtContents("abcdefgh\n");
@@ -30,10 +32,14 @@ static const std::string kATxtSha1Sum("32c96a03dc8cd20097940f351bca6261ee5a1643"
30// echo -n -e "abcdefgh\n" | sha1sum 32// echo -n -e "abcdefgh\n" | sha1sum
31static const std::string kBTxtSha1Sum("e414af7161c9554089f4106d6f1797ef14a73666"); 33static const std::string kBTxtSha1Sum("e414af7161c9554089f4106d6f1797ef14a73666");
32 34
33static const char* data_root = getenv("ANDROID_DATA");
34
35static std::string from_testdata_base(const std::string& fname) { 35static std::string from_testdata_base(const std::string& fname) {
36 return std::string(data_root) + "/nativetest/recovery/testdata/" + fname; 36#ifdef __ANDROID__
37 static std::string data_root = getenv("ANDROID_DATA");
38#else
39 static std::string data_root = std::string(getenv("ANDROID_PRODUCT_OUT")) + "/data";
40#endif
41
42 return data_root + "/nativetest/recovery/testdata/" + fname;
37} 43}
38 44
39#endif // _OTA_TEST_CONSTANTS_H 45#endif // _OTA_TEST_CONSTANTS_H
diff --git a/tests/component/imgdiff_test.cpp b/tests/component/imgdiff_test.cpp
index f82a9db5..6de804e0 100644
--- a/tests/component/imgdiff_test.cpp
+++ b/tests/component/imgdiff_test.cpp
@@ -32,6 +32,8 @@
32#include <gtest/gtest.h> 32#include <gtest/gtest.h>
33#include <ziparchive/zip_writer.h> 33#include <ziparchive/zip_writer.h>
34 34
35#include "common/test_constants.h"
36
35using android::base::get_unaligned; 37using android::base::get_unaligned;
36 38
37// Sanity check for the given imgdiff patch header. 39// Sanity check for the given imgdiff patch header.
@@ -797,44 +799,21 @@ TEST(ImgdiffTest, zip_mode_store_large_apk) {
797} 799}
798 800
799TEST(ImgdiffTest, zip_mode_deflate_large_apk) { 801TEST(ImgdiffTest, zip_mode_deflate_large_apk) {
800 // Generate 50 blocks of random data. 802 // Src and tgt zip files are constructed as follows.
801 std::string random_data;
802 random_data.reserve(4096 * 50);
803 generate_n(back_inserter(random_data), 4096 * 50, []() { return rand() % 256; });
804
805 // Construct src and tgt zip files with limit = 10 blocks.
806 // src tgt 803 // src tgt
807 // 22 blocks, "d" 4 blocks, "a" 804 // 22 blocks, "d" 4 blocks, "a"
808 // 5 blocks, "b" 4 blocks, "b" 805 // 5 blocks, "b" 4 blocks, "b"
809 // 3 blocks, "a" 7 blocks, "c" (exceeds limit) 806 // 3 blocks, "a" 8 blocks, "c" (exceeds limit)
810 // 8 blocks, "c" 20 blocks, "d" (exceeds limit) 807 // 1 block, "g" 20 blocks, "d" (exceeds limit)
811 // 1 block, "f" 2 blocks, "e" 808 // 8 blocks, "c" 2 blocks, "e"
812 TemporaryFile tgt_file; 809 // 1 block, "f" 1 block , "f"
813 FILE* tgt_file_ptr = fdopen(tgt_file.release(), "wb"); 810 std::string tgt_path = from_testdata_base("deflate_tgt.zip");
814 ZipWriter tgt_writer(tgt_file_ptr); 811 std::string src_path = from_testdata_base("deflate_src.zip");
815
816 construct_deflate_entry(
817 { { "a", 0, 4 }, { "b", 5, 4 }, { "c", 12, 8 }, { "d", 21, 20 }, { "e", 45, 2 },
818 { "f", 48, 1 } }, &tgt_writer, random_data);
819
820 ASSERT_EQ(0, tgt_writer.Finish());
821 ASSERT_EQ(0, fclose(tgt_file_ptr));
822
823 TemporaryFile src_file;
824 FILE* src_file_ptr = fdopen(src_file.release(), "wb");
825 ZipWriter src_writer(src_file_ptr);
826
827 construct_deflate_entry(
828 { { "d", 21, 22 }, { "b", 5, 5 }, { "a", 0, 3 }, { "g", 9, 1 }, { "c", 11, 8 },
829 { "f", 45, 1 } }, &src_writer, random_data);
830
831 ASSERT_EQ(0, src_writer.Finish());
832 ASSERT_EQ(0, fclose(src_file_ptr));
833 812
834 ZipModeImage src_image(true, 10 * 4096); 813 ZipModeImage src_image(true, 10 * 4096);
835 ZipModeImage tgt_image(false, 10 * 4096); 814 ZipModeImage tgt_image(false, 10 * 4096);
836 ASSERT_TRUE(src_image.Initialize(src_file.path)); 815 ASSERT_TRUE(src_image.Initialize(src_path));
837 ASSERT_TRUE(tgt_image.Initialize(tgt_file.path)); 816 ASSERT_TRUE(tgt_image.Initialize(tgt_path));
838 ASSERT_TRUE(ZipModeImage::CheckAndProcessChunks(&tgt_image, &src_image)); 817 ASSERT_TRUE(ZipModeImage::CheckAndProcessChunks(&tgt_image, &src_image));
839 818
840 src_image.DumpChunks(); 819 src_image.DumpChunks();
@@ -846,11 +825,12 @@ TEST(ImgdiffTest, zip_mode_deflate_large_apk) {
846 ZipModeImage::SplitZipModeImageWithLimit(tgt_image, src_image, &split_tgt_images, 825 ZipModeImage::SplitZipModeImageWithLimit(tgt_image, src_image, &split_tgt_images,
847 &split_src_images, &split_src_ranges); 826 &split_src_images, &split_src_ranges);
848 827
849 // src_piece 1: a 3 blocks, b 5 blocks 828 // Expected split images with limit = 10 blocks.
850 // src_piece 2: c 8 blocks 829 // src_piece 0: a 3 blocks, b 5 blocks
851 // src_piece 3: d-0 10 block 830 // src_piece 1: c 8 blocks
852 // src_piece 4: d-1 10 blocks 831 // src_piece 2: d-0 10 block
853 // src_piece 5: e 1 block, CD 832 // src_piece 3: d-1 10 blocks
833 // src_piece 4: e 1 block, CD
854 ASSERT_EQ(split_tgt_images.size(), split_src_images.size()); 834 ASSERT_EQ(split_tgt_images.size(), split_src_images.size());
855 ASSERT_EQ(static_cast<size_t>(5), split_tgt_images.size()); 835 ASSERT_EQ(static_cast<size_t>(5), split_tgt_images.size());
856 836
@@ -883,24 +863,21 @@ TEST(ImgdiffTest, zip_mode_deflate_large_apk) {
883 ASSERT_EQ("2", android::base::Trim(info_list[0])); 863 ASSERT_EQ("2", android::base::Trim(info_list[0]));
884 ASSERT_EQ("5", android::base::Trim(info_list[1])); 864 ASSERT_EQ("5", android::base::Trim(info_list[1]));
885 865
886 std::vector<size_t> patch_size; 866 std::string tgt;
867 ASSERT_TRUE(android::base::ReadFileToString(tgt_path, &tgt));
868 ASSERT_EQ(static_cast<size_t>(160385), tgt.size());
869 std::vector<std::string> tgt_file_ranges = {
870 "36864 2,22,31", "32768 2,31,40", "40960 2,0,11", "40960 2,11,21", "8833 4,21,22,40,41",
871 };
872
887 for (size_t i = 0; i < 5; i++) { 873 for (size_t i = 0; i < 5; i++) {
888 struct stat st = {}; 874 struct stat st;
889 std::string path = android::base::StringPrintf("%s/patch-%zu", debug_dir.path, i); 875 std::string path = android::base::StringPrintf("%s/patch-%zu", debug_dir.path, i);
890 ASSERT_EQ(0, stat(path.c_str(), &st)); 876 ASSERT_EQ(0, stat(path.c_str(), &st));
891 patch_size.push_back(st.st_size); 877 ASSERT_EQ(std::to_string(st.st_size) + " " + tgt_file_ranges[i],
878 android::base::Trim(info_list[i + 2]));
892 } 879 }
893 880
894 ASSERT_EQ(std::to_string(patch_size[0]) + " 36864 2,22,31", android::base::Trim(info_list[2]));
895 ASSERT_EQ(std::to_string(patch_size[1]) + " 32768 2,31,40", android::base::Trim(info_list[3]));
896 ASSERT_EQ(std::to_string(patch_size[2]) + " 40960 2,0,11", android::base::Trim(info_list[4]));
897 ASSERT_EQ(std::to_string(patch_size[3]) + " 40960 2,11,21", android::base::Trim(info_list[5]));
898 ASSERT_EQ(std::to_string(patch_size[4]) + " 8833 4,21,22,40,41",
899 android::base::Trim(info_list[6]));
900
901 std::string tgt;
902 ASSERT_TRUE(android::base::ReadFileToString(tgt_file.path, &tgt));
903
904 GenerateAndCheckSplitTarget(debug_dir.path, 5, tgt); 881 GenerateAndCheckSplitTarget(debug_dir.path, 5, tgt);
905} 882}
906 883
diff --git a/tests/testdata/deflate_src.zip b/tests/testdata/deflate_src.zip
new file mode 100644
index 00000000..bdb2b321
--- /dev/null
+++ b/tests/testdata/deflate_src.zip
Binary files differ
diff --git a/tests/testdata/deflate_tgt.zip b/tests/testdata/deflate_tgt.zip
new file mode 100644
index 00000000..2a21760e
--- /dev/null
+++ b/tests/testdata/deflate_tgt.zip
Binary files differ