summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2018-07-12 01:39:49 +0200
committerandroid-build-merger <android-build-merger@google.com>2018-07-12 01:39:49 +0200
commitad7beb410d7c54373bf13962a78762f0d740ff78 (patch)
treebef29e741fd384e46b786033678f6c3aceb9415c
parentMerge "updater: Let read_file() return Value::Type::STRING." am: ac234b4493 am: e089c1a149 (diff)
parentMerge "Remove the debug code for bspatch flakiness" am: a9f9acca91 (diff)
downloadandroid_bootable_recovery-ad7beb410d7c54373bf13962a78762f0d740ff78.tar
android_bootable_recovery-ad7beb410d7c54373bf13962a78762f0d740ff78.tar.gz
android_bootable_recovery-ad7beb410d7c54373bf13962a78762f0d740ff78.tar.bz2
android_bootable_recovery-ad7beb410d7c54373bf13962a78762f0d740ff78.tar.lz
android_bootable_recovery-ad7beb410d7c54373bf13962a78762f0d740ff78.tar.xz
android_bootable_recovery-ad7beb410d7c54373bf13962a78762f0d740ff78.tar.zst
android_bootable_recovery-ad7beb410d7c54373bf13962a78762f0d740ff78.zip
-rw-r--r--applypatch/applypatch.cpp13
-rw-r--r--applypatch/imgpatch.cpp21
-rw-r--r--tests/component/applypatch_modes_test.cpp68
3 files changed, 4 insertions, 98 deletions
diff --git a/applypatch/applypatch.cpp b/applypatch/applypatch.cpp
index b1f5607a6..eb0a2a7b5 100644
--- a/applypatch/applypatch.cpp
+++ b/applypatch/applypatch.cpp
@@ -587,11 +587,6 @@ static int GenerateTarget(const FileContents& source_file, const std::unique_ptr
SHA_CTX ctx;
SHA1_Init(&ctx);
SinkFn sink = [&memory_sink_str, &ctx](const unsigned char* data, size_t len) {
- if (len != 0) {
- uint8_t digest[SHA_DIGEST_LENGTH];
- SHA1(data, len, digest);
- LOG(DEBUG) << "Appending " << len << " bytes data, SHA-1: " << short_sha1(digest);
- }
SHA1_Update(&ctx, data, len);
memory_sink_str.append(reinterpret_cast<const char*>(data), len);
return len;
@@ -632,14 +627,6 @@ static int GenerateTarget(const FileContents& source_file, const std::unique_ptr
<< short_sha1(bonus_digest);
}
- // TODO(b/67849209) Remove after debugging the unit test flakiness.
- if (android::base::GetMinimumLogSeverity() <= android::base::LogSeverity::DEBUG) {
- if (WriteToPartition(reinterpret_cast<const unsigned char*>(memory_sink_str.c_str()),
- memory_sink_str.size(), target_filename) != 0) {
- LOG(DEBUG) << "Failed to write patched data " << target_filename;
- }
- }
-
return 1;
} else {
LOG(INFO) << " now " << short_sha1(target_sha1);
diff --git a/applypatch/imgpatch.cpp b/applypatch/imgpatch.cpp
index da7569219..e6be39a2f 100644
--- a/applypatch/imgpatch.cpp
+++ b/applypatch/imgpatch.cpp
@@ -61,11 +61,6 @@ static bool ApplyBSDiffPatchAndStreamOutput(const uint8_t* src_data, size_t src_
int mem_level = Read4(deflate_header + 52);
int strategy = Read4(deflate_header + 56);
- // TODO(b/67849209) Remove after debugging the unit test flakiness.
- if (android::base::GetMinimumLogSeverity() <= android::base::LogSeverity::DEBUG) {
- LOG(DEBUG) << "zlib version " << zlibVersion();
- }
-
z_stream strm;
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
@@ -83,10 +78,8 @@ static bool ApplyBSDiffPatchAndStreamOutput(const uint8_t* src_data, size_t src_
size_t actual_target_length = 0;
size_t total_written = 0;
static constexpr size_t buffer_size = 32768;
- SHA_CTX sha_ctx;
- SHA1_Init(&sha_ctx);
auto compression_sink = [&strm, &actual_target_length, &expected_target_length, &total_written,
- &ret, &sink, &sha_ctx](const uint8_t* data, size_t len) -> size_t {
+ &ret, &sink](const uint8_t* data, size_t len) -> size_t {
// The input patch length for an update never exceeds INT_MAX.
strm.avail_in = len;
strm.next_in = data;
@@ -113,11 +106,6 @@ static bool ApplyBSDiffPatchAndStreamOutput(const uint8_t* src_data, size_t src_
}
} while ((strm.avail_in != 0 || strm.avail_out == 0) && ret != Z_STREAM_END);
- // TODO(b/67849209) Remove after debugging the unit test flakiness.
- if (android::base::GetMinimumLogSeverity() <= android::base::LogSeverity::DEBUG) {
- SHA1_Update(&sha_ctx, data, len);
- }
-
actual_target_length += len;
return len;
};
@@ -125,11 +113,6 @@ static bool ApplyBSDiffPatchAndStreamOutput(const uint8_t* src_data, size_t src_
int bspatch_result = ApplyBSDiffPatch(src_data, src_len, patch, patch_offset, compression_sink);
deflateEnd(&strm);
- if (android::base::GetMinimumLogSeverity() <= android::base::LogSeverity::DEBUG) {
- uint8_t digest[SHA_DIGEST_LENGTH];
- SHA1_Final(digest, &sha_ctx);
- LOG(DEBUG) << "sha1 of " << actual_target_length << " bytes input data: " << short_sha1(digest);
- }
if (bspatch_result != 0) {
return false;
}
@@ -144,7 +127,7 @@ static bool ApplyBSDiffPatchAndStreamOutput(const uint8_t* src_data, size_t src_
<< actual_target_length;
return false;
}
- LOG(DEBUG) << "bspatch writes " << total_written << " bytes in total to streaming output.";
+ LOG(DEBUG) << "bspatch wrote " << total_written << " bytes in total to streaming output.";
return true;
}
diff --git a/tests/component/applypatch_modes_test.cpp b/tests/component/applypatch_modes_test.cpp
index b0a52b1e8..bfdc9cabd 100644
--- a/tests/component/applypatch_modes_test.cpp
+++ b/tests/component/applypatch_modes_test.cpp
@@ -21,13 +21,11 @@
#include <vector>
#include <android-base/file.h>
-#include <android-base/logging.h>
#include <android-base/stringprintf.h>
#include <android-base/test_utils.h>
#include <bsdiff/bsdiff.h>
#include <gtest/gtest.h>
#include <openssl/sha.h>
-#include <zlib.h>
#include "applypatch/applypatch_modes.h"
#include "common/test_constants.h"
@@ -36,47 +34,6 @@
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);
@@ -92,20 +49,10 @@ static void sha1sum(const std::string& fname, std::string* sha1, size_t* fsize =
*sha1 = print_sha1(digest);
}
-static void test_logger(android::base::LogId /* id */, android::base::LogSeverity severity,
- const char* /* tag */, const char* /* file */, unsigned int /* line */,
- const char* message) {
- if (severity >= android::base::GetMinimumLogSeverity()) {
- fprintf(stdout, "%s\n", message);
- }
-}
-
class ApplyPatchModesTest : public ::testing::Test {
protected:
void SetUp() override {
Paths::Get().set_cache_temp_source(cache_source.path);
- android::base::InitLogging(nullptr, &test_logger);
- android::base::SetMinimumLogSeverity(android::base::LogSeverity::DEBUG);
}
TemporaryFile cache_source;
@@ -178,10 +125,7 @@ TEST_F(ApplyPatchModesTest, PatchModeEmmcTargetWithoutBonusFile) {
recovery_img_size_arg.c_str(),
patch_arg.c_str() };
- if (applypatch_modes(args.size(), args.data()) != 0) {
- DecompressAndDumpRecoveryImage(tgt_file.path);
- FAIL();
- }
+ ASSERT_EQ(0, applypatch_modes(args.size(), args.data()));
}
TEST_F(ApplyPatchModesTest, PatchModeEmmcTargetWithMultiplePatches) {
@@ -219,16 +163,8 @@ TEST_F(ApplyPatchModesTest, PatchModeEmmcTargetWithMultiplePatches) {
patch1.c_str(),
patch2.c_str(),
patch3.c_str() };
- // TODO(b/67849209): Remove after addressing the flakiness.
- printf("Calling applypatch_modes with the following args:\n");
- for (const auto& arg : args) {
- printf(" %s\n", arg);
- }
- if (applypatch_modes(args.size(), args.data()) != 0) {
- DecompressAndDumpRecoveryImage(tgt_file.path);
- FAIL();
- }
+ ASSERT_EQ(0, applypatch_modes(args.size(), args.data()));
}
// Ensures that applypatch works with a bsdiff based recovery-from-boot.p.