summaryrefslogtreecommitdiffstats
path: root/tests/component
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/component/imgdiff_test.cpp51
-rw-r--r--tests/component/updater_test.cpp22
2 files changed, 57 insertions, 16 deletions
diff --git a/tests/component/imgdiff_test.cpp b/tests/component/imgdiff_test.cpp
index 3163a57cf..161d58d45 100644
--- a/tests/component/imgdiff_test.cpp
+++ b/tests/component/imgdiff_test.cpp
@@ -778,10 +778,13 @@ TEST(ImgdiffTest, zip_mode_store_large_apk) {
// Compute patch.
TemporaryFile patch_file;
+ TemporaryFile split_info_file;
TemporaryDir debug_dir;
+ std::string split_info_arg = android::base::StringPrintf("--split-info=%s", split_info_file.path);
+ std::string debug_dir_arg = android::base::StringPrintf("--debug-dir=%s", debug_dir.path);
std::vector<const char*> args = {
- "imgdiff", "-z", "--block-limit=10", android::base::StringPrintf(
- "--debug-dir=%s", debug_dir.path).c_str(), src_file.path, tgt_file.path, patch_file.path,
+ "imgdiff", "-z", "--block-limit=10", split_info_arg.c_str(), debug_dir_arg.c_str(),
+ src_file.path, tgt_file.path, patch_file.path,
};
ASSERT_EQ(0, imgdiff(args.size(), args.data()));
@@ -863,14 +866,40 @@ TEST(ImgdiffTest, zip_mode_deflate_large_apk) {
// Compute patch.
TemporaryFile patch_file;
+ TemporaryFile split_info_file;
TemporaryDir debug_dir;
ASSERT_TRUE(ZipModeImage::GeneratePatches(split_tgt_images, split_src_images, split_src_ranges,
- patch_file.path, debug_dir.path));
+ patch_file.path, split_info_file.path, debug_dir.path));
+
+ // Verify the content of split info.
+ // Expect 5 pieces of patch. ["a","b"; "c"; "d-0"; "d-1"; "e"]
+ std::string split_info_string;
+ android::base::ReadFileToString(split_info_file.path, &split_info_string);
+ std::vector<std::string> info_list =
+ android::base::Split(android::base::Trim(split_info_string), "\n");
+
+ ASSERT_EQ(static_cast<size_t>(7), info_list.size());
+ ASSERT_EQ("2", android::base::Trim(info_list[0]));
+ ASSERT_EQ("5", android::base::Trim(info_list[1]));
+
+ std::vector<size_t> patch_size;
+ for (size_t i = 0; i < 5; i++) {
+ struct stat st = {};
+ std::string path = android::base::StringPrintf("%s/patch-%zu", debug_dir.path, i);
+ ASSERT_EQ(0, stat(path.c_str(), &st));
+ patch_size.push_back(st.st_size);
+ }
+
+ ASSERT_EQ(std::to_string(patch_size[0]) + " 36864 2,22,31", android::base::Trim(info_list[2]));
+ ASSERT_EQ(std::to_string(patch_size[1]) + " 32768 2,31,40", android::base::Trim(info_list[3]));
+ ASSERT_EQ(std::to_string(patch_size[2]) + " 40960 2,0,11", android::base::Trim(info_list[4]));
+ ASSERT_EQ(std::to_string(patch_size[3]) + " 40960 2,11,21", android::base::Trim(info_list[5]));
+ ASSERT_EQ(std::to_string(patch_size[4]) + " 8833 4,21,22,40,41",
+ android::base::Trim(info_list[6]));
std::string tgt;
ASSERT_TRUE(android::base::ReadFileToString(tgt_file.path, &tgt));
- // Expect 5 pieces of patch. ["a","b"; "c"; "d-0"; "d-1"; "e"]
GenerateAndCheckSplitTarget(debug_dir.path, 5, tgt);
}
@@ -900,10 +929,13 @@ TEST(ImgdiffTest, zip_mode_no_match_source) {
// Compute patch.
TemporaryFile patch_file;
+ TemporaryFile split_info_file;
TemporaryDir debug_dir;
+ std::string split_info_arg = android::base::StringPrintf("--split-info=%s", split_info_file.path);
+ std::string debug_dir_arg = android::base::StringPrintf("--debug-dir=%s", debug_dir.path);
std::vector<const char*> args = {
- "imgdiff", "-z", "--block-limit=10", android::base::StringPrintf(
- "--debug-dir=%s", debug_dir.path).c_str(), src_file.path, tgt_file.path, patch_file.path,
+ "imgdiff", "-z", "--block-limit=10", debug_dir_arg.c_str(), split_info_arg.c_str(),
+ src_file.path, tgt_file.path, patch_file.path,
};
ASSERT_EQ(0, imgdiff(args.size(), args.data()));
@@ -939,10 +971,13 @@ TEST(ImgdiffTest, zip_mode_large_enough_limit) {
// Compute patch with a limit of 20 blocks.
TemporaryFile patch_file;
+ TemporaryFile split_info_file;
TemporaryDir debug_dir;
+ std::string split_info_arg = android::base::StringPrintf("--split-info=%s", split_info_file.path);
+ std::string debug_dir_arg = android::base::StringPrintf("--debug-dir=%s", debug_dir.path);
std::vector<const char*> args = {
- "imgdiff", "-z", "--block-limit=20", android::base::StringPrintf(
- "--debug-dir=%s", debug_dir.path).c_str(), src_file.path, tgt_file.path, patch_file.path,
+ "imgdiff", "-z", "--block-limit=20", split_info_arg.c_str(), debug_dir_arg.c_str(),
+ src_file.path, tgt_file.path, patch_file.path,
};
ASSERT_EQ(0, imgdiff(args.size(), args.data()));
diff --git a/tests/component/updater_test.cpp b/tests/component/updater_test.cpp
index 6c341c111..2a0575a31 100644
--- a/tests/component/updater_test.cpp
+++ b/tests/component/updater_test.cpp
@@ -383,7 +383,7 @@ TEST_F(UpdaterTest, set_progress) {
TemporaryFile tf;
UpdaterInfo updater_info;
- updater_info.cmd_pipe = fdopen(tf.fd, "w");
+ updater_info.cmd_pipe = fdopen(tf.release(), "w");
expect(".52", "set_progress(\".52\")", kNoCause, &updater_info);
fflush(updater_info.cmd_pipe);
@@ -392,6 +392,7 @@ TEST_F(UpdaterTest, set_progress) {
ASSERT_EQ(android::base::StringPrintf("set_progress %f\n", .52), cmd);
// recovery-updater protocol expects 2 tokens ("set_progress <frac>").
ASSERT_EQ(2U, android::base::Split(cmd, " ").size());
+ ASSERT_EQ(0, fclose(updater_info.cmd_pipe));
}
TEST_F(UpdaterTest, show_progress) {
@@ -407,7 +408,7 @@ TEST_F(UpdaterTest, show_progress) {
TemporaryFile tf;
UpdaterInfo updater_info;
- updater_info.cmd_pipe = fdopen(tf.fd, "w");
+ updater_info.cmd_pipe = fdopen(tf.release(), "w");
expect(".52", "show_progress(\".52\", \"10\")", kNoCause, &updater_info);
fflush(updater_info.cmd_pipe);
@@ -416,12 +417,13 @@ TEST_F(UpdaterTest, show_progress) {
ASSERT_EQ(android::base::StringPrintf("progress %f %d\n", .52, 10), cmd);
// recovery-updater protocol expects 3 tokens ("progress <frac> <secs>").
ASSERT_EQ(3U, android::base::Split(cmd, " ").size());
+ ASSERT_EQ(0, fclose(updater_info.cmd_pipe));
}
TEST_F(UpdaterTest, block_image_update) {
// Create a zip file with new_data and patch_data.
TemporaryFile zip_file;
- FILE* zip_file_ptr = fdopen(zip_file.fd, "wb");
+ FILE* zip_file_ptr = fdopen(zip_file.release(), "wb");
ZipWriter zip_writer(zip_file_ptr);
// Add a dummy new data.
@@ -485,7 +487,7 @@ TEST_F(UpdaterTest, block_image_update) {
UpdaterInfo updater_info;
updater_info.package_zip = handle;
TemporaryFile temp_pipe;
- updater_info.cmd_pipe = fopen(temp_pipe.path, "wbe");
+ updater_info.cmd_pipe = fdopen(temp_pipe.release(), "wbe");
updater_info.package_zip_addr = map.addr;
updater_info.package_zip_len = map.length;
@@ -518,7 +520,7 @@ TEST_F(UpdaterTest, block_image_update) {
TEST_F(UpdaterTest, new_data_short_write) {
// Create a zip file with new_data.
TemporaryFile zip_file;
- FILE* zip_file_ptr = fdopen(zip_file.fd, "wb");
+ FILE* zip_file_ptr = fdopen(zip_file.release(), "wb");
ZipWriter zip_writer(zip_file_ptr);
// Add the empty new data.
@@ -561,7 +563,7 @@ TEST_F(UpdaterTest, new_data_short_write) {
UpdaterInfo updater_info;
updater_info.package_zip = handle;
TemporaryFile temp_pipe;
- updater_info.cmd_pipe = fopen(temp_pipe.path, "wbe");
+ updater_info.cmd_pipe = fdopen(temp_pipe.release(), "wbe");
updater_info.package_zip_addr = map.addr;
updater_info.package_zip_len = map.length;
@@ -579,13 +581,15 @@ TEST_F(UpdaterTest, new_data_short_write) {
std::string script_exact_data = "block_image_update(\"" + std::string(update_file.path) +
R"(", package_extract_file("transfer_list"), "exact_new_data", "patch_data"))";
expect("t", script_exact_data.c_str(), kNoCause, &updater_info);
+
+ ASSERT_EQ(0, fclose(updater_info.cmd_pipe));
CloseArchive(handle);
}
TEST_F(UpdaterTest, brotli_new_data) {
// Create a zip file with new_data.
TemporaryFile zip_file;
- FILE* zip_file_ptr = fdopen(zip_file.fd, "wb");
+ FILE* zip_file_ptr = fdopen(zip_file.release(), "wb");
ZipWriter zip_writer(zip_file_ptr);
// Add a brotli compressed new data entry.
@@ -639,7 +643,7 @@ TEST_F(UpdaterTest, brotli_new_data) {
UpdaterInfo updater_info;
updater_info.package_zip = handle;
TemporaryFile temp_pipe;
- updater_info.cmd_pipe = fopen(temp_pipe.path, "wb");
+ updater_info.cmd_pipe = fdopen(temp_pipe.release(), "wb");
updater_info.package_zip_addr = map.addr;
updater_info.package_zip_len = map.length;
@@ -653,5 +657,7 @@ TEST_F(UpdaterTest, brotli_new_data) {
std::string updated_content;
ASSERT_TRUE(android::base::ReadFileToString(update_file.path, &updated_content));
ASSERT_EQ(brotli_new_data, updated_content);
+
+ ASSERT_EQ(0, fclose(updater_info.cmd_pipe));
CloseArchive(handle);
}