diff options
author | Tao Bao | 2018-03-12 23:18:52 -0500 |
---|---|---|
committer | Tao Bao | 2018-03-12 23:21:41 -0500 |
commit | d612b23dfd58dbe5059ba53d8fd13cbb343b177c (patch) | |
tree | 54f72add4fbb695b42efe9bbeb0b94c51f578874 /tests/component | |
parent | 0acbdac82b58786933a94e131e47f9109bf007d1 (diff) | |
download | platform-bootable-recovery-d612b23dfd58dbe5059ba53d8fd13cbb343b177c.tar.gz platform-bootable-recovery-d612b23dfd58dbe5059ba53d8fd13cbb343b177c.tar.xz platform-bootable-recovery-d612b23dfd58dbe5059ba53d8fd13cbb343b177c.zip |
tests: Add ApplyPatchModesTest.PatchModeEmmcTargetWithBsdiffPatch test.
/system/bin/applypatch on device is expected to work with bsdiff based
recovery-from-boot patch automatically. Adding a test to ensure that's
always the case.
Bug: 72731506
Test: Run recovery_component_test on marlin.
Change-Id: I56283cd3ce7cf0215cc3bb3619b206fa01d552c4
Diffstat (limited to 'tests/component')
-rw-r--r-- | tests/component/applypatch_test.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/component/applypatch_test.cpp b/tests/component/applypatch_test.cpp index b6d09255..61e06adb 100644 --- a/tests/component/applypatch_test.cpp +++ b/tests/component/applypatch_test.cpp | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <android-base/file.h> | 30 | #include <android-base/file.h> |
31 | #include <android-base/stringprintf.h> | 31 | #include <android-base/stringprintf.h> |
32 | #include <android-base/test_utils.h> | 32 | #include <android-base/test_utils.h> |
33 | #include <bsdiff/bsdiff.h> | ||
33 | #include <openssl/sha.h> | 34 | #include <openssl/sha.h> |
34 | 35 | ||
35 | #include "applypatch/applypatch.h" | 36 | #include "applypatch/applypatch.h" |
@@ -38,6 +39,8 @@ | |||
38 | #include "otautil/cache_location.h" | 39 | #include "otautil/cache_location.h" |
39 | #include "otautil/print_sha1.h" | 40 | #include "otautil/print_sha1.h" |
40 | 41 | ||
42 | using namespace std::string_literals; | ||
43 | |||
41 | static void sha1sum(const std::string& fname, std::string* sha1, size_t* fsize = nullptr) { | 44 | static void sha1sum(const std::string& fname, std::string* sha1, size_t* fsize = nullptr) { |
42 | ASSERT_NE(nullptr, sha1); | 45 | ASSERT_NE(nullptr, sha1); |
43 | 46 | ||
@@ -265,6 +268,54 @@ TEST_F(ApplyPatchModesTest, PatchModeEmmcTarget) { | |||
265 | ASSERT_EQ(0, applypatch_modes(args3.size(), args3.data())); | 268 | ASSERT_EQ(0, applypatch_modes(args3.size(), args3.data())); |
266 | } | 269 | } |
267 | 270 | ||
271 | // Ensures that applypatch works with a bsdiff based recovery-from-boot.p. | ||
272 | TEST_F(ApplyPatchModesTest, PatchModeEmmcTargetWithBsdiffPatch) { | ||
273 | std::string boot_img_file = from_testdata_base("boot.img"); | ||
274 | std::string boot_img_sha1; | ||
275 | size_t boot_img_size; | ||
276 | sha1sum(boot_img_file, &boot_img_sha1, &boot_img_size); | ||
277 | |||
278 | std::string recovery_img_file = from_testdata_base("recovery.img"); | ||
279 | std::string recovery_img_sha1; | ||
280 | size_t recovery_img_size; | ||
281 | sha1sum(recovery_img_file, &recovery_img_sha1, &recovery_img_size); | ||
282 | |||
283 | // Generate the bsdiff patch of recovery-from-boot.p. | ||
284 | std::string src_content; | ||
285 | ASSERT_TRUE(android::base::ReadFileToString(boot_img_file, &src_content)); | ||
286 | |||
287 | std::string tgt_content; | ||
288 | ASSERT_TRUE(android::base::ReadFileToString(recovery_img_file, &tgt_content)); | ||
289 | |||
290 | TemporaryFile patch_file; | ||
291 | ASSERT_EQ(0, | ||
292 | bsdiff::bsdiff(reinterpret_cast<const uint8_t*>(src_content.data()), src_content.size(), | ||
293 | reinterpret_cast<const uint8_t*>(tgt_content.data()), tgt_content.size(), | ||
294 | patch_file.path, nullptr)); | ||
295 | |||
296 | // applypatch <src-file> <tgt-file> <tgt-sha1> <tgt-size> <src-sha1>:<patch> | ||
297 | std::string src_file_arg = | ||
298 | "EMMC:" + boot_img_file + ":" + std::to_string(boot_img_size) + ":" + boot_img_sha1; | ||
299 | TemporaryFile tgt_file; | ||
300 | std::string tgt_file_arg = "EMMC:"s + tgt_file.path; | ||
301 | std::string recovery_img_size_arg = std::to_string(recovery_img_size); | ||
302 | std::string patch_arg = boot_img_sha1 + ":" + patch_file.path; | ||
303 | std::vector<const char*> args = { "applypatch", | ||
304 | src_file_arg.c_str(), | ||
305 | tgt_file_arg.c_str(), | ||
306 | recovery_img_sha1.c_str(), | ||
307 | recovery_img_size_arg.c_str(), | ||
308 | patch_arg.c_str() }; | ||
309 | ASSERT_EQ(0, applypatch_modes(args.size(), args.data())); | ||
310 | |||
311 | // Double check the patched recovery image. | ||
312 | std::string tgt_file_sha1; | ||
313 | size_t tgt_file_size; | ||
314 | sha1sum(tgt_file.path, &tgt_file_sha1, &tgt_file_size); | ||
315 | ASSERT_EQ(recovery_img_size, tgt_file_size); | ||
316 | ASSERT_EQ(recovery_img_sha1, tgt_file_sha1); | ||
317 | } | ||
318 | |||
268 | TEST_F(ApplyPatchModesTest, PatchModeInvalidArgs) { | 319 | TEST_F(ApplyPatchModesTest, PatchModeInvalidArgs) { |
269 | // Invalid bonus file. | 320 | // Invalid bonus file. |
270 | ASSERT_NE(0, applypatch_modes(3, (const char* []){ "applypatch", "-b", "/doesntexist" })); | 321 | ASSERT_NE(0, applypatch_modes(3, (const char* []){ "applypatch", "-b", "/doesntexist" })); |