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

Commit 2a7a14bf authored by Yifan Hong's avatar Yifan Hong
Browse files

fuzzy_fastboot: Add conformance test for getvar:max-fetch-size.

Test: run against bootloader
Test: run against fastbootd
Bug: 173654501
Change-Id: Ide38eee6b801110fef52f0f9213c038a72c775f2
parent e71fe244
Loading
Loading
Loading
Loading
+26 −13
Original line number Diff line number Diff line
@@ -349,22 +349,35 @@ TEST_F(Conformance, GetVarBattVoltageOk) {
    EXPECT_TRUE(var == "yes" || var == "no") << "getvar:battery-soc-ok must be 'yes' or 'no'";
}

TEST_F(Conformance, GetVarDownloadSize) {
    std::string var;
    EXPECT_EQ(fb->GetVar("max-download-size", &var), SUCCESS) << "getvar:max-download-size failed";
    EXPECT_NE(var, "") << "getvar:max-download-size responded with empty string";
void AssertHexUint32(const std::string& name, const std::string& var) {
    ASSERT_NE(var, "") << "getvar:" << name << " responded with empty string";
    // This must start with 0x
    EXPECT_FALSE(isspace(var.front()))
            << "getvar:max-download-size responded with a string with leading whitespace";
    EXPECT_FALSE(var.compare(0, 2, "0x"))
            << "getvar:max-download-size responded with a string that does not start with 0x...";
    ASSERT_FALSE(isspace(var.front()))
            << "getvar:" << name << " responded with a string with leading whitespace";
    ASSERT_FALSE(var.compare(0, 2, "0x"))
            << "getvar:" << name << " responded with a string that does not start with 0x...";
    int64_t size = strtoll(var.c_str(), nullptr, 16);
    EXPECT_GT(size, 0) << "'" + var + "' is not a valid response from getvar:max-download-size";
    ASSERT_GT(size, 0) << "'" + var + "' is not a valid response from getvar:" << name;
    // At most 32-bits
    EXPECT_LE(size, std::numeric_limits<uint32_t>::max())
            << "getvar:max-download-size must fit in a uint32_t";
    EXPECT_LE(var.size(), FB_RESPONSE_SZ - 4)
            << "getvar:max-download-size responded with too large of string: " + var;
    ASSERT_LE(size, std::numeric_limits<uint32_t>::max())
            << "getvar:" << name << " must fit in a uint32_t";
    ASSERT_LE(var.size(), FB_RESPONSE_SZ - 4)
            << "getvar:" << name << " responded with too large of string: " + var;
}

TEST_F(Conformance, GetVarDownloadSize) {
    std::string var;
    EXPECT_EQ(fb->GetVar("max-download-size", &var), SUCCESS) << "getvar:max-download-size failed";
    AssertHexUint32("max-download-size", var);
}

// If fetch is supported, getvar:max-fetch-size must return a hex string.
TEST_F(Conformance, GetVarFetchSize) {
    std::string var;
    if (SUCCESS != fb->GetVar("max-fetch-size", &var)) {
        GTEST_SKIP() << "getvar:max-fetch-size failed";
    }
    AssertHexUint32("max-fetch-size", var);
}

TEST_F(Conformance, GetVarAll) {