Add StepCrash's clean operation 02/226102/3
authorIlho Kim <ilho159.kim@samsung.com>
Thu, 27 Feb 2020 01:17:20 +0000 (10:17 +0900)
committerilho kim <ilho159.kim@samsung.com>
Thu, 27 Feb 2020 23:19:55 +0000 (23:19 +0000)
This patch can be used to test the installation termination in a clean operation

Change-Id: Iea285d4f6e66dc7104c00665c46a3295a91c8b93
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/unit_tests/smoke_test_helper.cc

index 26b3ccff230a570d7f3bf3799ddbcbdcddfa60c8..df2004a78600a2e2125ab1fe2d7d91d88cf477cd 100644 (file)
@@ -15,30 +15,46 @@ 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 {                                                      \
     tpk::TpkInstaller::STEPS();                                                \
     if (crash_at_ > -1)                                                        \
-      AddStepAtIndex<StepCrash>(crash_at_);                                    \
+      AddStepAtIndex<StepCrash>(crash_at_, type_);                             \
     else if (step_name_.size())                                                \
-      AddStepAfter<StepCrash>(step_name_);                                     \
+      AddStepAfter<StepCrash>(step_name_, type_);                              \
     else                                                                       \
-      AddStep<StepCrash>();                                                    \
+      AddStep<StepCrash>(type_);                                               \
   }                                                                            \
 
 #define OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(STEPS)                     \
@@ -50,8 +66,9 @@ class StepCrash : public ci::Step {
 class CrashTpkInstaller : public tpk::TpkInstaller {
  public:
   explicit CrashTpkInstaller(ci::PkgMgrPtr pkgmgr, int crash_at,
-      std::string step_name) : tpk::TpkInstaller(pkgmgr), crash_at_(crash_at),
-          step_name_(step_name) { }
+      std::string step_name, CrashStepType type) :
+          tpk::TpkInstaller(pkgmgr), crash_at_(crash_at),
+          step_name_(step_name), type_(type) {}
 
  private:
   OVERRIDE_STEPS_BLOCK(InstallSteps)
@@ -77,6 +94,7 @@ class CrashTpkInstaller : public tpk::TpkInstaller {
 
   int crash_at_;
   std::string step_name_;
+  CrashStepType type_;
 };
 
 class TpkInstallerWithoutPasrserPlugins : public tpk::TpkInstaller {
@@ -114,8 +132,9 @@ class TpkInstallerWithoutPasrserPlugins : public tpk::TpkInstaller {
 
 static int RunCrashTpkInstaller(ci::PkgMgrPtr pkgmgr,
                                 int index,
-                                std::string step_name) {
-  ::CrashTpkInstaller t(pkgmgr, index, step_name);
+                                std::string step_name,
+                                CrashStepType type) {
+  ::CrashTpkInstaller t(pkgmgr, index, step_name, type);
 
   if (t.Run() != ci::AppInstaller::Result::OK) {
     LOG(ERROR) << "CrashTpkInstaller run failure";
@@ -141,24 +160,32 @@ int main(const int argc, char* argv[]) {
   int backend_argc = argc;
   std::string step_name;
   bool remove_plugins = false;
-  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[backend_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[argc-1], "-remove_plugin_steps")) {
-    backend_argc = argc-1;
+  if (!strcmp(argv[backend_argc-1], "-remove_plugin_steps")) {
+    backend_argc--;
     remove_plugins = true;
     LOG(DEBUG) << "Remove parser plugins steps";
   }
 
+  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;
   tpk::TpkAppQueryInterface interface;
   ci::PkgMgrPtr pkgmgr = ci::PkgMgrInterface::Create(backend_argc, argv,
@@ -172,5 +199,5 @@ int main(const int argc, char* argv[]) {
   if (remove_plugins)
     return RunTpkInstallerWithoutParserPlugins(pkgmgr);
   else
-    return RunCrashTpkInstaller(pkgmgr, index, step_name);
+    return RunCrashTpkInstaller(pkgmgr, index, step_name, type);
 }