Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit dc8ae8c5 authored by Daniel Zheng's avatar Daniel Zheng Committed by Gerrit Code Review
Browse files

Merge "Fastboot-info testing" into main

parents e1a473cd eabfe272
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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<std::unique_ptr<Task>> 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);
+1 −1
Original line number Diff line number Diff line
@@ -187,7 +187,7 @@ void flash_partition_files(const std::string& partition, const std::vector<Spars
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,
+76 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include <memory>
#include <unordered_map>
#include "android-base/strings.h"

using android::base::Split;
using testing::_;

@@ -60,6 +61,33 @@ std::unique_ptr<Task> 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<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 @@ 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<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();
}