Merge "tests: Remove {old,new}.file."

This commit is contained in:
Treehugger Robot
2018-08-20 17:48:56 +00:00
committed by Gerrit Code Review
4 changed files with 54 additions and 49 deletions
+1 -1
View File
@@ -221,7 +221,7 @@ TEST_F(UpdaterTest, apply_patch_check) {
// File not found. // File not found.
expect("", "apply_patch_check(\"/doesntexist\")", kNoCause); 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; std::string src_content;
ASSERT_TRUE(android::base::ReadFileToString(src_file, &src_content)); ASSERT_TRUE(android::base::ReadFileToString(src_file, &src_content));
size_t src_size = src_content.size(); size_t src_size = src_content.size();
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
+53 -48
View File
@@ -46,17 +46,17 @@ using namespace std::string_literals;
class ApplyPatchTest : public ::testing::Test { class ApplyPatchTest : public ::testing::Test {
protected: protected:
void SetUp() override { void SetUp() override {
old_file = from_testdata_base("old.file"); source_file = from_testdata_base("boot.img");
FileContents old_fc; FileContents boot_fc;
ASSERT_EQ(0, LoadFileContents(old_file, &old_fc)); ASSERT_EQ(0, LoadFileContents(source_file, &boot_fc));
old_sha1 = print_sha1(old_fc.sha1); source_size = boot_fc.data.size();
old_size = old_fc.data.size(); source_sha1 = print_sha1(boot_fc.sha1);
new_file = from_testdata_base("new.file"); target_file = from_testdata_base("recovery.img");
FileContents new_fc; FileContents recovery_fc;
ASSERT_EQ(0, LoadFileContents(new_file, &new_fc)); ASSERT_EQ(0, LoadFileContents(target_file, &recovery_fc));
new_sha1 = print_sha1(new_fc.sha1); target_size = recovery_fc.data.size();
new_size = new_fc.data.size(); target_sha1 = print_sha1(recovery_fc.sha1);
srand(time(nullptr)); srand(time(nullptr));
bad_sha1_a = android::base::StringPrintf("%040x", rand()); 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"); Paths::Get().set_cache_temp_source("/cache/saved.file");
} }
std::string old_file; std::string source_file;
std::string old_sha1; std::string source_sha1;
size_t old_size; size_t source_size;
std::string new_file; std::string target_file;
std::string new_sha1; std::string target_sha1;
size_t new_size; size_t target_size;
std::string bad_sha1_a; std::string bad_sha1_a;
std::string bad_sha1_b; std::string bad_sha1_b;
}; };
TEST_F(ApplyPatchTest, CheckMode) { 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, {}));
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, 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) { TEST_F(ApplyPatchTest, CheckMode_NonEmmcTarget) {
ASSERT_NE(0, applypatch_check(old_file, {})); ASSERT_NE(0, applypatch_check(source_file, {}));
ASSERT_NE(0, applypatch_check(old_file, { old_sha1 })); ASSERT_NE(0, applypatch_check(source_file, { source_sha1 }));
ASSERT_NE(0, applypatch_check(old_file, { bad_sha1_a, bad_sha1_b })); ASSERT_NE(0, applypatch_check(source_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, { bad_sha1_a, source_sha1, bad_sha1_b }));
} }
TEST_F(ApplyPatchTest, CheckMode_EmmcTarget) { TEST_F(ApplyPatchTest, CheckMode_EmmcTarget) {
// EMMC:old_file:size:sha1 should pass the check. // EMMC:source_file:size:sha1 should pass the check.
std::string src_file = "EMMC:" + old_file + ":" + std::to_string(old_size) + ":" + old_sha1; std::string src_file =
"EMMC:" + source_file + ":" + std::to_string(source_size) + ":" + source_sha1;
ASSERT_EQ(0, applypatch_check(src_file, {})); ASSERT_EQ(0, applypatch_check(src_file, {}));
// EMMC:old_file:(size-1):sha1:(size+1):sha1 should fail the check. // EMMC:source_file:(size-1):sha1:(size+1):sha1 should fail the check.
src_file = "EMMC:" + old_file + ":" + std::to_string(old_size - 1) + ":" + old_sha1 + ":" + src_file = "EMMC:" + source_file + ":" + std::to_string(source_size - 1) + ":" + source_sha1 +
std::to_string(old_size + 1) + ":" + old_sha1; ":" + std::to_string(source_size + 1) + ":" + source_sha1;
ASSERT_NE(0, applypatch_check(src_file, {})); ASSERT_NE(0, applypatch_check(src_file, {}));
// EMMC:old_file:(size-1):sha1:size:sha1:(size+1):sha1 should pass the check. // EMMC:source_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 + ":" + src_file = "EMMC:" + source_file + ":" + std::to_string(source_size - 1) + ":" + source_sha1 +
std::to_string(old_size) + ":" + old_sha1 + ":" + std::to_string(old_size + 1) + ":" + ":" + std::to_string(source_size) + ":" + source_sha1 + ":" +
old_sha1; std::to_string(source_size + 1) + ":" + source_sha1;
ASSERT_EQ(0, applypatch_check(src_file, {})); ASSERT_EQ(0, applypatch_check(src_file, {}));
// EMMC:old_file:(size+1):sha1:(size-1):sha1:size:sha1 should pass the check. // EMMC:source_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 + ":" + src_file = "EMMC:" + source_file + ":" + std::to_string(source_size + 1) + ":" + source_sha1 +
std::to_string(old_size - 1) + ":" + old_sha1 + ":" + std::to_string(old_size) + ":" + ":" + std::to_string(source_size - 1) + ":" + source_sha1 + ":" +
old_sha1; std::to_string(source_size) + ":" + source_sha1;
ASSERT_EQ(0, applypatch_check(src_file, {})); 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. // should pass the check.
src_file = "EMMC:" + new_file + ":" + std::to_string(old_size + 1) + ":" + old_sha1 + ":" + src_file = "EMMC:" + target_file + ":" + std::to_string(source_size + 1) + ":" + source_sha1 +
std::to_string(old_size - 1) + ":" + old_sha1 + ":" + std::to_string(old_size) + ":" + ":" + std::to_string(source_size - 1) + ":" + source_sha1 + ":" +
old_sha1 + ":" + std::to_string(new_size) + ":" + new_sha1; std::to_string(source_size) + ":" + source_sha1 + ":" + std::to_string(target_size) +
":" + target_sha1;
ASSERT_EQ(0, applypatch_check(src_file, {})); ASSERT_EQ(0, applypatch_check(src_file, {}));
} }
TEST_F(ApplyPatchTest, CheckMode_UseBackup) { TEST_F(ApplyPatchTest, CheckMode_UseBackup) {
std::string corrupted = "EMMC:" + old_file + ":" + std::to_string(old_size) + ":" + bad_sha1_a; std::string corrupted =
ASSERT_NE(0, applypatch_check(corrupted, { old_sha1 })); "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); Paths::Get().set_cache_temp_source(source_file);
ASSERT_EQ(0, applypatch_check(corrupted, { old_sha1 })); ASSERT_EQ(0, applypatch_check(corrupted, { source_sha1 }));
ASSERT_EQ(0, applypatch_check(corrupted, { bad_sha1_a, old_sha1, bad_sha1_b })); ASSERT_EQ(0, applypatch_check(corrupted, { bad_sha1_a, source_sha1, bad_sha1_b }));
} }
TEST_F(ApplyPatchTest, CheckMode_UseBackup_BothCorrupted) { 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, {}));
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 })); ASSERT_NE(0, applypatch_check(corrupted, { bad_sha1_a, bad_sha1_b }));
} }