summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2018-08-20 20:22:44 +0200
committerandroid-build-merger <android-build-merger@google.com>2018-08-20 20:22:44 +0200
commitd8e8c7b6fa342de4692b00b7f60e05f409c4f211 (patch)
tree426288ab6c08dfbb3398e8de09a10a9bc4aeead2
parentMerge "updater: Add TransferList class." am: 102d14d6d1 am: 5cf27834f3 (diff)
parentMerge "tests: Remove {old,new}.file." am: 09ce7686f2 (diff)
downloadandroid_bootable_recovery-d8e8c7b6fa342de4692b00b7f60e05f409c4f211.tar
android_bootable_recovery-d8e8c7b6fa342de4692b00b7f60e05f409c4f211.tar.gz
android_bootable_recovery-d8e8c7b6fa342de4692b00b7f60e05f409c4f211.tar.bz2
android_bootable_recovery-d8e8c7b6fa342de4692b00b7f60e05f409c4f211.tar.lz
android_bootable_recovery-d8e8c7b6fa342de4692b00b7f60e05f409c4f211.tar.xz
android_bootable_recovery-d8e8c7b6fa342de4692b00b7f60e05f409c4f211.tar.zst
android_bootable_recovery-d8e8c7b6fa342de4692b00b7f60e05f409c4f211.zip
-rw-r--r--tests/component/updater_test.cpp2
-rw-r--r--tests/testdata/new.filebin1388877 -> 0 bytes
-rw-r--r--tests/testdata/old.filebin1348051 -> 0 bytes
-rw-r--r--tests/unit/applypatch_test.cpp103
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
deleted file mode 100644
index cdeb8fd50..000000000
--- a/tests/testdata/new.file
+++ /dev/null
Binary files differ
diff --git a/tests/testdata/old.file b/tests/testdata/old.file
deleted file mode 100644
index 166c8732e..000000000
--- a/tests/testdata/old.file
+++ /dev/null
Binary files differ
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 }));
}