diff options
author | Kelvin Zhang <zhangkelvin@google.com> | 2021-03-11 14:46:47 -0500 |
---|---|---|
committer | Kelvin Zhang <zhangkelvin@google.com> | 2021-03-31 18:43:49 +0000 |
commit | f55eab832fc0e368e8035244cba7bf8117775105 (patch) | |
tree | 17ac7812285d54d5f4fe0eacd77fe00617bfadb0 | |
parent | 331e3bd90c3532c1c97b720f671e5f2c0786645e (diff) | |
download | update_engine-f55eab832fc0e368e8035244cba7bf8117775105.tar.gz |
Add a unittest for read-after-write pattern in cow writer
Test: th
Change-Id: I4e461b03d4008d484eafe601d3de2f4b06bf585d
-rw-r--r-- | payload_consumer/filesystem_verifier_action_unittest.cc | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/payload_consumer/filesystem_verifier_action_unittest.cc b/payload_consumer/filesystem_verifier_action_unittest.cc index 2cad5232..c1006842 100644 --- a/payload_consumer/filesystem_verifier_action_unittest.cc +++ b/payload_consumer/filesystem_verifier_action_unittest.cc @@ -26,8 +26,8 @@ #include <brillo/message_loops/message_loop_utils.h> #include <brillo/secure_blob.h> #include <gtest/gtest.h> +#include <libsnapshot/snapshot_writer.h> -#include "gmock/gmock-actions.h" #include "update_engine/common/dynamic_partition_control_stub.h" #include "update_engine/common/hash_calculator.h" #include "update_engine/common/mock_dynamic_partition_control.h" @@ -463,4 +463,26 @@ TEST_F(FilesystemVerifierActionTest, RunWithVABCNoVerity) { ASSERT_EQ(actual_read_size, part.target_size); } +TEST_F(FilesystemVerifierActionTest, ReadAfterWrite) { + constexpr auto BLOCK_SIZE = 4096; + ScopedTempFile cow_device_file("cow_device.XXXXXX", true); + android::snapshot::CompressedSnapshotWriter snapshot_writer{ + {.block_size = BLOCK_SIZE}}; + snapshot_writer.SetCowDevice(android::base::unique_fd{cow_device_file.fd()}); + snapshot_writer.Initialize(); + std::vector<unsigned char> buffer; + buffer.resize(BLOCK_SIZE); + std::fill(buffer.begin(), buffer.end(), 123); + + ASSERT_TRUE(snapshot_writer.AddRawBlocks(0, buffer.data(), buffer.size())); + ASSERT_TRUE(snapshot_writer.Finalize()); + auto cow_reader = snapshot_writer.OpenReader(); + ASSERT_NE(cow_reader, nullptr); + ASSERT_TRUE(snapshot_writer.AddRawBlocks(1, buffer.data(), buffer.size())); + ASSERT_TRUE(snapshot_writer.AddRawBlocks(2, buffer.data(), buffer.size())); + ASSERT_TRUE(snapshot_writer.Finalize()); + cow_reader = snapshot_writer.OpenReader(); + ASSERT_NE(cow_reader, nullptr); +} + } // namespace chromeos_update_engine |