summaryrefslogtreecommitdiffstats
path: root/tests/component/applypatch_test.cpp
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2017-03-26 20:03:10 +0200
committerandroid-build-merger <android-build-merger@google.com>2017-03-26 20:03:10 +0200
commit351f69e64a3c7afc52f83c03d3a608f73175d440 (patch)
tree929bb39857857a078e24561f57c7e07526ad7440 /tests/component/applypatch_test.cpp
parentMerge "Don't fail ReadArgs if length to parse is 0" (diff)
parentMerge "applypatch: Drop the support for patching non-EMMC targets." (diff)
downloadandroid_bootable_recovery-351f69e64a3c7afc52f83c03d3a608f73175d440.tar
android_bootable_recovery-351f69e64a3c7afc52f83c03d3a608f73175d440.tar.gz
android_bootable_recovery-351f69e64a3c7afc52f83c03d3a608f73175d440.tar.bz2
android_bootable_recovery-351f69e64a3c7afc52f83c03d3a608f73175d440.tar.lz
android_bootable_recovery-351f69e64a3c7afc52f83c03d3a608f73175d440.tar.xz
android_bootable_recovery-351f69e64a3c7afc52f83c03d3a608f73175d440.tar.zst
android_bootable_recovery-351f69e64a3c7afc52f83c03d3a608f73175d440.zip
Diffstat (limited to 'tests/component/applypatch_test.cpp')
-rw-r--r--tests/component/applypatch_test.cpp124
1 files changed, 0 insertions, 124 deletions
diff --git a/tests/component/applypatch_test.cpp b/tests/component/applypatch_test.cpp
index d178303aa..5cba68f8a 100644
--- a/tests/component/applypatch_test.cpp
+++ b/tests/component/applypatch_test.cpp
@@ -280,66 +280,6 @@ TEST_F(ApplyPatchCacheTest, CheckCacheMissingFailure) {
ASSERT_NE(0, applypatch_check(&old_file[0], sha1s));
}
-TEST_F(ApplyPatchFullTest, ApplyInPlace) {
- std::vector<std::string> sha1s = { bad_sha1_a, old_sha1 };
- ASSERT_EQ(0, applypatch(&old_file[0], "-", &new_sha1[0], new_size, sha1s, patches, nullptr));
- ASSERT_TRUE(file_cmp(old_file, new_file));
-
- // reapply, applypatch is idempotent so it should succeed
- ASSERT_EQ(0, applypatch(&old_file[0], "-", &new_sha1[0], new_size, sha1s, patches, nullptr));
- ASSERT_TRUE(file_cmp(old_file, new_file));
-}
-
-TEST_F(ApplyPatchFullTest, ApplyInNewLocation) {
- std::vector<std::string> sha1s = { bad_sha1_a, old_sha1 };
- // Apply bsdiff patch to new location.
- ASSERT_EQ(
- 0, applypatch(&old_file[0], &output_loc[0], &new_sha1[0], new_size, sha1s, patches, nullptr));
- ASSERT_TRUE(file_cmp(output_loc, new_file));
-
- // Reapply to the same location.
- ASSERT_EQ(
- 0, applypatch(&old_file[0], &output_loc[0], &new_sha1[0], new_size, sha1s, patches, nullptr));
- ASSERT_TRUE(file_cmp(output_loc, new_file));
-}
-
-TEST_F(ApplyPatchFullTest, ApplyCorruptedInNewLocation) {
- std::vector<std::string> sha1s = { bad_sha1_a, old_sha1 };
- // Apply bsdiff patch to new location with corrupted source.
- mangle_file(old_file);
- ASSERT_EQ(
- 0, applypatch(&old_file[0], &output_loc[0], &new_sha1[0], new_size, sha1s, patches, nullptr));
- ASSERT_TRUE(file_cmp(output_loc, new_file));
-
- // Reapply bsdiff patch to new location with corrupted source.
- ASSERT_EQ(
- 0, applypatch(&old_file[0], &output_loc[0], &new_sha1[0], new_size, sha1s, patches, nullptr));
- ASSERT_TRUE(file_cmp(output_loc, new_file));
-}
-
-TEST_F(ApplyPatchDoubleCacheTest, ApplyDoubleCorruptedInNewLocation) {
- std::vector<std::string> sha1s = { bad_sha1_a, old_sha1 };
-
- // Apply bsdiff patch to new location with corrupted source and copy (no new file).
- // Expected to fail.
- mangle_file(old_file);
- mangle_file(cache_file);
- ASSERT_NE(
- 0, applypatch(&old_file[0], &output_loc[0], &new_sha1[0], new_size, sha1s, patches, nullptr));
- ASSERT_FALSE(file_cmp(output_loc, new_file));
-
- // Expected to fail again on retry.
- ASSERT_NE(
- 0, applypatch(&old_file[0], &output_loc[0], &new_sha1[0], new_size, sha1s, patches, nullptr));
- ASSERT_FALSE(file_cmp(output_loc, new_file));
-
- // Expected to fail with incorrect new file.
- mangle_file(output_loc);
- ASSERT_NE(
- 0, applypatch(&old_file[0], &output_loc[0], &new_sha1[0], new_size, sha1s, patches, nullptr));
- ASSERT_FALSE(file_cmp(output_loc, new_file));
-}
-
TEST(ApplyPatchModesTest, InvalidArgs) {
// At least two args (including the filename).
ASSERT_EQ(2, applypatch_modes(1, (const char* []){ "applypatch" }));
@@ -348,70 +288,6 @@ TEST(ApplyPatchModesTest, InvalidArgs) {
ASSERT_EQ(2, applypatch_modes(2, (const char* []){ "applypatch", "-x" }));
}
-TEST(ApplyPatchModesTest, PatchMode) {
- std::string boot_img = from_testdata_base("boot.img");
- size_t boot_img_size;
- std::string boot_img_sha1;
- sha1sum(boot_img, &boot_img_sha1, &boot_img_size);
-
- std::string recovery_img = from_testdata_base("recovery.img");
- std::string recovery_img_sha1;
- size_t size;
- sha1sum(recovery_img, &recovery_img_sha1, &size);
- std::string recovery_img_size = std::to_string(size);
- std::string bonus_file = from_testdata_base("bonus.file");
-
- // applypatch -b <bonus-file> <src-file> <tgt-file> <tgt-sha1> <tgt-size> <src-sha1>:<patch>
- TemporaryFile tmp1;
- std::string patch = boot_img_sha1 + ":" + from_testdata_base("recovery-from-boot.p");
- std::vector<const char*> args = {
- "applypatch",
- "-b",
- bonus_file.c_str(),
- boot_img.c_str(),
- tmp1.path,
- recovery_img_sha1.c_str(),
- recovery_img_size.c_str(),
- patch.c_str()
- };
- ASSERT_EQ(0, applypatch_modes(args.size(), args.data()));
-
- // applypatch <src-file> <tgt-file> <tgt-sha1> <tgt-size> <src-sha1>:<patch>
- TemporaryFile tmp2;
- patch = boot_img_sha1 + ":" + from_testdata_base("recovery-from-boot-with-bonus.p");
- std::vector<const char*> args2 = {
- "applypatch",
- boot_img.c_str(),
- tmp2.path,
- recovery_img_sha1.c_str(),
- recovery_img_size.c_str(),
- patch.c_str()
- };
- ASSERT_EQ(0, applypatch_modes(args2.size(), args2.data()));
-
- // applypatch -b <bonus-file> <src-file> <tgt-file> <tgt-sha1> <tgt-size> \
- // <src-sha1-fake>:<patch1> <src-sha1>:<patch2>
- TemporaryFile tmp3;
- std::string bad_sha1_a = android::base::StringPrintf("%040x", rand());
- std::string bad_sha1_b = android::base::StringPrintf("%040x", rand());
- std::string patch1 = bad_sha1_a + ":" + from_testdata_base("recovery-from-boot.p");
- std::string patch2 = boot_img_sha1 + ":" + from_testdata_base("recovery-from-boot.p");
- std::string patch3 = bad_sha1_b + ":" + from_testdata_base("recovery-from-boot.p");
- std::vector<const char*> args3 = {
- "applypatch",
- "-b",
- bonus_file.c_str(),
- boot_img.c_str(),
- tmp3.path,
- recovery_img_sha1.c_str(),
- recovery_img_size.c_str(),
- patch1.c_str(),
- patch2.c_str(),
- patch3.c_str()
- };
- ASSERT_EQ(0, applypatch_modes(args3.size(), args3.data()));
-}
-
TEST(ApplyPatchModesTest, PatchModeEmmcTarget) {
std::string boot_img = from_testdata_base("boot.img");
size_t boot_img_size;