Loading fs_mgr/libfs_avb/tests/util_test.cpp +4 −7 Original line number Diff line number Diff line Loading @@ -232,8 +232,7 @@ TEST(BasicUtilTest, ListFiles) { // List files for comparison. auto result = ListFiles(test_dir.value()); ASSERT_TRUE(result); ASSERT_TRUE(result.has_value()); ASSERT_RESULT_OK(result); auto files = result.value(); EXPECT_EQ(3UL, files.size()); // Sort them offline for comparison. Loading Loading @@ -266,8 +265,7 @@ TEST(BasicUtilTest, ListFilesShouldDiscardSymlink) { // List files for comparison. auto result = ListFiles(test_dir.value()); ASSERT_TRUE(result); ASSERT_TRUE(result.has_value()); ASSERT_RESULT_OK(result); auto files = result.value(); EXPECT_EQ(2UL, files.size()); // Should not include the symlink file. // Sort them offline for comparison. Loading @@ -287,7 +285,7 @@ TEST(BasicUtilTest, ListFilesOpenDirFailure) { base::FilePath no_such_dir = tmp_dir.Append("not_such_dir"); auto fail = ListFiles(no_such_dir.value()); ASSERT_FALSE(fail); ASSERT_FALSE(fail.ok()); EXPECT_EQ(ENOENT, fail.error().code()); EXPECT_TRUE(android::base::StartsWith(fail.error().message(), "Failed to opendir: ")); } Loading @@ -303,8 +301,7 @@ TEST(BasicUtilTest, ListFilesEmptyDir) { // List files without sorting. auto result = ListFiles(test_dir.value()); ASSERT_TRUE(result); ASSERT_TRUE(result.has_value()); ASSERT_RESULT_OK(result); auto files = result.value(); EXPECT_EQ(0UL, files.size()); Loading fs_mgr/libvbmeta/builder.cpp +10 −10 Original line number Diff line number Diff line Loading @@ -40,18 +40,18 @@ SuperVBMetaBuilder::SuperVBMetaBuilder(const int super_vbmeta_fd, Result<void> SuperVBMetaBuilder::Build() { for (const auto& [vbmeta_name, file_path] : images_path_) { Result<std::string> content = ReadVBMetaImageFromFile(file_path); if (!content) { if (!content.ok()) { return content.error(); } Result<uint8_t> vbmeta_index = AddVBMetaImage(vbmeta_name); if (!vbmeta_index) { if (!vbmeta_index.ok()) { return vbmeta_index.error(); } Result<void> rv_export_vbmeta_image = ExportVBMetaImageToFile(vbmeta_index.value(), content.value()); if (!rv_export_vbmeta_image) { if (!rv_export_vbmeta_image.ok()) { return rv_export_vbmeta_image; } } Loading @@ -65,7 +65,7 @@ Result<std::string> SuperVBMetaBuilder::ReadVBMetaImageFromFile(const std::strin } Result<uint64_t> file_size = GetFileSize(source_fd); if (!file_size) { if (!file_size.ok()) { return file_size.error(); } Loading Loading @@ -98,7 +98,7 @@ Result<uint8_t> SuperVBMetaBuilder::AddVBMetaImage(const std::string& vbmeta_nam slot_number = desc->vbmeta_index; } else { Result<uint8_t> new_slot = GetEmptySlot(); if (!new_slot) { if (!new_slot.ok()) { return new_slot; } slot_number = new_slot.value(); Loading Loading @@ -162,7 +162,7 @@ Result<void> SuperVBMetaBuilder::ExportVBMetaTableToFile() { android::base::Result<void> rv_write_primary_vbmeta_table = WritePrimaryVBMetaTable(super_vbmeta_fd_, serialized_table); if (!rv_write_primary_vbmeta_table) { if (!rv_write_primary_vbmeta_table.ok()) { return rv_write_primary_vbmeta_table; } Loading @@ -175,7 +175,7 @@ Result<void> SuperVBMetaBuilder::ExportVBMetaImageToFile(const uint8_t vbmeta_in const std::string& vbmeta_image) { Result<void> rv_write_vbmeta_image = WriteVBMetaImage(super_vbmeta_fd_, vbmeta_index, vbmeta_image); if (!rv_write_vbmeta_image) { if (!rv_write_vbmeta_image.ok()) { return rv_write_vbmeta_image; } Loading @@ -196,13 +196,13 @@ bool WriteToSuperVBMetaFile(const std::string& super_vbmeta_file, SuperVBMetaBuilder builder(super_vbmeta_fd, images_path); Result<void> rv_build = builder.Build(); if (!rv_build) { if (!rv_build.ok()) { LERROR << rv_build.error(); return false; } Result<void> rv_export = builder.ExportVBMetaTableToFile(); if (!rv_export) { if (!rv_export.ok()) { LERROR << rv_export.error(); return false; } Loading fs_mgr/libvbmeta/builder_test.cpp +11 −15 Original line number Diff line number Diff line Loading @@ -26,24 +26,20 @@ TEST(BuilderTest, VBMetaTableBasic) { std::unique_ptr<SuperVBMetaBuilder> builder = std::make_unique<SuperVBMetaBuilder>(); ASSERT_NE(builder, nullptr); Result<uint8_t> vbmeta_index = builder->AddVBMetaImage("vbmeta" /* vbmeta_name */ ); EXPECT_TRUE(vbmeta_index); Result<uint8_t> vbmeta_index = builder->AddVBMetaImage("vbmeta" /* vbmeta_name */); EXPECT_RESULT_OK(vbmeta_index); Result<uint8_t> vbmeta_system_slot = builder->AddVBMetaImage("vbmeta_system" /* vbmeta_name */ ); EXPECT_TRUE(vbmeta_system_slot); Result<uint8_t> vbmeta_system_slot = builder->AddVBMetaImage("vbmeta_system" /* vbmeta_name */); EXPECT_RESULT_OK(vbmeta_system_slot); Result<uint8_t> vbmeta_vendor_slot = builder->AddVBMetaImage("vbmeta_vendor" /* vbmeta_name */ ); EXPECT_TRUE(vbmeta_vendor_slot); Result<uint8_t> vbmeta_vendor_slot = builder->AddVBMetaImage("vbmeta_vendor" /* vbmeta_name */); EXPECT_RESULT_OK(vbmeta_vendor_slot); builder->DeleteVBMetaImage("vbmeta_system" /* vbmeta_name */ ); builder->DeleteVBMetaImage("vbmeta_system" /* vbmeta_name */); Result<uint8_t> vbmeta_product_slot = builder->AddVBMetaImage("vbmeta_product" /* vbmeta_name */ ); EXPECT_TRUE(vbmeta_product_slot); Result<uint8_t> vbmeta_product_slot = builder->AddVBMetaImage("vbmeta_product" /* vbmeta_name */); EXPECT_RESULT_OK(vbmeta_product_slot); std::unique_ptr<VBMetaTable> table = builder->ExportVBMetaTable(); ASSERT_NE(table, nullptr); Loading fs_mgr/libvbmeta/reader.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -64,7 +64,7 @@ Result<void> ReadVBMetaTable(int fd, uint64_t offset, VBMetaTable* table) { } Result<void> rv_header = LoadAndVerifySuperVBMetaHeader(header_buffer.get(), &table->header); if (!rv_header) { if (!rv_header.ok()) { return rv_header; } Loading Loading @@ -104,7 +104,7 @@ Result<std::string> ReadVBMetaImage(int fd, int slot) { Result<void> ValidateVBMetaImage(int super_vbmeta_fd, int vbmeta_index, const std::string& vbmeta_image) { Result<std::string> content = ReadVBMetaImage(super_vbmeta_fd, vbmeta_index); if (!content) { if (!content.ok()) { return content.error(); } Loading fs_mgr/libvbmeta/super_vbmeta_test.cpp +8 −8 Original line number Diff line number Diff line Loading @@ -77,7 +77,7 @@ std::string ReadVBMetaImageFromFile(const std::string& file) { android::base::unique_fd fd(open(file.c_str(), O_RDONLY | O_CLOEXEC)); EXPECT_GT(fd, 0); Result<uint64_t> file_size = GetFileSize(fd); EXPECT_TRUE(file_size); EXPECT_RESULT_OK(file_size); std::unique_ptr<uint8_t[]> buffer = std::make_unique<uint8_t[]>(VBMETA_IMAGE_MAX_SIZE); EXPECT_TRUE(android::base::ReadFully(fd, buffer.get(), file_size.value())); return std::string(reinterpret_cast<char*>(buffer.get()), VBMETA_IMAGE_MAX_SIZE); Loading Loading @@ -138,15 +138,15 @@ TEST(VBMetaTableTest, VBMetaTableBasic) { // Check the size of vbmeta table Result<uint64_t> super_vbmeta_size = GetFileSize(fd); EXPECT_TRUE(super_vbmeta_size); EXPECT_RESULT_OK(super_vbmeta_size); EXPECT_EQ(super_vbmeta_size.value(), SUPER_VBMETA_TABLE_MAX_SIZE * 2 + VBMETA_IMAGE_MAX_SIZE * 3); // Check Primary vbmeta table is equal to Backup one VBMetaTable table; EXPECT_TRUE(android::fs_mgr::ReadPrimaryVBMetaTable(fd, &table)); EXPECT_RESULT_OK(android::fs_mgr::ReadPrimaryVBMetaTable(fd, &table)); VBMetaTable table_backup; EXPECT_TRUE(android::fs_mgr::ReadBackupVBMetaTable(fd, &table_backup)); EXPECT_RESULT_OK(android::fs_mgr::ReadBackupVBMetaTable(fd, &table_backup)); EXPECT_EQ(android::fs_mgr::SerializeVBMetaTable(table), android::fs_mgr::SerializeVBMetaTable(table_backup)); Loading @@ -167,21 +167,21 @@ TEST(VBMetaTableTest, VBMetaTableBasic) { EXPECT_EQ(table.descriptors[0].vbmeta_name_length, 14); EXPECT_EQ(table.descriptors[0].vbmeta_name, "vbmeta_product"); Result<std::string> vbmeta_product_content = ReadVBMetaImage(fd, 0); EXPECT_TRUE(vbmeta_product_content); EXPECT_RESULT_OK(vbmeta_product_content); EXPECT_EQ(ReadVBMetaImageFromFile(vbmeta_product_path), vbmeta_product_content.value()); EXPECT_EQ(table.descriptors[1].vbmeta_index, 1); EXPECT_EQ(table.descriptors[1].vbmeta_name_length, 13); EXPECT_EQ(table.descriptors[1].vbmeta_name, "vbmeta_system"); Result<std::string> vbmeta_system_content = ReadVBMetaImage(fd, 1); EXPECT_TRUE(vbmeta_system_content); EXPECT_RESULT_OK(vbmeta_system_content); EXPECT_EQ(ReadVBMetaImageFromFile(vbmeta_system_path), vbmeta_system_content.value()); EXPECT_EQ(table.descriptors[2].vbmeta_index, 2); EXPECT_EQ(table.descriptors[2].vbmeta_name_length, 13); EXPECT_EQ(table.descriptors[2].vbmeta_name, "vbmeta_vendor"); Result<std::string> vbmeta_vendor_content = ReadVBMetaImage(fd, 2); EXPECT_TRUE(vbmeta_vendor_content); EXPECT_RESULT_OK(vbmeta_vendor_content); EXPECT_EQ(ReadVBMetaImageFromFile(vbmeta_vendor_path), vbmeta_vendor_content.value()); } Loading Loading
fs_mgr/libfs_avb/tests/util_test.cpp +4 −7 Original line number Diff line number Diff line Loading @@ -232,8 +232,7 @@ TEST(BasicUtilTest, ListFiles) { // List files for comparison. auto result = ListFiles(test_dir.value()); ASSERT_TRUE(result); ASSERT_TRUE(result.has_value()); ASSERT_RESULT_OK(result); auto files = result.value(); EXPECT_EQ(3UL, files.size()); // Sort them offline for comparison. Loading Loading @@ -266,8 +265,7 @@ TEST(BasicUtilTest, ListFilesShouldDiscardSymlink) { // List files for comparison. auto result = ListFiles(test_dir.value()); ASSERT_TRUE(result); ASSERT_TRUE(result.has_value()); ASSERT_RESULT_OK(result); auto files = result.value(); EXPECT_EQ(2UL, files.size()); // Should not include the symlink file. // Sort them offline for comparison. Loading @@ -287,7 +285,7 @@ TEST(BasicUtilTest, ListFilesOpenDirFailure) { base::FilePath no_such_dir = tmp_dir.Append("not_such_dir"); auto fail = ListFiles(no_such_dir.value()); ASSERT_FALSE(fail); ASSERT_FALSE(fail.ok()); EXPECT_EQ(ENOENT, fail.error().code()); EXPECT_TRUE(android::base::StartsWith(fail.error().message(), "Failed to opendir: ")); } Loading @@ -303,8 +301,7 @@ TEST(BasicUtilTest, ListFilesEmptyDir) { // List files without sorting. auto result = ListFiles(test_dir.value()); ASSERT_TRUE(result); ASSERT_TRUE(result.has_value()); ASSERT_RESULT_OK(result); auto files = result.value(); EXPECT_EQ(0UL, files.size()); Loading
fs_mgr/libvbmeta/builder.cpp +10 −10 Original line number Diff line number Diff line Loading @@ -40,18 +40,18 @@ SuperVBMetaBuilder::SuperVBMetaBuilder(const int super_vbmeta_fd, Result<void> SuperVBMetaBuilder::Build() { for (const auto& [vbmeta_name, file_path] : images_path_) { Result<std::string> content = ReadVBMetaImageFromFile(file_path); if (!content) { if (!content.ok()) { return content.error(); } Result<uint8_t> vbmeta_index = AddVBMetaImage(vbmeta_name); if (!vbmeta_index) { if (!vbmeta_index.ok()) { return vbmeta_index.error(); } Result<void> rv_export_vbmeta_image = ExportVBMetaImageToFile(vbmeta_index.value(), content.value()); if (!rv_export_vbmeta_image) { if (!rv_export_vbmeta_image.ok()) { return rv_export_vbmeta_image; } } Loading @@ -65,7 +65,7 @@ Result<std::string> SuperVBMetaBuilder::ReadVBMetaImageFromFile(const std::strin } Result<uint64_t> file_size = GetFileSize(source_fd); if (!file_size) { if (!file_size.ok()) { return file_size.error(); } Loading Loading @@ -98,7 +98,7 @@ Result<uint8_t> SuperVBMetaBuilder::AddVBMetaImage(const std::string& vbmeta_nam slot_number = desc->vbmeta_index; } else { Result<uint8_t> new_slot = GetEmptySlot(); if (!new_slot) { if (!new_slot.ok()) { return new_slot; } slot_number = new_slot.value(); Loading Loading @@ -162,7 +162,7 @@ Result<void> SuperVBMetaBuilder::ExportVBMetaTableToFile() { android::base::Result<void> rv_write_primary_vbmeta_table = WritePrimaryVBMetaTable(super_vbmeta_fd_, serialized_table); if (!rv_write_primary_vbmeta_table) { if (!rv_write_primary_vbmeta_table.ok()) { return rv_write_primary_vbmeta_table; } Loading @@ -175,7 +175,7 @@ Result<void> SuperVBMetaBuilder::ExportVBMetaImageToFile(const uint8_t vbmeta_in const std::string& vbmeta_image) { Result<void> rv_write_vbmeta_image = WriteVBMetaImage(super_vbmeta_fd_, vbmeta_index, vbmeta_image); if (!rv_write_vbmeta_image) { if (!rv_write_vbmeta_image.ok()) { return rv_write_vbmeta_image; } Loading @@ -196,13 +196,13 @@ bool WriteToSuperVBMetaFile(const std::string& super_vbmeta_file, SuperVBMetaBuilder builder(super_vbmeta_fd, images_path); Result<void> rv_build = builder.Build(); if (!rv_build) { if (!rv_build.ok()) { LERROR << rv_build.error(); return false; } Result<void> rv_export = builder.ExportVBMetaTableToFile(); if (!rv_export) { if (!rv_export.ok()) { LERROR << rv_export.error(); return false; } Loading
fs_mgr/libvbmeta/builder_test.cpp +11 −15 Original line number Diff line number Diff line Loading @@ -26,24 +26,20 @@ TEST(BuilderTest, VBMetaTableBasic) { std::unique_ptr<SuperVBMetaBuilder> builder = std::make_unique<SuperVBMetaBuilder>(); ASSERT_NE(builder, nullptr); Result<uint8_t> vbmeta_index = builder->AddVBMetaImage("vbmeta" /* vbmeta_name */ ); EXPECT_TRUE(vbmeta_index); Result<uint8_t> vbmeta_index = builder->AddVBMetaImage("vbmeta" /* vbmeta_name */); EXPECT_RESULT_OK(vbmeta_index); Result<uint8_t> vbmeta_system_slot = builder->AddVBMetaImage("vbmeta_system" /* vbmeta_name */ ); EXPECT_TRUE(vbmeta_system_slot); Result<uint8_t> vbmeta_system_slot = builder->AddVBMetaImage("vbmeta_system" /* vbmeta_name */); EXPECT_RESULT_OK(vbmeta_system_slot); Result<uint8_t> vbmeta_vendor_slot = builder->AddVBMetaImage("vbmeta_vendor" /* vbmeta_name */ ); EXPECT_TRUE(vbmeta_vendor_slot); Result<uint8_t> vbmeta_vendor_slot = builder->AddVBMetaImage("vbmeta_vendor" /* vbmeta_name */); EXPECT_RESULT_OK(vbmeta_vendor_slot); builder->DeleteVBMetaImage("vbmeta_system" /* vbmeta_name */ ); builder->DeleteVBMetaImage("vbmeta_system" /* vbmeta_name */); Result<uint8_t> vbmeta_product_slot = builder->AddVBMetaImage("vbmeta_product" /* vbmeta_name */ ); EXPECT_TRUE(vbmeta_product_slot); Result<uint8_t> vbmeta_product_slot = builder->AddVBMetaImage("vbmeta_product" /* vbmeta_name */); EXPECT_RESULT_OK(vbmeta_product_slot); std::unique_ptr<VBMetaTable> table = builder->ExportVBMetaTable(); ASSERT_NE(table, nullptr); Loading
fs_mgr/libvbmeta/reader.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -64,7 +64,7 @@ Result<void> ReadVBMetaTable(int fd, uint64_t offset, VBMetaTable* table) { } Result<void> rv_header = LoadAndVerifySuperVBMetaHeader(header_buffer.get(), &table->header); if (!rv_header) { if (!rv_header.ok()) { return rv_header; } Loading Loading @@ -104,7 +104,7 @@ Result<std::string> ReadVBMetaImage(int fd, int slot) { Result<void> ValidateVBMetaImage(int super_vbmeta_fd, int vbmeta_index, const std::string& vbmeta_image) { Result<std::string> content = ReadVBMetaImage(super_vbmeta_fd, vbmeta_index); if (!content) { if (!content.ok()) { return content.error(); } Loading
fs_mgr/libvbmeta/super_vbmeta_test.cpp +8 −8 Original line number Diff line number Diff line Loading @@ -77,7 +77,7 @@ std::string ReadVBMetaImageFromFile(const std::string& file) { android::base::unique_fd fd(open(file.c_str(), O_RDONLY | O_CLOEXEC)); EXPECT_GT(fd, 0); Result<uint64_t> file_size = GetFileSize(fd); EXPECT_TRUE(file_size); EXPECT_RESULT_OK(file_size); std::unique_ptr<uint8_t[]> buffer = std::make_unique<uint8_t[]>(VBMETA_IMAGE_MAX_SIZE); EXPECT_TRUE(android::base::ReadFully(fd, buffer.get(), file_size.value())); return std::string(reinterpret_cast<char*>(buffer.get()), VBMETA_IMAGE_MAX_SIZE); Loading Loading @@ -138,15 +138,15 @@ TEST(VBMetaTableTest, VBMetaTableBasic) { // Check the size of vbmeta table Result<uint64_t> super_vbmeta_size = GetFileSize(fd); EXPECT_TRUE(super_vbmeta_size); EXPECT_RESULT_OK(super_vbmeta_size); EXPECT_EQ(super_vbmeta_size.value(), SUPER_VBMETA_TABLE_MAX_SIZE * 2 + VBMETA_IMAGE_MAX_SIZE * 3); // Check Primary vbmeta table is equal to Backup one VBMetaTable table; EXPECT_TRUE(android::fs_mgr::ReadPrimaryVBMetaTable(fd, &table)); EXPECT_RESULT_OK(android::fs_mgr::ReadPrimaryVBMetaTable(fd, &table)); VBMetaTable table_backup; EXPECT_TRUE(android::fs_mgr::ReadBackupVBMetaTable(fd, &table_backup)); EXPECT_RESULT_OK(android::fs_mgr::ReadBackupVBMetaTable(fd, &table_backup)); EXPECT_EQ(android::fs_mgr::SerializeVBMetaTable(table), android::fs_mgr::SerializeVBMetaTable(table_backup)); Loading @@ -167,21 +167,21 @@ TEST(VBMetaTableTest, VBMetaTableBasic) { EXPECT_EQ(table.descriptors[0].vbmeta_name_length, 14); EXPECT_EQ(table.descriptors[0].vbmeta_name, "vbmeta_product"); Result<std::string> vbmeta_product_content = ReadVBMetaImage(fd, 0); EXPECT_TRUE(vbmeta_product_content); EXPECT_RESULT_OK(vbmeta_product_content); EXPECT_EQ(ReadVBMetaImageFromFile(vbmeta_product_path), vbmeta_product_content.value()); EXPECT_EQ(table.descriptors[1].vbmeta_index, 1); EXPECT_EQ(table.descriptors[1].vbmeta_name_length, 13); EXPECT_EQ(table.descriptors[1].vbmeta_name, "vbmeta_system"); Result<std::string> vbmeta_system_content = ReadVBMetaImage(fd, 1); EXPECT_TRUE(vbmeta_system_content); EXPECT_RESULT_OK(vbmeta_system_content); EXPECT_EQ(ReadVBMetaImageFromFile(vbmeta_system_path), vbmeta_system_content.value()); EXPECT_EQ(table.descriptors[2].vbmeta_index, 2); EXPECT_EQ(table.descriptors[2].vbmeta_name_length, 13); EXPECT_EQ(table.descriptors[2].vbmeta_name, "vbmeta_vendor"); Result<std::string> vbmeta_vendor_content = ReadVBMetaImage(fd, 2); EXPECT_TRUE(vbmeta_vendor_content); EXPECT_RESULT_OK(vbmeta_vendor_content); EXPECT_EQ(ReadVBMetaImageFromFile(vbmeta_vendor_path), vbmeta_vendor_content.value()); } Loading