diff options
author | Yifan Hong <elsk@google.com> | 2021-03-05 18:57:22 -0800 |
---|---|---|
committer | Yifan Hong <elsk@google.com> | 2021-03-17 15:38:06 -0700 |
commit | f09c1efd0af0fa35d751153f074a0e83b01e306b (patch) | |
tree | 600391526990bda37ff26b4668260acf527cf7b5 /fastboot/fuzzy_fastboot/main.cpp | |
parent | 2a7a14bfc464e0302b391a2551d1b25c683b160e (diff) |
fuzzy_fastboot: Add tests for fetch:vendor_boot
Test: run test against bootloader
Test: run test against fastbootd
Bug: 173654501
Change-Id: Ia3182b4f4390048139d2cafe9b1654b6fb92eb7b
Diffstat (limited to 'fastboot/fuzzy_fastboot/main.cpp')
-rw-r--r-- | fastboot/fuzzy_fastboot/main.cpp | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/fastboot/fuzzy_fastboot/main.cpp b/fastboot/fuzzy_fastboot/main.cpp index 6dbcf4a50..b6beaf93a 100644 --- a/fastboot/fuzzy_fastboot/main.cpp +++ b/fastboot/fuzzy_fastboot/main.cpp @@ -43,8 +43,10 @@ #include <thread> #include <vector> +#include <android-base/file.h> #include <android-base/parseint.h> #include <android-base/stringprintf.h> +#include <android-base/strings.h> #include <gtest/gtest.h> #include <sparse/sparse.h> @@ -669,6 +671,33 @@ TEST_F(UnlockPermissions, DownloadFlash) { EXPECT_EQ(fb->Partitions(&parts), SUCCESS) << "getvar:all failed in unlocked mode"; } +// If the implementation supports getvar:max-fetch-size, it must also support fetch:vendor_boot*. +TEST_F(UnlockPermissions, FetchVendorBoot) { + std::string var; + uint64_t fetch_size; + if (fb->GetVar("max-fetch-size", &var) != SUCCESS) { + GTEST_SKIP() << "This test is skipped because fetch is not supported."; + } + ASSERT_FALSE(var.empty()); + ASSERT_TRUE(android::base::ParseUint(var, &fetch_size)) << var << " is not an integer"; + std::vector<std::tuple<std::string, uint64_t>> parts; + EXPECT_EQ(fb->Partitions(&parts), SUCCESS) << "getvar:all failed"; + for (const auto& [partition, partition_size] : parts) { + if (!android::base::StartsWith(partition, "vendor_boot")) continue; + TemporaryFile fetched; + + uint64_t offset = 0; + while (offset < partition_size) { + uint64_t chunk_size = std::min(fetch_size, partition_size - offset); + auto ret = fb->FetchToFd(partition, fetched.fd, offset, chunk_size); + ASSERT_EQ(fastboot::RetCode::SUCCESS, ret) + << "Unable to fetch " << partition << " (offset=" << offset + << ", size=" << chunk_size << ")"; + offset += chunk_size; + } + } +} + TEST_F(LockPermissions, DownloadFlash) { std::vector<char> buf{'a', 'o', 's', 'p'}; EXPECT_EQ(fb->Download(buf), SUCCESS) << "Download failed in locked mode"; @@ -730,6 +759,16 @@ TEST_F(LockPermissions, Boot) { EXPECT_GT(resp.size(), 0) << "No error message was returned by device after FAIL"; } +TEST_F(LockPermissions, FetchVendorBoot) { + std::vector<std::tuple<std::string, uint64_t>> parts; + EXPECT_EQ(fb->Partitions(&parts), SUCCESS) << "getvar:all failed"; + for (const auto& [partition, _] : parts) { + TemporaryFile fetched; + ASSERT_EQ(fb->FetchToFd(partition, fetched.fd, 0, 0), DEVICE_FAIL) + << "fetch:" << partition << ":0:0 did not fail in locked mode"; + } +} + TEST_F(Fuzz, DownloadSize) { std::string var; EXPECT_EQ(fb->GetVar("max-download-size", &var), SUCCESS) << "getvar:max-download-size failed"; |