Fastboot-info testing
adding test to compare task list formed from fastboot-info vs list
formed from image list. To test, we need to set sparse_limit in flashing
plan and turn off update-super-optimization. The list of partitions to
be flashed by parsing fastboot-info should be a superset of the
partitions flashed by the hardcoded list. Changing is_retrofit_device()
to also take in a fastboot driver so we can pass in a mock
Test: fastboot_test
Bug: 194686221
Change-Id: Ib860c24c85779de1fbaa6bec8778e1f5ebb9475a
diff --git a/fastboot/fastboot.cpp b/fastboot/fastboot.cpp
index 79c7169..2941216 100644
--- a/fastboot/fastboot.cpp
+++ b/fastboot/fastboot.cpp
@@ -1411,7 +1411,7 @@
}
}
-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 @@
// 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 77430f0..50db25d 100644
--- a/fastboot/fastboot.h
+++ b/fastboot/fastboot.h
@@ -187,7 +187,7 @@
int64_t get_sparse_limit(int64_t size, const FlashingPlan* fp);
std::vector<SparsePtr> 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 b4e139b..1ba3f4a 100644
--- a/fastboot/task_test.cpp
+++ b/fastboot/task_test.cpp
@@ -24,6 +24,7 @@
#include <memory>
#include <unordered_map>
#include "android-base/strings.h"
+
using android::base::Split;
using testing::_;
@@ -60,6 +61,33 @@
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<std::unique_ptr<Task>>& tasks_a,
+ std::vector<std::unique_ptr<Task>>& tasks_b) {
+ std::set<std::string> 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<std::unique_ptr<Task>>& tasks) {
+ std::string output;
+ for (auto& task : tasks) {
+ output.append(task->ToString());
+ output.append("\n");
+ }
+ return output;
+}
+
TEST_F(ParseTest, CorrectFlashTaskFormed) {
std::vector<std::string> commands = {"flash dtbo", "flash --slot-other system system_other.img",
"flash system", "flash --apply-vbmeta vbmeta"};
@@ -159,3 +187,51 @@
task->Run();
}
}
+
+TEST_F(ParseTest, CorrectTaskLists) {
+ if (!get_android_product_out()) {
+ GTEST_SKIP();
+ }
+
+ LocalImageSource s;
+ fp->source = &s;
+ fp->sparse_limit = std::numeric_limits<int64_t>::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();
+}