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

Commit b8e1a605 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 9990577 from 17d95b64 to udc-release

Change-Id: I886d46bc7c8a760a95f552f8896555cd4c200aca
parents b61fd972 17d95b64
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -133,6 +133,7 @@ void syntax_error(const char* fmt, ...);
std::string get_current_slot();

// Code for Parsing fastboot-info.txt
bool CheckFastbootInfoRequirements(const std::vector<std::string>& command);
std::unique_ptr<FlashTask> ParseFlashCommand(const FlashingPlan* fp,
                                             const std::vector<std::string>& parts);
std::unique_ptr<RebootTask> ParseRebootCommand(const FlashingPlan* fp,
+41 −0
Original line number Diff line number Diff line
@@ -53,6 +53,11 @@ static std::vector<std::unique_ptr<Task>> collectTasks(FlashingPlan* fp,
    return tasks;
}

std::unique_ptr<Task> ParseCommand(FlashingPlan* fp, std::string command) {
    std::vector<std::string> vec_command = android::base::Split(command, " ");
    return ParseFastbootInfoLine(fp, vec_command);
}

TEST_F(ParseTest, CORRECT_FlASH_TASK_FORMED) {
    std::vector<std::string> commands = {"flash dtbo", "flash --slot-other system system_other.img",
                                         "flash system", "flash --apply-vbmeta vbmeta"};
@@ -80,3 +85,39 @@ TEST_F(ParseTest, CORRECT_FlASH_TASK_FORMED) {
        ASSERT_EQ(task->GetImageName(), expected_values[i][3]);
    }
}

TEST_F(ParseTest, VERSION_CHECK_CORRRECT) {
    std::vector<std::string> correct_versions = {
            "version 1.0",
            "version 22.00",
    };

    std::vector<std::string> bad_versions = {"version",        "version .01", "version x1",
                                             "version 1.0.1",  "version 1.",  "s 1.0",
                                             "version 1.0 2.0"};

    for (auto& version : correct_versions) {
        ASSERT_TRUE(CheckFastbootInfoRequirements(android::base::Split(version, " "))) << version;
    }
    for (auto& version : bad_versions) {
        ASSERT_FALSE(CheckFastbootInfoRequirements(android::base::Split(version, " "))) << version;
    }
}

TEST_F(ParseTest, BAD_FASTBOOT_INFO_INPUT) {
    ASSERT_EQ(ParseCommand(fp.get(), "flash"), nullptr);
    ASSERT_EQ(ParseCommand(fp.get(), "flash --slot-other --apply-vbmeta"), nullptr);
    ASSERT_EQ(ParseCommand(fp.get(), "flash --apply-vbmeta"), nullptr);
    ASSERT_EQ(ParseCommand(fp.get(), "if-wipe"), nullptr);
    ASSERT_EQ(ParseCommand(fp.get(), "if-wipe flash"), nullptr);
    ASSERT_EQ(ParseCommand(fp.get(), "wipe dtbo"), nullptr);
    ASSERT_EQ(ParseCommand(fp.get(), "update-super dtbo"), nullptr);
    ASSERT_EQ(ParseCommand(fp.get(), "flash system system.img system"), nullptr);
    ASSERT_EQ(ParseCommand(fp.get(), "reboot bootloader fastboot"), nullptr);
    ASSERT_EQ(ParseCommand(fp.get(),
                           "flash --slot-other --apply-vbmeta system system_other.img system"),
              nullptr);
    ASSERT_EQ(ParseCommand(fp.get(), "erase"), nullptr);
    ASSERT_EQ(ParseCommand(fp.get(), "erase dtbo dtbo"), nullptr);
    ASSERT_EQ(ParseCommand(fp.get(), "wipe this"), nullptr);
}