From: Ilho Kim Date: Mon, 7 Sep 2020 01:49:05 +0000 (+0900) Subject: Add recovery test for ReadonlyUpdateInstall X-Git-Tag: submit/tizen/20201027.061339~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4f78b5bdb2d27e61e553ff939bf648c14bac9526;p=platform%2Fcore%2Fappfw%2Ftpk-backend.git Add recovery test for ReadonlyUpdateInstall Change-Id: Ie204fa3c61024e8703a1065be9704bc451647f19 Signed-off-by: Ilho Kim --- diff --git a/test/smoke_tests/extensive_smoke_test.cc b/test/smoke_tests/extensive_smoke_test.cc index 559aa92..4e3238a 100644 --- a/test/smoke_tests/extensive_smoke_test.cc +++ b/test/smoke_tests/extensive_smoke_test.cc @@ -98,6 +98,18 @@ class SmokeTest : public testing::Test { TestParameters params; }; +class PreloadSmokeTest : public testing::Test { + public: + PreloadSmokeTest() : backend(std::to_string(env->test_user.uid)), + params{PackageType::TPK, true} { + params.test_user.uid = env->test_user.uid; + params.test_user.gid = env->test_user.gid; + } + protected: + TpkBackendInterface backend; + TestParameters params; +}; + TEST_F(SmokeTest, DeltaMode_Tpk_Rollback) { bf::path path = kSmokePackagesDirectory / "DeltaMode_Tpk_Rollback.tpk"; bf::path delta_package = kSmokePackagesDirectory / @@ -489,6 +501,44 @@ TEST_F(SmokeTest, MountUpdateMode_Rollback) { }); } +TEST_F(PreloadSmokeTest, RecoveryMode_ForReadonlyUpdateInstall) { + bf::path path_old = kSmokePackagesDirectory / + "RecoveryMode_ForReadonlyUpdateInstall.tpk"; + bf::path path_new = kSmokePackagesDirectory / + "RecoveryMode_ForReadonlyUpdateInstall_2.tpk"; + RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid); + ASSERT_EQ(backend.InstallPreload(path_old), ci::AppInstaller::Result::OK); + + std::string test_uid_str = std::to_string(params.test_user.uid); + std::vector args = + {"", "-i", path_new.string(), "-u", test_uid_str.c_str()}; + backend.CrashAfterEachStep(&args, [&](int step) -> bool { + if (step >= 2) { + std::string pkgid = "smoketpk46"; + std::string appid = "smoketpk46.RecoveryMode_ForReadonlyUpdateInstall"; + std::string exec = "smoketpk46"; + bf::path recovery_file = FindRecoveryFile("/tpk-recovery", + params.test_user.uid); + EXTENDED_ASSERT_FALSE(recovery_file.empty()); + std::unique_ptr recovery_info = + GetRecoverFileInfo(recovery_file); + EXTENDED_ASSERT_EQ(backend.Recover(recovery_file), + ci::AppInstaller::Result::OK); + if (recovery_info->cleanup()) + params.is_readonly = false; + EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params)); + std::string version = recovery_info->cleanup() ? "2" : "1"; + EXTENDED_ASSERT_TRUE( + ValidateFileContentInPackage(pkgid, "res/VERSION", version, params)); + if (recovery_info->cleanup()) { + EXTENDED_ASSERT_EQ(backend.Uninstall(pkgid), + ci::AppInstaller::Result::OK); + } + } + return true; + }, params.pkg_type); +} + } // namespace smoke_test int main(int argc, char** argv) { diff --git a/test/smoke_tests/smoke_test.cc b/test/smoke_tests/smoke_test.cc index c026b89..50bd8e0 100644 --- a/test/smoke_tests/smoke_test.cc +++ b/test/smoke_tests/smoke_test.cc @@ -891,6 +891,41 @@ TEST_F(SmokeTest, RecoveryMode_NonSharedDataUpdate) { ASSERT_FALSE(bf::exists(recovery_info->unpacked_dir())); } +TEST_F(PreloadSmokeTest, RecoveryMode_ForReadonlyUpdateInstall) { + ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user"; + bf::path path_old = kSmokePackagesDirectory / + "RecoveryMode_ForReadonlyUpdateInstall.tpk"; + bf::path path_new = kSmokePackagesDirectory / + "RecoveryMode_ForReadonlyUpdateInstall_2.tpk"; + RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid); + ASSERT_EQ(backend.InstallPreload(path_old), ci::AppInstaller::Result::OK); + + std::string pkgid = "smoketpk46"; + std::string appid = "smoketpk46.RecoveryMode_ForReadonlyUpdateInstall"; + std::string exec = "smoketpk46"; + ci::PkgQueryInterface pkg_query(pkgid, params.test_user.uid); + std::string version_old = pkg_query.Version(); + + ci::Subprocess backend_crash("/usr/bin/tpk-installer-ut/smoke-test-helper"); + std::string test_uid_str = std::to_string(params.test_user.uid); + backend_crash.Run("-i", path_new.string(), "-u", test_uid_str.c_str()); + ASSERT_NE(backend_crash.Wait(), 0); + + bf::path recovery_file = FindRecoveryFile("/tpk-recovery", + params.test_user.uid); + ASSERT_FALSE(recovery_file.empty()); + 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", "1", params)); + ASSERT_FALSE(bf::exists(recovery_info->unpacked_dir())); + ci::PkgQueryInterface pkg_query2(pkgid, params.test_user.uid, true); + std::string version_recovered = pkg_query2.Version(); + ASSERT_TRUE(version_old == version_recovered); +} + } // namespace smoke_test int main(int argc, char** argv) { diff --git a/test/smoke_tests/test_samples/smoke/RecoveryMode_ForReadonlyUpdateInstall.tpk b/test/smoke_tests/test_samples/smoke/RecoveryMode_ForReadonlyUpdateInstall.tpk new file mode 100644 index 0000000..da34119 Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/RecoveryMode_ForReadonlyUpdateInstall.tpk differ diff --git a/test/smoke_tests/test_samples/smoke/RecoveryMode_ForReadonlyUpdateInstall_2.tpk b/test/smoke_tests/test_samples/smoke/RecoveryMode_ForReadonlyUpdateInstall_2.tpk new file mode 100644 index 0000000..20de544 Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/RecoveryMode_ForReadonlyUpdateInstall_2.tpk differ