Add try-catch statement 19/241919/1
authorJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 21 Aug 2020 01:23:35 +0000 (10:23 +0900)
committerJunghyun Yeon <jungh.yeon@samsung.com>
Fri, 21 Aug 2020 01:23:35 +0000 (10:23 +0900)
Change-Id: I13bf668f13fabc277a94012a7217b48c46b158f7
Signed-off-by: Junghyun Yeon <jungh.yeon@samsung.com>
src/unit_tests/smoke_test_helper.cc

index 0c0e6f4..44ab422 100644 (file)
@@ -13,39 +13,44 @@ namespace ci = common_installer;
 
 // 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;
-  smoke_test::CrashStepType type = smoke_test::CrashStepType::PROCESS;
-
-  if (!strcmp(argv[backend_argc - 2], "-idx")) {
-    index = atoi(argv[argc - 1]);
-    backend_argc -= 2;
-    LOG(DEBUG) << "Step crash after " << index << " step.";
+  try {
+    int index = -1;
+    int backend_argc = argc;
+    std::string step_name;
+    smoke_test::CrashStepType type = smoke_test::CrashStepType::PROCESS;
+
+    if (!strcmp(argv[backend_argc - 2], "-idx")) {
+      index = atoi(argv[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], "-type_clean")) {
+      backend_argc--;
+      type = smoke_test::CrashStepType::CLEAN;
+      LOG(DEBUG) << "step will be crashed in clean operation";
+    }
+
+    ci::PkgmgrInstaller pkgmgr_installer;
+    wgt::WgtAppQueryInterface query_interface;
+    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;
+    }
+
+    smoke_test::CrashWgtInstaller installer(pkgmgr, index, step_name, type);
+    return (installer.Run() == ci::AppInstaller::Result::OK) ? 0 : 1;
+  } catch (...) {
+    std::cout << "Exception occurred during testing" << std::endl;
+    return 1;
   }
-
-  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], "-type_clean")) {
-    backend_argc--;
-    type = smoke_test::CrashStepType::CLEAN;
-    LOG(DEBUG) << "step will be crashed in clean operation";
-  }
-
-  ci::PkgmgrInstaller pkgmgr_installer;
-  wgt::WgtAppQueryInterface query_interface;
-  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;
-  }
-
-  smoke_test::CrashWgtInstaller installer(pkgmgr, index, step_name, type);
-  return (installer.Run() == ci::AppInstaller::Result::OK) ? 0 : 1;
 }