namespace {
+const uid_t kTestUserId = tzplatform_getuid(TZ_SYS_DEFAULT_USER);
+const std::string kTestUserIdStr =
+ std::to_string(kTestUserId);
+
const bf::path kSmokePackagesDirectory =
"/usr/share/tpk-backend-ut/test_samples/smoke/";
public:
explicit ScopedTzipInterface(const std::string& pkgid)
: pkg_path_(bf::path(ci::GetRootAppPath(false,
- tzplatform_getuid(TZ_SYS_DEFAULT_USER))) / pkgid),
+ kTestUserId)) / pkgid),
interface_(ci::GetMountLocation(pkg_path_)) {
interface_.MountZip(ci::GetZipPackageLocation(pkg_path_, pkgid));
}
void RemoveAllRecoveryFiles() {
bf::path root_path = ci::GetRootAppPath(false,
- tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+ kTestUserId);
if (!bf::exists(root_path))
return;
for (auto& dir_entry : boost::make_iterator_range(
bf::path FindRecoveryFile() {
bf::path root_path = ci::GetRootAppPath(false,
- tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+ kTestUserId);
for (auto& dir_entry : boost::make_iterator_range(
bf::directory_iterator(root_path), bf::directory_iterator())) {
if (bf::is_regular_file(dir_entry)) {
const std::string& relative,
const std::string& expected) {
bf::path root_path = ci::GetRootAppPath(false,
- tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+ kTestUserId);
bf::path file_path = root_path / pkgid / relative;
if (!bf::exists(file_path)) {
LOG(ERROR) << file_path << " doesn't exist";
void ValidatePackageFS(const std::string& pkgid, const std::string& appid) {
bf::path root_path = ci::GetRootAppPath(false,
- tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+ kTestUserId);
bf::path package_path = root_path / pkgid;
bf::path binary_path = package_path / "bin" / appid;
bf::path data_path = package_path / "data";
bf::path manifest_path =
bf::path(getUserManifestPath(
- tzplatform_getuid(TZ_SYS_DEFAULT_USER), false)) / (pkgid + ".xml");
+ kTestUserId, false)) / (pkgid + ".xml");
ASSERT_TRUE(bf::exists(manifest_path));
// backups should not exist
void PackageCheckCleanup(const std::string& pkgid, const std::string&) {
bf::path root_path = ci::GetRootAppPath(false,
- tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+ kTestUserId);
bf::path package_path = root_path / pkgid;
ASSERT_FALSE(bf::exists(package_path));
bf::path manifest_path =
bf::path(getUserManifestPath(
- tzplatform_getuid(TZ_SYS_DEFAULT_USER), false)) / (pkgid + ".xml");
+ kTestUserId, false)) / (pkgid + ".xml");
ASSERT_FALSE(bf::exists(manifest_path));
// backups should not exist
void ValidatePackage(const std::string& pkgid, const std::string& appid) {
ASSERT_TRUE(ci::QueryIsPackageInstalled(
- pkgid, ci::GetRequestMode(tzplatform_getuid(TZ_SYS_DEFAULT_USER)),
- tzplatform_getuid(TZ_SYS_DEFAULT_USER)));
+ pkgid, ci::GetRequestMode(kTestUserId),
+ kTestUserId));
ValidatePackageFS(pkgid, appid);
}
void CheckPackageNonExistance(const std::string& pkgid,
const std::string& appid) {
ASSERT_FALSE(ci::QueryIsPackageInstalled(
- pkgid, ci::GetRequestMode(tzplatform_getuid(TZ_SYS_DEFAULT_USER)),
- tzplatform_getuid(TZ_SYS_DEFAULT_USER)));
+ pkgid, ci::GetRequestMode(kTestUserId),
+ kTestUserId));
PackageCheckCleanup(pkgid, appid);
}
}
ci::AppInstaller::Result Install(const bf::path& path,
RequestResult mode = RequestResult::NORMAL) {
- const char* argv[] = {"", "-i", path.c_str()};
+ const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()};
return CallBackend(SIZEOFARRAY(argv), argv, mode);
}
ci::AppInstaller::Result MountInstall(const bf::path& path,
RequestResult mode = RequestResult::NORMAL) {
- const char* argv[] = {"", "-w", path.c_str()};
+ const char* argv[] = {"", "-w", path.c_str(), "-u", kTestUserIdStr.c_str()};
return CallBackend(SIZEOFARRAY(argv), argv, mode);
}
ci::AppInstaller::Result Uninstall(const std::string& pkgid,
RequestResult mode = RequestResult::NORMAL) {
- const char* argv[] = {"", "-d", pkgid.c_str()};
+ const char* argv[] = {"", "-d", pkgid.c_str(), "-u", kTestUserIdStr.c_str()};
return CallBackend(SIZEOFARRAY(argv), argv, mode);
}
ci::AppInstaller::Result Clear(const bf::path& path,
RequestResult mode = RequestResult::NORMAL) {
- const char* argv[] = {"", "-c", path.c_str()};
+ const char* argv[] = {"", "-c", path.c_str(), "-u", kTestUserIdStr.c_str()};
return CallBackend(SIZEOFARRAY(argv), argv, mode);
}
ci::AppInstaller::Result EnablePackage(const std::string& path,
RequestResult mode = RequestResult::NORMAL) {
- const char* argv[] = {"", "-A", path.c_str()};
+ const char* argv[] = {"", "-A", path.c_str(), "-u", kTestUserIdStr.c_str()};
return CallBackend(SIZEOFARRAY(argv), argv, mode);
}
ci::AppInstaller::Result DisablePackage(const std::string& path,
RequestResult mode = RequestResult::NORMAL) {
- const char* argv[] = {"", "-D", path.c_str()};
+ const char* argv[] = {"", "-D", path.c_str(), "-u", kTestUserIdStr.c_str()};
return CallBackend(SIZEOFARRAY(argv), argv, mode);
}
LOG(ERROR) << "Failed to install application. Cannot perform RDS";
return ci::AppInstaller::Result::UNKNOWN;
}
- const char* argv[] = {"", "-r", delta_dir.c_str()};
+ const char* argv[] = {"", "-r", delta_dir.c_str(), "-u",
+ kTestUserIdStr.c_str()};
return CallBackend(SIZEOFARRAY(argv), argv, mode);
}
ci::AppInstaller::Result Recover(const bf::path& recovery_file,
RequestResult mode = RequestResult::NORMAL) {
- const char* argv[] = {"", "-b", recovery_file.c_str()};
+ const char* argv[] = {"", "-b", recovery_file.c_str(), "-u",
+ kTestUserIdStr.c_str()};
return CallBackend(SIZEOFARRAY(argv), argv, mode);
}
explicit SmokeEnvironment(const bf::path& home) : home_(home) {
}
void SetUp() override {
- bf::path UserDBDir = bf::path(kUserDataBaseDir) / std::to_string(getuid());
+ bf::path UserDBDir = bf::path(kUserDataBaseDir) / kTestUserIdStr;
bf::path UserDBDirBackup = UserDBDir.string() + std::string(".bck");
bs::error_code error;
}
}
void TearDown() override {
- bf::path UserDBDir = bf::path(kUserDataBaseDir) / std::to_string(getuid());
+ bf::path UserDBDir = bf::path(kUserDataBaseDir) / kTestUserIdStr;
bf::path UserDBDirBackup = UserDBDir.string() + std::string(".bck");
bs::error_code error;
// Check delta modifications
bf::path root_path = ci::GetRootAppPath(false,
- tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+ kTestUserId);
ASSERT_FALSE(bf::exists(root_path / pkgid / "DELETED"));
ASSERT_TRUE(bf::exists(root_path / pkgid / "ADDED"));
ASSERT_TRUE(bf::exists(root_path / pkgid / "bin" / "native"));
// Check rds modifications
bf::path root_path = ci::GetRootAppPath(false,
- tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+ kTestUserId);
ASSERT_FALSE(bf::exists(root_path / pkgid / "DELETED"));
ASSERT_TRUE(bf::exists(root_path / pkgid / "ADDED"));
ASSERT_TRUE(bf::exists(root_path / pkgid / "bin" / "native"));
ASSERT_EQ(DisablePackage(pkgid), ci::AppInstaller::Result::OK);
ASSERT_EQ(EnablePackage(pkgid), ci::AppInstaller::Result::OK);
ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode(
- tzplatform_getuid(TZ_SYS_DEFAULT_USER)),
- tzplatform_getuid(TZ_SYS_DEFAULT_USER)));
+ kTestUserId),
+ kTestUserId));
}
TEST_F(SmokeTest, DisablePkg) {
ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK);
ASSERT_EQ(DisablePackage(pkgid), ci::AppInstaller::Result::OK);
ASSERT_FALSE(ci::QueryIsPackageInstalled(pkgid, ci::GetRequestMode(
- tzplatform_getuid(TZ_SYS_DEFAULT_USER)),
- tzplatform_getuid(TZ_SYS_DEFAULT_USER)));
+ kTestUserId),
+ kTestUserId));
ValidatePackageFS(pkgid, {appid});
}
std::string appid = "smokeapp21.ClearModeTpk";
ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK);
bf::path root_path = ci::GetRootAppPath(false,
- tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+ kTestUserId);
bs::error_code error;
bf::create_directory(root_path / pkgid / "data" / "dir", error);
ASSERT_FALSE(error);
bf::path path = kSmokePackagesDirectory / "RecoveryMode_Tpk_Installation.tpk";
RemoveAllRecoveryFiles();
ci::Subprocess backend_crash("/usr/bin/tpk-backend-ut/smoke-test-helper");
- backend_crash.Run("-i", path.string());
+ backend_crash.Run("-i", path.string(), "-u", kTestUserIdStr.c_str());
ASSERT_NE(backend_crash.Wait(), 0);
std::string pkgid = "smokeapp15";
bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_Tpk_Update.tpk";
bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_Tpk_Update_2.tpk";
RemoveAllRecoveryFiles();
- ci::Subprocess backend("/usr/bin/tpk-backend");
- backend.Run("-i", path_old.string());
- ASSERT_EQ(backend.Wait(), 0);
+ ASSERT_EQ(Install(path_old), ci::AppInstaller::Result::OK);
ci::Subprocess backend_crash("/usr/bin/tpk-backend-ut/smoke-test-helper");
- backend_crash.Run("-i", path_new.string());
+ backend_crash.Run("-i", path_new.string(), "-u", kTestUserIdStr.c_str());
ASSERT_NE(backend_crash.Wait(), 0);
std::string pkgid = "smokeapp16";
int main(int argc, char** argv) {
testing::InitGoogleTest(&argc, argv);
- const char* directory = getenv("HOME");
- if (!directory) {
- LOG(ERROR) << "Cannot get $HOME value";
- return 1;
- }
+ bf::path directory =
+ bf::path("/home") / tzplatform_getenv(TZ_SYS_DEFAULT_USER);
testing::AddGlobalTestEnvironment(
new common_installer::SmokeEnvironment(directory));
return RUN_ALL_TESTS();