Move CrashWgtInstaller class to wgt-smoke-utils 57/228657/5
authorSangyoon Jang <jeremy.jang@samsung.com>
Tue, 24 Mar 2020 11:08:04 +0000 (20:08 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Fri, 17 Apr 2020 03:24:48 +0000 (03:24 +0000)
This class can be used at other test, such as smoke test of unified-installer.

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

index 203e3d7..4523d05 100644 (file)
@@ -45,7 +45,7 @@ APPLY_PKG_CONFIG(${TARGET_MANIFEST_TEST} PUBLIC
 # GTEST_MAIN_LIBRARIES is needed.
 TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST} PRIVATE ${TARGET_LIBNAME_WGT} ${TARGET_LIBNAME_HYBRID} ${GTEST_MAIN_LIBRARIES} ${TARGET_SMOKE_UTILS} ${TARGET_WGT_SMOKE_UTILS})
 TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST_EXTENSIVE} PRIVATE ${TARGET_LIBNAME_WGT} ${TARGET_LIBNAME_HYBRID} ${GTEST_MAIN_LIBRARIES} ${TARGET_SMOKE_UTILS} ${TARGET_WGT_SMOKE_UTILS})
-TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST_HELPER} PRIVATE ${TARGET_LIBNAME_WGT})
+TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST_HELPER} PRIVATE ${TARGET_LIBNAME_WGT} ${TARGET_WGT_SMOKE_UTILS})
 TARGET_LINK_LIBRARIES(${TARGET_MANIFEST_TEST} PRIVATE ${TARGET_LIBNAME_WGT} ${GTEST_MAIN_LIBRARIES})
 TARGET_LINK_LIBRARIES(${TARGET_WGT_SMOKE_UTILS} PRIVATE ${TARGET_LIBNAME_WGT} ${TARGET_LIBNAME_HYBRID} ${TARGET_SMOKE_UTILS})
 
index 6e8643c..0c0e6f4 100644 (file)
@@ -3,99 +3,20 @@
 // found in the LICENSE file.
 
 #include <common/pkgmgr_interface.h>
-#include <cerrno>
+#include <manifest_parser/utils/logging.h>
 
+#include "unit_tests/wgt_smoke_utils.h"
 #include "wgt/utils/wgt_app_query_interface.h"
 #include "wgt/wgt_installer.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 {                                                      \
-    wgt::WgtInstaller::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 CrashWgtInstaller : public wgt::WgtInstaller {
- public:
-  explicit CrashWgtInstaller(ci::PkgMgrPtr pkgmgr, int crash_at,
-      std::string step_name, CrashStepType type) :
-          wgt::WgtInstaller(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_;
-};
-
-}  // namespace
-
 // this main of test binay in done purely for recovery smoke test.
 int main(int argc, char** argv) {
   int index = -1;
   int backend_argc = argc;
   std::string step_name;
-  CrashStepType type = CrashStepType::PROCESS;
+  smoke_test::CrashStepType type = smoke_test::CrashStepType::PROCESS;
 
   if (!strcmp(argv[backend_argc - 2], "-idx")) {
     index = atoi(argv[argc - 1]);
@@ -111,7 +32,7 @@ int main(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";
   }
 
@@ -124,7 +45,7 @@ int main(int argc, char** argv) {
     return EINVAL;
   }
 
-  ::CrashWgtInstaller installer(pkgmgr, index, step_name, type);
+  smoke_test::CrashWgtInstaller installer(pkgmgr, index, step_name, type);
   return (installer.Run() == ci::AppInstaller::Result::OK) ? 0 : 1;
 }
 
index 6de6b32..3aa4ec7 100644 (file)
@@ -131,6 +131,54 @@ class FailExpectedHybridInstaller : public hybrid::HybridInstaller {
   int fail_at_;
 };
 
+#ifdef OVERRIDE_STEPS_BLOCK
+#undef OVERRIDE_STEPS_BLOCK
+#endif
+#define OVERRIDE_STEPS_BLOCK(STEPS)                                            \
+  void STEPS() override {                                                      \
+    wgt::WgtInstaller::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 CrashWgtInstaller : public wgt::WgtInstaller {
+ public:
+  explicit CrashWgtInstaller(common_installer::PkgMgrPtr pkgmgr, int crash_at,
+      std::string step_name, CrashStepType type) :
+          wgt::WgtInstaller(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_;
+};
+
 }  // namespace smoke_test