diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp index 79c71692a..294121696 100644 --- a/fastboot/fastboot.cpp +++ b/fastboot/fastboot.cpp @@ -1411,7 +1411,7 @@ void do_for_partitions(const std::string& part, const std::string& slot, } } -bool is_retrofit_device() { +bool is_retrofit_device(fastboot::IFastBootDriver* fb) { std::string value; if (fb->GetVar("super-partition-name", &value) != fastboot::SUCCESS) { return false; @@ -1878,7 +1878,7 @@ std::vector> FlashAllTool::CollectTasksFromImageList() { // On these devices, secondary slots must be flashed as physical // partitions (otherwise they would not mount on first boot). To enforce // this, we delete any logical partitions for the "other" slot. - if (is_retrofit_device()) { + if (is_retrofit_device(fp_->fb)) { std::string partition_name = image->part_name + "_"s + slot; if (image->IsSecondary() && should_flash_in_userspace(partition_name)) { fp_->fb->DeletePartition(partition_name); diff --git a/fastboot/fastboot.h b/fastboot/fastboot.h index 77430f05a..50db25db0 100644 --- a/fastboot/fastboot.h +++ b/fastboot/fastboot.h @@ -187,7 +187,7 @@ void flash_partition_files(const std::string& partition, const std::vector resparse_file(sparse_file* s, int64_t max_size); -bool is_retrofit_device(); +bool is_retrofit_device(fastboot::IFastBootDriver* fb); bool is_logical(const std::string& partition); void fb_perform_format(const std::string& partition, int skip_if_not_supported, const std::string& type_override, const std::string& size_override, diff --git a/fastboot/task_test.cpp b/fastboot/task_test.cpp index b4e139b8d..1ba3f4ae4 100644 --- a/fastboot/task_test.cpp +++ b/fastboot/task_test.cpp @@ -24,6 +24,7 @@ #include #include #include "android-base/strings.h" + using android::base::Split; using testing::_; @@ -60,6 +61,33 @@ std::unique_ptr ParseCommand(FlashingPlan* fp, std::string command) { return ParseFastbootInfoLine(fp, vec_command); } +// tests if tasks_a is a superset of tasks_b. Used for checking to ensure all partitions flashed +// from hardcoded image list is also flashed in new fastboot-info.txt +static bool compareTaskList(std::vector>& tasks_a, + std::vector>& tasks_b) { + std::set list; + for (auto& task : tasks_a) { + list.insert(task->ToString()); + } + for (auto& task : tasks_b) { + if (list.find(task->ToString()) == list.end()) { + std::cout << "ERROR: " << task->ToString() + << " not found in task list created by fastboot-info.txt"; + return false; + } + } + return true; +} + +static std::string tasksToString(std::vector>& tasks) { + std::string output; + for (auto& task : tasks) { + output.append(task->ToString()); + output.append("\n"); + } + return output; +} + TEST_F(ParseTest, CorrectFlashTaskFormed) { std::vector commands = {"flash dtbo", "flash --slot-other system system_other.img", "flash system", "flash --apply-vbmeta vbmeta"}; @@ -159,3 +187,51 @@ TEST_F(ParseTest, CorrectDriverCalls) { task->Run(); } } + +TEST_F(ParseTest, CorrectTaskLists) { + if (!get_android_product_out()) { + GTEST_SKIP(); + } + + LocalImageSource s; + fp->source = &s; + fp->sparse_limit = std::numeric_limits::max(); + + fastboot::MockFastbootDriver fb; + fp->fb = &fb; + fp->should_optimize_flash_super = false; + + ON_CALL(fb, GetVar("super-partition-name", _, _)) + .WillByDefault(testing::Return(fastboot::BAD_ARG)); + + FlashAllTool tool(fp.get()); + + fp->should_use_fastboot_info = false; + auto hardcoded_tasks = tool.CollectTasks(); + fp->should_use_fastboot_info = true; + auto fastboot_info_tasks = tool.CollectTasks(); + + auto is_non_flash_task = [](const auto& task) -> bool { + return task->AsFlashTask() == nullptr; + }; + + // remove non flash tasks for testing purposes + hardcoded_tasks.erase( + std::remove_if(hardcoded_tasks.begin(), hardcoded_tasks.end(), is_non_flash_task), + hardcoded_tasks.end()); + fastboot_info_tasks.erase(std::remove_if(fastboot_info_tasks.begin(), fastboot_info_tasks.end(), + is_non_flash_task), + fastboot_info_tasks.end()); + + if (!compareTaskList(fastboot_info_tasks, hardcoded_tasks)) { + std::cout << "\n\n---Hardcoded Task List---\n" + << tasksToString(hardcoded_tasks) << "\n---Fastboot-Info Task List---\n" + << tasksToString(fastboot_info_tasks); + } + + ASSERT_TRUE(compareTaskList(fastboot_info_tasks, hardcoded_tasks)); + + ASSERT_TRUE(fastboot_info_tasks.size() >= hardcoded_tasks.size()) + << "size of fastboot-info task list: " << fastboot_info_tasks.size() + << " size of hardcoded task list: " << hardcoded_tasks.size(); +}