Add RunFunc to Subprocess for just executing function
[platform/core/appfw/app-installers.git] / test / smoke_tests / common / smoke_utils.cc
index b0004d1..8bf9210 100644 (file)
@@ -595,28 +595,43 @@ bool CheckSharedDataNonExistance(const std::string& pkgid,
 
 void BackendInterface::TestRollbackAfterEachStep(int argc, const char* argv[],
     std::function<bool()> validator) const {
-  TestPkgmgrInstaller pkgmgr_installer;
-  std::shared_ptr<ci::AppQueryInterface> query_interface =
-      CreateQueryInterface();
-  auto pkgmgr =
-      ci::PkgMgrInterface::Create(argc, const_cast<char**>(argv),
-                                  &pkgmgr_installer,
-                                  query_interface);
-  if (!pkgmgr) {
-    LOG(ERROR) << "Failed to initialize pkgmgr interface";
-    return;
-  }
-  AppInstallerPtr backend;
-  unsigned int insert_idx = 0;
-  do {
-    backend = CreateFailExpectedInstaller(pkgmgr, insert_idx);
-    LOG(DEBUG) << "StepFail is inserted at: " << insert_idx;
-    ASSERT_EQ(ci::AppInstaller::Result::ERROR, backend->Run());
-    if (!validator())
-      break;
-    insert_idx++;
-  } while (insert_idx < backend->StepCount());
-  ASSERT_EQ(insert_idx, backend->StepCount());
+  ci::Subprocess backend_helper = CreateSubprocess();
+  ASSERT_EQ(backend_helper.RunFunc({[&]() -> int {
+    TestPkgmgrInstaller pkgmgr_installer;
+    std::shared_ptr<ci::AppQueryInterface> query_interface =
+        CreateQueryInterface();
+    auto pkgmgr =
+        ci::PkgMgrInterface::Create(argc, const_cast<char**>(argv),
+                                    &pkgmgr_installer,
+                                    query_interface);
+    if (!pkgmgr) {
+      LOG(ERROR) << "Failed to initialize pkgmgr interface";
+      return 1;
+    }
+    AppInstallerPtr backend;
+    unsigned int insert_idx = 0;
+    do {
+      backend = CreateFailExpectedInstaller(pkgmgr, insert_idx);
+      LOG(DEBUG) << "StepFail is inserted at: " << insert_idx;
+      ci::AppInstaller::Result ret = backend->Run();
+      if (ret != ci::AppInstaller::Result::ERROR) {
+        LOG(ERROR) << "StepFail not executed";
+        return 1;
+      }
+      if (!validator())
+        break;
+      insert_idx++;
+    } while (insert_idx < backend->StepCount());
+    if (insert_idx != backend->StepCount()) {
+      LOG(ERROR) << "Fail to validate";
+      return 1;
+    }
+
+    return 0;
+  }}), true);
+  int status = backend_helper.Wait();
+  ASSERT_NE(WIFEXITED(status), 0);
+  ASSERT_EQ(WEXITSTATUS(status), 0);
 }
 
 void BackendInterface::CrashAfterEachStep(std::vector<std::string>* args,