--- /dev/null
+// Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include <boost/exception/diagnostic_information.hpp>
+#include <boost/program_options.hpp>
+
+#include <common/utils/subprocess.h>
+#include <unit_tests/common/smoke_utils.h>
+
+#include <gtest/gtest.h>
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "smoke_test/smoke_utils.h"
+
+namespace bf = boost::filesystem;
+namespace bpo = boost::program_options;
+namespace ci = common_installer;
+
+enum class ReqType : int {
+ UNKNOWN_REQ,
+ INSTALL_REQ,
+ UPDATE_REQ,
+ DELTA_REQ,
+ MOUNT_INSTALL_REQ,
+ MOUNT_UPDATE_REQ,
+};
+
+enum class BackupType : int {
+ MOVE,
+ COPY_AND_REMOVE,
+};
+
+std::map<ReqType, std::string> install_req_filter = {
+ { ReqType::INSTALL_REQ, "SmokeTest.RecoveryMode_Multi_Installation" },
+ { ReqType::UPDATE_REQ, "SmokeTest.RecoveryMode_Multi_Update" },
+ { ReqType::DELTA_REQ, "SmokeTest.RecoveryMode_ForDelta" },
+ { ReqType::MOUNT_INSTALL_REQ, "SmokeTest.RecoveryMode_ForMountInstall" },
+ { ReqType::MOUNT_UPDATE_REQ, "SmokeTest.RecoveryMode_ForMountUpdate" }
+};
+
+int delay = 1000000;
+int interval = 500000;
+int test_count = 0;
+
+namespace smoke_test {
+
+class SmokeEnvironment : public testing::Environment {
+ public:
+ explicit SmokeEnvironment(ci::RequestMode mode, bool no_backup,
+ BackupType backup_type) :
+ request_mode_(mode), no_backup_(no_backup),
+ backup_type_(backup_type) {
+ }
+
+ void SetUp() override {
+ if (request_mode_ == ci::RequestMode::USER)
+ ASSERT_TRUE(AddTestUser(&test_user));
+ if (no_backup_)
+ return;
+ backups_ = SetupBackupDirectories(test_user.uid);
+ if (backup_type_ == BackupType::MOVE) {
+ for (auto& path : backups_)
+ ASSERT_TRUE(BackupPath(path));
+ } else if (backup_type_ == BackupType::COPY_AND_REMOVE) {
+ for (auto& path : backups_)
+ ASSERT_TRUE(BackupPathCopyAndRemove(path));
+ }
+ }
+
+ void TearDown() override {
+ test_count++;
+ if (request_mode_ == ci::RequestMode::USER)
+ ASSERT_TRUE(DeleteTestUser());
+ if (no_backup_)
+ return;
+ if (backup_type_ == BackupType::MOVE) {
+ for (auto& path : backups_)
+ ASSERT_TRUE(RestorePath(path));
+ } else if (backup_type_ == BackupType::COPY_AND_REMOVE) {
+ for (auto& path : backups_)
+ ASSERT_TRUE(RestorePathCopyAndRemove(path));
+ }
+ }
+
+ User test_user;
+
+ private:
+ ci::RequestMode request_mode_;
+ std::vector<bf::path> backups_;
+ bool no_backup_;
+ BackupType backup_type_;
+};
+
+} // namespace smoke_test
+
+namespace {
+
+smoke_test::SmokeEnvironment *env = nullptr;
+
+void signalHandler(int signum) {
+ env->TearDown();
+ exit(signum);
+}
+
+} // namespace
+
+namespace smoke_test {
+
+const bf::path kUnifiedSmokePackagesDirectory =
+ "/usr/share/unified-installer-ut/test_samples/smoke/";
+
+class SmokeTest : public testing::Test {
+ public:
+ SmokeTest() : params{PackageType::TPK, false} {
+ params.test_user.uid = env->test_user.uid;
+ params.test_user.gid = env->test_user.gid;
+ }
+
+ protected:
+ UnifiedSmokeTestHelperRunner backend;
+ TestParameters params;
+};
+
+TEST_F(SmokeTest, RecoveryMode_Multi_Installation) {
+ RemoveAllRecoveryFiles("/unified-recovery", params.test_user.uid);
+ RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
+ RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
+
+ std::vector<bf::path> paths = {
+ kUnifiedSmokePackagesDirectory / "RecoveryTpkPkg.tpk",
+ kUnifiedSmokePackagesDirectory / "RecoveryWgtPkg.wgt",
+ kUnifiedSmokePackagesDirectory / "RecoveryHybridPkg.wgt" };
+ std::vector<std::string> pkgids =
+ { "smokerec01", "smokerec02", "smokerec03" };
+ std::vector<Apps> app_infos = {
+ { {"smokerec01.RecoveryTpk", "native"} },
+ { {"smokerec02.RecoveryWgt", "smokerec02.RecoveryWgt"} },
+ {
+ {"smokerec03.RecoveryHybridUI", "smokerec03.RecoveryHybridUI"},
+ {"smokerec03.recoveryhybridservice", "recoveryhybridservice"},
+ }
+ };
+
+ int wait_time = delay + interval * test_count;
+ SmokeTestHelperRunner::Result ret = backend.InstallPkgsWithSubprocessAndKill(
+ paths, params.test_user.uid, wait_time);
+ if (ret == SmokeTestHelperRunner::Result::SUCCESS) {
+ std::cout << "install finished before process killed" << std::endl;
+ return;
+ }
+ ASSERT_EQ(ret, SmokeTestHelperRunner::Result::KILLED);
+
+ bf::path recovery_file = FindRecoveryFile("/unified-recovery",
+ params.test_user.uid);
+ if (recovery_file.empty()) {
+ std::cout << "recovery file dosen't exist, "
+ "this test is skipped" << std::endl;
+ return;
+ }
+
+ UnifiedRecoveryInfo recovery_info(recovery_file);
+ ASSERT_TRUE(recovery_info.Init());
+ bf::remove(recovery_file);
+ const std::vector<bf::path>& recovery_list = recovery_info.GetRecoveryFiles();
+ if (recovery_list.empty()) {
+ std::cout << "installer recovery file is not created yet" << std::endl;
+ return;
+ }
+ ASSERT_EQ(
+ backend.RecoveryPkgsWithSubprocess(recovery_list, params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+ if (recovery_info.GetCleanUp()) {
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(0), app_infos.at(0), params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(1), app_infos.at(1), params));
+ params.pkg_type = PackageType::HYBRID;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(2), app_infos.at(2), params));
+ ASSERT_EQ(
+ backend.UninstallWithSubprocess(pkgids.at(0), params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+ ASSERT_EQ(
+ backend.UninstallWithSubprocess(pkgids.at(1), params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+ ASSERT_EQ(
+ backend.UninstallWithSubprocess(pkgids.at(2), params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+ } else {
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(CheckPackageNonExistance(pkgids.at(0), params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(CheckPackageNonExistance(pkgids.at(1), params));
+ params.pkg_type = PackageType::HYBRID;
+ ASSERT_TRUE(CheckPackageNonExistance(pkgids.at(2), params));
+ }
+}
+
+TEST_F(SmokeTest, RecoveryMode_Multi_Update) {
+ RemoveAllRecoveryFiles("/unified-recovery", params.test_user.uid);
+ RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
+ RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
+
+ std::vector<bf::path> paths_old = {
+ kUnifiedSmokePackagesDirectory / "RecoveryTpkPkg.tpk",
+ kUnifiedSmokePackagesDirectory / "RecoveryWgtPkg.wgt",
+ kUnifiedSmokePackagesDirectory / "RecoveryHybridPkg.wgt" };
+ std::vector<bf::path> paths_new = {
+ kUnifiedSmokePackagesDirectory / "RecoveryTpkPkg2.tpk",
+ kUnifiedSmokePackagesDirectory / "RecoveryWgtPkg2.wgt",
+ kUnifiedSmokePackagesDirectory / "RecoveryHybridPkg2.wgt" };
+ std::vector<std::string> pkgids =
+ { "smokerec01", "smokerec02", "smokerec03" };
+ std::vector<Apps> app_infos = {
+ { {"smokerec01.RecoveryTpk", "native"} },
+ { {"smokerec02.RecoveryWgt", "smokerec02.RecoveryWgt"} },
+ {
+ {"smokerec03.RecoveryHybridUI", "smokerec03.RecoveryHybridUI"},
+ {"smokerec03.recoveryhybridservice", "recoveryhybridservice"},
+ }
+ };
+ int wait_time = delay + interval * test_count;
+
+ ASSERT_EQ(backend.InstallPkgsWithSubprocess(paths_old, params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+
+ SmokeTestHelperRunner::Result ret = backend.InstallPkgsWithSubprocessAndKill(
+ paths_new, params.test_user.uid, wait_time);
+ if (ret == SmokeTestHelperRunner::Result::SUCCESS) {
+ std::cout << "update finished before process killed" << std::endl;
+ return;
+ }
+ ASSERT_EQ(ret, SmokeTestHelperRunner::Result::KILLED);
+
+ bf::path recovery_file = FindRecoveryFile("/unified-recovery",
+ params.test_user.uid);
+ if (recovery_file.empty()) {
+ std::cout << "recovery file dosen't exist, "
+ "this test is skipped" << std::endl;
+ return;
+ }
+
+ UnifiedRecoveryInfo recovery_info(recovery_file);
+ ASSERT_TRUE(recovery_info.Init());
+ bf::remove(recovery_file);
+ const std::vector<bf::path>& recovery_list = recovery_info.GetRecoveryFiles();
+ if (recovery_list.empty()) {
+ std::cout << "installer recovery file is not created yet" << std::endl;
+ return;
+ }
+
+ ASSERT_EQ(
+ backend.RecoveryPkgsWithSubprocess(recovery_list, params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+ if (recovery_info.GetCleanUp()) {
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(0), app_infos.at(0), params));
+ ASSERT_TRUE(ValidateFileContentInPackage(
+ pkgids.at(0), "res/VERSION", "2", params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(1), app_infos.at(1), params));
+ ASSERT_TRUE(ValidateFileContentInPackage(
+ pkgids.at(1), "res/wgt/VERSION", "2", params));
+ params.pkg_type = PackageType::HYBRID;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(2), app_infos.at(2), params));
+ ASSERT_TRUE(ValidateFileContentInPackage(
+ pkgids.at(2), "res/wgt/VERSION", "2", params));
+ } else {
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(0), app_infos.at(0), params));
+ ASSERT_TRUE(ValidateFileContentInPackage(
+ pkgids.at(0), "res/VERSION", "1", params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(1), app_infos.at(1), params));
+ ASSERT_TRUE(ValidateFileContentInPackage(
+ pkgids.at(1), "res/wgt/VERSION", "1", params));
+ params.pkg_type = PackageType::HYBRID;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(2), app_infos.at(2), params));
+ ASSERT_TRUE(ValidateFileContentInPackage(
+ pkgids.at(2), "res/wgt/VERSION", "1", params));
+ }
+ ASSERT_EQ(
+ backend.UninstallWithSubprocess(pkgids.at(0), params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+ ASSERT_EQ(
+ backend.UninstallWithSubprocess(pkgids.at(1), params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+ ASSERT_EQ(
+ backend.UninstallWithSubprocess(pkgids.at(2), params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+}
+
+TEST_F(SmokeTest, RecoveryMode_ForDelta) {
+ RemoveAllRecoveryFiles("/unified-recovery", params.test_user.uid);
+ RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
+ RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
+
+ std::vector<bf::path> paths_old = {
+ kUnifiedSmokePackagesDirectory / "RecoveryTpkPkg.tpk",
+ kUnifiedSmokePackagesDirectory / "RecoveryWgtPkg.wgt",
+ kUnifiedSmokePackagesDirectory / "RecoveryHybridPkg.wgt" };
+ std::vector<bf::path> paths_new = {
+ kUnifiedSmokePackagesDirectory / "RecoveryTpkPkg.delta",
+ kUnifiedSmokePackagesDirectory / "RecoveryWgtPkg.delta",
+ kUnifiedSmokePackagesDirectory / "RecoveryHybridPkg.delta" };
+ std::vector<std::string> pkgids =
+ { "smokerec01", "smokerec02", "smokerec03" };
+ std::vector<Apps> app_infos = {
+ { {"smokerec01.RecoveryTpk", "native"} },
+ { {"smokerec02.RecoveryWgt", "smokerec02.RecoveryWgt"} },
+ {
+ {"smokerec03.RecoveryHybridUI", "smokerec03.RecoveryHybridUI"},
+ {"smokerec03.recoveryhybridservice", "recoveryhybridservice"},
+ }
+ };
+ int wait_time = delay + interval * test_count;
+
+ ASSERT_EQ(backend.InstallPkgsWithSubprocess(paths_old, params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+
+ SmokeTestHelperRunner::Result ret = backend.InstallPkgsWithSubprocessAndKill(
+ paths_new, params.test_user.uid, wait_time);
+ if (ret == SmokeTestHelperRunner::Result::SUCCESS) {
+ std::cout << "delta finished before process killed" << std::endl;
+ return;
+ }
+ ASSERT_EQ(ret, SmokeTestHelperRunner::Result::KILLED);
+
+ bf::path recovery_file = FindRecoveryFile("/unified-recovery",
+ params.test_user.uid);
+ if (recovery_file.empty()) {
+ std::cout << "recovery file dosen't exist, "
+ "this test is skipped" << std::endl;
+ return;
+ }
+
+ UnifiedRecoveryInfo recovery_info(recovery_file);
+ ASSERT_TRUE(recovery_info.Init());
+ bf::remove(recovery_file);
+ const std::vector<bf::path>& recovery_list = recovery_info.GetRecoveryFiles();
+ if (recovery_list.empty()) {
+ std::cout << "installer recovery file is not created yet" << std::endl;
+ return;
+ }
+
+ ASSERT_EQ(
+ backend.RecoveryPkgsWithSubprocess(recovery_list, params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+ if (recovery_info.GetCleanUp()) {
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(0), app_infos.at(0), params));
+ ASSERT_TRUE(ValidateFileContentInPackage(
+ pkgids.at(0), "res/VERSION", "2", params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(1), app_infos.at(1), params));
+ ASSERT_TRUE(ValidateFileContentInPackage(
+ pkgids.at(1), "res/wgt/VERSION", "2", params));
+ params.pkg_type = PackageType::HYBRID;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(2), app_infos.at(2), params));
+ ASSERT_TRUE(ValidateFileContentInPackage(
+ pkgids.at(2), "res/wgt/VERSION", "2", params));
+ } else {
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(0), app_infos.at(0), params));
+ ASSERT_TRUE(ValidateFileContentInPackage(
+ pkgids.at(0), "res/VERSION", "1", params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(1), app_infos.at(1), params));
+ ASSERT_TRUE(ValidateFileContentInPackage(
+ pkgids.at(1), "res/wgt/VERSION", "1", params));
+ params.pkg_type = PackageType::HYBRID;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(2), app_infos.at(2), params));
+ ASSERT_TRUE(ValidateFileContentInPackage(
+ pkgids.at(2), "res/wgt/VERSION", "1", params));
+ }
+ ASSERT_EQ(
+ backend.UninstallWithSubprocess(pkgids.at(0), params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+ ASSERT_EQ(
+ backend.UninstallWithSubprocess(pkgids.at(1), params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+ ASSERT_EQ(
+ backend.UninstallWithSubprocess(pkgids.at(2), params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+}
+
+TEST_F(SmokeTest, RecoveryMode_ForMountInstall) {
+ RemoveAllRecoveryFiles("/unified-recovery", params.test_user.uid);
+ RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
+ RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
+
+ std::vector<bf::path> paths = {
+ kUnifiedSmokePackagesDirectory / "RecoveryTpkPkg.tpk",
+ kUnifiedSmokePackagesDirectory / "RecoveryWgtPkg.wgt",
+ kUnifiedSmokePackagesDirectory / "RecoveryHybridPkg.wgt" };
+ std::vector<std::string> pkgids =
+ { "smokerec01", "smokerec02", "smokerec03" };
+ std::vector<Apps> app_infos = {
+ { {"smokerec01.RecoveryTpk", "native"} },
+ { {"smokerec02.RecoveryWgt", "smokerec02.RecoveryWgt"} },
+ {
+ {"smokerec03.RecoveryHybridUI", "smokerec03.RecoveryHybridUI"},
+ {"smokerec03.recoveryhybridservice", "recoveryhybridservice"},
+ }
+ };
+
+ int wait_time = delay + interval * test_count;
+ SmokeTestHelperRunner::Result ret =
+ backend.MountInstallPkgsWithSubprocessAndKill(
+ paths, params.test_user.uid, wait_time);
+ if (ret == SmokeTestHelperRunner::Result::SUCCESS) {
+ std::cout << "install finished before process killed" << std::endl;
+ return;
+ }
+ ASSERT_EQ(ret, SmokeTestHelperRunner::Result::KILLED);
+
+ bf::path recovery_file = FindRecoveryFile("/unified-recovery",
+ params.test_user.uid);
+ if (recovery_file.empty()) {
+ std::cout << "recovery file dosen't exist, "
+ "this test is skipped" << std::endl;
+ return;
+ }
+
+ UnifiedRecoveryInfo recovery_info(recovery_file);
+ ASSERT_TRUE(recovery_info.Init());
+ bf::remove(recovery_file);
+ const std::vector<bf::path>& recovery_list = recovery_info.GetRecoveryFiles();
+ if (recovery_list.empty()) {
+ std::cout << "installer recovery file is not created yet" << std::endl;
+ return;
+ }
+ ASSERT_EQ(
+ backend.RecoveryPkgsWithSubprocess(recovery_list, params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+ if (recovery_info.GetCleanUp()) {
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(0), app_infos.at(0), params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(1), app_infos.at(1), params));
+ params.pkg_type = PackageType::HYBRID;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(2), app_infos.at(2), params));
+ ASSERT_EQ(
+ backend.UninstallWithSubprocess(pkgids.at(0), params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+ ASSERT_EQ(
+ backend.UninstallWithSubprocess(pkgids.at(1), params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+ ASSERT_EQ(
+ backend.UninstallWithSubprocess(pkgids.at(2), params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+ } else {
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(CheckPackageNonExistance(pkgids.at(0), params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(CheckPackageNonExistance(pkgids.at(1), params));
+ params.pkg_type = PackageType::HYBRID;
+ ASSERT_TRUE(CheckPackageNonExistance(pkgids.at(2), params));
+ }
+}
+
+TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) {
+ RemoveAllRecoveryFiles("/unified-recovery", params.test_user.uid);
+ RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
+ RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
+
+ std::vector<bf::path> paths_old = {
+ kUnifiedSmokePackagesDirectory / "RecoveryTpkPkg.tpk",
+ kUnifiedSmokePackagesDirectory / "RecoveryWgtPkg.wgt",
+ kUnifiedSmokePackagesDirectory / "RecoveryHybridPkg.wgt" };
+ std::vector<bf::path> paths_new = {
+ kUnifiedSmokePackagesDirectory / "RecoveryTpkPkg2.tpk",
+ kUnifiedSmokePackagesDirectory / "RecoveryWgtPkg2.wgt",
+ kUnifiedSmokePackagesDirectory / "RecoveryHybridPkg2.wgt" };
+ std::vector<std::string> pkgids =
+ { "smokerec01", "smokerec02", "smokerec03" };
+ std::vector<Apps> app_infos = {
+ { {"smokerec01.RecoveryTpk", "native"} },
+ { {"smokerec02.RecoveryWgt", "smokerec02.RecoveryWgt"} },
+ {
+ {"smokerec03.RecoveryHybridUI", "smokerec03.RecoveryHybridUI"},
+ {"smokerec03.recoveryhybridservice", "recoveryhybridservice"},
+ }
+ };
+ int wait_time = delay + interval * test_count;
+
+ ASSERT_EQ(backend.
+ MountInstallPkgsWithSubprocess(paths_old, params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+
+ SmokeTestHelperRunner::Result ret =
+ backend.MountInstallPkgsWithSubprocessAndKill(
+ paths_new, params.test_user.uid, wait_time);
+ if (ret == SmokeTestHelperRunner::Result::SUCCESS) {
+ std::cout << "update finished before process killed" << std::endl;
+ return;
+ }
+ ASSERT_EQ(ret, SmokeTestHelperRunner::Result::KILLED);
+
+ bf::path recovery_file = FindRecoveryFile("/unified-recovery",
+ params.test_user.uid);
+ if (recovery_file.empty()) {
+ std::cout << "recovery file dosen't exist, "
+ "this test is skipped" << std::endl;
+ return;
+ }
+
+ UnifiedRecoveryInfo recovery_info(recovery_file);
+ ASSERT_TRUE(recovery_info.Init());
+ bf::remove(recovery_file);
+ const std::vector<bf::path>& recovery_list = recovery_info.GetRecoveryFiles();
+ if (recovery_list.empty()) {
+ std::cout << "installer recovery file is not created yet" << std::endl;
+ return;
+ }
+
+ // Filesystem may be mounted after crash
+ for (const std::string& pkgid : pkgids) {
+ ScopedTzipInterface poweroff_unmount_interface(pkgid, params.test_user.uid);
+ poweroff_unmount_interface.Release();
+ }
+
+ ASSERT_EQ(
+ backend.RecoveryPkgsWithSubprocess(recovery_list, params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+
+ ScopedTzipInterface interface_1(pkgids.at(0), params.test_user.uid);
+ ScopedTzipInterface interface_2(pkgids.at(1), params.test_user.uid);
+ ScopedTzipInterface interface_3(pkgids.at(2), params.test_user.uid);
+
+ if (recovery_info.GetCleanUp()) {
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(0), app_infos.at(0), params));
+ ASSERT_TRUE(ValidateFileContentInPackage(
+ pkgids.at(0), "res/VERSION", "2", params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(1), app_infos.at(1), params));
+ ASSERT_TRUE(ValidateFileContentInPackage(
+ pkgids.at(1), "res/wgt/VERSION", "2", params));
+ params.pkg_type = PackageType::HYBRID;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(2), app_infos.at(2), params));
+ ASSERT_TRUE(ValidateFileContentInPackage(
+ pkgids.at(2), "res/wgt/VERSION", "2", params));
+ } else {
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(0), app_infos.at(0), params));
+ ASSERT_TRUE(ValidateFileContentInPackage(
+ pkgids.at(0), "res/VERSION", "1", params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(1), app_infos.at(1), params));
+ ASSERT_TRUE(ValidateFileContentInPackage(
+ pkgids.at(1), "res/wgt/VERSION", "1", params));
+ params.pkg_type = PackageType::HYBRID;
+ ASSERT_TRUE(ValidatePackage(pkgids.at(2), app_infos.at(2), params));
+ ASSERT_TRUE(ValidateFileContentInPackage(
+ pkgids.at(2), "res/wgt/VERSION", "1", params));
+ }
+
+ ASSERT_EQ(
+ backend.UninstallWithSubprocess(pkgids.at(0), params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+ ASSERT_EQ(
+ backend.UninstallWithSubprocess(pkgids.at(1), params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+ ASSERT_EQ(
+ backend.UninstallWithSubprocess(pkgids.at(2), params.test_user.uid),
+ SmokeTestHelperRunner::Result::SUCCESS);
+}
+
+} // namespace smoke_test
+
+const int kBufSize = 1024;
+
+int main(int argc, char** argv) {
+ bool no_backup = false;
+ int repeat_count = 10;
+ ReqType req_type = ReqType::UNKNOWN_REQ;
+ bool repeat = false;
+ BackupType backup_type = BackupType::MOVE;
+ ci::RequestMode request_mode = smoke_test::ParseRequestMode(argc, argv);
+ if (getuid() != 0 || request_mode != ci::RequestMode::GLOBAL)
+ std::cout << "Run recovery test with user request mode" << std::endl;
+
+ bpo::options_description options("Allowed options");
+ bpo::variables_map opt_map;
+ try {
+ options.add_options()
+ ("help", "display this help message")
+ ("install",
+ "recovery test for forced termination "
+ "during package installing")
+ ("update",
+ "recovery test for forced termination "
+ "during package updating")
+ ("delta",
+ "recovery test for forced termination "
+ "during package delta installing")
+ ("mount-install",
+ "recovery test for forced termination "
+ "during package mount-installing")
+ ("mount-update",
+ "recovery test for forced termination "
+ "during package mount-updating")
+ ("delay", bpo::value<int>(), "fixed delay for forced termination\n"
+ "unit : microsecond (ex. 1000000us = 1s)")
+ ("interval", bpo::value<int>(),
+ "use with repeat option.\n"
+ "as it repeat the interval is added to delay\n"
+ "unit : microsecond (ex. 1000000us = 1s)")
+ ("repeat", bpo::value<int>(), "option for performing tests repeatedly\n"
+ "enter -1 to test infinitely")
+ ("no-backup", "Do test without backup")
+ ("backup-type", bpo::value<std::string>(), "<move|copy> set test's "
+ "backup type \'move\', \'copy and remove\'");
+ bpo::store(bpo::command_line_parser(argc, argv).
+ options(options).allow_unregistered().run(), opt_map);
+ if (opt_map.count("help")) {
+ std::cerr << options << std::endl;
+ return -1;
+ }
+
+ if (opt_map.count("install"))
+ req_type = ReqType::INSTALL_REQ;
+ else if (opt_map.count("update"))
+ req_type = ReqType::UPDATE_REQ;
+ else if (opt_map.count("delta"))
+ req_type = ReqType::DELTA_REQ;
+ else if (opt_map.count("mount-install"))
+ req_type = ReqType::MOUNT_INSTALL_REQ;
+ else if (opt_map.count("mount-update"))
+ req_type = ReqType::MOUNT_UPDATE_REQ;
+
+ if (opt_map.count("delay"))
+ delay = opt_map["delay"].as<int>();
+
+ if (opt_map.count("interval"))
+ interval = opt_map["interval"].as<int>();
+
+ if (opt_map.count("repeat")) {
+ repeat = true;
+ repeat_count = opt_map["repeat"].as<int>();
+ }
+
+ if (opt_map.count("no-backup"))
+ no_backup = true;
+ if (opt_map.count("backup-type")) {
+ if (opt_map["backup-type"].as<std::string>() == "move") {
+ backup_type = BackupType::MOVE;
+ } else if (opt_map["backup-type"].as<std::string>() == "copy") {
+ backup_type = BackupType::COPY_AND_REMOVE;
+ } else {
+ std::cerr << options << std::endl;
+ return -1;
+ }
+ }
+ bpo::notify(opt_map);
+ } catch (...) {
+ std::cerr << "Exception occurred: "
+ << boost::current_exception_diagnostic_information()
+ << std::endl;
+ return -1;
+ }
+
+ if (req_type == ReqType::UNKNOWN_REQ) {
+ std::cerr << options << std::endl;
+ return 0;
+ }
+
+ try {
+ testing::GTEST_FLAG(filter) = install_req_filter[req_type];
+ if (repeat) {
+ testing::GTEST_FLAG(repeat) = repeat_count;
+ testing::GTEST_FLAG(break_on_failure) = true;
+ }
+ testing::InitGoogleTest(&argc, argv);
+ ::env = static_cast<smoke_test::SmokeEnvironment*>(
+ testing::AddGlobalTestEnvironment(
+ new smoke_test::SmokeEnvironment(request_mode,
+ no_backup, backup_type)));
+ signal(SIGINT, ::signalHandler);
+ signal(SIGSEGV, ::signalHandler);
+ return RUN_ALL_TESTS();
+ } catch (...) {
+ std::cout << "Exception occurred during testing" << std::endl;
+ return 1;
+ }
+}