Add new smoke tests
[platform/core/appfw/wgt-backend.git] / src / unit_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 <cerrno>
7
8 #include "wgt/wgt_app_query_interface.h"
9 #include "wgt/wgt_installer.h"
10
11 namespace ci = common_installer;
12
13 namespace {
14
15 class StepCrash : public ci::Step {
16  public:
17   using Step::Step;
18
19   ci::Step::Status process() override {
20     raise(SIGSEGV);
21     return Status::OK;
22   }
23   ci::Step::Status clean() override { return ci::Step::Status::OK; }
24   ci::Step::Status undo() override { return ci::Step::Status::OK; }
25   ci::Step::Status precheck() override { return ci::Step::Status::OK; }
26
27   STEP_NAME(Crash)
28 };
29
30 }  // namespace
31
32 // this main of test binay in done purely for recovery smoke test.
33 int main(int argc, char** argv) {
34   int index = -1;
35   int backend_argc = argc;
36   if (!strcmp(argv[argc-2], "-idx")) {
37     index = atoi(argv[argc-1]);
38     backend_argc = argc - 2;
39     LOG(DEBUG) << "Step crash after " << index << " step.";
40   }
41
42   ci::PkgmgrInstaller pkgmgr_installer;
43   wgt::WgtAppQueryInterface query_interface;
44   auto pkgmgr = ci::PkgMgrInterface::Create(backend_argc, argv, &pkgmgr_installer,
45                                             &query_interface);
46   if (!pkgmgr) {
47     LOG(ERROR) << "Options of pkgmgr installer cannot be parsed";
48     return EINVAL;
49   }
50
51   wgt::WgtInstaller installer(pkgmgr);
52   if (index != -1) {
53     installer.AddStepAtIndex<StepCrash>(index);
54   } else {
55     installer.AddStep<StepCrash>();
56   }
57   return (installer.Run() == ci::AppInstaller::Result::OK) ? 0 : 1;
58 }
59