diff options
Diffstat (limited to 'payload_consumer/postinstall_runner_action_unittest.cc')
-rw-r--r-- | payload_consumer/postinstall_runner_action_unittest.cc | 54 |
1 files changed, 38 insertions, 16 deletions
diff --git a/payload_consumer/postinstall_runner_action_unittest.cc b/payload_consumer/postinstall_runner_action_unittest.cc index a3192990..b7f0fdc0 100644 --- a/payload_consumer/postinstall_runner_action_unittest.cc +++ b/payload_consumer/postinstall_runner_action_unittest.cc @@ -39,6 +39,7 @@ #include "update_engine/common/fake_hardware.h" #include "update_engine/common/test_utils.h" #include "update_engine/common/utils.h" +#include "update_engine/mock_payload_state.h" using brillo::MessageLoop; using chromeos_update_engine::test_utils::ScopedLoopbackDeviceBinder; @@ -95,9 +96,10 @@ class PostinstallRunnerActionTest : public ::testing::Test { // Setup an action processor and run the PostinstallRunnerAction with a single // partition |device_path|, running the |postinstall_program| command from // there. - void RunPosinstallAction(const string& device_path, - const string& postinstall_program, - bool powerwash_required); + void RunPostinstallAction(const string& device_path, + const string& postinstall_program, + bool powerwash_required, + bool is_rollback); public: void ResumeRunningAction() { @@ -163,10 +165,11 @@ class PostinstallRunnerActionTest : public ::testing::Test { ActionProcessor* processor_{nullptr}; }; -void PostinstallRunnerActionTest::RunPosinstallAction( +void PostinstallRunnerActionTest::RunPostinstallAction( const string& device_path, const string& postinstall_program, - bool powerwash_required) { + bool powerwash_required, + bool is_rollback) { ActionProcessor processor; processor_ = &processor; ObjectFeederAction<InstallPlan> feeder_action; @@ -179,6 +182,7 @@ void PostinstallRunnerActionTest::RunPosinstallAction( install_plan.partitions = {part}; install_plan.download_url = "http://127.0.0.1:8080/update"; install_plan.powerwash_required = powerwash_required; + install_plan.is_rollback = is_rollback; feeder_action.set_obj(install_plan); PostinstallRunnerAction runner_action(&fake_boot_control_, &fake_hardware_); postinstall_action_ = &runner_action; @@ -241,7 +245,8 @@ TEST_F(PostinstallRunnerActionTest, ProcessProgressLineTest) { // /postinst command which only exits 0. TEST_F(PostinstallRunnerActionTest, RunAsRootSimpleTest) { ScopedLoopbackDeviceBinder loop(postinstall_image_, false, nullptr); - RunPosinstallAction(loop.dev(), kPostinstallDefaultScript, false); + + RunPostinstallAction(loop.dev(), kPostinstallDefaultScript, false, false); EXPECT_EQ(ErrorCode::kSuccess, processor_delegate_.code_); EXPECT_TRUE(processor_delegate_.processing_done_called_); @@ -251,14 +256,31 @@ TEST_F(PostinstallRunnerActionTest, RunAsRootSimpleTest) { TEST_F(PostinstallRunnerActionTest, RunAsRootRunSymlinkFileTest) { ScopedLoopbackDeviceBinder loop(postinstall_image_, false, nullptr); - RunPosinstallAction(loop.dev(), "bin/postinst_link", false); + RunPostinstallAction(loop.dev(), "bin/postinst_link", false, false); EXPECT_EQ(ErrorCode::kSuccess, processor_delegate_.code_); } TEST_F(PostinstallRunnerActionTest, RunAsRootPowerwashRequiredTest) { ScopedLoopbackDeviceBinder loop(postinstall_image_, false, nullptr); // Run a simple postinstall program but requiring a powerwash. - RunPosinstallAction(loop.dev(), "bin/postinst_example", true); + RunPostinstallAction(loop.dev(), + "bin/postinst_example", + /*powerwash_required=*/true, + false); + EXPECT_EQ(ErrorCode::kSuccess, processor_delegate_.code_); + + // Check that powerwash was scheduled. + EXPECT_TRUE(fake_hardware_.IsPowerwashScheduled()); +} + +TEST_F(PostinstallRunnerActionTest, RunAsRootRollbackTest) { + ScopedLoopbackDeviceBinder loop(postinstall_image_, false, nullptr); + + // Run a simple postinstall program, rollback happened. + RunPostinstallAction(loop.dev(), + "bin/postinst_example", + false, + /*is_rollback=*/true); EXPECT_EQ(ErrorCode::kSuccess, processor_delegate_.code_); // Check that powerwash was scheduled. @@ -268,7 +290,7 @@ TEST_F(PostinstallRunnerActionTest, RunAsRootPowerwashRequiredTest) { // Runs postinstall from a partition file that doesn't mount, so it should // fail. TEST_F(PostinstallRunnerActionTest, RunAsRootCantMountTest) { - RunPosinstallAction("/dev/null", kPostinstallDefaultScript, false); + RunPostinstallAction("/dev/null", kPostinstallDefaultScript, false, false); EXPECT_EQ(ErrorCode::kPostinstallRunnerError, processor_delegate_.code_); // In case of failure, Postinstall should not signal a powerwash even if it @@ -280,7 +302,7 @@ TEST_F(PostinstallRunnerActionTest, RunAsRootCantMountTest) { // fail. TEST_F(PostinstallRunnerActionTest, RunAsRootErrScriptTest) { ScopedLoopbackDeviceBinder loop(postinstall_image_, false, nullptr); - RunPosinstallAction(loop.dev(), "bin/postinst_fail1", false); + RunPostinstallAction(loop.dev(), "bin/postinst_fail1", false, false); EXPECT_EQ(ErrorCode::kPostinstallRunnerError, processor_delegate_.code_); } @@ -288,7 +310,7 @@ TEST_F(PostinstallRunnerActionTest, RunAsRootErrScriptTest) { // UMA with a different error code. Test those cases are properly detected. TEST_F(PostinstallRunnerActionTest, RunAsRootFirmwareBErrScriptTest) { ScopedLoopbackDeviceBinder loop(postinstall_image_, false, nullptr); - RunPosinstallAction(loop.dev(), "bin/postinst_fail3", false); + RunPostinstallAction(loop.dev(), "bin/postinst_fail3", false, false); EXPECT_EQ(ErrorCode::kPostinstallBootedFromFirmwareB, processor_delegate_.code_); } @@ -296,7 +318,7 @@ TEST_F(PostinstallRunnerActionTest, RunAsRootFirmwareBErrScriptTest) { // Check that you can't specify an absolute path. TEST_F(PostinstallRunnerActionTest, RunAsRootAbsolutePathNotAllowedTest) { ScopedLoopbackDeviceBinder loop(postinstall_image_, false, nullptr); - RunPosinstallAction(loop.dev(), "/etc/../bin/sh", false); + RunPostinstallAction(loop.dev(), "/etc/../bin/sh", false, false); EXPECT_EQ(ErrorCode::kPostinstallRunnerError, processor_delegate_.code_); } @@ -305,7 +327,7 @@ TEST_F(PostinstallRunnerActionTest, RunAsRootAbsolutePathNotAllowedTest) { // SElinux labels are only set on Android. TEST_F(PostinstallRunnerActionTest, RunAsRootCheckFileContextsTest) { ScopedLoopbackDeviceBinder loop(postinstall_image_, false, nullptr); - RunPosinstallAction(loop.dev(), "bin/self_check_context", false); + RunPosinstallAction(loop.dev(), "bin/self_check_context", false, false); EXPECT_EQ(ErrorCode::kSuccess, processor_delegate_.code_); } #endif // __ANDROID__ @@ -318,7 +340,7 @@ TEST_F(PostinstallRunnerActionTest, RunAsRootSuspendResumeActionTest) { loop_.PostTask(FROM_HERE, base::Bind(&PostinstallRunnerActionTest::SuspendRunningAction, base::Unretained(this))); - RunPosinstallAction(loop.dev(), "bin/postinst_suspend", false); + RunPostinstallAction(loop.dev(), "bin/postinst_suspend", false, false); // postinst_suspend returns 0 only if it was suspended at some point. EXPECT_EQ(ErrorCode::kSuccess, processor_delegate_.code_); EXPECT_TRUE(processor_delegate_.processing_done_called_); @@ -330,7 +352,7 @@ TEST_F(PostinstallRunnerActionTest, RunAsRootCancelPostinstallActionTest) { // Wait for the action to start and then cancel it. CancelWhenStarted(); - RunPosinstallAction(loop.dev(), "bin/postinst_suspend", false); + RunPostinstallAction(loop.dev(), "bin/postinst_suspend", false, false); // When canceling the action, the action never finished and therefore we had // a ProcessingStopped call instead. EXPECT_FALSE(processor_delegate_.code_set_); @@ -353,7 +375,7 @@ TEST_F(PostinstallRunnerActionTest, RunAsRootProgressUpdatesTest) { ScopedLoopbackDeviceBinder loop(postinstall_image_, false, nullptr); setup_action_delegate_ = &mock_delegate_; - RunPosinstallAction(loop.dev(), "bin/postinst_progress", false); + RunPostinstallAction(loop.dev(), "bin/postinst_progress", false, false); EXPECT_EQ(ErrorCode::kSuccess, processor_delegate_.code_); } |