Add hybrid smoke test helper
[platform/core/appfw/wgt-backend.git] / test / smoke_tests / hybrid_smoke_test_helper.cc
1 // Copyright (c) 2023 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
4
5 #include <common/pkgmgr_interface.h>
6 #include <manifest_parser/utils/logging.h>
7
8 #include "smoke_tests/wgt_smoke_utils.h"
9 #include "wgt/utils/wgt_app_query_interface.h"
10
11 namespace ci = common_installer;
12
13 static int RunCrashHybridInstaller(ci::PkgMgrPtr pkgmgr,
14                                 int index,
15                                 std::string step_name,
16                                 smoke_test::CrashStepType type) {
17   smoke_test::CrashHybridInstaller t(pkgmgr, index, step_name, type);
18
19   if (t.Run() != ci::AppInstaller::Result::OK) {
20     LOG(ERROR) << "CrashHybridInstaller run failure";
21     return 1;
22   }
23   return 0;
24 }
25
26 static int RunHybridInstallerWithoutParserPlugins(ci::PkgMgrPtr pkgmgr) {
27   smoke_test::HybridInstallerWithoutPasrserPlugins t(pkgmgr);
28
29   if (t.Run() != ci::AppInstaller::Result::OK) {
30     LOG(ERROR) << "HybridInstallerWithoutPasrserPlugins run failure";
31     return 1;
32   }
33   return 0;
34 }
35
36 // this main of test binay in done purely for recovery smoke test.
37 int main(int argc, char** argv) {
38   try {
39     int index = -1;
40     int backend_argc = argc;
41     std::string step_name;
42     bool remove_plugins = false;
43     smoke_test::CrashStepType type = smoke_test::CrashStepType::PROCESS;
44
45     if (!strcmp(argv[backend_argc - 1], "-type_clean")) {
46       backend_argc--;
47       type = smoke_test::CrashStepType::CLEAN;
48       LOG(DEBUG) << "step will be crashed in clean operation";
49     }
50
51     if (!strcmp(argv[backend_argc - 2], "-idx")) {
52       index = atoi(argv[backend_argc - 1]);
53       backend_argc -= 2;
54       LOG(DEBUG) << "Step crash after " << index << " step.";
55     }
56
57     if (!strcmp(argv[backend_argc - 2], "-step_name")) {
58       step_name = argv[backend_argc  - 1];
59       backend_argc -= 2;
60       LOG(DEBUG) << "Step crash after " << step_name << " step.";
61     }
62
63     if (!strcmp(argv[backend_argc-1], "-remove_plugin_steps")) {
64       backend_argc--;
65       remove_plugins = true;
66       LOG(DEBUG) << "Remove parser plugins steps";
67     }
68
69     ci::PkgmgrInstaller pkgmgr_installer;
70   std::shared_ptr<wgt::WgtAppQueryInterface> query_interface(
71         new wgt::WgtAppQueryInterface());
72     auto pkgmgr = ci::PkgMgrInterface::Create(backend_argc, argv,
73         &pkgmgr_installer, query_interface);
74     if (!pkgmgr) {
75       LOG(ERROR) << "Options of pkgmgr installer cannot be parsed";
76       return EINVAL;
77     }
78
79     if (remove_plugins)
80       return RunHybridInstallerWithoutParserPlugins(pkgmgr);
81     else
82       return RunCrashHybridInstaller(pkgmgr, index, step_name, type);
83   } catch (...) {
84     std::cout << "Exception occurred during testing" << std::endl;
85     return 1;
86   }
87 }
88