From: Ilho Kim Date: Thu, 27 Feb 2020 01:50:03 +0000 (+0900) Subject: Add StepCrash's clean operation X-Git-Tag: accepted/tizen/unified/20200309.031506~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=832271df62d44a92ebb4cd06927799a34e3b4d46;p=platform%2Fcore%2Fappfw%2Fwgt-backend.git Add StepCrash's clean operation This patch can be used to test the installation termination in a clean operation Change-Id: I9b5cc0e991d84196d4738d360d106b55c8e352ff Signed-off-by: Ilho Kim --- diff --git a/src/unit_tests/smoke_test_helper.cc b/src/unit_tests/smoke_test_helper.cc index 9d666b2..6e8643c 100644 --- a/src/unit_tests/smoke_test_helper.cc +++ b/src/unit_tests/smoke_test_helper.cc @@ -12,37 +12,54 @@ namespace ci = common_installer; namespace { +enum class CrashStepType { + PROCESS, + CLEAN +}; + class StepCrash : public ci::Step { public: using Step::Step; + explicit StepCrash(ci::InstallerContext* context, CrashStepType type) : + ci::Step::Step(context), type_(type) {} + ci::Step::Status process() override { - raise(SIGSEGV); + if (type_ == CrashStepType::PROCESS) + raise(SIGSEGV); + return Status::OK; + } + ci::Step::Status clean() override { + if (type_ == CrashStepType::CLEAN) + raise(SIGSEGV); return Status::OK; } - ci::Step::Status clean() override { return ci::Step::Status::OK; } ci::Step::Status undo() override { return ci::Step::Status::OK; } ci::Step::Status precheck() override { return ci::Step::Status::OK; } STEP_NAME(Crash) + + private: + CrashStepType type_; }; #define OVERRIDE_STEPS_BLOCK(STEPS) \ void STEPS() override { \ wgt::WgtInstaller::STEPS(); \ if (crash_at_ > -1) \ - AddStepAtIndex(crash_at_); \ + AddStepAtIndex(crash_at_, type_); \ else if (step_name_.size()) \ - AddStepAfter(step_name_); \ + AddStepAfter(step_name_, type_); \ else \ - AddStep(); \ + AddStep(type_); \ } \ class CrashWgtInstaller : public wgt::WgtInstaller { public: explicit CrashWgtInstaller(ci::PkgMgrPtr pkgmgr, int crash_at, - std::string step_name) : wgt::WgtInstaller(pkgmgr), crash_at_(crash_at), - step_name_(step_name) { } + std::string step_name, CrashStepType type) : + wgt::WgtInstaller(pkgmgr), crash_at_(crash_at), + step_name_(step_name), type_(type) { } private: OVERRIDE_STEPS_BLOCK(InstallSteps) @@ -68,6 +85,7 @@ class CrashWgtInstaller : public wgt::WgtInstaller { int crash_at_; std::string step_name_; + CrashStepType type_; }; } // namespace @@ -77,18 +95,26 @@ int main(int argc, char** argv) { int index = -1; int backend_argc = argc; std::string step_name; - if (!strcmp(argv[argc-2], "-idx")) { - index = atoi(argv[argc-1]); - backend_argc = argc - 2; + CrashStepType type = CrashStepType::PROCESS; + + if (!strcmp(argv[backend_argc - 2], "-idx")) { + index = atoi(argv[argc - 1]); + backend_argc -= 2; LOG(DEBUG) << "Step crash after " << index << " step."; } - if (!strcmp(argv[argc-2], "-step_name")) { - step_name = argv[argc-1]; - backend_argc = argc-2; + if (!strcmp(argv[backend_argc - 2], "-step_name")) { + step_name = argv[backend_argc - 1]; + backend_argc -= 2; LOG(DEBUG) << "Step crash after " << step_name << " step."; } + if (!strcmp(argv[backend_argc - 1], "-type_clean")) { + backend_argc--; + type = CrashStepType::CLEAN; + LOG(DEBUG) << "step will be crashed in clean operation"; + } + ci::PkgmgrInstaller pkgmgr_installer; wgt::WgtAppQueryInterface query_interface; auto pkgmgr = ci::PkgMgrInterface::Create(backend_argc, argv, @@ -98,7 +124,7 @@ int main(int argc, char** argv) { return EINVAL; } - ::CrashWgtInstaller installer(pkgmgr, index, step_name); + ::CrashWgtInstaller installer(pkgmgr, index, step_name, type); return (installer.Run() == ci::AppInstaller::Result::OK) ? 0 : 1; }