Add try-catch statement 21/241921/1
authorIlho Kim <ilho159.kim@samsung.com>
Fri, 21 Aug 2020 01:29:07 +0000 (10:29 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Fri, 21 Aug 2020 01:29:07 +0000 (10:29 +0900)
Change-Id: I3708d06c0ddd27f421c0adfe8350f514c09468a5
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/unit_tests/smoke_test_helper.cc

index e2706b496266e4ac3c6a23fa6d4783c0c350e9d6..d07590628852ea071d9ae536d2ed0321acdd2ac7 100644 (file)
@@ -37,48 +37,53 @@ static int RunTpkInstallerWithoutParserPlugins(ci::PkgMgrPtr pkgmgr) {
 // This version of backend will crash in the end
 // it is used for recovery testcase
 int main(const int argc, char* argv[]) {
-  int index = -1;
-  int backend_argc = argc;
-  std::string step_name;
-  bool remove_plugins = false;
-  smoke_test::CrashStepType type = smoke_test::CrashStepType::PROCESS;
+  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-2], "-idx")) {
-     index = atoi(argv[backend_argc-1]);
-     backend_argc -= 2;
-     LOG(DEBUG) << "Step crash after " << index << " step.";
-  }
+    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-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";
-  }
+    if (!strcmp(argv[backend_argc-1], "-remove_plugin_steps")) {
+      backend_argc--;
+      remove_plugins = true;
+      LOG(DEBUG) << "Remove parser plugins steps";
+    }
 
-  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-1], "-type_clean")) {
+      backend_argc--;
+      type = smoke_test::CrashStepType::CLEAN;
+      LOG(DEBUG) << "step will be crashed in clean operation";
+    }
 
-  ci::PkgmgrInstaller pkgmgr_installer;
-  tpk::TpkAppQueryInterface interface;
-  ci::PkgMgrPtr pkgmgr = ci::PkgMgrInterface::Create(backend_argc, argv,
-                                                     &pkgmgr_installer,
-                                                     &interface);
-  if (!pkgmgr) {
-    LOG(ERROR) << "Failed to create pkgmgr interface";
-    return -1;
-  }
+    ci::PkgmgrInstaller pkgmgr_installer;
+    tpk::TpkAppQueryInterface interface;
+    ci::PkgMgrPtr pkgmgr = ci::PkgMgrInterface::Create(backend_argc, argv,
+                                                       &pkgmgr_installer,
+                                                       &interface);
+    if (!pkgmgr) {
+      LOG(ERROR) << "Failed to create pkgmgr interface";
+      return -1;
+    }
 
-  if (remove_plugins)
-    return RunTpkInstallerWithoutParserPlugins(pkgmgr);
-  else
-    return RunCrashTpkInstaller(pkgmgr, index, step_name, type);
+    if (remove_plugins)
+      return RunTpkInstallerWithoutParserPlugins(pkgmgr);
+    else
+      return RunCrashTpkInstaller(pkgmgr, index, step_name, type);
+  } catch (...) {
+    std::cout << "Exception occurred during testing" << std::endl;
+    return 1;
+  }
 }