Move CrashTpkInstaller class to tpk-smoke-utils 58/228658/5
authorSangyoon Jang <jeremy.jang@samsung.com>
Tue, 24 Mar 2020 11:11:44 +0000 (20:11 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Fri, 17 Apr 2020 03:23:10 +0000 (03:23 +0000)
This class can be used at other test, such as smoke test of unified-installer.

Change-Id: Idf72e0c8533b5d70530d36684d7ec7c534627416
Signed-off-by: Sangyoon Jang <jeremy.jang@samsung.com>
src/unit_tests/CMakeLists.txt
src/unit_tests/smoke_test_helper.cc
src/unit_tests/tpk_smoke_utils.h

index 204ddb8cb2ea6e37c4ab94db7c475268c6947e5a..d38d2f17f88b21b4476b6c4827dc7403520340b4 100644 (file)
@@ -64,7 +64,7 @@ APPLY_PKG_CONFIG(${TARGET_RECOVERY_TEST} PUBLIC
 # GTEST_MAIN_LIBRARIES is needed.
 TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST} PRIVATE ${TARGET_LIBNAME_TPK} ${GTEST_MAIN_LIBRARIES} ${TARGET_SMOKE_UTILS} ${TARGET_TPK_SMOKE_UTILS})
 TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST_EXTENSIVE} PRIVATE ${TARGET_LIBNAME_TPK} ${GTEST_MAIN_LIBRARIES} ${TARGET_SMOKE_UTILS} ${TARGET_TPK_SMOKE_UTILS})
-TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST_HELPER} PRIVATE ${TARGET_LIBNAME_TPK})
+TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST_HELPER} PRIVATE ${TARGET_LIBNAME_TPK} ${TARGET_TPK_SMOKE_UTILS})
 TARGET_LINK_LIBRARIES(${TARGET_MANIFEST_TEST} PRIVATE ${TARGET_LIBNAME_TPK} ${GTEST_MAIN_LIBRARIES})
 TARGET_LINK_LIBRARIES(${TARGET_RECOVERY_TEST} PRIVATE ${TARGET_LIBNAME_TPK} ${GTEST_MAIN_LIBRARIES} ${TARGET_SMOKE_UTILS} ${TARGET_TPK_SMOKE_UTILS})
 TARGET_LINK_LIBRARIES(${TARGET_TPK_SMOKE_UTILS} PRIVATE ${TARGET_LIBNAME_TPK} ${TARGET_SMOKE_UTILS})
index df2004a78600a2e2125ab1fe2d7d91d88cf477cd..e2706b496266e4ac3c6a23fa6d4783c0c350e9d6 100644 (file)
 // found in the LICENSE file.
 
 #include <common/pkgmgr_interface.h>
-#include <common/step/step.h>
 #include <manifest_parser/utils/logging.h>
 
-#include <iostream>
-
 #include "tpk/tpk_app_query_interface.h"
 #include "tpk/tpk_installer.h"
+#include "unit_tests/tpk_smoke_utils.h"
 
 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 {
-    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 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_, type_);                             \
-    else if (step_name_.size())                                                \
-      AddStepAfter<StepCrash>(step_name_, type_);                              \
-    else                                                                       \
-      AddStep<StepCrash>(type_);                                               \
-  }                                                                            \
-
-#define OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(STEPS)                     \
-  void STEPS() override {                                                      \
-    tpk::TpkInstaller::STEPS();                                                \
-    RemoveStep("RunParserPlugin");                                             \
-  }                                                                            \
-
-class CrashTpkInstaller : public tpk::TpkInstaller {
- public:
-  explicit CrashTpkInstaller(ci::PkgMgrPtr pkgmgr, int crash_at,
-      std::string step_name, CrashStepType type) :
-          tpk::TpkInstaller(pkgmgr), crash_at_(crash_at),
-          step_name_(step_name), type_(type) {}
-
- private:
-  OVERRIDE_STEPS_BLOCK(InstallSteps)
-  OVERRIDE_STEPS_BLOCK(UpdateSteps)
-  OVERRIDE_STEPS_BLOCK(UninstallSteps)
-  OVERRIDE_STEPS_BLOCK(ReinstallSteps)
-  OVERRIDE_STEPS_BLOCK(DeltaSteps)
-  OVERRIDE_STEPS_BLOCK(MoveSteps)
-  OVERRIDE_STEPS_BLOCK(RecoverySteps)
-  OVERRIDE_STEPS_BLOCK(MountInstallSteps)
-  OVERRIDE_STEPS_BLOCK(MountUpdateSteps)
-  OVERRIDE_STEPS_BLOCK(ManifestDirectInstallSteps)
-  OVERRIDE_STEPS_BLOCK(ManifestDirectUpdateSteps)
-  OVERRIDE_STEPS_BLOCK(ManifestPartialInstallSteps)
-  OVERRIDE_STEPS_BLOCK(ManifestPartialUpdateSteps)
-  OVERRIDE_STEPS_BLOCK(PartialUninstallSteps)
-  OVERRIDE_STEPS_BLOCK(ReadonlyUpdateInstallSteps)
-  OVERRIDE_STEPS_BLOCK(ReadonlyUpdateUninstallSteps)
-  OVERRIDE_STEPS_BLOCK(DisablePkgSteps)
-  OVERRIDE_STEPS_BLOCK(EnablePkgSteps)
-  OVERRIDE_STEPS_BLOCK(MigrateExtImgSteps)
-  OVERRIDE_STEPS_BLOCK(RecoverDBSteps)
-
-  int crash_at_;
-  std::string step_name_;
-  CrashStepType type_;
-};
-
-class TpkInstallerWithoutPasrserPlugins : public tpk::TpkInstaller {
- public:
-  explicit TpkInstallerWithoutPasrserPlugins(ci::PkgMgrPtr pkgmgr) :
-      tpk::TpkInstaller(pkgmgr) { }
-
- private:
-  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(InstallSteps)
-  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(UpdateSteps)
-  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(UninstallSteps)
-  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(ReinstallSteps)
-  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(DeltaSteps)
-  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(MoveSteps)
-  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(MountInstallSteps)
-  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(MountUpdateSteps)
-  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(ManifestDirectInstallSteps)
-  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(ManifestDirectUpdateSteps)
-  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(ManifestPartialInstallSteps)
-  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(ManifestPartialUpdateSteps)
-  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(PartialUninstallSteps)
-  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(ReadonlyUpdateInstallSteps)
-  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(ReadonlyUpdateUninstallSteps)
-  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(DisablePkgSteps)
-  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(EnablePkgSteps)
-  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(MigrateExtImgSteps)
-  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(RecoverDBSteps)
-  void RecoverySteps() override {
-    tpk::TpkInstaller::RecoverySteps();
-    RemoveStep("RecoverParserPlugin");
-  }
-};
-
-}  // namespace
-
 static int RunCrashTpkInstaller(ci::PkgMgrPtr pkgmgr,
                                 int index,
                                 std::string step_name,
-                                CrashStepType type) {
-  ::CrashTpkInstaller t(pkgmgr, index, step_name, type);
+                                smoke_test::CrashStepType type) {
+  smoke_test::CrashTpkInstaller t(pkgmgr, index, step_name, type);
 
   if (t.Run() != ci::AppInstaller::Result::OK) {
     LOG(ERROR) << "CrashTpkInstaller run failure";
@@ -144,7 +25,7 @@ static int RunCrashTpkInstaller(ci::PkgMgrPtr pkgmgr,
 }
 
 static int RunTpkInstallerWithoutParserPlugins(ci::PkgMgrPtr pkgmgr) {
-  ::TpkInstallerWithoutPasrserPlugins t(pkgmgr);
+  smoke_test::TpkInstallerWithoutPasrserPlugins t(pkgmgr);
 
   if (t.Run() != ci::AppInstaller::Result::OK) {
     LOG(ERROR) << "TpkInstallerWithoutPasrserPlugins run failure";
@@ -160,7 +41,7 @@ int main(const int argc, char* argv[]) {
   int backend_argc = argc;
   std::string step_name;
   bool remove_plugins = false;
-  CrashStepType type = CrashStepType::PROCESS;
+  smoke_test::CrashStepType type = smoke_test::CrashStepType::PROCESS;
 
   if (!strcmp(argv[backend_argc-2], "-idx")) {
      index = atoi(argv[backend_argc-1]);
@@ -182,7 +63,7 @@ int main(const int argc, char* argv[]) {
 
   if (!strcmp(argv[backend_argc-1], "-type_clean")) {
     backend_argc--;
-    type = CrashStepType::CLEAN;
+    type = smoke_test::CrashStepType::CLEAN;
     LOG(DEBUG) << "step will be crashed in clean operation";
   }
 
index aeaa259d160c319361bb42ad9068ed41576a2edf..57a76ad1d9c2ed91a60d95f9234179e7e68d7efd 100644 (file)
@@ -103,6 +103,94 @@ class FailExpectedTpkInstaller : public tpk::TpkInstaller {
   int fail_at_;
 };
 
+#ifdef OVERRIDE_STEPS_BLOCK
+#undef OVERRIDE_STEPS_BLOCK
+#endif
+#define OVERRIDE_STEPS_BLOCK(STEPS)                                            \
+  void STEPS() override {                                                      \
+    tpk::TpkInstaller::STEPS();                                                \
+    if (crash_at_ > -1)                                                        \
+      AddStepAtIndex<StepCrash>(crash_at_, type_);                             \
+    else if (step_name_.size())                                                \
+      AddStepAfter<StepCrash>(step_name_, type_);                              \
+    else                                                                       \
+      AddStep<StepCrash>(type_);                                               \
+  }                                                                            \
+
+class CrashTpkInstaller : public tpk::TpkInstaller {
+ public:
+  explicit CrashTpkInstaller(common_installer::PkgMgrPtr pkgmgr, int crash_at,
+      std::string step_name, CrashStepType type) :
+          tpk::TpkInstaller(pkgmgr), crash_at_(crash_at),
+          step_name_(step_name), type_(type) {}
+
+ private:
+  OVERRIDE_STEPS_BLOCK(InstallSteps)
+  OVERRIDE_STEPS_BLOCK(UpdateSteps)
+  OVERRIDE_STEPS_BLOCK(UninstallSteps)
+  OVERRIDE_STEPS_BLOCK(ReinstallSteps)
+  OVERRIDE_STEPS_BLOCK(DeltaSteps)
+  OVERRIDE_STEPS_BLOCK(MoveSteps)
+  OVERRIDE_STEPS_BLOCK(RecoverySteps)
+  OVERRIDE_STEPS_BLOCK(MountInstallSteps)
+  OVERRIDE_STEPS_BLOCK(MountUpdateSteps)
+  OVERRIDE_STEPS_BLOCK(ManifestDirectInstallSteps)
+  OVERRIDE_STEPS_BLOCK(ManifestDirectUpdateSteps)
+  OVERRIDE_STEPS_BLOCK(ManifestPartialInstallSteps)
+  OVERRIDE_STEPS_BLOCK(ManifestPartialUpdateSteps)
+  OVERRIDE_STEPS_BLOCK(PartialUninstallSteps)
+  OVERRIDE_STEPS_BLOCK(ReadonlyUpdateInstallSteps)
+  OVERRIDE_STEPS_BLOCK(ReadonlyUpdateUninstallSteps)
+  OVERRIDE_STEPS_BLOCK(DisablePkgSteps)
+  OVERRIDE_STEPS_BLOCK(EnablePkgSteps)
+  OVERRIDE_STEPS_BLOCK(MigrateExtImgSteps)
+  OVERRIDE_STEPS_BLOCK(RecoverDBSteps)
+
+  int crash_at_;
+  std::string step_name_;
+  CrashStepType type_;
+};
+
+#ifdef OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS
+#undef OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS
+#endif
+#define OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(STEPS)                     \
+  void STEPS() override {                                                      \
+    tpk::TpkInstaller::STEPS();                                                \
+    RemoveStep("RunParserPlugin");                                             \
+  }                                                                            \
+
+class TpkInstallerWithoutPasrserPlugins : public tpk::TpkInstaller {
+ public:
+  explicit TpkInstallerWithoutPasrserPlugins(
+      common_installer::PkgMgrPtr pkgmgr) : tpk::TpkInstaller(pkgmgr) { }
+
+ private:
+  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(InstallSteps)
+  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(UpdateSteps)
+  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(UninstallSteps)
+  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(ReinstallSteps)
+  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(DeltaSteps)
+  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(MoveSteps)
+  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(MountInstallSteps)
+  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(MountUpdateSteps)
+  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(ManifestDirectInstallSteps)
+  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(ManifestDirectUpdateSteps)
+  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(ManifestPartialInstallSteps)
+  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(ManifestPartialUpdateSteps)
+  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(PartialUninstallSteps)
+  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(ReadonlyUpdateInstallSteps)
+  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(ReadonlyUpdateUninstallSteps)
+  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(DisablePkgSteps)
+  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(EnablePkgSteps)
+  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(MigrateExtImgSteps)
+  OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(RecoverDBSteps)
+  void RecoverySteps() override {
+    tpk::TpkInstaller::RecoverySteps();
+    RemoveStep("RecoverParserPlugin");
+  }
+};
+
 }  // namespace smoke_test