Merge "Fix multiple calls to set_[source/type]" into main am: ad51f09b05
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2860565 Change-Id: Ib59f9500b195ddbbb4b730f7994d5538374a5d98 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
14ba80454f
2 changed files with 43 additions and 0 deletions
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue