Release version 0.15.33
[platform/core/appfw/wgt-backend.git] / test / smoke_tests / smoke_test_helper.cc
1 // Copyright (c) 2015 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 #include "wgt/wgt_installer.h"
11
12 namespace ci = common_installer;
13
14 static int RunCrashWgtInstaller(ci::PkgMgrPtr pkgmgr,
15                                 int index,
16                                 std::string step_name,
17                                 smoke_test::CrashStepType type) {
18   smoke_test::CrashWgtInstaller t(pkgmgr, index, step_name, type);
19
20   if (t.Run() != ci::AppInstaller::Result::OK) {
21     LOG(ERROR) << "CrashWgtInstaller run failure";
22     return 1;
23   }
24   return 0;
25 }
26
27 static int RunWgtInstallerWithoutParserPlugins(ci::PkgMgrPtr pkgmgr) {
28   smoke_test::WgtInstallerWithoutPasrserPlugins t(pkgmgr);
29
30   if (t.Run() != ci::AppInstaller::Result::OK) {
31     LOG(ERROR) << "WgtInstallerWithoutPasrserPlugins run failure";
32     return 1;
33   }
34   return 0;
35 }
36
37 // this main of test binay in done purely for recovery smoke test.
38 int main(int argc, char** argv) {
39   try {
40     int index = -1;
41     int backend_argc = argc;
42     std::string step_name;
43     bool remove_plugins = false;
44     smoke_test::CrashStepType type = smoke_test::CrashStepType::PROCESS;
45
46     if (!strcmp(argv[backend_argc - 1], "-type_clean")) {
47       backend_argc--;
48       type = smoke_test::CrashStepType::CLEAN;
49       LOG(DEBUG) << "step will be crashed in clean operation";
50     }
51
52     if (!strcmp(argv[backend_argc - 2], "-idx")) {
53       index = atoi(argv[backend_argc - 1]);
54       backend_argc -= 2;
55       LOG(DEBUG) << "Step crash after " << index << " step.";
56     }
57
58     if (!strcmp(argv[backend_argc - 2], "-step_name")) {
59       step_name = argv[backend_argc  - 1];
60       backend_argc -= 2;
61       LOG(DEBUG) << "Step crash after " << step_name << " step.";
62     }
63
64     if (!strcmp(argv[backend_argc-1], "-remove_plugin_steps")) {
65       backend_argc--;
66       remove_plugins = true;
67       LOG(DEBUG) << "Remove parser plugins steps";
68     }
69
70     ci::PkgmgrInstaller pkgmgr_installer;
71     std::shared_ptr<wgt::WgtAppQueryInterface> query_interface(
72         new wgt::WgtAppQueryInterface());
73     auto pkgmgr = ci::PkgMgrInterface::Create(backend_argc, argv,
74         &pkgmgr_installer, query_interface);
75     if (!pkgmgr) {
76       LOG(ERROR) << "Options of pkgmgr installer cannot be parsed";
77       return EINVAL;
78     }
79
80     if (remove_plugins)
81       return RunWgtInstallerWithoutParserPlugins(pkgmgr);
82     else
83       return RunCrashWgtInstaller(pkgmgr, index, step_name, type);
84   } catch (...) {
85     std::cout << "Exception occurred during testing" << std::endl;
86     return 1;
87   }
88 }
89