#include <boost/filesystem/path.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/system/error_code.hpp>
-#include <boost/format.hpp>
#include <common/paths.h>
#include <common/pkgmgr_interface.h>
#include <tzplatform_config.h>
#include <vconf.h>
#include <vconf-internal-keys.h>
-#include <getopt.h>
#include <array>
#include <cstdio>
namespace ci = common_installer;
namespace {
-ci::RequestMode kRequestMode = ci::RequestMode::GLOBAL;
-const char *short_opts = "g:u";
-const struct option long_opts[] = {
- { "request_mode", 1, NULL, 'r' },
- { 0, 0, 0, 0 } /* sentinel */
-};
-const char *request_modes[] {
- "global",
- "user"
-};
-void ParseRequestMode(int argc, char** argv) {
- int c;
- int opt_idx = 0;
- do {
- c = getopt_long(argc, argv, short_opts, long_opts, &opt_idx);
- switch (c) {
- case 'r':
- if (strncmp(optarg, request_modes[0], strlen(request_modes[0])) == 0)
- kRequestMode = ci::RequestMode::GLOBAL;
- else if (strncmp(optarg, request_modes[1], strlen(request_modes[1])) == 0)
- kRequestMode = ci::RequestMode::USER;
- else
- LOG(ERROR) << "Wrong request mode " << optarg
- << ". Available: \"global\" or \"user\"";
- break;
- case 'g':
- kRequestMode = ci::RequestMode::GLOBAL;
- break;
- case 'u':
- kRequestMode = ci::RequestMode::USER;
- break;
- default:
- break;
- }
- } while (c != -1);
-}
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);
-uid_t kTestUserId = kGlobalUserUid;
-gid_t kTestGroupId = kGlobalUserGid;
-std::string kTestUserIdStr = std::to_string(kTestUserId);
-const char kNormalUserName[] = "smokeuser";
+const uid_t kTestUserId = kGlobalUserUid;
+const gid_t kTestGroupId = kGlobalUserGid;
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";
return true;
}
-bool AddTestUser(const char *user_name) {
- std::cout << "Adding test user: " << user_name << std::endl;
- gboolean ret = ci::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;
- gboolean ret = ci::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();
}
}
}
}
-std::vector<bf::path> SetupBackupDirectories() {
+std::vector<bf::path> SetupBackupDirectories(uid_t uid) {
std::vector<bf::path> entries;
bf::path db_dir = bf::path(tzplatform_getenv(TZ_SYS_DB));
- if (kTestUserId != kGlobalUserUid)
- db_dir = db_dir / "user" / std::to_string(kTestUserId);
+ if (uid != kGlobalUserUid)
+ db_dir = db_dir / "user" / std::to_string(uid);
for (auto e : kDBEntries) {
bf::path path = db_dir / e;
entries.emplace_back(path);
entries.emplace_back(kPreloadIcons);
}
- if (kTestUserId == kGlobalUserUid) {
+ if (uid == kGlobalUserUid) {
entries.emplace_back(kSkelDir);
entries.emplace_back(kGlobalManifestDir);
ci::UserList list = ci::GetUserList();
entries.emplace_back(apps);
}
} else {
- tzplatform_set_user(kTestUserId);
+ tzplatform_set_user(uid);
bf::path approot = tzplatform_getenv(TZ_USER_APPROOT);
tzplatform_reset_user();
entries.emplace_back(approot);
}
- bf::path apps_rw = ci::GetRootAppPath(false, kTestUserId);
+ bf::path apps_rw = ci::GetRootAppPath(false, uid);
entries.emplace_back(apps_rw);
return entries;
}
}
-void UninstallAllSmokeApps() {
- if (getuid() == 0 && kRequestMode == ci::RequestMode::GLOBAL) {
+void UninstallAllSmokeApps(uid_t uid) {
+ if (getuid() == 0) {
bf::path root_path = kPreloadApps;
UninstallAllAppsInDirectory(root_path, true);
}
- bf::path apps_rw = ci::GetRootAppPath(false, kTestUserId);
+ bf::path apps_rw = ci::GetRootAppPath(false, uid);
UninstallAllAppsInDirectory(apps_rw, false);
}
class SmokeEnvironment : public testing::Environment {
public:
- explicit SmokeEnvironment() {
+ explicit SmokeEnvironment(uid_t uid) : uid_(uid) {
}
void SetUp() override {
- if (kRequestMode == ci::RequestMode::USER)
- ASSERT_TRUE(AddTestUser(kNormalUserName));
- else {
- kTestUserId = kGlobalUserUid;
- kTestGroupId = kGlobalUserGid;
- kTestUserIdStr = std::to_string(kTestUserId);
- }
- backups_ = SetupBackupDirectories();
+ backups_ = SetupBackupDirectories(uid_);
for (auto& path : backups_)
BackupPath(path);
}
void TearDown() override {
- ASSERT_TRUE(kRequestMode == ci::RequestMode::GLOBAL ||
- (kRequestMode == ci::RequestMode::USER &&
- kGlobalUserUid != kTestUserId));
- UninstallAllSmokeApps();
+ UninstallAllSmokeApps(uid_);
for (auto& path : backups_)
RestorePath(path);
- if (kRequestMode == ci::RequestMode::USER)
- ASSERT_TRUE(DeleteTestUser(kNormalUserName));
}
private:
+ uid_t uid_;
std::vector<bf::path> backups_;
};
class SmokeTest : public testing::Test {
};
-class PreloadSmokeTest : public testing::Test {
- void SetUp() override {
- ASSERT_TRUE(kRequestMode == ci::RequestMode::GLOBAL);
- }
-};
-
TEST_F(SmokeTest, InstallationMode) {
bf::path path = kSmokePackagesDirectory / "InstallationMode.wgt";
std::string pkgid = "smokewgt03";
}
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);
}
ValidateExternalPackage(pkgid, {appid});
}
-TEST_F(PreloadSmokeTest, InstallationMode_Preload) {
+TEST_F(SmokeTest, InstallationMode_Preload) {
ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
bf::path path = kSmokePackagesDirectory / "InstallationMode_Preload.wgt";
std::string pkgid = "smokewgt37";
ValidatePackage(pkgid, {appid}, true);
}
-TEST_F(PreloadSmokeTest, UpdateMode_Preload) {
+TEST_F(SmokeTest, 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";
ValidateDataFiles(pkgid, kTestUserId);
}
-TEST_F(PreloadSmokeTest, DeinstallationMode_Preload) {
+TEST_F(SmokeTest, DeinstallationMode_Preload) {
ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
bf::path path = kSmokePackagesDirectory / "DeinstallationMode_Preload.wgt";
std::string pkgid = "smokewgt39";
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
- testing::Environment *env = testing::AddGlobalTestEnvironment(
- new common_installer::SmokeEnvironment());
- ParseRequestMode(argc, argv);
+ testing::AddGlobalTestEnvironment(
+ new common_installer::SmokeEnvironment(kGlobalUserUid));
return RUN_ALL_TESTS();
}