diff options
author | Tao Bao <tbao@google.com> | 2018-08-20 20:13:54 +0200 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2018-08-20 20:13:54 +0200 |
commit | 14d87881d89418287bc1ab02ac2bcd992a70e49a (patch) | |
tree | 426288ab6c08dfbb3398e8de09a10a9bc4aeead2 | |
parent | Merge "updater: Add TransferList class." (diff) | |
parent | Merge "tests: Remove {old,new}.file." (diff) | |
download | android_bootable_recovery-14d87881d89418287bc1ab02ac2bcd992a70e49a.tar android_bootable_recovery-14d87881d89418287bc1ab02ac2bcd992a70e49a.tar.gz android_bootable_recovery-14d87881d89418287bc1ab02ac2bcd992a70e49a.tar.bz2 android_bootable_recovery-14d87881d89418287bc1ab02ac2bcd992a70e49a.tar.lz android_bootable_recovery-14d87881d89418287bc1ab02ac2bcd992a70e49a.tar.xz android_bootable_recovery-14d87881d89418287bc1ab02ac2bcd992a70e49a.tar.zst android_bootable_recovery-14d87881d89418287bc1ab02ac2bcd992a70e49a.zip |
Diffstat (limited to '')
-rw-r--r-- | tests/component/updater_test.cpp | 2 | ||||
-rw-r--r-- | tests/testdata/new.file | bin | 1388877 -> 0 bytes | |||
-rw-r--r-- | tests/testdata/old.file | bin | 1348051 -> 0 bytes | |||
-rw-r--r-- | tests/unit/applypatch_test.cpp | 103 |
4 files changed, 55 insertions, 50 deletions
diff --git a/tests/component/updater_test.cpp b/tests/component/updater_test.cpp index 2ed797e62..c4f3176f9 100644 --- a/tests/component/updater_test.cpp +++ b/tests/component/updater_test.cpp @@ -221,7 +221,7 @@ TEST_F(UpdaterTest, apply_patch_check) { // File not found. expect("", "apply_patch_check(\"/doesntexist\")", kNoCause); - std::string src_file = from_testdata_base("old.file"); + std::string src_file = from_testdata_base("boot.img"); std::string src_content; ASSERT_TRUE(android::base::ReadFileToString(src_file, &src_content)); size_t src_size = src_content.size(); diff --git a/tests/testdata/new.file b/tests/testdata/new.file Binary files differdeleted file mode 100644 index cdeb8fd50..000000000 --- a/tests/testdata/new.file +++ /dev/null diff --git a/tests/testdata/old.file b/tests/testdata/old.file Binary files differdeleted file mode 100644 index 166c8732e..000000000 --- a/tests/testdata/old.file +++ /dev/null diff --git a/tests/unit/applypatch_test.cpp b/tests/unit/applypatch_test.cpp index 0d4123b5e..fe00e1e66 100644 --- a/tests/unit/applypatch_test.cpp +++ b/tests/unit/applypatch_test.cpp @@ -46,17 +46,17 @@ using namespace std::string_literals; class ApplyPatchTest : public ::testing::Test { protected: void SetUp() override { - old_file = from_testdata_base("old.file"); - FileContents old_fc; - ASSERT_EQ(0, LoadFileContents(old_file, &old_fc)); - old_sha1 = print_sha1(old_fc.sha1); - old_size = old_fc.data.size(); - - new_file = from_testdata_base("new.file"); - FileContents new_fc; - ASSERT_EQ(0, LoadFileContents(new_file, &new_fc)); - new_sha1 = print_sha1(new_fc.sha1); - new_size = new_fc.data.size(); + source_file = from_testdata_base("boot.img"); + FileContents boot_fc; + ASSERT_EQ(0, LoadFileContents(source_file, &boot_fc)); + source_size = boot_fc.data.size(); + source_sha1 = print_sha1(boot_fc.sha1); + + target_file = from_testdata_base("recovery.img"); + FileContents recovery_fc; + ASSERT_EQ(0, LoadFileContents(target_file, &recovery_fc)); + target_size = recovery_fc.data.size(); + target_sha1 = print_sha1(recovery_fc.sha1); srand(time(nullptr)); bad_sha1_a = android::base::StringPrintf("%040x", rand()); @@ -66,78 +66,83 @@ class ApplyPatchTest : public ::testing::Test { Paths::Get().set_cache_temp_source("/cache/saved.file"); } - std::string old_file; - std::string old_sha1; - size_t old_size; + std::string source_file; + std::string source_sha1; + size_t source_size; - std::string new_file; - std::string new_sha1; - size_t new_size; + std::string target_file; + std::string target_sha1; + size_t target_size; std::string bad_sha1_a; std::string bad_sha1_b; }; TEST_F(ApplyPatchTest, CheckMode) { - std::string partition = "EMMC:" + old_file + ":" + std::to_string(old_size) + ":" + old_sha1; + std::string partition = + "EMMC:" + source_file + ":" + std::to_string(source_size) + ":" + source_sha1; ASSERT_EQ(0, applypatch_check(partition, {})); - ASSERT_EQ(0, applypatch_check(partition, { old_sha1 })); + ASSERT_EQ(0, applypatch_check(partition, { source_sha1 })); ASSERT_EQ(0, applypatch_check(partition, { bad_sha1_a, bad_sha1_b })); - ASSERT_EQ(0, applypatch_check(partition, { bad_sha1_a, old_sha1, bad_sha1_b })); + ASSERT_EQ(0, applypatch_check(partition, { bad_sha1_a, source_sha1, bad_sha1_b })); } TEST_F(ApplyPatchTest, CheckMode_NonEmmcTarget) { - ASSERT_NE(0, applypatch_check(old_file, {})); - ASSERT_NE(0, applypatch_check(old_file, { old_sha1 })); - ASSERT_NE(0, applypatch_check(old_file, { bad_sha1_a, bad_sha1_b })); - ASSERT_NE(0, applypatch_check(old_file, { bad_sha1_a, old_sha1, bad_sha1_b })); + ASSERT_NE(0, applypatch_check(source_file, {})); + ASSERT_NE(0, applypatch_check(source_file, { source_sha1 })); + ASSERT_NE(0, applypatch_check(source_file, { bad_sha1_a, bad_sha1_b })); + ASSERT_NE(0, applypatch_check(source_file, { bad_sha1_a, source_sha1, bad_sha1_b })); } TEST_F(ApplyPatchTest, CheckMode_EmmcTarget) { - // EMMC:old_file:size:sha1 should pass the check. - std::string src_file = "EMMC:" + old_file + ":" + std::to_string(old_size) + ":" + old_sha1; + // EMMC:source_file:size:sha1 should pass the check. + std::string src_file = + "EMMC:" + source_file + ":" + std::to_string(source_size) + ":" + source_sha1; ASSERT_EQ(0, applypatch_check(src_file, {})); - // EMMC:old_file:(size-1):sha1:(size+1):sha1 should fail the check. - src_file = "EMMC:" + old_file + ":" + std::to_string(old_size - 1) + ":" + old_sha1 + ":" + - std::to_string(old_size + 1) + ":" + old_sha1; + // EMMC:source_file:(size-1):sha1:(size+1):sha1 should fail the check. + src_file = "EMMC:" + source_file + ":" + std::to_string(source_size - 1) + ":" + source_sha1 + + ":" + std::to_string(source_size + 1) + ":" + source_sha1; ASSERT_NE(0, applypatch_check(src_file, {})); - // EMMC:old_file:(size-1):sha1:size:sha1:(size+1):sha1 should pass the check. - src_file = "EMMC:" + old_file + ":" + std::to_string(old_size - 1) + ":" + old_sha1 + ":" + - std::to_string(old_size) + ":" + old_sha1 + ":" + std::to_string(old_size + 1) + ":" + - old_sha1; + // EMMC:source_file:(size-1):sha1:size:sha1:(size+1):sha1 should pass the check. + src_file = "EMMC:" + source_file + ":" + std::to_string(source_size - 1) + ":" + source_sha1 + + ":" + std::to_string(source_size) + ":" + source_sha1 + ":" + + std::to_string(source_size + 1) + ":" + source_sha1; ASSERT_EQ(0, applypatch_check(src_file, {})); - // EMMC:old_file:(size+1):sha1:(size-1):sha1:size:sha1 should pass the check. - src_file = "EMMC:" + old_file + ":" + std::to_string(old_size + 1) + ":" + old_sha1 + ":" + - std::to_string(old_size - 1) + ":" + old_sha1 + ":" + std::to_string(old_size) + ":" + - old_sha1; + // EMMC:source_file:(size+1):sha1:(size-1):sha1:size:sha1 should pass the check. + src_file = "EMMC:" + source_file + ":" + std::to_string(source_size + 1) + ":" + source_sha1 + + ":" + std::to_string(source_size - 1) + ":" + source_sha1 + ":" + + std::to_string(source_size) + ":" + source_sha1; ASSERT_EQ(0, applypatch_check(src_file, {})); - // EMMC:new_file:(size+1):old_sha1:(size-1):old_sha1:size:old_sha1:size:new_sha1 + // EMMC:target_file:(size+1):source_sha1:(size-1):source_sha1:size:source_sha1:size:target_sha1 // should pass the check. - src_file = "EMMC:" + new_file + ":" + std::to_string(old_size + 1) + ":" + old_sha1 + ":" + - std::to_string(old_size - 1) + ":" + old_sha1 + ":" + std::to_string(old_size) + ":" + - old_sha1 + ":" + std::to_string(new_size) + ":" + new_sha1; + src_file = "EMMC:" + target_file + ":" + std::to_string(source_size + 1) + ":" + source_sha1 + + ":" + std::to_string(source_size - 1) + ":" + source_sha1 + ":" + + std::to_string(source_size) + ":" + source_sha1 + ":" + std::to_string(target_size) + + ":" + target_sha1; ASSERT_EQ(0, applypatch_check(src_file, {})); } TEST_F(ApplyPatchTest, CheckMode_UseBackup) { - std::string corrupted = "EMMC:" + old_file + ":" + std::to_string(old_size) + ":" + bad_sha1_a; - ASSERT_NE(0, applypatch_check(corrupted, { old_sha1 })); + std::string corrupted = + "EMMC:" + source_file + ":" + std::to_string(source_size) + ":" + bad_sha1_a; + ASSERT_NE(0, applypatch_check(corrupted, { source_sha1 })); - Paths::Get().set_cache_temp_source(old_file); - ASSERT_EQ(0, applypatch_check(corrupted, { old_sha1 })); - ASSERT_EQ(0, applypatch_check(corrupted, { bad_sha1_a, old_sha1, bad_sha1_b })); + Paths::Get().set_cache_temp_source(source_file); + ASSERT_EQ(0, applypatch_check(corrupted, { source_sha1 })); + ASSERT_EQ(0, applypatch_check(corrupted, { bad_sha1_a, source_sha1, bad_sha1_b })); } TEST_F(ApplyPatchTest, CheckMode_UseBackup_BothCorrupted) { - std::string corrupted = "EMMC:" + old_file + ":" + std::to_string(old_size) + ":" + bad_sha1_a; + std::string corrupted = + "EMMC:" + source_file + ":" + std::to_string(source_size) + ":" + bad_sha1_a; ASSERT_NE(0, applypatch_check(corrupted, {})); - ASSERT_NE(0, applypatch_check(corrupted, { old_sha1 })); + ASSERT_NE(0, applypatch_check(corrupted, { source_sha1 })); - Paths::Get().set_cache_temp_source(old_file); + Paths::Get().set_cache_temp_source(source_file); ASSERT_NE(0, applypatch_check(corrupted, { bad_sha1_a, bad_sha1_b })); } |