Merge "Simulator: add the argument to keep the updated images" am: c34e4e7fb5 am: be3f56543e
am: 112acdc043
Change-Id: I259f6627b736f979884d1797734562266e44981f
This commit is contained in:
@@ -93,7 +93,7 @@ static void RunSimulation(std::string_view src_tf, std::string_view ota_package,
|
|||||||
|
|
||||||
// Run the update simulation and check the result.
|
// Run the update simulation and check the result.
|
||||||
TemporaryDir work_dir;
|
TemporaryDir work_dir;
|
||||||
BuildInfo build_info(work_dir.path);
|
BuildInfo build_info(work_dir.path, false);
|
||||||
ASSERT_TRUE(build_info.ParseTargetFile(src_tf, false));
|
ASSERT_TRUE(build_info.ParseTargetFile(src_tf, false));
|
||||||
Updater updater(std::make_unique<SimulatorRuntime>(&build_info));
|
Updater updater(std::make_unique<SimulatorRuntime>(&build_info));
|
||||||
ASSERT_TRUE(updater.Init(cmd_pipe.release(), ota_package, false));
|
ASSERT_TRUE(updater.Init(cmd_pipe.release(), ota_package, false));
|
||||||
@@ -211,7 +211,7 @@ TEST_F(UpdateSimulatorTest, BuildInfo_ParseTargetFile) {
|
|||||||
AddZipEntries(zip_file.release(), entries);
|
AddZipEntries(zip_file.release(), entries);
|
||||||
|
|
||||||
TemporaryDir temp_dir;
|
TemporaryDir temp_dir;
|
||||||
BuildInfo build_info(temp_dir.path);
|
BuildInfo build_info(temp_dir.path, false);
|
||||||
ASSERT_TRUE(build_info.ParseTargetFile(zip_file.path, false));
|
ASSERT_TRUE(build_info.ParseTargetFile(zip_file.path, false));
|
||||||
|
|
||||||
std::map<string, string> expected_result = {
|
std::map<string, string> expected_result = {
|
||||||
|
|||||||
+15
-2
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
#include "updater/build_info.h"
|
#include "updater/build_info.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@@ -55,12 +57,23 @@ bool BuildInfo::ParseTargetFile(const std::string_view target_file_path, bool ex
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string mapped_path = image_file.path;
|
||||||
|
// Rename the images to more readable ones if we want to keep the image.
|
||||||
|
if (keep_images_) {
|
||||||
|
mapped_path = work_dir_ + fstab_info.mount_point + ".img";
|
||||||
|
image_file.release();
|
||||||
|
if (rename(image_file.path, mapped_path.c_str()) != 0) {
|
||||||
|
PLOG(ERROR) << "Failed to rename " << image_file.path << " to " << mapped_path;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LOG(INFO) << "Mounted " << fstab_info.mount_point << "\nMapping: " << fstab_info.blockdev_name
|
LOG(INFO) << "Mounted " << fstab_info.mount_point << "\nMapping: " << fstab_info.blockdev_name
|
||||||
<< " to " << image_file.path;
|
<< " to " << mapped_path;
|
||||||
|
|
||||||
blockdev_map_.emplace(
|
blockdev_map_.emplace(
|
||||||
fstab_info.blockdev_name,
|
fstab_info.blockdev_name,
|
||||||
FakeBlockDevice(fstab_info.blockdev_name, fstab_info.mount_point, image_file.path));
|
FakeBlockDevice(fstab_info.blockdev_name, fstab_info.mount_point, mapped_path));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,8 @@ class FakeBlockDevice {
|
|||||||
// query the information and run the update on host.
|
// query the information and run the update on host.
|
||||||
class BuildInfo {
|
class BuildInfo {
|
||||||
public:
|
public:
|
||||||
explicit BuildInfo(const std::string_view work_dir) : work_dir_(work_dir) {}
|
BuildInfo(const std::string_view work_dir, bool keep_images)
|
||||||
|
: work_dir_(work_dir), keep_images_(keep_images) {}
|
||||||
// Returns the value of the build properties.
|
// Returns the value of the build properties.
|
||||||
std::string GetProperty(const std::string_view key, const std::string_view default_value) const;
|
std::string GetProperty(const std::string_view key, const std::string_view default_value) const;
|
||||||
// Returns the path to the mock block device.
|
// Returns the path to the mock block device.
|
||||||
@@ -69,4 +70,5 @@ class BuildInfo {
|
|||||||
|
|
||||||
std::list<TemporaryFile> temp_files_;
|
std::list<TemporaryFile> temp_files_;
|
||||||
std::string work_dir_; // A temporary directory to store the extracted image files
|
std::string work_dir_; // A temporary directory to store the extracted image files
|
||||||
|
bool keep_images_;
|
||||||
};
|
};
|
||||||
|
|||||||
+8
-1
@@ -113,7 +113,7 @@ Value* PackageExtractFileFn(const char* name, State* state,
|
|||||||
argv.size());
|
argv.size());
|
||||||
}
|
}
|
||||||
const std::string& zip_path = args[0];
|
const std::string& zip_path = args[0];
|
||||||
const std::string& dest_path = args[1];
|
std::string dest_path = args[1];
|
||||||
|
|
||||||
ZipArchiveHandle za = state->updater->GetPackageHandle();
|
ZipArchiveHandle za = state->updater->GetPackageHandle();
|
||||||
ZipEntry entry;
|
ZipEntry entry;
|
||||||
@@ -122,6 +122,13 @@ Value* PackageExtractFileFn(const char* name, State* state,
|
|||||||
return StringValue("");
|
return StringValue("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the destination of package_extract_file if it's a block device. During simulation the
|
||||||
|
// destination will map to a fake file.
|
||||||
|
if (std::string block_device_name = state->updater->FindBlockDeviceName(dest_path);
|
||||||
|
!block_device_name.empty()) {
|
||||||
|
dest_path = block_device_name;
|
||||||
|
}
|
||||||
|
|
||||||
android::base::unique_fd fd(TEMP_FAILURE_RETRY(
|
android::base::unique_fd fd(TEMP_FAILURE_RETRY(
|
||||||
open(dest_path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)));
|
open(dest_path.c_str(), O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)));
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
|
|||||||
@@ -58,12 +58,16 @@ int main(int argc, char** argv) {
|
|||||||
std::string skip_function_file;
|
std::string skip_function_file;
|
||||||
std::string source_target_file;
|
std::string source_target_file;
|
||||||
std::string package_name;
|
std::string package_name;
|
||||||
|
std::string work_dir;
|
||||||
|
bool keep_images = false;
|
||||||
|
|
||||||
constexpr struct option OPTIONS[] = {
|
constexpr struct option OPTIONS[] = {
|
||||||
|
{ "keep_images", no_argument, nullptr, 0 },
|
||||||
{ "oem_settings", required_argument, nullptr, 0 },
|
{ "oem_settings", required_argument, nullptr, 0 },
|
||||||
{ "ota_package", required_argument, nullptr, 0 },
|
{ "ota_package", required_argument, nullptr, 0 },
|
||||||
{ "skip_functions", required_argument, nullptr, 0 },
|
{ "skip_functions", required_argument, nullptr, 0 },
|
||||||
{ "source", required_argument, nullptr, 0 },
|
{ "source", required_argument, nullptr, 0 },
|
||||||
|
{ "work_dir", required_argument, nullptr, 0 },
|
||||||
{ nullptr, 0, nullptr, 0 },
|
{ nullptr, 0, nullptr, 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -86,6 +90,10 @@ int main(int argc, char** argv) {
|
|||||||
source_target_file = optarg;
|
source_target_file = optarg;
|
||||||
} else if (option_name == "ota_package"s) {
|
} else if (option_name == "ota_package"s) {
|
||||||
package_name = optarg;
|
package_name = optarg;
|
||||||
|
} else if (option_name == "keep_images"s) {
|
||||||
|
keep_images = true;
|
||||||
|
} else if (option_name == "work_dir"s) {
|
||||||
|
work_dir = optarg;
|
||||||
} else {
|
} else {
|
||||||
Usage(argv[0]);
|
Usage(argv[0]);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@@ -129,8 +137,11 @@ int main(int argc, char** argv) {
|
|||||||
|
|
||||||
TemporaryFile cmd_pipe;
|
TemporaryFile cmd_pipe;
|
||||||
TemporaryDir source_temp_dir;
|
TemporaryDir source_temp_dir;
|
||||||
|
if (work_dir.empty()) {
|
||||||
|
work_dir = source_temp_dir.path;
|
||||||
|
}
|
||||||
|
|
||||||
BuildInfo source_build_info(source_temp_dir.path);
|
BuildInfo source_build_info(work_dir, keep_images);
|
||||||
if (!source_build_info.ParseTargetFile(source_target_file, false)) {
|
if (!source_build_info.ParseTargetFile(source_target_file, false)) {
|
||||||
LOG(ERROR) << "Failed to parse the target file " << source_target_file;
|
LOG(ERROR) << "Failed to parse the target file " << source_target_file;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|||||||
Reference in New Issue
Block a user