From: Ilho Kim Date: Tue, 8 Jun 2021 00:21:14 +0000 (+0900) Subject: Add Test for creating res-control directories X-Git-Tag: submit/tizen/20210617.070222~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a243d3c36c5fb1a501d32256bf08c7408fad128d;p=platform%2Fcore%2Fappfw%2Ftpk-backend.git Add Test for creating res-control directories smoke-test -SmokeTest.InstallationMode_ResControl -SmokeTest.UpdateMode_AddResControl -SmokeTest.UpdateMode_RemoveResControl -SmokeTest.RecoveryMode_AddResControl -SmokeTest.RecoveryMode_RemoveResControl extensive-smoke-test -SmokeTest.RecoveryMode_AddResControl -SmokeTest.RecoveryMode_RemoveResControl Change-Id: Ie4d64b84e5395446cbe3028294febc9534c5cd20 Signed-off-by: Ilho Kim --- diff --git a/test/smoke_tests/extensive_smoke_test.cc b/test/smoke_tests/extensive_smoke_test.cc index 4e3238a..3266eff 100644 --- a/test/smoke_tests/extensive_smoke_test.cc +++ b/test/smoke_tests/extensive_smoke_test.cc @@ -43,6 +43,8 @@ class SmokeEnvironment : public testing::Environment { for (auto& path : backups_) ASSERT_TRUE(BackupPathCopyAndRemove(path)); } + + CreateDatabase(); } void TearDown() override { ASSERT_TRUE(request_mode_ == ci::RequestMode::GLOBAL || @@ -539,6 +541,98 @@ TEST_F(PreloadSmokeTest, RecoveryMode_ForReadonlyUpdateInstall) { }, params.pkg_type); } +TEST_F(SmokeTest, RecoveryMode_AddResControl) { + bf::path path_old = kSmokePackagesDirectory + / "RecoveryMode_AddResControl.tpk"; + bf::path path_new = kSmokePackagesDirectory + / "RecoveryMode_AddResControl_2.tpk"; + RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid); + ASSERT_EQ(backend.Install(path_old), ci::AppInstaller::Result::OK); + + std::string pkgid = "smoketpk50"; + std::string appid = "smoketpk50.RecoveryMode_AddResControl"; + std::string exec = "native"; + bf::path root_path = ci::GetRootAppPath(params.is_readonly, + params.test_user.uid); + + 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) { + 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); + EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params)); + bool dir_exists = recovery_info->cleanup(); + EXTENDED_ASSERT_EQ(bf::exists(root_path / pkgid / "res/mount/allowed"), + dir_exists); + EXTENDED_ASSERT_EQ(bf::exists(root_path / pkgid / "res/mount/global"), + dir_exists); + EXTENDED_ASSERT_EQ(bf::exists(root_path / pkgid / "res/mount/work"), + dir_exists); + + if (recovery_info->cleanup()) { + EXTENDED_ASSERT_EQ(backend.Uninstall(pkgid), + ci::AppInstaller::Result::OK); + EXTENDED_ASSERT_EQ(backend.Install(path_old), + ci::AppInstaller::Result::OK); + } + } + return true; + }, params.pkg_type); +} + +TEST_F(SmokeTest, RecoveryMode_RemoveResControl) { + bf::path path_old = kSmokePackagesDirectory + / "RecoveryMode_RemoveResControl.tpk"; + bf::path path_new = kSmokePackagesDirectory + / "RecoveryMode_RemoveResControl_2.tpk"; + RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid); + ASSERT_EQ(backend.Install(path_old), ci::AppInstaller::Result::OK); + + std::string pkgid = "smoketpk51"; + std::string appid = "smoketpk51.RecoveryMode_RemoveResControl"; + std::string exec = "native"; + bf::path root_path = ci::GetRootAppPath(params.is_readonly, + params.test_user.uid); + + 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) { + 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); + EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params)); + bool dir_exists = !recovery_info->cleanup(); + EXTENDED_ASSERT_EQ(bf::exists(root_path / pkgid / "res/mount/allowed"), + dir_exists); + EXTENDED_ASSERT_EQ(bf::exists(root_path / pkgid / "res/mount/global"), + dir_exists); + EXTENDED_ASSERT_EQ(bf::exists(root_path / pkgid / "res/mount/work"), + dir_exists); + + if (recovery_info->cleanup()) { + EXTENDED_ASSERT_EQ(backend.Uninstall(pkgid), + ci::AppInstaller::Result::OK); + EXTENDED_ASSERT_EQ(backend.Install(path_old), + 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 ced8f24..71d2c40 100644 --- a/test/smoke_tests/smoke_test.cc +++ b/test/smoke_tests/smoke_test.cc @@ -928,6 +928,143 @@ TEST_F(PreloadSmokeTest, RecoveryMode_ForReadonlyUpdateInstall) { ASSERT_TRUE(version_old == version_recovered); } +TEST_F(SmokeTest, InstallationMode_ResControl) { + bf::path path = kSmokePackagesDirectory / "InstallationMode_ResControl.tpk"; + std::string pkgid = "smoketpk47"; + std::string appid = "smoketpk47.InstallationMode_ResControl"; + std::string exec = "native"; + bf::path root_path = ci::GetRootAppPath(params.is_readonly, + params.test_user.uid); + + ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK); + ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params)); + ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/allowed")); + ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/global")); + ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/work")); +} + +TEST_F(SmokeTest, UpdateMode_AddResControl) { + bf::path path_old = kSmokePackagesDirectory + / "UpdateMode_AddResControl.tpk"; + bf::path path_new = kSmokePackagesDirectory + / "UpdateMode_AddResControl_2.tpk"; + std::string pkgid = "smoketpk48"; + std::string appid = "smoketpk48.UpdateMode_AddResControl"; + std::string exec = "native"; + bf::path root_path = ci::GetRootAppPath(params.is_readonly, + params.test_user.uid); + + ASSERT_EQ(backend.Install(path_old), ci::AppInstaller::Result::OK); + ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params)); + ASSERT_FALSE(bf::exists(root_path / pkgid / "res/mount/allowed")); + ASSERT_FALSE(bf::exists(root_path / pkgid / "res/mount/global")); + ASSERT_FALSE(bf::exists(root_path / pkgid / "res/mount/work")); + + ASSERT_EQ(backend.Install(path_new), ci::AppInstaller::Result::OK); + ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params)); + ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/allowed")); + ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/global")); + ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/work")); +} + +TEST_F(SmokeTest, UpdateMode_RemoveResControl) { + bf::path path_old = kSmokePackagesDirectory + / "UpdateMode_RemoveResControl.tpk"; + bf::path path_new = kSmokePackagesDirectory + / "UpdateMode_RemoveResControl_2.tpk"; + std::string pkgid = "smoketpk49"; + std::string appid = "smoketpk49.UpdateMode_RemoveResControl"; + std::string exec = "native"; + bf::path root_path = ci::GetRootAppPath(params.is_readonly, + params.test_user.uid); + + ASSERT_EQ(backend.Install(path_old), ci::AppInstaller::Result::OK); + ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params)); + ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/allowed")); + ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/global")); + ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/work")); + + ASSERT_EQ(backend.Install(path_new), ci::AppInstaller::Result::OK); + ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params)); + ASSERT_FALSE(bf::exists(root_path / pkgid / "res/mount/allowed")); + ASSERT_FALSE(bf::exists(root_path / pkgid / "res/mount/global")); + ASSERT_FALSE(bf::exists(root_path / pkgid / "res/mount/work")); +} + +TEST_F(SmokeTest, RecoveryMode_AddResControl) { + bf::path path_old = kSmokePackagesDirectory + / "RecoveryMode_AddResControl.tpk"; + bf::path path_new = kSmokePackagesDirectory + / "RecoveryMode_AddResControl_2.tpk"; + RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid); + + std::string pkgid = "smoketpk50"; + std::string appid = "smoketpk50.RecoveryMode_AddResControl"; + std::string exec = "native"; + bf::path root_path = ci::GetRootAppPath(params.is_readonly, + params.test_user.uid); + + ASSERT_EQ(backend.Install(path_old), ci::AppInstaller::Result::OK); + ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params)); + ASSERT_FALSE(bf::exists(root_path / pkgid / "res/mount/allowed")); + ASSERT_FALSE(bf::exists(root_path / pkgid / "res/mount/global")); + ASSERT_FALSE(bf::exists(root_path / pkgid / "res/mount/work")); + + 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_FALSE(bf::exists(root_path / pkgid / "res/mount/allowed")); + ASSERT_FALSE(bf::exists(root_path / pkgid / "res/mount/global")); + ASSERT_FALSE(bf::exists(root_path / pkgid / "res/mount/work")); +} + +TEST_F(SmokeTest, RecoveryMode_RemoveResControl) { + bf::path path_old = kSmokePackagesDirectory + / "RecoveryMode_RemoveResControl.tpk"; + bf::path path_new = kSmokePackagesDirectory + / "RecoveryMode_RemoveResControl_2.tpk"; + RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid); + + std::string pkgid = "smoketpk51"; + std::string appid = "smoketpk51.RecoveryMode_RemoveResControl"; + std::string exec = "native"; + bf::path root_path = ci::GetRootAppPath(params.is_readonly, + params.test_user.uid); + + ASSERT_EQ(backend.Install(path_old), ci::AppInstaller::Result::OK); + ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params)); + ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/allowed")); + ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/global")); + ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/work")); + + 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(bf::exists(root_path / pkgid / "res/mount/allowed")); + ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/global")); + ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/work")); +} + } // namespace smoke_test int main(int argc, char** argv) { diff --git a/test/smoke_tests/test_samples/smoke/InstallationMode_ResControl.tpk b/test/smoke_tests/test_samples/smoke/InstallationMode_ResControl.tpk new file mode 100644 index 0000000..471fc24 Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/InstallationMode_ResControl.tpk differ diff --git a/test/smoke_tests/test_samples/smoke/RecoveryMode_AddResControl.tpk b/test/smoke_tests/test_samples/smoke/RecoveryMode_AddResControl.tpk new file mode 100644 index 0000000..a181ef4 Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/RecoveryMode_AddResControl.tpk differ diff --git a/test/smoke_tests/test_samples/smoke/RecoveryMode_AddResControl_2.tpk b/test/smoke_tests/test_samples/smoke/RecoveryMode_AddResControl_2.tpk new file mode 100644 index 0000000..712cd67 Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/RecoveryMode_AddResControl_2.tpk differ diff --git a/test/smoke_tests/test_samples/smoke/RecoveryMode_RemoveResControl.tpk b/test/smoke_tests/test_samples/smoke/RecoveryMode_RemoveResControl.tpk new file mode 100644 index 0000000..8f39f9e Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/RecoveryMode_RemoveResControl.tpk differ diff --git a/test/smoke_tests/test_samples/smoke/RecoveryMode_RemoveResControl_2.tpk b/test/smoke_tests/test_samples/smoke/RecoveryMode_RemoveResControl_2.tpk new file mode 100644 index 0000000..8c57e1e Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/RecoveryMode_RemoveResControl_2.tpk differ diff --git a/test/smoke_tests/test_samples/smoke/UpdateMode_AddResControl.tpk b/test/smoke_tests/test_samples/smoke/UpdateMode_AddResControl.tpk new file mode 100644 index 0000000..231e03d Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/UpdateMode_AddResControl.tpk differ diff --git a/test/smoke_tests/test_samples/smoke/UpdateMode_AddResControl_2.tpk b/test/smoke_tests/test_samples/smoke/UpdateMode_AddResControl_2.tpk new file mode 100644 index 0000000..c3840a5 Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/UpdateMode_AddResControl_2.tpk differ diff --git a/test/smoke_tests/test_samples/smoke/UpdateMode_RemoveResControl.tpk b/test/smoke_tests/test_samples/smoke/UpdateMode_RemoveResControl.tpk new file mode 100644 index 0000000..692c570 Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/UpdateMode_RemoveResControl.tpk differ diff --git a/test/smoke_tests/test_samples/smoke/UpdateMode_RemoveResControl_2.tpk b/test/smoke_tests/test_samples/smoke/UpdateMode_RemoveResControl_2.tpk new file mode 100644 index 0000000..9a6dcad Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/UpdateMode_RemoveResControl_2.tpk differ