#include <boost/filesystem/path.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/system/error_code.hpp>
+#include <boost/format.hpp>
+#include <boost/program_options.hpp>
#include <common/paths.h>
#include <common/pkgmgr_interface.h>
#include <common/utils/file_util.h>
#include <common/utils/subprocess.h>
#include <common/utils/user_util.h>
+#include <gum/gum-user.h>
+#include <gum/gum-user-service.h>
+#include <gum/common/gum-user-types.h>
#include <gtest/gtest.h>
#include <gtest/gtest-death-test.h>
#include <tzplatform_config.h>
#include <vconf.h>
#include <vconf-internal-keys.h>
+#include <getopt.h>
#include <array>
#include <cstdio>
#include <cstdlib>
#include <vector>
+#include <regex>
#include "hybrid/hybrid_installer.h"
#include "wgt/wgt_app_query_interface.h"
namespace bf = boost::filesystem;
namespace bs = boost::system;
+namespace bo = boost::program_options;
namespace ci = common_installer;
namespace {
+ci::RequestMode ParseRequestMode(int argc, char** argv) {
+ bo::options_description desc("Available options");
+ desc.add_options()
+ ("request-mode", bo::value<std::string>(), "set request mode")
+ ("global-request,g", "set request mode to global")
+ ("user-request,u", "set request mode to user");
+
+ bo::variables_map vm;
+ bo::store(bo::parse_command_line(argc, argv, desc), vm);
+ bo::notify(vm);
+
+ if (vm.count("global-request")) {
+ std::cout << "Request mode was set to global." << std::endl;
+ return ci::RequestMode::GLOBAL;
+ }
+ if (vm.count("user-request")) {
+ std::cout << "Request mode was set to user." << std::endl;
+ return ci::RequestMode::USER;
+ }
+ if (vm.count("request-mode")) {
+ if (vm["request-mode"].as<std::string>() == "global") {
+ std::cout << "Request mode was set to global." << std::endl;
+ return ci::RequestMode::GLOBAL;
+ }
+ if (vm["request-mode"].as<std::string>() == "user") {
+ std::cout << "Request mode was set to user." << std::endl;
+ return ci::RequestMode::USER;
+ }
+ std::cout << "Cannot set request mode to "
+ << vm["request-mode"].as<std::string>() << std::endl;
+ std::cout << "Request mode was set to global." << std::endl;
+ return ci::RequestMode::GLOBAL;
+
+ }
+}
const uid_t kGlobalUserUid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
const uid_t kGlobalUserGid = tzplatform_getgid(TZ_SYS_GLOBALAPP_USER);
const uid_t kDefaultUserUid = tzplatform_getuid(TZ_SYS_DEFAULT_USER);
-const uid_t kTestUserId = kGlobalUserUid;
-const gid_t kTestGroupId = kGlobalUserGid;
+uid_t kTestUserId = kGlobalUserUid;
+gid_t kTestGroupId = kGlobalUserGid;
+std::string kTestUserIdStr = std::to_string(kTestUserId);
+const char kNormalUserName[] = "smokeuser";
const char kSystemShareGroupName[] = "system_share";
-const std::string& kTestUserIdStr =
- std::to_string(kTestUserId);
const std::string& kDefaultUserIdStr = std::to_string(kDefaultUserUid);
const char kLegacyExtImageDir[] = "legacy_extimage_dir";
const char kMigrateTestDBName[] = "app2sd_migrate.db";
const bf::path kSmokePackagesDirectory =
"/usr/share/wgt-backend-ut/test_samples/smoke/";
+enum RWDirectory {
+ DATA,
+ CACHE,
+ SHARED_CACHE,
+ SHARED_DATA,
+ SHARED_TRUSTED
+};
+
+const char* rwDirectories[] = {
+ "data",
+ "cache",
+ "shared/cache",
+ "shared/data",
+ "shared/trusted",
+};
+
// common entries
const std::vector<std::string> kDBEntries = {
{".pkgmgr_parser.db"},
// globaluser entries
const char kGlobalManifestDir[] = "/opt/share/packages";
const char kSkelDir[] = "/etc/skel/apps_rw";
+const char kPreloadApps[] = "/usr/apps";
+const char kPreloadManifestDir[] = "/usr/share/packages";
+const char kPreloadIcons[] = "/usr/share/icons";
enum class RequestResult {
NORMAL,
return true;
}
+bool AddUser(const char *user_name) {
+ GumUser* user = nullptr;
+ user = gum_user_create_sync(FALSE);
+ if (user == nullptr)
+ LOG(WARNING) << "Failed to create gum user! (user name: "
+ << user_name << ")";
+ g_object_set(G_OBJECT(user), "username", user_name, "usertype",
+ GUM_USERTYPE_NORMAL, NULL);
+ gboolean rval = FALSE;
+ rval = gum_user_add_sync(user);
+ g_object_unref(user);
+ return rval;
+}
+
+bool DeleteUser(const char *user_name, bool rem_home_dir) {
+ bool rval = FALSE;
+ GumUser* guser = gum_user_get_by_name_sync(user_name, FALSE);
+ if(guser)
+ rval = gum_user_delete_sync(guser, rem_home_dir);
+ return rval;
+}
+
+bool AddTestUser(const char *user_name) {
+ std::cout << "Adding test user: " << user_name << std::endl;
+ bool ret = AddUser(user_name);
+ if (boost::optional<uid_t> uid = ci::GetUidByUserName(user_name)) {
+ kTestUserId = *uid;
+ kTestUserIdStr = std::to_string(kTestUserId);
+ std::cout << "User created properly: uid=" << *uid;
+ if (boost::optional<gid_t> gid = ci::GetGidByUid(*uid)) {
+ kTestGroupId = *gid;
+ std::cout << " gid=" << *gid;
+ }
+ std::cout << std::endl;
+ return true;
+ }
+ LOG(ERROR) << "Adding test user failed";
+ return false;
+}
+
+bool DeleteTestUser(const char *user_name) {
+ std::cout << "Deleting test user: " << user_name << std::endl;
+ uid_t test_uid;
+ if (boost::optional<uid_t> uid = ci::GetUidByUserName(user_name))
+ test_uid = *uid;
+ bool ret = DeleteUser(user_name, true);
+ if (boost::optional<uid_t> uid = ci::GetUidByUserName(user_name));
+ else {
+ std::cout << "User deleted properly: user_name=" << user_name
+ << " uid=" << test_uid << std::endl;
+ return true;
+ }
+ LOG(ERROR) << "Deleting test user failed";
+ return false;
+}
+
void RemoveAllRecoveryFiles() {
bf::path root_path = ci::GetRootAppPath(false,
kTestUserId);
for (auto& dir_entry : boost::make_iterator_range(
bf::directory_iterator(root_path), bf::directory_iterator())) {
if (bf::is_regular_file(dir_entry)) {
- if (dir_entry.path().string().find("/recovery") != std::string::npos) {
+ if (dir_entry.path().string().find("/wgt-recovery")
+ != std::string::npos) {
bs::error_code error;
bf::remove(dir_entry.path(), error);
}
for (auto& dir_entry : boost::make_iterator_range(
bf::directory_iterator(root_path), bf::directory_iterator())) {
if (bf::is_regular_file(dir_entry)) {
- if (dir_entry.path().string().find("/recovery") != std::string::npos) {
+ if (dir_entry.path().string().find("/wgt-recovery")
+ != std::string::npos) {
return dir_entry.path();
}
}
bool ValidateFileContentInPackage(const std::string& pkgid,
const std::string& relative,
- const std::string& expected) {
- bf::path file_path = GetPackageRoot(pkgid, kTestUserId) / relative;
+ const std::string& expected,
+ bool is_readonly = false) {
+ bf::path file_path = ci::GetRootAppPath(is_readonly, kTestUserId);
+ file_path = file_path / pkgid / relative;
if (!bf::exists(file_path)) {
LOG(ERROR) << file_path << " doesn't exist";
return false;
void ValidatePackageRWFS(const std::string& pkgid, uid_t uid) {
bf::path root_path = ci::GetRootAppPath(false, uid);
bf::path package_path = root_path / pkgid;
- bf::path data_path = package_path / "data";
- bf::path cache_path = package_path / "cache";
- bf::path shared_data_path = package_path / "shared" / "data";
+ bf::path data_path = package_path / rwDirectories[DATA];
+ bf::path cache_path = package_path / rwDirectories[CACHE];
+ bf::path shared_data_path = package_path / rwDirectories[SHARED_DATA];
ASSERT_TRUE(bf::exists(data_path));
ASSERT_TRUE(bf::exists(cache_path));
void ValidatePackageFS(const std::string& pkgid,
const std::vector<std::string>& appids,
- uid_t uid, gid_t gid) {
- bf::path root_path = ci::GetRootAppPath(false, uid);
- bf::path package_path = GetPackageRoot(pkgid, uid);
+ uid_t uid, gid_t gid, bool is_readonly) {
+ bf::path root_path = ci::GetRootAppPath(is_readonly, uid);
+ bf::path package_path = root_path / pkgid;
bf::path shared_path = package_path / "shared";
ASSERT_TRUE(bf::exists(root_path));
ASSERT_TRUE(bf::exists(package_path));
ASSERT_TRUE(bf::exists(shared_path));
bf::path manifest_path =
- bf::path(getUserManifestPath(uid, false)) / (pkgid + ".xml");
+ bf::path(getUserManifestPath(uid, is_readonly)) / (pkgid + ".xml");
ASSERT_TRUE(bf::exists(manifest_path));
for (auto& appid : appids) {
iter != bf::recursive_directory_iterator(); ++iter) {
if (bf::is_symlink(symlink_status(iter->path())))
continue;
- if (iter->path().filename() == "data" ||
- iter->path().filename() == ".mmc")
+ bool is_rw_dir = false;
+ for(const auto rw_dir : rwDirectories) {
+ bf::path rw_dir_path = rw_dir;
+ is_rw_dir |= ci::MakeRelativePath(iter->path(), package_path) == rw_dir_path;
+ }
+ if (is_rw_dir || iter->path().filename() == ".mmc") {
+ iter.no_push();
continue;
+ }
struct stat stats;
stat(iter->path().c_str(), &stats);
ASSERT_EQ(uid, stats.st_uid) << "Invalid uid: " << iter->path();
}
void PackageCheckCleanup(const std::string& pkgid,
- const std::vector<std::string>&) {
- bf::path package_path = GetPackageRoot(pkgid, kTestUserId);
+ const std::vector<std::string>&, bool is_readonly = false) {
+ bf::path root_path = ci::GetRootAppPath(is_readonly, kTestUserId);
+ bf::path package_path = root_path / pkgid;
ASSERT_FALSE(bf::exists(package_path));
- bf::path manifest_path =
- bf::path(getUserManifestPath(
- kTestUserId, false)) / (pkgid + ".xml");
+ bf::path manifest_path = bf::path(getUserManifestPath(kTestUserId,
+ is_readonly)) / (pkgid + ".xml");
ASSERT_FALSE(bf::exists(manifest_path));
// backups should not exist
}
void ValidatePackage(const std::string& pkgid,
- const std::vector<std::string>& appids) {
+ const std::vector<std::string>& appids, bool is_readonly = false) {
ASSERT_TRUE(ci::QueryIsPackageInstalled(
- pkgid, ci::GetRequestMode(kTestUserId),
- kTestUserId));
- ValidatePackageFS(pkgid, appids, kTestUserId, kTestGroupId);
+ pkgid, ci::GetRequestMode(kTestUserId), kTestUserId));
+ ValidatePackageFS(pkgid, appids, kTestUserId, kTestGroupId, is_readonly);
if (kTestUserId == kGlobalUserUid) {
ci::UserList list = ci::GetUserList();
for (auto& l : list)
ASSERT_EQ(app2ext_usr_enable_external_pkg(pkgid.c_str(), uid), 0);
bf::path root_path = ci::GetRootAppPath(false, uid);
ASSERT_TRUE(bf::exists(root_path / pkgid / ".mmc" / "res"));
- ValidatePackageFS(pkgid, appids, uid, gid);
+ ValidatePackageFS(pkgid, appids, uid, gid, false);
ASSERT_EQ(app2ext_usr_disable_external_pkg(pkgid.c_str(), uid), 0);
}
pkgid, ci::GetRequestMode(kTestUserId),
kTestUserId));
PackageCheckCleanup(pkgid, appids);
+ if (kTestUserId == kGlobalUserUid) {
+ ci::UserList list = ci::GetUserList();
+ bf::path skel_path(kSkelDir);
+ ASSERT_FALSE(bf::exists(skel_path / pkgid));
+ for (auto& l : list) {
+ bf::path root_path = ci::GetRootAppPath(false, std::get<0>(l));
+ bf::path package_path = root_path / pkgid;
+ ASSERT_FALSE(bf::exists(package_path));
+ }
+ }
+}
+
+void CheckPackageReadonlyNonExistance(const std::string& pkgid,
+ const std::vector<std::string>& appids) {
+ ASSERT_FALSE(ci::QueryIsPackageInstalled(
+ pkgid, ci::GetRequestMode(kTestUserId), kTestUserId));
+ PackageCheckCleanup(pkgid, appids, true);
}
std::unique_ptr<ci::AppQueryInterface> CreateQueryInterface() {
return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
}
+ci::AppInstaller::Result InstallPreload(const bf::path& path, PackageType type,
+ RequestResult mode = RequestResult::NORMAL) {
+ const char* argv[] = {"", "-i", path.c_str(), "--preload"};
+ return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
+}
+
bool CheckAvailableExternalPath() {
bf::path ext_mount_path = ci::GetExternalCardPath();
LOG(DEBUG) << "ext_mount_path :" << ext_mount_path;
ci::AppInstaller::Result Uninstall(const std::string& pkgid,
PackageType type,
+ bool is_preload,
RequestResult mode = RequestResult::NORMAL) {
- const char* argv[] = {"", "-d", pkgid.c_str(), "-u", kTestUserIdStr.c_str()};
- return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
+ if (is_preload) {
+ const char* argv[] = {"", "-d", pkgid.c_str(), "--preload",
+ "--force-remove"};
+ return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
+ } else {
+ const char* argv[] = {"", "-d", pkgid.c_str(), "-u",
+ kTestUserIdStr.c_str()};
+ return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
+ }
}
ci::AppInstaller::Result RDSUpdate(const bf::path& path,
RequestResult mode = RequestResult::NORMAL) {
const char* argv[] = {"", "-b", recovery_file.c_str(), "-u",
kTestUserIdStr.c_str()};
- TestPkgmgrInstaller pkgmgr_installer;
- std::unique_ptr<ci::AppQueryInterface> query_interface =
- CreateQueryInterface();
- auto pkgmgr =
- ci::PkgMgrInterface::Create(SIZEOFARRAY(argv), const_cast<char**>(argv),
- &pkgmgr_installer, query_interface.get());
- if (!pkgmgr) {
- LOG(ERROR) << "Failed to initialize pkgmgr interface";
- return ci::AppInstaller::Result::UNKNOWN;
- }
- return RunInstallerWithPkgrmgr(pkgmgr, type, mode);
+ return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
}
void BackupPath(const bf::path& path) {
}
}
-std::vector<bf::path> SetupBackupDirectories(uid_t uid) {
+std::vector<bf::path> SetupBackupDirectories() {
std::vector<bf::path> entries;
bf::path db_dir = bf::path(tzplatform_getenv(TZ_SYS_DB));
- if (uid != kGlobalUserUid)
- db_dir = db_dir / "user" / std::to_string(uid);
+ if (kTestUserId != kGlobalUserUid)
+ db_dir = db_dir / "user" / std::to_string(kTestUserId);
for (auto e : kDBEntries) {
bf::path path = db_dir / e;
entries.emplace_back(path);
}
- if (uid == kGlobalUserUid) {
+ if (getuid() == 0) {
+ entries.emplace_back(kPreloadApps);
+ entries.emplace_back(kPreloadManifestDir);
+ entries.emplace_back(kPreloadIcons);
+ }
+
+ if (kTestUserId == kGlobalUserUid) {
entries.emplace_back(kSkelDir);
entries.emplace_back(kGlobalManifestDir);
ci::UserList list = ci::GetUserList();
entries.emplace_back(apps);
}
} else {
- tzplatform_set_user(uid);
+ tzplatform_set_user(kTestUserId);
bf::path approot = tzplatform_getenv(TZ_USER_APPROOT);
tzplatform_reset_user();
entries.emplace_back(approot);
}
- bf::path apps_rw = ci::GetRootAppPath(false, uid);
+ bf::path apps_rw = ci::GetRootAppPath(false, kTestUserId);
entries.emplace_back(apps_rw);
return entries;
}
+void UninstallAllAppsInDirectory(bf::path dir, bool is_preload) {
+ if(bf::exists(dir)) {
+ for (auto& dir_entry : boost::make_iterator_range(
+ bf::directory_iterator(dir), bf::directory_iterator())) {
+ if (dir_entry.path().string().find("smoke") != std::string::npos &&
+ bf::is_directory(dir_entry)) {
+ std::string package = dir_entry.path().filename().string();
+ std::regex pkg_regex("smoke[a-zA-Z]{3,}[1-9]{2,}");
+ if (std::regex_match(package, pkg_regex)) {
+ if(Uninstall(dir_entry.path().filename().string(), PackageType::WGT,
+ is_preload, RequestResult::NORMAL) !=
+ ci::AppInstaller::Result::OK) {
+ LOG(ERROR) << "Cannot uninstall smoke test app: "
+ << dir_entry.path().filename().string();
+ }
+ }
+ }
+ }
+ }
+}
+
+void UninstallAllSmokeApps(ci::RequestMode request_mode) {
+ if (getuid() == 0 && request_mode == ci::RequestMode::GLOBAL) {
+ bf::path root_path = kPreloadApps;
+ UninstallAllAppsInDirectory(root_path, true);
+ }
+ bf::path apps_rw = ci::GetRootAppPath(false, kTestUserId);
+ UninstallAllAppsInDirectory(apps_rw, false);
+}
+
} // namespace
namespace common_installer {
class SmokeEnvironment : public testing::Environment {
public:
- explicit SmokeEnvironment(uid_t uid) : uid_(uid) {
+ explicit SmokeEnvironment(ci::RequestMode mode) {\
+ request_mode_ = mode;
}
void SetUp() override {
- backups_ = SetupBackupDirectories(uid_);
+ if (request_mode_ == ci::RequestMode::USER)
+ ASSERT_TRUE(AddTestUser(kNormalUserName));
+ else {
+ kTestUserId = kGlobalUserUid;
+ kTestGroupId = kGlobalUserGid;
+ kTestUserIdStr = std::to_string(kTestUserId);
+ }
+ backups_ = SetupBackupDirectories();
for (auto& path : backups_)
BackupPath(path);
}
void TearDown() override {
- // TODO(s89.jang): Uninstall smoke packages to clear security context
+ ASSERT_TRUE(request_mode_ == ci::RequestMode::GLOBAL ||
+ (request_mode_ == ci::RequestMode::USER &&
+ kGlobalUserUid != kTestUserId));
+ UninstallAllSmokeApps(request_mode_);
for (auto& path : backups_)
RestorePath(path);
+ if (request_mode_ == ci::RequestMode::USER)
+ ASSERT_TRUE(DeleteTestUser(kNormalUserName));
}
private:
- uid_t uid_;
+ ci::RequestMode request_mode_;
std::vector<bf::path> backups_;
};
class SmokeTest : public testing::Test {
};
+class PreloadSmokeTest : public testing::Test {
+ void SetUp() override {
+ ASSERT_EQ(kGlobalUserUid, kTestUserId);
+ }
+};
+
TEST_F(SmokeTest, InstallationMode) {
bf::path path = kSmokePackagesDirectory / "InstallationMode.wgt";
- std::string pkgid = "smokeapp03";
- std::string appid = "smokeapp03.InstallationMode";
+ std::string pkgid = "smokewgt03";
+ std::string appid = "smokewgt03.InstallationMode";
ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
ValidatePackage(pkgid, {appid});
}
TEST_F(SmokeTest, UpdateMode) {
bf::path path_old = kSmokePackagesDirectory / "UpdateMode.wgt";
bf::path path_new = kSmokePackagesDirectory / "UpdateMode_2.wgt";
- std::string pkgid = "smokeapp04";
- std::string appid = "smokeapp04.UpdateMode";
+ std::string pkgid = "smokewgt04";
+ std::string appid = "smokewgt04.UpdateMode";
ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
AddDataFiles(pkgid, kTestUserId);
ASSERT_EQ(Install(path_new, PackageType::WGT), ci::AppInstaller::Result::OK);
TEST_F(SmokeTest, DeinstallationMode) {
bf::path path = kSmokePackagesDirectory / "DeinstallationMode.wgt";
- std::string pkgid = "smokeapp05";
- std::string appid = "smokeapp05.DeinstallationMode";
+ std::string pkgid = "smokewgt05";
+ std::string appid = "smokewgt05.DeinstallationMode";
ASSERT_EQ(Install(path, PackageType::WGT),
ci::AppInstaller::Result::OK);
- ASSERT_EQ(Uninstall(pkgid, PackageType::WGT), ci::AppInstaller::Result::OK);
+ ASSERT_EQ(Uninstall(pkgid, PackageType::WGT, false),
+ ci::AppInstaller::Result::OK);
CheckPackageNonExistance(pkgid, {appid});
}
TEST_F(SmokeTest, RDSMode) {
bf::path path = kSmokePackagesDirectory / "RDSMode.wgt";
- std::string pkgid = "smokeapp11";
- std::string appid = "smokeapp11.RDSMode";
+ std::string pkgid = "smokewgt11";
+ std::string appid = "smokewgt11.RDSMode";
bf::path delta_directory = kSmokePackagesDirectory / "delta_dir/";
bf::path sdk_expected_directory =
bf::path(ci::GetRootAppPath(false, kTestUserId)) / "tmp" / pkgid;
TEST_F(SmokeTest, EnablePkg) {
bf::path path = kSmokePackagesDirectory / "EnablePkg.wgt";
- std::string pkgid = "smokeapp22";
+ std::string pkgid = "smokewgt22";
ASSERT_EQ(Install(path, PackageType::WGT),
ci::AppInstaller::Result::OK);
ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
TEST_F(SmokeTest, DisablePkg) {
bf::path path = kSmokePackagesDirectory / "DisablePkg.wgt";
- std::string pkgid = "smokeapp21";
- std::string appid = "smokeapp21.DisablePkg";
+ std::string pkgid = "smokewgt21";
+ std::string appid = "smokewgt21.DisablePkg";
ASSERT_EQ(Install(path, PackageType::WGT),
ci::AppInstaller::Result::OK);
ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
TEST_F(SmokeTest, DeltaMode) {
bf::path path = kSmokePackagesDirectory / "DeltaMode.wgt";
bf::path delta_package = kSmokePackagesDirectory / "DeltaMode.delta";
- std::string pkgid = "smokeapp17";
- std::string appid = "smokeapp17.DeltaMode";
+ std::string pkgid = "smokewgt17";
+ std::string appid = "smokewgt17.DeltaMode";
ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::WGT),
ci::AppInstaller::Result::OK);
ValidatePackage(pkgid, {appid});
backend_crash.Run("-i", path.string(), "-u", kTestUserIdStr.c_str());
ASSERT_NE(backend_crash.Wait(), 0);
- std::string pkgid = "smokeapp09";
- std::string appid = "smokeapp09.RecoveryModeForInstallation";
+ std::string pkgid = "smokewgt09";
+ std::string appid = "smokewgt09.RecoveryModeForInstallation";
bf::path recovery_file = FindRecoveryFile();
ASSERT_FALSE(recovery_file.empty());
ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
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";
+ std::string pkgid = "smokewgt10";
+ std::string appid = "smokewgt10.RecoveryModeForUpdate";
AddDataFiles(pkgid, kTestUserId);
Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
backend_crash.Run("-i", path_new.string(), "-u", kTestUserIdStr.c_str());
backend_crash.Run("-i", path_new.string(), "-u", kTestUserIdStr.c_str());
ASSERT_NE(backend_crash.Wait(), 0);
- std::string pkgid = "smokeapp30";
- std::string appid = "smokeapp30.RecoveryModeForDelta";
+ std::string pkgid = "smokewgt30";
+ std::string appid = "smokewgt30.RecoveryModeForDelta";
bf::path recovery_file = FindRecoveryFile();
ASSERT_FALSE(recovery_file.empty());
ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
backend_crash.Run("-w", path.string(), "-u", kTestUserIdStr.c_str());
ASSERT_NE(backend_crash.Wait(), 0);
- std::string pkgid = "smokeapp31";
- std::string appid = "smokeapp31.RecoveryModeForMountInstall";
+ std::string pkgid = "smokewgt31";
+ std::string appid = "smokewgt31.RecoveryModeForMountInstall";
bf::path recovery_file = FindRecoveryFile();
ASSERT_FALSE(recovery_file.empty());
ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate.wgt";
bf::path path_new =
kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate_2.wgt";
- std::string pkgid = "smokeapp32";
- std::string appid = "smokeapp32.RecoveryModeForMountUpdate";
+ std::string pkgid = "smokewgt32";
+ std::string appid = "smokewgt32.RecoveryModeForMountUpdate";
RemoveAllRecoveryFiles();
ASSERT_EQ(MountInstall(path_old, PackageType::WGT),
ci::AppInstaller::Result::OK);
}
TEST_F(SmokeTest, InstallationMode_GoodSignature) {
+ // pkgid: smokewgt08
bf::path path = kSmokePackagesDirectory / "InstallationMode_GoodSignature.wgt"; // NOLINT
ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
}
TEST_F(SmokeTest, InstallationMode_WrongSignature) {
+ // pkgid: smokewgt12
bf::path path = kSmokePackagesDirectory / "InstallationMode_WrongSignature.wgt"; // NOLINT
ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::ERROR);
}
TEST_F(SmokeTest, InstallationMode_Rollback) {
bf::path path = kSmokePackagesDirectory / "InstallationMode_Rollback.wgt";
- std::string pkgid = "smokeapp06";
- std::string appid = "smokeapp06.InstallationModeRollback";
+ std::string pkgid = "smokewgt06";
+ std::string appid = "smokewgt06.InstallationModeRollback";
ASSERT_EQ(Install(path, PackageType::WGT, RequestResult::FAIL),
ci::AppInstaller::Result::ERROR);
CheckPackageNonExistance(pkgid, {appid});
TEST_F(SmokeTest, UpdateMode_Rollback) {
bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Rollback.wgt";
bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Rollback_2.wgt";
- std::string pkgid = "smokeapp07";
- std::string appid = "smokeapp07.UpdateModeRollback";
+ std::string pkgid = "smokewgt07";
+ std::string appid = "smokewgt07.UpdateModeRollback";
ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
AddDataFiles(pkgid, kTestUserId);
ASSERT_EQ(Install(path_new, PackageType::WGT, RequestResult::FAIL),
ValidateDataFiles(pkgid, kTestUserId);
}
+TEST_F(SmokeTest, DeltaMode_Rollback) {
+ bf::path path = kSmokePackagesDirectory / "DeltaMode_Rollback.wgt";
+ bf::path delta_package = kSmokePackagesDirectory / "DeltaMode_Rollback.delta";
+ std::string pkgid = "smokewgt01";
+ std::string appid = "smokewgt01.DeltaMode";
+ ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
+ AddDataFiles(pkgid, kTestUserId);
+ ASSERT_EQ(Install(delta_package, PackageType::WGT, RequestResult::FAIL),
+ ci::AppInstaller::Result::ERROR);
+
+ ValidatePackage(pkgid, {appid});
+ ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED",
+ "version 1\n"));
+ ValidateDataFiles(pkgid, kTestUserId);
+ ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
+ "res/wgt/DELETED"));
+ ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
+ "res/wgt/ADDED"));
+}
+
TEST_F(SmokeTest, InstallationMode_Hybrid) {
bf::path path = kSmokePackagesDirectory / "InstallationMode_Hybrid.wgt";
std::string pkgid = "smokehyb01";
std::string appid1 = "smokehyb03.Web";
ASSERT_EQ(Install(path, PackageType::HYBRID),
ci::AppInstaller::Result::OK);
- ASSERT_EQ(Uninstall(pkgid, PackageType::HYBRID),
+ ASSERT_EQ(Uninstall(pkgid, PackageType::HYBRID, false),
ci::AppInstaller::Result::OK);
CheckPackageNonExistance(pkgid, {appid1});
}
ValidateDataFiles(pkgid, kTestUserId);
}
+TEST_F(SmokeTest, DeltaMode_Rollback_Hybrid) {
+ bf::path path = kSmokePackagesDirectory / "DeltaMode_Rollback_Hybrid.wgt";
+ bf::path delta_package = kSmokePackagesDirectory /
+ "DeltaMode_Rollback_Hybrid.delta";
+ std::string pkgid = "smokehyb11";
+ std::string appid1 = "smokehyb11.web";
+ ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK);
+ AddDataFiles(pkgid, kTestUserId);
+ ASSERT_EQ(Install(delta_package, PackageType::HYBRID, RequestResult::FAIL),
+ ci::AppInstaller::Result::ERROR);
+
+ ValidatePackage(pkgid, {appid1});
+ // Check delta modifications
+ bf::path root_path = GetPackageRoot(pkgid, kTestUserId);
+ ASSERT_TRUE(bf::exists(root_path / "res" / "wgt" / "DELETED"));
+ ASSERT_FALSE(bf::exists(root_path / "res" / "wgt" / "ADDED"));
+ ASSERT_TRUE(bf::exists(root_path / "lib" / "DELETED"));
+ ASSERT_FALSE(bf::exists(root_path / "lib" / "ADDED"));
+ ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED",
+ "version 1\n"));
+ ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/MODIFIED",
+ "version 1\n"));
+ ValidateDataFiles(pkgid, kTestUserId);
+}
+
TEST_F(SmokeTest, MountInstallationMode_Rollback_Hybrid) {
bf::path path = kSmokePackagesDirectory /
"MountInstallationMode_Rollback_Hybrid.wgt";
TEST_F(SmokeTest, MountInstallationMode) {
bf::path path = kSmokePackagesDirectory / "MountInstallationMode.wgt";
- std::string pkgid = "smokeapp28";
- std::string appid = "smokeapp28.InstallationMode";
+ std::string pkgid = "smokewgt28";
+ std::string appid = "smokewgt28.InstallationMode";
ASSERT_EQ(MountInstall(path, PackageType::WGT), ci::AppInstaller::Result::OK);
ScopedTzipInterface interface(pkgid);
ValidatePackage(pkgid, {appid});
TEST_F(SmokeTest, MountUpdateMode) {
bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode.wgt";
bf::path path_new = kSmokePackagesDirectory / "MountUpdateMode_2.wgt";
- std::string pkgid = "smokeapp29";
- std::string appid = "smokeapp29.UpdateMode";
+ std::string pkgid = "smokewgt29";
+ std::string appid = "smokewgt29.UpdateMode";
ASSERT_EQ(MountInstall(path_old, PackageType::WGT),
ci::AppInstaller::Result::OK);
AddDataFiles(pkgid, kTestUserId);
TEST_F(SmokeTest, MountInstallationMode_Rollback) {
bf::path path =
kSmokePackagesDirectory / "MountInstallationMode_Rollback.wgt";
- std::string pkgid = "smokeapp33";
- std::string appid = "smokeapp33.web";
+ std::string pkgid = "smokewgt33";
+ std::string appid = "smokewgt33.web";
ASSERT_EQ(MountInstall(path, PackageType::WGT, RequestResult::FAIL),
ci::AppInstaller::Result::ERROR);
ScopedTzipInterface interface(pkgid);
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";
+ std::string pkgid = "smokewgt34";
+ std::string appid = "smokewgt34.web";
ASSERT_EQ(MountInstall(path_old, PackageType::WGT),
ci::AppInstaller::Result::OK);
AddDataFiles(pkgid, kTestUserId);
TEST_F(SmokeTest, UserDefinedPlugins) {
bf::path path = kSmokePackagesDirectory / "SimpleEchoPrivilege.wgt";
- std::string pkgid = "0CSPVhKmRk";
- std::string appid = "0CSPVhKmRk.SimpleEcho";
+ std::string pkgid = "smokewgt02";
+ std::string appid = "smokewgt02.SimpleEcho";
std::string call_privilege = "http://tizen.org/privilege/call";
std::string location_privilege = "http://tizen.org/privilege/location";
std::string power_privilege = "http://tizen.org/privilege/power";
TEST_F(SmokeTest, InstallExternalMode) {
ASSERT_TRUE(CheckAvailableExternalPath());
bf::path path = kSmokePackagesDirectory / "InstallExternalMode.wgt";
- std::string pkgid = "smokeapp35";
- std::string appid = "smokeapp35.web";
+ std::string pkgid = "smokewgt35";
+ std::string appid = "smokewgt35.web";
ASSERT_EQ(InstallExternal(path, PackageType::WGT),
ci::AppInstaller::Result::OK);
ValidateExternalPackage(pkgid, {appid});
ASSERT_TRUE(CheckAvailableExternalPath());
bf::path path =
kSmokePackagesDirectory / "MigrateLegacyExternalImageMode.wgt";
- std::string pkgid = "smokeapp36";
- std::string appid = "smokeapp36.web";
+ std::string pkgid = "smokewgt36";
+ std::string appid = "smokewgt36.web";
bf::path legacy_path = kSmokePackagesDirectory / kLegacyExtImageDir;
ASSERT_EQ(MigrateLegacyExternalImage(pkgid, path, legacy_path,
PackageType::WGT), ci::AppInstaller::Result::OK);
ValidateExternalPackage(pkgid, {appid});
}
+TEST_F(PreloadSmokeTest, InstallationMode_Preload) {
+ ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
+ bf::path path = kSmokePackagesDirectory / "InstallationMode_Preload.wgt";
+ std::string pkgid = "smokewgt37";
+ std::string appid = "smokewgt37.InstallationModePreload";
+ ASSERT_EQ(InstallPreload(path, PackageType::WGT),
+ ci::AppInstaller::Result::OK);
+ ValidatePackage(pkgid, {appid}, true);
+}
+
+TEST_F(PreloadSmokeTest, UpdateMode_Preload) {
+ ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
+ bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Preload.wgt";
+ bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Preload2.wgt";
+ std::string pkgid = "smokewgt38";
+ std::string appid = "smokewgt38.UpdateModePreload";
+ ASSERT_EQ(InstallPreload(path_old, PackageType::WGT),
+ ci::AppInstaller::Result::OK);
+ AddDataFiles(pkgid, kTestUserId);
+ ASSERT_EQ(InstallPreload(path_new, PackageType::WGT),
+ ci::AppInstaller::Result::OK);
+ ValidatePackage(pkgid, {appid}, true);
+
+ ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2",
+ true));
+ ValidateDataFiles(pkgid, kTestUserId);
+}
+
+TEST_F(PreloadSmokeTest, DeinstallationMode_Preload) {
+ ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
+ bf::path path = kSmokePackagesDirectory / "DeinstallationMode_Preload.wgt";
+ std::string pkgid = "smokewgt39";
+ std::string appid = "smokewgt39.DeinstallationModePreload";
+ ASSERT_EQ(InstallPreload(path, PackageType::WGT),
+ ci::AppInstaller::Result::OK);
+ ASSERT_EQ(Uninstall(pkgid, PackageType::WGT, true),
+ ci::AppInstaller::Result::OK);
+ CheckPackageReadonlyNonExistance(pkgid, {appid});
+}
+
+TEST_F(SmokeTest, SharedRes24) {
+ bf::path path = kSmokePackagesDirectory / "SharedRes24.wgt";
+ std::string pkgid = "smokeSh2xx";
+ std::string appid = "smokeSh2xx.SharedRes24";
+ ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
+ ValidatePackage(pkgid, {appid});
+ bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
+ ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "NOT-SHARED-WGT")); // NOLINT
+ ASSERT_FALSE(bf::exists(root_path / pkgid / "shared" / "res" / "NOT-SHARED-WGT")); // NOLINT
+}
+
+TEST_F(SmokeTest, SharedRes30) {
+ bf::path path = kSmokePackagesDirectory / "SharedRes30.wgt";
+ std::string pkgid = "smokeSh3xx";
+ std::string appid = "smokeSh3xx.SharedRes30";
+ ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
+ ValidatePackage(pkgid, {appid});
+ bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
+ ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT")); // NOLINT
+ ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "shared" / "res" / "SHARED-WGT")); // NOLINT
+}
+
+TEST_F(SmokeTest, SharedRes30Delta) {
+ bf::path path = kSmokePackagesDirectory / "SharedRes30Delta.wgt";
+ bf::path delta_package = kSmokePackagesDirectory / "SharedRes30Delta.delta";
+ std::string pkgid = "smokeSh3De";
+ std::string appid = "smokeSh3De.SharedRes30Delta";
+ ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::WGT),
+ ci::AppInstaller::Result::OK);
+ ValidatePackage(pkgid, {appid});
+ // Check delta modifications
+ bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
+ ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-2")); // NOLINT
+ ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "shared" / "res" / "SHARED-WGT-2")); // NOLINT
+ ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-1")); // NOLINT
+ ASSERT_FALSE(bf::exists(root_path / pkgid / "shared" / "res" / "SHARED-WGT-1")); // NOLINT
+}
+
+TEST_F(SmokeTest, SharedRes30Hybrid) {
+ bf::path path = kSmokePackagesDirectory / "SharedRes30Hybrid.wgt";
+ std::string pkgid = "smokeSh3Hy";
+ std::string appid1 = "smokeSh3Hy.SharedRes30Hybrid";
+ std::string appid2 = "sharedres30hybridserivce";
+ ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK);
+ ValidatePackage(pkgid, {appid1, appid2});
+ bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
+ ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT")); // NOLINT
+ ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "shared" / "res" / "SHARED-WGT")); // NOLINT
+ ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "shared" / "res" / "SHARED-TPK")); // NOLINT
+ ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-TPK")); // NOLINT
+}
+
+TEST_F(SmokeTest, SharedRes30HybridDelta) {
+ bf::path path = kSmokePackagesDirectory / "SharedRes30HybridDelta.wgt";
+ bf::path delta_package = kSmokePackagesDirectory / "SharedRes30HybridDelta.delta";
+ std::string pkgid = "smokeSh3HD";
+ std::string appid1 = "smokeSh3HD.SharedRes30HybridDelta";
+ std::string appid2 = "sharedres30hybriddeltaserivce";
+ ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::HYBRID),
+ ci::AppInstaller::Result::OK);
+ ValidatePackage(pkgid, {appid1, appid2});
+ // Check delta modifications
+ bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
+ ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-2")); // NOLINT
+ ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "shared" / "res" / "SHARED-WGT-2")); // NOLINT
+ ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "shared" / "res" / "SHARED-TPK-2")); // NOLINT
+ ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-TPK-2")); // NOLINT
+ ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-1")); // NOLINT
+ ASSERT_FALSE(bf::exists(root_path / pkgid / "shared" / "res" / "SHARED-WGT-1")); // NOLINT
+}
+
} // namespace common_installer
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
- testing::AddGlobalTestEnvironment(
- new common_installer::SmokeEnvironment(kGlobalUserUid));
+ testing::Environment *env = testing::AddGlobalTestEnvironment(
+ new common_installer::SmokeEnvironment(ParseRequestMode(argc, argv)));
return RUN_ALL_TESTS();
}