Add hybrid smoke test helper 19/286419/1
authorilho kim <ilho159.kim@samsung.com>
Thu, 5 Jan 2023 12:44:52 +0000 (21:44 +0900)
committerilho kim <ilho159.kim@samsung.com>
Thu, 5 Jan 2023 12:47:17 +0000 (21:47 +0900)
This tool is used to execute installer with crash or plugin removed in
hybrid smoke test

Change-Id: Ic461c8faadf15753e2c0e2a9490bbf3340fa9bcc
Signed-off-by: ilho kim <ilho159.kim@samsung.com>
CMakeLists.txt
packaging/wgt-backend.spec
packaging/wgt-installer-tests.manifest
test/smoke_tests/CMakeLists.txt
test/smoke_tests/hybrid_smoke_test_helper.cc [new file with mode: 0644]
test/smoke_tests/wgt_smoke_utils.cc
test/smoke_tests/wgt_smoke_utils.h

index b39ba87..c1435dc 100644 (file)
@@ -33,6 +33,7 @@ SET(TARGET_LIBNAME_HYBRID "hybrid-installer")
 SET(TARGET_SMOKE_TEST "smoke-test")
 SET(TARGET_SMOKE_TEST_EXTENSIVE "extensive-smoke-test")
 SET(TARGET_SMOKE_TEST_HELPER "smoke-test-helper")
+SET(TARGET_HYBRID_SMOKE_TEST_HELPER "hybrid-smoke-test-helper")
 SET(TARGET_MANIFEST_TEST "manifest-test")
 SET(TARGET_WGT_SMOKE_UTILS "wgt-smoke-utils")
 
index 958c74b..8990a08 100644 (file)
@@ -75,6 +75,7 @@ ln -s %{_bindir}/wgt-backend %{buildroot}%{_sysconfdir}/package-manager/backend/
 %post -n wgt-installer-tests
 /usr/sbin/setcap cap_chown,cap_dac_override,cap_fowner,cap_mac_override=eip %{_bindir}/wgt-installer-ut/smoke-test
 /usr/sbin/setcap cap_chown,cap_dac_override,cap_fowner,cap_mac_override=eip %{_bindir}/wgt-installer-ut/smoke-test-helper
+/usr/sbin/setcap cap_chown,cap_dac_override,cap_fowner,cap_mac_override=eip %{_bindir}/wgt-installer-ut/hybrid-smoke-test-helper
 /usr/sbin/setcap cap_chown,cap_dac_override,cap_fowner,cap_mac_override=eip %{_bindir}/wgt-installer-ut/extensive-smoke-test
 
 %files
index e0632fd..e4cbba4 100644 (file)
@@ -5,6 +5,7 @@
         <assign>
                 <filesystem path="/usr/bin/wgt-installer-ut/smoke-test" exec_label="System::Privileged" />
                 <filesystem path="/usr/bin/wgt-installer-ut/smoke-test-helper" exec_label="System::Privileged" />
+                <filesystem path="/usr/bin/wgt-installer-ut/hybrid-smoke-test-helper" exec_label="System::Privileged" />
                 <filesystem path="/usr/bin/wgt-installer-ut/extensive-smoke-test" exec_label="System::Privileged" />
         </assign>
 </manifest>
index 0bd8a0a..fa1ad77 100644 (file)
@@ -11,6 +11,9 @@ ADD_EXECUTABLE(${TARGET_SMOKE_TEST_EXTENSIVE}
 ADD_EXECUTABLE(${TARGET_SMOKE_TEST_HELPER}
   smoke_test_helper.cc
 )
+ADD_EXECUTABLE(${TARGET_HYBRID_SMOKE_TEST_HELPER}
+  hybrid_smoke_test_helper.cc
+)
 ADD_EXECUTABLE(${TARGET_MANIFEST_TEST}
   manifest_test.cc
 )
@@ -21,6 +24,7 @@ ADD_LIBRARY(${TARGET_WGT_SMOKE_UTILS} SHARED
 TARGET_INCLUDE_DIRECTORIES(${TARGET_SMOKE_TEST} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)
 TARGET_INCLUDE_DIRECTORIES(${TARGET_SMOKE_TEST_EXTENSIVE} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)
 TARGET_INCLUDE_DIRECTORIES(${TARGET_SMOKE_TEST_HELPER} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)
+TARGET_INCLUDE_DIRECTORIES(${TARGET_HYBRID_SMOKE_TEST_HELPER} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)
 TARGET_INCLUDE_DIRECTORIES(${TARGET_MANIFEST_TEST} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)
 TARGET_INCLUDE_DIRECTORIES(${TARGET_WGT_SMOKE_UTILS} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)
 
@@ -49,12 +53,14 @@ APPLY_PKG_CONFIG(${TARGET_MANIFEST_TEST} PUBLIC
 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_WGT_SMOKE_UTILS})
+TARGET_LINK_LIBRARIES(${TARGET_HYBRID_SMOKE_TEST_HELPER} PRIVATE ${TARGET_LIBNAME_WGT} ${TARGET_WGT_SMOKE_UTILS} ${TARGET_LIBNAME_HYBRID})
 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})
 
 INSTALL(TARGETS ${TARGET_SMOKE_TEST} DESTINATION ${BINDIR}/${DESTINATION_DIR})
 INSTALL(TARGETS ${TARGET_SMOKE_TEST_EXTENSIVE} DESTINATION ${BINDIR}/${DESTINATION_DIR})
 INSTALL(TARGETS ${TARGET_SMOKE_TEST_HELPER} DESTINATION ${BINDIR}/${DESTINATION_DIR})
+INSTALL(TARGETS ${TARGET_HYBRID_SMOKE_TEST_HELPER} DESTINATION ${BINDIR}/${DESTINATION_DIR})
 INSTALL(TARGETS ${TARGET_MANIFEST_TEST} DESTINATION ${BINDIR}/${DESTINATION_DIR})
 INSTALL(TARGETS ${TARGET_WGT_SMOKE_UTILS} DESTINATION ${LIB_INSTALL_DIR})
 INSTALL(FILES wgt_smoke_utils.h DESTINATION ${INCLUDEDIR}/app-installers/smoke_tests/)
diff --git a/test/smoke_tests/hybrid_smoke_test_helper.cc b/test/smoke_tests/hybrid_smoke_test_helper.cc
new file mode 100644 (file)
index 0000000..1398457
--- /dev/null
@@ -0,0 +1,88 @@
+// Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include <common/pkgmgr_interface.h>
+#include <manifest_parser/utils/logging.h>
+
+#include "smoke_tests/wgt_smoke_utils.h"
+#include "wgt/utils/wgt_app_query_interface.h"
+
+namespace ci = common_installer;
+
+static int RunCrashHybridInstaller(ci::PkgMgrPtr pkgmgr,
+                                int index,
+                                std::string step_name,
+                                smoke_test::CrashStepType type) {
+  smoke_test::CrashHybridInstaller t(pkgmgr, index, step_name, type);
+
+  if (t.Run() != ci::AppInstaller::Result::OK) {
+    LOG(ERROR) << "CrashHybridInstaller run failure";
+    return 1;
+  }
+  return 0;
+}
+
+static int RunHybridInstallerWithoutParserPlugins(ci::PkgMgrPtr pkgmgr) {
+  smoke_test::HybridInstallerWithoutPasrserPlugins t(pkgmgr);
+
+  if (t.Run() != ci::AppInstaller::Result::OK) {
+    LOG(ERROR) << "HybridInstallerWithoutPasrserPlugins run failure";
+    return 1;
+  }
+  return 0;
+}
+
+// this main of test binay in done purely for recovery smoke test.
+int main(int argc, char** argv) {
+  try {
+    int index = -1;
+    int backend_argc = argc;
+    std::string step_name;
+    bool remove_plugins = false;
+    smoke_test::CrashStepType type = smoke_test::CrashStepType::PROCESS;
+
+    if (!strcmp(argv[backend_argc - 1], "-type_clean")) {
+      backend_argc--;
+      type = smoke_test::CrashStepType::CLEAN;
+      LOG(DEBUG) << "step will be crashed in clean operation";
+    }
+
+    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[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], "-remove_plugin_steps")) {
+      backend_argc--;
+      remove_plugins = true;
+      LOG(DEBUG) << "Remove parser plugins steps";
+    }
+
+    ci::PkgmgrInstaller pkgmgr_installer;
+  std::shared_ptr<wgt::WgtAppQueryInterface> query_interface(
+        new wgt::WgtAppQueryInterface());
+    auto pkgmgr = ci::PkgMgrInterface::Create(backend_argc, argv,
+        &pkgmgr_installer, query_interface);
+    if (!pkgmgr) {
+      LOG(ERROR) << "Options of pkgmgr installer cannot be parsed";
+      return EINVAL;
+    }
+
+    if (remove_plugins)
+      return RunHybridInstallerWithoutParserPlugins(pkgmgr);
+    else
+      return RunCrashHybridInstaller(pkgmgr, index, step_name, type);
+  } catch (...) {
+    std::cout << "Exception occurred during testing" << std::endl;
+    return 1;
+  }
+}
+
index 3b11756..a45bcc5 100644 (file)
@@ -88,4 +88,9 @@ HybridBackendInterface::CreateFailExpectedInstaller(
   return AppInstallerPtr(new FailExpectedHybridInstaller(pkgmgr, fail_at));
 }
 
+common_installer::Subprocess HybridBackendInterface::CreateSubprocess() const {
+  return common_installer::Subprocess(
+      "/usr/bin/wgt-installer-ut/hybrid-smoke-test-helper");
+}
+
 }  // namespace smoke_test
index 4467971..e0a0453 100644 (file)
@@ -56,6 +56,7 @@ class HybridBackendInterface: public BackendInterface {
       common_installer::PkgMgrPtr pkgmgr) const override;
   AppInstallerPtr CreateFailExpectedInstaller(
       common_installer::PkgMgrPtr pkgmgr, int fail_at) const override;
+  common_installer::Subprocess CreateSubprocess() const override;
 };
 
 #ifdef OVERRIDE_STEPS_BLOCK
@@ -135,9 +136,9 @@ class FailExpectedHybridInstaller : public hybrid::HybridInstaller {
 #ifdef OVERRIDE_STEPS_BLOCK
 #undef OVERRIDE_STEPS_BLOCK
 #endif
-#define OVERRIDE_STEPS_BLOCK(STEPS)                                            \
+#define OVERRIDE_STEPS_BLOCK(TYPE, STEPS)                                      \
   void STEPS() override {                                                      \
-    wgt::WgtInstaller::STEPS();                                                \
+    TYPE::STEPS();                                                             \
     if (crash_at_ > -1)                                                        \
       AddStepAtIndex<StepCrash>(crash_at_, type_);                             \
     else if (step_name_.size())                                                \
@@ -154,26 +155,60 @@ class CrashWgtInstaller : public wgt::WgtInstaller {
           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)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, InstallSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, UpdateSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, UninstallSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, ReinstallSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, DeltaSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, MoveSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, RecoverySteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, MountInstallSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, MountUpdateSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, ManifestDirectInstallSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, ManifestDirectUpdateSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, ManifestPartialInstallSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, ManifestPartialUpdateSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, PartialUninstallSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, ReadonlyUpdateInstallSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, ReadonlyUpdateUninstallSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, DisablePkgSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, EnablePkgSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, MigrateExtImgSteps)
+  OVERRIDE_STEPS_BLOCK(wgt::WgtInstaller, RecoverDBSteps)
+
+  int crash_at_;
+  std::string step_name_;
+  CrashStepType type_;
+};
+
+class CrashHybridInstaller : public hybrid::HybridInstaller {
+ public:
+  explicit CrashHybridInstaller(common_installer::PkgMgrPtr pkgmgr,
+      int crash_at, std::string step_name, CrashStepType type) :
+          hybrid::HybridInstaller(pkgmgr), crash_at_(crash_at),
+          step_name_(step_name), type_(type) { }
+
+ private:
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, InstallSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, UpdateSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, UninstallSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, ReinstallSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, DeltaSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, MoveSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, RecoverySteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, MountInstallSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, MountUpdateSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, ManifestDirectInstallSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, ManifestDirectUpdateSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, ManifestPartialInstallSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, ManifestPartialUpdateSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, PartialUninstallSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, ReadonlyUpdateInstallSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, ReadonlyUpdateUninstallSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, DisablePkgSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, EnablePkgSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, MigrateExtImgSteps)
+  OVERRIDE_STEPS_BLOCK(hybrid::HybridInstaller, RecoverDBSteps)
 
   int crash_at_;
   std::string step_name_;