From 1becfd8fad003f075220eac15e92d3cbfcffad0f Mon Sep 17 00:00:00 2001 From: Piotr Ganicz Date: Thu, 16 Mar 2017 11:03:23 +0100 Subject: [PATCH] Extensive tests for Recovery and Rollback This commit creates new executable (extensive-smoke-test) for new type of tests which will be testing recovery and rollback modes after each step in each installation mode. Requires: - https://review.tizen.org/gerrit/#/c/119323/ - https://review.tizen.org/gerrit/#/c/116059/ Change-Id: I0a7023e89edb60c400e808535b780a57469e3c5b --- CMakeLists.txt | 1 + src/unit_tests/CMakeLists.txt | 14 ++ src/unit_tests/extensive_smoke_test.cc | 346 +++++++++++++++++++++++++++++++++ src/unit_tests/smoke_test.cc | 80 ++++---- src/unit_tests/smoke_test_helper.cc | 17 +- src/unit_tests/smoke_utils.cc | 157 ++++++++++----- src/unit_tests/smoke_utils.h | 41 +++- 7 files changed, 563 insertions(+), 93 deletions(-) create mode 100644 src/unit_tests/extensive_smoke_test.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 06192ca..55aafb7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,6 +30,7 @@ SET(TARGET_LIBNAME_TPK_ARCHIVE_INFO "tpk") SET(TARGET_TPK_BACKEND "tpk-backend") SET(TARGET_SMOKE_TEST "smoke-test") +SET(TARGET_SMOKE_TEST_EXTENSIVE "extensive-smoke-test") SET(TARGET_SMOKE_TEST_HELPER "smoke-test-helper") SET(TARGET_MANIFEST_TEST "manifest-test") diff --git a/src/unit_tests/CMakeLists.txt b/src/unit_tests/CMakeLists.txt index 10b1cae..8838214 100644 --- a/src/unit_tests/CMakeLists.txt +++ b/src/unit_tests/CMakeLists.txt @@ -7,6 +7,12 @@ ADD_EXECUTABLE(${TARGET_SMOKE_TEST} smoke_utils.cc ) +ADD_EXECUTABLE(${TARGET_SMOKE_TEST_EXTENSIVE} + extensive_smoke_test.cc + smoke_utils.h + smoke_utils.cc +) + ADD_EXECUTABLE(${TARGET_SMOKE_TEST_HELPER} smoke_test_helper.cc ) @@ -21,6 +27,7 @@ ADD_EXECUTABLE(${TARGET_MANIFEST_TEST} ) TARGET_INCLUDE_DIRECTORIES(${TARGET_SMOKE_TEST} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../) +TARGET_INCLUDE_DIRECTORIES(${TARGET_SMOKE_TEST_EXTENSIVE} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../) TARGET_INCLUDE_DIRECTORIES(${TARGET_SMOKE_TEST_HELPER} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../) TARGET_INCLUDE_DIRECTORIES(${TARGET_MANIFEST_TEST} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../) @@ -31,6 +38,11 @@ APPLY_PKG_CONFIG(${TARGET_SMOKE_TEST} PUBLIC GTEST GUM_DEPS ) +APPLY_PKG_CONFIG(${TARGET_SMOKE_TEST_EXTENSIVE} PUBLIC + Boost + GTEST + GUM_DEPS +) APPLY_PKG_CONFIG(${TARGET_MANIFEST_TEST} PUBLIC Boost GTEST @@ -40,9 +52,11 @@ APPLY_PKG_CONFIG(${TARGET_MANIFEST_TEST} PUBLIC # GTest main libraries is still missing, so additional linking of # GTEST_MAIN_LIBRARIES is needed. TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST} PRIVATE ${TARGET_LIBNAME_TPK} ${GTEST_MAIN_LIBRARIES}) +TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST_EXTENSIVE} PRIVATE ${TARGET_LIBNAME_TPK} ${GTEST_MAIN_LIBRARIES}) TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST_HELPER} PRIVATE ${TARGET_LIBNAME_TPK}) TARGET_LINK_LIBRARIES(${TARGET_MANIFEST_TEST} PRIVATE ${TARGET_LIBNAME_TPK} ${GTEST_MAIN_LIBRARIES}) INSTALL(TARGETS ${TARGET_SMOKE_TEST} DESTINATION ${BINDIR}/${DESTINATION_DIR}) +INSTALL(TARGETS ${TARGET_SMOKE_TEST_EXTENSIVE} DESTINATION ${BINDIR}/${DESTINATION_DIR}) INSTALL(TARGETS ${TARGET_SMOKE_TEST_HELPER} DESTINATION ${BINDIR}/${DESTINATION_DIR}) INSTALL(TARGETS ${TARGET_MANIFEST_TEST} DESTINATION ${BINDIR}/${DESTINATION_DIR}) diff --git a/src/unit_tests/extensive_smoke_test.cc b/src/unit_tests/extensive_smoke_test.cc new file mode 100644 index 0000000..5d6bda8 --- /dev/null +++ b/src/unit_tests/extensive_smoke_test.cc @@ -0,0 +1,346 @@ +// Copyright (c) 2017 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 +#include + +#include "unit_tests/smoke_utils.h" + + +namespace common_installer { + +class SmokeEnvironment : public testing::Environment { + public: + explicit SmokeEnvironment(uid_t uid) : uid_(uid) { + } + void SetUp() override { + backups_ = SetupBackupDirectories(); + for (auto& path : backups_) + BackupPath(path); + } + void TearDown() override { + UninstallAllSmokeApps(RequestMode::GLOBAL); + for (auto& path : backups_) + RestorePath(path); + } + + private: + uid_t uid_; + std::vector backups_; +}; + +class SmokeTest : public testing::Test { +}; + + +TEST_F(SmokeTest, DeltaMode_Tpk_Rollback) { + bf::path path = kSmokePackagesDirectory / "DeltaMode_Tpk_Rollback.tpk"; + bf::path delta_package = kSmokePackagesDirectory / + "DeltaMode_Tpk_Rollback.delta"; + std::string pkgid = "smoketpk28"; + std::string appid = "smoketpk28.DeltaModeTpk_Rollback"; + ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK); + const char* argv[] = + {"", "-i", delta_package.c_str(), "-u", kTestUserIdStr.c_str()}; + + TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool { + EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, appid)); + + // Check delta modifications + + bf::path root_path = ci::GetRootAppPath(false, kTestUserId); + EXTENDED_ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "DELETED")); + EXTENDED_ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "ADDED")); + EXTENDED_ASSERT_TRUE(bf::exists(root_path / pkgid / "bin" / "basicdali")); + EXTENDED_ASSERT_TRUE(bf::exists(root_path / pkgid / "shared" / "res" / + "basicdali.png")); + EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid, + "res/MODIFIED", "version 1\n")); + return true; + }); +} + +TEST_F(SmokeTest, RecoveryMode_Tpk_Installation) { + bf::path path = kSmokePackagesDirectory / "RecoveryMode_Tpk_Installation.tpk"; + std::string pkgid = "smokeapp15"; + std::string appid = "smokeapp15.RecoveryModeTpkInstallation"; + RemoveAllRecoveryFiles(); + + std::vector args = + {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()}; + CrashAfterEachStep(args, [=](int step) -> bool { + if (step >= 1) { + bf::path recovery_file = FindRecoveryFile(); + EXTENDED_ASSERT_FALSE(recovery_file.empty()); + EXTENDED_ASSERT_EQ(Recover(recovery_file), ci::AppInstaller::Result::OK); + EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, appid)); + } + return true; + }); + RemoveAllRecoveryFiles(); +} + +TEST_F(SmokeTest, RecoveryMode_Tpk_Update) { + bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_Tpk_Update.tpk"; + bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_Tpk_Update_2.tpk"; + RemoveAllRecoveryFiles(); + ASSERT_EQ(Install(path_old), ci::AppInstaller::Result::OK); + + std::vector args = + {"", "-i", path_new.string(), "-u", kTestUserIdStr.c_str()}; + CrashAfterEachStep(args, [=](int step) -> bool { + if (step >= 1) { + std::string pkgid = "smokeapp16"; + std::string appid = "smokeapp16.RecoveryModeTpkUpdate"; + bf::path recovery_file = FindRecoveryFile(); + EXTENDED_ASSERT_FALSE(recovery_file.empty()); + EXTENDED_ASSERT_EQ(Recover(recovery_file), ci::AppInstaller::Result::OK); + EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, appid)); + + EXTENDED_ASSERT_TRUE( + ValidateFileContentInPackage(pkgid, "VERSION", "1\n")); + } + return true; + }); +} + +#define TEP_TEST_STARTING_BLOCK(NUMBER) \ + bf::path path = kSmokePackagesDirectory / "TEP_Tpk"; \ + path += #NUMBER; \ + path += ".tpk"; \ + bf::path tep1 = kSmokePackagesDirectory / "tep1.tep"; \ + bf::path tep2 = kSmokePackagesDirectory / "tep2.tep"; \ + std::string number = std::to_string(50 + NUMBER - 1); \ + std::string pkgid = std::string("smokeapp") + number; \ + std::string appid = pkgid + ".TEP"; \ + + +TEST_F(SmokeTest, TEP_Tpk_TepInstallTepUpdateRollback) { + TEP_TEST_STARTING_BLOCK(5) + ASSERT_EQ(InstallWithTEP(path, tep1), ci::AppInstaller::Result::OK); + const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str(), + "-e", tep1.c_str()}; + TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool { + EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, appid)); + EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid, + "tep/tep1.tep", "tep1\n")); + return true; + }); +} + +TEST_F(SmokeTest, TEP_Tpk_NoTepInstallTepUpdateRollback) { + TEP_TEST_STARTING_BLOCK(6) + ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK); + const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str(), + "-e", tep1.c_str()}; + TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool { + EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, appid)); + bf::path root_path = ci::GetRootAppPath(false, kTestUserId); + bf::path tep_file = root_path / pkgid / "tep" / "tep2.tep"; + EXTENDED_ASSERT_FALSE(bf::exists(tep_file)); + return true; + }); +} + +TEST_F(SmokeTest, TEP_Tpk_TepInstallNoTepUpdateRollback) { + TEP_TEST_STARTING_BLOCK(7) + ASSERT_EQ(InstallWithTEP(path, tep1), ci::AppInstaller::Result::OK); + const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()}; + TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool { + EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, appid)); + EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid, + "tep/tep1.tep", "tep1\n")); + return true; + }); +} + +TEST_F(SmokeTest, TEP_Tpk_Mount_TepInstallTepUpdateRollback) { + TEP_TEST_STARTING_BLOCK(12) + ASSERT_EQ(MountInstallWithTEP(path, tep1), ci::AppInstaller::Result::OK); + const char* argv[] = {"", "-w", path.c_str(), "-u", kTestUserIdStr.c_str(), + "-e", tep2.c_str()}; + TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool { + ScopedTzipInterface package_mount(pkgid); + EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, appid)); + EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid, + "tep/tep1.tep", "tep1\n")); + return true; + }); +} + +TEST_F(SmokeTest, TEP_Tpk_Mount_NoTepInstallTepUpdateRollback) { + TEP_TEST_STARTING_BLOCK(13) + ASSERT_EQ(MountInstall(path), ci::AppInstaller::Result::OK); + const char* argv[] = {"", "-w", path.c_str(), "-u", kTestUserIdStr.c_str(), + "-e", tep1.c_str()}; + TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool { + ScopedTzipInterface package_mount(pkgid); + EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, appid)); + bf::path root_path = ci::GetRootAppPath(false, kTestUserId); + bf::path tep_file = root_path / pkgid / "tep" / "tep2.tep"; + EXTENDED_ASSERT_FALSE(bf::exists(tep_file)); + return true; + }); +} + +TEST_F(SmokeTest, TEP_Tpk_Mount_TepInstallNoTepUpdateRollback) { + TEP_TEST_STARTING_BLOCK(14) + ASSERT_EQ(MountInstallWithTEP(path, tep1), ci::AppInstaller::Result::OK); + const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()}; + TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool { + ScopedTzipInterface package_mount(pkgid); + EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, appid)); + EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid, + "tep/tep1.tep", "tep1\n")); + return true; + }); +} + +TEST_F(SmokeTest, InstallationMode_Rollback) { + bf::path path = kSmokePackagesDirectory / "InstallationMode_Rollback.tpk"; + std::string pkgid = "smoketpk34"; + std::string appid = "smoketpk34.InstallationMode_Rollback"; + const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()}; + + TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool { + EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, appid)); + return true; + }); +} + +TEST_F(SmokeTest, RecoveryMode_ForDelta) { + bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForDelta.tpk"; + bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForDelta.delta"; + RemoveAllRecoveryFiles(); + ASSERT_EQ(ci::AppInstaller::Result::OK, Install(path_old)); + + std::vector args = + {"", "-i", path_new.string(), "-u", kTestUserIdStr.c_str()}; + CrashAfterEachStep(args, [=](int step) -> bool { + if (step >= 1) { + std::string pkgid = "smoketpk35"; + std::string appid = "smoketpk35.RecoveryMode_ForDelta"; + bf::path recovery_file = FindRecoveryFile(); + EXTENDED_ASSERT_FALSE(recovery_file.empty()); + EXTENDED_ASSERT_EQ(Recover(recovery_file), ci::AppInstaller::Result::OK); + EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid})); + + EXTENDED_ASSERT_TRUE( + ValidateFileContentInPackage(pkgid, "res/MODIFIED", "version 1")); + bf::path root_path = ci::GetRootAppPath(false, kTestUserId); + EXTENDED_ASSERT_TRUE(bf::exists(root_path / pkgid / "res/DELETED")); + EXTENDED_ASSERT_FALSE(bf::exists(root_path / pkgid / "res/ADDED")); + } + return true; + }); +} + +TEST_F(SmokeTest, UpdateMode_Rollback) { + bf::path old_path = kSmokePackagesDirectory / "UpdateMode_Rollback.tpk"; + bf::path new_path = kSmokePackagesDirectory / "UpdateMode_Rollback2.tpk"; + std::string pkgid = "smoketpk36"; + std::string appid = "smoketpk36.UpdateMode_Rollback"; + ASSERT_EQ(ci::AppInstaller::Result::OK, Install(old_path)); + + const char* argv[] = + {"", "-i", new_path.c_str(), "-u", kTestUserIdStr.c_str()}; + TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool { + EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, appid)); + EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid, + "res/VERSION", "1")); + return true; + }); +} + +TEST_F(SmokeTest, RecoveryMode_ForMountInstall) { + bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForMountInstall.tpk"; + RemoveAllRecoveryFiles(); + + std::vector args = + {"", "-w", path.string(), "-u", kTestUserIdStr.c_str()}; + CrashAfterEachStep(args, [=](int step) -> bool { + if (step >= 1) { + std::string pkgid = "smoketpk37"; + std::string appid = "smoketpk37.RecoveryMode_ForMountInstall"; + bf::path recovery_file = FindRecoveryFile(); + EXTENDED_ASSERT_FALSE(recovery_file.empty()); + EXTENDED_ASSERT_EQ(Recover(recovery_file), ci::AppInstaller::Result::OK); + EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, appid)); + } + return true; + }); +} + +TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) { + bf::path path_old = + kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate.tpk"; + bf::path path_new = + kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate2.tpk"; + RemoveAllRecoveryFiles(); + ASSERT_EQ(ci::AppInstaller::Result::OK, MountInstall(path_old)); + + std::vector args = + {"", "-w", path_new.string(), "-u", kTestUserIdStr.c_str()}; + CrashAfterEachStep(args, [=](int step) -> bool { + if (step >= 1) { + std::string pkgid = "smoketpk38"; + std::string appid = "smoketpk38.RecoveryMode_ForMountUpdate"; + + // Filesystem may be mounted after crash + ScopedTzipInterface poweroff_unmount_interface(pkgid); + poweroff_unmount_interface.Release(); + + bf::path recovery_file = FindRecoveryFile(); + EXTENDED_ASSERT_FALSE(recovery_file.empty()); + EXTENDED_ASSERT_EQ(Recover(recovery_file), ci::AppInstaller::Result::OK); + ScopedTzipInterface interface(pkgid); + EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, appid)); + + EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid, + "res/VERSION", "1")); + } + return true; + }); +} + +TEST_F(SmokeTest, MountInstallationMode_Rollback) { + bf::path path = + kSmokePackagesDirectory / "MountInstallationMode_Rollback.tpk"; + std::string pkgid = "smoketpk39"; + std::string appid = "smoketpk39.MountInstallationMode_Rollback"; + const char* argv[] = {"", "-w", path.c_str(), "-u", kTestUserIdStr.c_str()}; + + TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool { + ScopedTzipInterface package_mount(pkgid); + EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, appid)); + return true; + }); +} + +TEST_F(SmokeTest, MountUpdateMode_Rollback) { + bf::path old_path = kSmokePackagesDirectory / "MountUpdateMode_Rollback.tpk"; + bf::path new_path = kSmokePackagesDirectory / "MountUpdateMode_Rollback2.tpk"; + std::string pkgid = "smoketpk40"; + std::string appid = "smoketpk40.MountUpdateMode_Rollback"; + ASSERT_EQ(ci::AppInstaller::Result::OK, MountInstall(old_path)); + const char* argv[] = + {"", "-w", new_path.c_str(), "-u", kTestUserIdStr.c_str()}; + + TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool { + ScopedTzipInterface package_mount(pkgid); + EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, appid)); + EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid, + "res/VERSION", "1")); + return true; + }); +} + +} // namespace common_installer + +int main(int argc, char** argv) { + testing::InitGoogleTest(&argc, argv); + testing::AddGlobalTestEnvironment( + new common_installer::SmokeEnvironment(kGlobalUserUid)); + return RUN_ALL_TESTS(); +} diff --git a/src/unit_tests/smoke_test.cc b/src/unit_tests/smoke_test.cc index 4270c1b..169d5a6 100644 --- a/src/unit_tests/smoke_test.cc +++ b/src/unit_tests/smoke_test.cc @@ -65,7 +65,7 @@ TEST_F(SmokeTest, DeltaMode_Tpk) { std::string appid = "smokeapp18.DeltaModeTpk"; ASSERT_EQ(DeltaInstall(path, delta_package), ci::AppInstaller::Result::OK); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); // Check delta modifications bf::path root_path = ci::GetRootAppPath(false, @@ -74,7 +74,7 @@ TEST_F(SmokeTest, DeltaMode_Tpk) { ASSERT_TRUE(bf::exists(root_path / pkgid / "ADDED")); ASSERT_TRUE(bf::exists(root_path / pkgid / "bin" / "native")); ASSERT_TRUE(bf::exists(root_path / pkgid / "shared" / "res" / "native.png")); - ValidateFileContentInPackage(pkgid, "MODIFIED", "version 2\n"); + ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "MODIFIED", "version 2\n")); } TEST_F(SmokeTest, DeltaMode_Tpk_Rollback) { @@ -86,7 +86,7 @@ TEST_F(SmokeTest, DeltaMode_Tpk_Rollback) { ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK); ASSERT_EQ(Install(delta_package, RequestResult::FAIL), ci::AppInstaller::Result::ERROR); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); // Check delta modifications bf::path root_path = ci::GetRootAppPath(false, kTestUserId); @@ -95,7 +95,9 @@ TEST_F(SmokeTest, DeltaMode_Tpk_Rollback) { ASSERT_TRUE(bf::exists(root_path / pkgid / "bin" / "basicdali")); ASSERT_TRUE(bf::exists(root_path / pkgid / "shared" / "res" / "basicdali.png")); - ValidateFileContentInPackage(pkgid, "res/MODIFIED", "version 1\n"); + ASSERT_TRUE(ValidateFileContentInPackage(pkgid, + "res/MODIFIED", + "version 1\n")); } TEST_F(SmokeTest, ReinstallMode_Tpk) { @@ -110,7 +112,7 @@ TEST_F(SmokeTest, ReinstallMode_Tpk) { ASSERT_FALSE(error); ASSERT_TRUE(ci::CopyDir(rds_directory, sdk_expected_dir)); ASSERT_EQ(RDSUpdate(path, pkgid), ci::AppInstaller::Result::OK); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); // Check rds modifications bf::path root_path = ci::GetRootAppPath(false, @@ -119,7 +121,7 @@ TEST_F(SmokeTest, ReinstallMode_Tpk) { ASSERT_TRUE(bf::exists(root_path / pkgid / "ADDED")); ASSERT_TRUE(bf::exists(root_path / pkgid / "bin" / "native")); ASSERT_TRUE(bf::exists(root_path / pkgid / "shared" / "res" / "native.png")); - ValidateFileContentInPackage(pkgid, "MODIFIED", "version 2\n"); + ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "MODIFIED", "version 2\n")); } TEST_F(SmokeTest, InstallationMode_Tpk) { @@ -127,7 +129,7 @@ TEST_F(SmokeTest, InstallationMode_Tpk) { std::string pkgid = "smokeapp12"; std::string appid = "smokeapp12.InstallationModeTpk"; ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); } TEST_F(SmokeTest, UpdateMode_Tpk) { @@ -136,7 +138,7 @@ TEST_F(SmokeTest, UpdateMode_Tpk) { std::string pkgid = "smokeapp13"; std::string appid = "smokeapp13.UpdateModeTpk"; ASSERT_EQ(Update(path_old, path_new), ci::AppInstaller::Result::OK); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "VERSION", "2\n")); } @@ -147,7 +149,7 @@ TEST_F(SmokeTest, DeinstallationMode_Tpk) { std::string appid = "smokeapp14.DeinstallationModeTpk"; ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK); ASSERT_EQ(Uninstall(pkgid, false), ci::AppInstaller::Result::OK); - CheckPackageNonExistance(pkgid, appid); + ASSERT_TRUE(CheckPackageNonExistance(pkgid, appid)); } TEST_F(SmokeTest, EnablePkg) { @@ -168,7 +170,7 @@ TEST_F(SmokeTest, DisablePkg) { ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK); ASSERT_EQ(DisablePackage(pkgid), ci::AppInstaller::Result::OK); ASSERT_TRUE(ci::QueryIsDisabledPackage(pkgid, kTestUserId)); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); } TEST_F(SmokeTest, RecoveryMode_Tpk_Installation) { @@ -183,7 +185,7 @@ TEST_F(SmokeTest, RecoveryMode_Tpk_Installation) { bf::path recovery_file = FindRecoveryFile(); ASSERT_FALSE(recovery_file.empty()); ASSERT_EQ(Recover(recovery_file), ci::AppInstaller::Result::OK); - CheckPackageNonExistance(pkgid, appid); + ASSERT_TRUE(CheckPackageNonExistance(pkgid, appid)); } TEST_F(SmokeTest, RecoveryMode_Tpk_Update) { @@ -200,7 +202,7 @@ TEST_F(SmokeTest, RecoveryMode_Tpk_Update) { bf::path recovery_file = FindRecoveryFile(); ASSERT_FALSE(recovery_file.empty()); ASSERT_EQ(Recover(recovery_file), ci::AppInstaller::Result::OK); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "VERSION", "1\n")); } @@ -211,7 +213,7 @@ TEST_F(SmokeTest, MountInstallationMode_Tpk) { std::string appid = "smokeapp26.MountInstallationModeTpk"; ASSERT_EQ(MountInstall(path), ci::AppInstaller::Result::OK); ScopedTzipInterface package_mount(pkgid); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); } TEST_F(SmokeTest, MountUpdateMode_Tpk) { @@ -221,7 +223,7 @@ TEST_F(SmokeTest, MountUpdateMode_Tpk) { std::string appid = "smokeapp27.MountUpdateModeTpk"; ASSERT_EQ(MountUpdate(path_old, path_new), ci::AppInstaller::Result::OK); ScopedTzipInterface package_mount(pkgid); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/VERSION", "2\n")); } @@ -234,7 +236,7 @@ TEST_F(SmokeTest, MigrateLegacyExternalImage_Tpk) { bf::path legacy_path = kSmokePackagesDirectory / kLegacyExtImageDir; ASSERT_EQ(MigrateLegacyExternalImage(pkgid, path, legacy_path), ci::AppInstaller::Result::OK); - ValidateExternalPackage(pkgid, appid); + ASSERT_TRUE(ValidateExternalPackage(pkgid, appid)); } TEST_F(SmokeTest, InstallExternal_Tpk) { @@ -243,7 +245,7 @@ TEST_F(SmokeTest, InstallExternal_Tpk) { std::string pkgid = "smokeapp29"; std::string appid = "smokeapp29.InstallExternalTpk"; ASSERT_EQ(InstallExternal(path), ci::AppInstaller::Result::OK); - ValidateExternalPackage(pkgid, appid); + ASSERT_TRUE(ValidateExternalPackage(pkgid, appid)); } #define TEP_TEST_STARTING_BLOCK(NUMBER) \ @@ -259,7 +261,7 @@ TEST_F(SmokeTest, InstallExternal_Tpk) { TEST_F(SmokeTest, TEP_Tpk_TepInstall) { TEP_TEST_STARTING_BLOCK(1) ASSERT_EQ(InstallWithTEP(path, tep1), ci::AppInstaller::Result::OK); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n")); } @@ -267,7 +269,7 @@ TEST_F(SmokeTest, TEP_Tpk_TepInstallTepUpdate) { TEP_TEST_STARTING_BLOCK(2) ASSERT_EQ(InstallWithTEP(path, tep1), ci::AppInstaller::Result::OK); ASSERT_EQ(InstallWithTEP(path, tep2), ci::AppInstaller::Result::OK); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep2.tep", "tep2\n")); } @@ -275,7 +277,7 @@ TEST_F(SmokeTest, TEP_Tpk_NoTepInstallTepUpdate) { TEP_TEST_STARTING_BLOCK(3) ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK); ASSERT_EQ(InstallWithTEP(path, tep2), ci::AppInstaller::Result::OK); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep2.tep", "tep2\n")); } @@ -283,7 +285,7 @@ TEST_F(SmokeTest, TEP_Tpk_TepInstallNoTepUpdate) { TEP_TEST_STARTING_BLOCK(4) ASSERT_EQ(InstallWithTEP(path, tep1), ci::AppInstaller::Result::OK); ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n")); } @@ -292,7 +294,7 @@ TEST_F(SmokeTest, TEP_Tpk_TepInstallTepUpdateRollback) { ASSERT_EQ(InstallWithTEP(path, tep1), ci::AppInstaller::Result::OK); ASSERT_EQ(InstallWithTEP(path, tep2, RequestResult::FAIL), ci::AppInstaller::Result::ERROR); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n")); } @@ -301,7 +303,7 @@ TEST_F(SmokeTest, TEP_Tpk_NoTepInstallTepUpdateRollback) { ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK); ASSERT_EQ(InstallWithTEP(path, tep2, RequestResult::FAIL), ci::AppInstaller::Result::ERROR); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); bf::path root_path = ci::GetRootAppPath(false, kTestUserId); bf::path tep_file = root_path / pkgid / "tep" / "tep2.tep"; @@ -313,7 +315,7 @@ TEST_F(SmokeTest, TEP_Tpk_TepInstallNoTepUpdateRollback) { ASSERT_EQ(InstallWithTEP(path, tep1), ci::AppInstaller::Result::OK); ASSERT_EQ(Install(path, RequestResult::FAIL), ci::AppInstaller::Result::ERROR); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n")); } @@ -321,7 +323,7 @@ TEST_F(SmokeTest, TEP_Tpk_Mount_TepInstall) { TEP_TEST_STARTING_BLOCK(8) ASSERT_EQ(MountInstallWithTEP(path, tep1), ci::AppInstaller::Result::OK); ScopedTzipInterface package_mount(pkgid); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n")); } @@ -330,7 +332,7 @@ TEST_F(SmokeTest, TEP_Tpk_Mount_TepInstallTepUpdate) { ASSERT_EQ(MountInstallWithTEP(path, tep1), ci::AppInstaller::Result::OK); ASSERT_EQ(MountInstallWithTEP(path, tep2), ci::AppInstaller::Result::OK); ScopedTzipInterface package_mount(pkgid); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep2.tep", "tep2\n")); } @@ -339,7 +341,7 @@ TEST_F(SmokeTest, TEP_Tpk_Mount_NoTepInstallTepUpdate) { ASSERT_EQ(MountInstall(path), ci::AppInstaller::Result::OK); ASSERT_EQ(MountInstallWithTEP(path, tep2), ci::AppInstaller::Result::OK); ScopedTzipInterface package_mount(pkgid); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep2.tep", "tep2\n")); } @@ -348,7 +350,7 @@ TEST_F(SmokeTest, TEP_Tpk_Mount_TepInstallNoTepUpdate) { ASSERT_EQ(MountInstallWithTEP(path, tep1), ci::AppInstaller::Result::OK); ASSERT_EQ(MountInstall(path), ci::AppInstaller::Result::OK); ScopedTzipInterface package_mount(pkgid); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n")); } @@ -358,7 +360,7 @@ TEST_F(SmokeTest, TEP_Tpk_Mount_TepInstallTepUpdateRollback) { ASSERT_EQ(MountInstallWithTEP(path, tep2, RequestResult::FAIL), ci::AppInstaller::Result::ERROR); ScopedTzipInterface package_mount(pkgid); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n")); } @@ -368,7 +370,7 @@ TEST_F(SmokeTest, TEP_Tpk_Mount_NoTepInstallTepUpdateRollback) { ASSERT_EQ(MountInstallWithTEP(path, tep2, RequestResult::FAIL), ci::AppInstaller::Result::ERROR); ScopedTzipInterface package_mount(pkgid); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); bf::path root_path = ci::GetRootAppPath(false, kTestUserId); bf::path tep_file = root_path / pkgid / "tep" / "tep2.tep"; @@ -381,7 +383,7 @@ TEST_F(SmokeTest, TEP_Tpk_Mount_TepInstallNoTepUpdateRollback) { ASSERT_EQ(MountInstall(path, RequestResult::FAIL), ci::AppInstaller::Result::ERROR); ScopedTzipInterface package_mount(pkgid); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n")); } @@ -391,7 +393,7 @@ TEST_F(PreloadSmokeTest, InstallationMode_Preload) { std::string pkgid = "smoketpk29"; std::string appid = "smoketpk29.InstallationModePreload"; ASSERT_EQ(InstallPreload(path), ci::AppInstaller::Result::OK); - ValidatePackage(pkgid, appid, true); + ASSERT_TRUE(ValidatePackage(pkgid, appid, true)); } TEST_F(PreloadSmokeTest, UpdateMode_Preload) { @@ -402,7 +404,7 @@ TEST_F(PreloadSmokeTest, UpdateMode_Preload) { std::string appid = "smoketpk30.UpdateModePreload"; ASSERT_EQ(InstallPreload(path_old), ci::AppInstaller::Result::OK); ASSERT_EQ(InstallPreload(path_new), ci::AppInstaller::Result::OK); - ValidatePackage(pkgid, appid, true); + ASSERT_TRUE(ValidatePackage(pkgid, appid, true)); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/VERSION", "2", true)); } @@ -435,7 +437,7 @@ TEST_F(SmokeTest, InstallationMode_Rollback) { std::string appid = "smoketpk34.InstallationMode_Rollback"; ASSERT_EQ(ci::AppInstaller::Result::ERROR, Install(path, RequestResult::FAIL)); - CheckPackageNonExistance(pkgid, appid); + ASSERT_TRUE(CheckPackageNonExistance(pkgid, appid)); } TEST_F(SmokeTest, RecoveryMode_ForDelta) { @@ -452,7 +454,7 @@ TEST_F(SmokeTest, RecoveryMode_ForDelta) { bf::path recovery_file = FindRecoveryFile(); ASSERT_FALSE(recovery_file.empty()); ASSERT_EQ(ci::AppInstaller::Result::OK, Recover(recovery_file)); - ValidatePackage(pkgid, {appid}); + ASSERT_TRUE(ValidatePackage(pkgid, {appid})); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/MODIFIED", "version 1")); bf::path root_path = ci::GetRootAppPath(false, kTestUserId); @@ -468,7 +470,7 @@ TEST_F(SmokeTest, UpdateMode_Rollback) { ASSERT_EQ(ci::AppInstaller::Result::OK, Install(old_path)); ASSERT_EQ(ci::AppInstaller::Result::ERROR, Install(new_path, RequestResult::FAIL)); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/VERSION", "1")); } @@ -485,7 +487,7 @@ TEST_F(SmokeTest, RecoveryMode_ForMountInstall) { bf::path recovery_file = FindRecoveryFile(); ASSERT_FALSE(recovery_file.empty()); ASSERT_EQ(ci::AppInstaller::Result::OK, Recover(recovery_file)); - CheckPackageNonExistance(pkgid, appid); + ASSERT_TRUE(CheckPackageNonExistance(pkgid, appid)); } TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) { @@ -510,7 +512,7 @@ TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) { ASSERT_FALSE(recovery_file.empty()); ASSERT_EQ(ci::AppInstaller::Result::OK, Recover(recovery_file)); ScopedTzipInterface interface(pkgid); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/VERSION", "1")); } @@ -523,7 +525,7 @@ TEST_F(SmokeTest, MountInstallationMode_Rollback) { ASSERT_EQ(ci::AppInstaller::Result::ERROR, MountInstall(path, RequestResult::FAIL)); ScopedTzipInterface package_mount(pkgid); - CheckPackageNonExistance(pkgid, appid); + ASSERT_TRUE(CheckPackageNonExistance(pkgid, appid)); } TEST_F(SmokeTest, MountUpdateMode_Rollback) { @@ -535,7 +537,7 @@ TEST_F(SmokeTest, MountUpdateMode_Rollback) { ASSERT_EQ(ci::AppInstaller::Result::ERROR, MountInstall(new_path, RequestResult::FAIL)); ScopedTzipInterface package_mount(pkgid); - ValidatePackage(pkgid, appid); + ASSERT_TRUE(ValidatePackage(pkgid, appid)); ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/VERSION", "1")); } diff --git a/src/unit_tests/smoke_test_helper.cc b/src/unit_tests/smoke_test_helper.cc index 0edb55b..24c4f0a 100644 --- a/src/unit_tests/smoke_test_helper.cc +++ b/src/unit_tests/smoke_test_helper.cc @@ -35,9 +35,17 @@ class StepCrash : public ci::Step { // This version of backend will crash in the end // it is used for recovery testcase int main(const int argc, char* argv[]) { + int index = -1; + int backend_argc = argc; + if (!strcmp(argv[argc-2], "-idx")) { + index = atoi(argv[argc-1]); + backend_argc = argc-2; + LOG(DEBUG) << "Step crash after " << index << " step."; + } + ci::PkgmgrInstaller pkgmgr_installer; tpk::TpkAppQueryInterface interface; - ci::PkgMgrPtr pkgmgr = ci::PkgMgrInterface::Create(argc, argv, + ci::PkgMgrPtr pkgmgr = ci::PkgMgrInterface::Create(backend_argc, argv, &pkgmgr_installer, &interface); if (!pkgmgr) { @@ -46,7 +54,12 @@ int main(const int argc, char* argv[]) { } tpk::TpkInstaller t(pkgmgr); - t.AddStep(); + if (index != -1) { + t.AddStepAtIndex(index); + } else { + t.AddStep(); + } + if (t.Run() != ci::AppInstaller::Result::OK) { LOG(ERROR) << "TpkInstaller run failure"; return -1; diff --git a/src/unit_tests/smoke_utils.cc b/src/unit_tests/smoke_utils.cc index 4c41174..38fd105 100644 --- a/src/unit_tests/smoke_utils.cc +++ b/src/unit_tests/smoke_utils.cc @@ -251,52 +251,53 @@ bool ValidateFileContentInPackage(const std::string& pkgid, return content == expected; } -void ValidatePackageRWFS(const std::string& pkgid, uid_t uid) { +bool ValidatePackageRWFS(const std::string& pkgid, uid_t uid) { bf::path root_path = ci::GetRootAppPath(false, uid); bf::path package_path = root_path / pkgid; bf::path data_path = package_path / rwDirectories[DATA]; bf::path cache_path = package_path / rwDirectories[CACHE]; bf::path shared_data_path = package_path / rwDirectories[SHARED_DATA]; - ASSERT_TRUE(bf::exists(data_path)); - ASSERT_TRUE(bf::exists(cache_path)); + EXTENDED_ASSERT_TRUE(bf::exists(data_path)); + EXTENDED_ASSERT_TRUE(bf::exists(cache_path)); struct stat stats; stat(data_path.c_str(), &stats); // gid of RW dirs should be system_share boost::optional system_share = ci::GetGidByGroupName(kSystemShareGroupName); - ASSERT_EQ(uid, stats.st_uid); - ASSERT_EQ(*system_share, stats.st_gid); + EXTENDED_ASSERT_EQ(uid, stats.st_uid); + EXTENDED_ASSERT_EQ(*system_share, stats.st_gid); if (bf::exists(shared_data_path)) { stat(shared_data_path.c_str(), &stats); - ASSERT_EQ(uid, stats.st_uid); - ASSERT_EQ(*system_share, stats.st_gid); + EXTENDED_ASSERT_EQ(uid, stats.st_uid); + EXTENDED_ASSERT_EQ(*system_share, stats.st_gid); } stat(cache_path.c_str(), &stats); - ASSERT_EQ(uid, stats.st_uid); - ASSERT_EQ(*system_share, stats.st_gid); + EXTENDED_ASSERT_EQ(uid, stats.st_uid); + EXTENDED_ASSERT_EQ(*system_share, stats.st_gid); + return true; } -void ValidatePackageFS(const std::string& pkgid, const std::string&, +bool ValidatePackageFS(const std::string& pkgid, const std::string& appid, uid_t uid, gid_t gid, bool is_readonly) { bf::path root_path = ci::GetRootAppPath(is_readonly, uid); bf::path package_path = root_path / pkgid; bf::path shared_path = package_path / "shared"; - ASSERT_TRUE(bf::exists(root_path)); - ASSERT_TRUE(bf::exists(package_path)); - ASSERT_TRUE(bf::exists(shared_path)); + EXTENDED_ASSERT_TRUE(bf::exists(root_path)); + EXTENDED_ASSERT_TRUE(bf::exists(package_path)); + EXTENDED_ASSERT_TRUE(bf::exists(shared_path)); bf::path manifest_path = bf::path(getUserManifestPath(uid, is_readonly)) / (pkgid + ".xml"); - ASSERT_TRUE(bf::exists(manifest_path)); + EXTENDED_ASSERT_TRUE(bf::exists(manifest_path)); // backups should not exist bf::path package_backup = ci::GetBackupPathForPackagePath(package_path); bf::path manifest_backup = ci::GetBackupPathForManifestFile(manifest_path); - ASSERT_FALSE(bf::exists(package_backup)); - ASSERT_FALSE(bf::exists(manifest_backup)); + EXTENDED_ASSERT_FALSE(bf::exists(package_backup)); + EXTENDED_ASSERT_FALSE(bf::exists(manifest_backup)); for (bf::recursive_directory_iterator iter(package_path); iter != bf::recursive_directory_iterator(); ++iter) { @@ -314,84 +315,90 @@ void ValidatePackageFS(const std::string& pkgid, const std::string&, } struct stat stats; stat(iter->path().c_str(), &stats); - ASSERT_EQ(uid, stats.st_uid); - ASSERT_EQ(gid, stats.st_gid); + EXTENDED_ASSERT_EQ(uid, stats.st_uid); + EXTENDED_ASSERT_EQ(gid, stats.st_gid); } + return true; } -void PackageCheckCleanup(const std::string& pkgid, const std::string&, +bool PackageCheckCleanup(const std::string& pkgid, const std::string&, bool is_readonly) { bf::path root_path = ci::GetRootAppPath(is_readonly, kTestUserId); bf::path package_path = root_path / pkgid; - ASSERT_FALSE(bf::exists(package_path)); + EXTENDED_ASSERT_FALSE(bf::exists(package_path)); bf::path manifest_path = bf::path(getUserManifestPath( kTestUserId, is_readonly)) / (pkgid + ".xml"); - ASSERT_FALSE(bf::exists(manifest_path)); + EXTENDED_ASSERT_FALSE(bf::exists(manifest_path)); // backups should not exist bf::path package_backup = ci::GetBackupPathForPackagePath(package_path); bf::path manifest_backup = ci::GetBackupPathForManifestFile(manifest_path); - ASSERT_FALSE(bf::exists(package_backup)); - ASSERT_FALSE(bf::exists(manifest_backup)); + EXTENDED_ASSERT_FALSE(bf::exists(package_backup)); + EXTENDED_ASSERT_FALSE(bf::exists(manifest_backup)); + return true; } -void ValidatePackage(const std::string& pkgid, const std::string& appid, +bool ValidatePackage(const std::string& pkgid, const std::string& appid, bool is_readonly) { - ASSERT_TRUE(ci::QueryIsPackageInstalled( + EXTENDED_ASSERT_TRUE(ci::QueryIsPackageInstalled( pkgid, ci::GetRequestMode(kTestUserId), kTestUserId)); - ValidatePackageFS(pkgid, appid, kTestUserId, - kTestGroupId, is_readonly); + EXTENDED_ASSERT_TRUE(ValidatePackageFS(pkgid, appid, kTestUserId, + kTestGroupId, is_readonly)); if (kTestUserId == kGlobalUserUid) { ci::UserList list = ci::GetUserList(); for (auto& l : list) - ValidatePackageRWFS(pkgid, std::get<0>(l)); + EXTENDED_ASSERT_TRUE(ValidatePackageRWFS(pkgid, std::get<0>(l))); } else { - ValidatePackageRWFS(pkgid, kTestUserId); + EXTENDED_ASSERT_TRUE(ValidatePackageRWFS(pkgid, kTestUserId)); } + return true; } -void ValidateExternalPackage_FS(const std::string& pkgid, +bool ValidateExternalPackage_FS(const std::string& pkgid, const std::string& appid, uid_t uid) { - ASSERT_EQ(app2ext_usr_enable_external_pkg(pkgid.c_str(), uid), 0); + EXTENDED_ASSERT_EQ(app2ext_usr_enable_external_pkg(pkgid.c_str(), uid), 0); bf::path root_path = ci::GetRootAppPath(false, uid); - ASSERT_TRUE(bf::exists(root_path / pkgid / ".mmc" / "bin")); - ASSERT_TRUE(bf::exists(root_path / pkgid / ".mmc" / "lib")); - ASSERT_TRUE(bf::exists(root_path / pkgid / ".mmc" / "res")); - ValidatePackage(pkgid, appid); - ASSERT_EQ(app2ext_usr_disable_external_pkg(pkgid.c_str(), uid), 0); + EXTENDED_ASSERT_TRUE(bf::exists(root_path / pkgid / ".mmc" / "bin")); + EXTENDED_ASSERT_TRUE(bf::exists(root_path / pkgid / ".mmc" / "lib")); + EXTENDED_ASSERT_TRUE(bf::exists(root_path / pkgid / ".mmc" / "res")); + EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, appid)); + EXTENDED_ASSERT_EQ(app2ext_usr_disable_external_pkg(pkgid.c_str(), uid), 0); + return true; } -void ValidateExternalPackage(const std::string& pkgid, +bool ValidateExternalPackage(const std::string& pkgid, const std::string& appid) { std::string storage = ci::QueryStorageForPkgId(pkgid, kTestUserId); bf::path ext_mount_path = ci::GetExternalCardPath(); if (bf::is_empty(ext_mount_path)) { LOG(INFO) << "Sdcard not exists!"; - ASSERT_EQ(storage, "installed_internal"); + EXTENDED_ASSERT_EQ(storage, "installed_internal"); } else { - ASSERT_EQ(storage, "installed_external"); + EXTENDED_ASSERT_EQ(storage, "installed_external"); } - ValidateExternalPackage_FS(pkgid, appid, kTestUserId); + EXTENDED_ASSERT_TRUE(ValidateExternalPackage_FS(pkgid, appid, kTestUserId)); + return true; } -void CheckPackageNonExistance(const std::string& pkgid, +bool CheckPackageNonExistance(const std::string& pkgid, const std::string& appid, bool is_readonly) { - ASSERT_FALSE(ci::QueryIsPackageInstalled( + EXTENDED_ASSERT_FALSE(ci::QueryIsPackageInstalled( pkgid, ci::GetRequestMode(kTestUserId), kTestUserId)); - PackageCheckCleanup(pkgid, appid, is_readonly); + EXTENDED_ASSERT_TRUE(PackageCheckCleanup(pkgid, appid, is_readonly)); if (kTestUserId == kGlobalUserUid) { bf::path skel_path(kSkelDir); - ASSERT_FALSE(bf::exists(skel_path / pkgid)); + EXTENDED_ASSERT_FALSE(bf::exists(skel_path / pkgid)); ci::UserList list = ci::GetUserList(); for (auto& l : list) { bf::path root_path = ci::GetRootAppPath(false, std::get<0>(l)); bf::path package_path = root_path / pkgid; - ASSERT_FALSE(bf::exists(package_path)); + EXTENDED_ASSERT_FALSE(bf::exists(package_path)); } } + return true; } std::unique_ptr CreateQueryInterface() { @@ -405,6 +412,66 @@ std::unique_ptr CreateInstaller(ci::PkgMgrPtr pkgmgr) { return installer; } +void TestRollbackAfterEachStep( + int argc, const char* argv[], std::function validator) { + TestPkgmgrInstaller pkgmgr_installer; + std::unique_ptr query_interface = + CreateQueryInterface(); + auto pkgmgr = + ci::PkgMgrInterface::Create(argc, const_cast(argv), + &pkgmgr_installer, + query_interface.get()); + if (!pkgmgr) { + LOG(ERROR) << "Failed to initialize pkgmgr interface"; + return; + } + std::unique_ptr backend = CreateInstaller(pkgmgr); + int i; + for (i = backend->StepCount()-1; i >= 0; i--) { + backend->AddStepAtIndex(i); + LOG(DEBUG) << "StepFail is inserted at: " << i; + ASSERT_EQ(ci::AppInstaller::Result::ERROR, + backend->Run()); + if (!validator()) + break; + } + ASSERT_EQ(-1, i); +} + +void CrashAfterEachStep(std::vector args, + std::function validator) { + std::unique_ptr argv(new const char*[args.size()]); + for (size_t i = 0; i < args.size(); ++i) { + argv[i] = args[i].c_str(); + } + TestPkgmgrInstaller pkgmgr_installer; + std::unique_ptr query_interface = + CreateQueryInterface(); + auto pkgmgr = + ci::PkgMgrInterface::Create(args.size(), const_cast(argv.get()), + &pkgmgr_installer, + query_interface.get()); + if (!pkgmgr) { + LOG(ERROR) << "Failed to initialize pkgmgr interface"; + return; + } + std::unique_ptr backend = CreateInstaller(pkgmgr); + int stepCount = backend->StepCount(); + + args.push_back("-idx"); + args.push_back(std::to_string(stepCount)); + int i; + for (i = 0; i < stepCount; i++) { + ci::Subprocess backend_crash("/usr/bin/tpk-backend-ut/smoke-test-helper"); + args.back() = std::to_string(i); + backend_crash.Run(args); + ASSERT_NE(backend_crash.Wait(), 0); + if (!validator(i)) + break; + } + ASSERT_EQ(stepCount, i); +} + ci::AppInstaller::Result RunInstallerWithPkgrmgr(ci::PkgMgrPtr pkgmgr, RequestResult mode) { std::unique_ptr installer = CreateInstaller(pkgmgr); diff --git a/src/unit_tests/smoke_utils.h b/src/unit_tests/smoke_utils.h index df41971..7e8f242 100644 --- a/src/unit_tests/smoke_utils.h +++ b/src/unit_tests/smoke_utils.h @@ -23,6 +23,27 @@ #define SIZEOFARRAY(ARR) \ sizeof(ARR) / sizeof(ARR[0]) \ +#define EXTENDED_ASSERT_TRUE(expression) do { \ + bool tmp = expression; \ + EXPECT_TRUE(tmp) << #expression << " is not true"; \ + if (!tmp) \ + return false; \ +} while (0); + +#define EXTENDED_ASSERT_FALSE(expression) do { \ + bool tmp = expression; \ + EXPECT_FALSE(tmp) << #expression << " is not false"; \ + if (tmp) \ + return false; \ +} while (0); + +#define EXTENDED_ASSERT_EQ(expression, value) do { \ + auto ret = expression; \ + EXPECT_EQ(ret, value) << #expression << " is not equal to " << #value; \ + if (ret != value) \ + return false; \ +} while (0); + namespace bf = boost::filesystem; namespace bs = boost::system; @@ -120,24 +141,24 @@ bool ValidateFileContentInPackage(const std::string& pkgid, const std::string& expected, bool is_readonly = false); -void ValidatePackageRWFS(const std::string& pkgid, uid_t uid); +bool ValidatePackageRWFS(const std::string& pkgid, uid_t uid); -void ValidatePackageFS(const std::string& pkgid, const std::string& appid, +bool ValidatePackageFS(const std::string& pkgid, const std::string& appid, uid_t uid, gid_t gid, bool is_readonly = false); -void PackageCheckCleanup(const std::string& pkgid, const std::string&, +bool PackageCheckCleanup(const std::string& pkgid, const std::string&, bool is_readonly = false); -void ValidatePackage(const std::string& pkgid, const std::string& appid, +bool ValidatePackage(const std::string& pkgid, const std::string& appid, bool is_readonly = false); -void ValidateExternalPackage_FS(const std::string& pkgid, +bool ValidateExternalPackage_FS(const std::string& pkgid, const std::string& appid, uid_t uid); -void ValidateExternalPackage(const std::string& pkgid, +bool ValidateExternalPackage(const std::string& pkgid, const std::string& appid); -void CheckPackageNonExistance(const std::string& pkgid, +bool CheckPackageNonExistance(const std::string& pkgid, const std::string& appid, bool is_readonly = false); @@ -147,6 +168,12 @@ std::unique_ptr CreateQueryInterface(); std::unique_ptr CreateInstaller(ci::PkgMgrPtr pkgmgr); +void TestRollbackAfterEachStep( + int argc, const char* argv[], std::function validator); + +void CrashAfterEachStep(std::vector args, + std::function validator); + ci::AppInstaller::Result RunInstallerWithPkgrmgr(ci::PkgMgrPtr pkgmgr, RequestResult mode); ci::AppInstaller::Result CallBackend(int argc, -- 2.7.4