FIND_PACKAGE(GTest REQUIRED)
ADD_SUBDIRECTORY(src)
+ADD_SUBDIRECTORY(test)
ADD_SUBDIRECTORY(unified)
-ADD_SUBDIRECTORY(unit_tests)
+++ /dev/null
-SET(DESTINATION_DIR unified-installer-ut)
-SET(TARGET_SMOKE_UTILS smoke-utils)
-SET(TARGET_TPK_SMOKE_UTILS tpk-smoke-utils)
-SET(TARGET_WGT_SMOKE_UTILS wgt-smoke-utils)
-
-# Executables
-ADD_EXECUTABLE(${TARGET_SMOKE_TEST}
- smoke_test.cc
- smoke_utils.h
- smoke_utils.cc
-)
-
-ADD_EXECUTABLE(${TARGET_SMOKE_TEST_HELPER}
- smoke_test_helper.cc
-)
-
-TARGET_INCLUDE_DIRECTORIES(${TARGET_SMOKE_TEST} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)
-TARGET_INCLUDE_DIRECTORIES(${TARGET_SMOKE_TEST_HELPER} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)
-
-INSTALL(DIRECTORY test_samples/ DESTINATION ${SHAREDIR}/${DESTINATION_DIR}/test_samples)
-
-APPLY_PKG_CONFIG(${TARGET_SMOKE_TEST} PUBLIC
- Boost
- GTEST
- GUM_DEPS
-)
-
-# FindGTest module do not sets all needed libraries in GTEST_LIBRARIES and
-# GTest main libraries is still missing, so additional linking of
-# GTEST_MAIN_LIBRARIES is needed.
-TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST} PRIVATE ${TARGET_LIBNAME_UNIFIED} ${GTEST_MAIN_LIBRARIES} ${TARGET_SMOKE_UTILS} ${TARGET_TPK_SMOKE_UTILS} ${TARGET_WGT_SMOKE_UTILS})
-TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST_HELPER} PRIVATE ${TARGET_LIBNAME_UNIFIED} ${TARGET_TPK_SMOKE_UTILS} ${TARGET_WGT_SMOKE_UTILS})
-
-INSTALL(TARGETS ${TARGET_SMOKE_TEST} DESTINATION ${BINDIR}/${DESTINATION_DIR})
-INSTALL(TARGETS ${TARGET_SMOKE_TEST_HELPER} DESTINATION ${BINDIR}/${DESTINATION_DIR})
+++ /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 <common/utils/subprocess.h>
-
-#include <gtest/gtest.h>
-#include <gtest/gtest-death-test.h>
-
-#include "unit_tests/smoke_utils.h"
-
-namespace ci = common_installer;
-
-namespace smoke_test {
-
-class SmokeEnvironment : public testing::Environment {
- public:
- explicit SmokeEnvironment(ci::RequestMode mode) : request_mode_(mode) { }
-
- void SetUp() override {
- if (request_mode_ == ci::RequestMode::USER) {
- ASSERT_TRUE(AddTestUser(&test_user));
- }
- backups_ = SetupBackupDirectories(test_user.uid);
- for (auto& path : backups_)
- ASSERT_TRUE(BackupPath(path));
- }
- void TearDown() override {
- ASSERT_TRUE(request_mode_ == ci::RequestMode::GLOBAL ||
- (request_mode_ == ci::RequestMode::USER &&
- kGlobalUserUid != test_user.uid));
- BackendInterface::SmokeInstallerFactoryPtr factory(
- new UnifiedSmokeInstallerFactory());
- UnifiedBackendInterface backend(
- std::move(factory), std::to_string(test_user.uid));
- UninstallAllSmokeApps(request_mode_, test_user.uid, &backend);
- for (auto& path : backups_)
- ASSERT_TRUE(RestorePath(path));
- if (request_mode_ == ci::RequestMode::USER) {
- ASSERT_TRUE(DeleteTestUser());
- }
- }
- User test_user;
-
- private:
- ci::RequestMode request_mode_;
- std::vector<bf::path> backups_;
-};
-
-} // namespace smoke_test
-
-
-namespace {
-
-const char kSmokeTestHelperPath[] =
- "/usr/bin/unified-installer-ut/smoke-test-helper";
-
-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()
- : backend(BackendInterface::SmokeInstallerFactoryPtr(
- new UnifiedSmokeInstallerFactory()),
- std::to_string(env->test_user.uid)),
- params({PackageType::TPK, false}) {
- params.test_user.uid = env->test_user.uid;
- params.test_user.gid = env->test_user.gid;
- }
- protected:
- UnifiedBackendInterface backend;
- TestParameters params;
-};
-
-TEST_F(SmokeTest, Install_Single) {
- bf::path path =
- kUnifiedSmokePackagesDirectory / "Install_SingleTpk.tpk";
- std::string pkgid = "smokeuni01";
- std::string appid = "smokeuni01.InstallSingleTpk";
- std::string exec = "smokeunified";
-
- std::vector<bf::path> paths = { path };
- ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
- params.pkg_type = PackageType::TPK;
- ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
-}
-
-TEST_F(SmokeTest, Install_Double) {
- bf::path path1 =
- kUnifiedSmokePackagesDirectory / "Install_DoubleTpk.tpk";
- std::string pkgid1 = "smokeuni02";
- std::string appid1 = "smokeuni02.InstallDoubleTpk";
- std::string exec1 = "smokeunified";
- bf::path path2 =
- kUnifiedSmokePackagesDirectory / "Install_DoubleWgt.wgt";
- std::string pkgid2 = "smokeuni03";
- std::string appid2 = "smokeuni03.InstallDoubleWgt";
- std::string exec2 = "smokeuni03.InstallDoubleWgt";
-
- std::vector<bf::path> paths = { path1, path2 };
- ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
- params.pkg_type = PackageType::TPK;
- ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
- params.pkg_type = PackageType::WGT;
- ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
-}
-
-TEST_F(SmokeTest, Install_Triple) {
- bf::path path1 =
- kUnifiedSmokePackagesDirectory / "Install_TripleTpk.tpk";
- std::string pkgid1 = "smokeuni04";
- std::string appid1 = "smokeuni04.InstallTripleTpk";
- std::string exec1 = "smokeunified";
- bf::path path2 =
- kUnifiedSmokePackagesDirectory / "Install_TripleWgt.wgt";
- std::string pkgid2 = "smokeuni05";
- std::string appid2 = "smokeuni05.InstallTripleWgt";
- std::string exec2 = "smokeuni05.InstallTripleWgt";
- bf::path path3 =
- kUnifiedSmokePackagesDirectory / "Install_TripleHybrid.wgt";
- std::string pkgid3 = "smokeuni06";
- std::string appid3 = "smokeuni06.InstallTripleHybrid";
- std::string exec3 = "smokeuni06.InstallTripleHybrid";
-
- std::vector<bf::path> paths = { path1, path2, path3 };
- ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
- params.pkg_type = PackageType::TPK;
- ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
- params.pkg_type = PackageType::WGT;
- ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
- params.pkg_type = PackageType::HYBRID;
- ASSERT_TRUE(ValidatePackage(pkgid3, {appid3, exec3}, params));
-}
-
-TEST_F(SmokeTest, Update_Single) {
- bf::path path_old =
- kUnifiedSmokePackagesDirectory / "Update_SingleTpk.tpk";
- bf::path path_new =
- kUnifiedSmokePackagesDirectory / "Update_SingleTpk_2.tpk";
- std::string pkgid = "smokeuni07";
- std::string appid = "smokeuni07.UpdateSingleTpk";
- std::string exec = "smokeunified";
-
- std::vector<bf::path> paths = { path_old };
-// ASSERT_EQ(backend.InstallSuccess(paths), ci::AppInstaller::Result::OK);
- ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
- paths = { path_new };
- ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
- params.pkg_type = PackageType::TPK;
- ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
- ASSERT_TRUE(
- ValidateFileContentInPackage(pkgid, "res/VERSION", "2", params));
-}
-
-TEST_F(SmokeTest, Update_Double) {
- bf::path path1_old =
- kUnifiedSmokePackagesDirectory / "Update_DoubleTpk.tpk";
- bf::path path1_new =
- kUnifiedSmokePackagesDirectory / "Update_DoubleTpk_2.tpk";
- std::string pkgid1 = "smokeuni08";
- std::string appid1 = "smokeuni08.UpdateDoubleTpk";
- std::string exec1 = "smokeunified";
- bf::path path2_old =
- kUnifiedSmokePackagesDirectory / "Update_DoubleWgt.wgt";
- bf::path path2_new =
- kUnifiedSmokePackagesDirectory / "Update_DoubleWgt_2.wgt";
- std::string pkgid2 = "smokeuni09";
- std::string appid2 = "smokeuni09.UpdateDoubleWgt";
- std::string exec2 = "smokeuni09.UpdateDoubleWgt";
-
- std::vector<bf::path> paths = { path1_old, path2_old };
-// ASSERT_EQ(backend.InstallSuccess(paths), ci::AppInstaller::Result::OK);
- ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
- paths = { path1_new, path2_new };
- ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
- params.pkg_type = PackageType::TPK;
- ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
- params.pkg_type = PackageType::WGT;
- ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
- ASSERT_TRUE(
- ValidateFileContentInPackage(pkgid1, "res/VERSION", "2", params));
- ASSERT_TRUE(
- ValidateFileContentInPackage(pkgid2, "res/wgt/VERSION", "2", params));
-}
-
-TEST_F(SmokeTest, Update_Triple) {
- bf::path path1_old =
- kUnifiedSmokePackagesDirectory / "Update_TripleTpk.tpk";
- bf::path path1_new =
- kUnifiedSmokePackagesDirectory / "Update_TripleTpk_2.tpk";
- std::string pkgid1 = "smokeuni10";
- std::string appid1 = "smokeuni10.UpdateTripleTpk";
- std::string exec1 = "smokeunified";
- bf::path path2_old =
- kUnifiedSmokePackagesDirectory / "Update_TripleWgt.wgt";
- bf::path path2_new =
- kUnifiedSmokePackagesDirectory / "Update_TripleWgt_2.wgt";
- std::string pkgid2 = "smokeuni11";
- std::string appid2 = "smokeuni11.UpdateTripleWgt";
- std::string exec2 = "smokeuni11.UpdateTripleWgt";
- bf::path path3_old =
- kUnifiedSmokePackagesDirectory / "Update_TripleHybrid.wgt";
- bf::path path3_new =
- kUnifiedSmokePackagesDirectory / "Update_TripleHybrid_2.wgt";
- std::string pkgid3 = "smokeuni12";
- std::string appid3 = "smokeuni12.UpdateTripleHybrid";
- std::string exec3 = "smokeuni12.UpdateTripleHybrid";
-
- std::vector<bf::path> paths = { path1_old, path2_old, path3_old };
-// ASSERT_EQ(backend.InstallSuccess(paths), ci::AppInstaller::Result::OK);
- ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
- paths = { path1_new, path2_new, path3_new };
- ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
- params.pkg_type = PackageType::TPK;
- ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
- params.pkg_type = PackageType::WGT;
- ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
- params.pkg_type = PackageType::HYBRID;
- ASSERT_TRUE(ValidatePackage(pkgid3, {appid3, exec3}, params));
- ASSERT_TRUE(
- ValidateFileContentInPackage(pkgid1, "res/VERSION", "2", params));
- ASSERT_TRUE(
- ValidateFileContentInPackage(pkgid2, "res/wgt/VERSION", "2", params));
- ASSERT_TRUE(
- ValidateFileContentInPackage(pkgid3, "res/wgt/VERSION", "2", params));
-}
-
-TEST_F(SmokeTest, InstallAndUpdate) {
- bf::path path1_old =
- kUnifiedSmokePackagesDirectory / "InstallAndUpdate_Tpk.tpk";
- bf::path path1_new =
- kUnifiedSmokePackagesDirectory / "InstallAndUpdate_Tpk_2.tpk";
- std::string pkgid1 = "smokeuni13";
- std::string appid1 = "smokeuni13.InstallAndUpdateModeTpk";
- std::string exec1 = "smokeunified";
- bf::path path2 =
- kUnifiedSmokePackagesDirectory / "InstallAndUpdate_Wgt.wgt";
- std::string pkgid2 = "smokeuni14";
- std::string appid2 = "smokeuni14.InstallAndUpdateWgt";
- std::string exec2 = "smokeuni14.InstallAndUpdateWgt";
-
- // install tpk version 1
- std::vector<bf::path> paths = { path1_old };
- ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
- // update tpk version 2, install wgt version 1
- paths = { path1_new, path2 };
- ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
- params.pkg_type = PackageType::TPK;
- ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
- params.pkg_type = PackageType::WGT;
- ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
- ASSERT_TRUE(
- ValidateFileContentInPackage(pkgid1, "res/VERSION", "2", params));
-}
-
-TEST_F(SmokeTest, InstallAndROUpdate) {
- bf::path path1_old =
- kUnifiedSmokePackagesDirectory / "InstallAndROUpdate_Tpk.tpk";
- bf::path path1_new =
- kUnifiedSmokePackagesDirectory / "InstallAndROUpdate_Tpk_2.tpk";
- std::string pkgid1 = "smokeuni25";
- std::string appid1 = "smokeuni25.InstallAndROUpdateModeTpk";
- std::string exec1 = "smokeunified";
- bf::path path2 =
- kUnifiedSmokePackagesDirectory / "InstallAndROUpdate_Wgt.wgt";
- std::string pkgid2 = "smokeuni26";
- std::string appid2 = "smokeuni26.InstallAndROUpdateWgt";
- std::string exec2 = "smokeuni26.InstallAndROUpdateWgt";
-
- // install tpk version 1
- ASSERT_EQ(backend.InstallPreload(path1_old), ci::AppInstaller::Result::OK);
- // update tpk version 2, install wgt version 1
- std::vector<bf::path> paths = { path1_new, path2 };
- ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
- params.pkg_type = PackageType::TPK;
- ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
- params.pkg_type = PackageType::WGT;
- ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
- ASSERT_TRUE(
- ValidateFileContentInPackage(pkgid1, "res/VERSION", "2", params));
-}
-
-TEST_F(SmokeTest, Uninstall_Single) {
- bf::path path =
- kUnifiedSmokePackagesDirectory / "Uninstall_SingleTpk.tpk";
- std::string pkgid = "smokeuni29";
- std::string appid = "smokeuni29.UninstallSingleTpk";
- std::string exec = "smokeunified";
-
- std::vector<bf::path> paths = { path };
- ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
- params.pkg_type = PackageType::TPK;
- ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
- std::vector<std::string> pkgids = { pkgid };
- ASSERT_EQ(backend.Uninstall(pkgids), ci::AppInstaller::Result::OK);
- ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
-}
-
-TEST_F(SmokeTest, Uninstall_Double) {
- bf::path path1 =
- kUnifiedSmokePackagesDirectory / "Uninstall_DoubleTpk.tpk";
- std::string pkgid1 = "smokeuni30";
- std::string appid1 = "smokeuni30.UninstallDoubleTpk";
- std::string exec1 = "smokeunified";
- bf::path path2 =
- kUnifiedSmokePackagesDirectory / "Uninstall_DoubleWgt.wgt";
- std::string pkgid2 = "smokeuni31";
- std::string appid2 = "smokeuni31.UninstallDoubleWgt";
- std::string exec2 = "smokeuni31.UninstallDoubleWgt";
-
- std::vector<bf::path> paths = { path1, path2 };
- ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
- params.pkg_type = PackageType::TPK;
- ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
- params.pkg_type = PackageType::WGT;
- ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
- std::vector<std::string> pkgids = { pkgid1, pkgid2 };
- ASSERT_EQ(backend.Uninstall(pkgids), ci::AppInstaller::Result::OK);
- ASSERT_TRUE(CheckPackageNonExistance(pkgid1, params));
- ASSERT_TRUE(CheckPackageNonExistance(pkgid2, params));
-}
-
-TEST_F(SmokeTest, Uninstall_Triple) {
- bf::path path1 =
- kUnifiedSmokePackagesDirectory / "Uninstall_TripleTpk.tpk";
- std::string pkgid1 = "smokeuni32";
- std::string appid1 = "smokeuni32.UninstallTripleTpk";
- std::string exec1 = "smokeunified";
- bf::path path2 =
- kUnifiedSmokePackagesDirectory / "Uninstall_TripleWgt.wgt";
- std::string pkgid2 = "smokeuni33";
- std::string appid2 = "smokeuni33.UninstallTripleWgt";
- std::string exec2 = "smokeuni33.UninstallTripleWgt";
- bf::path path3 =
- kUnifiedSmokePackagesDirectory / "Uninstall_TripleHybrid.wgt";
- std::string pkgid3 = "smokeuni34";
- std::string appid3 = "smokeuni34.UninstallTripleHybrid";
- std::string exec3 = "smokeuni34.UninstallTripleHybrid";
-
- std::vector<bf::path> paths = { path1, path2, path3 };
- ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
- params.pkg_type = PackageType::TPK;
- ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
- params.pkg_type = PackageType::WGT;
- ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
- params.pkg_type = PackageType::HYBRID;
- ASSERT_TRUE(ValidatePackage(pkgid3, {appid3, exec3}, params));
- std::vector<std::string> pkgids = { pkgid1, pkgid2, pkgid3 };
- ASSERT_EQ(backend.Uninstall(pkgids), ci::AppInstaller::Result::OK);
- ASSERT_TRUE(CheckPackageNonExistance(pkgid1, params));
- ASSERT_TRUE(CheckPackageNonExistance(pkgid2, params));
- ASSERT_TRUE(CheckPackageNonExistance(pkgid3, params));
-}
-
-TEST_F(SmokeTest, UninstallAndROUpdateUninstall) {
- bf::path path1_old =
- kUnifiedSmokePackagesDirectory / "UninstallAndROUpdateUninstall_Tpk.tpk";
- bf::path path1_new =
- kUnifiedSmokePackagesDirectory /
- "UninstallAndROUpdateUninstall_Tpk_2.tpk";
- std::string pkgid1 = "smokeuni35";
- std::string appid1 = "smokeuni35.UninstallAndROUpdateUninstallTpk";
- std::string exec1 = "smokeunified";
- bf::path path2 =
- kUnifiedSmokePackagesDirectory / "UninstallAndROUpdateUninstall_Wgt.wgt";
- std::string pkgid2 = "smokeuni36";
- std::string appid2 = "smokeuni36.UninstallAndROUpdateUninstallWgt";
- std::string exec2 = "smokeuni36.UninstallAndROUpdateUninstallWgt";
-
- // install tpk version 1
- ASSERT_EQ(backend.InstallPreload(path1_old), ci::AppInstaller::Result::OK);
- ci::PkgQueryInterface pkg_query1(pkgid1, params.test_user.uid);
- PackageAttributes original(pkg_query1);
- // update tpk version 2, install wgt version 1
- std::vector<bf::path> paths = { path1_new, path2 };
- ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
- params.pkg_type = PackageType::TPK;
- ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
- params.pkg_type = PackageType::WGT;
- ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
- ASSERT_TRUE(
- ValidateFileContentInPackage(pkgid1, "res/VERSION", "2", params));
- // uninstall
- std::vector<std::string> pkgids = { pkgid1, pkgid2 };
- ASSERT_EQ(backend.Uninstall(pkgids), ci::AppInstaller::Result::OK);
- ci::PkgQueryInterface pkg_query2(pkgid1, params.test_user.uid, true);
- PackageAttributes restored(pkg_query2);
- ASSERT_EQ(original, restored);
- ASSERT_TRUE(CheckPackageNonExistance(pkgid2, params));
- params.pkg_type = PackageType::TPK;
- params.is_readonly = true;
- ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
- ASSERT_TRUE(
- ValidateFileContentInPackage(pkgid1, "res/VERSION", "1", params));
-}
-
-class RollbackSmokeTest : public testing::Test {
- public:
- RollbackSmokeTest()
- : backend(BackendInterface::SmokeInstallerFactoryPtr(
- new UnifiedSmokeInstallerFactory()),
- std::to_string(env->test_user.uid),
- RequestResult::FAIL),
- params({PackageType::TPK, false}) {
- params.test_user.uid = env->test_user.uid;
- params.test_user.gid = env->test_user.gid;
- }
- protected:
- UnifiedBackendInterface backend;
- TestParameters params;
-};
-
-TEST_F(RollbackSmokeTest, Install_Rollback) {
- bf::path path1 =
- kUnifiedSmokePackagesDirectory / "Install_RollbackTpk.tpk";
- std::string pkgid1 = "smokeuni15";
- std::string appid1 = "smokeuni15.InstallRollbackTpk";
- std::string exec1 = "smokeunified";
- bf::path path2 =
- kUnifiedSmokePackagesDirectory / "Install_RollbackWgt.wgt";
- std::string pkgid2 = "smokeuni16";
- std::string appid2 = "smokeuni16.InstallRollbackWgt";
- std::string exec2 = "smokeuni16.InstallRollbackWgt";
-
- std::vector<bf::path> paths = { path1, path2 };
- ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::ERROR);
- params.pkg_type = PackageType::TPK;
- ASSERT_TRUE(CheckPackageNonExistance(pkgid1, params));
- params.pkg_type = PackageType::WGT;
- ASSERT_TRUE(CheckPackageNonExistance(pkgid2, params));
-}
-
-TEST_F(RollbackSmokeTest, Update_Rollback) {
- bf::path path1_old =
- kUnifiedSmokePackagesDirectory / "Update_RollbackTpk.tpk";
- bf::path path1_new =
- kUnifiedSmokePackagesDirectory / "Update_RollbackTpk_2.tpk";
- std::string pkgid1 = "smokeuni17";
- std::string appid1 = "smokeuni17.UpdateRollbackTpk";
- std::string exec1 = "smokeunified";
- bf::path path2_old =
- kUnifiedSmokePackagesDirectory / "Update_RollbackWgt.wgt";
- bf::path path2_new =
- kUnifiedSmokePackagesDirectory / "Update_RollbackWgt_2.wgt";
- std::string pkgid2 = "smokeuni18";
- std::string appid2 = "smokeuni18.UpdateRollbackWgt";
- std::string exec2 = "smokeuni18.UpdateRollbackWgt";
-
- std::vector<bf::path> paths = { path1_old, path2_old };
- ASSERT_EQ(backend.InstallSuccess(paths), ci::AppInstaller::Result::OK);
- paths = { path1_new, path2_new };
- ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::ERROR);
-
- params.pkg_type = PackageType::TPK;
- ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
- params.pkg_type = PackageType::WGT;
- ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
- ASSERT_TRUE(
- ValidateFileContentInPackage(pkgid1, "res/VERSION", "1", params));
- ASSERT_TRUE(
- ValidateFileContentInPackage(pkgid2, "res/wgt/VERSION", "1", params));
-}
-
-TEST_F(RollbackSmokeTest, InstallAndUpdate_Rollback) {
- bf::path path1 =
- kUnifiedSmokePackagesDirectory / "InstallAndUpdate_RollbackTpk.tpk";
- std::string pkgid1 = "smokeuni19";
- std::string appid1 = "smokeuni19.InstallAndUpdateRollbackTpk";
- std::string exec1 = "smokeunified";
- bf::path path2_old =
- kUnifiedSmokePackagesDirectory / "InstallAndUpdate_RollbackWgt.wgt";
- bf::path path2_new =
- kUnifiedSmokePackagesDirectory / "InstallAndUpdate_RollbackWgt_2.wgt";
- std::string pkgid2 = "smokeuni20";
- std::string appid2 = "smokeuni20.InstallAndUpdateRollbackWgt";
- std::string exec2 = "smokeuni20.InstallAndUpdateRollbackWgt";
-
- std::vector<bf::path> paths = { path2_old };
- ASSERT_EQ(backend.InstallSuccess(paths), ci::AppInstaller::Result::OK);
- // pkgid1: install, pkgid2: update
- paths = { path1, path2_new };
- ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::ERROR);
-
- params.pkg_type = PackageType::TPK;
- ASSERT_TRUE(CheckPackageNonExistance(pkgid1, params));
- params.pkg_type = PackageType::WGT;
- ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
- ASSERT_TRUE(
- ValidateFileContentInPackage(pkgid2, "res/wgt/VERSION", "1", params));
-}
-
-TEST_F(RollbackSmokeTest, InstallAndROUpdate_Rollback) {
- bf::path path1 =
- kUnifiedSmokePackagesDirectory / "InstallAndROUpdate_RollbackTpk.tpk";
- std::string pkgid1 = "smokeuni27";
- std::string appid1 = "smokeuni27.InstallAndROUpdateRollbackTpk";
- std::string exec1 = "smokeunified";
- bf::path path2_old =
- kUnifiedSmokePackagesDirectory / "InstallAndROUpdate_RollbackWgt.wgt";
- bf::path path2_new =
- kUnifiedSmokePackagesDirectory / "InstallAndROUpdate_RollbackWgt_2.wgt";
- std::string pkgid2 = "smokeuni28";
- std::string appid2 = "smokeuni28.InstallAndROUpdateRollbackWgt";
- std::string exec2 = "smokeuni28.InstallAndROUpdateRollbackWgt";
-
- ASSERT_EQ(backend.InstallPreloadSuccess(path2_old),
- ci::AppInstaller::Result::OK);
- // pkgid1: install, pkgid2: update
- std::vector<bf::path> paths = { path1, path2_new };
- ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::ERROR);
- params.pkg_type = PackageType::TPK;
- ASSERT_TRUE(CheckPackageNonExistance(pkgid1, params));
- params.pkg_type = PackageType::WGT;
- params.is_readonly = true;
- ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
- ASSERT_TRUE(
- ValidateFileContentInPackage(pkgid2, "res/wgt/VERSION", "1", params));
-}
-
-TEST_F(SmokeTest, Recovery_Install) {
- bf::path path1 =
- kUnifiedSmokePackagesDirectory / "Recovery_InstallTpk.tpk";
- std::string pkgid1 = "smokeuni21";
- std::string appid1 = "smokeuni21.RecoveryInstallTpk";
- std::string exec1 = "smokeunified";
- bf::path path2 =
- kUnifiedSmokePackagesDirectory / "Recovery_InstallWgt.wgt";
- std::string pkgid2 = "smokeuni22";
- std::string appid2 = "smokeuni22.RecoveryInstallWgt";
- std::string exec2 = "smokeuni22.RecoveryInstallWgt";
-
- std::vector<std::string> paths = { path1.string(), path2.string() };
- ci::Subprocess backend_crash(kSmokeTestHelperPath);
- std::string test_uid_str = std::to_string(params.test_user.uid);
- std::vector<std::string> argv = { "-u", test_uid_str, "-i" };
- argv.insert(argv.end(), paths.begin(), paths.end());
- backend_crash.Run(argv);
- ASSERT_NE(backend_crash.Wait(), 0);
-
- bf::path recovery_file =
- FindRecoveryFile("/tpk-recovery", params.test_user.uid);
- ASSERT_FALSE(recovery_file.empty());
- std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
- GetRecoverFileInfo(recovery_file);
- ASSERT_TRUE(recovery_info);
- ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
- params.pkg_type = PackageType::TPK;
- ASSERT_TRUE(CheckPackageNonExistance(pkgid1, params));
- ASSERT_FALSE(bf::exists(recovery_info->unpacked_dir()));
-
- recovery_file =
- FindRecoveryFile("/wgt-recovery", params.test_user.uid);
- ASSERT_FALSE(recovery_file.empty());
- recovery_info.reset();
- recovery_info = GetRecoverFileInfo(recovery_file);
- ASSERT_TRUE(recovery_info);
- ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
- params.pkg_type = PackageType::WGT;
- ASSERT_TRUE(CheckPackageNonExistance(pkgid2, params));
- ASSERT_FALSE(bf::exists(recovery_info->unpacked_dir()));
-}
-
-TEST_F(SmokeTest, Recovery_Update) {
- bf::path path1_old =
- kUnifiedSmokePackagesDirectory / "Recovery_UpdateTpk.tpk";
- bf::path path1_new =
- kUnifiedSmokePackagesDirectory / "Recovery_UpdateTpk_2.tpk";
- std::string pkgid1 = "smokeuni23";
- std::string appid1 = "smokeuni23.RecoveryUpdateTpk";
- std::string exec1 = "smokeunified";
- bf::path path2_old =
- kUnifiedSmokePackagesDirectory / "Recovery_UpdateWgt.wgt";
- bf::path path2_new =
- kUnifiedSmokePackagesDirectory / "Recovery_UpdateWgt_2.wgt";
- std::string pkgid2 = "smokeuni24";
- std::string appid2 = "smokeuni24.RecoveryUpdateWgt";
- std::string exec2 = "smokeuni24.RecoveryUpdateWgt";
-
- std::vector<bf::path> paths_old = { path1_old, path2_old };
- ASSERT_EQ(backend.Install(paths_old), ci::AppInstaller::Result::OK);
-
- std::vector<std::string> paths = { path1_new.string(), path2_new.string() };
- ci::Subprocess backend_crash(kSmokeTestHelperPath);
- std::string test_uid_str = std::to_string(params.test_user.uid);
- std::vector<std::string> argv = { "-u", test_uid_str, "-i" };
- argv.insert(argv.end(), paths.begin(), paths.end());
- backend_crash.Run(argv);
- ASSERT_NE(backend_crash.Wait(), 0);
-
- bf::path recovery_file =
- FindRecoveryFile("/tpk-recovery", params.test_user.uid);
- ASSERT_FALSE(recovery_file.empty());
- std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
- GetRecoverFileInfo(recovery_file);
- ASSERT_TRUE(recovery_info);
- ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
- params.pkg_type = PackageType::TPK;
- ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
- ASSERT_TRUE(
- ValidateFileContentInPackage(pkgid1, "res/VERSION", "1", params));
-
- recovery_file =
- FindRecoveryFile("/wgt-recovery", params.test_user.uid);
- ASSERT_FALSE(recovery_file.empty());
- recovery_info.reset();
- recovery_info = GetRecoverFileInfo(recovery_file);
- ASSERT_TRUE(recovery_info);
- ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
- params.pkg_type = PackageType::WGT;
- ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
- ASSERT_TRUE(
- ValidateFileContentInPackage(pkgid2, "res/wgt/VERSION", "1", params));
-}
-
-} // namespace smoke_test
-
-int main(int argc, char** argv) {
- try {
- ci::RequestMode request_mode = smoke_test::ParseRequestMode(argc, argv);
- if (getuid() != 0 || request_mode != ci::RequestMode::GLOBAL) {
- std::cout << "Skip tests for preload request" << std::endl;
- ::testing::GTEST_FLAG(filter) = "SmokeTest.*";
- }
- testing::InitGoogleTest(&argc, argv);
- ::env = static_cast<smoke_test::SmokeEnvironment*>(
- testing::AddGlobalTestEnvironment(
- new smoke_test::SmokeEnvironment(request_mode)));
- signal(SIGINT, ::signalHandler);
- signal(SIGSEGV, ::signalHandler);
- return RUN_ALL_TESTS();
- } catch (...) {
- std::cout << "Exception occurred during testing" << std::endl;
- return -1;
- }
-}
+++ /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 <common/installer_factory.h>
-#include <common/installer_runner.h>
-#include <common/pkgmgr_interface.h>
-#include <tpk/tpk_app_query_interface.h>
-#include <unit_tests/common/smoke_utils.h>
-#include <unit_tests/tpk_smoke_utils.h>
-#include <unit_tests/wgt_smoke_utils.h>
-#include <wgt/utils/wgt_app_query_interface.h>
-
-#include <algorithm>
-#include <memory>
-#include <string>
-
-namespace ci = common_installer;
-
-namespace {
-
-bool EndsWith(const std::string str, const std::string& to_match) {
- if (to_match.size() > str.size())
- return false;
- return std::equal(to_match.rbegin(), to_match.rend(), str.rbegin());
-}
-
-#if __cplusplus < 201300L
-template<typename T, typename... Args>
-std::unique_ptr<T> make_unique(Args&&... args) {
- return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
-}
-#endif
-
-} // namespace
-
-class CrashInstallerFactory : public ci::InstallerFactory {
- public:
- std::unique_ptr<ci::AppInstaller> CreateInstaller(ci::PkgMgrPtr pkgmgr,
- int idx) override {
- std::string type =
- EndsWith(pkgmgr->GetRequestInfo(idx), "tpk") ? "tpk" : "wgt";
- int n_pkgs = pkgmgr->GetRequestInfoCount();
- std::unique_ptr<ci::AppInstaller> installer;
- if (type == "tpk") {
- tpk::TpkAppQueryInterface* tpk_aqi = new tpk::TpkAppQueryInterface();
- pkgmgr->AddAppQueryInterface(idx, tpk_aqi);
- installer.reset(
- idx + 1 == n_pkgs ?
- new smoke_test::CrashTpkInstaller(pkgmgr, -1, {},
- smoke_test::CrashStepType::PROCESS) :
- new tpk::TpkInstaller(pkgmgr));
-
- } else {
- wgt::WgtAppQueryInterface* wgt_aqi = new wgt::WgtAppQueryInterface();
- pkgmgr->AddAppQueryInterface(idx, wgt_aqi);
- installer.reset(
- idx + 1 == n_pkgs ?
- new smoke_test::CrashWgtInstaller(pkgmgr, -1, {},
- smoke_test::CrashStepType::PROCESS) :
- new wgt::WgtInstaller(pkgmgr));
- }
- installer->SetIndex(idx);
- return installer;
- }
-};
-
-int main(int argc, char** argv) {
- ci::PkgmgrInstaller pkgmgr_installer;
- auto pkgmgr = ci::PkgMgrInterface::Create(argc, argv, &pkgmgr_installer);
-
-#if __cplusplus >= 201300L
- using std;
-#endif
- ci::InstallerRunner runner(make_unique<CrashInstallerFactory>(), pkgmgr);
- ci::AppInstaller::Result result = runner.Run();
-
- return (result == ci::AppInstaller::Result::OK) ? 0 : 1;
-}
+++ /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 "unit_tests/smoke_utils.h"
-
-#include <unit_tests/common/smoke_utils.h>
-#include <unit_tests/tpk_smoke_utils.h>
-#include <unit_tests/wgt_smoke_utils.h>
-#include <unzip.h>
-
-#include <map>
-#include <string>
-
-namespace bf = boost::filesystem;
-namespace ci = common_installer;
-
-namespace {
-
-std::map<const char*, const char*> kTypeMap = {
- {"res/wgt/config.xml", "wgt"},
- {"config.xml", "wgt"},
- {"tizen-manifest.xml", "tpk"},
-};
-
-std::string GetPkgTypeFromPkgid(const std::string& pkgid, uid_t uid) {
- ci::PkgQueryInterface query(pkgid, uid);
- return query.Type();
-}
-
-std::string GetPkgTypeFromPath(const std::string& path) {
- std::string type;
- unzFile uf = unzOpen(path.c_str());
- if (!uf) {
- LOG(ERROR) << "Failed to open zip file: " << path;
- return type;
- }
- for (auto it : kTypeMap) {
- if (unzLocateFile(uf, it.first, 0) == UNZ_OK) {
- LOG(DEBUG) << "Found: " << it.first;
- type = it.second;
- break;
- }
- }
- if (type.empty())
- LOG(ERROR) << "Cannot get pkg type";
- unzClose(uf);
- return type;
-}
-
-std::string GetPkgTypeFromRecoveryFile(const std::string& path) {
- bf::path recovery_file = path;
- if (recovery_file.filename().string().find("tpk") == 0)
- return "tpk";
- else if (recovery_file.filename().string().find("wgt") == 0)
- return "wgt";
- return {};
-}
-
-std::string GetPkgType(const std::string& pkginfo, uid_t uid) {
- std::string type = GetPkgTypeFromPkgid(pkginfo, uid);
- if (type.empty())
- type = GetPkgTypeFromPath(pkginfo);
- // recovery file
- if (type.empty())
- type = GetPkgTypeFromRecoveryFile(pkginfo);
- return type;
-}
-
-} // namespace
-
-namespace smoke_test {
-
-UnifiedSmokeInstallerFactory::AppInstallerPtr
-UnifiedSmokeInstallerFactory::CreateInstaller(
- int idx, ci::PkgMgrPtr pkgmgr) const {
- std::string type = GetPkgType(pkgmgr->GetRequestInfo(idx), pkgmgr->GetUid());
- if (type.empty())
- return {};
-
- std::unique_ptr<ci::AppInstaller> installer;
- if (type == "tpk") {
- tpk::TpkAppQueryInterface* tpk_aqi = new tpk::TpkAppQueryInterface();
- pkgmgr->AddAppQueryInterface(idx, tpk_aqi);
- installer.reset(new tpk::TpkInstaller(pkgmgr));
- } else {
- wgt::WgtAppQueryInterface* wgt_aqi = new wgt::WgtAppQueryInterface();
- pkgmgr->AddAppQueryInterface(idx, wgt_aqi);
- if (wgt_aqi->IsHybridApplication(pkgmgr->GetRequestInfo(idx),
- pkgmgr->GetUid())) {
- LOG(INFO) << "Hybrid package detected";
- installer.reset(new hybrid::HybridInstaller(pkgmgr));
- } else {
- installer.reset(new wgt::WgtInstaller(pkgmgr));
- }
- }
-
- installer->SetIndex(idx);
-
- return installer;
-}
-
-UnifiedSmokeInstallerFactory::AppInstallerPtr
-UnifiedSmokeInstallerFactory::CreateFailExpectedInstaller(
- int idx, ci::PkgMgrPtr pkgmgr, int fail_at) const {
- std::string type = GetPkgType(pkgmgr->GetRequestInfo(idx), pkgmgr->GetUid());
- if (type.empty())
- return {};
-
- std::unique_ptr<ci::AppInstaller> installer;
- if (type == "tpk") {
- tpk::TpkAppQueryInterface* tpk_aqi = new tpk::TpkAppQueryInterface();
- pkgmgr->AddAppQueryInterface(idx, tpk_aqi);
- installer.reset(new smoke_test::FailExpectedTpkInstaller(pkgmgr, fail_at));
- } else {
- wgt::WgtAppQueryInterface* wgt_aqi = new wgt::WgtAppQueryInterface();
- pkgmgr->AddAppQueryInterface(idx, wgt_aqi);
- if (wgt_aqi->IsHybridApplication(pkgmgr->GetRequestInfo(idx),
- pkgmgr->GetUid())) {
- LOG(INFO) << "Hybrid package detected";
- installer.reset(
- new smoke_test::FailExpectedHybridInstaller(pkgmgr, fail_at));
- } else {
- installer.reset(
- new smoke_test::FailExpectedWgtInstaller(pkgmgr, fail_at));
- }
- }
-
- installer->SetIndex(idx);
-
- return installer;
-}
-
-UnifiedBackendInterface::AppQueryInterfacePtr
-UnifiedBackendInterface::CreateQueryInterface() const {
- // this is not used
- return {};
-}
-
-UnifiedBackendInterface::AppInstallerPtr
-UnifiedBackendInterface::CreateInstaller(ci::PkgMgrPtr pkgmgr) const {
- return factory_->CreateInstaller(0, pkgmgr);
-}
-
-UnifiedBackendInterface::AppInstallerPtr
-UnifiedBackendInterface::CreateFailExpectedInstaller(
- ci::PkgMgrPtr pkgmgr, int fail_at) const {
- return factory_->CreateFailExpectedInstaller(0, pkgmgr, fail_at);;
-}
-
-} // namespace smoke_test
+++ /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.
-
-#ifndef UNIT_TESTS_SMOKE_UTILS_H_
-#define UNIT_TESTS_SMOKE_UTILS_H_
-
-#include <common/installer/app_installer.h>
-#include <common/pkgmgr_interface.h>
-#include <unit_tests/common/smoke_utils.h>
-#include <unit_tests/tpk_smoke_utils.h>
-
-namespace smoke_test {
-
-class UnifiedSmokeInstallerFactory : public SmokeInstallerFactory {
- public:
- AppInstallerPtr CreateInstaller(
- int idx, common_installer::PkgMgrPtr pkgmgr) const override;
- AppInstallerPtr CreateFailExpectedInstaller(
- int idx, common_installer::PkgMgrPtr pkgmgr, int fail_at) const override;
-};
-
-class UnifiedBackendInterface : public BackendInterface {
- public:
- using BackendInterface::BackendInterface;
-
- AppQueryInterfacePtr CreateQueryInterface() const override;
- AppInstallerPtr CreateInstaller(
- common_installer::PkgMgrPtr pkgmgr) const override;
- AppInstallerPtr CreateFailExpectedInstaller(
- common_installer::PkgMgrPtr pkgmgr, int fail_at) const override;
-};
-
-} // namespace smoke_test
-
-#endif // UNIT_TESTS_SMOKE_UTILS_H_
--- /dev/null
+ADD_SUBDIRECTORY(smoke_test)
--- /dev/null
+SET(DESTINATION_DIR unified-installer-ut)
+SET(TARGET_SMOKE_UTILS smoke-utils)
+SET(TARGET_TPK_SMOKE_UTILS tpk-smoke-utils)
+SET(TARGET_WGT_SMOKE_UTILS wgt-smoke-utils)
+
+# Executables
+ADD_EXECUTABLE(${TARGET_SMOKE_TEST}
+ smoke_test.cc
+ smoke_utils.h
+ smoke_utils.cc
+)
+
+ADD_EXECUTABLE(${TARGET_SMOKE_TEST_HELPER}
+ smoke_test_helper.cc
+)
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_SMOKE_TEST} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)
+TARGET_INCLUDE_DIRECTORIES(${TARGET_SMOKE_TEST_HELPER} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)
+
+INSTALL(DIRECTORY test_samples/ DESTINATION ${SHAREDIR}/${DESTINATION_DIR}/test_samples)
+
+APPLY_PKG_CONFIG(${TARGET_SMOKE_TEST} PUBLIC
+ Boost
+ GTEST
+ GUM_DEPS
+)
+
+# FindGTest module do not sets all needed libraries in GTEST_LIBRARIES and
+# GTest main libraries is still missing, so additional linking of
+# GTEST_MAIN_LIBRARIES is needed.
+TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST} PRIVATE ${TARGET_LIBNAME_UNIFIED} ${GTEST_MAIN_LIBRARIES} ${TARGET_SMOKE_UTILS} ${TARGET_TPK_SMOKE_UTILS} ${TARGET_WGT_SMOKE_UTILS})
+TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST_HELPER} PRIVATE ${TARGET_LIBNAME_UNIFIED} ${TARGET_TPK_SMOKE_UTILS} ${TARGET_WGT_SMOKE_UTILS})
+
+INSTALL(TARGETS ${TARGET_SMOKE_TEST} DESTINATION ${BINDIR}/${DESTINATION_DIR})
+INSTALL(TARGETS ${TARGET_SMOKE_TEST_HELPER} DESTINATION ${BINDIR}/${DESTINATION_DIR})
--- /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 <common/utils/subprocess.h>
+
+#include <gtest/gtest.h>
+#include <gtest/gtest-death-test.h>
+
+#include "smoke_test/smoke_utils.h"
+
+namespace ci = common_installer;
+
+namespace smoke_test {
+
+class SmokeEnvironment : public testing::Environment {
+ public:
+ explicit SmokeEnvironment(ci::RequestMode mode) : request_mode_(mode) { }
+
+ void SetUp() override {
+ if (request_mode_ == ci::RequestMode::USER) {
+ ASSERT_TRUE(AddTestUser(&test_user));
+ }
+ backups_ = SetupBackupDirectories(test_user.uid);
+ for (auto& path : backups_)
+ ASSERT_TRUE(BackupPath(path));
+ }
+ void TearDown() override {
+ ASSERT_TRUE(request_mode_ == ci::RequestMode::GLOBAL ||
+ (request_mode_ == ci::RequestMode::USER &&
+ kGlobalUserUid != test_user.uid));
+ BackendInterface::SmokeInstallerFactoryPtr factory(
+ new UnifiedSmokeInstallerFactory());
+ UnifiedBackendInterface backend(
+ std::move(factory), std::to_string(test_user.uid));
+ UninstallAllSmokeApps(request_mode_, test_user.uid, &backend);
+ for (auto& path : backups_)
+ ASSERT_TRUE(RestorePath(path));
+ if (request_mode_ == ci::RequestMode::USER) {
+ ASSERT_TRUE(DeleteTestUser());
+ }
+ }
+ User test_user;
+
+ private:
+ ci::RequestMode request_mode_;
+ std::vector<bf::path> backups_;
+};
+
+} // namespace smoke_test
+
+
+namespace {
+
+const char kSmokeTestHelperPath[] =
+ "/usr/bin/unified-installer-ut/smoke-test-helper";
+
+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()
+ : backend(BackendInterface::SmokeInstallerFactoryPtr(
+ new UnifiedSmokeInstallerFactory()),
+ std::to_string(env->test_user.uid)),
+ params({PackageType::TPK, false}) {
+ params.test_user.uid = env->test_user.uid;
+ params.test_user.gid = env->test_user.gid;
+ }
+ protected:
+ UnifiedBackendInterface backend;
+ TestParameters params;
+};
+
+TEST_F(SmokeTest, Install_Single) {
+ bf::path path =
+ kUnifiedSmokePackagesDirectory / "Install_SingleTpk.tpk";
+ std::string pkgid = "smokeuni01";
+ std::string appid = "smokeuni01.InstallSingleTpk";
+ std::string exec = "smokeunified";
+
+ std::vector<bf::path> paths = { path };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
+}
+
+TEST_F(SmokeTest, Install_Double) {
+ bf::path path1 =
+ kUnifiedSmokePackagesDirectory / "Install_DoubleTpk.tpk";
+ std::string pkgid1 = "smokeuni02";
+ std::string appid1 = "smokeuni02.InstallDoubleTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2 =
+ kUnifiedSmokePackagesDirectory / "Install_DoubleWgt.wgt";
+ std::string pkgid2 = "smokeuni03";
+ std::string appid2 = "smokeuni03.InstallDoubleWgt";
+ std::string exec2 = "smokeuni03.InstallDoubleWgt";
+
+ std::vector<bf::path> paths = { path1, path2 };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
+}
+
+TEST_F(SmokeTest, Install_Triple) {
+ bf::path path1 =
+ kUnifiedSmokePackagesDirectory / "Install_TripleTpk.tpk";
+ std::string pkgid1 = "smokeuni04";
+ std::string appid1 = "smokeuni04.InstallTripleTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2 =
+ kUnifiedSmokePackagesDirectory / "Install_TripleWgt.wgt";
+ std::string pkgid2 = "smokeuni05";
+ std::string appid2 = "smokeuni05.InstallTripleWgt";
+ std::string exec2 = "smokeuni05.InstallTripleWgt";
+ bf::path path3 =
+ kUnifiedSmokePackagesDirectory / "Install_TripleHybrid.wgt";
+ std::string pkgid3 = "smokeuni06";
+ std::string appid3 = "smokeuni06.InstallTripleHybrid";
+ std::string exec3 = "smokeuni06.InstallTripleHybrid";
+
+ std::vector<bf::path> paths = { path1, path2, path3 };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
+ params.pkg_type = PackageType::HYBRID;
+ ASSERT_TRUE(ValidatePackage(pkgid3, {appid3, exec3}, params));
+}
+
+TEST_F(SmokeTest, Update_Single) {
+ bf::path path_old =
+ kUnifiedSmokePackagesDirectory / "Update_SingleTpk.tpk";
+ bf::path path_new =
+ kUnifiedSmokePackagesDirectory / "Update_SingleTpk_2.tpk";
+ std::string pkgid = "smokeuni07";
+ std::string appid = "smokeuni07.UpdateSingleTpk";
+ std::string exec = "smokeunified";
+
+ std::vector<bf::path> paths = { path_old };
+// ASSERT_EQ(backend.InstallSuccess(paths), ci::AppInstaller::Result::OK);
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ paths = { path_new };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid, "res/VERSION", "2", params));
+}
+
+TEST_F(SmokeTest, Update_Double) {
+ bf::path path1_old =
+ kUnifiedSmokePackagesDirectory / "Update_DoubleTpk.tpk";
+ bf::path path1_new =
+ kUnifiedSmokePackagesDirectory / "Update_DoubleTpk_2.tpk";
+ std::string pkgid1 = "smokeuni08";
+ std::string appid1 = "smokeuni08.UpdateDoubleTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2_old =
+ kUnifiedSmokePackagesDirectory / "Update_DoubleWgt.wgt";
+ bf::path path2_new =
+ kUnifiedSmokePackagesDirectory / "Update_DoubleWgt_2.wgt";
+ std::string pkgid2 = "smokeuni09";
+ std::string appid2 = "smokeuni09.UpdateDoubleWgt";
+ std::string exec2 = "smokeuni09.UpdateDoubleWgt";
+
+ std::vector<bf::path> paths = { path1_old, path2_old };
+// ASSERT_EQ(backend.InstallSuccess(paths), ci::AppInstaller::Result::OK);
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ paths = { path1_new, path2_new };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid1, "res/VERSION", "2", params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid2, "res/wgt/VERSION", "2", params));
+}
+
+TEST_F(SmokeTest, Update_Triple) {
+ bf::path path1_old =
+ kUnifiedSmokePackagesDirectory / "Update_TripleTpk.tpk";
+ bf::path path1_new =
+ kUnifiedSmokePackagesDirectory / "Update_TripleTpk_2.tpk";
+ std::string pkgid1 = "smokeuni10";
+ std::string appid1 = "smokeuni10.UpdateTripleTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2_old =
+ kUnifiedSmokePackagesDirectory / "Update_TripleWgt.wgt";
+ bf::path path2_new =
+ kUnifiedSmokePackagesDirectory / "Update_TripleWgt_2.wgt";
+ std::string pkgid2 = "smokeuni11";
+ std::string appid2 = "smokeuni11.UpdateTripleWgt";
+ std::string exec2 = "smokeuni11.UpdateTripleWgt";
+ bf::path path3_old =
+ kUnifiedSmokePackagesDirectory / "Update_TripleHybrid.wgt";
+ bf::path path3_new =
+ kUnifiedSmokePackagesDirectory / "Update_TripleHybrid_2.wgt";
+ std::string pkgid3 = "smokeuni12";
+ std::string appid3 = "smokeuni12.UpdateTripleHybrid";
+ std::string exec3 = "smokeuni12.UpdateTripleHybrid";
+
+ std::vector<bf::path> paths = { path1_old, path2_old, path3_old };
+// ASSERT_EQ(backend.InstallSuccess(paths), ci::AppInstaller::Result::OK);
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ paths = { path1_new, path2_new, path3_new };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
+ params.pkg_type = PackageType::HYBRID;
+ ASSERT_TRUE(ValidatePackage(pkgid3, {appid3, exec3}, params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid1, "res/VERSION", "2", params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid2, "res/wgt/VERSION", "2", params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid3, "res/wgt/VERSION", "2", params));
+}
+
+TEST_F(SmokeTest, InstallAndUpdate) {
+ bf::path path1_old =
+ kUnifiedSmokePackagesDirectory / "InstallAndUpdate_Tpk.tpk";
+ bf::path path1_new =
+ kUnifiedSmokePackagesDirectory / "InstallAndUpdate_Tpk_2.tpk";
+ std::string pkgid1 = "smokeuni13";
+ std::string appid1 = "smokeuni13.InstallAndUpdateModeTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2 =
+ kUnifiedSmokePackagesDirectory / "InstallAndUpdate_Wgt.wgt";
+ std::string pkgid2 = "smokeuni14";
+ std::string appid2 = "smokeuni14.InstallAndUpdateWgt";
+ std::string exec2 = "smokeuni14.InstallAndUpdateWgt";
+
+ // install tpk version 1
+ std::vector<bf::path> paths = { path1_old };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ // update tpk version 2, install wgt version 1
+ paths = { path1_new, path2 };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid1, "res/VERSION", "2", params));
+}
+
+TEST_F(SmokeTest, InstallAndROUpdate) {
+ bf::path path1_old =
+ kUnifiedSmokePackagesDirectory / "InstallAndROUpdate_Tpk.tpk";
+ bf::path path1_new =
+ kUnifiedSmokePackagesDirectory / "InstallAndROUpdate_Tpk_2.tpk";
+ std::string pkgid1 = "smokeuni25";
+ std::string appid1 = "smokeuni25.InstallAndROUpdateModeTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2 =
+ kUnifiedSmokePackagesDirectory / "InstallAndROUpdate_Wgt.wgt";
+ std::string pkgid2 = "smokeuni26";
+ std::string appid2 = "smokeuni26.InstallAndROUpdateWgt";
+ std::string exec2 = "smokeuni26.InstallAndROUpdateWgt";
+
+ // install tpk version 1
+ ASSERT_EQ(backend.InstallPreload(path1_old), ci::AppInstaller::Result::OK);
+ // update tpk version 2, install wgt version 1
+ std::vector<bf::path> paths = { path1_new, path2 };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid1, "res/VERSION", "2", params));
+}
+
+TEST_F(SmokeTest, Uninstall_Single) {
+ bf::path path =
+ kUnifiedSmokePackagesDirectory / "Uninstall_SingleTpk.tpk";
+ std::string pkgid = "smokeuni29";
+ std::string appid = "smokeuni29.UninstallSingleTpk";
+ std::string exec = "smokeunified";
+
+ std::vector<bf::path> paths = { path };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
+ std::vector<std::string> pkgids = { pkgid };
+ ASSERT_EQ(backend.Uninstall(pkgids), ci::AppInstaller::Result::OK);
+ ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
+}
+
+TEST_F(SmokeTest, Uninstall_Double) {
+ bf::path path1 =
+ kUnifiedSmokePackagesDirectory / "Uninstall_DoubleTpk.tpk";
+ std::string pkgid1 = "smokeuni30";
+ std::string appid1 = "smokeuni30.UninstallDoubleTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2 =
+ kUnifiedSmokePackagesDirectory / "Uninstall_DoubleWgt.wgt";
+ std::string pkgid2 = "smokeuni31";
+ std::string appid2 = "smokeuni31.UninstallDoubleWgt";
+ std::string exec2 = "smokeuni31.UninstallDoubleWgt";
+
+ std::vector<bf::path> paths = { path1, path2 };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
+ std::vector<std::string> pkgids = { pkgid1, pkgid2 };
+ ASSERT_EQ(backend.Uninstall(pkgids), ci::AppInstaller::Result::OK);
+ ASSERT_TRUE(CheckPackageNonExistance(pkgid1, params));
+ ASSERT_TRUE(CheckPackageNonExistance(pkgid2, params));
+}
+
+TEST_F(SmokeTest, Uninstall_Triple) {
+ bf::path path1 =
+ kUnifiedSmokePackagesDirectory / "Uninstall_TripleTpk.tpk";
+ std::string pkgid1 = "smokeuni32";
+ std::string appid1 = "smokeuni32.UninstallTripleTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2 =
+ kUnifiedSmokePackagesDirectory / "Uninstall_TripleWgt.wgt";
+ std::string pkgid2 = "smokeuni33";
+ std::string appid2 = "smokeuni33.UninstallTripleWgt";
+ std::string exec2 = "smokeuni33.UninstallTripleWgt";
+ bf::path path3 =
+ kUnifiedSmokePackagesDirectory / "Uninstall_TripleHybrid.wgt";
+ std::string pkgid3 = "smokeuni34";
+ std::string appid3 = "smokeuni34.UninstallTripleHybrid";
+ std::string exec3 = "smokeuni34.UninstallTripleHybrid";
+
+ std::vector<bf::path> paths = { path1, path2, path3 };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
+ params.pkg_type = PackageType::HYBRID;
+ ASSERT_TRUE(ValidatePackage(pkgid3, {appid3, exec3}, params));
+ std::vector<std::string> pkgids = { pkgid1, pkgid2, pkgid3 };
+ ASSERT_EQ(backend.Uninstall(pkgids), ci::AppInstaller::Result::OK);
+ ASSERT_TRUE(CheckPackageNonExistance(pkgid1, params));
+ ASSERT_TRUE(CheckPackageNonExistance(pkgid2, params));
+ ASSERT_TRUE(CheckPackageNonExistance(pkgid3, params));
+}
+
+TEST_F(SmokeTest, UninstallAndROUpdateUninstall) {
+ bf::path path1_old =
+ kUnifiedSmokePackagesDirectory / "UninstallAndROUpdateUninstall_Tpk.tpk";
+ bf::path path1_new =
+ kUnifiedSmokePackagesDirectory /
+ "UninstallAndROUpdateUninstall_Tpk_2.tpk";
+ std::string pkgid1 = "smokeuni35";
+ std::string appid1 = "smokeuni35.UninstallAndROUpdateUninstallTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2 =
+ kUnifiedSmokePackagesDirectory / "UninstallAndROUpdateUninstall_Wgt.wgt";
+ std::string pkgid2 = "smokeuni36";
+ std::string appid2 = "smokeuni36.UninstallAndROUpdateUninstallWgt";
+ std::string exec2 = "smokeuni36.UninstallAndROUpdateUninstallWgt";
+
+ // install tpk version 1
+ ASSERT_EQ(backend.InstallPreload(path1_old), ci::AppInstaller::Result::OK);
+ ci::PkgQueryInterface pkg_query1(pkgid1, params.test_user.uid);
+ PackageAttributes original(pkg_query1);
+ // update tpk version 2, install wgt version 1
+ std::vector<bf::path> paths = { path1_new, path2 };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid1, "res/VERSION", "2", params));
+ // uninstall
+ std::vector<std::string> pkgids = { pkgid1, pkgid2 };
+ ASSERT_EQ(backend.Uninstall(pkgids), ci::AppInstaller::Result::OK);
+ ci::PkgQueryInterface pkg_query2(pkgid1, params.test_user.uid, true);
+ PackageAttributes restored(pkg_query2);
+ ASSERT_EQ(original, restored);
+ ASSERT_TRUE(CheckPackageNonExistance(pkgid2, params));
+ params.pkg_type = PackageType::TPK;
+ params.is_readonly = true;
+ ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid1, "res/VERSION", "1", params));
+}
+
+class RollbackSmokeTest : public testing::Test {
+ public:
+ RollbackSmokeTest()
+ : backend(BackendInterface::SmokeInstallerFactoryPtr(
+ new UnifiedSmokeInstallerFactory()),
+ std::to_string(env->test_user.uid),
+ RequestResult::FAIL),
+ params({PackageType::TPK, false}) {
+ params.test_user.uid = env->test_user.uid;
+ params.test_user.gid = env->test_user.gid;
+ }
+ protected:
+ UnifiedBackendInterface backend;
+ TestParameters params;
+};
+
+TEST_F(RollbackSmokeTest, Install_Rollback) {
+ bf::path path1 =
+ kUnifiedSmokePackagesDirectory / "Install_RollbackTpk.tpk";
+ std::string pkgid1 = "smokeuni15";
+ std::string appid1 = "smokeuni15.InstallRollbackTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2 =
+ kUnifiedSmokePackagesDirectory / "Install_RollbackWgt.wgt";
+ std::string pkgid2 = "smokeuni16";
+ std::string appid2 = "smokeuni16.InstallRollbackWgt";
+ std::string exec2 = "smokeuni16.InstallRollbackWgt";
+
+ std::vector<bf::path> paths = { path1, path2 };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::ERROR);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(CheckPackageNonExistance(pkgid1, params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(CheckPackageNonExistance(pkgid2, params));
+}
+
+TEST_F(RollbackSmokeTest, Update_Rollback) {
+ bf::path path1_old =
+ kUnifiedSmokePackagesDirectory / "Update_RollbackTpk.tpk";
+ bf::path path1_new =
+ kUnifiedSmokePackagesDirectory / "Update_RollbackTpk_2.tpk";
+ std::string pkgid1 = "smokeuni17";
+ std::string appid1 = "smokeuni17.UpdateRollbackTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2_old =
+ kUnifiedSmokePackagesDirectory / "Update_RollbackWgt.wgt";
+ bf::path path2_new =
+ kUnifiedSmokePackagesDirectory / "Update_RollbackWgt_2.wgt";
+ std::string pkgid2 = "smokeuni18";
+ std::string appid2 = "smokeuni18.UpdateRollbackWgt";
+ std::string exec2 = "smokeuni18.UpdateRollbackWgt";
+
+ std::vector<bf::path> paths = { path1_old, path2_old };
+ ASSERT_EQ(backend.InstallSuccess(paths), ci::AppInstaller::Result::OK);
+ paths = { path1_new, path2_new };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::ERROR);
+
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid1, "res/VERSION", "1", params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid2, "res/wgt/VERSION", "1", params));
+}
+
+TEST_F(RollbackSmokeTest, InstallAndUpdate_Rollback) {
+ bf::path path1 =
+ kUnifiedSmokePackagesDirectory / "InstallAndUpdate_RollbackTpk.tpk";
+ std::string pkgid1 = "smokeuni19";
+ std::string appid1 = "smokeuni19.InstallAndUpdateRollbackTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2_old =
+ kUnifiedSmokePackagesDirectory / "InstallAndUpdate_RollbackWgt.wgt";
+ bf::path path2_new =
+ kUnifiedSmokePackagesDirectory / "InstallAndUpdate_RollbackWgt_2.wgt";
+ std::string pkgid2 = "smokeuni20";
+ std::string appid2 = "smokeuni20.InstallAndUpdateRollbackWgt";
+ std::string exec2 = "smokeuni20.InstallAndUpdateRollbackWgt";
+
+ std::vector<bf::path> paths = { path2_old };
+ ASSERT_EQ(backend.InstallSuccess(paths), ci::AppInstaller::Result::OK);
+ // pkgid1: install, pkgid2: update
+ paths = { path1, path2_new };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::ERROR);
+
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(CheckPackageNonExistance(pkgid1, params));
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid2, "res/wgt/VERSION", "1", params));
+}
+
+TEST_F(RollbackSmokeTest, InstallAndROUpdate_Rollback) {
+ bf::path path1 =
+ kUnifiedSmokePackagesDirectory / "InstallAndROUpdate_RollbackTpk.tpk";
+ std::string pkgid1 = "smokeuni27";
+ std::string appid1 = "smokeuni27.InstallAndROUpdateRollbackTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2_old =
+ kUnifiedSmokePackagesDirectory / "InstallAndROUpdate_RollbackWgt.wgt";
+ bf::path path2_new =
+ kUnifiedSmokePackagesDirectory / "InstallAndROUpdate_RollbackWgt_2.wgt";
+ std::string pkgid2 = "smokeuni28";
+ std::string appid2 = "smokeuni28.InstallAndROUpdateRollbackWgt";
+ std::string exec2 = "smokeuni28.InstallAndROUpdateRollbackWgt";
+
+ ASSERT_EQ(backend.InstallPreloadSuccess(path2_old),
+ ci::AppInstaller::Result::OK);
+ // pkgid1: install, pkgid2: update
+ std::vector<bf::path> paths = { path1, path2_new };
+ ASSERT_EQ(backend.Install(paths), ci::AppInstaller::Result::ERROR);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(CheckPackageNonExistance(pkgid1, params));
+ params.pkg_type = PackageType::WGT;
+ params.is_readonly = true;
+ ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid2, "res/wgt/VERSION", "1", params));
+}
+
+TEST_F(SmokeTest, Recovery_Install) {
+ bf::path path1 =
+ kUnifiedSmokePackagesDirectory / "Recovery_InstallTpk.tpk";
+ std::string pkgid1 = "smokeuni21";
+ std::string appid1 = "smokeuni21.RecoveryInstallTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2 =
+ kUnifiedSmokePackagesDirectory / "Recovery_InstallWgt.wgt";
+ std::string pkgid2 = "smokeuni22";
+ std::string appid2 = "smokeuni22.RecoveryInstallWgt";
+ std::string exec2 = "smokeuni22.RecoveryInstallWgt";
+
+ std::vector<std::string> paths = { path1.string(), path2.string() };
+ ci::Subprocess backend_crash(kSmokeTestHelperPath);
+ std::string test_uid_str = std::to_string(params.test_user.uid);
+ std::vector<std::string> argv = { "-u", test_uid_str, "-i" };
+ argv.insert(argv.end(), paths.begin(), paths.end());
+ backend_crash.Run(argv);
+ ASSERT_NE(backend_crash.Wait(), 0);
+
+ bf::path recovery_file =
+ FindRecoveryFile("/tpk-recovery", params.test_user.uid);
+ ASSERT_FALSE(recovery_file.empty());
+ std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
+ GetRecoverFileInfo(recovery_file);
+ ASSERT_TRUE(recovery_info);
+ ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(CheckPackageNonExistance(pkgid1, params));
+ ASSERT_FALSE(bf::exists(recovery_info->unpacked_dir()));
+
+ recovery_file =
+ FindRecoveryFile("/wgt-recovery", params.test_user.uid);
+ ASSERT_FALSE(recovery_file.empty());
+ recovery_info.reset();
+ recovery_info = GetRecoverFileInfo(recovery_file);
+ ASSERT_TRUE(recovery_info);
+ ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(CheckPackageNonExistance(pkgid2, params));
+ ASSERT_FALSE(bf::exists(recovery_info->unpacked_dir()));
+}
+
+TEST_F(SmokeTest, Recovery_Update) {
+ bf::path path1_old =
+ kUnifiedSmokePackagesDirectory / "Recovery_UpdateTpk.tpk";
+ bf::path path1_new =
+ kUnifiedSmokePackagesDirectory / "Recovery_UpdateTpk_2.tpk";
+ std::string pkgid1 = "smokeuni23";
+ std::string appid1 = "smokeuni23.RecoveryUpdateTpk";
+ std::string exec1 = "smokeunified";
+ bf::path path2_old =
+ kUnifiedSmokePackagesDirectory / "Recovery_UpdateWgt.wgt";
+ bf::path path2_new =
+ kUnifiedSmokePackagesDirectory / "Recovery_UpdateWgt_2.wgt";
+ std::string pkgid2 = "smokeuni24";
+ std::string appid2 = "smokeuni24.RecoveryUpdateWgt";
+ std::string exec2 = "smokeuni24.RecoveryUpdateWgt";
+
+ std::vector<bf::path> paths_old = { path1_old, path2_old };
+ ASSERT_EQ(backend.Install(paths_old), ci::AppInstaller::Result::OK);
+
+ std::vector<std::string> paths = { path1_new.string(), path2_new.string() };
+ ci::Subprocess backend_crash(kSmokeTestHelperPath);
+ std::string test_uid_str = std::to_string(params.test_user.uid);
+ std::vector<std::string> argv = { "-u", test_uid_str, "-i" };
+ argv.insert(argv.end(), paths.begin(), paths.end());
+ backend_crash.Run(argv);
+ ASSERT_NE(backend_crash.Wait(), 0);
+
+ bf::path recovery_file =
+ FindRecoveryFile("/tpk-recovery", params.test_user.uid);
+ ASSERT_FALSE(recovery_file.empty());
+ std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
+ GetRecoverFileInfo(recovery_file);
+ ASSERT_TRUE(recovery_info);
+ ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::TPK;
+ ASSERT_TRUE(ValidatePackage(pkgid1, {appid1, exec1}, params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid1, "res/VERSION", "1", params));
+
+ recovery_file =
+ FindRecoveryFile("/wgt-recovery", params.test_user.uid);
+ ASSERT_FALSE(recovery_file.empty());
+ recovery_info.reset();
+ recovery_info = GetRecoverFileInfo(recovery_file);
+ ASSERT_TRUE(recovery_info);
+ ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
+ params.pkg_type = PackageType::WGT;
+ ASSERT_TRUE(ValidatePackage(pkgid2, {appid2, exec2}, params));
+ ASSERT_TRUE(
+ ValidateFileContentInPackage(pkgid2, "res/wgt/VERSION", "1", params));
+}
+
+} // namespace smoke_test
+
+int main(int argc, char** argv) {
+ try {
+ ci::RequestMode request_mode = smoke_test::ParseRequestMode(argc, argv);
+ if (getuid() != 0 || request_mode != ci::RequestMode::GLOBAL) {
+ std::cout << "Skip tests for preload request" << std::endl;
+ ::testing::GTEST_FLAG(filter) = "SmokeTest.*";
+ }
+ testing::InitGoogleTest(&argc, argv);
+ ::env = static_cast<smoke_test::SmokeEnvironment*>(
+ testing::AddGlobalTestEnvironment(
+ new smoke_test::SmokeEnvironment(request_mode)));
+ signal(SIGINT, ::signalHandler);
+ signal(SIGSEGV, ::signalHandler);
+ return RUN_ALL_TESTS();
+ } catch (...) {
+ std::cout << "Exception occurred during testing" << std::endl;
+ return -1;
+ }
+}
--- /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 <common/installer_factory.h>
+#include <common/installer_runner.h>
+#include <common/pkgmgr_interface.h>
+#include <tpk/tpk_app_query_interface.h>
+#include <unit_tests/common/smoke_utils.h>
+#include <unit_tests/tpk_smoke_utils.h>
+#include <unit_tests/wgt_smoke_utils.h>
+#include <wgt/utils/wgt_app_query_interface.h>
+
+#include <algorithm>
+#include <memory>
+#include <string>
+
+namespace ci = common_installer;
+
+namespace {
+
+bool EndsWith(const std::string str, const std::string& to_match) {
+ if (to_match.size() > str.size())
+ return false;
+ return std::equal(to_match.rbegin(), to_match.rend(), str.rbegin());
+}
+
+#if __cplusplus < 201300L
+template<typename T, typename... Args>
+std::unique_ptr<T> make_unique(Args&&... args) {
+ return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
+}
+#endif
+
+} // namespace
+
+class CrashInstallerFactory : public ci::InstallerFactory {
+ public:
+ std::unique_ptr<ci::AppInstaller> CreateInstaller(ci::PkgMgrPtr pkgmgr,
+ int idx) override {
+ std::string type =
+ EndsWith(pkgmgr->GetRequestInfo(idx), "tpk") ? "tpk" : "wgt";
+ int n_pkgs = pkgmgr->GetRequestInfoCount();
+ std::unique_ptr<ci::AppInstaller> installer;
+ if (type == "tpk") {
+ tpk::TpkAppQueryInterface* tpk_aqi = new tpk::TpkAppQueryInterface();
+ pkgmgr->AddAppQueryInterface(idx, tpk_aqi);
+ installer.reset(
+ idx + 1 == n_pkgs ?
+ new smoke_test::CrashTpkInstaller(pkgmgr, -1, {},
+ smoke_test::CrashStepType::PROCESS) :
+ new tpk::TpkInstaller(pkgmgr));
+
+ } else {
+ wgt::WgtAppQueryInterface* wgt_aqi = new wgt::WgtAppQueryInterface();
+ pkgmgr->AddAppQueryInterface(idx, wgt_aqi);
+ installer.reset(
+ idx + 1 == n_pkgs ?
+ new smoke_test::CrashWgtInstaller(pkgmgr, -1, {},
+ smoke_test::CrashStepType::PROCESS) :
+ new wgt::WgtInstaller(pkgmgr));
+ }
+ installer->SetIndex(idx);
+ return installer;
+ }
+};
+
+int main(int argc, char** argv) {
+ ci::PkgmgrInstaller pkgmgr_installer;
+ auto pkgmgr = ci::PkgMgrInterface::Create(argc, argv, &pkgmgr_installer);
+
+#if __cplusplus >= 201300L
+ using std;
+#endif
+ ci::InstallerRunner runner(make_unique<CrashInstallerFactory>(), pkgmgr);
+ ci::AppInstaller::Result result = runner.Run();
+
+ return (result == ci::AppInstaller::Result::OK) ? 0 : 1;
+}
--- /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 "smoke_test/smoke_utils.h"
+
+#include <unit_tests/common/smoke_utils.h>
+#include <unit_tests/tpk_smoke_utils.h>
+#include <unit_tests/wgt_smoke_utils.h>
+#include <unzip.h>
+
+#include <map>
+#include <string>
+
+namespace bf = boost::filesystem;
+namespace ci = common_installer;
+
+namespace {
+
+std::map<const char*, const char*> kTypeMap = {
+ {"res/wgt/config.xml", "wgt"},
+ {"config.xml", "wgt"},
+ {"tizen-manifest.xml", "tpk"},
+};
+
+std::string GetPkgTypeFromPkgid(const std::string& pkgid, uid_t uid) {
+ ci::PkgQueryInterface query(pkgid, uid);
+ return query.Type();
+}
+
+std::string GetPkgTypeFromPath(const std::string& path) {
+ std::string type;
+ unzFile uf = unzOpen(path.c_str());
+ if (!uf) {
+ LOG(ERROR) << "Failed to open zip file: " << path;
+ return type;
+ }
+ for (auto it : kTypeMap) {
+ if (unzLocateFile(uf, it.first, 0) == UNZ_OK) {
+ LOG(DEBUG) << "Found: " << it.first;
+ type = it.second;
+ break;
+ }
+ }
+ if (type.empty())
+ LOG(ERROR) << "Cannot get pkg type";
+ unzClose(uf);
+ return type;
+}
+
+std::string GetPkgTypeFromRecoveryFile(const std::string& path) {
+ bf::path recovery_file = path;
+ if (recovery_file.filename().string().find("tpk") == 0)
+ return "tpk";
+ else if (recovery_file.filename().string().find("wgt") == 0)
+ return "wgt";
+ return {};
+}
+
+std::string GetPkgType(const std::string& pkginfo, uid_t uid) {
+ std::string type = GetPkgTypeFromPkgid(pkginfo, uid);
+ if (type.empty())
+ type = GetPkgTypeFromPath(pkginfo);
+ // recovery file
+ if (type.empty())
+ type = GetPkgTypeFromRecoveryFile(pkginfo);
+ return type;
+}
+
+} // namespace
+
+namespace smoke_test {
+
+UnifiedSmokeInstallerFactory::AppInstallerPtr
+UnifiedSmokeInstallerFactory::CreateInstaller(
+ int idx, ci::PkgMgrPtr pkgmgr) const {
+ std::string type = GetPkgType(pkgmgr->GetRequestInfo(idx), pkgmgr->GetUid());
+ if (type.empty())
+ return {};
+
+ std::unique_ptr<ci::AppInstaller> installer;
+ if (type == "tpk") {
+ tpk::TpkAppQueryInterface* tpk_aqi = new tpk::TpkAppQueryInterface();
+ pkgmgr->AddAppQueryInterface(idx, tpk_aqi);
+ installer.reset(new tpk::TpkInstaller(pkgmgr));
+ } else {
+ wgt::WgtAppQueryInterface* wgt_aqi = new wgt::WgtAppQueryInterface();
+ pkgmgr->AddAppQueryInterface(idx, wgt_aqi);
+ if (wgt_aqi->IsHybridApplication(pkgmgr->GetRequestInfo(idx),
+ pkgmgr->GetUid())) {
+ LOG(INFO) << "Hybrid package detected";
+ installer.reset(new hybrid::HybridInstaller(pkgmgr));
+ } else {
+ installer.reset(new wgt::WgtInstaller(pkgmgr));
+ }
+ }
+
+ installer->SetIndex(idx);
+
+ return installer;
+}
+
+UnifiedSmokeInstallerFactory::AppInstallerPtr
+UnifiedSmokeInstallerFactory::CreateFailExpectedInstaller(
+ int idx, ci::PkgMgrPtr pkgmgr, int fail_at) const {
+ std::string type = GetPkgType(pkgmgr->GetRequestInfo(idx), pkgmgr->GetUid());
+ if (type.empty())
+ return {};
+
+ std::unique_ptr<ci::AppInstaller> installer;
+ if (type == "tpk") {
+ tpk::TpkAppQueryInterface* tpk_aqi = new tpk::TpkAppQueryInterface();
+ pkgmgr->AddAppQueryInterface(idx, tpk_aqi);
+ installer.reset(new smoke_test::FailExpectedTpkInstaller(pkgmgr, fail_at));
+ } else {
+ wgt::WgtAppQueryInterface* wgt_aqi = new wgt::WgtAppQueryInterface();
+ pkgmgr->AddAppQueryInterface(idx, wgt_aqi);
+ if (wgt_aqi->IsHybridApplication(pkgmgr->GetRequestInfo(idx),
+ pkgmgr->GetUid())) {
+ LOG(INFO) << "Hybrid package detected";
+ installer.reset(
+ new smoke_test::FailExpectedHybridInstaller(pkgmgr, fail_at));
+ } else {
+ installer.reset(
+ new smoke_test::FailExpectedWgtInstaller(pkgmgr, fail_at));
+ }
+ }
+
+ installer->SetIndex(idx);
+
+ return installer;
+}
+
+UnifiedBackendInterface::AppQueryInterfacePtr
+UnifiedBackendInterface::CreateQueryInterface() const {
+ // this is not used
+ return {};
+}
+
+UnifiedBackendInterface::AppInstallerPtr
+UnifiedBackendInterface::CreateInstaller(ci::PkgMgrPtr pkgmgr) const {
+ return factory_->CreateInstaller(0, pkgmgr);
+}
+
+UnifiedBackendInterface::AppInstallerPtr
+UnifiedBackendInterface::CreateFailExpectedInstaller(
+ ci::PkgMgrPtr pkgmgr, int fail_at) const {
+ return factory_->CreateFailExpectedInstaller(0, pkgmgr, fail_at);;
+}
+
+} // namespace smoke_test
--- /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.
+
+#ifndef UNIT_TESTS_SMOKE_UTILS_H_
+#define UNIT_TESTS_SMOKE_UTILS_H_
+
+#include <common/installer/app_installer.h>
+#include <common/pkgmgr_interface.h>
+#include <unit_tests/common/smoke_utils.h>
+#include <unit_tests/tpk_smoke_utils.h>
+
+namespace smoke_test {
+
+class UnifiedSmokeInstallerFactory : public SmokeInstallerFactory {
+ public:
+ AppInstallerPtr CreateInstaller(
+ int idx, common_installer::PkgMgrPtr pkgmgr) const override;
+ AppInstallerPtr CreateFailExpectedInstaller(
+ int idx, common_installer::PkgMgrPtr pkgmgr, int fail_at) const override;
+};
+
+class UnifiedBackendInterface : public BackendInterface {
+ public:
+ using BackendInterface::BackendInterface;
+
+ AppQueryInterfacePtr CreateQueryInterface() const override;
+ AppInstallerPtr CreateInstaller(
+ common_installer::PkgMgrPtr pkgmgr) const override;
+ AppInstallerPtr CreateFailExpectedInstaller(
+ common_installer::PkgMgrPtr pkgmgr, int fail_at) const override;
+};
+
+} // namespace smoke_test
+
+#endif // UNIT_TESTS_SMOKE_UTILS_H_