aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKelvin Zhang <zhangkelvin@google.com>2021-03-31 19:53:54 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2021-03-31 19:53:54 +0000
commitb2b532873da45e0b7b6be70732000bd98b40060f (patch)
tree17ac7812285d54d5f4fe0eacd77fe00617bfadb0
parentb165e446cbc75b8e070bf6f2caff1538c27417e9 (diff)
parentf55eab832fc0e368e8035244cba7bf8117775105 (diff)
downloadupdate_engine-b2b532873da45e0b7b6be70732000bd98b40060f.tar.gz
Add a unittest for read-after-write pattern in cow writer am: f55eab832f
Original change: https://android-review.googlesource.com/c/platform/system/update_engine/+/1629699 Change-Id: I69ad6dd99cb7745a36251594735eb59b18e6372f
-rw-r--r--payload_consumer/filesystem_verifier_action_unittest.cc24
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