summaryrefslogtreecommitdiffstats
path: root/tests/component
diff options
context:
space:
mode:
authorTianjie Xu <xunchang@google.com>2018-04-26 02:19:20 +0200
committerTianjie Xu <xunchang@google.com>2018-04-26 05:00:56 +0200
commit9e1ccd47b49199b728afb06b28aa7987b5d65960 (patch)
treed9f64a67bd53fc014c562e34d726f8f3b9fca1a8 /tests/component
parentMerge "sample_updater: add non-streaming demo" (diff)
downloadandroid_bootable_recovery-9e1ccd47b49199b728afb06b28aa7987b5d65960.tar
android_bootable_recovery-9e1ccd47b49199b728afb06b28aa7987b5d65960.tar.gz
android_bootable_recovery-9e1ccd47b49199b728afb06b28aa7987b5d65960.tar.bz2
android_bootable_recovery-9e1ccd47b49199b728afb06b28aa7987b5d65960.tar.lz
android_bootable_recovery-9e1ccd47b49199b728afb06b28aa7987b5d65960.tar.xz
android_bootable_recovery-9e1ccd47b49199b728afb06b28aa7987b5d65960.tar.zst
android_bootable_recovery-9e1ccd47b49199b728afb06b28aa7987b5d65960.zip
Diffstat (limited to 'tests/component')
-rw-r--r--tests/component/applypatch_test.cpp54
1 files changed, 52 insertions, 2 deletions
diff --git a/tests/component/applypatch_test.cpp b/tests/component/applypatch_test.cpp
index 292d76e43..04055b9fe 100644
--- a/tests/component/applypatch_test.cpp
+++ b/tests/component/applypatch_test.cpp
@@ -37,6 +37,7 @@
#include <android-base/unique_fd.h>
#include <bsdiff/bsdiff.h>
#include <openssl/sha.h>
+#include <zlib.h>
#include "applypatch/applypatch.h"
#include "applypatch/applypatch_modes.h"
@@ -46,6 +47,47 @@
using namespace std::string_literals;
+// TODO(b/67849209) Remove after debug the flakiness.
+static void DecompressAndDumpRecoveryImage(const std::string& image_path) {
+ // Expected recovery_image structure
+ // chunk normal: 45066 bytes
+ // chunk deflate: 479442 bytes
+ // chunk normal: 5199 bytes
+ std::string recovery_content;
+ ASSERT_TRUE(android::base::ReadFileToString(image_path, &recovery_content));
+ ASSERT_GT(recovery_content.size(), 45066 + 5199);
+
+ z_stream strm = {};
+ strm.avail_in = recovery_content.size() - 45066 - 5199;
+ strm.next_in =
+ const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(recovery_content.data())) + 45066;
+
+ ASSERT_EQ(Z_OK, inflateInit2(&strm, -15));
+
+ constexpr unsigned int BUFFER_SIZE = 32768;
+ std::vector<uint8_t> uncompressed_data(BUFFER_SIZE);
+ size_t uncompressed_length = 0;
+ SHA_CTX ctx;
+ SHA1_Init(&ctx);
+ int ret;
+ do {
+ strm.avail_out = BUFFER_SIZE;
+ strm.next_out = uncompressed_data.data();
+
+ ret = inflate(&strm, Z_NO_FLUSH);
+ ASSERT_GE(ret, 0);
+
+ SHA1_Update(&ctx, uncompressed_data.data(), BUFFER_SIZE - strm.avail_out);
+ uncompressed_length += BUFFER_SIZE - strm.avail_out;
+ } while (ret != Z_STREAM_END);
+ inflateEnd(&strm);
+
+ uint8_t digest[SHA_DIGEST_LENGTH];
+ SHA1_Final(digest, &ctx);
+ GTEST_LOG_(INFO) << "uncompressed length " << uncompressed_length
+ << " sha1: " << short_sha1(digest);
+}
+
static void sha1sum(const std::string& fname, std::string* sha1, size_t* fsize = nullptr) {
ASSERT_TRUE(sha1 != nullptr);
@@ -317,7 +359,11 @@ TEST_F(ApplyPatchModesTest, PatchModeEmmcTargetWithoutBonusFile) {
recovery_img_sha1.c_str(),
recovery_img_size_arg.c_str(),
patch_arg.c_str() };
- ASSERT_EQ(0, applypatch_modes(args.size(), args.data()));
+
+ if (applypatch_modes(args.size(), args.data()) != 0) {
+ DecompressAndDumpRecoveryImage(tgt_file.path);
+ FAIL();
+ }
}
TEST_F(ApplyPatchModesTest, PatchModeEmmcTargetWithMultiplePatches) {
@@ -360,7 +406,11 @@ TEST_F(ApplyPatchModesTest, PatchModeEmmcTargetWithMultiplePatches) {
for (const auto& arg : args) {
printf(" %s\n", arg);
}
- ASSERT_EQ(0, applypatch_modes(args.size(), args.data()));
+
+ if (applypatch_modes(args.size(), args.data()) != 0) {
+ DecompressAndDumpRecoveryImage(tgt_file.path);
+ FAIL();
+ }
}
// Ensures that applypatch works with a bsdiff based recovery-from-boot.p.