Merge "Dump debug information for apply_patch unit tests" am: fe527cced4
am: 943c2057ad
Change-Id: If76814a3e45b6f199f2cfe5d8da7a176d37a573f
This commit is contained in:
@@ -630,6 +630,11 @@ static int GenerateTarget(const FileContents& source_file, const std::unique_ptr
|
|||||||
SHA_CTX ctx;
|
SHA_CTX ctx;
|
||||||
SHA1_Init(&ctx);
|
SHA1_Init(&ctx);
|
||||||
SinkFn sink = [&memory_sink_str, &ctx](const unsigned char* data, size_t len) {
|
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, sha1: " << short_sha1(digest);
|
||||||
|
}
|
||||||
SHA1_Update(&ctx, data, len);
|
SHA1_Update(&ctx, data, len);
|
||||||
memory_sink_str.append(reinterpret_cast<const char*>(data), len);
|
memory_sink_str.append(reinterpret_cast<const char*>(data), len);
|
||||||
return len;
|
return len;
|
||||||
|
|||||||
@@ -182,6 +182,8 @@ int ApplyImagePatch(const unsigned char* old_data, size_t old_size, const Value&
|
|||||||
printf("Failed to apply bsdiff patch.\n");
|
printf("Failed to apply bsdiff patch.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG(DEBUG) << "Processed chunk type normal";
|
||||||
} else if (type == CHUNK_RAW) {
|
} else if (type == CHUNK_RAW) {
|
||||||
const char* raw_header = patch_header + pos;
|
const char* raw_header = patch_header + pos;
|
||||||
pos += 4;
|
pos += 4;
|
||||||
@@ -201,6 +203,8 @@ int ApplyImagePatch(const unsigned char* old_data, size_t old_size, const Value&
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
pos += data_len;
|
pos += data_len;
|
||||||
|
|
||||||
|
LOG(DEBUG) << "Processed chunk type raw";
|
||||||
} else if (type == CHUNK_DEFLATE) {
|
} else if (type == CHUNK_DEFLATE) {
|
||||||
// deflate chunks have an additional 60 bytes in their chunk header.
|
// deflate chunks have an additional 60 bytes in their chunk header.
|
||||||
const char* deflate_header = patch_header + pos;
|
const char* deflate_header = patch_header + pos;
|
||||||
@@ -276,6 +280,7 @@ int ApplyImagePatch(const unsigned char* old_data, size_t old_size, const Value&
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LOG(DEBUG) << "Processed chunk type deflate";
|
||||||
} else {
|
} else {
|
||||||
printf("patch chunk %d is unknown type %d\n", i, type);
|
printf("patch chunk %d is unknown type %d\n", i, type);
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <android-base/file.h>
|
#include <android-base/file.h>
|
||||||
|
#include <android-base/logging.h>
|
||||||
#include <android-base/stringprintf.h>
|
#include <android-base/stringprintf.h>
|
||||||
#include <android-base/test_utils.h>
|
#include <android-base/test_utils.h>
|
||||||
#include <android-base/unique_fd.h>
|
#include <android-base/unique_fd.h>
|
||||||
@@ -46,7 +47,7 @@
|
|||||||
using namespace std::string_literals;
|
using namespace std::string_literals;
|
||||||
|
|
||||||
static void sha1sum(const std::string& fname, std::string* sha1, size_t* fsize = nullptr) {
|
static void sha1sum(const std::string& fname, std::string* sha1, size_t* fsize = nullptr) {
|
||||||
ASSERT_NE(nullptr, sha1);
|
ASSERT_TRUE(sha1 != nullptr);
|
||||||
|
|
||||||
std::string data;
|
std::string data;
|
||||||
ASSERT_TRUE(android::base::ReadFileToString(fname, &data));
|
ASSERT_TRUE(android::base::ReadFileToString(fname, &data));
|
||||||
@@ -68,6 +69,14 @@ static void mangle_file(const std::string& fname) {
|
|||||||
ASSERT_TRUE(android::base::WriteStringToFile(content, fname));
|
ASSERT_TRUE(android::base::WriteStringToFile(content, fname));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 ApplyPatchTest : public ::testing::Test {
|
class ApplyPatchTest : public ::testing::Test {
|
||||||
public:
|
public:
|
||||||
virtual void SetUp() override {
|
virtual void SetUp() override {
|
||||||
@@ -109,6 +118,8 @@ class ApplyPatchModesTest : public ::testing::Test {
|
|||||||
protected:
|
protected:
|
||||||
void SetUp() override {
|
void SetUp() override {
|
||||||
CacheLocation::location().set_cache_temp_source(cache_source.path);
|
CacheLocation::location().set_cache_temp_source(cache_source.path);
|
||||||
|
android::base::InitLogging(nullptr, &test_logger);
|
||||||
|
android::base::SetMinimumLogSeverity(android::base::LogSeverity::DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
TemporaryFile cache_source;
|
TemporaryFile cache_source;
|
||||||
|
|||||||
Reference in New Issue
Block a user