diff options
author | Linux Build Service Account <lnxbuild@localhost> | 2021-04-18 12:53:07 -0700 |
---|---|---|
committer | Linux Build Service Account <lnxbuild@localhost> | 2021-04-18 12:53:07 -0700 |
commit | cb81ab091697e25f1b332c7e8f128cbe174ba141 (patch) | |
tree | e7c44a4b9bae8a98c9a6075dddc68e064ad616c2 /payload_consumer/filesystem_verifier_action_unittest.cc | |
parent | a1531c020edb7ad659164d6be96378fad956b61b (diff) | |
parent | aae41a1bf81c4141ebd5c61d1295d165bdc897a3 (diff) |
Merge aae41a1bf81c4141ebd5c61d1295d165bdc897a3 on remote branch
Change-Id: I54f3f25d6d84de3386d38b6c2a851d0c472fd9c8
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 |