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;
}});
void BackendInterface::CrashAfterEachStep(std::vector<std::string>* args,
std::function<bool(int iter)> validator, PackageType type) const {
- std::unique_ptr<const char*[]> 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<char**>(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<const char*[]> 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<char**>(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(