aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTreehugger Robot2018-03-13 10:48:33 -0500
committerGerrit Code Review2018-03-13 10:48:33 -0500
commit3537a2659e06f316476542589b9627098ad3f8d6 (patch)
tree0d8c36f3fddaeab6dbb7e91f60893cabd392cea2
parentfc39f3ffd7dd89de30441cd3ce656bc4de4316a9 (diff)
parentd612b23dfd58dbe5059ba53d8fd13cbb343b177c (diff)
downloadplatform-bootable-recovery-master.tar.gz
platform-bootable-recovery-master.tar.xz
platform-bootable-recovery-master.zip
Merge "tests: Add ApplyPatchModesTest.PatchModeEmmcTargetWithBsdiffPatch test."HEADmaster
-rw-r--r--tests/component/applypatch_test.cpp51
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
42using namespace std::string_literals;
43
41static void sha1sum(const std::string& fname, std::string* sha1, size_t* fsize = nullptr) { 44static 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.
272TEST_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
268TEST_F(ApplyPatchModesTest, PatchModeInvalidArgs) { 319TEST_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" }));