From 7cc1495ee56c22a510f9ee39cb1e31080a8f7bdb Mon Sep 17 00:00:00 2001 From: Tomasz Iwanek Date: Thu, 15 Sep 2016 14:53:42 +0200 Subject: [PATCH] Check private data files preservation in smoke tests Change-Id: I1de7c32e4c9fe14f0a781e5d1f328dea62c9a02b --- src/unit_tests/smoke_test.cc | 153 ++++++++++++++++++++++++------------------- 1 file changed, 87 insertions(+), 66 deletions(-) diff --git a/src/unit_tests/smoke_test.cc b/src/unit_tests/smoke_test.cc index a8725bc..48c6045 100644 --- a/src/unit_tests/smoke_test.cc +++ b/src/unit_tests/smoke_test.cc @@ -143,12 +143,15 @@ bf::path FindRecoveryFile() { return {}; } +bf::path GetPackageRoot(const std::string& pkgid) { + bf::path root_path = ci::GetRootAppPath(false, kTestUserId); + return root_path / pkgid; +} + bool ValidateFileContentInPackage(const std::string& pkgid, const std::string& relative, const std::string& expected) { - bf::path root_path = ci::GetRootAppPath(false, - kTestUserId); - bf::path file_path = root_path / pkgid / relative; + bf::path file_path = GetPackageRoot(pkgid) / relative; if (!bf::exists(file_path)) { LOG(ERROR) << file_path << " doesn't exist"; return false; @@ -167,11 +170,22 @@ bool ValidateFileContentInPackage(const std::string& pkgid, return content == expected; } +void AddDataFiles(const std::string& pkgid) { + auto pkg_path = GetPackageRoot(pkgid); + ASSERT_TRUE(TouchFile(pkg_path / "data" / "file1.txt")); + ASSERT_TRUE(TouchFile(pkg_path / "data" / "file2.txt")); +} + +void ValidateDataFiles(const std::string& pkgid) { + auto pkg_path = GetPackageRoot(pkgid); + ASSERT_TRUE(bf::exists(pkg_path / "data" / "file1.txt")); + ASSERT_TRUE(bf::exists(pkg_path / "data" / "file2.txt")); +} + void ValidatePackageFS(const std::string& pkgid, const std::vector& appids) { - bf::path root_path = ci::GetRootAppPath(false, - kTestUserId); - bf::path package_path = root_path / pkgid; + bf::path root_path = ci::GetRootAppPath(false, kTestUserId); + bf::path package_path = GetPackageRoot(pkgid); bf::path data_path = package_path / "data"; bf::path shared_path = package_path / "shared"; bf::path cache_path = package_path / "cache"; @@ -218,9 +232,7 @@ void ValidatePackageFS(const std::string& pkgid, void PackageCheckCleanup(const std::string& pkgid, const std::vector&) { - bf::path root_path = ci::GetRootAppPath( - false, kTestUserId); - bf::path package_path = root_path / pkgid; + bf::path package_path = GetPackageRoot(pkgid); ASSERT_FALSE(bf::exists(package_path)); bf::path manifest_path = @@ -309,33 +321,12 @@ ci::AppInstaller::Result Install(const bf::path& path, return CallBackend(SIZEOFARRAY(argv), argv, type, mode); } -ci::AppInstaller::Result Update(const bf::path& path_old, - const bf::path& path_new, - PackageType type, - RequestResult mode = RequestResult::NORMAL) { - if (Install(path_old, type) != ci::AppInstaller::Result::OK) { - LOG(ERROR) << "Failed to install application. Cannot update"; - return ci::AppInstaller::Result::UNKNOWN; - } - return Install(path_new, type, mode); -} - ci::AppInstaller::Result MountInstall(const bf::path& path, PackageType type, RequestResult mode = RequestResult::NORMAL) { const char* argv[] = {"", "-w", path.c_str(), "-u", kTestUserIdStr.c_str()}; return CallBackend(SIZEOFARRAY(argv), argv, type, mode); } -ci::AppInstaller::Result MountUpdate(const bf::path& path_old, - const bf::path& path_new, PackageType type, - RequestResult mode = RequestResult::NORMAL) { - if (MountInstall(path_old, type) != ci::AppInstaller::Result::OK) { - LOG(ERROR) << "Failed to mount-install application. Cannot mount-update"; - return ci::AppInstaller::Result::UNKNOWN; - } - return MountInstall(path_new, type, mode); -} - ci::AppInstaller::Result Uninstall(const std::string& pkgid, PackageType type, RequestResult mode = RequestResult::NORMAL) { @@ -481,11 +472,13 @@ TEST_F(SmokeTest, UpdateMode) { bf::path path_new = kSmokePackagesDirectory / "UpdateMode_2.wgt"; std::string pkgid = "smokeapp04"; std::string appid = "smokeapp04.UpdateMode"; - ASSERT_EQ(Update(path_old, path_new, PackageType::WGT), - ci::AppInstaller::Result::OK); + ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK); + AddDataFiles(pkgid); + ASSERT_EQ(Install(path_new, PackageType::WGT), ci::AppInstaller::Result::OK); ValidatePackage(pkgid, {appid}); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n")); + ValidateDataFiles(pkgid); } TEST_F(SmokeTest, DeinstallationMode) { @@ -508,10 +501,8 @@ TEST_F(SmokeTest, RDSMode) { ValidatePackage(pkgid, {appid}); // Check delta modifications - bf::path root_path = ci::GetRootAppPath(false, - kTestUserId); - ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED")); - ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED")); + ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid) / "res" / "wgt" / "DELETED")); + ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid) / "res" / "wgt" / "ADDED")); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "2\n")); } @@ -550,17 +541,15 @@ TEST_F(SmokeTest, ClearMode) { std::string appid = "smokeapp20.ClearMode"; ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK); - bf::path root_path = ci::GetRootAppPath(false, - kTestUserId); bs::error_code error; - bf::create_directory(root_path / pkgid / "data" / "dir", error); + bf::create_directory(GetPackageRoot(pkgid) / "data" / "dir", error); ASSERT_FALSE(error); - ASSERT_TRUE(TouchFile(root_path / pkgid / "data" / "dir" / "file")); - ASSERT_TRUE(TouchFile(root_path / pkgid / "data" / "file")); + ASSERT_TRUE(TouchFile(GetPackageRoot(pkgid) / "data" / "dir" / "file")); + ASSERT_TRUE(TouchFile(GetPackageRoot(pkgid) / "data" / "file")); ASSERT_EQ(Clear(pkgid, PackageType::WGT), ci::AppInstaller::Result::OK); ValidatePackage(pkgid, {appid}); - ASSERT_FALSE(bf::exists(root_path / pkgid / "data" / "dir" / "file")); - ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "file")); + ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid) / "data" / "dir" / "file")); + ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid) / "res" / "file")); } TEST_F(SmokeTest, DeltaMode) { @@ -573,14 +562,12 @@ TEST_F(SmokeTest, DeltaMode) { ValidatePackage(pkgid, {appid}); // Check delta modifications - bf::path root_path = ci::GetRootAppPath(false, - kTestUserId); - ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED")); - ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED")); - ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "css" / "style.css")); // NOLINT - ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "images" / "tizen_32.png")); // NOLINT - ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "js" / "main.js")); - ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "version 2\n")); + ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid) / "res" / "wgt" / "DELETED")); + ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid) / "res" / "wgt" / "ADDED")); + ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid) / "res" / "wgt" / "css" / "style.css")); // NOLINT + ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid) / "res" / "wgt" / "images" / "tizen_32.png")); // NOLINT + ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid) / "res" / "wgt" / "js" / "main.js")); // NOLINT + ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "version 2\n")); // NOLINT } TEST_F(SmokeTest, RecoveryMode_ForInstallation) { @@ -603,12 +590,13 @@ TEST_F(SmokeTest, RecoveryMode_ForUpdate) { bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForUpdate_2.wgt"; RemoveAllRecoveryFiles(); ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK); + std::string pkgid = "smokeapp10"; + std::string appid = "smokeapp10.RecoveryModeForUpdate"; + AddDataFiles(pkgid); Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper"); backend_crash.Run("-i", path_new.string(), "-u", kTestUserIdStr.c_str()); ASSERT_NE(backend_crash.Wait(), 0); - std::string pkgid = "smokeapp10"; - std::string appid = "smokeapp10.RecoveryModeForUpdate"; bf::path recovery_file = FindRecoveryFile(); ASSERT_FALSE(recovery_file.empty()); ASSERT_EQ(Recover(recovery_file, PackageType::WGT), @@ -616,6 +604,7 @@ TEST_F(SmokeTest, RecoveryMode_ForUpdate) { ValidatePackage(pkgid, {appid}); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n")); + ValidateDataFiles(pkgid); } TEST_F(SmokeTest, RecoveryMode_ForDelta) { @@ -664,6 +653,7 @@ TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) { RemoveAllRecoveryFiles(); ASSERT_EQ(MountInstall(path_old, PackageType::WGT), ci::AppInstaller::Result::OK); + AddDataFiles(pkgid); Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper"); backend_crash.Run("-w", path_new.string(), "-u", kTestUserIdStr.c_str()); ASSERT_NE(backend_crash.Wait(), 0); @@ -680,6 +670,7 @@ TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) { ScopedTzipInterface interface(pkgid); ValidatePackage(pkgid, {appid}); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n")); + ValidateDataFiles(pkgid); } TEST_F(SmokeTest, InstallationMode_GoodSignature) { @@ -706,11 +697,14 @@ TEST_F(SmokeTest, UpdateMode_Rollback) { bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Rollback_2.wgt"; std::string pkgid = "smokeapp07"; std::string appid = "smokeapp07.UpdateModeRollback"; - ASSERT_EQ(Update(path_old, path_new, PackageType::WGT, RequestResult::FAIL), - ci::AppInstaller::Result::ERROR); + ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK); + AddDataFiles(pkgid); + ASSERT_EQ(Install(path_new, PackageType::WGT, RequestResult::FAIL), + ci::AppInstaller::Result::ERROR); ValidatePackage(pkgid, {appid}); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n")); + ValidateDataFiles(pkgid); } TEST_F(SmokeTest, InstallationMode_Hybrid) { @@ -728,12 +722,16 @@ TEST_F(SmokeTest, UpdateMode_Hybrid) { std::string pkgid = "smokehyb02"; std::string appid1 = "smokehyb02.Web"; std::string appid2 = "smokehyb02.Native"; - ASSERT_EQ(Update(path_old, path_new, PackageType::HYBRID), + ASSERT_EQ(Install(path_old, PackageType::HYBRID), + ci::AppInstaller::Result::OK); + AddDataFiles(pkgid); + ASSERT_EQ(Install(path_new, PackageType::HYBRID), ci::AppInstaller::Result::OK); ValidatePackage(pkgid, {appid1, appid2}); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n")); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "VERSION", "2\n")); + ValidateDataFiles(pkgid); } TEST_F(SmokeTest, DeinstallationMode_Hybrid) { @@ -767,8 +765,8 @@ TEST_F(SmokeTest, DeltaMode_Hybrid) { ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "css" / "style.css")); // NOLINT ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "images" / "tizen_32.png")); // NOLINT ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "js" / "main.js")); - ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "version 2\n")); - ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/MODIFIED", "version 2\n")); + ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "version 2\n")); // NOLINT + ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/MODIFIED", "version 2\n")); // NOLINT } TEST_F(SmokeTest, MountInstallationMode_Hybrid) { @@ -776,7 +774,8 @@ TEST_F(SmokeTest, MountInstallationMode_Hybrid) { std::string pkgid = "smokehyb05"; std::string appid1 = "smokehyb05.web"; std::string appid2 = "smokehyb05.service"; - ASSERT_EQ(MountInstall(path, PackageType::HYBRID), ci::AppInstaller::Result::OK); + ASSERT_EQ(MountInstall(path, PackageType::HYBRID), + ci::AppInstaller::Result::OK); ScopedTzipInterface interface(pkgid); ValidatePackage(pkgid, {appid1, appid2}); } @@ -787,13 +786,17 @@ TEST_F(SmokeTest, MountUpdateMode_Hybrid) { std::string pkgid = "smokehyb06"; std::string appid1 = "smokehyb06.web"; std::string appid2 = "smokehyb06.service"; - ASSERT_EQ(MountUpdate(path_old, path_new, PackageType::WGT), + ASSERT_EQ(MountInstall(path_old, PackageType::WGT), + ci::AppInstaller::Result::OK); + AddDataFiles(pkgid); + ASSERT_EQ(MountInstall(path_new, PackageType::WGT), ci::AppInstaller::Result::OK); ScopedTzipInterface interface(pkgid); ValidatePackage(pkgid, {appid1, appid2}); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n")); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/VERSION", "2\n")); + ValidateDataFiles(pkgid); } TEST_F(SmokeTest, InstallationMode_Rollback_Hybrid) { @@ -815,12 +818,16 @@ TEST_F(SmokeTest, UpdateMode_Rollback_Hybrid) { std::string pkgid = "smokehyb08"; std::string appid1 = "smokehyb08.web"; std::string appid2 = "smokehyb08.service"; - ASSERT_EQ(Update(path_old, path_new, PackageType::HYBRID, + ASSERT_EQ(Install(path_old, PackageType::HYBRID), + ci::AppInstaller::Result::OK); + AddDataFiles(pkgid); + ASSERT_EQ(Install(path_new, PackageType::HYBRID, RequestResult::FAIL), ci::AppInstaller::Result::ERROR); ValidatePackage(pkgid, {appid1, appid2}); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n")); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/VERSION", "1\n")); + ValidateDataFiles(pkgid); } TEST_F(SmokeTest, MountInstallationMode_Rollback_Hybrid) { @@ -843,13 +850,17 @@ TEST_F(SmokeTest, MountUpdateMode_Rollback_Hybrid) { std::string pkgid = "smokehyb10"; std::string appid1 = "smokehyb10.web"; std::string appid2 = "smokehyb10.service"; - ASSERT_EQ(MountUpdate(path_old, path_new, PackageType::HYBRID, + ASSERT_EQ(MountInstall(path_old, PackageType::HYBRID), + ci::AppInstaller::Result::OK); + AddDataFiles(pkgid); + ASSERT_EQ(MountInstall(path_new, PackageType::HYBRID, RequestResult::FAIL), ci::AppInstaller::Result::ERROR); ScopedTzipInterface interface(pkgid); ValidatePackage(pkgid, {appid1, appid2}); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n")); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/VERSION", "1\n")); + ValidateDataFiles(pkgid); } TEST_F(SmokeTest, MountInstallationMode) { @@ -866,16 +877,21 @@ TEST_F(SmokeTest, MountUpdateMode) { bf::path path_new = kSmokePackagesDirectory / "MountUpdateMode_2.wgt"; std::string pkgid = "smokeapp29"; std::string appid = "smokeapp29.UpdateMode"; - ASSERT_EQ(MountUpdate(path_old, path_new, PackageType::WGT), + ASSERT_EQ(MountInstall(path_old, PackageType::WGT), + ci::AppInstaller::Result::OK); + AddDataFiles(pkgid); + ASSERT_EQ(MountInstall(path_new, PackageType::WGT), ci::AppInstaller::Result::OK); ScopedTzipInterface interface(pkgid); ValidatePackage(pkgid, {appid}); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n")); + ValidateDataFiles(pkgid); } TEST_F(SmokeTest, MountInstallationMode_Rollback) { - bf::path path = kSmokePackagesDirectory / "MountInstallationMode_Rollback.wgt"; + bf::path path = + kSmokePackagesDirectory / "MountInstallationMode_Rollback.wgt"; std::string pkgid = "smokeapp33"; std::string appid = "smokeapp33.web"; ASSERT_EQ(MountInstall(path, PackageType::WGT, RequestResult::FAIL), @@ -886,15 +902,20 @@ TEST_F(SmokeTest, MountInstallationMode_Rollback) { TEST_F(SmokeTest, MountUpdateMode_Rollback) { bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode_Rollback.wgt"; - bf::path path_new = kSmokePackagesDirectory / "MountUpdateMode_Rollback_2.wgt"; + bf::path path_new = + kSmokePackagesDirectory / "MountUpdateMode_Rollback_2.wgt"; std::string pkgid = "smokeapp34"; std::string appid = "smokeapp34.web"; - ASSERT_EQ(MountUpdate(path_old, path_new, PackageType::WGT, + ASSERT_EQ(MountInstall(path_old, PackageType::WGT), + ci::AppInstaller::Result::OK); + AddDataFiles(pkgid); + ASSERT_EQ(MountInstall(path_new, PackageType::WGT, RequestResult::FAIL), ci::AppInstaller::Result::ERROR); ScopedTzipInterface interface(pkgid); ValidatePackage(pkgid, {appid}); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n")); + ValidateDataFiles(pkgid); } TEST_F(SmokeTest, UserDefinedPlugins) { -- 2.7.4