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

Commit ad51f09b authored by Kelvin Zhang's avatar Kelvin Zhang Committed by Gerrit Code Review
Browse files

Merge "Fix multiple calls to set_[source/type]" into main

parents 96fd39c2 12e05312
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -226,6 +226,9 @@ struct CowOperationV3 {
    uint64_t source_info_;
    constexpr uint64_t source() const { return source_info_ & kCowOpSourceInfoDataMask; }
    constexpr void set_source(uint64_t source) {
        // Clear the first 48 bit first
        source_info_ &= ~kCowOpSourceInfoDataMask;
        // Set the actual source field
        source_info_ |= source & kCowOpSourceInfoDataMask;
    }
    constexpr CowOperationType type() const {
@@ -234,6 +237,9 @@ struct CowOperationV3 {
        return static_cast<CowOperationType>(type);
    }
    constexpr void set_type(CowOperationType type) {
        // Clear the top 4 bits first
        source_info_ &= ((1ULL << kCowOpSourceInfoTypeBit) - 1);
        // set the actual type bits
        source_info_ |= (static_cast<uint64_t>(type) & kCowOpSourceInfoTypeMask)
                        << kCowOpSourceInfoTypeBit;
    }
+37 −0
Original line number Diff line number Diff line
@@ -621,5 +621,42 @@ TEST_F(CowTestV3, ResumeSeqOp) {
    ASSERT_EQ(expected_block, 0);
    ASSERT_TRUE(iter->AtEnd());
}

TEST_F(CowTestV3, SetSourceManyTimes) {
    CowOperationV3 op{};
    op.set_source(1);
    ASSERT_EQ(op.source(), 1);
    op.set_source(2);
    ASSERT_EQ(op.source(), 2);
    op.set_source(4);
    ASSERT_EQ(op.source(), 4);
    op.set_source(8);
    ASSERT_EQ(op.source(), 8);
}

TEST_F(CowTestV3, SetTypeManyTimes) {
    CowOperationV3 op{};
    op.set_type(kCowCopyOp);
    ASSERT_EQ(op.type(), kCowCopyOp);
    op.set_type(kCowReplaceOp);
    ASSERT_EQ(op.type(), kCowReplaceOp);
    op.set_type(kCowZeroOp);
    ASSERT_EQ(op.type(), kCowZeroOp);
    op.set_type(kCowXorOp);
    ASSERT_EQ(op.type(), kCowXorOp);
}

TEST_F(CowTestV3, SetTypeSourceInverleave) {
    CowOperationV3 op{};
    op.set_type(kCowCopyOp);
    ASSERT_EQ(op.type(), kCowCopyOp);
    op.set_source(0x010203040506);
    ASSERT_EQ(op.source(), 0x010203040506);
    ASSERT_EQ(op.type(), kCowCopyOp);
    op.set_type(kCowReplaceOp);
    ASSERT_EQ(op.source(), 0x010203040506);
    ASSERT_EQ(op.type(), kCowReplaceOp);
}

}  // namespace snapshot
}  // namespace android