1 // Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
2 // Use of this source code is governed by an apache-2.0 license that can be
3 // found in the LICENSE file.
5 #include <boost/filesystem/operations.hpp>
6 #include <boost/filesystem/path.hpp>
7 #include <boost/range/iterator_range.hpp>
8 #include <boost/system/error_code.hpp>
9 #include <boost/format.hpp>
11 #include <common/paths.h>
12 #include <common/pkgmgr_interface.h>
13 #include <common/pkgmgr_query.h>
14 #include <common/request.h>
15 #include <common/step/configuration/step_fail.h>
16 #include <common/tzip_interface.h>
17 #include <common/utils/file_util.h>
18 #include <common/utils/subprocess.h>
19 #include <common/utils/user_util.h>
21 #include <gtest/gtest.h>
22 #include <gtest/gtest-death-test.h>
23 #include <pkgmgr-info.h>
26 #include <tzplatform_config.h>
28 #include <vconf-internal-keys.h>
37 #include "hybrid/hybrid_installer.h"
38 #include "wgt/wgt_app_query_interface.h"
39 #include "wgt/wgt_installer.h"
41 #define SIZEOFARRAY(ARR) \
42 sizeof(ARR) / sizeof(ARR[0]) \
44 namespace bf = boost::filesystem;
45 namespace bs = boost::system;
46 namespace ci = common_installer;
49 ci::RequestMode kRequestMode = ci::RequestMode::GLOBAL;
50 const char *short_opts = "g:u";
51 const struct option long_opts[] = {
52 { "request_mode", 1, NULL, 'r' },
53 { 0, 0, 0, 0 } /* sentinel */
55 const char *request_modes[] {
59 void ParseRequestMode(int argc, char** argv) {
63 c = getopt_long(argc, argv, short_opts, long_opts, &opt_idx);
66 if (strncmp(optarg, request_modes[0], strlen(request_modes[0])) == 0)
67 kRequestMode = ci::RequestMode::GLOBAL;
68 else if (strncmp(optarg, request_modes[1], strlen(request_modes[1])) == 0)
69 kRequestMode = ci::RequestMode::USER;
71 LOG(ERROR) << "Wrong request mode " << optarg
72 << ". Available: \"global\" or \"user\"";
75 kRequestMode = ci::RequestMode::GLOBAL;
78 kRequestMode = ci::RequestMode::USER;
86 const uid_t kGlobalUserUid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
87 const uid_t kGlobalUserGid = tzplatform_getgid(TZ_SYS_GLOBALAPP_USER);
88 const uid_t kDefaultUserUid = tzplatform_getuid(TZ_SYS_DEFAULT_USER);
89 uid_t kTestUserId = kGlobalUserUid;
90 gid_t kTestGroupId = kGlobalUserGid;
91 std::string kTestUserIdStr = std::to_string(kTestUserId);
92 const char kNormalUserName[] = "smokeuser";
93 const char kSystemShareGroupName[] = "system_share";
94 const std::string& kDefaultUserIdStr = std::to_string(kDefaultUserUid);
95 const char kLegacyExtImageDir[] = "legacy_extimage_dir";
96 const char kMigrateTestDBName[] = "app2sd_migrate.db";
98 const bf::path kSmokePackagesDirectory =
99 "/usr/share/wgt-backend-ut/test_samples/smoke/";
109 const char* rwDirectories[] = {
118 const std::vector<std::string> kDBEntries = {
119 {".pkgmgr_parser.db"},
120 {".pkgmgr_parser.db-journal"},
122 {".pkgmgr_cert.db-journal"},
124 {".app2sd.db-journal"},
126 // globaluser entries
127 const char kGlobalManifestDir[] = "/opt/share/packages";
128 const char kSkelDir[] = "/etc/skel/apps_rw";
129 const char kPreloadApps[] = "/usr/apps";
130 const char kPreloadManifestDir[] = "/usr/share/packages";
131 const char kPreloadIcons[] = "/usr/share/icons";
133 enum class RequestResult {
138 class ScopedTzipInterface {
140 explicit ScopedTzipInterface(const std::string& pkgid)
141 : pkg_path_(bf::path(ci::GetRootAppPath(false,
142 kTestUserId)) / pkgid),
143 interface_(ci::GetMountLocation(pkg_path_)),
145 interface_.MountZip(ci::GetZipPackageLocation(pkg_path_, pkgid));
150 interface_.UnmountZip();
155 ~ScopedTzipInterface() {
161 ci::TzipInterface interface_;
165 class TestPkgmgrInstaller : public ci::PkgmgrInstallerInterface {
167 bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
168 ci::InstallationMode* mode) {
169 *installer = pkgmgr_installer_offline_new();
172 *mode = ci::InstallationMode::ONLINE;
176 bool ShouldCreateSignal() const {
181 enum class PackageType {
186 bool TouchFile(const bf::path& path) {
187 FILE* f = fopen(path.c_str(), "w+");
194 bool AddTestUser(const char *user_name) {
195 std::cout << "Adding test user: " << user_name << std::endl;
196 gboolean ret = ci::AddUser(user_name);
197 if (boost::optional<uid_t> uid = ci::GetUidByUserName(user_name)) {
199 kTestUserIdStr = std::to_string(kTestUserId);
200 std::cout << "User created properly: uid=" << *uid;
201 if (boost::optional<gid_t> gid = ci::GetGidByUid(*uid)) {
203 std::cout << " gid=" << *gid;
205 std::cout << std::endl;
208 LOG(ERROR) << "Adding test user failed";
212 bool DeleteTestUser(const char *user_name) {
213 std::cout << "Deleting test user: " << user_name << std::endl;
215 if (boost::optional<uid_t> uid = ci::GetUidByUserName(user_name))
217 gboolean ret = ci::DeleteUser(user_name, true);
218 if (boost::optional<uid_t> uid = ci::GetUidByUserName(user_name));
220 std::cout << "User deleted properly: user_name=" << user_name
221 << " uid=" << test_uid << std::endl;
224 LOG(ERROR) << "Deleting test user failed";
228 void RemoveAllRecoveryFiles() {
229 bf::path root_path = ci::GetRootAppPath(false,
231 if (!bf::exists(root_path))
233 for (auto& dir_entry : boost::make_iterator_range(
234 bf::directory_iterator(root_path), bf::directory_iterator())) {
235 if (bf::is_regular_file(dir_entry)) {
236 if (dir_entry.path().string().find("/recovery") != std::string::npos) {
237 bs::error_code error;
238 bf::remove(dir_entry.path(), error);
244 bf::path FindRecoveryFile() {
245 bf::path root_path = ci::GetRootAppPath(false,
247 for (auto& dir_entry : boost::make_iterator_range(
248 bf::directory_iterator(root_path), bf::directory_iterator())) {
249 if (bf::is_regular_file(dir_entry)) {
250 if (dir_entry.path().string().find("/recovery") != std::string::npos) {
251 return dir_entry.path();
258 bf::path GetPackageRoot(const std::string& pkgid, uid_t uid) {
259 bf::path root_path = ci::GetRootAppPath(false, uid);
260 return root_path / pkgid;
263 bool ValidateFileContentInPackage(const std::string& pkgid,
264 const std::string& relative,
265 const std::string& expected,
266 bool is_readonly = false) {
267 bf::path file_path = ci::GetRootAppPath(is_readonly, kTestUserId);
268 file_path = file_path / pkgid / relative;
269 if (!bf::exists(file_path)) {
270 LOG(ERROR) << file_path << " doesn't exist";
273 FILE* handle = fopen(file_path.c_str(), "r");
275 LOG(ERROR) << file_path << " cannot be open";
279 std::array<char, 200> buffer;
280 while (fgets(buffer.data(), buffer.size(), handle)) {
281 content += buffer.data();
284 return content == expected;
287 void AddDataFiles(const std::string& pkgid, uid_t uid) {
288 if (uid == kGlobalUserUid) {
289 ci::UserList list = ci::GetUserList();
290 for (auto l : list) {
291 auto pkg_path = GetPackageRoot(pkgid, std::get<0>(l));
292 ASSERT_TRUE(TouchFile(pkg_path / "data" / "file1.txt"));
293 ASSERT_TRUE(TouchFile(pkg_path / "data" / "file2.txt"));
296 auto pkg_path = GetPackageRoot(pkgid, uid);
297 ASSERT_TRUE(TouchFile(pkg_path / "data" / "file1.txt"));
298 ASSERT_TRUE(TouchFile(pkg_path / "data" / "file2.txt"));
302 void ValidateDataFiles(const std::string& pkgid, uid_t uid) {
303 if (uid == kGlobalUserUid) {
304 ci::UserList list = ci::GetUserList();
305 for (auto l : list) {
306 auto pkg_path = GetPackageRoot(pkgid, std::get<0>(l));
307 ASSERT_TRUE(bf::exists(pkg_path / "data" / "file1.txt"));
308 ASSERT_TRUE(bf::exists(pkg_path / "data" / "file2.txt"));
311 auto pkg_path = GetPackageRoot(pkgid, uid);
312 ASSERT_TRUE(bf::exists(pkg_path / "data" / "file1.txt"));
313 ASSERT_TRUE(bf::exists(pkg_path / "data" / "file2.txt"));
317 void ValidatePackageRWFS(const std::string& pkgid, uid_t uid) {
318 bf::path root_path = ci::GetRootAppPath(false, uid);
319 bf::path package_path = root_path / pkgid;
320 bf::path data_path = package_path / rwDirectories[DATA];
321 bf::path cache_path = package_path / rwDirectories[CACHE];
322 bf::path shared_data_path = package_path / rwDirectories[SHARED_DATA];
324 ASSERT_TRUE(bf::exists(data_path));
325 ASSERT_TRUE(bf::exists(cache_path));
328 stat(data_path.c_str(), &stats);
329 // gid of RW dirs should be system_share
330 boost::optional<gid_t> system_share =
331 ci::GetGidByGroupName(kSystemShareGroupName);
332 ASSERT_EQ(uid, stats.st_uid) << "Invalid gid: " << data_path;
333 ASSERT_EQ(*system_share, stats.st_gid) << "Invalid gid: " << data_path;
334 if (bf::exists(shared_data_path)) {
335 stat(shared_data_path.c_str(), &stats);
336 ASSERT_EQ(uid, stats.st_uid) << "Invalid gid: " << shared_data_path;
337 ASSERT_EQ(*system_share, stats.st_gid) << "Invalid gid: "
341 stat(cache_path.c_str(), &stats);
342 ASSERT_EQ(uid, stats.st_uid) << "Invalid gid: " << cache_path;
343 ASSERT_EQ(*system_share, stats.st_gid) << "Invalid gid: " << cache_path;
346 void ValidatePackageFS(const std::string& pkgid,
347 const std::vector<std::string>& appids,
348 uid_t uid, gid_t gid, bool is_readonly) {
349 bf::path root_path = ci::GetRootAppPath(is_readonly, uid);
350 bf::path package_path = root_path / pkgid;
351 bf::path shared_path = package_path / "shared";
352 ASSERT_TRUE(bf::exists(root_path));
353 ASSERT_TRUE(bf::exists(package_path));
354 ASSERT_TRUE(bf::exists(shared_path));
356 bf::path manifest_path =
357 bf::path(getUserManifestPath(uid, is_readonly)) / (pkgid + ".xml");
358 ASSERT_TRUE(bf::exists(manifest_path));
360 for (auto& appid : appids) {
361 bf::path binary_path = package_path / "bin" / appid;
362 ASSERT_TRUE(bf::exists(binary_path));
365 bf::path widget_root_path = package_path / "res" / "wgt";
366 bf::path config_path = widget_root_path / "config.xml";
367 ASSERT_TRUE(bf::exists(widget_root_path));
368 ASSERT_TRUE(bf::exists(config_path));
370 bf::path private_tmp_path = package_path / "tmp";
371 ASSERT_TRUE(bf::exists(private_tmp_path));
373 // backups should not exist
374 bf::path package_backup = ci::GetBackupPathForPackagePath(package_path);
375 bf::path manifest_backup = ci::GetBackupPathForManifestFile(manifest_path);
376 ASSERT_FALSE(bf::exists(package_backup));
377 ASSERT_FALSE(bf::exists(manifest_backup));
379 for (bf::recursive_directory_iterator iter(package_path);
380 iter != bf::recursive_directory_iterator(); ++iter) {
381 if (bf::is_symlink(symlink_status(iter->path())))
383 bool is_rw_dir = false;
384 for(const auto rw_dir : rwDirectories) {
385 bf::path rw_dir_path = rw_dir;
386 is_rw_dir |= ci::MakeRelativePath(iter->path(), package_path) == rw_dir_path;
388 if (is_rw_dir || iter->path().filename() == ".mmc") {
393 stat(iter->path().c_str(), &stats);
394 ASSERT_EQ(uid, stats.st_uid) << "Invalid uid: " << iter->path();
395 ASSERT_EQ(gid, stats.st_gid) << "Invalid gid: " << iter->path();
399 void PackageCheckCleanup(const std::string& pkgid,
400 const std::vector<std::string>&, bool is_readonly = false) {
401 bf::path root_path = ci::GetRootAppPath(is_readonly, kTestUserId);
402 bf::path package_path = root_path / pkgid;
403 ASSERT_FALSE(bf::exists(package_path));
405 bf::path manifest_path = bf::path(getUserManifestPath(kTestUserId,
406 is_readonly)) / (pkgid + ".xml");
407 ASSERT_FALSE(bf::exists(manifest_path));
409 // backups should not exist
410 bf::path package_backup = ci::GetBackupPathForPackagePath(package_path);
411 bf::path manifest_backup = ci::GetBackupPathForManifestFile(manifest_path);
412 ASSERT_FALSE(bf::exists(package_backup));
413 ASSERT_FALSE(bf::exists(manifest_backup));
416 void ValidatePackage(const std::string& pkgid,
417 const std::vector<std::string>& appids, bool is_readonly = false) {
418 ASSERT_TRUE(ci::QueryIsPackageInstalled(
419 pkgid, ci::GetRequestMode(kTestUserId), kTestUserId));
420 ValidatePackageFS(pkgid, appids, kTestUserId, kTestGroupId, is_readonly);
421 if (kTestUserId == kGlobalUserUid) {
422 ci::UserList list = ci::GetUserList();
424 ValidatePackageRWFS(pkgid, std::get<0>(l));
426 ValidatePackageRWFS(pkgid, kTestUserId);
430 void ValidateExternalPackageFS(const std::string& pkgid,
431 const std::vector<std::string>& appids,
432 uid_t uid, gid_t gid) {
433 ASSERT_EQ(app2ext_usr_enable_external_pkg(pkgid.c_str(), uid), 0);
434 bf::path root_path = ci::GetRootAppPath(false, uid);
435 ASSERT_TRUE(bf::exists(root_path / pkgid / ".mmc" / "res"));
436 ValidatePackageFS(pkgid, appids, uid, gid, false);
437 ASSERT_EQ(app2ext_usr_disable_external_pkg(pkgid.c_str(), uid), 0);
440 void ValidateExternalPackage(const std::string& pkgid,
441 const std::vector<std::string>& appids) {
442 ASSERT_TRUE(ci::QueryIsPackageInstalled(
443 pkgid, ci::GetRequestMode(kTestUserId),
445 std::string storage = ci::QueryStorageForPkgId(pkgid, kTestUserId);
446 bf::path ext_mount_path = ci::GetExternalCardPath();
447 if (bf::is_empty(ext_mount_path)) {
448 LOG(INFO) << "Sdcard not exists!";
449 ASSERT_EQ(storage, "installed_internal");
451 ASSERT_EQ(storage, "installed_external");
453 ValidateExternalPackageFS(pkgid, appids, kTestUserId, kTestGroupId);
454 if (kTestUserId == kGlobalUserUid) {
455 ci::UserList list = ci::GetUserList();
457 ValidatePackageRWFS(pkgid, std::get<0>(l));
459 ValidatePackageRWFS(pkgid, kTestUserId);
463 void CheckPackageNonExistance(const std::string& pkgid,
464 const std::vector<std::string>& appids) {
465 ASSERT_FALSE(ci::QueryIsPackageInstalled(
466 pkgid, ci::GetRequestMode(kTestUserId),
468 PackageCheckCleanup(pkgid, appids);
469 if (kTestUserId == kGlobalUserUid) {
470 ci::UserList list = ci::GetUserList();
471 bf::path skel_path(kSkelDir);
472 ASSERT_FALSE(bf::exists(skel_path / pkgid));
473 for (auto& l : list) {
474 bf::path root_path = ci::GetRootAppPath(false, std::get<0>(l));
475 bf::path package_path = root_path / pkgid;
476 ASSERT_FALSE(bf::exists(package_path));
481 void CheckPackageReadonlyNonExistance(const std::string& pkgid,
482 const std::vector<std::string>& appids) {
483 ASSERT_FALSE(ci::QueryIsPackageInstalled(
484 pkgid, ci::GetRequestMode(kTestUserId), kTestUserId));
485 PackageCheckCleanup(pkgid, appids, true);
488 std::unique_ptr<ci::AppQueryInterface> CreateQueryInterface() {
489 std::unique_ptr<ci::AppQueryInterface> query_interface(
490 new wgt::WgtAppQueryInterface());
491 return query_interface;
494 std::unique_ptr<ci::AppInstaller> CreateInstaller(ci::PkgMgrPtr pkgmgr,
497 case PackageType::WGT:
498 return std::unique_ptr<ci::AppInstaller>(new wgt::WgtInstaller(pkgmgr));
499 case PackageType::HYBRID:
500 return std::unique_ptr<ci::AppInstaller>(
501 new hybrid::HybridInstaller(pkgmgr));
503 LOG(ERROR) << "Unknown installer type";
508 ci::AppInstaller::Result RunInstallerWithPkgrmgr(ci::PkgMgrPtr pkgmgr,
510 RequestResult mode) {
511 std::unique_ptr<ci::AppInstaller> installer = CreateInstaller(pkgmgr, type);
513 case RequestResult::FAIL:
514 installer->AddStep<ci::configuration::StepFail>();
519 return installer->Run();
521 ci::AppInstaller::Result CallBackend(int argc,
524 RequestResult mode = RequestResult::NORMAL
526 TestPkgmgrInstaller pkgmgr_installer;
527 std::unique_ptr<ci::AppQueryInterface> query_interface =
528 CreateQueryInterface();
530 ci::PkgMgrInterface::Create(argc, const_cast<char**>(argv),
531 &pkgmgr_installer, query_interface.get());
533 LOG(ERROR) << "Failed to initialize pkgmgr interface";
534 return ci::AppInstaller::Result::UNKNOWN;
536 return RunInstallerWithPkgrmgr(pkgmgr, type, mode);
539 ci::AppInstaller::Result Install(const bf::path& path,
541 RequestResult mode = RequestResult::NORMAL) {
542 const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()};
543 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
546 ci::AppInstaller::Result InstallPreload(const bf::path& path, PackageType type,
547 RequestResult mode = RequestResult::NORMAL) {
548 const char* argv[] = {"", "-i", path.c_str(), "--preload"};
549 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
552 bool CheckAvailableExternalPath() {
553 bf::path ext_mount_path = ci::GetExternalCardPath();
554 LOG(DEBUG) << "ext_mount_path :" << ext_mount_path;
555 if (ext_mount_path.empty()) {
556 LOG(ERROR) << "Sdcard not exists!";
562 ci::AppInstaller::Result InstallExternal(const bf::path& path,
564 RequestResult mode = RequestResult::NORMAL) {
565 int default_storage = 0;
566 vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_MEM_INSTALL_APPLICATIONS_INT,
568 vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_MEM_INSTALL_APPLICATIONS_INT, 1);
570 const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()};
571 ci::AppInstaller::Result result =
572 CallBackend(SIZEOFARRAY(argv), argv, type, mode);
574 vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_MEM_INSTALL_APPLICATIONS_INT,
579 ci::AppInstaller::Result MigrateLegacyExternalImage(const std::string& pkgid,
580 const bf::path& path,
581 const bf::path& legacy_path,
583 RequestResult mode = RequestResult::NORMAL) {
584 if (InstallExternal(path, type) != ci::AppInstaller::Result::OK) {
585 LOG(ERROR) << "Failed to install application. Cannot perform Migrate";
586 return ci::AppInstaller::Result::ERROR;
589 bf::path ext_mount_path = ci::GetExternalCardPath();
590 if (bf::is_empty(ext_mount_path)) {
591 LOG(ERROR) << "Sdcard not exists!";
592 return ci::AppInstaller::Result::ERROR;
594 bf::path app2sd_path = ext_mount_path / "app2sd";
596 char* image_name = app2ext_usr_getname_image(pkgid.c_str(),
599 LOG(ERROR) << "Failed to get external image name";
600 return ci::AppInstaller::Result::ERROR;
602 bf::path org_image = app2sd_path / image_name;
605 bs::error_code error;
606 bf::remove(org_image, error);
608 LOG(ERROR) << "Failed to remove org image";
609 return ci::AppInstaller::Result::ERROR;
612 bf::path db_path = tzplatform_getenv(TZ_SYS_DB);
613 bf::path app2sd_db = db_path / ".app2sd.db";
614 bf::path app2sd_db_journal = db_path / ".app2sd.db-journal";
615 bf::remove(app2sd_db, error);
617 LOG(ERROR) << "Failed to remove app2sd db";
618 return ci::AppInstaller::Result::ERROR;
620 bf::remove(app2sd_db_journal, error);
622 LOG(ERROR) << "Failed to remove app2sd journal db";
623 return ci::AppInstaller::Result::ERROR;
626 bf::path app2sd_migrate_db = legacy_path / kMigrateTestDBName;
627 if (!ci::CopyFile(app2sd_migrate_db, app2sd_db)) {
628 LOG(ERROR) << "Failed to copy test db";
629 return ci::AppInstaller::Result::ERROR;
632 bf::path legacy_src = legacy_path / pkgid;
633 bf::path legacy_dst = app2sd_path / pkgid;
634 if (!ci::CopyFile(legacy_src, legacy_dst)) {
635 LOG(ERROR) << "Failed to copy test image";
636 return ci::AppInstaller::Result::ERROR;
638 const char* argv[] = {"", "--migrate-extimg", pkgid.c_str(),
639 "-u", kDefaultUserIdStr.c_str()};
640 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
643 ci::AppInstaller::Result MountInstall(const bf::path& path,
644 PackageType type, RequestResult mode = RequestResult::NORMAL) {
645 const char* argv[] = {"", "-w", path.c_str(), "-u", kTestUserIdStr.c_str()};
646 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
649 ci::AppInstaller::Result Uninstall(const std::string& pkgid,
652 RequestResult mode = RequestResult::NORMAL) {
654 const char* argv[] = {"", "-d", pkgid.c_str(), "--preload",
656 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
658 const char* argv[] = {"", "-d", pkgid.c_str(), "-u",
659 kTestUserIdStr.c_str()};
660 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
664 ci::AppInstaller::Result RDSUpdate(const bf::path& path,
665 const std::string& pkgid,
667 RequestResult mode = RequestResult::NORMAL) {
668 if (Install(path, type) != ci::AppInstaller::Result::OK) {
669 LOG(ERROR) << "Failed to install application. Cannot perform RDS";
670 return ci::AppInstaller::Result::UNKNOWN;
672 const char* argv[] = {"", "-r", pkgid.c_str(), "-u",
673 kTestUserIdStr.c_str()};
674 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
677 ci::AppInstaller::Result DeltaInstall(const bf::path& path,
678 const bf::path& delta_package, PackageType type) {
679 if (Install(path, type) != ci::AppInstaller::Result::OK) {
680 LOG(ERROR) << "Failed to install application. Cannot perform delta update";
681 return ci::AppInstaller::Result::UNKNOWN;
683 return Install(delta_package, type);
686 ci::AppInstaller::Result EnablePackage(const std::string& pkgid,
688 RequestResult mode = RequestResult::NORMAL) {
689 const char* argv[] = {"", "-A", pkgid.c_str(), "-u", kTestUserIdStr.c_str()};
690 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
693 ci::AppInstaller::Result DisablePackage(const std::string& pkgid,
695 RequestResult mode = RequestResult::NORMAL) {
696 const char* argv[] = {"", "-D", pkgid.c_str(), "-u", kTestUserIdStr.c_str()};
697 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
700 ci::AppInstaller::Result Recover(const bf::path& recovery_file,
702 RequestResult mode = RequestResult::NORMAL) {
703 const char* argv[] = {"", "-b", recovery_file.c_str(), "-u",
704 kTestUserIdStr.c_str()};
705 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
708 void BackupPath(const bf::path& path) {
709 bf::path backup_path = path.string() + ".bck";
710 std::cout << "Backup path: " << path << " to " << backup_path << std::endl;
711 bs::error_code error;
712 bf::remove_all(backup_path, error);
714 LOG(ERROR) << "Remove failed: " << backup_path
715 << " (" << error.message() << ")";
716 if (bf::exists(path)) {
717 bf::rename(path, backup_path, error);
719 LOG(ERROR) << "Failed to setup test environment. Does some previous"
720 << " test crashed? Path: "
721 << backup_path << " should not exist.";
726 void RestorePath(const bf::path& path) {
727 bf::path backup_path = path.string() + ".bck";
728 std::cout << "Restore path: " << path << " from " << backup_path << std::endl;
729 bs::error_code error;
730 bf::remove_all(path, error);
732 LOG(ERROR) << "Remove failed: " << path
733 << " (" << error.message() << ")";
734 if (bf::exists(backup_path)) {
735 bf::rename(backup_path, path, error);
737 LOG(ERROR) << "Failed to restore backup path: " << backup_path
738 << " (" << error.message() << ")";
742 std::vector<bf::path> SetupBackupDirectories() {
743 std::vector<bf::path> entries;
744 bf::path db_dir = bf::path(tzplatform_getenv(TZ_SYS_DB));
745 if (kTestUserId != kGlobalUserUid)
746 db_dir = db_dir / "user" / std::to_string(kTestUserId);
747 for (auto e : kDBEntries) {
748 bf::path path = db_dir / e;
749 entries.emplace_back(path);
753 entries.emplace_back(kPreloadApps);
754 entries.emplace_back(kPreloadManifestDir);
755 entries.emplace_back(kPreloadIcons);
758 if (kTestUserId == kGlobalUserUid) {
759 entries.emplace_back(kSkelDir);
760 entries.emplace_back(kGlobalManifestDir);
761 ci::UserList list = ci::GetUserList();
762 for (auto l : list) {
763 bf::path apps = std::get<2>(l) / "apps_rw";
764 entries.emplace_back(apps);
767 tzplatform_set_user(kTestUserId);
768 bf::path approot = tzplatform_getenv(TZ_USER_APPROOT);
769 tzplatform_reset_user();
770 entries.emplace_back(approot);
773 bf::path apps_rw = ci::GetRootAppPath(false, kTestUserId);
774 entries.emplace_back(apps_rw);
779 void UninstallAllAppsInDirectory(bf::path dir, bool is_preload) {
780 if(bf::exists(dir)) {
781 for (auto& dir_entry : boost::make_iterator_range(
782 bf::directory_iterator(dir), bf::directory_iterator())) {
783 if (dir_entry.path().string().find("smoke") != std::string::npos &&
784 bf::is_directory(dir_entry)) {
785 std::string package = dir_entry.path().filename().string();
786 std::regex pkg_regex("smoke[a-zA-Z]{3,}[1-9]{2,}");
787 if (std::regex_match(package, pkg_regex)) {
788 if(Uninstall(dir_entry.path().filename().string(), PackageType::WGT,
789 is_preload, RequestResult::NORMAL) !=
790 ci::AppInstaller::Result::OK) {
791 LOG(ERROR) << "Cannot uninstall smoke test app: "
792 << dir_entry.path().filename().string();
800 void UninstallAllSmokeApps() {
801 if (getuid() == 0 && kRequestMode == ci::RequestMode::GLOBAL) {
802 bf::path root_path = kPreloadApps;
803 UninstallAllAppsInDirectory(root_path, true);
805 bf::path apps_rw = ci::GetRootAppPath(false, kTestUserId);
806 UninstallAllAppsInDirectory(apps_rw, false);
811 namespace common_installer {
813 class SmokeEnvironment : public testing::Environment {
815 explicit SmokeEnvironment() {
817 void SetUp() override {
818 if (kRequestMode == ci::RequestMode::USER)
819 ASSERT_TRUE(AddTestUser(kNormalUserName));
821 kTestUserId = kGlobalUserUid;
822 kTestGroupId = kGlobalUserGid;
823 kTestUserIdStr = std::to_string(kTestUserId);
825 backups_ = SetupBackupDirectories();
826 for (auto& path : backups_)
829 void TearDown() override {
830 ASSERT_TRUE(kRequestMode == ci::RequestMode::GLOBAL ||
831 (kRequestMode == ci::RequestMode::USER &&
832 kGlobalUserUid != kTestUserId));
833 UninstallAllSmokeApps();
834 for (auto& path : backups_)
836 if (kRequestMode == ci::RequestMode::USER)
837 ASSERT_TRUE(DeleteTestUser(kNormalUserName));
841 std::vector<bf::path> backups_;
844 class SmokeTest : public testing::Test {
847 class PreloadSmokeTest : public testing::Test {
848 void SetUp() override {
849 ASSERT_TRUE(kRequestMode == ci::RequestMode::GLOBAL);
853 TEST_F(SmokeTest, InstallationMode) {
854 bf::path path = kSmokePackagesDirectory / "InstallationMode.wgt";
855 std::string pkgid = "smokewgt03";
856 std::string appid = "smokewgt03.InstallationMode";
857 ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
858 ValidatePackage(pkgid, {appid});
861 TEST_F(SmokeTest, UpdateMode) {
862 bf::path path_old = kSmokePackagesDirectory / "UpdateMode.wgt";
863 bf::path path_new = kSmokePackagesDirectory / "UpdateMode_2.wgt";
864 std::string pkgid = "smokewgt04";
865 std::string appid = "smokewgt04.UpdateMode";
866 ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
867 AddDataFiles(pkgid, kTestUserId);
868 ASSERT_EQ(Install(path_new, PackageType::WGT), ci::AppInstaller::Result::OK);
869 ValidatePackage(pkgid, {appid});
871 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
872 ValidateDataFiles(pkgid, kTestUserId);
875 TEST_F(SmokeTest, DeinstallationMode) {
876 bf::path path = kSmokePackagesDirectory / "DeinstallationMode.wgt";
877 std::string pkgid = "smokewgt05";
878 std::string appid = "smokewgt05.DeinstallationMode";
879 ASSERT_EQ(Install(path, PackageType::WGT),
880 ci::AppInstaller::Result::OK);
881 ASSERT_EQ(Uninstall(pkgid, PackageType::WGT, false),
882 ci::AppInstaller::Result::OK);
883 CheckPackageNonExistance(pkgid, {appid});
886 TEST_F(SmokeTest, RDSMode) {
887 bf::path path = kSmokePackagesDirectory / "RDSMode.wgt";
888 std::string pkgid = "smokewgt11";
889 std::string appid = "smokewgt11.RDSMode";
890 bf::path delta_directory = kSmokePackagesDirectory / "delta_dir/";
891 bf::path sdk_expected_directory =
892 bf::path(ci::GetRootAppPath(false, kTestUserId)) / "tmp" / pkgid;
893 bs::error_code error;
894 bf::create_directories(sdk_expected_directory.parent_path(), error);
896 ASSERT_TRUE(CopyDir(delta_directory, sdk_expected_directory));
897 ASSERT_EQ(RDSUpdate(path, pkgid, PackageType::WGT),
898 ci::AppInstaller::Result::OK);
899 ValidatePackage(pkgid, {appid});
901 // Check delta modifications
902 ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
903 "res" / "wgt" / "DELETED"));
904 ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
905 "res" / "wgt" / "ADDED"));
906 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "2\n"));
909 TEST_F(SmokeTest, EnablePkg) {
910 bf::path path = kSmokePackagesDirectory / "EnablePkg.wgt";
911 std::string pkgid = "smokewgt22";
912 ASSERT_EQ(Install(path, PackageType::WGT),
913 ci::AppInstaller::Result::OK);
914 ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
915 ci::AppInstaller::Result::OK);
916 ASSERT_EQ(EnablePackage(pkgid, PackageType::WGT),
917 ci::AppInstaller::Result::OK);
919 ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid,
920 ci::GetRequestMode(kTestUserId),
924 TEST_F(SmokeTest, DisablePkg) {
925 bf::path path = kSmokePackagesDirectory / "DisablePkg.wgt";
926 std::string pkgid = "smokewgt21";
927 std::string appid = "smokewgt21.DisablePkg";
928 ASSERT_EQ(Install(path, PackageType::WGT),
929 ci::AppInstaller::Result::OK);
930 ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
931 ci::AppInstaller::Result::OK);
932 ASSERT_TRUE(ci::QueryIsDisabledPackage(pkgid, kTestUserId));
933 ValidatePackage(pkgid, {appid});
936 TEST_F(SmokeTest, DeltaMode) {
937 bf::path path = kSmokePackagesDirectory / "DeltaMode.wgt";
938 bf::path delta_package = kSmokePackagesDirectory / "DeltaMode.delta";
939 std::string pkgid = "smokewgt17";
940 std::string appid = "smokewgt17.DeltaMode";
941 ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::WGT),
942 ci::AppInstaller::Result::OK);
943 ValidatePackage(pkgid, {appid});
945 // Check delta modifications
946 ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
947 "res" / "wgt" / "DELETED"));
948 ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
949 "res" / "wgt" / "ADDED"));
950 ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
951 "res" / "wgt" / "css" / "style.css"));
952 ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
953 "res" / "wgt" / "images" / "tizen_32.png"));
954 ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
955 "res" / "wgt" / "js" / "main.js"));
956 ASSERT_TRUE(ValidateFileContentInPackage(
957 pkgid, "res/wgt/MODIFIED", "version 2\n"));
960 TEST_F(SmokeTest, RecoveryMode_ForInstallation) {
961 bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForInstallation.wgt";
962 Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
963 backend_crash.Run("-i", path.string(), "-u", kTestUserIdStr.c_str());
964 ASSERT_NE(backend_crash.Wait(), 0);
966 std::string pkgid = "smokewgt09";
967 std::string appid = "smokewgt09.RecoveryModeForInstallation";
968 bf::path recovery_file = FindRecoveryFile();
969 ASSERT_FALSE(recovery_file.empty());
970 ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
971 ci::AppInstaller::Result::OK);
972 CheckPackageNonExistance(pkgid, {appid});
975 TEST_F(SmokeTest, RecoveryMode_ForUpdate) {
976 bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForUpdate.wgt";
977 bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForUpdate_2.wgt";
978 RemoveAllRecoveryFiles();
979 ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
980 std::string pkgid = "smokewgt10";
981 std::string appid = "smokewgt10.RecoveryModeForUpdate";
982 AddDataFiles(pkgid, kTestUserId);
983 Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
984 backend_crash.Run("-i", path_new.string(), "-u", kTestUserIdStr.c_str());
985 ASSERT_NE(backend_crash.Wait(), 0);
987 bf::path recovery_file = FindRecoveryFile();
988 ASSERT_FALSE(recovery_file.empty());
989 ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
990 ci::AppInstaller::Result::OK);
991 ValidatePackage(pkgid, {appid});
993 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
994 ValidateDataFiles(pkgid, kTestUserId);
997 TEST_F(SmokeTest, RecoveryMode_ForDelta) {
998 bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForDelta.wgt";
999 bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForDelta.delta";
1000 RemoveAllRecoveryFiles();
1001 ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
1002 Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
1003 backend_crash.Run("-i", path_new.string(), "-u", kTestUserIdStr.c_str());
1004 ASSERT_NE(backend_crash.Wait(), 0);
1006 std::string pkgid = "smokewgt30";
1007 std::string appid = "smokewgt30.RecoveryModeForDelta";
1008 bf::path recovery_file = FindRecoveryFile();
1009 ASSERT_FALSE(recovery_file.empty());
1010 ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
1011 ci::AppInstaller::Result::OK);
1012 ValidatePackage(pkgid, {appid});
1014 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
1017 TEST_F(SmokeTest, RecoveryMode_ForMountInstall) {
1018 bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForMountInstall.wgt";
1019 RemoveAllRecoveryFiles();
1020 Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
1021 backend_crash.Run("-w", path.string(), "-u", kTestUserIdStr.c_str());
1022 ASSERT_NE(backend_crash.Wait(), 0);
1024 std::string pkgid = "smokewgt31";
1025 std::string appid = "smokewgt31.RecoveryModeForMountInstall";
1026 bf::path recovery_file = FindRecoveryFile();
1027 ASSERT_FALSE(recovery_file.empty());
1028 ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
1029 ci::AppInstaller::Result::OK);
1030 CheckPackageNonExistance(pkgid, {appid});
1033 TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) {
1035 kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate.wgt";
1037 kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate_2.wgt";
1038 std::string pkgid = "smokewgt32";
1039 std::string appid = "smokewgt32.RecoveryModeForMountUpdate";
1040 RemoveAllRecoveryFiles();
1041 ASSERT_EQ(MountInstall(path_old, PackageType::WGT),
1042 ci::AppInstaller::Result::OK);
1043 AddDataFiles(pkgid, kTestUserId);
1044 Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
1045 backend_crash.Run("-w", path_new.string(), "-u", kTestUserIdStr.c_str());
1046 ASSERT_NE(backend_crash.Wait(), 0);
1048 // Filesystem may be mounted after crash
1049 ScopedTzipInterface poweroff_unmount_interface(pkgid);
1050 poweroff_unmount_interface.Release();
1052 bf::path recovery_file = FindRecoveryFile();
1053 ASSERT_FALSE(recovery_file.empty());
1054 ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
1055 ci::AppInstaller::Result::OK);
1057 ScopedTzipInterface interface(pkgid);
1058 ValidatePackage(pkgid, {appid});
1059 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
1060 ValidateDataFiles(pkgid, kTestUserId);
1063 TEST_F(SmokeTest, InstallationMode_GoodSignature) {
1064 // pkgid: smokewgt08
1065 bf::path path = kSmokePackagesDirectory / "InstallationMode_GoodSignature.wgt"; // NOLINT
1066 ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
1069 TEST_F(SmokeTest, InstallationMode_WrongSignature) {
1070 // pkgid: smokewgt12
1071 bf::path path = kSmokePackagesDirectory / "InstallationMode_WrongSignature.wgt"; // NOLINT
1072 ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::ERROR);
1075 TEST_F(SmokeTest, InstallationMode_Rollback) {
1076 bf::path path = kSmokePackagesDirectory / "InstallationMode_Rollback.wgt";
1077 std::string pkgid = "smokewgt06";
1078 std::string appid = "smokewgt06.InstallationModeRollback";
1079 ASSERT_EQ(Install(path, PackageType::WGT, RequestResult::FAIL),
1080 ci::AppInstaller::Result::ERROR);
1081 CheckPackageNonExistance(pkgid, {appid});
1084 TEST_F(SmokeTest, UpdateMode_Rollback) {
1085 bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Rollback.wgt";
1086 bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Rollback_2.wgt";
1087 std::string pkgid = "smokewgt07";
1088 std::string appid = "smokewgt07.UpdateModeRollback";
1089 ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
1090 AddDataFiles(pkgid, kTestUserId);
1091 ASSERT_EQ(Install(path_new, PackageType::WGT, RequestResult::FAIL),
1092 ci::AppInstaller::Result::ERROR);
1093 ValidatePackage(pkgid, {appid});
1095 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
1096 ValidateDataFiles(pkgid, kTestUserId);
1099 TEST_F(SmokeTest, DeltaMode_Rollback) {
1100 bf::path path = kSmokePackagesDirectory / "DeltaMode_Rollback.wgt";
1101 bf::path delta_package = kSmokePackagesDirectory / "DeltaMode_Rollback.delta";
1102 std::string pkgid = "smokewgt01";
1103 std::string appid = "smokewgt01.DeltaMode";
1104 ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
1105 AddDataFiles(pkgid, kTestUserId);
1106 ASSERT_EQ(Install(delta_package, PackageType::WGT, RequestResult::FAIL),
1107 ci::AppInstaller::Result::ERROR);
1109 ValidatePackage(pkgid, {appid});
1110 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED",
1112 ValidateDataFiles(pkgid, kTestUserId);
1113 ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
1114 "res/wgt/DELETED"));
1115 ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
1119 TEST_F(SmokeTest, InstallationMode_Hybrid) {
1120 bf::path path = kSmokePackagesDirectory / "InstallationMode_Hybrid.wgt";
1121 std::string pkgid = "smokehyb01";
1122 // Excutable for native app doesn't create symlink
1123 std::string appid1 = "smokehyb01.Web";
1124 ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK);
1125 ValidatePackage(pkgid, {appid1});
1128 TEST_F(SmokeTest, UpdateMode_Hybrid) {
1129 bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Hybrid.wgt";
1130 bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Hybrid_2.wgt";
1131 std::string pkgid = "smokehyb02";
1132 std::string appid1 = "smokehyb02.Web";
1133 ASSERT_EQ(Install(path_old, PackageType::HYBRID),
1134 ci::AppInstaller::Result::OK);
1135 // AddDataFiles(pkgid, kTestUserId);
1136 ASSERT_EQ(Install(path_new, PackageType::HYBRID),
1137 ci::AppInstaller::Result::OK);
1138 ValidatePackage(pkgid, {appid1});
1140 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
1141 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "VERSION", "2\n"));
1142 // ValidateDataFiles(pkgid, kTestUserId);
1145 TEST_F(SmokeTest, DeinstallationMode_Hybrid) {
1146 bf::path path = kSmokePackagesDirectory / "DeinstallationMode_Hybrid.wgt";
1147 std::string pkgid = "smokehyb03";
1148 std::string appid1 = "smokehyb03.Web";
1149 ASSERT_EQ(Install(path, PackageType::HYBRID),
1150 ci::AppInstaller::Result::OK);
1151 ASSERT_EQ(Uninstall(pkgid, PackageType::HYBRID, false),
1152 ci::AppInstaller::Result::OK);
1153 CheckPackageNonExistance(pkgid, {appid1});
1156 TEST_F(SmokeTest, DeltaMode_Hybrid) {
1157 bf::path path = kSmokePackagesDirectory / "DeltaMode_Hybrid.wgt";
1158 bf::path delta_package = kSmokePackagesDirectory / "DeltaMode_Hybrid.delta";
1159 std::string pkgid = "smokehyb04";
1160 std::string appid1 = "smokehyb04.Web";
1161 ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::HYBRID),
1162 ci::AppInstaller::Result::OK);
1163 ValidatePackage(pkgid, {appid1});
1165 // Check delta modifications
1166 bf::path root_path = ci::GetRootAppPath(false,
1168 ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED"));
1169 ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED"));
1170 ASSERT_FALSE(bf::exists(root_path / pkgid / "lib" / "DELETED"));
1171 ASSERT_TRUE(bf::exists(root_path / pkgid / "lib" / "ADDED"));
1172 ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "css" / "style.css")); // NOLINT
1173 ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "images" / "tizen_32.png")); // NOLINT
1174 ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "js" / "main.js"));
1175 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "version 2\n")); // NOLINT
1176 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/MODIFIED", "version 2\n")); // NOLINT
1179 TEST_F(SmokeTest, MountInstallationMode_Hybrid) {
1180 bf::path path = kSmokePackagesDirectory / "MountInstallationMode_Hybrid.wgt";
1181 std::string pkgid = "smokehyb05";
1182 std::string appid1 = "smokehyb05.web";
1183 ASSERT_EQ(MountInstall(path, PackageType::HYBRID),
1184 ci::AppInstaller::Result::OK);
1185 ScopedTzipInterface interface(pkgid);
1186 ValidatePackage(pkgid, {appid1});
1189 TEST_F(SmokeTest, MountUpdateMode_Hybrid) {
1190 bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode_Hybrid.wgt";
1191 bf::path path_new = kSmokePackagesDirectory / "MountUpdateMode_Hybrid_2.wgt";
1192 std::string pkgid = "smokehyb06";
1193 std::string appid1 = "smokehyb06.web";
1194 ASSERT_EQ(MountInstall(path_old, PackageType::HYBRID),
1195 ci::AppInstaller::Result::OK);
1196 AddDataFiles(pkgid, kTestUserId);
1197 ASSERT_EQ(MountInstall(path_new, PackageType::HYBRID),
1198 ci::AppInstaller::Result::OK);
1199 ScopedTzipInterface interface(pkgid);
1200 ValidatePackage(pkgid, {appid1});
1202 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
1203 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/VERSION", "2\n"));
1204 ValidateDataFiles(pkgid, kTestUserId);
1207 TEST_F(SmokeTest, InstallationMode_Rollback_Hybrid) {
1208 bf::path path = kSmokePackagesDirectory /
1209 "InstallationMode_Rollback_Hybrid.wgt";
1210 std::string pkgid = "smokehyb07";
1211 std::string appid1 = "smokehyb07.web";
1212 ASSERT_EQ(Install(path, PackageType::HYBRID, RequestResult::FAIL),
1213 ci::AppInstaller::Result::ERROR);
1214 CheckPackageNonExistance(pkgid, {appid1});
1217 TEST_F(SmokeTest, UpdateMode_Rollback_Hybrid) {
1218 bf::path path_old = kSmokePackagesDirectory /
1219 "UpdateMode_Rollback_Hybrid.wgt";
1220 bf::path path_new = kSmokePackagesDirectory /
1221 "UpdateMode_Rollback_Hybrid_2.wgt";
1222 std::string pkgid = "smokehyb08";
1223 std::string appid1 = "smokehyb08.web";
1224 ASSERT_EQ(Install(path_old, PackageType::HYBRID),
1225 ci::AppInstaller::Result::OK);
1226 AddDataFiles(pkgid, kTestUserId);
1227 ASSERT_EQ(Install(path_new, PackageType::HYBRID,
1228 RequestResult::FAIL), ci::AppInstaller::Result::ERROR);
1229 ValidatePackage(pkgid, {appid1});
1231 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
1232 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/VERSION", "1\n"));
1233 ValidateDataFiles(pkgid, kTestUserId);
1236 TEST_F(SmokeTest, DeltaMode_Rollback_Hybrid) {
1237 bf::path path = kSmokePackagesDirectory / "DeltaMode_Rollback_Hybrid.wgt";
1238 bf::path delta_package = kSmokePackagesDirectory /
1239 "DeltaMode_Rollback_Hybrid.delta";
1240 std::string pkgid = "smokehyb11";
1241 std::string appid1 = "smokehyb11.web";
1242 ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK);
1243 AddDataFiles(pkgid, kTestUserId);
1244 ASSERT_EQ(Install(delta_package, PackageType::HYBRID, RequestResult::FAIL),
1245 ci::AppInstaller::Result::ERROR);
1247 ValidatePackage(pkgid, {appid1});
1248 // Check delta modifications
1249 bf::path root_path = GetPackageRoot(pkgid, kTestUserId);
1250 ASSERT_TRUE(bf::exists(root_path / "res" / "wgt" / "DELETED"));
1251 ASSERT_FALSE(bf::exists(root_path / "res" / "wgt" / "ADDED"));
1252 ASSERT_TRUE(bf::exists(root_path / "lib" / "DELETED"));
1253 ASSERT_FALSE(bf::exists(root_path / "lib" / "ADDED"));
1254 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED",
1256 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/MODIFIED",
1258 ValidateDataFiles(pkgid, kTestUserId);
1261 TEST_F(SmokeTest, MountInstallationMode_Rollback_Hybrid) {
1262 bf::path path = kSmokePackagesDirectory /
1263 "MountInstallationMode_Rollback_Hybrid.wgt";
1264 std::string pkgid = "smokehyb09";
1265 std::string appid1 = "smokehyb09.web";
1266 ASSERT_EQ(MountInstall(path, PackageType::HYBRID, RequestResult::FAIL),
1267 ci::AppInstaller::Result::ERROR);
1268 ScopedTzipInterface interface(pkgid);
1269 CheckPackageNonExistance(pkgid, {appid1});
1272 TEST_F(SmokeTest, MountUpdateMode_Rollback_Hybrid) {
1273 bf::path path_old = kSmokePackagesDirectory /
1274 "MountUpdateMode_Rollback_Hybrid.wgt";
1275 bf::path path_new = kSmokePackagesDirectory /
1276 "MountUpdateMode_Rollback_Hybrid_2.wgt";
1277 std::string pkgid = "smokehyb10";
1278 std::string appid1 = "smokehyb10.web";
1279 ASSERT_EQ(MountInstall(path_old, PackageType::HYBRID),
1280 ci::AppInstaller::Result::OK);
1281 AddDataFiles(pkgid, kTestUserId);
1282 ASSERT_EQ(MountInstall(path_new, PackageType::HYBRID,
1283 RequestResult::FAIL), ci::AppInstaller::Result::ERROR);
1284 ScopedTzipInterface interface(pkgid);
1285 ValidatePackage(pkgid, {appid1});
1287 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
1288 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/VERSION", "1\n"));
1289 ValidateDataFiles(pkgid, kTestUserId);
1292 TEST_F(SmokeTest, MountInstallationMode) {
1293 bf::path path = kSmokePackagesDirectory / "MountInstallationMode.wgt";
1294 std::string pkgid = "smokewgt28";
1295 std::string appid = "smokewgt28.InstallationMode";
1296 ASSERT_EQ(MountInstall(path, PackageType::WGT), ci::AppInstaller::Result::OK);
1297 ScopedTzipInterface interface(pkgid);
1298 ValidatePackage(pkgid, {appid});
1301 TEST_F(SmokeTest, MountUpdateMode) {
1302 bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode.wgt";
1303 bf::path path_new = kSmokePackagesDirectory / "MountUpdateMode_2.wgt";
1304 std::string pkgid = "smokewgt29";
1305 std::string appid = "smokewgt29.UpdateMode";
1306 ASSERT_EQ(MountInstall(path_old, PackageType::WGT),
1307 ci::AppInstaller::Result::OK);
1308 AddDataFiles(pkgid, kTestUserId);
1309 ASSERT_EQ(MountInstall(path_new, PackageType::WGT),
1310 ci::AppInstaller::Result::OK);
1311 ScopedTzipInterface interface(pkgid);
1312 ValidatePackage(pkgid, {appid});
1314 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
1315 ValidateDataFiles(pkgid, kTestUserId);
1318 TEST_F(SmokeTest, MountInstallationMode_Rollback) {
1320 kSmokePackagesDirectory / "MountInstallationMode_Rollback.wgt";
1321 std::string pkgid = "smokewgt33";
1322 std::string appid = "smokewgt33.web";
1323 ASSERT_EQ(MountInstall(path, PackageType::WGT, RequestResult::FAIL),
1324 ci::AppInstaller::Result::ERROR);
1325 ScopedTzipInterface interface(pkgid);
1326 CheckPackageNonExistance(pkgid, {appid});
1329 TEST_F(SmokeTest, MountUpdateMode_Rollback) {
1330 bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode_Rollback.wgt";
1332 kSmokePackagesDirectory / "MountUpdateMode_Rollback_2.wgt";
1333 std::string pkgid = "smokewgt34";
1334 std::string appid = "smokewgt34.web";
1335 ASSERT_EQ(MountInstall(path_old, PackageType::WGT),
1336 ci::AppInstaller::Result::OK);
1337 AddDataFiles(pkgid, kTestUserId);
1338 ASSERT_EQ(MountInstall(path_new, PackageType::WGT,
1339 RequestResult::FAIL), ci::AppInstaller::Result::ERROR);
1340 ScopedTzipInterface interface(pkgid);
1341 ValidatePackage(pkgid, {appid});
1343 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
1344 ValidateDataFiles(pkgid, kTestUserId);
1347 TEST_F(SmokeTest, UserDefinedPlugins) {
1348 bf::path path = kSmokePackagesDirectory / "SimpleEchoPrivilege.wgt";
1349 std::string pkgid = "smokewgt02";
1350 std::string appid = "smokewgt02.SimpleEcho";
1351 std::string call_privilege = "http://tizen.org/privilege/call";
1352 std::string location_privilege = "http://tizen.org/privilege/location";
1353 std::string power_privilege = "http://tizen.org/privilege/power";
1355 ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
1356 ValidatePackage(pkgid, {appid});
1357 std::vector<std::string> res;
1358 ASSERT_TRUE(ci::QueryPrivilegesForPkgId(pkgid, kTestUserId, &res));
1359 ASSERT_TRUE(std::find(res.begin(), res.end(), call_privilege) != res.end());
1360 ASSERT_TRUE(std::find(res.begin(), res.end(), location_privilege)
1362 ASSERT_TRUE(std::find(res.begin(), res.end(), power_privilege) != res.end());
1365 TEST_F(SmokeTest, InstallExternalMode) {
1366 ASSERT_TRUE(CheckAvailableExternalPath());
1367 bf::path path = kSmokePackagesDirectory / "InstallExternalMode.wgt";
1368 std::string pkgid = "smokewgt35";
1369 std::string appid = "smokewgt35.web";
1370 ASSERT_EQ(InstallExternal(path, PackageType::WGT),
1371 ci::AppInstaller::Result::OK);
1372 ValidateExternalPackage(pkgid, {appid});
1375 TEST_F(SmokeTest, MigrateLegacyExternalImageMode) {
1376 ASSERT_TRUE(CheckAvailableExternalPath());
1378 kSmokePackagesDirectory / "MigrateLegacyExternalImageMode.wgt";
1379 std::string pkgid = "smokewgt36";
1380 std::string appid = "smokewgt36.web";
1381 bf::path legacy_path = kSmokePackagesDirectory / kLegacyExtImageDir;
1382 ASSERT_EQ(MigrateLegacyExternalImage(pkgid, path, legacy_path,
1383 PackageType::WGT), ci::AppInstaller::Result::OK);
1384 ValidateExternalPackage(pkgid, {appid});
1387 TEST_F(PreloadSmokeTest, InstallationMode_Preload) {
1388 ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
1389 bf::path path = kSmokePackagesDirectory / "InstallationMode_Preload.wgt";
1390 std::string pkgid = "smokewgt37";
1391 std::string appid = "smokewgt37.InstallationModePreload";
1392 ASSERT_EQ(InstallPreload(path, PackageType::WGT),
1393 ci::AppInstaller::Result::OK);
1394 ValidatePackage(pkgid, {appid}, true);
1397 TEST_F(PreloadSmokeTest, UpdateMode_Preload) {
1398 ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
1399 bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Preload.wgt";
1400 bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Preload2.wgt";
1401 std::string pkgid = "smokewgt38";
1402 std::string appid = "smokewgt38.UpdateModePreload";
1403 ASSERT_EQ(InstallPreload(path_old, PackageType::WGT),
1404 ci::AppInstaller::Result::OK);
1405 AddDataFiles(pkgid, kTestUserId);
1406 ASSERT_EQ(InstallPreload(path_new, PackageType::WGT),
1407 ci::AppInstaller::Result::OK);
1408 ValidatePackage(pkgid, {appid}, true);
1410 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2",
1412 ValidateDataFiles(pkgid, kTestUserId);
1415 TEST_F(PreloadSmokeTest, DeinstallationMode_Preload) {
1416 ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
1417 bf::path path = kSmokePackagesDirectory / "DeinstallationMode_Preload.wgt";
1418 std::string pkgid = "smokewgt39";
1419 std::string appid = "smokewgt39.DeinstallationModePreload";
1420 ASSERT_EQ(InstallPreload(path, PackageType::WGT),
1421 ci::AppInstaller::Result::OK);
1422 ASSERT_EQ(Uninstall(pkgid, PackageType::WGT, true),
1423 ci::AppInstaller::Result::OK);
1424 CheckPackageReadonlyNonExistance(pkgid, {appid});
1427 } // namespace common_installer
1429 int main(int argc, char** argv) {
1430 testing::InitGoogleTest(&argc, argv);
1431 testing::Environment *env = testing::AddGlobalTestEnvironment(
1432 new common_installer::SmokeEnvironment());
1433 ParseRequestMode(argc, argv);
1434 return RUN_ALL_TESTS();