From d7efbea407a2ba2cbe0aa3c0cc0a4df072de849b Mon Sep 17 00:00:00 2001 From: Daniel Zheng Date: Mon, 18 Mar 2024 15:42:33 -0700 Subject: [PATCH] cow_api_test: big replace op With the modified cache system we might be processing big replace ops at once. Our old tests didn't catch a case where a big replace op was chunked into seperate batch writes. Test: cow_api_test Change-Id: I3bc80a2f9ed3e4c73dd9f74d9affaba79d49e4d2 --- .../libsnapshot/libsnapshot_cow/test_v3.cpp | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/fs_mgr/libsnapshot/libsnapshot_cow/test_v3.cpp b/fs_mgr/libsnapshot/libsnapshot_cow/test_v3.cpp index 202134841..4456b269c 100644 --- a/fs_mgr/libsnapshot/libsnapshot_cow/test_v3.cpp +++ b/fs_mgr/libsnapshot/libsnapshot_cow/test_v3.cpp @@ -209,6 +209,48 @@ TEST_F(CowTestV3, ReplaceOp) { ASSERT_EQ(sink, data); } +TEST_F(CowTestV3, BigReplaceOp) { + CowOptions options; + options.op_count_max = 10000; + options.batch_write = true; + options.cluster_ops = 2048; + + auto writer = CreateCowWriter(3, options, GetCowFd()); + std::string data = "This is some data, believe it"; + data.resize(options.block_size * 4096, '\0'); + for (int i = 0; i < data.size(); i++) { + data[i] = static_cast('A' + i / options.block_size); + } + ASSERT_TRUE(writer->AddRawBlocks(5, data.data(), data.size())); + ASSERT_TRUE(writer->Finalize()); + + CowReader reader; + ASSERT_TRUE(reader.Parse(cow_->fd)); + + const auto& header = reader.header_v3(); + ASSERT_EQ(header.op_count, 4096); + + auto iter = reader.GetOpIter(); + ASSERT_NE(iter, nullptr); + ASSERT_FALSE(iter->AtEnd()); + + size_t i = 0; + + while (!iter->AtEnd()) { + auto op = iter->Get(); + std::string sink(options.block_size, '\0'); + ASSERT_EQ(op->type(), kCowReplaceOp); + ASSERT_EQ(op->data_length, options.block_size); + ASSERT_EQ(op->new_block, 5 + i); + ASSERT_TRUE(ReadData(reader, op, sink.data(), options.block_size)); + ASSERT_EQ(std::string_view(sink), + std::string_view(data).substr(i * options.block_size, options.block_size)) + << " readback data for " << i << "th block does not match"; + iter->Next(); + i++; + } +} + TEST_F(CowTestV3, ConsecutiveReplaceOp) { CowOptions options; options.op_count_max = 20;