Extensive tests for Recovery and Rollback 02/120102/1
authorPiotr Ganicz <p.ganicz@samsung.com>
Mon, 20 Mar 2017 14:41:46 +0000 (15:41 +0100)
committerPiotr Ganicz <p.ganicz@samsung.com>
Tue, 21 Mar 2017 10:43:16 +0000 (11:43 +0100)
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/116059/
 - https://review.tizen.org/gerrit/#/c/119925/

Change-Id: Ib39dfd3df2f42ff33644904f682775a6a9b113f7

CMakeLists.txt
src/unit_tests/CMakeLists.txt
src/unit_tests/extensive_smoke_test.cc [new file with mode: 0644]
src/unit_tests/smoke_test.cc
src/unit_tests/smoke_test_helper.cc
src/unit_tests/smoke_utils.cc
src/unit_tests/smoke_utils.h

index 465821f..86b3f98 100644 (file)
@@ -31,6 +31,7 @@ SET(TARGET_WGT_BACKEND "wgt-backend")
 SET(TARGET_LIBNAME_HYBRID "hybrid-installer")
 
 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")
 
index 5aa1409..6b0aac1 100644 (file)
@@ -6,6 +6,11 @@ ADD_EXECUTABLE(${TARGET_SMOKE_TEST}
   smoke_utils.h
   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
 )
@@ -14,6 +19,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}/../)
 
@@ -24,6 +30,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
@@ -33,9 +44,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_WGT} ${TARGET_LIBNAME_HYBRID} ${GTEST_MAIN_LIBRARIES})
+TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST_EXTENSIVE} PRIVATE ${TARGET_LIBNAME_WGT} ${TARGET_LIBNAME_HYBRID} ${GTEST_MAIN_LIBRARIES})
 TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST_HELPER} PRIVATE ${TARGET_LIBNAME_WGT})
 TARGET_LINK_LIBRARIES(${TARGET_MANIFEST_TEST} PRIVATE ${TARGET_LIBNAME_WGT} ${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 (file)
index 0000000..58f11f6
--- /dev/null
@@ -0,0 +1,388 @@
+// 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 <common/utils/subprocess.h>
+
+#include <common/utils/file_util.h>
+
+#include <gtest/gtest.h>
+#include <gtest/gtest-death-test.h>
+
+#include "unit_tests/smoke_utils.h"
+
+
+namespace common_installer {
+
+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(kNormalUserName));
+    } else {
+      kTestUserId = kGlobalUserUid;
+      kTestGroupId = kGlobalUserGid;
+      kTestUserIdStr = std::to_string(kTestUserId);
+    }
+    backups_ = SetupBackupDirectories();
+    for (auto& path : backups_)
+      BackupPath(path);
+  }
+  void TearDown() override {
+    ASSERT_TRUE(request_mode_ == ci::RequestMode::GLOBAL ||
+                (request_mode_ == ci::RequestMode::USER &&
+                kGlobalUserUid != kTestUserId));
+    UninstallAllSmokeApps(request_mode_);
+    for (auto& path : backups_)
+      RestorePath(path);
+    if (request_mode_ == ci::RequestMode::USER)
+      ASSERT_TRUE(DeleteTestUser(kNormalUserName));
+  }
+
+ private:
+  ci::RequestMode request_mode_;
+  std::vector<bf::path> backups_;
+};
+
+class SmokeTest : public testing::Test {
+};
+
+class PreloadSmokeTest : public testing::Test {
+  void SetUp() override {
+    ASSERT_EQ(kGlobalUserUid, kTestUserId);
+  }
+};
+
+TEST_F(SmokeTest, RecoveryMode_ForInstallation) {
+  bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForInstallation.wgt";
+  std::string pkgid = "smokewgt09";
+  std::string appid = "smokewgt09.RecoveryModeForInstallation";
+
+  std::vector<std::string> args =
+      {"", "-i", path.string(), "-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, PackageType::WGT),
+          ci::AppInstaller::Result::OK);
+      EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid}));
+    }
+    return true;
+  });
+}
+
+TEST_F(SmokeTest, RecoveryMode_ForUpdate) {
+  bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForUpdate.wgt";
+  bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForUpdate_2.wgt";
+  RemoveAllRecoveryFiles();
+  ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
+  std::string pkgid = "smokewgt10";
+  std::string appid = "smokewgt10.RecoveryModeForUpdate";
+  AddDataFiles(pkgid, kTestUserId);
+
+  std::vector<std::string> args =
+      {"", "-i", path_new.string(), "-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, PackageType::WGT),
+          ci::AppInstaller::Result::OK);
+      EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
+
+      EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
+          "res/wgt/VERSION", "1\n"));
+      EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
+    }
+    return true;
+  });
+}
+
+TEST_F(SmokeTest, RecoveryMode_ForDelta) {
+  bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForDelta.wgt";
+  bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForDelta.delta";
+  std::string pkgid = "smokewgt30";
+  std::string appid = "smokewgt30.RecoveryModeForDelta";
+  bf::path recovery_file = FindRecoveryFile();
+  RemoveAllRecoveryFiles();
+  std::vector<std::string> args =
+      {"", "-i", path_new.string(), "-u", kTestUserIdStr.c_str()};
+  CrashAfterEachStep(args, [=](int step) -> bool {
+    if (step >= 1) {
+      EXTENDED_ASSERT_FALSE(recovery_file.empty());
+      EXTENDED_ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
+          ci::AppInstaller::Result::OK);
+      EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
+
+      EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
+          "res/wgt/VERSION", "1\n"));
+    }
+    return true;
+  });
+}
+
+TEST_F(SmokeTest, RecoveryMode_ForMountInstall) {
+  bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForMountInstall.wgt";
+  std::string pkgid = "smokewgt31";
+  std::string appid = "smokewgt31.RecoveryModeForMountInstall";
+  RemoveAllRecoveryFiles();
+  std::vector<std::string> args =
+      {"", "-w", path.string(), "-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, PackageType::WGT),
+          ci::AppInstaller::Result::OK);
+      EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid}));
+    }
+    return true;
+  });
+}
+
+TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) {
+  bf::path path_old =
+      kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate.wgt";
+  bf::path path_new =
+      kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate_2.wgt";
+  std::string pkgid = "smokewgt32";
+  std::string appid = "smokewgt32.RecoveryModeForMountUpdate";
+  RemoveAllRecoveryFiles();
+  ASSERT_EQ(MountInstall(path_old, PackageType::WGT),
+            ci::AppInstaller::Result::OK);
+  AddDataFiles(pkgid, kTestUserId);
+  std::vector<std::string> args =
+      {"", "-w", path_new.string(), "-u", kTestUserIdStr.c_str()};
+  CrashAfterEachStep(args, [=](int step) -> bool {
+    if (step >= 1) {
+      // 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, PackageType::WGT),
+          ci::AppInstaller::Result::OK);
+
+      ScopedTzipInterface interface(pkgid);
+      EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
+      EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(
+          pkgid, "res/wgt/VERSION", "1\n"));
+      EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
+    }
+    return true;
+  });
+}
+
+
+TEST_F(SmokeTest, InstallationMode_Rollback) {
+  bf::path path = kSmokePackagesDirectory / "InstallationMode_Rollback.wgt";
+  std::string pkgid = "smokewgt06";
+  std::string appid = "smokewgt06.InstallationModeRollback";
+
+  const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()};
+  TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
+    EXTENDED_ASSERT_EQ(Install(path, PackageType::WGT, RequestResult::FAIL),
+              ci::AppInstaller::Result::ERROR);
+    EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid}));
+    return true;
+  });
+}
+
+TEST_F(SmokeTest, UpdateMode_Rollback) {
+  bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Rollback.wgt";
+  bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Rollback_2.wgt";
+  std::string pkgid = "smokewgt07";
+  std::string appid = "smokewgt07.UpdateModeRollback";
+  ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
+  AddDataFiles(pkgid, kTestUserId);
+  const char* argv[] =
+      {"", "-i", path_new.c_str(), "-u", kTestUserIdStr.c_str()};
+  TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
+    EXTENDED_ASSERT_EQ(Install(path_new, PackageType::WGT, RequestResult::FAIL),
+                      ci::AppInstaller::Result::ERROR);
+    EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
+
+    EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
+        "res/wgt/VERSION", "1\n"));
+    EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
+    return true;
+  });
+}
+
+TEST_F(SmokeTest, DeltaMode_Rollback) {
+  bf::path path = kSmokePackagesDirectory / "DeltaMode_Rollback.wgt";
+  bf::path delta_package = kSmokePackagesDirectory / "DeltaMode_Rollback.delta";
+  std::string pkgid = "smokewgt01";
+  std::string appid = "smokewgt01.DeltaMode";
+  ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
+  AddDataFiles(pkgid, kTestUserId);
+  const char* argv[] =
+      {"", "-i", delta_package.c_str(), "-u", kTestUserIdStr.c_str()};
+  TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
+    EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
+    EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED",
+                                             "version 1\n"));
+    EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
+    EXTENDED_ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
+                           "res/wgt/DELETED"));
+    EXTENDED_ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
+                            "res/wgt/ADDED"));
+    return true;
+  });
+}
+
+TEST_F(SmokeTest, InstallationMode_Rollback_Hybrid) {
+  bf::path path = kSmokePackagesDirectory /
+      "InstallationMode_Rollback_Hybrid.wgt";
+  std::string pkgid = "smokehyb07";
+  std::string appid1 = "smokehyb07.web";
+  const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()};
+  TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
+     EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid1}));
+     return true;
+  }, PackageType::HYBRID);
+}
+
+TEST_F(SmokeTest, UpdateMode_Rollback_Hybrid) {
+  bf::path path_old = kSmokePackagesDirectory /
+      "UpdateMode_Rollback_Hybrid.wgt";
+  bf::path path_new = kSmokePackagesDirectory /
+      "UpdateMode_Rollback_Hybrid_2.wgt";
+  std::string pkgid = "smokehyb08";
+  std::string appid1 = "smokehyb08.web";
+  ASSERT_EQ(Install(path_old, PackageType::HYBRID),
+            ci::AppInstaller::Result::OK);
+  AddDataFiles(pkgid, kTestUserId);
+  const char* argv[] =
+      {"", "-i", path_new.c_str(), "-u", kTestUserIdStr.c_str()};
+  TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
+    EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
+
+    EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
+        "res/wgt/VERSION", "1\n"));
+    EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
+        "lib/VERSION", "1\n"));
+    EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
+    return true;
+  }, PackageType::HYBRID);
+}
+
+TEST_F(SmokeTest, DeltaMode_Rollback_Hybrid) {
+  bf::path path = kSmokePackagesDirectory / "DeltaMode_Rollback_Hybrid.wgt";
+  bf::path delta_package = kSmokePackagesDirectory /
+      "DeltaMode_Rollback_Hybrid.delta";
+  std::string pkgid = "smokehyb11";
+  std::string appid1 = "smokehyb11.web";
+  ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK);
+  AddDataFiles(pkgid, kTestUserId);
+  const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()};
+  TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
+    EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
+    // Check delta modifications
+    bf::path root_path = GetPackageRoot(pkgid, kTestUserId);
+    EXTENDED_ASSERT_TRUE(bf::exists(root_path / "res" / "wgt" / "DELETED"));
+    EXTENDED_ASSERT_FALSE(bf::exists(root_path / "res" / "wgt" / "ADDED"));
+    EXTENDED_ASSERT_TRUE(bf::exists(root_path / "lib" / "DELETED"));
+    EXTENDED_ASSERT_FALSE(bf::exists(root_path / "lib" / "ADDED"));
+    EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED",
+                                             "version 1\n"));
+    EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/MODIFIED",
+                                             "version 1\n"));
+    EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
+    return true;
+  });
+}
+
+TEST_F(SmokeTest, MountInstallationMode_Rollback_Hybrid) {
+  bf::path path = kSmokePackagesDirectory /
+      "MountInstallationMode_Rollback_Hybrid.wgt";
+  std::string pkgid = "smokehyb09";
+  std::string appid1 = "smokehyb09.web";
+  const char* argv[] = {"", "-w", path.c_str(), "-u", kTestUserIdStr.c_str()};
+  TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
+    ScopedTzipInterface interface(pkgid);
+    EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid1}));
+    return true;
+  }, PackageType::HYBRID);
+}
+
+TEST_F(SmokeTest, MountUpdateMode_Rollback_Hybrid) {
+  bf::path path_old = kSmokePackagesDirectory /
+      "MountUpdateMode_Rollback_Hybrid.wgt";
+  bf::path path_new = kSmokePackagesDirectory /
+      "MountUpdateMode_Rollback_Hybrid_2.wgt";
+  std::string pkgid = "smokehyb10";
+  std::string appid1 = "smokehyb10.web";
+  ASSERT_EQ(MountInstall(path_old, PackageType::HYBRID),
+            ci::AppInstaller::Result::OK);
+  AddDataFiles(pkgid, kTestUserId);
+  const char* argv[] =
+      {"", "-w", path_new.c_str(), "-u", kTestUserIdStr.c_str()};
+  TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
+    ScopedTzipInterface interface(pkgid);
+    EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
+
+    EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
+        "res/wgt/VERSION", "1\n"));
+    EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
+        "lib/VERSION", "1\n"));
+    EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
+    return true;
+  });
+}
+
+TEST_F(SmokeTest, MountInstallationMode_Rollback) {
+  bf::path path =
+      kSmokePackagesDirectory / "MountInstallationMode_Rollback.wgt";
+  std::string pkgid = "smokewgt33";
+  std::string appid = "smokewgt33.web";
+  const char* argv[] = {"", "-w", path.c_str(), "-u", kTestUserIdStr.c_str()};
+  TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
+    ScopedTzipInterface interface(pkgid);
+    EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid}));
+    return true;
+  });
+}
+
+TEST_F(SmokeTest, MountUpdateMode_Rollback) {
+  bf::path path_old = kSmokePackagesDirectory / "MountUpdateMode_Rollback.wgt";
+  bf::path path_new =
+      kSmokePackagesDirectory / "MountUpdateMode_Rollback_2.wgt";
+  std::string pkgid = "smokewgt34";
+  std::string appid = "smokewgt34.web";
+  ASSERT_EQ(MountInstall(path_old, PackageType::WGT),
+            ci::AppInstaller::Result::OK);
+  AddDataFiles(pkgid, kTestUserId);
+  const char* argv[] =
+      {"", "-w", path_new.c_str(), "-u", kTestUserIdStr.c_str()};
+  TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
+    EXTENDED_ASSERT_EQ(MountInstall(path_new, PackageType::WGT,
+        RequestResult::FAIL), ci::AppInstaller::Result::ERROR);
+    ScopedTzipInterface interface(pkgid);
+    EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
+
+    EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
+        "res/wgt/VERSION", "1\n"));
+    EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
+    return true;
+  });
+}
+
+}  // namespace common_installer
+
+int main(int argc,  char** argv) {
+  ci::RequestMode request_mode = 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);
+  testing::Environment *env = testing::AddGlobalTestEnvironment(
+      new common_installer::SmokeEnvironment(request_mode));
+  return RUN_ALL_TESTS();
+}
index f446f8a..38c2b01 100644 (file)
@@ -61,7 +61,7 @@ TEST_F(SmokeTest, InstallationMode) {
   std::string pkgid = "smokewgt03";
   std::string appid = "smokewgt03.InstallationMode";
   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
-  ValidatePackage(pkgid, {appid});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
 }
 
 TEST_F(SmokeTest, UpdateMode) {
@@ -72,10 +72,10 @@ TEST_F(SmokeTest, UpdateMode) {
   ASSERT_EQ(Install(path_old, PackageType::WGT), ci::AppInstaller::Result::OK);
   AddDataFiles(pkgid, kTestUserId);
   ASSERT_EQ(Install(path_new, PackageType::WGT), ci::AppInstaller::Result::OK);
-  ValidatePackage(pkgid, {appid});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
 
   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
-  ValidateDataFiles(pkgid, kTestUserId);
+  ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
 }
 
 TEST_F(SmokeTest, DeinstallationMode) {
@@ -86,7 +86,7 @@ TEST_F(SmokeTest, DeinstallationMode) {
             ci::AppInstaller::Result::OK);
   ASSERT_EQ(Uninstall(pkgid, PackageType::WGT, false),
             ci::AppInstaller::Result::OK);
-  CheckPackageNonExistance(pkgid, {appid});
+  ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid}));
 }
 
 TEST_F(SmokeTest, RDSMode) {
@@ -102,7 +102,7 @@ TEST_F(SmokeTest, RDSMode) {
   ASSERT_TRUE(CopyDir(delta_directory, sdk_expected_directory));
   ASSERT_EQ(RDSUpdate(path, pkgid, PackageType::WGT),
             ci::AppInstaller::Result::OK);
-  ValidatePackage(pkgid, {appid});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
 
   // Check delta modifications
   ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
@@ -136,7 +136,7 @@ TEST_F(SmokeTest, DisablePkg) {
   ASSERT_EQ(DisablePackage(pkgid, PackageType::WGT),
             ci::AppInstaller::Result::OK);
   ASSERT_TRUE(ci::QueryIsDisabledPackage(pkgid, kTestUserId));
-  ValidatePackage(pkgid, {appid});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
 }
 
 TEST_F(SmokeTest, DeltaMode) {
@@ -146,7 +146,7 @@ TEST_F(SmokeTest, DeltaMode) {
   std::string appid = "smokewgt17.DeltaMode";
   ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::WGT),
             ci::AppInstaller::Result::OK);
-  ValidatePackage(pkgid, {appid});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
 
   // Check delta modifications
   ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
@@ -175,7 +175,7 @@ TEST_F(SmokeTest, RecoveryMode_ForInstallation) {
   ASSERT_FALSE(recovery_file.empty());
   ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
       ci::AppInstaller::Result::OK);
-  CheckPackageNonExistance(pkgid, {appid});
+  ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid}));
 }
 
 TEST_F(SmokeTest, RecoveryMode_ForUpdate) {
@@ -194,10 +194,10 @@ TEST_F(SmokeTest, RecoveryMode_ForUpdate) {
   ASSERT_FALSE(recovery_file.empty());
   ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
             ci::AppInstaller::Result::OK);
-  ValidatePackage(pkgid, {appid});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
 
   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
-  ValidateDataFiles(pkgid, kTestUserId);
+  ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
 }
 
 TEST_F(SmokeTest, RecoveryMode_ForDelta) {
@@ -215,7 +215,7 @@ TEST_F(SmokeTest, RecoveryMode_ForDelta) {
   ASSERT_FALSE(recovery_file.empty());
   ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
             ci::AppInstaller::Result::OK);
-  ValidatePackage(pkgid, {appid});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
 
   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
 }
@@ -233,7 +233,7 @@ TEST_F(SmokeTest, RecoveryMode_ForMountInstall) {
   ASSERT_FALSE(recovery_file.empty());
   ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
             ci::AppInstaller::Result::OK);
-  CheckPackageNonExistance(pkgid, {appid});
+  ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid}));
 }
 
 TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) {
@@ -261,9 +261,9 @@ TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) {
             ci::AppInstaller::Result::OK);
 
   ScopedTzipInterface interface(pkgid);
-  ValidatePackage(pkgid, {appid});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
-  ValidateDataFiles(pkgid, kTestUserId);
+  ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
 }
 
 TEST_F(SmokeTest, InstallationMode_GoodSignature) {
@@ -284,7 +284,7 @@ TEST_F(SmokeTest, InstallationMode_Rollback) {
   std::string appid = "smokewgt06.InstallationModeRollback";
   ASSERT_EQ(Install(path, PackageType::WGT, RequestResult::FAIL),
             ci::AppInstaller::Result::ERROR);
-  CheckPackageNonExistance(pkgid, {appid});
+  ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid}));
 }
 
 TEST_F(SmokeTest, UpdateMode_Rollback) {
@@ -296,10 +296,10 @@ TEST_F(SmokeTest, UpdateMode_Rollback) {
   AddDataFiles(pkgid, kTestUserId);
   ASSERT_EQ(Install(path_new, PackageType::WGT, RequestResult::FAIL),
                     ci::AppInstaller::Result::ERROR);
-  ValidatePackage(pkgid, {appid});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
 
   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
-  ValidateDataFiles(pkgid, kTestUserId);
+  ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
 }
 
 TEST_F(SmokeTest, DeltaMode_Rollback) {
@@ -312,10 +312,10 @@ TEST_F(SmokeTest, DeltaMode_Rollback) {
   ASSERT_EQ(Install(delta_package, PackageType::WGT, RequestResult::FAIL),
             ci::AppInstaller::Result::ERROR);
 
-  ValidatePackage(pkgid, {appid});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/MODIFIED",
                                            "version 1\n"));
-  ValidateDataFiles(pkgid, kTestUserId);
+  ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
   ASSERT_TRUE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
                          "res/wgt/DELETED"));
   ASSERT_FALSE(bf::exists(GetPackageRoot(pkgid, kTestUserId) /
@@ -328,7 +328,7 @@ TEST_F(SmokeTest, InstallationMode_Hybrid) {
   // Excutable for native app doesn't create symlink
   std::string appid1 = "smokehyb01.Web";
   ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK);
-  ValidatePackage(pkgid, {appid1});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
 }
 
 TEST_F(SmokeTest, UpdateMode_Hybrid) {
@@ -341,7 +341,7 @@ TEST_F(SmokeTest, UpdateMode_Hybrid) {
 //  AddDataFiles(pkgid, kTestUserId);
   ASSERT_EQ(Install(path_new, PackageType::HYBRID),
             ci::AppInstaller::Result::OK);
-  ValidatePackage(pkgid, {appid1});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
 
   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "VERSION", "2\n"));
@@ -356,7 +356,7 @@ TEST_F(SmokeTest, DeinstallationMode_Hybrid) {
             ci::AppInstaller::Result::OK);
   ASSERT_EQ(Uninstall(pkgid, PackageType::HYBRID, false),
             ci::AppInstaller::Result::OK);
-  CheckPackageNonExistance(pkgid, {appid1});
+  ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid1}));
 }
 
 TEST_F(SmokeTest, DeltaMode_Hybrid) {
@@ -366,7 +366,7 @@ TEST_F(SmokeTest, DeltaMode_Hybrid) {
   std::string appid1 = "smokehyb04.Web";
   ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::HYBRID),
             ci::AppInstaller::Result::OK);
-  ValidatePackage(pkgid, {appid1});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
 
   // Check delta modifications
   bf::path root_path = ci::GetRootAppPath(false,
@@ -389,7 +389,7 @@ TEST_F(SmokeTest, MountInstallationMode_Hybrid) {
   ASSERT_EQ(MountInstall(path, PackageType::HYBRID),
             ci::AppInstaller::Result::OK);
   ScopedTzipInterface interface(pkgid);
-  ValidatePackage(pkgid, {appid1});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
 }
 
 TEST_F(SmokeTest, MountUpdateMode_Hybrid) {
@@ -403,11 +403,11 @@ TEST_F(SmokeTest, MountUpdateMode_Hybrid) {
   ASSERT_EQ(MountInstall(path_new, PackageType::HYBRID),
             ci::AppInstaller::Result::OK);
   ScopedTzipInterface interface(pkgid);
-  ValidatePackage(pkgid, {appid1});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
 
   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/VERSION", "2\n"));
-  ValidateDataFiles(pkgid, kTestUserId);
+  ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
 }
 
 TEST_F(SmokeTest, InstallationMode_Rollback_Hybrid) {
@@ -417,7 +417,7 @@ TEST_F(SmokeTest, InstallationMode_Rollback_Hybrid) {
   std::string appid1 = "smokehyb07.web";
   ASSERT_EQ(Install(path, PackageType::HYBRID, RequestResult::FAIL),
             ci::AppInstaller::Result::ERROR);
-  CheckPackageNonExistance(pkgid, {appid1});
+  ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid1}));
 }
 
 TEST_F(SmokeTest, UpdateMode_Rollback_Hybrid) {
@@ -432,11 +432,11 @@ TEST_F(SmokeTest, UpdateMode_Rollback_Hybrid) {
   AddDataFiles(pkgid, kTestUserId);
   ASSERT_EQ(Install(path_new, PackageType::HYBRID,
       RequestResult::FAIL), ci::AppInstaller::Result::ERROR);
-  ValidatePackage(pkgid, {appid1});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
 
   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/VERSION", "1\n"));
-  ValidateDataFiles(pkgid, kTestUserId);
+  ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
 }
 
 TEST_F(SmokeTest, DeltaMode_Rollback_Hybrid) {
@@ -450,7 +450,7 @@ TEST_F(SmokeTest, DeltaMode_Rollback_Hybrid) {
   ASSERT_EQ(Install(delta_package, PackageType::HYBRID, RequestResult::FAIL),
             ci::AppInstaller::Result::ERROR);
 
-  ValidatePackage(pkgid, {appid1});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
   // Check delta modifications
   bf::path root_path = GetPackageRoot(pkgid, kTestUserId);
   ASSERT_TRUE(bf::exists(root_path / "res" / "wgt" / "DELETED"));
@@ -461,7 +461,7 @@ TEST_F(SmokeTest, DeltaMode_Rollback_Hybrid) {
                                            "version 1\n"));
   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/MODIFIED",
                                            "version 1\n"));
-  ValidateDataFiles(pkgid, kTestUserId);
+  ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
 }
 
 TEST_F(SmokeTest, MountInstallationMode_Rollback_Hybrid) {
@@ -472,7 +472,7 @@ TEST_F(SmokeTest, MountInstallationMode_Rollback_Hybrid) {
   ASSERT_EQ(MountInstall(path, PackageType::HYBRID, RequestResult::FAIL),
       ci::AppInstaller::Result::ERROR);
   ScopedTzipInterface interface(pkgid);
-  CheckPackageNonExistance(pkgid, {appid1});
+  ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid1}));
 }
 
 TEST_F(SmokeTest, MountUpdateMode_Rollback_Hybrid) {
@@ -488,11 +488,11 @@ TEST_F(SmokeTest, MountUpdateMode_Rollback_Hybrid) {
   ASSERT_EQ(MountInstall(path_new, PackageType::HYBRID,
       RequestResult::FAIL), ci::AppInstaller::Result::ERROR);
   ScopedTzipInterface interface(pkgid);
-  ValidatePackage(pkgid, {appid1});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid1}));
 
   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "lib/VERSION", "1\n"));
-  ValidateDataFiles(pkgid, kTestUserId);
+  ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
 }
 
 TEST_F(SmokeTest, MountInstallationMode) {
@@ -501,7 +501,7 @@ TEST_F(SmokeTest, MountInstallationMode) {
   std::string appid = "smokewgt28.InstallationMode";
   ASSERT_EQ(MountInstall(path, PackageType::WGT), ci::AppInstaller::Result::OK);
   ScopedTzipInterface interface(pkgid);
-  ValidatePackage(pkgid, {appid});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
 }
 
 TEST_F(SmokeTest, MountUpdateMode) {
@@ -515,10 +515,10 @@ TEST_F(SmokeTest, MountUpdateMode) {
   ASSERT_EQ(MountInstall(path_new, PackageType::WGT),
             ci::AppInstaller::Result::OK);
   ScopedTzipInterface interface(pkgid);
-  ValidatePackage(pkgid, {appid});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
 
   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2\n"));
-  ValidateDataFiles(pkgid, kTestUserId);
+  ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
 }
 
 TEST_F(SmokeTest, MountInstallationMode_Rollback) {
@@ -529,7 +529,7 @@ TEST_F(SmokeTest, MountInstallationMode_Rollback) {
   ASSERT_EQ(MountInstall(path, PackageType::WGT, RequestResult::FAIL),
             ci::AppInstaller::Result::ERROR);
   ScopedTzipInterface interface(pkgid);
-  CheckPackageNonExistance(pkgid, {appid});
+  ASSERT_TRUE(CheckPackageNonExistance(pkgid, {appid}));
 }
 
 TEST_F(SmokeTest, MountUpdateMode_Rollback) {
@@ -544,10 +544,10 @@ TEST_F(SmokeTest, MountUpdateMode_Rollback) {
   ASSERT_EQ(MountInstall(path_new, PackageType::WGT,
       RequestResult::FAIL), ci::AppInstaller::Result::ERROR);
   ScopedTzipInterface interface(pkgid);
-  ValidatePackage(pkgid, {appid});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
 
   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
-  ValidateDataFiles(pkgid, kTestUserId);
+  ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
 }
 
 TEST_F(SmokeTest, UserDefinedPlugins) {
@@ -559,7 +559,7 @@ TEST_F(SmokeTest, UserDefinedPlugins) {
   std::string power_privilege = "http://tizen.org/privilege/power";
 
   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
-  ValidatePackage(pkgid, {appid});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
   std::vector<std::string> res;
   ASSERT_TRUE(ci::QueryPrivilegesForPkgId(pkgid, kTestUserId, &res));
   ASSERT_TRUE(std::find(res.begin(), res.end(), call_privilege) != res.end());
@@ -597,7 +597,7 @@ TEST_F(PreloadSmokeTest, InstallationMode_Preload) {
   std::string appid = "smokewgt37.InstallationModePreload";
   ASSERT_EQ(InstallPreload(path, PackageType::WGT),
             ci::AppInstaller::Result::OK);
-  ValidatePackage(pkgid, {appid}, true);
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid}, true));
 }
 
 TEST_F(PreloadSmokeTest, UpdateMode_Preload) {
@@ -611,11 +611,11 @@ TEST_F(PreloadSmokeTest, UpdateMode_Preload) {
   AddDataFiles(pkgid, kTestUserId);
   ASSERT_EQ(InstallPreload(path_new, PackageType::WGT),
             ci::AppInstaller::Result::OK);
-  ValidatePackage(pkgid, {appid}, true);
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid}, true));
 
   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2",
                                            true));
-  ValidateDataFiles(pkgid, kTestUserId);
+  ASSERT_TRUE(ValidateDataFiles(pkgid, kTestUserId));
 }
 
 TEST_F(PreloadSmokeTest, DeinstallationMode_Preload) {
@@ -646,7 +646,7 @@ TEST_F(SmokeTest, SharedRes30) {
   std::string pkgid = "smokeSh3xx";
   std::string appid = "smokeSh3xx.SharedRes30";
   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
-  ValidatePackage(pkgid, {appid});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
   bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT"));  // NOLINT
   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "shared" / "res" / "SHARED-WGT"));  // NOLINT
@@ -659,7 +659,7 @@ TEST_F(SmokeTest, SharedRes30Delta) {
   std::string appid = "smokeSh3De.SharedRes30Delta";
   ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::WGT),
             ci::AppInstaller::Result::OK);
-  ValidatePackage(pkgid, {appid});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
   // Check delta modifications
   bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-2"));  // NOLINT
@@ -674,7 +674,7 @@ TEST_F(SmokeTest, SharedRes30Hybrid) {
   std::string appid1 = "smokeSh3Hy.SharedRes30Hybrid";
   std::string appid2 = "sharedres30hybridserivce";
   ASSERT_EQ(Install(path, PackageType::HYBRID), ci::AppInstaller::Result::OK);
-  ValidatePackage(pkgid, {appid1, appid2});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid1, appid2}));
   bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT"));  // NOLINT
   ASSERT_TRUE(bf::is_symlink(root_path / pkgid / "shared" / "res" / "SHARED-WGT"));  // NOLINT
@@ -691,7 +691,7 @@ TEST_F(SmokeTest, SharedRes30HybridDelta) {
   std::string appid2 = "sharedres30hybriddeltaserivce";
   ASSERT_EQ(DeltaInstall(path, delta_package, PackageType::HYBRID),
             ci::AppInstaller::Result::OK);
-  ValidatePackage(pkgid, {appid1, appid2});
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid1, appid2}));
   // Check delta modifications
   bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
   ASSERT_TRUE(bf::is_regular_file(root_path / pkgid / "res" / "wgt" / "shared" / "res" / "SHARED-WGT-2"));  // NOLINT
index 0d37d1c..4501e89 100644 (file)
@@ -31,6 +31,14 @@ class StepCrash : public ci::Step {
 
 // this main of test binay in done purely for recovery smoke test.
 int main(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;
   wgt::WgtAppQueryInterface query_interface;
   auto pkgmgr = ci::PkgMgrInterface::Create(argc, argv, &pkgmgr_installer,
@@ -41,7 +49,11 @@ int main(int argc, char** argv) {
   }
 
   wgt::WgtInstaller installer(pkgmgr);
-  installer.AddStep<StepCrash>();
+  if (index != -1) {
+    installer.AddStepAtIndex<StepCrash>(index);
+  } else {
+    installer.AddStep<StepCrash>();
+  }
   return (installer.Run() == ci::AppInstaller::Result::OK) ? 0 : 1;
 }
 
index c1750f1..fff20f4 100644 (file)
@@ -8,6 +8,7 @@
 #include <boost/program_options.hpp>
 #include <boost/system/error_code.hpp>
 
+#include <common/utils/subprocess.h>
 #include <common/step/configuration/step_fail.h>
 #include <common/utils/user_util.h>
 #include <common/utils/file_util.h>
@@ -249,82 +250,83 @@ void AddDataFiles(const std::string& pkgid, uid_t uid) {
   }
 }
 
-void ValidateDataFiles(const std::string& pkgid, uid_t uid) {
+bool ValidateDataFiles(const std::string& pkgid, uid_t uid) {
   if (uid == kGlobalUserUid) {
     ci::UserList list = ci::GetUserList();
     for (auto l : list) {
       auto pkg_path = GetPackageRoot(pkgid, std::get<0>(l));
-      ASSERT_TRUE(bf::exists(pkg_path / "data" / "file1.txt"));
-      ASSERT_TRUE(bf::exists(pkg_path / "data" / "file2.txt"));
+      EXTENDED_ASSERT_TRUE(bf::exists(pkg_path / "data" / "file1.txt"));
+      EXTENDED_ASSERT_TRUE(bf::exists(pkg_path / "data" / "file2.txt"));
     }
   } else {
     auto pkg_path = GetPackageRoot(pkgid, uid);
-    ASSERT_TRUE(bf::exists(pkg_path / "data" / "file1.txt"));
-    ASSERT_TRUE(bf::exists(pkg_path / "data" / "file2.txt"));
+    EXTENDED_ASSERT_TRUE(bf::exists(pkg_path / "data" / "file1.txt"));
+    EXTENDED_ASSERT_TRUE(bf::exists(pkg_path / "data" / "file2.txt"));
   }
+  return true;
 }
 
-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<gid_t> system_share =
     ci::GetGidByGroupName(kSystemShareGroupName);
-  ASSERT_EQ(uid, stats.st_uid) << "Invalid gid: " << data_path;
-  ASSERT_EQ(*system_share, stats.st_gid) << "Invalid gid: " << data_path;
+  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) << "Invalid gid: " << shared_data_path;
-    ASSERT_EQ(*system_share, stats.st_gid) << "Invalid gid: "
-      << shared_data_path;
+    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) << "Invalid gid: " << cache_path;
-  ASSERT_EQ(*system_share, stats.st_gid) << "Invalid gid: " << cache_path;
+  EXTENDED_ASSERT_EQ(uid, stats.st_uid);
+  EXTENDED_ASSERT_EQ(*system_share, stats.st_gid);
+  return true;
 }
 
-void ValidatePackageFS(const std::string& pkgid,
+bool ValidatePackageFS(const std::string& pkgid,
                        const std::vector<std::string>& appids,
                        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));
 
   for (auto& appid : appids) {
     bf::path binary_path = package_path / "bin" / appid;
-    ASSERT_TRUE(bf::exists(binary_path));
+    EXTENDED_ASSERT_TRUE(bf::exists(binary_path));
   }
 
   bf::path widget_root_path = package_path / "res" / "wgt";
   bf::path config_path = widget_root_path / "config.xml";
-  ASSERT_TRUE(bf::exists(widget_root_path));
-  ASSERT_TRUE(bf::exists(config_path));
+  EXTENDED_ASSERT_TRUE(bf::exists(widget_root_path));
+  EXTENDED_ASSERT_TRUE(bf::exists(config_path));
 
   bf::path private_tmp_path = package_path / "tmp";
-  ASSERT_TRUE(bf::exists(private_tmp_path));
+  EXTENDED_ASSERT_TRUE(bf::exists(private_tmp_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) {
@@ -342,9 +344,10 @@ void ValidatePackageFS(const std::string& pkgid,
     }
     struct stat stats;
     stat(iter->path().c_str(), &stats);
-    ASSERT_EQ(uid, stats.st_uid) << "Invalid uid: " << iter->path();
-    ASSERT_EQ(gid, stats.st_gid) << "Invalid gid: " << iter->path();
+    EXTENDED_ASSERT_EQ(uid, stats.st_uid);
+    EXTENDED_ASSERT_EQ(gid, stats.st_gid);
   }
+  return true;
 }
 
 void PackageCheckCleanup(const std::string& pkgid,
@@ -364,18 +367,20 @@ void PackageCheckCleanup(const std::string& pkgid,
   ASSERT_FALSE(bf::exists(manifest_backup));
 }
 
-void ValidatePackage(const std::string& pkgid,
+bool ValidatePackage(const std::string& pkgid,
     const std::vector<std::string>& appids, bool is_readonly) {
-  ASSERT_TRUE(ci::QueryIsPackageInstalled(
+  EXTENDED_ASSERT_TRUE(ci::QueryIsPackageInstalled(
       pkgid, ci::GetRequestMode(kTestUserId), kTestUserId));
-  ValidatePackageFS(pkgid, appids, kTestUserId, kTestGroupId, is_readonly);
+  EXTENDED_ASSERT_TRUE(ValidatePackageFS(
+      pkgid, appids, 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 ValidateExternalPackageFS(const std::string& pkgid,
@@ -411,22 +416,23 @@ void ValidateExternalPackage(const std::string& pkgid,
   }
 }
 
-void CheckPackageNonExistance(const std::string& pkgid,
+bool CheckPackageNonExistance(const std::string& pkgid,
                               const std::vector<std::string>& appids) {
-  ASSERT_FALSE(ci::QueryIsPackageInstalled(
+  EXTENDED_ASSERT_FALSE(ci::QueryIsPackageInstalled(
       pkgid, ci::GetRequestMode(kTestUserId),
       kTestUserId));
   PackageCheckCleanup(pkgid, appids);
   if (kTestUserId == kGlobalUserUid) {
       ci::UserList list = ci::GetUserList();
       bf::path skel_path(kSkelDir);
-      ASSERT_FALSE(bf::exists(skel_path / pkgid));
+      EXTENDED_ASSERT_FALSE(bf::exists(skel_path / pkgid));
       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;
 }
 
 void CheckPackageReadonlyNonExistance(const std::string& pkgid,
@@ -456,6 +462,68 @@ std::unique_ptr<ci::AppInstaller> CreateInstaller(ci::PkgMgrPtr pkgmgr,
   }
 }
 
+void TestRollbackAfterEachStep(int argc, const char*argv[],
+                               std::function<bool()> validator,
+                               PackageType type) {
+  TestPkgmgrInstaller pkgmgr_installer;
+  std::unique_ptr<ci::AppQueryInterface> query_interface =
+      CreateQueryInterface();
+  auto pkgmgr =
+      ci::PkgMgrInterface::Create(argc, const_cast<char**>(argv),
+                                  &pkgmgr_installer,
+                                  query_interface.get());
+  if (!pkgmgr) {
+    LOG(ERROR) << "Failed to initialize pkgmgr interface";
+    return;
+  }
+  std::unique_ptr<ci::AppInstaller> backend = CreateInstaller(pkgmgr, type);
+  int i;
+  for (i = backend->StepCount()-1; i >= 0; i--) {
+    backend->AddStepAtIndex<ci::configuration::StepFail>(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<std::string> args,
+                        std::function<bool(int iter)> validator,
+                        PackageType type) {
+  std::unique_ptr<const char*[]> 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<ci::AppQueryInterface> query_interface =
+         CreateQueryInterface();
+    auto pkgmgr =
+        ci::PkgMgrInterface::Create(args.size(), const_cast<char**>(argv.get()),
+                                    &pkgmgr_installer,
+                                    query_interface.get());
+    if (!pkgmgr) {
+      LOG(ERROR) << "Failed to initialize pkgmgr interface";
+      return;
+    }
+    std::unique_ptr<ci::AppInstaller> backend = CreateInstaller(pkgmgr, type);
+    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,
                                                  PackageType type,
                                                  RequestResult mode) {
index efc2551..d0a4b47 100644 (file)
@@ -5,6 +5,7 @@
 #ifndef UNIT_TESTS_SMOKE_UTILS_H_
 #define UNIT_TESTS_SMOKE_UTILS_H_
 
+
 #include <boost/filesystem/path.hpp>
 
 #include <common/paths.h>
 #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;
 namespace ci = common_installer;
@@ -140,18 +162,18 @@ bool ValidateFileContentInPackage(const std::string& pkgid,
 
 void AddDataFiles(const std::string& pkgid, uid_t uid);
 
-void ValidateDataFiles(const std::string& pkgid, uid_t uid);
+bool ValidateDataFiles(const std::string& pkgid, uid_t uid);
 
-void ValidatePackageRWFS(const std::string& pkgid, uid_t uid);
+bool ValidatePackageRWFS(const std::string& pkgid, uid_t uid);
 
-void ValidatePackageFS(const std::string& pkgid,
+bool ValidatePackageFS(const std::string& pkgid,
                        const std::vector<std::string>& appids,
                        uid_t uid, gid_t gid, bool is_readonly);
 
 void PackageCheckCleanup(const std::string& pkgid,
     const std::vector<std::string>&, bool is_readonly = false);
 
-void ValidatePackage(const std::string& pkgid,
+bool ValidatePackage(const std::string& pkgid,
     const std::vector<std::string>& appids, bool is_readonly = false);
 
 void ValidateExternalPackageFS(const std::string& pkgid,
@@ -161,7 +183,7 @@ void ValidateExternalPackageFS(const std::string& pkgid,
 void ValidateExternalPackage(const std::string& pkgid,
                              const std::vector<std::string>& appids);
 
-void CheckPackageNonExistance(const std::string& pkgid,
+bool CheckPackageNonExistance(const std::string& pkgid,
                               const std::vector<std::string>& appids);
 
 void CheckPackageReadonlyNonExistance(const std::string& pkgid,
@@ -172,6 +194,14 @@ std::unique_ptr<ci::AppQueryInterface> CreateQueryInterface();
 std::unique_ptr<ci::AppInstaller> CreateInstaller(ci::PkgMgrPtr pkgmgr,
                                                   PackageType type);
 
+void TestRollbackAfterEachStep(int argc, const char*argv[],
+                               std::function<bool()> validator,
+                               PackageType type = PackageType::WGT);
+
+void CrashAfterEachStep(std::vector<std::string> args,
+                        std::function<bool(int iter)> validator,
+                        PackageType type = PackageType::WGT);
+
 ci::AppInstaller::Result RunInstallerWithPkgrmgr(ci::PkgMgrPtr pkgmgr,
                                                  PackageType type,
                                                  RequestResult mode);