diff options
author | Alex Deymo <deymo@google.com> | 2016-06-03 19:26:58 -0700 |
---|---|---|
committer | Alex Deymo <deymo@google.com> | 2016-06-09 06:02:30 +0000 |
commit | fb905d9b8d49f8fe41297c7aba2dd0942f1be311 (patch) | |
tree | a7a7567b0178b335d6ba876e800b07d6644369a8 /payload_consumer/postinstall_runner_action_unittest.cc | |
parent | 675d0d209eec584968cee9984c093c6d07bee62e (diff) |
Implement powerwash on Android.
Powerwash, the name for the equivalent of a factory reset or /data wipe,
can be triggered in Android by writing the desired command to the
recovery command file and rebooting into recovery.
This patch moves the powerwash scheduling/canceling logic to the
HardwareInterface and implements it on Android.
Bug: 28700985
TEST=Called update_engine_client passing POWERWASH=1, BCB is stored up
to offset 832.
Change-Id: If737fd4b9b3e2ed9bce709b3b59f22e9f0a3dc9a
Diffstat (limited to 'payload_consumer/postinstall_runner_action_unittest.cc')
-rw-r--r-- | payload_consumer/postinstall_runner_action_unittest.cc | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/payload_consumer/postinstall_runner_action_unittest.cc b/payload_consumer/postinstall_runner_action_unittest.cc index 3b6b49a4..5a8e9508 100644 --- a/payload_consumer/postinstall_runner_action_unittest.cc +++ b/payload_consumer/postinstall_runner_action_unittest.cc @@ -26,7 +26,6 @@ #include <base/bind.h> #include <base/files/file_util.h> -#include <base/files/scoped_temp_dir.h> #include <base/message_loop/message_loop.h> #include <base/strings/string_util.h> #include <base/strings/stringprintf.h> @@ -38,6 +37,7 @@ #include "update_engine/common/constants.h" #include "update_engine/common/fake_boot_control.h" +#include "update_engine/common/fake_hardware.h" #include "update_engine/common/test_utils.h" #include "update_engine/common/utils.h" @@ -88,10 +88,6 @@ class PostinstallRunnerActionTest : public ::testing::Test { loop_.SetAsCurrent(); async_signal_handler_.Init(); subprocess_.Init(&async_signal_handler_); - ASSERT_TRUE(working_dir_.CreateUniqueTempDir()); - // We use a test-specific powerwash marker file, to avoid race conditions. - powerwash_marker_file_ = - working_dir_.path().Append("factory_install_reset").value(); // These tests use the postinstall files generated by "generate_images.sh" // stored in the "disk_ext2_unittest.img" image. postinstall_image_ = @@ -154,14 +150,11 @@ class PostinstallRunnerActionTest : public ::testing::Test { brillo::AsynchronousSignalHandler async_signal_handler_; Subprocess subprocess_; - // A temporary working directory used for the test. - base::ScopedTempDir working_dir_; - string powerwash_marker_file_; - // The path to the postinstall sample image. string postinstall_image_; FakeBootControl fake_boot_control_; + FakeHardware fake_hardware_; PostinstActionProcessorDelegate processor_delegate_; // The PostinstallRunnerAction delegate receiving the progress updates. @@ -189,8 +182,7 @@ void PostinstallRunnerActionTest::RunPosinstallAction( install_plan.download_url = "http://127.0.0.1:8080/update"; install_plan.powerwash_required = powerwash_required; feeder_action.set_obj(install_plan); - PostinstallRunnerAction runner_action(&fake_boot_control_, - powerwash_marker_file_.c_str()); + PostinstallRunnerAction runner_action(&fake_boot_control_, &fake_hardware_); postinstall_action_ = &runner_action; runner_action.set_delegate(setup_action_delegate_); BondActions(&feeder_action, &runner_action); @@ -216,8 +208,7 @@ void PostinstallRunnerActionTest::RunPosinstallAction( } TEST_F(PostinstallRunnerActionTest, ProcessProgressLineTest) { - PostinstallRunnerAction action(&fake_boot_control_, - powerwash_marker_file_.c_str()); + PostinstallRunnerAction action(&fake_boot_control_, &fake_hardware_); testing::StrictMock<MockPostinstallRunnerActionDelegate> mock_delegate_; action.set_delegate(&mock_delegate_); @@ -246,7 +237,7 @@ TEST_F(PostinstallRunnerActionTest, RunAsRootSimpleTest) { EXPECT_TRUE(processor_delegate_.processing_done_called_); // Since powerwash_required was false, this should not trigger a powerwash. - EXPECT_FALSE(utils::FileExists(powerwash_marker_file_.c_str())); + EXPECT_FALSE(fake_hardware_.IsPowerwashScheduled()); } TEST_F(PostinstallRunnerActionTest, RunAsRootRunSymlinkFileTest) { @@ -261,11 +252,8 @@ TEST_F(PostinstallRunnerActionTest, RunAsRootPowerwashRequiredTest) { RunPosinstallAction(loop.dev(), "bin/postinst_example", true); EXPECT_EQ(ErrorCode::kSuccess, processor_delegate_.code_); - // Check that the powerwash marker file was set. - string actual_cmd; - EXPECT_TRUE(base::ReadFileToString(base::FilePath(powerwash_marker_file_), - &actual_cmd)); - EXPECT_EQ(kPowerwashCommand, actual_cmd); + // Check that powerwash was scheduled. + EXPECT_TRUE(fake_hardware_.IsPowerwashScheduled()); } // Runs postinstall from a partition file that doesn't mount, so it should @@ -276,7 +264,7 @@ TEST_F(PostinstallRunnerActionTest, RunAsRootCantMountTest) { // In case of failure, Postinstall should not signal a powerwash even if it // was requested. - EXPECT_FALSE(utils::FileExists(powerwash_marker_file_.c_str())); + EXPECT_FALSE(fake_hardware_.IsPowerwashScheduled()); } // Check that the failures from the postinstall script cause the action to |