#include <boost/filesystem/path.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/system/error_code.hpp>
+
#include <common/paths.h>
#include <common/pkgmgr_interface.h>
#include <common/pkgmgr_query.h>
#include <common/request.h>
#include <common/step/configuration/step_fail.h>
#include <common/tzip_interface.h>
+#include <common/utils/file_util.h>
#include <common/utils/subprocess.h>
+
#include <gtest/gtest.h>
#include <gtest/gtest-death-test.h>
#include <pkgmgr-info.h>
namespace {
const uid_t kTestUserId = tzplatform_getuid(TZ_SYS_DEFAULT_USER);
+const gid_t kTestGroupId = tzplatform_getgid(TZ_SYS_DEFAULT_USER);
const std::string kTestUserIdStr =
std::to_string(kTestUserId);
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;
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<std::string>& 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";
bf::path manifest_backup = ci::GetBackupPathForManifestFile(manifest_path);
ASSERT_FALSE(bf::exists(package_backup));
ASSERT_FALSE(bf::exists(manifest_backup));
+
+ for (bf::recursive_directory_iterator iter(package_path);
+ iter != bf::recursive_directory_iterator(); ++iter) {
+ if (bf::is_symlink(symlink_status(iter->path())))
+ continue;
+ struct stat stats;
+ stat(iter->path().c_str(), &stats);
+ ASSERT_EQ(kTestUserId, stats.st_uid) << "Invalid uid: " << iter->path();
+ ASSERT_EQ(kTestGroupId, stats.st_gid) << "Invalid gid: " << iter->path();
+ }
}
void PackageCheckCleanup(const std::string& pkgid,
const std::vector<std::string>&) {
- 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 =
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) {
return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
}
-ci::AppInstaller::Result Reinstall(const bf::path& path,
- const bf::path& delta_dir,
+ci::AppInstaller::Result RDSUpdate(const bf::path& path,
+ const std::string& pkgid,
PackageType type,
RequestResult mode = RequestResult::NORMAL) {
if (Install(path, type) != ci::AppInstaller::Result::OK) {
LOG(ERROR) << "Failed to install application. Cannot perform RDS";
return ci::AppInstaller::Result::UNKNOWN;
}
- const char* argv[] = {"", "-r", delta_dir.c_str(), "-u",
+ const char* argv[] = {"", "-r", pkgid.c_str(), "-u",
kTestUserIdStr.c_str()};
return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
}
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) {
TEST_F(SmokeTest, RDSMode) {
bf::path path = kSmokePackagesDirectory / "RDSMode.wgt";
- bf::path delta_directory = kSmokePackagesDirectory / "delta_dir/";
std::string pkgid = "smokeapp11";
std::string appid = "smokeapp11.RDSMode";
- ASSERT_EQ(Reinstall(path, delta_directory, PackageType::WGT),
+ bf::path delta_directory = kSmokePackagesDirectory / "delta_dir/";
+ bf::path sdk_expected_directory =
+ bf::path(ci::GetRootAppPath(false, kTestUserId)) / "tmp" / pkgid;
+ bs::error_code error;
+ bf::create_directories(sdk_expected_directory.parent_path(), error);
+ ASSERT_FALSE(error);
+ ASSERT_TRUE(CopyDir(delta_directory, sdk_expected_directory));
+ ASSERT_EQ(RDSUpdate(path, pkgid, PackageType::WGT),
ci::AppInstaller::Result::OK);
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"));
- ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "2\n");
+ 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"));
}
TEST_F(SmokeTest, EnablePkg) {
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) {
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"));
- 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) {
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),
ValidatePackage(pkgid, {appid});
ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
+ ValidateDataFiles(pkgid);
}
TEST_F(SmokeTest, RecoveryMode_ForDelta) {
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);
ScopedTzipInterface interface(pkgid);
ValidatePackage(pkgid, {appid});
ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
+ ValidateDataFiles(pkgid);
}
TEST_F(SmokeTest, InstallationMode_GoodSignature) {
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) {
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) {
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"));
- ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "version 2\n");
- 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) {
+ bf::path path = kSmokePackagesDirectory / "MountInstallationMode_Hybrid.wgt";
+ std::string pkgid = "smokehyb05";
+ std::string appid1 = "smokehyb05.web";
+ std::string appid2 = "smokehyb05.service";
+ ASSERT_EQ(MountInstall(path, PackageType::HYBRID),
+ ci::AppInstaller::Result::OK);
+ ScopedTzipInterface interface(pkgid);
+ ValidatePackage(pkgid, {appid1, appid2});
+}
+
+TEST_F(SmokeTest, MountUpdateMode_Hybrid) {
+ bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode_Hybrid.wgt";
+ bf::path path_new = kSmokePackagesDirectory / "MountUpdateMode_Hybrid_2.wgt";
+ std::string pkgid = "smokehyb06";
+ std::string appid1 = "smokehyb06.web";
+ std::string appid2 = "smokehyb06.service";
+ 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) {
+ bf::path path = kSmokePackagesDirectory /
+ "InstallationMode_Rollback_Hybrid.wgt";
+ std::string pkgid = "smokehyb07";
+ std::string appid1 = "smokehyb07.web";
+ std::string appid2 = "smokehyb07.service";
+ ASSERT_EQ(Install(path, PackageType::HYBRID, RequestResult::FAIL),
+ ci::AppInstaller::Result::ERROR);
+ CheckPackageNonExistance(pkgid, {appid1, appid2});
+}
+
+TEST_F(SmokeTest, UpdateMode_Rollback_Hybrid) {
+ bf::path path_old = kSmokePackagesDirectory /
+ "UpdateMode_Rollback_Hybrid.wgt";
+ bf::path path_new = kSmokePackagesDirectory /
+ "UpdateMode_Rollback_Hybrid_2.wgt";
+ std::string pkgid = "smokehyb08";
+ std::string appid1 = "smokehyb08.web";
+ std::string appid2 = "smokehyb08.service";
+ 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) {
+ bf::path path = kSmokePackagesDirectory /
+ "MountInstallationMode_Rollback_Hybrid.wgt";
+ std::string pkgid = "smokehyb09";
+ std::string appid1 = "smokehyb09.web";
+ std::string appid2 = "smokehyb09.service";
+ ASSERT_EQ(MountInstall(path, PackageType::HYBRID, RequestResult::FAIL),
+ ci::AppInstaller::Result::ERROR);
+ ScopedTzipInterface interface(pkgid);
+ CheckPackageNonExistance(pkgid, {appid1, appid2});
+}
+
+TEST_F(SmokeTest, MountUpdateMode_Rollback_Hybrid) {
+ bf::path path_old = kSmokePackagesDirectory /
+ "MountUpdateMode_Rollback_Hybrid.wgt";
+ bf::path path_new = kSmokePackagesDirectory /
+ "MountUpdateMode_Rollback_Hybrid_2.wgt";
+ std::string pkgid = "smokehyb10";
+ std::string appid1 = "smokehyb10.web";
+ std::string appid2 = "smokehyb10.service";
+ 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) {
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";
+ std::string pkgid = "smokeapp33";
+ std::string appid = "smokeapp33.web";
+ ASSERT_EQ(MountInstall(path, PackageType::WGT, RequestResult::FAIL),
+ ci::AppInstaller::Result::ERROR);
+ ScopedTzipInterface interface(pkgid);
+ CheckPackageNonExistance(pkgid, {appid});
+}
+
+TEST_F(SmokeTest, MountUpdateMode_Rollback) {
+ bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode_Rollback.wgt";
+ bf::path path_new =
+ kSmokePackagesDirectory / "MountUpdateMode_Rollback_2.wgt";
+ std::string pkgid = "smokeapp34";
+ std::string appid = "smokeapp34.web";
+ 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) {