(request_mode_ == ci::RequestMode::USER &&
kGlobalUserUid != test_user.uid));
- TpkBackendInterface backend(std::to_string(test_user.uid));
- UninstallAllSmokeApps(request_mode_, test_user.uid, &backend);
+ ci::PkgQueryInterface pkg_query("recoverypkg", test_user.uid, true);
+ if (pkg_query.IsPackageInstalled()) {
+ TpkSmokeTestHelperRunner backend;
+ SmokeTestHelperRunner::Result ret =
+ backend.UninstallWithSubprocess("recoverypkg", test_user.uid);
+ ASSERT_EQ(ret, SmokeTestHelperRunner::Result::SUCCESS);
+ }
if (request_mode_ == ci::RequestMode::USER)
ASSERT_TRUE(DeleteTestUser());
class SmokeTest : public testing::Test {
public:
- SmokeTest() : backend(std::to_string(env->test_user.uid)),
- params{PackageType::TPK, false} {
+ SmokeTest() : params{PackageType::TPK, false} {
params.test_user.uid = env->test_user.uid;
params.test_user.gid = env->test_user.gid;
}
protected:
- TpkBackendInterface backend;
+ TpkSmokeTestHelperRunner backend;
TestParameters params;
};
RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
bf::path path = kSmokePackagesDirectory / "RecoveryPkg.tpk";
- ci::Subprocess tpk_backend("/usr/bin/tpk-backend");
- std::string test_uid_str = std::to_string(params.test_user.uid);
-
- tpk_backend.Run("-i", path.string(), "-u", test_uid_str.c_str());
- usleep(delay + interval * test_count);
- tpk_backend.Kill();
-
- if (tpk_backend.Wait() == 9) {
- std::string pkgid = "recoverypkg";
- bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
- params.test_user.uid);
- if (recovery_file.empty()) {
- std::cout << "recovery file dosen't exist, "
- "this test is skipped" << std::endl;
- return;
- }
+ int wait_time = delay + interval * test_count;
- ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
- ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
- } else {
+ SmokeTestHelperRunner::Result ret = backend.InstallWithSubprocessAndKill(
+ path, params.test_user.uid, wait_time);
+ if (ret == SmokeTestHelperRunner::Result::SUCCESS) {
std::cout << "install finished before process killed" << std::endl;
+ return;
+ }
+ ASSERT_EQ(ret, SmokeTestHelperRunner::Result::KILLED);
+ std::string pkgid = "recoverypkg";
+ bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
+ params.test_user.uid);
+ if (recovery_file.empty()) {
+ std::cout << "recovery file dosen't exist, "
+ "this test is skipped" << std::endl;
+ return;
}
+ ASSERT_EQ(backend.RecoveryWithSubprocess(recovery_file, params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+ ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
}
TEST_F(SmokeTest, RecoveryMode_Tpk_Update) {
bf::path path_old = kSmokePackagesDirectory / "RecoveryPkg.tpk";
bf::path path_new = kSmokePackagesDirectory / "RecoveryPkg2.tpk";
- ASSERT_EQ(backend.Install(path_old), ci::AppInstaller::Result::OK);
- ci::Subprocess tpk_backend("/usr/bin/tpk-backend");
- std::string test_uid_str = std::to_string(params.test_user.uid);
-
- tpk_backend.Run("-i", path_new.string(), "-u", test_uid_str.c_str());
- usleep(delay + interval * test_count);
- tpk_backend.Kill();
-
- if (tpk_backend.Wait() == 9) {
- std::string pkgid = "recoverypkg";
- std::string appid = "recoverypkg";
- std::string exec = "recoverypkg";
- bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
- params.test_user.uid);
- if (recovery_file.empty()) {
- std::cout << "recovery file dosen't exist, "
- "this test is skipped" << std::endl;
- return;
- }
+ int wait_time = delay + interval * test_count;
+
+ ASSERT_EQ(backend.InstallWithSubprocess(path_old, params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
- std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
- GetRecoverFileInfo(recovery_file);
- ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
- ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
- ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/VERSION",
- recovery_info->cleanup() ? "2\n" : "1\n", params));
- } else {
+ SmokeTestHelperRunner::Result ret = backend.InstallWithSubprocessAndKill(
+ path_new, params.test_user.uid, wait_time);
+ if (ret == SmokeTestHelperRunner::Result::SUCCESS) {
std::cout << "update finished before process killed" << std::endl;
+ return;
}
+ ASSERT_EQ(ret, SmokeTestHelperRunner::Result::KILLED);
+
+ std::string pkgid = "recoverypkg";
+ std::string appid = "recoverypkg";
+ std::string exec = "recoverypkg";
+ bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
+ params.test_user.uid);
+ if (recovery_file.empty()) {
+ std::cout << "recovery file dosen't exist, "
+ "this test is skipped" << std::endl;
+ return;
+ }
+
+ std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
+ GetRecoverFileInfo(recovery_file);
+ ASSERT_EQ(backend.RecoveryWithSubprocess(recovery_file, params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+ ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
+ ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/VERSION",
+ recovery_info->cleanup() ? "2\n" : "1\n", params));
}
TEST_F(SmokeTest, RecoveryMode_ForDelta) {
bf::path path_old = kSmokePackagesDirectory / "RecoveryPkg.tpk";
bf::path path_new = kSmokePackagesDirectory / "RecoveryPkg.delta";
- ASSERT_EQ(backend.Install(path_old), ci::AppInstaller::Result::OK);
- ci::Subprocess tpk_backend("/usr/bin/tpk-backend");
- std::string test_uid_str = std::to_string(params.test_user.uid);
-
- tpk_backend.Run("-i", path_new.string(), "-u", test_uid_str.c_str());
- usleep(delay + interval * test_count);
- tpk_backend.Kill();
-
- if (tpk_backend.Wait() == 9) {
- std::string pkgid = "recoverypkg";
- std::string appid = "recoverypkg";
- std::string exec = "recoverypkg";
- bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
- params.test_user.uid);
- bf::path root_path = ci::GetRootAppPath(params.is_readonly,
- params.test_user.uid);
- if (recovery_file.empty()) {
- std::cout << "recovery file dosen't exist, "
- "this test is skipped" << std::endl;
- return;
- }
+ int wait_time = delay + interval * test_count;
+
+ ASSERT_EQ(backend.InstallWithSubprocess(path_old, params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
- std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
- GetRecoverFileInfo(recovery_file);
- ASSERT_EQ(ci::AppInstaller::Result::OK, backend.Recover(recovery_file));
- ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
- ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/VERSION",
- recovery_info->cleanup() ? "2\n" : "1\n", params));
- bool deleted_exist = bf::exists(root_path / pkgid / "res/DELETED");
- bool added_exist = bf::exists(root_path / pkgid / "res/ADDED");
- ASSERT_NE(deleted_exist, added_exist);
- ASSERT_TRUE(recovery_info->cleanup() ? added_exist : deleted_exist);
- } else {
+ SmokeTestHelperRunner::Result ret = backend.InstallWithSubprocessAndKill(
+ path_new, params.test_user.uid, wait_time);
+ if (ret == SmokeTestHelperRunner::Result::SUCCESS) {
std::cout << "delta finished before process killed" << std::endl;
+ return;
+ }
+ ASSERT_EQ(ret, SmokeTestHelperRunner::Result::KILLED);
+
+ std::string pkgid = "recoverypkg";
+ std::string appid = "recoverypkg";
+ std::string exec = "recoverypkg";
+ bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
+ params.test_user.uid);
+ bf::path root_path = ci::GetRootAppPath(params.is_readonly,
+ params.test_user.uid);
+ if (recovery_file.empty()) {
+ std::cout << "recovery file dosen't exist, "
+ "this test is skipped" << std::endl;
+ return;
}
+
+ std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
+ GetRecoverFileInfo(recovery_file);
+ ASSERT_EQ(backend.RecoveryWithSubprocess(recovery_file, params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+ ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
+ ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/VERSION",
+ recovery_info->cleanup() ? "2\n" : "1\n", params));
+ bool deleted_exist = bf::exists(root_path / pkgid / "res/DELETED");
+ bool added_exist = bf::exists(root_path / pkgid / "res/ADDED");
+ ASSERT_NE(deleted_exist, added_exist);
+ ASSERT_TRUE(recovery_info->cleanup() ? added_exist : deleted_exist);
}
TEST_F(SmokeTest, RecoveryMode_ForMountInstall) {
RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
bf::path path = kSmokePackagesDirectory / "RecoveryPkg.tpk";
- ci::Subprocess tpk_backend("/usr/bin/tpk-backend");
- std::string test_uid_str = std::to_string(params.test_user.uid);
-
- tpk_backend.Run("-w", path.string(), "-u", test_uid_str.c_str());
- usleep(delay + interval * test_count);
- tpk_backend.Kill();
-
- if (tpk_backend.Wait() == 9) {
- std::string pkgid = "recoverypkg";
- bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
- params.test_user.uid);
- if (recovery_file.empty()) {
- std::cout << "recovery file dosen't exist, "
- "this test is skipped" << std::endl;
- return;
- }
+ int wait_time = delay + interval * test_count;
- ASSERT_EQ(ci::AppInstaller::Result::OK, backend.Recover(recovery_file));
- ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
- } else {
+ SmokeTestHelperRunner::Result ret = backend.MountInstallWithSubprocessAndKill(
+ path, params.test_user.uid, wait_time);
+ if (ret == SmokeTestHelperRunner::Result::SUCCESS) {
std::cout << "mount install finished before process killed" << std::endl;
+ return;
}
+
+ std::string pkgid = "recoverypkg";
+ bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
+ params.test_user.uid);
+ if (recovery_file.empty()) {
+ std::cout << "recovery file dosen't exist, "
+ "this test is skipped" << std::endl;
+ return;
+ }
+ ASSERT_EQ(backend.RecoveryWithSubprocess(recovery_file, params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+
+ ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
}
TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) {
kSmokePackagesDirectory / "RecoveryPkg.tpk";
bf::path path_new =
kSmokePackagesDirectory / "RecoveryPkg2.tpk";
- ASSERT_EQ(ci::AppInstaller::Result::OK, backend.MountInstall(path_old));
- ci::Subprocess tpk_backend("/usr/bin/tpk-backend");
- std::string test_uid_str = std::to_string(params.test_user.uid);
-
- tpk_backend.Run("-w", path_new.string(), "-u", test_uid_str.c_str());
- usleep(delay + interval * test_count);
- tpk_backend.Kill();
-
- if (tpk_backend.Wait() == 9) {
- std::string pkgid = "recoverypkg";
- std::string appid = "recoverypkg";
- std::string exec = "recoverypkg";
- bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
- params.test_user.uid);
- if (recovery_file.empty()) {
- std::cout << "recovery file dosen't exist, "
- "this test is skipped" << std::endl;
- return;
- }
+ int wait_time = delay + interval * test_count;
- // Filesystem may be mounted after crash
- ScopedTzipInterface poweroff_unmount_interface(pkgid, params.test_user.uid);
- poweroff_unmount_interface.Release();
+ ASSERT_EQ(backend.MountInstallWithSubprocess(path_old, params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
- ASSERT_EQ(ci::AppInstaller::Result::OK, backend.Recover(recovery_file));
- ScopedTzipInterface interface(pkgid, params.test_user.uid);
- ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
- ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
- "res/VERSION", "1\n", params));
- } else {
+ SmokeTestHelperRunner::Result ret = backend.MountInstallWithSubprocessAndKill(
+ path_new, params.test_user.uid, wait_time);
+ if (ret == SmokeTestHelperRunner::Result::SUCCESS) {
std::cout << "mount update finished before process killed" << std::endl;
+ return;
+ }
+
+ std::string pkgid = "recoverypkg";
+ std::string appid = "recoverypkg";
+ std::string exec = "recoverypkg";
+ bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
+ params.test_user.uid);
+ if (recovery_file.empty()) {
+ std::cout << "recovery file dosen't exist, "
+ "this test is skipped" << std::endl;
+ return;
}
+
+ // Filesystem may be mounted after crash
+ ScopedTzipInterface poweroff_unmount_interface(pkgid, params.test_user.uid);
+ poweroff_unmount_interface.Release();
+
+ ASSERT_EQ(backend.RecoveryWithSubprocess(recovery_file, params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+
+ ScopedTzipInterface interface(pkgid, params.test_user.uid);
+ ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
+ ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
+ "res/VERSION", "1\n", params));
}
} // namespace smoke_test
AddStep<StepCrash>(); \
} \
+#define OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(STEPS) \
+ void STEPS() override { \
+ tpk::TpkInstaller::STEPS(); \
+ RemoveStep("RunParserPlugin"); \
+ } \
+
class CrashTpkInstaller : public tpk::TpkInstaller {
public:
explicit CrashTpkInstaller(ci::PkgMgrPtr pkgmgr, int crash_at,
std::string step_name_;
};
+class TpkInstallerWithoutPasrserPlugins : public tpk::TpkInstaller {
+ public:
+ explicit TpkInstallerWithoutPasrserPlugins(ci::PkgMgrPtr pkgmgr) :
+ tpk::TpkInstaller(pkgmgr) { }
+
+ private:
+ OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(InstallSteps)
+ OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(UpdateSteps)
+ OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(UninstallSteps)
+ OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(ReinstallSteps)
+ OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(DeltaSteps)
+ OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(MoveSteps)
+ OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(MountInstallSteps)
+ OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(MountUpdateSteps)
+ OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(ManifestDirectInstallSteps)
+ OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(ManifestDirectUpdateSteps)
+ OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(ManifestPartialInstallSteps)
+ OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(ManifestPartialUpdateSteps)
+ OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(PartialUninstallSteps)
+ OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(ReadonlyUpdateInstallSteps)
+ OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(ReadonlyUpdateUninstallSteps)
+ OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(DisablePkgSteps)
+ OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(EnablePkgSteps)
+ OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(MigrateExtImgSteps)
+ OVERRIDE_STEPS_BLOCK_WITHOUT_PARSER_PLUGINS(RecoverDBSteps)
+ void RecoverySteps() override {
+ tpk::TpkInstaller::RecoverySteps();
+ RemoveStep("RecoverParserPlugin");
+ }
+};
+
} // namespace
+static int RunCrashTpkInstaller(ci::PkgMgrPtr pkgmgr,
+ int index,
+ std::string step_name) {
+ ::CrashTpkInstaller t(pkgmgr, index, step_name);
+
+ if (t.Run() != ci::AppInstaller::Result::OK) {
+ LOG(ERROR) << "CrashTpkInstaller run failure";
+ return -1;
+ }
+ return 0;
+}
+
+static int RunTpkInstallerWithoutParserPlugins(ci::PkgMgrPtr pkgmgr) {
+ ::TpkInstallerWithoutPasrserPlugins t(pkgmgr);
+
+ if (t.Run() != ci::AppInstaller::Result::OK) {
+ LOG(ERROR) << "TpkInstallerWithoutPasrserPlugins run failure";
+ return -1;
+ }
+ return 0;
+}
+
// 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;
if (!strcmp(argv[argc-2], "-idx")) {
index = atoi(argv[argc-1]);
backend_argc = argc-2;
LOG(DEBUG) << "Step crash after " << step_name << " step.";
}
+ if (!strcmp(argv[argc-1], "-remove_plugin_steps")) {
+ backend_argc = argc-1;
+ remove_plugins = true;
+ LOG(DEBUG) << "Remove parser plugins steps";
+ }
+
ci::PkgmgrInstaller pkgmgr_installer;
tpk::TpkAppQueryInterface interface;
ci::PkgMgrPtr pkgmgr = ci::PkgMgrInterface::Create(backend_argc, argv,
return -1;
}
- ::CrashTpkInstaller t(pkgmgr, index, step_name);
-
- if (t.Run() != ci::AppInstaller::Result::OK) {
- LOG(ERROR) << "CrashTpkInstaller run failure";
- return -1;
- }
- return 0;
+ if (remove_plugins)
+ return RunTpkInstallerWithoutParserPlugins(pkgmgr);
+ else
+ return RunCrashTpkInstaller(pkgmgr, index, step_name);
}