From: ilho kim Date: Thu, 5 Jan 2023 06:45:45 +0000 (+0900) Subject: Run CrashAfterEachStep with subprocess X-Git-Tag: accepted/tizen/7.0/unified/20230111.015138~1 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fappfw%2Fapp-installers.git;a=commitdiff_plain;h=60ed071e80ff4f171f00079ba32d846d4e40c7a1 Run CrashAfterEachStep with subprocess CrashAfterEachStep function use RunFunc to make the smoke test's main process lighter Change-Id: Ib11a5a016a2ec4c2d5df3ba3dfb66f28c4111b22 Signed-off-by: ilho kim --- diff --git a/test/smoke_tests/common/smoke_utils.cc b/test/smoke_tests/common/smoke_utils.cc index 3b265df..ba7fe5d 100644 --- a/test/smoke_tests/common/smoke_utils.cc +++ b/test/smoke_tests/common/smoke_utils.cc @@ -618,14 +618,14 @@ void BackendInterface::TestRollbackAfterEachStep(int argc, const char* argv[], LOG(ERROR) << "StepFail not executed"; return 1; } - if (!validator()) + if (!validator()) { + LOG(ERROR) << "Fail to validate. index of StepFail : " << insert_idx; break; + } insert_idx++; } while (insert_idx < backend->StepCount()); - if (insert_idx != backend->StepCount()) { - LOG(ERROR) << "Fail to validate"; + if (insert_idx != backend->StepCount()) return 1; - } return 0; }}); @@ -637,52 +637,75 @@ void BackendInterface::TestRollbackAfterEachStep(int argc, const char* argv[], void BackendInterface::CrashAfterEachStep(std::vector* args, std::function validator, PackageType type) const { - std::unique_ptr argv(new const char*[args->size()]); - for (size_t i = 0; i < args->size(); ++i) { - argv[i] = args->at(i).c_str(); - } - TestPkgmgrInstaller pkgmgr_installer; - auto query_interface = CreateQueryInterface(); - auto pkgmgr = - ci::PkgMgrInterface::Create(args->size(), const_cast(argv.get()), - &pkgmgr_installer, - query_interface); - if (!pkgmgr) { - LOG(ERROR) << "Failed to initialize pkgmgr interface"; - return; - } - auto backend = CreateFailExpectedInstaller(pkgmgr, 0); - ASSERT_EQ(backend->Run(), ci::AppInstaller::Result::ERROR); - int stepCount = backend->StepCount(); - - args->push_back("-idx"); - args->push_back(std::to_string(stepCount)); - int i; - std::string prefix = (type == PackageType::TPK) ? "tpk" : "wgt"; - for (i = 0; i < stepCount; i++) { - ci::Subprocess backend_crash( - "/usr/bin/" + prefix + "-installer-ut/smoke-test-helper"); - args->back() = std::to_string(i); - backend_crash.Run(*args); - ASSERT_NE(backend_crash.Wait(), 0); - if (!validator(i)) - break; - } - ASSERT_EQ(stepCount, i); - - args->push_back("-type_clean"); - for (i = stepCount - 1; i >= 2; i--) { - ci::Subprocess backend_crash( - "/usr/bin/" + prefix + "-installer-ut/smoke-test-helper"); - auto it = args->end(); - it -= 2; - *it = std::to_string(i); - backend_crash.Run(*args); - ASSERT_NE(backend_crash.Wait(), 0); - if (!validator(i)) - break; - } - ASSERT_EQ(i , 1); + ci::Subprocess backend_helper = CreateSubprocess(); + bool result = backend_helper.RunFunc({[&]() { + std::unique_ptr argv(new const char*[args->size()]); + for (size_t i = 0; i < args->size(); ++i) { + argv[i] = args->at(i).c_str(); + } + TestPkgmgrInstaller pkgmgr_installer; + auto query_interface = CreateQueryInterface(); + auto pkgmgr = ci::PkgMgrInterface::Create(args->size(), + const_cast(argv.get()), &pkgmgr_installer, query_interface); + if (!pkgmgr) { + LOG(ERROR) << "Failed to initialize pkgmgr interface"; + return 1; + } + auto backend = CreateFailExpectedInstaller(pkgmgr, 0); + if (backend->Run() != ci::AppInstaller::Result::ERROR) { + LOG(ERROR) << "StepFail not executed"; + return 1; + } + int stepCount = backend->StepCount(); + + args->push_back("-idx"); + args->push_back(std::to_string(stepCount)); + int insert_idx; + std::string prefix = (type == PackageType::TPK) ? "tpk" : "wgt"; + for (insert_idx = 0; insert_idx < stepCount; insert_idx++) { + ci::Subprocess backend_crash( + "/usr/bin/" + prefix + "-installer-ut/smoke-test-helper"); + args->back() = std::to_string(insert_idx); + backend_crash.Run(*args); + if (backend_crash.Wait() == 0) { + LOG(ERROR) << "Subprocess exit without crash"; + return 1; + } + if (!validator(insert_idx)) { + LOG(ERROR) << "Fail to validate. index of StepCrash : " << insert_idx; + break; + } + } + if (stepCount != insert_idx) + return 1; + + args->push_back("-type_clean"); + for (insert_idx = stepCount - 1; insert_idx >= 2; insert_idx--) { + ci::Subprocess backend_crash( + "/usr/bin/" + prefix + "-installer-ut/smoke-test-helper"); + auto it = args->end(); + it -= 2; + *it = std::to_string(insert_idx); + backend_crash.Run(*args); + if (backend_crash.Wait() == 0) { + LOG(ERROR) << "Subprocess exit without crash"; + return 1; + } + if (!validator(insert_idx)) { + LOG(ERROR) << "Fail to validate. index of StepCrash : " << insert_idx; + break; + } + } + if (insert_idx != 1) + return 1; + + return 0; + }}); + + ASSERT_EQ(result, true); + int status = backend_helper.Wait(); + ASSERT_NE(WIFEXITED(status), 0); + ASSERT_EQ(WEXITSTATUS(status), 0); } BackendInterface::CommandResult BackendInterface::RunInstallersWithPkgmgr(