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

Commit 2e660433 authored by Yifan Hong's avatar Yifan Hong Committed by Gerrit Code Review
Browse files

Merge "Add tests for zero snapshot size."

parents 794acfc0 e0c2e62c
Loading
Loading
Loading
Loading
+39 −14
Original line number Original line Diff line number Diff line
@@ -46,20 +46,20 @@ class PartitionCowCreatorTest : public ::testing::Test {
};
};


TEST_F(PartitionCowCreatorTest, IntersectSelf) {
TEST_F(PartitionCowCreatorTest, IntersectSelf) {
    constexpr uint64_t initial_size = 1_MiB;
    constexpr uint64_t super_size = 1_MiB;
    constexpr uint64_t final_size = 40_KiB;
    constexpr uint64_t partition_size = 40_KiB;


    auto builder_a = MetadataBuilder::New(initial_size, 1_KiB, 2);
    auto builder_a = MetadataBuilder::New(super_size, 1_KiB, 2);
    ASSERT_NE(builder_a, nullptr);
    ASSERT_NE(builder_a, nullptr);
    auto system_a = builder_a->AddPartition("system_a", LP_PARTITION_ATTR_READONLY);
    auto system_a = builder_a->AddPartition("system_a", LP_PARTITION_ATTR_READONLY);
    ASSERT_NE(system_a, nullptr);
    ASSERT_NE(system_a, nullptr);
    ASSERT_TRUE(builder_a->ResizePartition(system_a, final_size));
    ASSERT_TRUE(builder_a->ResizePartition(system_a, partition_size));


    auto builder_b = MetadataBuilder::New(initial_size, 1_KiB, 2);
    auto builder_b = MetadataBuilder::New(super_size, 1_KiB, 2);
    ASSERT_NE(builder_b, nullptr);
    ASSERT_NE(builder_b, nullptr);
    auto system_b = builder_b->AddPartition("system_b", LP_PARTITION_ATTR_READONLY);
    auto system_b = builder_b->AddPartition("system_b", LP_PARTITION_ATTR_READONLY);
    ASSERT_NE(system_b, nullptr);
    ASSERT_NE(system_b, nullptr);
    ASSERT_TRUE(builder_b->ResizePartition(system_b, final_size));
    ASSERT_TRUE(builder_b->ResizePartition(system_b, partition_size));


    PartitionCowCreator creator{.target_metadata = builder_b.get(),
    PartitionCowCreator creator{.target_metadata = builder_b.get(),
                                .target_suffix = "_b",
                                .target_suffix = "_b",
@@ -68,8 +68,8 @@ TEST_F(PartitionCowCreatorTest, IntersectSelf) {
                                .current_suffix = "_a"};
                                .current_suffix = "_a"};
    auto ret = creator.Run();
    auto ret = creator.Run();
    ASSERT_TRUE(ret.has_value());
    ASSERT_TRUE(ret.has_value());
    ASSERT_EQ(final_size, ret->snapshot_status.device_size());
    ASSERT_EQ(partition_size, ret->snapshot_status.device_size());
    ASSERT_EQ(final_size, ret->snapshot_status.snapshot_size());
    ASSERT_EQ(partition_size, ret->snapshot_status.snapshot_size());
}
}


TEST_F(PartitionCowCreatorTest, Holes) {
TEST_F(PartitionCowCreatorTest, Holes) {
@@ -118,20 +118,20 @@ TEST_F(PartitionCowCreatorTest, CowSize) {
    using RepeatedInstallOperationPtr = google::protobuf::RepeatedPtrField<InstallOperation>;
    using RepeatedInstallOperationPtr = google::protobuf::RepeatedPtrField<InstallOperation>;
    using Extent = chromeos_update_engine::Extent;
    using Extent = chromeos_update_engine::Extent;


    constexpr uint64_t initial_size = 50_MiB;
    constexpr uint64_t super_size = 50_MiB;
    constexpr uint64_t final_size = 40_MiB;
    constexpr uint64_t partition_size = 40_MiB;


    auto builder_a = MetadataBuilder::New(initial_size, 1_KiB, 2);
    auto builder_a = MetadataBuilder::New(super_size, 1_KiB, 2);
    ASSERT_NE(builder_a, nullptr);
    ASSERT_NE(builder_a, nullptr);
    auto system_a = builder_a->AddPartition("system_a", LP_PARTITION_ATTR_READONLY);
    auto system_a = builder_a->AddPartition("system_a", LP_PARTITION_ATTR_READONLY);
    ASSERT_NE(system_a, nullptr);
    ASSERT_NE(system_a, nullptr);
    ASSERT_TRUE(builder_a->ResizePartition(system_a, final_size));
    ASSERT_TRUE(builder_a->ResizePartition(system_a, partition_size));


    auto builder_b = MetadataBuilder::New(initial_size, 1_KiB, 2);
    auto builder_b = MetadataBuilder::New(super_size, 1_KiB, 2);
    ASSERT_NE(builder_b, nullptr);
    ASSERT_NE(builder_b, nullptr);
    auto system_b = builder_b->AddPartition("system_b", LP_PARTITION_ATTR_READONLY);
    auto system_b = builder_b->AddPartition("system_b", LP_PARTITION_ATTR_READONLY);
    ASSERT_NE(system_b, nullptr);
    ASSERT_NE(system_b, nullptr);
    ASSERT_TRUE(builder_b->ResizePartition(system_b, final_size));
    ASSERT_TRUE(builder_b->ResizePartition(system_b, partition_size));


    const uint64_t block_size = builder_b->logical_block_size();
    const uint64_t block_size = builder_b->logical_block_size();
    const uint64_t chunk_size = kSnapshotChunkSize * dm::kSectorSize;
    const uint64_t chunk_size = kSnapshotChunkSize * dm::kSectorSize;
@@ -197,6 +197,31 @@ TEST_F(PartitionCowCreatorTest, CowSize) {
    ASSERT_EQ(6 * chunk_size, cow_device_size(iopv, builder_a.get(), builder_b.get(), system_b));
    ASSERT_EQ(6 * chunk_size, cow_device_size(iopv, builder_a.get(), builder_b.get(), system_b));
}
}


TEST_F(PartitionCowCreatorTest, Zero) {
    constexpr uint64_t super_size = 1_MiB;
    auto builder_a = MetadataBuilder::New(super_size, 1_KiB, 2);
    ASSERT_NE(builder_a, nullptr);

    auto builder_b = MetadataBuilder::New(super_size, 1_KiB, 2);
    ASSERT_NE(builder_b, nullptr);
    auto system_b = builder_b->AddPartition("system_b", LP_PARTITION_ATTR_READONLY);
    ASSERT_NE(system_b, nullptr);

    PartitionCowCreator creator{.target_metadata = builder_b.get(),
                                .target_suffix = "_b",
                                .target_partition = system_b,
                                .current_metadata = builder_a.get(),
                                .current_suffix = "_a",
                                .operations = nullptr};

    auto ret = creator.Run();

    ASSERT_EQ(0u, ret->snapshot_status.device_size());
    ASSERT_EQ(0u, ret->snapshot_status.snapshot_size());
    ASSERT_EQ(0u, ret->snapshot_status.cow_file_size());
    ASSERT_EQ(0u, ret->snapshot_status.cow_partition_size());
}

TEST(DmSnapshotInternals, CowSizeCalculator) {
TEST(DmSnapshotInternals, CowSizeCalculator) {
    DmSnapCowSizeCalculator cc(512, 8);
    DmSnapCowSizeCalculator cc(512, 8);
    unsigned long int b;
    unsigned long int b;