diff options
author | Mohammad Samiul Islam <samiul@google.com> | 2021-02-26 14:04:17 +0000 |
---|---|---|
committer | Mohammad Islam <samiul@google.com> | 2021-03-17 12:50:13 +0000 |
commit | b0ab865e4a4a7981b8dc316738ca002f9bbe4a46 (patch) | |
tree | 2d5efc8796f00d5744cf0390841c6ebdf8eefbf8 /aosp/apex_handler_android_unittest.cc | |
parent | ebd115e8bd045dfd05889e3574d5a02e7b53b2be (diff) |
Make update_engine reserve space for decompression via apexd
Bug: 172911822
Test: atest ApexHandlerAndroidTest (checked that file was created)
Change-Id: I8024695ebba1a9c1796c05b27a0eec3da3b3d1bc
Diffstat (limited to 'aosp/apex_handler_android_unittest.cc')
-rw-r--r-- | aosp/apex_handler_android_unittest.cc | 100 |
1 files changed, 32 insertions, 68 deletions
diff --git a/aosp/apex_handler_android_unittest.cc b/aosp/apex_handler_android_unittest.cc index 3a99f79b..981ae9dd 100644 --- a/aosp/apex_handler_android_unittest.cc +++ b/aosp/apex_handler_android_unittest.cc @@ -29,81 +29,45 @@ namespace chromeos_update_engine { namespace fs = std::filesystem; -class ApexHandlerAndroidTest : public ::testing::Test { - protected: - ApexHandlerAndroidTest() = default; - - android::sp<android::apex::IApexService> GetApexService() const { - return apex_handler_.GetApexService(); - } - - uint64_t CalculateSize( - const std::vector<ApexInfo>& apex_infos, - android::sp<android::apex::IApexService> apex_service) const { - return apex_handler_.CalculateSize(apex_infos, apex_service); - } - - bool AllocateSpace(const uint64_t size_required, - const std::string& dir_path) const { - return apex_handler_.AllocateSpace(size_required, dir_path); - } - - ApexInfo CreateApexInfo(const std::string& package_name, - int version, - bool is_compressed, - int decompressed_size) { - ApexInfo result; - result.set_package_name(package_name); - result.set_version(version); - result.set_is_compressed(is_compressed); - result.set_decompressed_size(decompressed_size); - return std::move(result); - } - - ApexHandlerAndroid apex_handler_; -}; +ApexInfo CreateApexInfo(const std::string& package_name, + int version, + bool is_compressed, + int decompressed_size) { + ApexInfo result; + result.set_package_name(package_name); + result.set_version(version); + result.set_is_compressed(is_compressed); + result.set_decompressed_size(decompressed_size); + return std::move(result); +} -// TODO(b/172911822): Once apexd has more optimized response for CalculateSize, -// improve this test -TEST_F(ApexHandlerAndroidTest, CalculateSize) { +TEST(ApexHandlerAndroidTest, CalculateSize) { + ApexHandlerAndroid apex_handler; std::vector<ApexInfo> apex_infos; - ApexInfo compressed_apex_1 = CreateApexInfo("sample1", 1, true, 10); - ApexInfo compressed_apex_2 = CreateApexInfo("sample2", 2, true, 20); + ApexInfo compressed_apex_1 = CreateApexInfo("sample1", 1, true, 1); + ApexInfo compressed_apex_2 = CreateApexInfo("sample2", 2, true, 2); + ApexInfo uncompressed_apex = CreateApexInfo("uncompressed", 1, false, 4); apex_infos.push_back(compressed_apex_1); apex_infos.push_back(compressed_apex_2); - auto apex_service = GetApexService(); - EXPECT_TRUE(apex_service != nullptr) << "Apexservice not found"; - int required_size = CalculateSize(apex_infos, apex_service); - EXPECT_EQ(required_size, 30); + apex_infos.push_back(uncompressed_apex); + auto result = apex_handler.CalculateSize(apex_infos); + ASSERT_TRUE(result.ok()); + EXPECT_EQ(*result, 3u); } -TEST_F(ApexHandlerAndroidTest, AllocateSpace) { - // Allocating 0 space should be a no op - TemporaryDir td; - EXPECT_TRUE(AllocateSpace(0, td.path)); - EXPECT_TRUE(fs::is_empty(td.path)); - - // Allocating non-zero space should create a file with tmp suffix - EXPECT_TRUE(AllocateSpace(2 << 20, td.path)); - EXPECT_FALSE(fs::is_empty(td.path)); - int num_of_file = 0; - for (const auto& entry : fs::directory_iterator(td.path)) { - num_of_file++; - EXPECT_TRUE(EndsWith(entry.path().string(), ".tmp")); - EXPECT_EQ(fs::file_size(entry.path()), 2u << 20); - } - EXPECT_EQ(num_of_file, 1); +TEST(ApexHandlerAndroidTest, AllocateSpace) { + ApexHandlerAndroid apex_handler; + std::vector<ApexInfo> apex_infos; + ApexInfo compressed_apex_1 = CreateApexInfo("sample1", 1, true, 1); + ApexInfo compressed_apex_2 = CreateApexInfo("sample2", 2, true, 2); + ApexInfo uncompressed_apex = CreateApexInfo("uncompressed", 1, false, 4); + apex_infos.push_back(compressed_apex_1); + apex_infos.push_back(compressed_apex_2); + apex_infos.push_back(uncompressed_apex); + EXPECT_TRUE(apex_handler.AllocateSpace(apex_infos)); - // AllocateSpace should be safe to call twice - EXPECT_TRUE(AllocateSpace(100, td.path)); - EXPECT_FALSE(fs::is_empty(td.path)); - num_of_file = 0; - for (const auto& entry : fs::directory_iterator(td.path)) { - num_of_file++; - EXPECT_TRUE(EndsWith(entry.path().string(), ".tmp")); - EXPECT_EQ(fs::file_size(entry.path()), 100u); - } - EXPECT_EQ(num_of_file, 1); + // Should be able to pass empty list + EXPECT_TRUE(apex_handler.AllocateSpace({})); } } // namespace chromeos_update_engine |