summaryrefslogtreecommitdiff
path: root/payload_consumer/filesystem_verifier_action_unittest.cc
diff options
context:
space:
mode:
authorSen Jiang <senj@google.com>2018-08-13 15:41:43 -0700
committerSen Jiang <senj@google.com>2018-08-13 16:21:46 -0700
commit456853f95df07a8b87985395e8ce192a23aaa02b (patch)
treed37bfe0df2dc3b79e6aad402c00f612ff25cd509 /payload_consumer/filesystem_verifier_action_unittest.cc
parentf6b0daf427de7a407406f58a73978e774d3d4260 (diff)
parent20262ad1d3f8d620b7227fd8d9e13938243ce32f (diff)
Merge remote-tracking branch 'aosp/upstream-master' into aosp/master.
The following change is reverted because aosp has newer libchrome. 71818c84 Partially Revert 2b9d241 Added stub override for ReportInternalErrorCode(). Fixed RunPosinstallAction typo. Bug: 112326236 Test: update_engine_unittests Change-Id: Ieaae0eef425cbb1278067a48aa19b14ed056317a
Diffstat (limited to 'payload_consumer/filesystem_verifier_action_unittest.cc')
-rw-r--r--payload_consumer/filesystem_verifier_action_unittest.cc116
1 files changed, 55 insertions, 61 deletions
diff --git a/payload_consumer/filesystem_verifier_action_unittest.cc b/payload_consumer/filesystem_verifier_action_unittest.cc
index fd1d0845..91a7da49 100644
--- a/payload_consumer/filesystem_verifier_action_unittest.cc
+++ b/payload_consumer/filesystem_verifier_action_unittest.cc
@@ -18,8 +18,10 @@
#include <fcntl.h>
+#include <memory>
#include <set>
#include <string>
+#include <utility>
#include <vector>
#include <base/bind.h>
@@ -61,27 +63,14 @@ class FilesystemVerifierActionTest : public ::testing::Test {
class FilesystemVerifierActionTestDelegate : public ActionProcessorDelegate {
public:
- explicit FilesystemVerifierActionTestDelegate(
- FilesystemVerifierAction* action)
- : action_(action), ran_(false), code_(ErrorCode::kError) {}
- void ExitMainLoop() {
- // We need to wait for the Action to call Cleanup.
- if (action_->IsCleanupPending()) {
- LOG(INFO) << "Waiting for Cleanup() to be called.";
- MessageLoop::current()->PostDelayedTask(
- FROM_HERE,
- base::Bind(&FilesystemVerifierActionTestDelegate::ExitMainLoop,
- base::Unretained(this)),
- base::TimeDelta::FromMilliseconds(100));
- } else {
- MessageLoop::current()->BreakLoop();
- }
- }
+ FilesystemVerifierActionTestDelegate()
+ : ran_(false), code_(ErrorCode::kError) {}
+
void ProcessingDone(const ActionProcessor* processor, ErrorCode code) {
- ExitMainLoop();
+ MessageLoop::current()->BreakLoop();
}
void ProcessingStopped(const ActionProcessor* processor) {
- ExitMainLoop();
+ MessageLoop::current()->BreakLoop();
}
void ActionCompleted(ActionProcessor* processor,
AbstractAction* action,
@@ -89,27 +78,24 @@ class FilesystemVerifierActionTestDelegate : public ActionProcessorDelegate {
if (action->Type() == FilesystemVerifierAction::StaticType()) {
ran_ = true;
code_ = code;
+ EXPECT_FALSE(static_cast<FilesystemVerifierAction*>(action)->src_stream_);
+ } else if (action->Type() ==
+ ObjectCollectorAction<InstallPlan>::StaticType()) {
+ auto collector_action =
+ static_cast<ObjectCollectorAction<InstallPlan>*>(action);
+ install_plan_.reset(new InstallPlan(collector_action->object()));
}
}
bool ran() const { return ran_; }
ErrorCode code() const { return code_; }
+ std::unique_ptr<InstallPlan> install_plan_;
+
private:
- FilesystemVerifierAction* action_;
bool ran_;
ErrorCode code_;
};
-void StartProcessorInRunLoop(ActionProcessor* processor,
- FilesystemVerifierAction* filesystem_copier_action,
- bool terminate_early) {
- processor->StartProcessing();
- if (terminate_early) {
- EXPECT_NE(nullptr, filesystem_copier_action);
- processor->StopProcessing();
- }
-}
-
bool FilesystemVerifierActionTest::DoTest(bool terminate_early,
bool hash_fail) {
test_utils::ScopedTempFile a_loop_file("a_loop_file.XXXXXX");
@@ -158,27 +144,32 @@ bool FilesystemVerifierActionTest::DoTest(bool terminate_early,
}
install_plan.partitions = {part};
- ActionProcessor processor;
-
- ObjectFeederAction<InstallPlan> feeder_action;
- FilesystemVerifierAction copier_action;
- ObjectCollectorAction<InstallPlan> collector_action;
+ auto feeder_action = std::make_unique<ObjectFeederAction<InstallPlan>>();
+ feeder_action->set_obj(install_plan);
+ auto copier_action = std::make_unique<FilesystemVerifierAction>();
+ auto collector_action =
+ std::make_unique<ObjectCollectorAction<InstallPlan>>();
- BondActions(&feeder_action, &copier_action);
- BondActions(&copier_action, &collector_action);
+ BondActions(feeder_action.get(), copier_action.get());
+ BondActions(copier_action.get(), collector_action.get());
- FilesystemVerifierActionTestDelegate delegate(&copier_action);
+ ActionProcessor processor;
+ FilesystemVerifierActionTestDelegate delegate;
processor.set_delegate(&delegate);
- processor.EnqueueAction(&feeder_action);
- processor.EnqueueAction(&copier_action);
- processor.EnqueueAction(&collector_action);
-
- feeder_action.set_obj(install_plan);
-
- loop_.PostTask(FROM_HERE, base::Bind(&StartProcessorInRunLoop,
- &processor,
- &copier_action,
- terminate_early));
+ processor.EnqueueAction(std::move(feeder_action));
+ processor.EnqueueAction(std::move(copier_action));
+ processor.EnqueueAction(std::move(collector_action));
+
+ loop_.PostTask(FROM_HERE,
+ base::Bind(
+ [](ActionProcessor* processor, bool terminate_early) {
+ processor->StartProcessing();
+ if (terminate_early) {
+ processor->StopProcessing();
+ }
+ },
+ base::Unretained(&processor),
+ terminate_early));
loop_.Run();
if (!terminate_early) {
@@ -207,7 +198,7 @@ bool FilesystemVerifierActionTest::DoTest(bool terminate_early,
EXPECT_TRUE(is_a_file_reading_eq);
success = success && is_a_file_reading_eq;
- bool is_install_plan_eq = (collector_action.object() == install_plan);
+ bool is_install_plan_eq = (*delegate.install_plan_ == install_plan);
EXPECT_TRUE(is_install_plan_eq);
success = success && is_install_plan_eq;
return success;
@@ -233,13 +224,14 @@ TEST_F(FilesystemVerifierActionTest, MissingInputObjectTest) {
processor.set_delegate(&delegate);
- FilesystemVerifierAction copier_action;
- ObjectCollectorAction<InstallPlan> collector_action;
+ auto copier_action = std::make_unique<FilesystemVerifierAction>();
+ auto collector_action =
+ std::make_unique<ObjectCollectorAction<InstallPlan>>();
- BondActions(&copier_action, &collector_action);
+ BondActions(copier_action.get(), collector_action.get());
- processor.EnqueueAction(&copier_action);
- processor.EnqueueAction(&collector_action);
+ processor.EnqueueAction(std::move(copier_action));
+ processor.EnqueueAction(std::move(collector_action));
processor.StartProcessing();
EXPECT_FALSE(processor.IsRunning());
EXPECT_TRUE(delegate.ran_);
@@ -252,7 +244,6 @@ TEST_F(FilesystemVerifierActionTest, NonExistentDriveTest) {
processor.set_delegate(&delegate);
- ObjectFeederAction<InstallPlan> feeder_action;
InstallPlan install_plan;
InstallPlan::Partition part;
part.name = "nope";
@@ -260,15 +251,18 @@ TEST_F(FilesystemVerifierActionTest, NonExistentDriveTest) {
part.target_path = "/no/such/file";
install_plan.partitions = {part};
- feeder_action.set_obj(install_plan);
- FilesystemVerifierAction verifier_action;
- ObjectCollectorAction<InstallPlan> collector_action;
+ auto feeder_action = std::make_unique<ObjectFeederAction<InstallPlan>>();
+ auto verifier_action = std::make_unique<FilesystemVerifierAction>();
+ auto collector_action =
+ std::make_unique<ObjectCollectorAction<InstallPlan>>();
+
+ feeder_action->set_obj(install_plan);
- BondActions(&verifier_action, &collector_action);
+ BondActions(verifier_action.get(), collector_action.get());
- processor.EnqueueAction(&feeder_action);
- processor.EnqueueAction(&verifier_action);
- processor.EnqueueAction(&collector_action);
+ processor.EnqueueAction(std::move(feeder_action));
+ processor.EnqueueAction(std::move(verifier_action));
+ processor.EnqueueAction(std::move(collector_action));
processor.StartProcessing();
EXPECT_FALSE(processor.IsRunning());
EXPECT_TRUE(delegate.ran_);