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 <common/paths.h>
10 #include <common/pkgmgr_interface.h>
11 #include <common/pkgmgr_query.h>
12 #include <common/request.h>
13 #include <common/step/configuration/step_fail.h>
14 #include <common/tzip_interface.h>
15 #include <common/utils/subprocess.h>
16 #include <gtest/gtest.h>
17 #include <gtest/gtest-death-test.h>
18 #include <pkgmgr-info.h>
21 #include <tzplatform_config.h>
28 #include "hybrid/hybrid_installer.h"
29 #include "wgt/wgt_app_query_interface.h"
30 #include "wgt/wgt_installer.h"
32 #define SIZEOFARRAY(ARR) \
33 sizeof(ARR) / sizeof(ARR[0]) \
35 namespace bf = boost::filesystem;
36 namespace bs = boost::system;
37 namespace ci = common_installer;
41 const uid_t kTestUserId = tzplatform_getuid(TZ_SYS_DEFAULT_USER);
42 const std::string kTestUserIdStr =
43 std::to_string(kTestUserId);
45 const bf::path kSmokePackagesDirectory =
46 "/usr/share/wgt-backend-ut/test_samples/smoke/";
48 const char kApplicationDir[] = ".applications";
49 const char kApplicationDirBackup[] = ".applications.bck";
50 const char KUserAppsDir[] = "apps_rw";
51 const char KUserAppsDirBackup[] = "apps_rw.bck";
52 const char kUserDataBaseDir[] = "/opt/dbspace/user";
54 enum class RequestResult {
59 class ScopedTzipInterface {
61 explicit ScopedTzipInterface(const std::string& pkgid)
62 : pkg_path_(bf::path(ci::GetRootAppPath(false,
63 kTestUserId)) / pkgid),
64 interface_(ci::GetMountLocation(pkg_path_)),
66 interface_.MountZip(ci::GetZipPackageLocation(pkg_path_, pkgid));
71 interface_.UnmountZip();
76 ~ScopedTzipInterface() {
82 ci::TzipInterface interface_;
86 class TestPkgmgrInstaller : public ci::PkgmgrInstallerInterface {
88 bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
89 ci::InstallationMode* mode) {
90 *installer = pkgmgr_installer_offline_new();
93 *mode = ci::InstallationMode::ONLINE;
97 bool ShouldCreateSignal() const {
102 enum class PackageType {
107 bool TouchFile(const bf::path& path) {
108 FILE* f = fopen(path.c_str(), "w+");
115 void RemoveAllRecoveryFiles() {
116 bf::path root_path = ci::GetRootAppPath(false,
118 if (!bf::exists(root_path))
120 for (auto& dir_entry : boost::make_iterator_range(
121 bf::directory_iterator(root_path), bf::directory_iterator())) {
122 if (bf::is_regular_file(dir_entry)) {
123 if (dir_entry.path().string().find("/recovery") != std::string::npos) {
124 bs::error_code error;
125 bf::remove(dir_entry.path(), error);
131 bf::path FindRecoveryFile() {
132 bf::path root_path = ci::GetRootAppPath(false,
134 for (auto& dir_entry : boost::make_iterator_range(
135 bf::directory_iterator(root_path), bf::directory_iterator())) {
136 if (bf::is_regular_file(dir_entry)) {
137 if (dir_entry.path().string().find("/recovery") != std::string::npos) {
138 return dir_entry.path();
145 bool ValidateFileContentInPackage(const std::string& pkgid,
146 const std::string& relative,
147 const std::string& expected) {
148 bf::path root_path = ci::GetRootAppPath(false,
150 bf::path file_path = root_path / pkgid / relative;
151 if (!bf::exists(file_path)) {
152 LOG(ERROR) << file_path << " doesn't exist";
155 FILE* handle = fopen(file_path.c_str(), "r");
157 LOG(ERROR) << file_path << " cannot be open";
161 std::array<char, 200> buffer;
162 while (fgets(buffer.data(), buffer.size(), handle)) {
163 content += buffer.data();
166 return content == expected;
169 void ValidatePackageFS(const std::string& pkgid,
170 const std::vector<std::string>& appids) {
171 bf::path root_path = ci::GetRootAppPath(false,
173 bf::path package_path = root_path / pkgid;
174 bf::path data_path = package_path / "data";
175 bf::path shared_path = package_path / "shared";
176 bf::path cache_path = package_path / "cache";
177 ASSERT_TRUE(bf::exists(root_path));
178 ASSERT_TRUE(bf::exists(package_path));
179 ASSERT_TRUE(bf::exists(data_path));
180 ASSERT_TRUE(bf::exists(shared_path));
181 ASSERT_TRUE(bf::exists(cache_path));
183 bf::path manifest_path =
184 bf::path(getUserManifestPath(
185 kTestUserId, false)) / (pkgid + ".xml");
186 ASSERT_TRUE(bf::exists(manifest_path));
188 for (auto& appid : appids) {
189 bf::path binary_path = package_path / "bin" / appid;
190 ASSERT_TRUE(bf::exists(binary_path));
193 bf::path widget_root_path = package_path / "res" / "wgt";
194 bf::path config_path = widget_root_path / "config.xml";
195 ASSERT_TRUE(bf::exists(widget_root_path));
196 ASSERT_TRUE(bf::exists(config_path));
198 bf::path private_tmp_path = package_path / "tmp";
199 ASSERT_TRUE(bf::exists(private_tmp_path));
201 // backups should not exist
202 bf::path package_backup = ci::GetBackupPathForPackagePath(package_path);
203 bf::path manifest_backup = ci::GetBackupPathForManifestFile(manifest_path);
204 ASSERT_FALSE(bf::exists(package_backup));
205 ASSERT_FALSE(bf::exists(manifest_backup));
208 void PackageCheckCleanup(const std::string& pkgid,
209 const std::vector<std::string>&) {
210 bf::path root_path = ci::GetRootAppPath(
212 bf::path package_path = root_path / pkgid;
213 ASSERT_FALSE(bf::exists(package_path));
215 bf::path manifest_path =
216 bf::path(getUserManifestPath(
217 kTestUserId, false)) / (pkgid + ".xml");
218 ASSERT_FALSE(bf::exists(manifest_path));
220 // backups should not exist
221 bf::path package_backup = ci::GetBackupPathForPackagePath(package_path);
222 bf::path manifest_backup = ci::GetBackupPathForManifestFile(manifest_path);
223 ASSERT_FALSE(bf::exists(package_backup));
224 ASSERT_FALSE(bf::exists(manifest_backup));
227 void ValidatePackage(const std::string& pkgid,
228 const std::vector<std::string>& appids) {
229 ASSERT_TRUE(ci::QueryIsPackageInstalled(
230 pkgid, ci::GetRequestMode(kTestUserId),
232 ValidatePackageFS(pkgid, appids);
235 void CheckPackageNonExistance(const std::string& pkgid,
236 const std::vector<std::string>& appids) {
237 ASSERT_FALSE(ci::QueryIsPackageInstalled(
238 pkgid, ci::GetRequestMode(kTestUserId),
240 PackageCheckCleanup(pkgid, appids);
243 std::unique_ptr<ci::AppQueryInterface> CreateQueryInterface() {
244 std::unique_ptr<ci::AppQueryInterface> query_interface(
245 new wgt::WgtAppQueryInterface());
246 return query_interface;
249 std::unique_ptr<ci::AppInstaller> CreateInstaller(ci::PkgMgrPtr pkgmgr,
252 case PackageType::WGT:
253 return std::unique_ptr<ci::AppInstaller>(new wgt::WgtInstaller(pkgmgr));
254 case PackageType::HYBRID:
255 return std::unique_ptr<ci::AppInstaller>(
256 new hybrid::HybridInstaller(pkgmgr));
258 LOG(ERROR) << "Unknown installer type";
263 ci::AppInstaller::Result RunInstallerWithPkgrmgr(ci::PkgMgrPtr pkgmgr,
265 RequestResult mode) {
266 std::unique_ptr<ci::AppInstaller> installer = CreateInstaller(pkgmgr, type);
268 case RequestResult::FAIL:
269 installer->AddStep<ci::configuration::StepFail>();
274 return installer->Run();
276 ci::AppInstaller::Result CallBackend(int argc,
279 RequestResult mode = RequestResult::NORMAL
281 TestPkgmgrInstaller pkgmgr_installer;
282 std::unique_ptr<ci::AppQueryInterface> query_interface =
283 CreateQueryInterface();
285 ci::PkgMgrInterface::Create(argc, const_cast<char**>(argv),
286 &pkgmgr_installer, query_interface.get());
288 LOG(ERROR) << "Failed to initialize pkgmgr interface";
289 return ci::AppInstaller::Result::UNKNOWN;
291 return RunInstallerWithPkgrmgr(pkgmgr, type, mode);
294 ci::AppInstaller::Result Install(const bf::path& path,
296 RequestResult mode = RequestResult::NORMAL) {
297 const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()};
298 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
301 ci::AppInstaller::Result Update(const bf::path& path_old,
302 const bf::path& path_new,
304 RequestResult mode = RequestResult::NORMAL) {
305 if (Install(path_old, type) != ci::AppInstaller::Result::OK) {
306 LOG(ERROR) << "Failed to install application. Cannot update";
307 return ci::AppInstaller::Result::UNKNOWN;
309 return Install(path_new, type, mode);
312 ci::AppInstaller::Result MountInstall(const bf::path& path,
313 PackageType type, RequestResult mode = RequestResult::NORMAL) {
314 const char* argv[] = {"", "-w", path.c_str(), "-u", kTestUserIdStr.c_str()};
315 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
318 ci::AppInstaller::Result MountUpdate(const bf::path& path_old,
319 const bf::path& path_new, PackageType type,
320 RequestResult mode = RequestResult::NORMAL) {
321 if (MountInstall(path_old, type) != ci::AppInstaller::Result::OK) {
322 LOG(ERROR) << "Failed to mount-install application. Cannot mount-update";
323 return ci::AppInstaller::Result::UNKNOWN;
325 return MountInstall(path_new, type, mode);
328 ci::AppInstaller::Result Uninstall(const std::string& pkgid,
330 RequestResult mode = RequestResult::NORMAL) {
331 const char* argv[] = {"", "-d", pkgid.c_str(), "-u", kTestUserIdStr.c_str()};
332 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
335 ci::AppInstaller::Result Reinstall(const bf::path& path,
336 const bf::path& delta_dir,
338 RequestResult mode = RequestResult::NORMAL) {
339 if (Install(path, type) != ci::AppInstaller::Result::OK) {
340 LOG(ERROR) << "Failed to install application. Cannot perform RDS";
341 return ci::AppInstaller::Result::UNKNOWN;
343 const char* argv[] = {"", "-r", delta_dir.c_str(), "-u",
344 kTestUserIdStr.c_str()};
345 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
348 ci::AppInstaller::Result DeltaInstall(const bf::path& path,
349 const bf::path& delta_package, PackageType type) {
350 if (Install(path, type) != ci::AppInstaller::Result::OK) {
351 LOG(ERROR) << "Failed to install application. Cannot perform delta update";
352 return ci::AppInstaller::Result::UNKNOWN;
354 return Install(delta_package, type);
357 ci::AppInstaller::Result Clear(const std::string& pkgid,
359 RequestResult mode = RequestResult::NORMAL) {
360 const char* argv[] = {"", "-c", pkgid.c_str(), "-u", kTestUserIdStr.c_str()};
361 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
364 ci::AppInstaller::Result EnablePackage(const std::string& pkgid,
366 RequestResult mode = RequestResult::NORMAL) {
367 const char* argv[] = {"", "-A", pkgid.c_str(), "-u", kTestUserIdStr.c_str()};
368 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
371 ci::AppInstaller::Result DisablePackage(const std::string& pkgid,
373 RequestResult mode = RequestResult::NORMAL) {
374 const char* argv[] = {"", "-D", pkgid.c_str(), "-u", kTestUserIdStr.c_str()};
375 return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
378 ci::AppInstaller::Result Recover(const bf::path& recovery_file,
380 RequestResult mode = RequestResult::NORMAL) {
381 const char* argv[] = {"", "-b", recovery_file.c_str(), "-u",
382 kTestUserIdStr.c_str()};
383 TestPkgmgrInstaller pkgmgr_installer;
384 std::unique_ptr<ci::AppQueryInterface> query_interface =
385 CreateQueryInterface();
387 ci::PkgMgrInterface::Create(SIZEOFARRAY(argv), const_cast<char**>(argv),
388 &pkgmgr_installer, query_interface.get());
390 LOG(ERROR) << "Failed to initialize pkgmgr interface";
391 return ci::AppInstaller::Result::UNKNOWN;
393 return RunInstallerWithPkgrmgr(pkgmgr, type, mode);
398 namespace common_installer {
400 class SmokeEnvironment : public testing::Environment {
402 explicit SmokeEnvironment(const bf::path& home) : home_(home) {
404 void SetUp() override {
405 bf::path UserDBDir = bf::path(kUserDataBaseDir) / kTestUserIdStr;
406 bf::path UserDBDirBackup = UserDBDir.string() + std::string(".bck");
408 bs::error_code error;
409 bf::remove_all(home_ / kApplicationDirBackup, error);
410 bf::remove_all(home_ / KUserAppsDirBackup, error);
411 bf::remove_all(UserDBDirBackup, error);
412 if (bf::exists(home_ / KUserAppsDir)) {
413 bf::rename(home_ / KUserAppsDir, home_ / KUserAppsDirBackup, error);
415 LOG(ERROR) << "Failed to setup test environment. Does some previous"
416 << " test crashed? Directory: "
417 << (home_ / KUserAppsDirBackup) << " should not exist.";
420 if (bf::exists(home_ / kApplicationDir)) {
421 bf::rename(home_ / kApplicationDir, home_ / kApplicationDirBackup, error);
423 LOG(ERROR) << "Failed to setup test environment. Does some previous"
424 << " test crashed? Directory: "
425 << (home_ / kApplicationDirBackup) << " should not exist.";
428 if (bf::exists(UserDBDir)) {
429 bf::rename(UserDBDir, UserDBDirBackup, error);
431 LOG(ERROR) << "Failed to setup test environment. Does some previous"
432 << " test crashed? Directory: "
433 << UserDBDirBackup << " should not exist.";
437 void TearDown() override {
438 bf::path UserDBDir = bf::path(kUserDataBaseDir) / kTestUserIdStr;
439 bf::path UserDBDirBackup = UserDBDir.string() + std::string(".bck");
441 bs::error_code error;
442 bf::remove_all(home_ / kApplicationDir, error);
443 bf::remove_all(home_ / KUserAppsDir, error);
444 bf::remove_all(UserDBDir, error);
445 if (bf::exists(home_ / KUserAppsDirBackup))
446 bf::rename(home_ / KUserAppsDirBackup, home_ / KUserAppsDir, error);
447 if (bf::exists(home_ / kApplicationDirBackup))
448 bf::rename(home_ / kApplicationDirBackup, home_ / kApplicationDir, error);
449 if (bf::exists(UserDBDirBackup))
450 bf::rename(UserDBDirBackup, UserDBDir, error);
457 class SmokeTest : public testing::Test {
460 TEST_F(SmokeTest, InstallationMode) {
461 bf::path path = kSmokePackagesDirectory / "InstallationMode.wgt";
462 std::string pkgid = "smokeapp03";
463 std::string appid = "smokeapp03.InstallationMode";
464 ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
465 ValidatePackage(pkgid, {appid});
468 TEST_F(SmokeTest, UpdateMode) {
469 bf::path path_old = kSmokePackagesDirectory / "UpdateMode.wgt";
470 bf::path path_new = kSmokePackagesDirectory / "UpdateMode_2.wgt";
471 std::string pkgid = "smokeapp04";
472 std::string appid = "smokeapp04.UpdateMode";
473 ASSERT_EQ(Update(path_old, path_new, PackageType::WGT),
474 ci::AppInstaller::Result::OK);
475 ValidatePackage(pkgid, {appid});
477 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
480 TEST_F(SmokeTest, DeinstallationMode) {
481 bf::path path = kSmokePackagesDirectory / "DeinstallationMode.wgt";
482 std::string pkgid = "smokeapp05";
483 std::string appid = "smokeapp05.DeinstallationMode";
484 ASSERT_EQ(Install(path, PackageType::WGT),
485 ci::AppInstaller::Result::OK);
486 ASSERT_EQ(Uninstall(pkgid, PackageType::WGT), ci::AppInstaller::Result::OK);
487 CheckPackageNonExistance(pkgid, {appid});
490 TEST_F(SmokeTest, RDSMode) {
491 bf::path path = kSmokePackagesDirectory / "RDSMode.wgt";
492 bf::path delta_directory = kSmokePackagesDirectory / "delta_dir/";
493 std::string pkgid = "smokeapp11";
494 std::string appid = "smokeapp11.RDSMode";
495 ASSERT_EQ(Reinstall(path, delta_directory, PackageType::WGT),
496 ci::AppInstaller::Result::OK);
497 ValidatePackage(pkgid, {appid});
499 // Check delta modifications
500 bf::path root_path = ci::GetRootAppPath(false,
502 ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED"));
503 ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED"));
504 ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "2\n");
507 TEST_F(SmokeTest, EnablePkg) {
508 bf::path path = kSmokePackagesDirectory / "EnablePkg.wgt";
509 std::string pkgid = "smokeapp22";
510 ASSERT_EQ(Install(path, PackageType::WGT),
511 ci::AppInstaller::Result::OK);
512 ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
513 ci::AppInstaller::Result::OK);
514 ASSERT_EQ(EnablePackage(pkgid, PackageType::WGT),
515 ci::AppInstaller::Result::OK);
517 ASSERT_TRUE(ci::QueryIsPackageInstalled(pkgid,
518 ci::GetRequestMode(kTestUserId),
522 TEST_F(SmokeTest, DisablePkg) {
523 bf::path path = kSmokePackagesDirectory / "DisablePkg.wgt";
524 std::string pkgid = "smokeapp21";
525 std::string appid = "smokeapp21.DisablePkg";
526 ASSERT_EQ(Install(path, PackageType::WGT),
527 ci::AppInstaller::Result::OK);
528 ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
529 ci::AppInstaller::Result::OK);
530 ASSERT_FALSE(ci::QueryIsPackageInstalled(pkgid,
531 ci::GetRequestMode(kTestUserId),
533 ValidatePackageFS(pkgid, {appid});
536 TEST_F(SmokeTest, ClearMode) {
537 bf::path path = kSmokePackagesDirectory / "ClearMode.wgt";
538 std::string pkgid = "smokeapp20";
539 std::string appid = "smokeapp20.ClearMode";
540 ASSERT_EQ(Install(path, PackageType::WGT),
541 ci::AppInstaller::Result::OK);
542 bf::path root_path = ci::GetRootAppPath(false,
544 bs::error_code error;
545 bf::create_directory(root_path / pkgid / "data" / "dir", error);
547 ASSERT_TRUE(TouchFile(root_path / pkgid / "data" / "dir" / "file"));
548 ASSERT_TRUE(TouchFile(root_path / pkgid / "data" / "file"));
549 ASSERT_EQ(Clear(pkgid, PackageType::WGT), ci::AppInstaller::Result::OK);
550 ValidatePackage(pkgid, {appid});
551 ASSERT_FALSE(bf::exists(root_path / pkgid / "data" / "dir" / "file"));
552 ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "file"));
555 TEST_F(SmokeTest, DeltaMode) {
556 bf::path path = kSmokePackagesDirectory / "DeltaMode.wgt";
557 bf::path delta_package = kSmokePackagesDirectory / "DeltaMode.delta";
558 std::string pkgid = "smokeapp17";
559 std::string appid = "smokeapp17.DeltaMode";
560 ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::WGT),
561 ci::AppInstaller::Result::OK);
562 ValidatePackage(pkgid, {appid});
564 // Check delta modifications
565 bf::path root_path = ci::GetRootAppPath(false,
567 ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED"));
568 ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED"));
569 ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "css" / "style.css")); // NOLINT
570 ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "images" / "tizen_32.png")); // NOLINT
571 ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "js" / "main.js"));
572 ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "version 2\n");
575 TEST_F(SmokeTest, RecoveryMode_ForInstallation) {
576 bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForInstallation.wgt";
577 Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
578 backend_crash.Run("-i", path.string(), "-u", kTestUserIdStr.c_str());
579 ASSERT_NE(backend_crash.Wait(), 0);
581 std::string pkgid = "smokeapp09";
582 std::string appid = "smokeapp09.RecoveryModeForInstallation";
583 bf::path recovery_file = FindRecoveryFile();
584 ASSERT_FALSE(recovery_file.empty());
585 ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
586 ci::AppInstaller::Result::OK);
587 CheckPackageNonExistance(pkgid, {appid});
590 TEST_F(SmokeTest, RecoveryMode_ForUpdate) {
591 bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForUpdate.wgt";
592 bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForUpdate_2.wgt";
593 RemoveAllRecoveryFiles();
594 ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
595 Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
596 backend_crash.Run("-i", path_new.string(), "-u", kTestUserIdStr.c_str());
597 ASSERT_NE(backend_crash.Wait(), 0);
599 std::string pkgid = "smokeapp10";
600 std::string appid = "smokeapp10.RecoveryModeForUpdate";
601 bf::path recovery_file = FindRecoveryFile();
602 ASSERT_FALSE(recovery_file.empty());
603 ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
604 ci::AppInstaller::Result::OK);
605 ValidatePackage(pkgid, {appid});
607 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
610 TEST_F(SmokeTest, RecoveryMode_ForDelta) {
611 bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForDelta.wgt";
612 bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForDelta.delta";
613 RemoveAllRecoveryFiles();
614 ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
615 Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
616 backend_crash.Run("-i", path_new.string(), "-u", kTestUserIdStr.c_str());
617 ASSERT_NE(backend_crash.Wait(), 0);
619 std::string pkgid = "smokeapp30";
620 std::string appid = "smokeapp30.RecoveryModeForDelta";
621 bf::path recovery_file = FindRecoveryFile();
622 ASSERT_FALSE(recovery_file.empty());
623 ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
624 ci::AppInstaller::Result::OK);
625 ValidatePackage(pkgid, {appid});
627 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
630 TEST_F(SmokeTest, RecoveryMode_ForMountInstall) {
631 bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForMountInstall.wgt";
632 RemoveAllRecoveryFiles();
633 Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
634 backend_crash.Run("-w", path.string(), "-u", kTestUserIdStr.c_str());
635 ASSERT_NE(backend_crash.Wait(), 0);
637 std::string pkgid = "smokeapp31";
638 std::string appid = "smokeapp31.RecoveryModeForMountInstall";
639 bf::path recovery_file = FindRecoveryFile();
640 ASSERT_FALSE(recovery_file.empty());
641 ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
642 ci::AppInstaller::Result::OK);
643 CheckPackageNonExistance(pkgid, {appid});
646 TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) {
648 kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate.wgt";
650 kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate_2.wgt";
651 std::string pkgid = "smokeapp32";
652 std::string appid = "smokeapp32.RecoveryModeForMountUpdate";
653 RemoveAllRecoveryFiles();
654 ASSERT_EQ(MountInstall(path_old, PackageType::WGT),
655 ci::AppInstaller::Result::OK);
656 Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
657 backend_crash.Run("-w", path_new.string(), "-u", kTestUserIdStr.c_str());
658 ASSERT_NE(backend_crash.Wait(), 0);
660 // Filesystem may be mounted after crash
661 ScopedTzipInterface poweroff_unmount_interface(pkgid);
662 poweroff_unmount_interface.Release();
664 bf::path recovery_file = FindRecoveryFile();
665 ASSERT_FALSE(recovery_file.empty());
666 ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
667 ci::AppInstaller::Result::OK);
669 ScopedTzipInterface interface(pkgid);
670 ValidatePackage(pkgid, {appid});
671 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
674 TEST_F(SmokeTest, InstallationMode_GoodSignature) {
675 bf::path path = kSmokePackagesDirectory / "InstallationMode_GoodSignature.wgt"; // NOLINT
676 ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
679 TEST_F(SmokeTest, InstallationMode_WrongSignature) {
680 bf::path path = kSmokePackagesDirectory / "InstallationMode_WrongSignature.wgt"; // NOLINT
681 ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::ERROR);
684 TEST_F(SmokeTest, InstallationMode_Rollback) {
685 bf::path path = kSmokePackagesDirectory / "InstallationMode_Rollback.wgt";
686 std::string pkgid = "smokeapp06";
687 std::string appid = "smokeapp06.InstallationModeRollback";
688 ASSERT_EQ(Install(path, PackageType::WGT, RequestResult::FAIL),
689 ci::AppInstaller::Result::ERROR);
690 CheckPackageNonExistance(pkgid, {appid});
693 TEST_F(SmokeTest, UpdateMode_Rollback) {
694 bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Rollback.wgt";
695 bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Rollback_2.wgt";
696 std::string pkgid = "smokeapp07";
697 std::string appid = "smokeapp07.UpdateModeRollback";
698 ASSERT_EQ(Update(path_old, path_new, PackageType::WGT, RequestResult::FAIL),
699 ci::AppInstaller::Result::ERROR);
700 ValidatePackage(pkgid, {appid});
702 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
705 TEST_F(SmokeTest, InstallationMode_Hybrid) {
706 bf::path path = kSmokePackagesDirectory / "InstallationMode_Hybrid.wgt";
707 std::string pkgid = "smokehyb01";
708 std::string appid1 = "smokehyb01.Web";
709 std::string appid2 = "smokehyb01.Native";
710 ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK);
711 ValidatePackage(pkgid, {appid1, appid2});
714 TEST_F(SmokeTest, UpdateMode_Hybrid) {
715 bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Hybrid.wgt";
716 bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Hybrid_2.wgt";
717 std::string pkgid = "smokehyb02";
718 std::string appid1 = "smokehyb02.Web";
719 std::string appid2 = "smokehyb02.Native";
720 ASSERT_EQ(Update(path_old, path_new, PackageType::HYBRID),
721 ci::AppInstaller::Result::OK);
722 ValidatePackage(pkgid, {appid1, appid2});
724 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
725 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "VERSION", "2\n"));
728 TEST_F(SmokeTest, DeinstallationMode_Hybrid) {
729 bf::path path = kSmokePackagesDirectory / "DeinstallationMode_Hybrid.wgt";
730 std::string pkgid = "smokehyb03";
731 std::string appid1 = "smokehyb03.Web";
732 std::string appid2 = "smokehyb03.Native";
733 ASSERT_EQ(Install(path, PackageType::HYBRID),
734 ci::AppInstaller::Result::OK);
735 ASSERT_EQ(Uninstall(pkgid, PackageType::WGT), ci::AppInstaller::Result::OK);
736 CheckPackageNonExistance(pkgid, {appid1, appid2});
739 TEST_F(SmokeTest, DeltaMode_Hybrid) {
740 bf::path path = kSmokePackagesDirectory / "DeltaMode_Hybrid.wgt";
741 bf::path delta_package = kSmokePackagesDirectory / "DeltaMode_Hybrid.delta";
742 std::string pkgid = "smokehyb04";
743 std::string appid1 = "smokehyb04.Web";
744 std::string appid2 = "smokehyb04.Native";
745 ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::HYBRID),
746 ci::AppInstaller::Result::OK);
747 ValidatePackage(pkgid, {appid1, appid2});
749 // Check delta modifications
750 bf::path root_path = ci::GetRootAppPath(false,
752 ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "wgt" / "DELETED"));
753 ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "ADDED"));
754 ASSERT_FALSE(bf::exists(root_path / pkgid / "lib" / "DELETED"));
755 ASSERT_TRUE(bf::exists(root_path / pkgid / "lib" / "ADDED"));
756 ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "css" / "style.css")); // NOLINT
757 ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "images" / "tizen_32.png")); // NOLINT
758 ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "wgt" / "js" / "main.js"));
759 ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED", "version 2\n");
760 ValidateFileContentInPackage(pkgid, "lib/MODIFIED", "version 2\n");
763 TEST_F(SmokeTest, MountInstallationMode) {
764 bf::path path = kSmokePackagesDirectory / "MountInstallationMode.wgt";
765 std::string pkgid = "smokeapp28";
766 std::string appid = "smokeapp28.InstallationMode";
767 ASSERT_EQ(MountInstall(path, PackageType::WGT), ci::AppInstaller::Result::OK);
768 ScopedTzipInterface interface(pkgid);
769 ValidatePackage(pkgid, {appid});
772 TEST_F(SmokeTest, MountUpdateMode) {
773 bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode.wgt";
774 bf::path path_new = kSmokePackagesDirectory / "MountUpdateMode_2.wgt";
775 std::string pkgid = "smokeapp29";
776 std::string appid = "smokeapp29.UpdateMode";
777 ASSERT_EQ(MountUpdate(path_old, path_new, PackageType::WGT),
778 ci::AppInstaller::Result::OK);
779 ScopedTzipInterface interface(pkgid);
780 ValidatePackage(pkgid, {appid});
782 ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
785 } // namespace common_installer
787 int main(int argc, char** argv) {
788 testing::InitGoogleTest(&argc, argv);
790 bf::path("/home") / tzplatform_getenv(TZ_SYS_DEFAULT_USER);
791 testing::AddGlobalTestEnvironment(
792 new common_installer::SmokeEnvironment(directory));
793 return RUN_ALL_TESTS();