From: Ilho Kim Date: Thu, 12 Dec 2019 04:28:32 +0000 (+0900) Subject: Change the way to invoke installer as a subprocess X-Git-Tag: accepted/tizen/unified/20200212.125959~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F05%2F220005%2F12;p=platform%2Fcore%2Fappfw%2Ftpk-backend.git Change the way to invoke installer as a subprocess Requires : [app-installers]https://review.tizen.org/gerrit/#/c/platform/core/appfw/app-installers/+/220004/ Change-Id: I18b51a7bdf85daeb1dad60178fa045bf40f85cad --- diff --git a/src/unit_tests/recovery_test.cc b/src/unit_tests/recovery_test.cc index 2ad8754..beea2fd 100644 --- a/src/unit_tests/recovery_test.cc +++ b/src/unit_tests/recovery_test.cc @@ -71,8 +71,13 @@ class SmokeEnvironment : public testing::Environment { (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()); @@ -107,14 +112,13 @@ namespace smoke_test { 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; }; @@ -122,28 +126,26 @@ TEST_F(SmokeTest, RecoveryMode_Tpk_Installation) { 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) { @@ -151,35 +153,37 @@ 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 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 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) { @@ -187,69 +191,70 @@ 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 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 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) { @@ -259,38 +264,40 @@ 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 diff --git a/src/unit_tests/smoke_test_helper.cc b/src/unit_tests/smoke_test_helper.cc index 22b6252..26b3ccf 100644 --- a/src/unit_tests/smoke_test_helper.cc +++ b/src/unit_tests/smoke_test_helper.cc @@ -41,6 +41,12 @@ class StepCrash : public ci::Step { AddStep(); \ } \ +#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, @@ -73,14 +79,68 @@ class CrashTpkInstaller : public tpk::TpkInstaller { 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; @@ -93,6 +153,12 @@ int main(const int argc, char* argv[]) { 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, @@ -103,11 +169,8 @@ int main(const int argc, char* 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); } diff --git a/src/unit_tests/smoke_utils.h b/src/unit_tests/smoke_utils.h index e029050..5d9b854 100644 --- a/src/unit_tests/smoke_utils.h +++ b/src/unit_tests/smoke_utils.h @@ -53,6 +53,14 @@ class TpkBackendInterface: public BackendInterface { common_installer::PkgMgrPtr pkgmgr, int fail_at) const override; }; +class TpkSmokeTestHelperRunner : public SmokeTestHelperRunner { + private: + common_installer::Subprocess CreateSubprocess() const { + return common_installer::Subprocess( + "/usr/bin/tpk-backend-ut/smoke-test-helper"); + } +}; + #define OVERRIDE_STEPS_BLOCK(STEPS) \ void STEPS() override { \ tpk::TpkInstaller::STEPS(); \