diff options
author | Android Build Role Account android-build-prod <android-build-team-robot@google.com> | 2021-04-07 10:08:15 +0000 |
---|---|---|
committer | Android Build Role Account android-build-prod <android-build-team-robot@google.com> | 2021-04-07 10:08:15 +0000 |
commit | 2f31caeb63a6c98e86af98e944ef62a77758a51f (patch) | |
tree | 18c582d1acd12ab352c594b32f8cc20ec57b1d71 /payload_consumer/filesystem_verifier_action_unittest.cc | |
parent | 75548accd9594d870fa712e3da2d9f618e38c60e (diff) | |
parent | e9401cf1628af34db6783705f04ddfbecb75fa24 (diff) |
Snap for 7264743 from e9401cf1628af34db6783705f04ddfbecb75fa24 to s-keystone-qcom-release
Change-Id: Ibc2eb6d8ca09cb6a00cc34e6a531b746adee3411
Diffstat (limited to 'payload_consumer/filesystem_verifier_action_unittest.cc')
-rw-r--r-- | payload_consumer/filesystem_verifier_action_unittest.cc | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/payload_consumer/filesystem_verifier_action_unittest.cc b/payload_consumer/filesystem_verifier_action_unittest.cc index d163ec20..2cad5232 100644 --- a/payload_consumer/filesystem_verifier_action_unittest.cc +++ b/payload_consumer/filesystem_verifier_action_unittest.cc @@ -33,6 +33,7 @@ #include "update_engine/common/mock_dynamic_partition_control.h" #include "update_engine/common/test_utils.h" #include "update_engine/common/utils.h" +#include "update_engine/payload_consumer/fake_file_descriptor.h" #include "update_engine/payload_consumer/install_plan.h" using brillo::MessageLoop; @@ -83,7 +84,8 @@ class FilesystemVerifierActionTestDelegate : public ActionProcessorDelegate { if (action->Type() == FilesystemVerifierAction::StaticType()) { ran_ = true; code_ = code; - EXPECT_FALSE(static_cast<FilesystemVerifierAction*>(action)->read_fd_); + EXPECT_FALSE( + static_cast<FilesystemVerifierAction*>(action)->partition_fd_); } else if (action->Type() == ObjectCollectorAction<InstallPlan>::StaticType()) { auto collector_action = @@ -251,8 +253,8 @@ TEST_F(FilesystemVerifierActionTest, MissingInputObjectTest) { processor_.set_delegate(&delegate); processor_.StartProcessing(); - EXPECT_FALSE(processor_.IsRunning()); - EXPECT_TRUE(delegate.ran_); + ASSERT_FALSE(processor_.IsRunning()); + ASSERT_TRUE(delegate.ran_); EXPECT_EQ(ErrorCode::kError, delegate.code_); } @@ -397,12 +399,12 @@ TEST_F(FilesystemVerifierActionTest, RunAsRootSkipWriteVerityTest) { base::Unretained(&processor_))); loop_.Run(); - EXPECT_FALSE(processor_.IsRunning()); - EXPECT_TRUE(delegate.ran()); - EXPECT_EQ(ErrorCode::kSuccess, delegate.code()); + ASSERT_FALSE(processor_.IsRunning()); + ASSERT_TRUE(delegate.ran()); + ASSERT_EQ(ErrorCode::kSuccess, delegate.code()); } -TEST_F(FilesystemVerifierActionTest, RunWithVABC) { +TEST_F(FilesystemVerifierActionTest, RunWithVABCNoVerity) { InstallPlan install_plan; InstallPlan::Partition& part = install_plan.partitions.emplace_back(); part.name = "fake_part"; @@ -410,21 +412,25 @@ TEST_F(FilesystemVerifierActionTest, RunWithVABC) { part.target_size = 4096 * 4096; part.block_size = 4096; part.source_path = "/dev/fake_source_path"; + part.fec_size = 0; + part.hash_tree_size = 0; + part.target_hash.clear(); + part.source_hash.clear(); NiceMock<MockDynamicPartitionControl> dynamic_control; + auto fake_fd = std::make_shared<FakeFileDescriptor>(); ON_CALL(dynamic_control, GetDynamicPartitionsFeatureFlag()) .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::LAUNCH))); ON_CALL(dynamic_control, UpdateUsesSnapshotCompression()) .WillByDefault(Return(true)); - ON_CALL(dynamic_control, OpenCowReader(_, _, _)) - .WillByDefault(Return(nullptr)); - ON_CALL(dynamic_control, IsDynamicPartition(part.name)) + ON_CALL(dynamic_control, OpenCowFd(_, _, _)).WillByDefault(Return(fake_fd)); + ON_CALL(dynamic_control, IsDynamicPartition(part.name, _)) .WillByDefault(Return(true)); EXPECT_CALL(dynamic_control, UpdateUsesSnapshotCompression()) .Times(AtLeast(1)); - EXPECT_CALL(dynamic_control, OpenCowReader(part.name, {part.source_path}, _)) + EXPECT_CALL(dynamic_control, OpenCowFd(part.name, {part.source_path}, _)) .Times(1); EXPECT_CALL(dynamic_control, ListDynamicPartitionsForSlot(_, _, _)) .WillRepeatedly( @@ -443,10 +449,18 @@ TEST_F(FilesystemVerifierActionTest, RunWithVABC) { base::Unretained(&processor_))); loop_.Run(); - EXPECT_FALSE(processor_.IsRunning()); - EXPECT_TRUE(delegate.ran()); - // Filesystem verifier will fail, because we returned nullptr as CowReader - EXPECT_EQ(ErrorCode::kFilesystemVerifierError, delegate.code()); + ASSERT_FALSE(processor_.IsRunning()); + ASSERT_TRUE(delegate.ran()); + // Filesystem verifier will fail, because we set an empty hash + ASSERT_EQ(ErrorCode::kNewRootfsVerificationError, delegate.code()); + const auto& read_pos = fake_fd->GetReadOps(); + size_t expected_offset = 0; + for (const auto& [off, size] : read_pos) { + ASSERT_EQ(off, expected_offset); + expected_offset += size; + } + const auto actual_read_size = expected_offset; + ASSERT_EQ(actual_read_size, part.target_size); } } // namespace chromeos_update_engine |