Loading fs_mgr/libsnapshot/partition_cow_creator_test.cpp +5 −33 Original line number Diff line number Diff line Loading @@ -18,48 +18,20 @@ #include <liblp/property_fetcher.h> #include "partition_cow_creator.h" #include "test_helpers.h" using ::android::fs_mgr::MetadataBuilder; using ::testing::_; using ::testing::AnyNumber; using ::testing::Return; namespace android { namespace snapshot { class MockPropertyFetcher : public fs_mgr::IPropertyFetcher { class PartitionCowCreatorTest : public ::testing::Test { public: MOCK_METHOD2(GetProperty, std::string(const std::string&, const std::string&)); MOCK_METHOD2(GetBoolProperty, bool(const std::string&, bool)); void SetUp() override { SnapshotTestPropertyFetcher::SetUp(); } void TearDown() override { SnapshotTestPropertyFetcher::TearDown(); } }; class PartitionCowCreatorTest : ::testing::Test { public: void SetUp() override { fs_mgr::IPropertyFetcher::OverrideForTesting(std::make_unique<MockPropertyFetcher>()); EXPECT_CALL(fetcher(), GetProperty("ro.boot.slot_suffix", _)) .Times(AnyNumber()) .WillRepeatedly(Return("_a")); EXPECT_CALL(fetcher(), GetBoolProperty("ro.boot.dynamic_partitions", _)) .Times(AnyNumber()) .WillRepeatedly(Return(true)); EXPECT_CALL(fetcher(), GetBoolProperty("ro.boot.dynamic_partitions_retrofit", _)) .Times(AnyNumber()) .WillRepeatedly(Return(false)); EXPECT_CALL(fetcher(), GetBoolProperty("ro.virtual_ab.enabled", _)) .Times(AnyNumber()) .WillRepeatedly(Return(true)); } void TearDown() override { fs_mgr::IPropertyFetcher::OverrideForTesting(std::make_unique<MockPropertyFetcher>()); } MockPropertyFetcher& fetcher() { return *static_cast<MockPropertyFetcher*>(fs_mgr::IPropertyFetcher::GetInstance()); } }; TEST(PartitionCowCreator, IntersectSelf) { TEST_F(PartitionCowCreatorTest, IntersectSelf) { auto builder_a = MetadataBuilder::New(1024 * 1024, 1024, 2); ASSERT_NE(builder_a, nullptr); auto system_a = builder_a->AddPartition("system_a", LP_PARTITION_ATTR_READONLY); Loading fs_mgr/libsnapshot/snapshot_metadata_updater_test.cpp +3 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ class SnapshotMetadataUpdaterTest : public ::testing::TestWithParam<uint32_t> { void SetUp() override { target_slot_ = GetParam(); target_suffix_ = SlotSuffixForSlotNumber(target_slot_); SnapshotTestPropertyFetcher::SetUp(SlotSuffixForSlotNumber(1 - target_slot_)); builder_ = MetadataBuilder::New(4_GiB + 1_MiB, 4_KiB, 2); group_ = manifest_.mutable_dynamic_partition_metadata()->add_groups(); Loading @@ -62,6 +63,8 @@ class SnapshotMetadataUpdaterTest : public ::testing::TestWithParam<uint32_t> { ASSERT_TRUE(FillFakeMetadata(builder_.get(), manifest_, target_suffix_)); } void TearDown() override { SnapshotTestPropertyFetcher::TearDown(); } // Append suffix to name. std::string T(std::string_view name) { return std::string(name) + target_suffix_; } Loading fs_mgr/libsnapshot/snapshot_test.cpp +2 −19 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ #include <libdm/dm.h> #include <libfiemap/image_manager.h> #include <liblp/builder.h> #include <liblp/mock_property_fetcher.h> #include <storage_literals/storage_literals.h> #include "test_helpers.h" Loading @@ -53,7 +52,6 @@ using android::fs_mgr::MetadataBuilder; using chromeos_update_engine::DeltaArchiveManifest; using chromeos_update_engine::PartitionUpdate; using namespace ::testing; using namespace android::fs_mgr::testing; using namespace android::storage_literals; using namespace std::chrono_literals; using namespace std::string_literals; Loading @@ -79,7 +77,7 @@ class SnapshotTest : public ::testing::Test { protected: void SetUp() override { ResetMockPropertyFetcher(); SnapshotTestPropertyFetcher::SetUp(); InitializeState(); CleanupTestArtifacts(); FormatFakeSuper(); Loading @@ -91,7 +89,7 @@ class SnapshotTest : public ::testing::Test { lock_ = nullptr; CleanupTestArtifacts(); ResetMockPropertyFetcher(); SnapshotTestPropertyFetcher::TearDown(); } void InitializeState() { Loading Loading @@ -373,9 +371,6 @@ TEST_F(SnapshotTest, FirstStageMountAfterRollback) { } TEST_F(SnapshotTest, Merge) { ON_CALL(*GetMockedPropertyFetcher(), GetBoolProperty("ro.virtual_ab.enabled", _)) .WillByDefault(Return(true)); ASSERT_TRUE(AcquireLock()); static const uint64_t kDeviceSize = 1024 * 1024; Loading Loading @@ -493,9 +488,6 @@ TEST_F(SnapshotTest, MergeCannotRemoveCow) { } TEST_F(SnapshotTest, FirstStageMountAndMerge) { ON_CALL(*GetMockedPropertyFetcher(), GetBoolProperty("ro.virtual_ab.enabled", _)) .WillByDefault(Return(true)); ASSERT_TRUE(AcquireLock()); static const uint64_t kDeviceSize = 1024 * 1024; Loading Loading @@ -535,9 +527,6 @@ TEST_F(SnapshotTest, FirstStageMountAndMerge) { } TEST_F(SnapshotTest, FlashSuperDuringUpdate) { ON_CALL(*GetMockedPropertyFetcher(), GetBoolProperty("ro.virtual_ab.enabled", _)) .WillByDefault(Return(true)); ASSERT_TRUE(AcquireLock()); static const uint64_t kDeviceSize = 1024 * 1024; Loading Loading @@ -583,9 +572,6 @@ TEST_F(SnapshotTest, FlashSuperDuringUpdate) { } TEST_F(SnapshotTest, FlashSuperDuringMerge) { ON_CALL(*GetMockedPropertyFetcher(), GetBoolProperty("ro.virtual_ab.enabled", _)) .WillByDefault(Return(true)); ASSERT_TRUE(AcquireLock()); static const uint64_t kDeviceSize = 1024 * 1024; Loading Loading @@ -636,9 +622,6 @@ class SnapshotUpdateTest : public SnapshotTest { // Cleanup() changes slot suffix, so initialize it again. test_device->set_slot_suffix("_a"); ON_CALL(*GetMockedPropertyFetcher(), GetBoolProperty("ro.virtual_ab.enabled", _)) .WillByDefault(Return(true)); opener_ = std::make_unique<TestPartitionOpener>(fake_super); // Create a fake update package metadata. Loading fs_mgr/libsnapshot/test_helpers.h +29 −0 Original line number Diff line number Diff line Loading @@ -17,8 +17,10 @@ #include <optional> #include <string> #include <gmock/gmock.h> #include <gtest/gtest.h> #include <libfiemap/image_manager.h> #include <liblp/mock_property_fetcher.h> #include <liblp/partition_opener.h> #include <libsnapshot/snapshot.h> #include <update_engine/update_metadata.pb.h> Loading @@ -26,10 +28,15 @@ namespace android { namespace snapshot { using android::fs_mgr::IPropertyFetcher; using android::fs_mgr::MetadataBuilder; using android::fs_mgr::testing::MockPropertyFetcher; using chromeos_update_engine::DeltaArchiveManifest; using chromeos_update_engine::PartitionUpdate; using testing::_; using testing::AssertionResult; using testing::NiceMock; using testing::Return; using namespace std::string_literals; Loading Loading @@ -72,6 +79,28 @@ class TestDeviceInfo : public SnapshotManager::IDeviceInfo { std::unique_ptr<TestPartitionOpener> opener_; }; class SnapshotTestPropertyFetcher : public android::fs_mgr::testing::MockPropertyFetcher { public: SnapshotTestPropertyFetcher(const std::string& slot_suffix) { ON_CALL(*this, GetProperty("ro.boot.slot_suffix", _)).WillByDefault(Return(slot_suffix)); ON_CALL(*this, GetBoolProperty("ro.boot.dynamic_partitions", _)) .WillByDefault(Return(true)); ON_CALL(*this, GetBoolProperty("ro.boot.dynamic_partitions_retrofit", _)) .WillByDefault(Return(false)); ON_CALL(*this, GetBoolProperty("ro.virtual_ab.enabled", _)).WillByDefault(Return(true)); } static void SetUp(const std::string& slot_suffix = "_a") { Reset(slot_suffix); } static void TearDown() { Reset("_a"); } private: static void Reset(const std::string& slot_suffix) { IPropertyFetcher::OverrideForTesting( std::make_unique<NiceMock<SnapshotTestPropertyFetcher>>(slot_suffix)); } }; // Helper for error-spam-free cleanup. void DeleteBackingImage(android::fiemap::IImageManager* manager, const std::string& name); Loading Loading
fs_mgr/libsnapshot/partition_cow_creator_test.cpp +5 −33 Original line number Diff line number Diff line Loading @@ -18,48 +18,20 @@ #include <liblp/property_fetcher.h> #include "partition_cow_creator.h" #include "test_helpers.h" using ::android::fs_mgr::MetadataBuilder; using ::testing::_; using ::testing::AnyNumber; using ::testing::Return; namespace android { namespace snapshot { class MockPropertyFetcher : public fs_mgr::IPropertyFetcher { class PartitionCowCreatorTest : public ::testing::Test { public: MOCK_METHOD2(GetProperty, std::string(const std::string&, const std::string&)); MOCK_METHOD2(GetBoolProperty, bool(const std::string&, bool)); void SetUp() override { SnapshotTestPropertyFetcher::SetUp(); } void TearDown() override { SnapshotTestPropertyFetcher::TearDown(); } }; class PartitionCowCreatorTest : ::testing::Test { public: void SetUp() override { fs_mgr::IPropertyFetcher::OverrideForTesting(std::make_unique<MockPropertyFetcher>()); EXPECT_CALL(fetcher(), GetProperty("ro.boot.slot_suffix", _)) .Times(AnyNumber()) .WillRepeatedly(Return("_a")); EXPECT_CALL(fetcher(), GetBoolProperty("ro.boot.dynamic_partitions", _)) .Times(AnyNumber()) .WillRepeatedly(Return(true)); EXPECT_CALL(fetcher(), GetBoolProperty("ro.boot.dynamic_partitions_retrofit", _)) .Times(AnyNumber()) .WillRepeatedly(Return(false)); EXPECT_CALL(fetcher(), GetBoolProperty("ro.virtual_ab.enabled", _)) .Times(AnyNumber()) .WillRepeatedly(Return(true)); } void TearDown() override { fs_mgr::IPropertyFetcher::OverrideForTesting(std::make_unique<MockPropertyFetcher>()); } MockPropertyFetcher& fetcher() { return *static_cast<MockPropertyFetcher*>(fs_mgr::IPropertyFetcher::GetInstance()); } }; TEST(PartitionCowCreator, IntersectSelf) { TEST_F(PartitionCowCreatorTest, IntersectSelf) { auto builder_a = MetadataBuilder::New(1024 * 1024, 1024, 2); ASSERT_NE(builder_a, nullptr); auto system_a = builder_a->AddPartition("system_a", LP_PARTITION_ATTR_READONLY); Loading
fs_mgr/libsnapshot/snapshot_metadata_updater_test.cpp +3 −0 Original line number Diff line number Diff line Loading @@ -45,6 +45,7 @@ class SnapshotMetadataUpdaterTest : public ::testing::TestWithParam<uint32_t> { void SetUp() override { target_slot_ = GetParam(); target_suffix_ = SlotSuffixForSlotNumber(target_slot_); SnapshotTestPropertyFetcher::SetUp(SlotSuffixForSlotNumber(1 - target_slot_)); builder_ = MetadataBuilder::New(4_GiB + 1_MiB, 4_KiB, 2); group_ = manifest_.mutable_dynamic_partition_metadata()->add_groups(); Loading @@ -62,6 +63,8 @@ class SnapshotMetadataUpdaterTest : public ::testing::TestWithParam<uint32_t> { ASSERT_TRUE(FillFakeMetadata(builder_.get(), manifest_, target_suffix_)); } void TearDown() override { SnapshotTestPropertyFetcher::TearDown(); } // Append suffix to name. std::string T(std::string_view name) { return std::string(name) + target_suffix_; } Loading
fs_mgr/libsnapshot/snapshot_test.cpp +2 −19 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ #include <libdm/dm.h> #include <libfiemap/image_manager.h> #include <liblp/builder.h> #include <liblp/mock_property_fetcher.h> #include <storage_literals/storage_literals.h> #include "test_helpers.h" Loading @@ -53,7 +52,6 @@ using android::fs_mgr::MetadataBuilder; using chromeos_update_engine::DeltaArchiveManifest; using chromeos_update_engine::PartitionUpdate; using namespace ::testing; using namespace android::fs_mgr::testing; using namespace android::storage_literals; using namespace std::chrono_literals; using namespace std::string_literals; Loading @@ -79,7 +77,7 @@ class SnapshotTest : public ::testing::Test { protected: void SetUp() override { ResetMockPropertyFetcher(); SnapshotTestPropertyFetcher::SetUp(); InitializeState(); CleanupTestArtifacts(); FormatFakeSuper(); Loading @@ -91,7 +89,7 @@ class SnapshotTest : public ::testing::Test { lock_ = nullptr; CleanupTestArtifacts(); ResetMockPropertyFetcher(); SnapshotTestPropertyFetcher::TearDown(); } void InitializeState() { Loading Loading @@ -373,9 +371,6 @@ TEST_F(SnapshotTest, FirstStageMountAfterRollback) { } TEST_F(SnapshotTest, Merge) { ON_CALL(*GetMockedPropertyFetcher(), GetBoolProperty("ro.virtual_ab.enabled", _)) .WillByDefault(Return(true)); ASSERT_TRUE(AcquireLock()); static const uint64_t kDeviceSize = 1024 * 1024; Loading Loading @@ -493,9 +488,6 @@ TEST_F(SnapshotTest, MergeCannotRemoveCow) { } TEST_F(SnapshotTest, FirstStageMountAndMerge) { ON_CALL(*GetMockedPropertyFetcher(), GetBoolProperty("ro.virtual_ab.enabled", _)) .WillByDefault(Return(true)); ASSERT_TRUE(AcquireLock()); static const uint64_t kDeviceSize = 1024 * 1024; Loading Loading @@ -535,9 +527,6 @@ TEST_F(SnapshotTest, FirstStageMountAndMerge) { } TEST_F(SnapshotTest, FlashSuperDuringUpdate) { ON_CALL(*GetMockedPropertyFetcher(), GetBoolProperty("ro.virtual_ab.enabled", _)) .WillByDefault(Return(true)); ASSERT_TRUE(AcquireLock()); static const uint64_t kDeviceSize = 1024 * 1024; Loading Loading @@ -583,9 +572,6 @@ TEST_F(SnapshotTest, FlashSuperDuringUpdate) { } TEST_F(SnapshotTest, FlashSuperDuringMerge) { ON_CALL(*GetMockedPropertyFetcher(), GetBoolProperty("ro.virtual_ab.enabled", _)) .WillByDefault(Return(true)); ASSERT_TRUE(AcquireLock()); static const uint64_t kDeviceSize = 1024 * 1024; Loading Loading @@ -636,9 +622,6 @@ class SnapshotUpdateTest : public SnapshotTest { // Cleanup() changes slot suffix, so initialize it again. test_device->set_slot_suffix("_a"); ON_CALL(*GetMockedPropertyFetcher(), GetBoolProperty("ro.virtual_ab.enabled", _)) .WillByDefault(Return(true)); opener_ = std::make_unique<TestPartitionOpener>(fake_super); // Create a fake update package metadata. Loading
fs_mgr/libsnapshot/test_helpers.h +29 −0 Original line number Diff line number Diff line Loading @@ -17,8 +17,10 @@ #include <optional> #include <string> #include <gmock/gmock.h> #include <gtest/gtest.h> #include <libfiemap/image_manager.h> #include <liblp/mock_property_fetcher.h> #include <liblp/partition_opener.h> #include <libsnapshot/snapshot.h> #include <update_engine/update_metadata.pb.h> Loading @@ -26,10 +28,15 @@ namespace android { namespace snapshot { using android::fs_mgr::IPropertyFetcher; using android::fs_mgr::MetadataBuilder; using android::fs_mgr::testing::MockPropertyFetcher; using chromeos_update_engine::DeltaArchiveManifest; using chromeos_update_engine::PartitionUpdate; using testing::_; using testing::AssertionResult; using testing::NiceMock; using testing::Return; using namespace std::string_literals; Loading Loading @@ -72,6 +79,28 @@ class TestDeviceInfo : public SnapshotManager::IDeviceInfo { std::unique_ptr<TestPartitionOpener> opener_; }; class SnapshotTestPropertyFetcher : public android::fs_mgr::testing::MockPropertyFetcher { public: SnapshotTestPropertyFetcher(const std::string& slot_suffix) { ON_CALL(*this, GetProperty("ro.boot.slot_suffix", _)).WillByDefault(Return(slot_suffix)); ON_CALL(*this, GetBoolProperty("ro.boot.dynamic_partitions", _)) .WillByDefault(Return(true)); ON_CALL(*this, GetBoolProperty("ro.boot.dynamic_partitions_retrofit", _)) .WillByDefault(Return(false)); ON_CALL(*this, GetBoolProperty("ro.virtual_ab.enabled", _)).WillByDefault(Return(true)); } static void SetUp(const std::string& slot_suffix = "_a") { Reset(slot_suffix); } static void TearDown() { Reset("_a"); } private: static void Reset(const std::string& slot_suffix) { IPropertyFetcher::OverrideForTesting( std::make_unique<NiceMock<SnapshotTestPropertyFetcher>>(slot_suffix)); } }; // Helper for error-spam-free cleanup. void DeleteBackingImage(android::fiemap::IImageManager* manager, const std::string& name); Loading