diff options
author | Kelvin Zhang <zhangkelvin@google.com> | 2020-11-11 09:25:01 -0500 |
---|---|---|
committer | Kelvin Zhang <zhangkelvin@google.com> | 2020-12-16 14:21:28 +0000 |
commit | 44858971e0a0c71fa1828f1dae9381e896facf62 (patch) | |
tree | cdb340e9f5ef9a44fe5cb1f06f7257a9646ad4bc /payload_consumer/filesystem_verifier_action_unittest.cc | |
parent | ead9fd765fb5da10e081d1d15ccf66ed36138a80 (diff) |
Add unittest for filesystem verification action
Test: treehuggre
Change-Id: I03f69b7add96eaa481b1152a1425f4cb669d1113
Diffstat (limited to 'payload_consumer/filesystem_verifier_action_unittest.cc')
-rw-r--r-- | payload_consumer/filesystem_verifier_action_unittest.cc | 68 |
1 files changed, 66 insertions, 2 deletions
diff --git a/payload_consumer/filesystem_verifier_action_unittest.cc b/payload_consumer/filesystem_verifier_action_unittest.cc index 925fdab9..e9560f0b 100644 --- a/payload_consumer/filesystem_verifier_action_unittest.cc +++ b/payload_consumer/filesystem_verifier_action_unittest.cc @@ -27,13 +27,22 @@ #include <brillo/secure_blob.h> #include <gtest/gtest.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" #include "update_engine/common/test_utils.h" #include "update_engine/common/utils.h" +#include "update_engine/payload_consumer/install_plan.h" using brillo::MessageLoop; using std::string; +using testing::_; +using testing::AtLeast; +using testing::DoAll; +using testing::NiceMock; +using testing::Return; +using testing::SetArgPointee; namespace chromeos_update_engine { @@ -49,6 +58,8 @@ class FilesystemVerifierActionTest : public ::testing::Test { bool DoTest(bool terminate_early, bool hash_fail); void BuildActions(const InstallPlan& install_plan); + void BuildActions(const InstallPlan& install_plan, + DynamicPartitionControlInterface* dynamic_control); brillo::FakeMessageLoop loop_{nullptr}; ActionProcessor processor_; @@ -188,10 +199,11 @@ bool FilesystemVerifierActionTest::DoTest(bool terminate_early, } void FilesystemVerifierActionTest::BuildActions( - const InstallPlan& install_plan) { + const InstallPlan& install_plan, + DynamicPartitionControlInterface* dynamic_control) { auto feeder_action = std::make_unique<ObjectFeederAction<InstallPlan>>(); auto verifier_action = - std::make_unique<FilesystemVerifierAction>(&dynamic_control_stub_); + std::make_unique<FilesystemVerifierAction>(dynamic_control); auto collector_action = std::make_unique<ObjectCollectorAction<InstallPlan>>(); @@ -205,6 +217,11 @@ void FilesystemVerifierActionTest::BuildActions( processor_.EnqueueAction(std::move(collector_action)); } +void FilesystemVerifierActionTest::BuildActions( + const InstallPlan& install_plan) { + BuildActions(install_plan, &dynamic_control_stub_); +} + class FilesystemVerifierActionTest2Delegate : public ActionProcessorDelegate { public: void ActionCompleted(ActionProcessor* processor, @@ -385,4 +402,51 @@ TEST_F(FilesystemVerifierActionTest, RunAsRootSkipWriteVerityTest) { EXPECT_EQ(ErrorCode::kSuccess, delegate.code()); } +TEST_F(FilesystemVerifierActionTest, RunWithVABC) { + InstallPlan install_plan; + InstallPlan::Partition& part = install_plan.partitions.emplace_back(); + part.name = "fake_part"; + part.target_path = "/dev/fake_target_path"; + part.target_size = 4096 * 4096; + part.block_size = 4096; + part.source_path = "/dev/fake_source_path"; + + NiceMock<MockDynamicPartitionControl> dynamic_control; + + ON_CALL(dynamic_control, GetDynamicPartitionsFeatureFlag()) + .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::LAUNCH))); + ON_CALL(dynamic_control, GetVirtualAbCompressionFeatureFlag()) + .WillByDefault(Return(FeatureFlag(FeatureFlag::Value::LAUNCH))); + ON_CALL(dynamic_control, OpenCowReader(_, _, _)) + .WillByDefault(Return(nullptr)); + ON_CALL(dynamic_control, IsDynamicPartition(part.name)) + .WillByDefault(Return(true)); + + EXPECT_CALL(dynamic_control, GetVirtualAbCompressionFeatureFlag()) + .Times(AtLeast(1)); + EXPECT_CALL(dynamic_control, OpenCowReader(part.name, {part.source_path}, _)) + .Times(1); + EXPECT_CALL(dynamic_control, ListDynamicPartitionsForSlot(_, _)) + .WillRepeatedly( + DoAll(SetArgPointee<1, std::vector<std::string>>({part.name}), + Return(true))); + + BuildActions(install_plan, &dynamic_control); + + FilesystemVerifierActionTestDelegate delegate; + processor_.set_delegate(&delegate); + + loop_.PostTask( + FROM_HERE, + base::Bind( + [](ActionProcessor* processor) { processor->StartProcessing(); }, + 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()); +} + } // namespace chromeos_update_engine |