Apply new library for smoke utils 01/149601/9
authorDamian Pietruchowski <d.pietruchow@samsung.com>
Tue, 12 Sep 2017 13:59:59 +0000 (15:59 +0200)
committerDamian Pietruchowski <d.pietruchow@samsung.com>
Tue, 17 Oct 2017 14:19:18 +0000 (16:19 +0200)
Wgt-backend and tpk-backend have common util functions for smoke tests.
They should be exported to lib in app-installers.

Submit together:
- https://review.tizen.org/gerrit/#/c/149136/
- https://review.tizen.org/gerrit/#/c/149137/

Change-Id: I30046243f9a1fb5baac6f148edb7c409ab69bea3
Signed-off-by: Damian Pietruchowski <d.pietruchow@samsung.com>
packaging/tpk-backend.spec
src/unit_tests/CMakeLists.txt
src/unit_tests/extensive_smoke_test.cc
src/unit_tests/smoke_test.cc
src/unit_tests/smoke_utils.cc
src/unit_tests/smoke_utils.h

index c9d0ae7..264e144 100644 (file)
@@ -11,6 +11,7 @@ Source1001:     tpk-backend-tests.manifest
 BuildRequires:  boost-devel
 BuildRequires:  cmake
 BuildRequires:  gtest-devel
+BuildRequires:  app-installers-tests
 BuildRequires:  pkgconfig(app-installers)
 BuildRequires:  pkgconfig(manifest-parser)
 BuildRequires:  pkgconfig(pkgmgr)
index 8838214..66d0437 100644 (file)
@@ -1,4 +1,5 @@
 SET(DESTINATION_DIR tpk-backend-ut)
+SET(TARGET_SMOKE_UTILS smoke-utils)
 
 # Executables
 ADD_EXECUTABLE(${TARGET_SMOKE_TEST}
@@ -51,8 +52,8 @@ APPLY_PKG_CONFIG(${TARGET_MANIFEST_TEST} PUBLIC
 # FindGTest module do not sets all needed libraries in GTEST_LIBRARIES and
 # GTest main libraries is still missing, so additional linking of
 # GTEST_MAIN_LIBRARIES is needed.
-TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST} PRIVATE ${TARGET_LIBNAME_TPK} ${GTEST_MAIN_LIBRARIES})
-TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST_EXTENSIVE} PRIVATE ${TARGET_LIBNAME_TPK} ${GTEST_MAIN_LIBRARIES})
+TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST} PRIVATE ${TARGET_LIBNAME_TPK} ${GTEST_MAIN_LIBRARIES} ${TARGET_SMOKE_UTILS})
+TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST_EXTENSIVE} PRIVATE ${TARGET_LIBNAME_TPK} ${GTEST_MAIN_LIBRARIES} ${TARGET_SMOKE_UTILS})
 TARGET_LINK_LIBRARIES(${TARGET_SMOKE_TEST_HELPER} PRIVATE ${TARGET_LIBNAME_TPK})
 TARGET_LINK_LIBRARIES(${TARGET_MANIFEST_TEST} PRIVATE ${TARGET_LIBNAME_TPK} ${GTEST_MAIN_LIBRARIES})
 
index 5d6bda8..e6b72b3 100644 (file)
 // Use of this source code is governed by an apache-2.0 license that can be
 // found in the LICENSE file.
 
+#include <unit_tests/common/smoke_utils.h>
+
 #include <gtest/gtest.h>
 #include <gtest/gtest-death-test.h>
 
 #include "unit_tests/smoke_utils.h"
 
+namespace ci = common_installer;
 
-namespace common_installer {
+namespace smoke_test {
 
 class SmokeEnvironment : public testing::Environment {
  public:
-  explicit SmokeEnvironment(uid_t uid) : uid_(uid) {
+  explicit SmokeEnvironment(ci::RequestMode mode) {
+    request_mode_ = mode;
   }
   void SetUp() override {
-    backups_ = SetupBackupDirectories();
+    if (request_mode_ == ci::RequestMode::USER)
+      ASSERT_TRUE(AddTestUser(&test_user));
+    backups_ = SetupBackupDirectories(test_user.uid);
     for (auto& path : backups_)
-      BackupPath(path);
+      ASSERT_TRUE(BackupPath(path));
   }
   void TearDown() override {
-    UninstallAllSmokeApps(RequestMode::GLOBAL);
+    ASSERT_TRUE(request_mode_ == ci::RequestMode::GLOBAL ||
+                (request_mode_ == ci::RequestMode::USER &&
+                kGlobalUserUid != test_user.uid));
+    TpkBackendInterface backend(std::to_string(test_user.uid));
+    UninstallAllSmokeApps(request_mode_, test_user.uid, &backend);
     for (auto& path : backups_)
-      RestorePath(path);
+      ASSERT_TRUE(RestorePath(path));
+    if (request_mode_ == ci::RequestMode::USER)
+      ASSERT_TRUE(DeleteTestUser());
   }
+  User test_user;
 
  private:
-  uid_t uid_;
+  ci::RequestMode request_mode_;
   std::vector<bf::path> backups_;
 };
 
+}  // namespace smoke_test
+
+namespace {
+
+testing::Environment *env = nullptr;
+void signalHandler(int signum) {
+  env->TearDown();
+  exit(signum);
+}
+
+smoke_test::SmokeEnvironment *dcast(testing::Environment* _env) {
+  return dynamic_cast<smoke_test::SmokeEnvironment *>(_env);
+}
+
+}  // namespace
+
+namespace smoke_test {
+
 class SmokeTest : public testing::Test {
+ public:
+  SmokeTest() : backend(std::to_string(dcast(env)->test_user.uid)),
+      params{PackageType::TPK, false} {
+    params.test_user.uid = dcast(env)->test_user.uid;
+    params.test_user.gid = dcast(env)->test_user.gid;
+  }
+ protected:
+  TpkBackendInterface backend;
+  TestParameters params;
 };
 
-
 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);
+  ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
+  std::string test_uid_str = std::to_string(params.test_user.uid);
   const char* argv[] =
-      {"", "-i", delta_package.c_str(), "-u", kTestUserIdStr.c_str()};
+      {"", "-i", delta_package.c_str(), "-u", test_uid_str.c_str()};
 
-  TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
-    EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, appid));
+  backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
+    EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {"basicdali"}, params));
 
     // Check delta modifications
 
-    bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
+    bf::path root_path = ci::GetRootAppPath(params.is_readonly,
+        params.test_user.uid);
     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"));
+        "res/MODIFIED", "version 1\n", params));
     return true;
   });
 }
@@ -65,44 +106,50 @@ TEST_F(SmokeTest, RecoveryMode_Tpk_Installation) {
   bf::path path = kSmokePackagesDirectory / "RecoveryMode_Tpk_Installation.tpk";
   std::string pkgid = "smokeapp15";
   std::string appid = "smokeapp15.RecoveryModeTpkInstallation";
-  RemoveAllRecoveryFiles();
+  RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
 
+  std::string test_uid_str = std::to_string(params.test_user.uid);
   std::vector<std::string> args =
-      {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()};
-  CrashAfterEachStep(args, [=](int step) -> bool {
+      {"", "-i", path.c_str(), "-u", test_uid_str.c_str()};
+  backend.CrashAfterEachStep(&args, [&](int step) -> bool {
     if (step >= 1) {
-      bf::path recovery_file = FindRecoveryFile();
+      bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
+      params.test_user.uid);
       EXTENDED_ASSERT_FALSE(recovery_file.empty());
-      EXTENDED_ASSERT_EQ(Recover(recovery_file), ci::AppInstaller::Result::OK);
-      EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, appid));
+      EXTENDED_ASSERT_EQ(backend.Recover(recovery_file),
+          ci::AppInstaller::Result::OK);
+      EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
     }
     return true;
-  });
-  RemoveAllRecoveryFiles();
+  }, params.pkg_type);
+  RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
 }
 
 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);
+  RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
+  ASSERT_EQ(backend.Install(path_old), ci::AppInstaller::Result::OK);
 
+  std::string test_uid_str = std::to_string(params.test_user.uid);
   std::vector<std::string> args =
-      {"", "-i", path_new.string(), "-u", kTestUserIdStr.c_str()};
-  CrashAfterEachStep(args, [=](int step) -> bool {
+      {"", "-i", path_new.string(), "-u", test_uid_str.c_str()};
+  backend.CrashAfterEachStep(&args, [&](int step) -> bool {
     if (step >= 1) {
       std::string pkgid = "smokeapp16";
       std::string appid = "smokeapp16.RecoveryModeTpkUpdate";
-      bf::path recovery_file = FindRecoveryFile();
+      bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
+          params.test_user.uid);
       EXTENDED_ASSERT_FALSE(recovery_file.empty());
-      EXTENDED_ASSERT_EQ(Recover(recovery_file), ci::AppInstaller::Result::OK);
-      EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, appid));
+      EXTENDED_ASSERT_EQ(backend.Recover(recovery_file),
+          ci::AppInstaller::Result::OK);
+      EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
 
       EXTENDED_ASSERT_TRUE(
-          ValidateFileContentInPackage(pkgid, "VERSION", "1\n"));
+          ValidateFileContentInPackage(pkgid, "VERSION", "1\n", params));
     }
     return true;
-  });
+  }, params.pkg_type);
 }
 
 #define TEP_TEST_STARTING_BLOCK(NUMBER)                                        \
@@ -118,25 +165,28 @@ TEST_F(SmokeTest, RecoveryMode_Tpk_Update) {
 
 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(),
+  ASSERT_EQ(backend.InstallWithTEP(path, tep1), ci::AppInstaller::Result::OK);
+  std::string test_uid_str = std::to_string(params.test_user.uid);
+  const char* argv[] = {"", "-i", path.c_str(), "-u", test_uid_str.c_str(),
                         "-e", tep1.c_str()};
-  TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
-    EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, appid));
+  backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
+    EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
     EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
-        "tep/tep1.tep", "tep1\n"));
+        "tep/tep1.tep", "tep1\n", params));
     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(),
+  ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
+  std::string test_uid_str = std::to_string(params.test_user.uid);
+  const char* argv[] = {"", "-i", path.c_str(), "-u", test_uid_str.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);
+  backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
+    EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
+    bf::path root_path = ci::GetRootAppPath(params.is_readonly,
+        params.test_user.uid);
     bf::path tep_file = root_path / pkgid / "tep" / "tep2.tep";
     EXTENDED_ASSERT_FALSE(bf::exists(tep_file));
     return true;
@@ -145,39 +195,44 @@ TEST_F(SmokeTest, TEP_Tpk_NoTepInstallTepUpdateRollback) {
 
 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));
+  ASSERT_EQ(backend.InstallWithTEP(path, tep1), ci::AppInstaller::Result::OK);
+  std::string test_uid_str = std::to_string(params.test_user.uid);
+  const char* argv[] = {"", "-i", path.c_str(), "-u", test_uid_str.c_str()};
+  backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
+    EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
     EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
-        "tep/tep1.tep", "tep1\n"));
+        "tep/tep1.tep", "tep1\n", params));
     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(),
+  ASSERT_EQ(backend.MountInstallWithTEP(path, tep1),
+      ci::AppInstaller::Result::OK);
+  std::string test_uid_str = std::to_string(params.test_user.uid);
+  const char* argv[] = {"", "-w", path.c_str(), "-u", test_uid_str.c_str(),
                         "-e", tep2.c_str()};
-  TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
-    ScopedTzipInterface package_mount(pkgid);
-    EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, appid));
+  backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
+    ScopedTzipInterface package_mount(pkgid, params.test_user.uid);
+    EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
     EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
-        "tep/tep1.tep", "tep1\n"));
+        "tep/tep1.tep", "tep1\n", params));
     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(),
+  ASSERT_EQ(backend.MountInstall(path), ci::AppInstaller::Result::OK);
+  std::string test_uid_str = std::to_string(params.test_user.uid);
+  const char* argv[] = {"", "-w", path.c_str(), "-u", test_uid_str.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);
+  backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
+    ScopedTzipInterface package_mount(pkgid, params.test_user.uid);
+    EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
+    bf::path root_path = ci::GetRootAppPath(params.is_readonly,
+        params.test_user.uid);
     bf::path tep_file = root_path / pkgid / "tep" / "tep2.tep";
     EXTENDED_ASSERT_FALSE(bf::exists(tep_file));
     return true;
@@ -186,13 +241,15 @@ TEST_F(SmokeTest, TEP_Tpk_Mount_NoTepInstallTepUpdateRollback) {
 
 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));
+  ASSERT_EQ(backend.MountInstallWithTEP(path, tep1),
+      ci::AppInstaller::Result::OK);
+  std::string test_uid_str = std::to_string(params.test_user.uid);
+  const char* argv[] = {"", "-i", path.c_str(), "-u", test_uid_str.c_str()};
+  backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
+    ScopedTzipInterface package_mount(pkgid, params.test_user.uid);
+    EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
     EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
-        "tep/tep1.tep", "tep1\n"));
+        "tep/tep1.tep", "tep1\n", params));
     return true;
   });
 }
@@ -201,10 +258,11 @@ 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()};
+  std::string test_uid_str = std::to_string(params.test_user.uid);
+  const char* argv[] = {"", "-i", path.c_str(), "-u", test_uid_str.c_str()};
 
-  TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool  {
-    EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, appid));
+  backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool  {
+    EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
     return true;
   });
 }
@@ -212,28 +270,33 @@ TEST_F(SmokeTest, InstallationMode_Rollback) {
 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));
+  RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
+  ASSERT_EQ(ci::AppInstaller::Result::OK, backend.Install(path_old));
 
+  std::string test_uid_str = std::to_string(params.test_user.uid);
   std::vector<std::string> args =
-    {"", "-i", path_new.string(), "-u", kTestUserIdStr.c_str()};
-  CrashAfterEachStep(args, [=](int step) -> bool {
+    {"", "-i", path_new.string(), "-u", test_uid_str.c_str()};
+  backend.CrashAfterEachStep(&args, [&](int step) -> bool {
     if (step >= 1) {
       std::string pkgid = "smoketpk35";
       std::string appid = "smoketpk35.RecoveryMode_ForDelta";
-      bf::path recovery_file = FindRecoveryFile();
+      bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
+          params.test_user.uid);
       EXTENDED_ASSERT_FALSE(recovery_file.empty());
-      EXTENDED_ASSERT_EQ(Recover(recovery_file), ci::AppInstaller::Result::OK);
-      EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
+      EXTENDED_ASSERT_EQ(backend.Recover(recovery_file),
+          ci::AppInstaller::Result::OK);
+      EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {"smoketpk35"}, params));
 
       EXTENDED_ASSERT_TRUE(
-          ValidateFileContentInPackage(pkgid, "res/MODIFIED", "version 1"));
-      bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
+          ValidateFileContentInPackage(pkgid, "res/MODIFIED", "version 1",
+              params));
+      bf::path root_path = ci::GetRootAppPath(params.is_readonly,
+          params.test_user.uid);
       EXTENDED_ASSERT_TRUE(bf::exists(root_path / pkgid / "res/DELETED"));
       EXTENDED_ASSERT_FALSE(bf::exists(root_path / pkgid / "res/ADDED"));
     }
     return true;
-  });
+  }, params.pkg_type);
 }
 
 TEST_F(SmokeTest, UpdateMode_Rollback) {
@@ -241,35 +304,39 @@ TEST_F(SmokeTest, UpdateMode_Rollback) {
   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));
+  ASSERT_EQ(ci::AppInstaller::Result::OK, backend.Install(old_path));
 
+  std::string test_uid_str = std::to_string(params.test_user.uid);
   const char* argv[] =
-      {"", "-i", new_path.c_str(), "-u", kTestUserIdStr.c_str()};
-  TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool  {
-    EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, appid));
+      {"", "-i", new_path.c_str(), "-u", test_uid_str.c_str()};
+  backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool  {
+    EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {"smoketpk36"}, params));
     EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
-                         "res/VERSION", "1"));
+        "res/VERSION", "1", params));
     return true;
   });
 }
 
 TEST_F(SmokeTest, RecoveryMode_ForMountInstall) {
   bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForMountInstall.tpk";
-  RemoveAllRecoveryFiles();
+  RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
 
+  std::string test_uid_str = std::to_string(params.test_user.uid);
   std::vector<std::string> args =
-      {"", "-w", path.string(), "-u", kTestUserIdStr.c_str()};
-  CrashAfterEachStep(args, [=](int step) -> bool {
+      {"", "-w", path.string(), "-u", test_uid_str.c_str()};
+  backend.CrashAfterEachStep(&args, [&](int step) -> bool {
     if (step >= 1) {
       std::string pkgid = "smoketpk37";
       std::string appid = "smoketpk37.RecoveryMode_ForMountInstall";
-      bf::path recovery_file = FindRecoveryFile();
+      bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
+      params.test_user.uid);
       EXTENDED_ASSERT_FALSE(recovery_file.empty());
-      EXTENDED_ASSERT_EQ(Recover(recovery_file), ci::AppInstaller::Result::OK);
-      EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, appid));
+      EXTENDED_ASSERT_EQ(backend.Recover(recovery_file),
+          ci::AppInstaller::Result::OK);
+      EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
     }
     return true;
-  });
+  }, params.pkg_type);
 }
 
 TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) {
@@ -277,31 +344,35 @@ TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) {
       kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate.tpk";
   bf::path path_new =
       kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate2.tpk";
-  RemoveAllRecoveryFiles();
-  ASSERT_EQ(ci::AppInstaller::Result::OK, MountInstall(path_old));
+  RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
+  ASSERT_EQ(ci::AppInstaller::Result::OK, backend.MountInstall(path_old));
 
+  std::string test_uid_str = std::to_string(params.test_user.uid);
   std::vector<std::string> args =
-      {"", "-w", path_new.string(), "-u", kTestUserIdStr.c_str()};
-  CrashAfterEachStep(args, [=](int step) -> bool {
+      {"", "-w", path_new.string(), "-u", test_uid_str.c_str()};
+  backend.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);
+      ScopedTzipInterface poweroff_unmount_interface(pkgid,
+          params.test_user.uid);
       poweroff_unmount_interface.Release();
 
-      bf::path recovery_file = FindRecoveryFile();
+      bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
+      params.test_user.uid);
       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_EQ(backend.Recover(recovery_file),
+          ci::AppInstaller::Result::OK);
+      ScopedTzipInterface interface(pkgid, params.test_user.uid);
+      EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {"smoketpk38"}, params));
 
       EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
-          "res/VERSION", "1"));
+        "res/VERSION", "1", params));
     }
     return true;
-  });
+  }, params.pkg_type);
 }
 
 TEST_F(SmokeTest, MountInstallationMode_Rollback) {
@@ -309,11 +380,12 @@ TEST_F(SmokeTest, MountInstallationMode_Rollback) {
       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()};
+  std::string test_uid_str = std::to_string(params.test_user.uid);
+  const char* argv[] = {"", "-w", path.c_str(), "-u", test_uid_str.c_str()};
 
-  TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool {
-    ScopedTzipInterface package_mount(pkgid);
-    EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, appid));
+  backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool {
+    ScopedTzipInterface package_mount(pkgid, params.test_user.uid);
+    EXTENDED_ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
     return true;
   });
 }
@@ -323,24 +395,32 @@ TEST_F(SmokeTest, MountUpdateMode_Rollback) {
   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));
+  ASSERT_EQ(ci::AppInstaller::Result::OK, backend.MountInstall(old_path));
+  std::string test_uid_str = std::to_string(params.test_user.uid);
   const char* argv[] =
-    {"", "-w", new_path.c_str(), "-u", kTestUserIdStr.c_str()};
+    {"", "-w", new_path.c_str(), "-u", test_uid_str.c_str()};
 
-  TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [=]() -> bool  {
-    ScopedTzipInterface package_mount(pkgid);
-    EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, appid));
+  backend.TestRollbackAfterEachStep(SIZEOFARRAY(argv), argv, [&]() -> bool  {
+    ScopedTzipInterface package_mount(pkgid, params.test_user.uid);
+    EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {"smoketpk40"}, params));
     EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
-        "res/VERSION", "1"));
+        "res/VERSION", "1", params));
     return true;
   });
 }
 
-}  // namespace common_installer
+}  // namespace smoke_test
 
 int main(int argc,  char** argv) {
+  ci::RequestMode request_mode = smoke_test::ParseRequestMode(argc, argv);
+  if (getuid() != 0 || request_mode != ci::RequestMode::GLOBAL) {
+    std::cout << "Skip tests for preload request" << std::endl;
+    ::testing::GTEST_FLAG(filter) = "SmokeTest.*";
+  }
   testing::InitGoogleTest(&argc, argv);
-  testing::AddGlobalTestEnvironment(
-      new common_installer::SmokeEnvironment(kGlobalUserUid));
+  ::env = testing::AddGlobalTestEnvironment(
+      new smoke_test::SmokeEnvironment(request_mode));
+  signal(SIGINT, ::signalHandler);
+  signal(SIGSEGV, ::signalHandler);
   return RUN_ALL_TESTS();
 }
index 8536959..cb62961 100644 (file)
 // found in the LICENSE file.
 
 #include <common/utils/subprocess.h>
+#include <common/utils/file_util.h>
+#include <common/pkgmgr_query.h>
+#include <unit_tests/common/smoke_utils.h>
 
 #include <gtest/gtest.h>
 #include <gtest/gtest-death-test.h>
 
 #include "unit_tests/smoke_utils.h"
 
+namespace st = smoke_test;
+namespace bf = boost::filesystem;
+namespace bs = boost::system;
+namespace ci = common_installer;
+namespace bo = boost::program_options;
 
-namespace common_installer {
+namespace smoke_test {
 
 class SmokeEnvironment : public testing::Environment {
  public:
   explicit SmokeEnvironment(ci::RequestMode mode) : request_mode_(mode) {
   }
   void SetUp() override {
-    if (request_mode_ == ci::RequestMode::USER) {
-      ASSERT_TRUE(AddTestUser(kNormalUserName));
-    } else {
-      kTestUserId = kGlobalUserUid;
-      kTestGroupId = kGlobalUserGid;
-      kTestUserIdStr = std::to_string(kTestUserId);
-    }
-    backups_ = SetupBackupDirectories();
+    if (request_mode_ == ci::RequestMode::USER)
+      ASSERT_TRUE(AddTestUser(&test_user));
+    backups_ = SetupBackupDirectories(test_user.uid);
     for (auto& path : backups_)
-      BackupPath(path);
+      ASSERT_TRUE(BackupPath(path));
   }
   void TearDown() override {
     ASSERT_TRUE(request_mode_ == ci::RequestMode::GLOBAL ||
                 (request_mode_ == ci::RequestMode::USER &&
-                kGlobalUserUid != kTestUserId));
-    UninstallAllSmokeApps(request_mode_);
+                kGlobalUserUid != test_user.uid));
+    TpkBackendInterface backend(std::to_string(test_user.uid));
+    UninstallAllSmokeApps(request_mode_, test_user.uid, &backend);
     for (auto& path : backups_)
-      RestorePath(path);
+      ASSERT_TRUE(RestorePath(path));
     if (request_mode_ == ci::RequestMode::USER)
-      ASSERT_TRUE(DeleteTestUser(kNormalUserName));
+      ASSERT_TRUE(DeleteTestUser());
   }
+  User test_user;
 
  private:
   ci::RequestMode request_mode_;
   std::vector<bf::path> backups_;
 };
 
+}  // namespace smoke_test
+
+namespace {
+
+testing::Environment *env = nullptr;
+void signalHandler(int signum) {
+  env->TearDown();
+  exit(signum);
+}
+
+smoke_test::SmokeEnvironment *dcast(testing::Environment* _env) {
+  return dynamic_cast<smoke_test::SmokeEnvironment *>(_env);
+}
+
+}  // namespace
+
+namespace smoke_test {
+
 class SmokeTest : public testing::Test {
+ public:
+  SmokeTest() : backend(std::to_string(dcast(env)->test_user.uid)),
+      params{PackageType::TPK, false} {
+    params.test_user.uid = dcast(env)->test_user.uid;
+    params.test_user.gid = dcast(env)->test_user.gid;
+  }
+ protected:
+  TpkBackendInterface backend;
+  TestParameters params;
+};
+
+class RollbackSmokeTest : public testing::Test {
+ public:
+  RollbackSmokeTest() : backend(std::to_string(dcast(env)->test_user.uid),
+      RequestResult::FAIL), params{PackageType::TPK, false} {
+    params.test_user.uid = dcast(env)->test_user.uid;
+    params.test_user.gid = dcast(env)->test_user.gid;
+  }
+ protected:
+  TpkBackendInterface backend;
+  TestParameters params;
 };
 
 class PreloadSmokeTest : public testing::Test {
-  void SetUp() override {
-    ASSERT_EQ(kGlobalUserUid, kTestUserId);
+ public:
+  PreloadSmokeTest() : backend(std::to_string(dcast(env)->test_user.uid)),
+      params{PackageType::TPK, true}  {
+    params.test_user.uid = dcast(env)->test_user.uid;
+    params.test_user.gid = dcast(env)->test_user.gid;
   }
+ protected:
+  TpkBackendInterface backend;
+  TestParameters params;
 };
 
 // TODO(b.kunikowski): New smoke app pkgid name convention.
@@ -63,33 +113,34 @@ TEST_F(SmokeTest, DeltaMode_Tpk) {
   bf::path delta_package = kSmokePackagesDirectory / "DeltaMode_Tpk.delta";
   std::string pkgid = "smokeapp18";
   std::string appid = "smokeapp18.DeltaModeTpk";
-  ASSERT_EQ(DeltaInstall(path, delta_package),
-            ci::AppInstaller::Result::OK);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
+  ASSERT_EQ(backend.InstallSuccess(path), ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.Install(delta_package), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
 
   // Check delta modifications
-  bf::path root_path = ci::GetRootAppPath(false,
-      kTestUserId);
+  bf::path root_path = ci::GetRootAppPath(params.is_readonly,
+                                          params.test_user.uid);
   ASSERT_FALSE(bf::exists(root_path / pkgid / "DELETED"));
   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"));
-  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "MODIFIED", "version 2\n"));
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "MODIFIED", "version 2\n",
+      params));
 }
 
-TEST_F(SmokeTest, DeltaMode_Tpk_Rollback) {
+TEST_F(RollbackSmokeTest, DeltaMode) {
   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);
-  ASSERT_EQ(Install(delta_package, RequestResult::FAIL),
-            ci::AppInstaller::Result::ERROR);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
+  ASSERT_EQ(backend.InstallSuccess(path), ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.Install(delta_package), ci::AppInstaller::Result::ERROR);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"basicdali"}, params));
 
   // Check delta modifications
-  bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
+  bf::path root_path = ci::GetRootAppPath(params.is_readonly,
+      params.test_user.uid);
   ASSERT_TRUE(bf::exists(root_path / pkgid / "res" / "DELETED"));
   ASSERT_FALSE(bf::exists(root_path / pkgid / "res" / "ADDED"));
   ASSERT_TRUE(bf::exists(root_path / pkgid / "bin" / "basicdali"));
@@ -97,7 +148,8 @@ TEST_F(SmokeTest, DeltaMode_Tpk_Rollback) {
                          "basicdali.png"));
   ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
                                            "res/MODIFIED",
-                                           "version 1\n"));
+                                           "version 1\n",
+                                           params));
 }
 
 TEST_F(SmokeTest, ReinstallMode_Tpk) {
@@ -105,31 +157,32 @@ TEST_F(SmokeTest, ReinstallMode_Tpk) {
   bf::path rds_directory = kSmokePackagesDirectory / "delta_dir";
   std::string pkgid = "smokeapp25";
   std::string appid = "smokeapp25.ReinstallModeTpk";
-  bf::path sdk_expected_dir =
-      bf::path(ci::GetRootAppPath(false, kTestUserId)) / "tmp" / pkgid;
+  bf::path sdk_expected_dir = bf::path(ci::GetRootAppPath(params.is_readonly,
+      params.test_user.uid)) / "tmp" / pkgid;
   bs::error_code error;
   bf::create_directories(sdk_expected_dir.parent_path(), error);
   ASSERT_FALSE(error);
   ASSERT_TRUE(ci::CopyDir(rds_directory, sdk_expected_dir));
-  ASSERT_EQ(RDSUpdate(path, pkgid), ci::AppInstaller::Result::OK);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
+  ASSERT_EQ(backend.RDSUpdate(path, pkgid), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
 
   // Check rds modifications
   bf::path root_path = ci::GetRootAppPath(false,
-      kTestUserId);
+      params.test_user.uid);
   ASSERT_FALSE(bf::exists(root_path / pkgid / "DELETED"));
   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"));
-  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "MODIFIED", "version 2\n"));
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "MODIFIED", "version 2\n",
+      params));
 }
 
 TEST_F(SmokeTest, InstallationMode_Tpk) {
   bf::path path = kSmokePackagesDirectory / "InstallationMode_Tpk.tpk";
   std::string pkgid = "smokeapp12";
   std::string appid = "smokeapp12.InstallationModeTpk";
-  ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
+  ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
 }
 
 TEST_F(SmokeTest, UpdateMode_Tpk) {
@@ -137,82 +190,88 @@ TEST_F(SmokeTest, UpdateMode_Tpk) {
   bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Tpk_2.tpk";
   std::string pkgid = "smokeapp13";
   std::string appid = "smokeapp13.UpdateModeTpk";
-  ASSERT_EQ(Update(path_old, path_new), ci::AppInstaller::Result::OK);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
+  ASSERT_EQ(backend.InstallSuccess(path_old), ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.Install(path_new), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
 
-  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "VERSION", "2\n"));
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "VERSION", "2\n", params));
 }
 
 TEST_F(SmokeTest, DeinstallationMode_Tpk) {
   bf::path path = kSmokePackagesDirectory / "DeinstallationMode_Tpk.tpk";
   std::string pkgid = "smokeapp14";
   std::string appid = "smokeapp14.DeinstallationModeTpk";
-  ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK);
-  ASSERT_EQ(Uninstall(pkgid, false), ci::AppInstaller::Result::OK);
-  ASSERT_TRUE(CheckPackageNonExistance(pkgid, appid));
+  ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.Uninstall(pkgid), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
 }
 
 TEST_F(SmokeTest, EnablePkg) {
   bf::path path = kSmokePackagesDirectory / "EnablePkg.tpk";
   std::string pkgid = "smokeapp22";
-  ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK);
-  ASSERT_EQ(DisablePackage(pkgid), ci::AppInstaller::Result::OK);
-  ASSERT_EQ(EnablePackage(pkgid), ci::AppInstaller::Result::OK);
-  ci::PkgQueryInterface pkg_query(pkgid, kTestUserId);
-  ASSERT_TRUE(pkg_query.IsPackageInstalled(ci::GetRequestMode(kTestUserId)));
+  ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.DisablePackage(pkgid), ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.EnablePackage(pkgid), ci::AppInstaller::Result::OK);
+  ci::PkgQueryInterface pkg_query(pkgid, params.test_user.uid);
+  ASSERT_TRUE(pkg_query.IsPackageInstalled(
+      ci::GetRequestMode(params.test_user.uid)));
 }
 
 TEST_F(SmokeTest, DisablePkg) {
   bf::path path = kSmokePackagesDirectory / "DisablePkg.tpk";
   std::string pkgid = "smokeapp23";
   std::string appid = "smokeapp23.DisablePkg";
-  ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK);
-  ASSERT_EQ(DisablePackage(pkgid), ci::AppInstaller::Result::OK);
-  ASSERT_TRUE(ci::QueryIsDisabledPackage(pkgid, kTestUserId));
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
+  ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.DisablePackage(pkgid), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(ci::QueryIsDisabledPackage(pkgid, params.test_user.uid));
+  ASSERT_TRUE(ValidatePackage(pkgid, {"=disablepkg"}, params));
 }
 
 TEST_F(SmokeTest, RecoveryMode_Tpk_Installation) {
   bf::path path = kSmokePackagesDirectory / "RecoveryMode_Tpk_Installation.tpk";
-  RemoveAllRecoveryFiles();
+  RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
   ci::Subprocess backend_crash("/usr/bin/tpk-backend-ut/smoke-test-helper");
-  backend_crash.Run("-i", path.string(), "-u", kTestUserIdStr.c_str());
+  std::string test_uid_str = std::to_string(params.test_user.uid);
+  backend_crash.Run("-i", path.string(), "-u", test_uid_str.c_str());
   ASSERT_NE(backend_crash.Wait(), 0);
 
   std::string pkgid = "smokeapp15";
   std::string appid = "smokeapp15.RecoveryModeTpkInstallation";
-  bf::path recovery_file = FindRecoveryFile();
+  bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
+      params.test_user.uid);
   ASSERT_FALSE(recovery_file.empty());
-  ASSERT_EQ(Recover(recovery_file), ci::AppInstaller::Result::OK);
-  ASSERT_TRUE(CheckPackageNonExistance(pkgid, appid));
+  ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
 }
 
 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);
+  RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
+  ASSERT_EQ(backend.Install(path_old), ci::AppInstaller::Result::OK);
   ci::Subprocess backend_crash("/usr/bin/tpk-backend-ut/smoke-test-helper");
-  backend_crash.Run("-i", path_new.string(), "-u", kTestUserIdStr.c_str());
+  std::string test_uid_str = std::to_string(params.test_user.uid);
+  backend_crash.Run("-i", path_new.string(), "-u", test_uid_str.c_str());
   ASSERT_NE(backend_crash.Wait(), 0);
 
   std::string pkgid = "smokeapp16";
   std::string appid = "smokeapp16.RecoveryModeTpkUpdate";
-  bf::path recovery_file = FindRecoveryFile();
+  bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
+      params.test_user.uid);
   ASSERT_FALSE(recovery_file.empty());
-  ASSERT_EQ(Recover(recovery_file), ci::AppInstaller::Result::OK);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
+  ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
 
-  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "VERSION", "1\n"));
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "VERSION", "1\n", params));
 }
 
 TEST_F(SmokeTest, MountInstallationMode_Tpk) {
   bf::path path = kSmokePackagesDirectory / "MountInstallationMode_Tpk.tpk";
   std::string pkgid = "smokeapp26";
   std::string appid = "smokeapp26.MountInstallationModeTpk";
-  ASSERT_EQ(MountInstall(path), ci::AppInstaller::Result::OK);
-  ScopedTzipInterface package_mount(pkgid);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
+  ASSERT_EQ(backend.MountInstall(path), ci::AppInstaller::Result::OK);
+  ScopedTzipInterface package_mount(pkgid, params.test_user.uid);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
 }
 
 TEST_F(SmokeTest, MountUpdateMode_Tpk) {
@@ -220,11 +279,14 @@ TEST_F(SmokeTest, MountUpdateMode_Tpk) {
   bf::path path_new = kSmokePackagesDirectory / "MountUpdateMode_Tpk_2.tpk";
   std::string pkgid = "smokeapp27";
   std::string appid = "smokeapp27.MountUpdateModeTpk";
-  ASSERT_EQ(MountUpdate(path_old, path_new), ci::AppInstaller::Result::OK);
-  ScopedTzipInterface package_mount(pkgid);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
+  ASSERT_EQ(backend.MountInstallSuccess(path_old),
+      ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.MountInstall(path_new), ci::AppInstaller::Result::OK);
+  ScopedTzipInterface package_mount(pkgid, params.test_user.uid);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
 
-  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/VERSION", "2\n"));
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/VERSION", "2\n",
+      params));
 }
 
 TEST_F(SmokeTest, MigrateLegacyExternalImage_Tpk) {
@@ -233,9 +295,16 @@ TEST_F(SmokeTest, MigrateLegacyExternalImage_Tpk) {
   std::string pkgid = "smokeapp28";
   std::string appid = "smokeapp28.InstallExternalTpk";
   bf::path legacy_path = kSmokePackagesDirectory / kLegacyExtImageDir;
-  ASSERT_EQ(MigrateLegacyExternalImage(pkgid, path, legacy_path),
-      ci::AppInstaller::Result::OK);
-  ASSERT_TRUE(ValidateExternalPackage(pkgid, appid));
+  std::string test_uid_str = std::to_string(params.test_user.uid);
+  if (test_uid_str == kDefaultUserIdStr ||
+      params.test_user.uid == kGlobalUserUid) {
+    ASSERT_EQ(backend.MigrateLegacyExternalImage(pkgid, path, legacy_path),
+        ci::AppInstaller::Result::OK);
+    ValidateExternalPackage(pkgid, {"smokeapp28"}, params);
+  } else {
+    ASSERT_EQ(backend.MigrateLegacyExternalImage(pkgid, path, legacy_path),
+        ci::AppInstaller::Result::ERROR);
+  }
 }
 
 TEST_F(SmokeTest, InstallExternal_Tpk) {
@@ -243,9 +312,9 @@ TEST_F(SmokeTest, InstallExternal_Tpk) {
   bf::path path = kSmokePackagesDirectory / "InstallExternal_Tpk.tpk";
   std::string pkgid = "smokeapp29";
   std::string appid = "smokeapp29.InstallExternalTpk";
-  ASSERT_EQ(InstallWithStorage(path, StorageType::EXTERNAL),
+  ASSERT_EQ(backend.InstallWithStorage(path, StorageType::EXTERNAL),
       ci::AppInstaller::Result::OK);
-  ASSERT_TRUE(ValidateExternalPackage(pkgid, appid));
+  ASSERT_TRUE(ValidateExternalPackage(pkgid, {"smokeapp29"}, params));
 }
 
 #define TEP_TEST_STARTING_BLOCK(NUMBER)                                        \
@@ -260,131 +329,150 @@ 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);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
-  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n"));
+  ASSERT_EQ(backend.InstallWithTEP(path, tep1), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n",
+      params));
 }
 
 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);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
-  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep2.tep", "tep2\n"));
+  ASSERT_EQ(backend.InstallWithTEP(path, tep1), ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.InstallWithTEP(path, tep2), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep2.tep", "tep2\n",
+      params));
 }
 
 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);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
-  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep2.tep", "tep2\n"));
+  ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.InstallWithTEP(path, tep2), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep2.tep", "tep2\n",
+      params));
 }
 
 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);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
-  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n"));
+  ASSERT_EQ(backend.InstallWithTEP(path, tep1), ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n",
+      params));
 }
 
-TEST_F(SmokeTest, TEP_Tpk_TepInstallTepUpdateRollback) {
+TEST_F(RollbackSmokeTest, TEP_Tpk_TepInstallTepUpdateRollback) {
   TEP_TEST_STARTING_BLOCK(5)
-  ASSERT_EQ(InstallWithTEP(path, tep1), ci::AppInstaller::Result::OK);
-  ASSERT_EQ(InstallWithTEP(path, tep2, RequestResult::FAIL),
-            ci::AppInstaller::Result::ERROR);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
-  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n"));
+  ASSERT_EQ(backend.InstallSuccessWithTEP(path, tep1),
+      ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.InstallWithTEP(path, tep2),
+      ci::AppInstaller::Result::ERROR);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n",
+      params));
 }
 
-TEST_F(SmokeTest, TEP_Tpk_NoTepInstallTepUpdateRollback) {
+TEST_F(RollbackSmokeTest, TEP_Tpk_NoTepInstallTepUpdateRollback) {
   TEP_TEST_STARTING_BLOCK(6)
-  ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK);
-  ASSERT_EQ(InstallWithTEP(path, tep2, RequestResult::FAIL),
-            ci::AppInstaller::Result::ERROR);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
-  bf::path root_path = ci::GetRootAppPath(false,
-      kTestUserId);
+  ASSERT_EQ(backend.InstallSuccess(path), ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.InstallWithTEP(path, tep2),
+      ci::AppInstaller::Result::ERROR);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
+  bf::path root_path = ci::GetRootAppPath(params.is_readonly,
+      params.test_user.uid);
   bf::path tep_file = root_path / pkgid / "tep" / "tep2.tep";
   ASSERT_FALSE(bf::exists(tep_file));
 }
 
-TEST_F(SmokeTest, TEP_Tpk_TepInstallNoTepUpdateRollback) {
+TEST_F(RollbackSmokeTest, TEP_Tpk_TepInstallNoTepUpdateRollback) {
   TEP_TEST_STARTING_BLOCK(7)
-  ASSERT_EQ(InstallWithTEP(path, tep1), ci::AppInstaller::Result::OK);
-  ASSERT_EQ(Install(path, RequestResult::FAIL),
-            ci::AppInstaller::Result::ERROR);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
-  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n"));
+  ASSERT_EQ(backend.InstallSuccessWithTEP(path, tep1),
+      ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::ERROR);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n",
+      params));
 }
 
 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);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
-  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n"));
+  ASSERT_EQ(backend.MountInstallWithTEP(path, tep1),
+      ci::AppInstaller::Result::OK);
+  ScopedTzipInterface package_mount(pkgid, params.test_user.uid);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n",
+      params));
 }
 
 TEST_F(SmokeTest, TEP_Tpk_Mount_TepInstallTepUpdate) {
   TEP_TEST_STARTING_BLOCK(9)
-  ASSERT_EQ(MountInstallWithTEP(path, tep1), ci::AppInstaller::Result::OK);
-  ASSERT_EQ(MountInstallWithTEP(path, tep2), ci::AppInstaller::Result::OK);
-  ScopedTzipInterface package_mount(pkgid);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
-  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep2.tep", "tep2\n"));
+  ASSERT_EQ(backend.MountInstallWithTEP(path, tep1),
+      ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.MountInstallWithTEP(path, tep2),
+      ci::AppInstaller::Result::OK);
+  ScopedTzipInterface package_mount(pkgid, params.test_user.uid);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep2.tep", "tep2\n",
+      params));
 }
 
 TEST_F(SmokeTest, TEP_Tpk_Mount_NoTepInstallTepUpdate) {
   TEP_TEST_STARTING_BLOCK(10)
-  ASSERT_EQ(MountInstall(path), ci::AppInstaller::Result::OK);
-  ASSERT_EQ(MountInstallWithTEP(path, tep2), ci::AppInstaller::Result::OK);
-  ScopedTzipInterface package_mount(pkgid);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
-  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep2.tep", "tep2\n"));
+  ASSERT_EQ(backend.MountInstall(path), ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.MountInstallWithTEP(path, tep2),
+      ci::AppInstaller::Result::OK);
+  ScopedTzipInterface package_mount(pkgid, params.test_user.uid);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep2.tep", "tep2\n",
+      params));
 }
 
 TEST_F(SmokeTest, TEP_Tpk_Mount_TepInstallNoTepUpdate) {
   TEP_TEST_STARTING_BLOCK(11)
-  ASSERT_EQ(MountInstallWithTEP(path, tep1), ci::AppInstaller::Result::OK);
-  ASSERT_EQ(MountInstall(path), ci::AppInstaller::Result::OK);
-  ScopedTzipInterface package_mount(pkgid);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
-  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n"));
+  ASSERT_EQ(backend.MountInstallWithTEP(path, tep1),
+      ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.MountInstall(path), ci::AppInstaller::Result::OK);
+  ScopedTzipInterface package_mount(pkgid, params.test_user.uid);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n",
+      params));
 }
 
-TEST_F(SmokeTest, TEP_Tpk_Mount_TepInstallTepUpdateRollback) {
+TEST_F(RollbackSmokeTest, TEP_Tpk_Mount_TepInstallTepUpdateRollback) {
   TEP_TEST_STARTING_BLOCK(12)
-  ASSERT_EQ(MountInstallWithTEP(path, tep1), ci::AppInstaller::Result::OK);
-  ASSERT_EQ(MountInstallWithTEP(path, tep2, RequestResult::FAIL),
+  ASSERT_EQ(backend.MountInstallSuccessWithTEP(path, tep1),
+      ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.MountInstallWithTEP(path, tep2),
             ci::AppInstaller::Result::ERROR);
-  ScopedTzipInterface package_mount(pkgid);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
-  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n"));
+  ScopedTzipInterface package_mount(pkgid, params.test_user.uid);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n",
+      params));
 }
 
-TEST_F(SmokeTest, TEP_Tpk_Mount_NoTepInstallTepUpdateRollback) {
+TEST_F(RollbackSmokeTest, TEP_Tpk_Mount_NoTepInstallTepUpdateRollback) {
   TEP_TEST_STARTING_BLOCK(13)
-  ASSERT_EQ(MountInstall(path), ci::AppInstaller::Result::OK);
-  ASSERT_EQ(MountInstallWithTEP(path, tep2, RequestResult::FAIL),
+  ASSERT_EQ(backend.MountInstallSuccess(path), ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.MountInstallWithTEP(path, tep2),
             ci::AppInstaller::Result::ERROR);
-  ScopedTzipInterface package_mount(pkgid);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
-  bf::path root_path = ci::GetRootAppPath(false,
-      kTestUserId);
+  ScopedTzipInterface package_mount(pkgid, params.test_user.uid);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
+  bf::path root_path = ci::GetRootAppPath(params.is_readonly,
+      params.test_user.uid);
   bf::path tep_file = root_path / pkgid / "tep" / "tep2.tep";
   ASSERT_FALSE(bf::exists(tep_file));
 }
 
-TEST_F(SmokeTest, TEP_Tpk_Mount_TepInstallNoTepUpdateRollback) {
+TEST_F(RollbackSmokeTest, TEP_Tpk_Mount_TepInstallNoTepUpdateRollback) {
   TEP_TEST_STARTING_BLOCK(14)
-  ASSERT_EQ(MountInstallWithTEP(path, tep1), ci::AppInstaller::Result::OK);
-  ASSERT_EQ(MountInstall(path, RequestResult::FAIL),
-      ci::AppInstaller::Result::ERROR);
-  ScopedTzipInterface package_mount(pkgid);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
-  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n"));
+  ASSERT_EQ(backend.MountInstallSuccessWithTEP(path, tep1),
+      ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.MountInstall(path), ci::AppInstaller::Result::ERROR);
+  ScopedTzipInterface package_mount(pkgid, params.test_user.uid);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n",
+      params));
 }
 
 TEST_F(PreloadSmokeTest, InstallationMode_Preload) {
@@ -392,8 +480,8 @@ TEST_F(PreloadSmokeTest, InstallationMode_Preload) {
   bf::path path = kSmokePackagesDirectory / "InstallationMode_Preload.tpk";
   std::string pkgid = "smoketpk29";
   std::string appid = "smoketpk29.InstallationModePreload";
-  ASSERT_EQ(InstallPreload(path), ci::AppInstaller::Result::OK);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid, true));
+  ASSERT_EQ(backend.InstallPreload(path), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
 }
 
 TEST_F(PreloadSmokeTest, UpdateMode_Preload) {
@@ -402,11 +490,11 @@ TEST_F(PreloadSmokeTest, UpdateMode_Preload) {
   bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Preload2.tpk";
   std::string pkgid = "smoketpk30";
   std::string appid = "smoketpk30.UpdateModePreload";
-  ASSERT_EQ(InstallPreload(path_old), ci::AppInstaller::Result::OK);
-  ASSERT_EQ(InstallPreload(path_new), ci::AppInstaller::Result::OK);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid, true));
+  ASSERT_EQ(backend.InstallPreload(path_old), ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.InstallPreload(path_new), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"native"}, params));
 
-  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/VERSION", "2", true));
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/VERSION", "2", params));
 }
 
 TEST_F(PreloadSmokeTest, DeinstallationMode_Preload) {
@@ -414,80 +502,85 @@ TEST_F(PreloadSmokeTest, DeinstallationMode_Preload) {
   bf::path path = kSmokePackagesDirectory / "DeinstallationMode_Preload.tpk";
   std::string pkgid = "smoketpk31";
   std::string appid = "smoketpk31.DeinstallationModePreload";
-  ASSERT_EQ(InstallPreload(path), ci::AppInstaller::Result::OK);
-  ASSERT_EQ(Uninstall(pkgid, true), ci::AppInstaller::Result::OK);
-  CheckPackageNonExistance(pkgid, appid, true);
+  ASSERT_EQ(backend.InstallPreload(path), ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.UninstallPreload(pkgid), ci::AppInstaller::Result::OK);
+  CheckPackageNonExistance(pkgid, params);
 }
 
 TEST_F(SmokeTest, InstallationMode_GoodSignature) {
   bf::path path =
       kSmokePackagesDirectory / "InstallationMode_GoodSignature.tpk";
-  ASSERT_EQ(ci::AppInstaller::Result::OK, Install(path));
+  ASSERT_EQ(ci::AppInstaller::Result::OK, backend.Install(path));
 }
 
 TEST_F(SmokeTest, InstallationMode_WrongSignature) {
   bf::path path =
       kSmokePackagesDirectory / "InstallationMode_WrongSignature.tpk";
-  ASSERT_EQ(ci::AppInstaller::Result::ERROR, Install(path));
+  ASSERT_EQ(ci::AppInstaller::Result::ERROR, backend.Install(path));
 }
 
-TEST_F(SmokeTest, InstallationMode_Rollback) {
+TEST_F(RollbackSmokeTest, InstallationMode_Rollback) {
   bf::path path = kSmokePackagesDirectory / "InstallationMode_Rollback.tpk";
   std::string pkgid = "smoketpk34";
   std::string appid = "smoketpk34.InstallationMode_Rollback";
-  ASSERT_EQ(ci::AppInstaller::Result::ERROR,
-            Install(path, RequestResult::FAIL));
-  ASSERT_TRUE(CheckPackageNonExistance(pkgid, appid));
+  ASSERT_EQ(ci::AppInstaller::Result::ERROR, backend.Install(path));
+  ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
 }
 
 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));
+  RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
+  ASSERT_EQ(ci::AppInstaller::Result::OK, backend.Install(path_old));
   ci::Subprocess backend_crash("/usr/bin/tpk-backend-ut/smoke-test-helper");
-  backend_crash.Run("-i", path_new.string(), "-u", kTestUserIdStr.c_str());
+  std::string test_uid_str = std::to_string(params.test_user.uid);
+  backend_crash.Run("-i", path_new.string(), "-u", test_uid_str.c_str());
   ASSERT_NE(backend_crash.Wait(), 0);
 
   std::string pkgid = "smoketpk35";
   std::string appid = "smoketpk35.RecoveryMode_ForDelta";
-  bf::path recovery_file = FindRecoveryFile();
+  bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
+      params.test_user.uid);
   ASSERT_FALSE(recovery_file.empty());
-  ASSERT_EQ(ci::AppInstaller::Result::OK, Recover(recovery_file));
-  ASSERT_TRUE(ValidatePackage(pkgid, {appid}));
+  ASSERT_EQ(ci::AppInstaller::Result::OK, backend.Recover(recovery_file));
+  ASSERT_TRUE(ValidatePackage(pkgid, {"smoketpk35"}, params));
 
-  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/MODIFIED", "version 1"));
-  bf::path root_path = ci::GetRootAppPath(false, kTestUserId);
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/MODIFIED", "version 1",
+      params));
+  bf::path root_path = ci::GetRootAppPath(params.is_readonly,
+                                          params.test_user.uid);
   ASSERT_TRUE(bf::exists(root_path / pkgid / "res/DELETED"));
   ASSERT_FALSE(bf::exists(root_path / pkgid / "res/ADDED"));
 }
 
-TEST_F(SmokeTest, UpdateMode_Rollback) {
+TEST_F(RollbackSmokeTest, UpdateMode) {
   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));
-  ASSERT_EQ(ci::AppInstaller::Result::ERROR,
-            Install(new_path, RequestResult::FAIL));
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
+  ASSERT_EQ(ci::AppInstaller::Result::OK, backend.InstallSuccess(old_path));
+  ASSERT_EQ(ci::AppInstaller::Result::ERROR, backend.Install(new_path));
+  ASSERT_TRUE(ValidatePackage(pkgid, {"smoketpk36"}, params));
 
-  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/VERSION", "1"));
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/VERSION", "1",
+      params));
 }
 
 TEST_F(SmokeTest, RecoveryMode_ForMountInstall) {
   bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForMountInstall.tpk";
-  RemoveAllRecoveryFiles();
+  RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
   ci::Subprocess backend_crash("/usr/bin/tpk-backend-ut/smoke-test-helper");
-  backend_crash.Run("-w", path.string(), "-u", kTestUserIdStr.c_str());
+  std::string test_uid_str = std::to_string(params.test_user.uid);
+  backend_crash.Run("-w", path.string(), "-u", test_uid_str.c_str());
   ASSERT_NE(0, backend_crash.Wait());
 
   std::string pkgid = "smoketpk37";
   std::string appid = "smoketpk37.RecoveryMode_ForMountInstall";
-  bf::path recovery_file = FindRecoveryFile();
+  bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
+      params.test_user.uid);
   ASSERT_FALSE(recovery_file.empty());
-  ASSERT_EQ(ci::AppInstaller::Result::OK, Recover(recovery_file));
-  ASSERT_TRUE(CheckPackageNonExistance(pkgid, appid));
+  ASSERT_EQ(ci::AppInstaller::Result::OK, backend.Recover(recovery_file));
+  ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
 }
 
 TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) {
@@ -495,65 +588,68 @@ TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) {
       kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate.tpk";
   bf::path path_new =
       kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate2.tpk";
-  RemoveAllRecoveryFiles();
-  ASSERT_EQ(ci::AppInstaller::Result::OK, MountInstall(path_old));
+  RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
+  ASSERT_EQ(ci::AppInstaller::Result::OK, backend.MountInstall(path_old));
   ci::Subprocess backend_crash("/usr/bin/tpk-backend-ut/smoke-test-helper");
-  backend_crash.Run("-w", path_new.string(), "-u", kTestUserIdStr.c_str());
+  std::string test_uid_str = std::to_string(params.test_user.uid);
+  backend_crash.Run("-w", path_new.string(), "-u", test_uid_str.c_str());
   ASSERT_NE(0, backend_crash.Wait());
 
   std::string pkgid = "smoketpk38";
   std::string appid = "smoketpk38.RecoveryMode_ForMountUpdate";
 
   // Filesystem may be mounted after crash
-  ScopedTzipInterface poweroff_unmount_interface(pkgid);
+  ScopedTzipInterface poweroff_unmount_interface(pkgid, params.test_user.uid);
   poweroff_unmount_interface.Release();
 
-  bf::path recovery_file = FindRecoveryFile();
+  bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
+      params.test_user.uid);
   ASSERT_FALSE(recovery_file.empty());
-  ASSERT_EQ(ci::AppInstaller::Result::OK, Recover(recovery_file));
-  ScopedTzipInterface interface(pkgid);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
+  ASSERT_EQ(ci::AppInstaller::Result::OK, backend.Recover(recovery_file));
+  ScopedTzipInterface interface(pkgid, params.test_user.uid);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"smoketpk38"}, params));
 
-  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/VERSION", "1"));
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/VERSION", "1", params));
 }
 
-TEST_F(SmokeTest, MountInstallationMode_Rollback) {
+TEST_F(RollbackSmokeTest, MountInstallationMode) {
   bf::path path =
       kSmokePackagesDirectory / "MountInstallationMode_Rollback.tpk";
   std::string pkgid = "smoketpk39";
   std::string appid = "smoketpk39.MountInstallationMode_Rollback";
-  ASSERT_EQ(ci::AppInstaller::Result::ERROR,
-            MountInstall(path, RequestResult::FAIL));
-  ScopedTzipInterface package_mount(pkgid);
-  ASSERT_TRUE(CheckPackageNonExistance(pkgid, appid));
+  ASSERT_EQ(ci::AppInstaller::Result::ERROR, backend.MountInstall(path));
+  ScopedTzipInterface package_mount(pkgid, params.test_user.uid);
+  ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
 }
 
-TEST_F(SmokeTest, MountUpdateMode_Rollback) {
+TEST_F(RollbackSmokeTest, MountUpdateMode) {
   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));
-  ASSERT_EQ(ci::AppInstaller::Result::ERROR,
-            MountInstall(new_path, RequestResult::FAIL));
-  ScopedTzipInterface package_mount(pkgid);
-  ASSERT_TRUE(ValidatePackage(pkgid, appid));
+  ASSERT_EQ(ci::AppInstaller::Result::OK,
+      backend.MountInstallSuccess(old_path));
+  ASSERT_EQ(ci::AppInstaller::Result::ERROR, backend.MountInstall(new_path));
+  ScopedTzipInterface package_mount(pkgid, params.test_user.uid);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"smoketpk40"}, params));
 
-  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/VERSION", "1"));
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/VERSION", "1", params));
 }
 
-TEST_F(PreloadSmokeTest, ManifestDirectInstallMode) {
+TEST_F(SmokeTest, ManifestDirectInstallMode) {
   ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
   bf::path src_path = kSmokePackagesDirectory / "ManifestDirectInstallMode";
   std::string pkgid = "smoketpk41";
   std::string appid = "smoketpk41.ManifestDirectInstallMode";
-  bf::path pkg_path = ci::GetRootAppPath(false, kTestUserId);
+  bf::path pkg_path = ci::GetRootAppPath(params.is_readonly,
+      params.test_user.uid);
 
-  CopyDir(src_path / pkgid, pkg_path / pkgid);
-  ci::PkgQueryInterface pkg_query(pkgid, kTestUserId);
-  ASSERT_FALSE(pkg_query.IsPackageInstalled(ci::GetRequestMode(kTestUserId)));
-  ASSERT_EQ(ManifestDirectInstall(pkgid), ci::AppInstaller::Result::OK);
-  ValidatePackage(pkgid, {appid});
+  ci::CopyDir(src_path / pkgid, pkg_path / pkgid);
+  ci::PkgQueryInterface pkg_query(pkgid, params.test_user.uid);
+  ASSERT_FALSE(pkg_query.IsPackageInstalled(
+      ci::GetRequestMode(params.test_user.uid)));
+  ASSERT_EQ(backend.ManifestDirectInstall(pkgid), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(ValidatePackage(pkgid, {"basicui"}, params));
 }
 
 TEST_F(SmokeTest, ManifestDirectUpdateMode) {
@@ -561,12 +657,13 @@ TEST_F(SmokeTest, ManifestDirectUpdateMode) {
   std::string pkgid = "smoketpk42";
   std::string appid = "smoketpk42.ManifestDirectUpdateMode";
 
-  ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK);
-  int install_time = GetAppInstalledTime(appid.c_str(), kTestUserId);
-  ASSERT_EQ(ManifestDirectInstall(pkgid), ci::AppInstaller::Result::OK);
-  ASSERT_TRUE(GetAppInstalledTime(appid.c_str(), kTestUserId) > install_time)
+  ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
+  int install_time = GetAppInstalledTime(appid.c_str(), params.test_user.uid);
+  ASSERT_EQ(backend.ManifestDirectInstall(pkgid), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(GetAppInstalledTime(appid.c_str(),
+      params.test_user.uid) > install_time)
       << "Package is not updated (app installed time didn't change).";
-  ValidatePackage(pkgid, {appid});
+  ASSERT_TRUE(ValidatePackage(pkgid, {"basicui"}, params));
 }
 
 TEST_F(PreloadSmokeTest, ReadonlyUpdateInstallMode) {
@@ -575,10 +672,12 @@ TEST_F(PreloadSmokeTest, ReadonlyUpdateInstallMode) {
   std::string pkgid = "smoketpk43";
   std::string appid = "smoketpk43.ReadonlyUpdateInstallMode";
 
-  ASSERT_EQ(InstallPreload(path), ci::AppInstaller::Result::OK);
-  ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK);
-  ValidatePackage(pkgid, {appid});
-  ValidatePackage(pkgid, {appid}, true);
+  ASSERT_EQ(backend.InstallPreload(path), ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
+  ValidatePackage(pkgid, {"basicui"}, params);
+  TestParameters nonreadonly_params(params);
+  nonreadonly_params.is_readonly = false;
+  ValidatePackage(pkgid, {"basicui"}, nonreadonly_params);
 }
 
 TEST_F(PreloadSmokeTest, ReadonlyUpdateUninstallMode) {
@@ -586,35 +685,40 @@ TEST_F(PreloadSmokeTest, ReadonlyUpdateUninstallMode) {
   bf::path path = kSmokePackagesDirectory / "ReadonlyUpdateUninstallMode.tpk";
   std::string pkgid = "smoketpk44";
   std::string appid = "smoketpk44.ReadonlyUpdateUninstallMode";
+  std::string exec = "basicui";
 
-  ASSERT_EQ(InstallPreload(path), ci::AppInstaller::Result::OK);
-  ASSERT_EQ(Install(path), ci::AppInstaller::Result::OK);
-  ValidatePackage(pkgid, {appid});
-  ValidatePackage(pkgid, {appid}, true);
-  ASSERT_EQ(Uninstall(pkgid, false), ci::AppInstaller::Result::OK);
-  ValidatePackage(pkgid, {appid}, true);
+  ASSERT_EQ(backend.InstallPreload(path), ci::AppInstaller::Result::OK);
+  ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
+  ValidatePackage(pkgid, {exec}, params);
+  TestParameters nonreadonly_params(params);
+  nonreadonly_params.is_readonly = false;
+  ValidatePackage(pkgid, {exec}, nonreadonly_params);
+  ASSERT_EQ(backend.Uninstall(pkgid), ci::AppInstaller::Result::OK);
+  ValidatePackage(pkgid, {exec}, params);
 }
 
 TEST_F(SmokeTest, InstallExtended_Tpk) {
-  ASSERT_TRUE(CheckAvailableExtendedStorage());
+  ASSERT_TRUE(CheckAvailableExtendedPath());
   bf::path path = kSmokePackagesDirectory / "InstallExtended_Tpk.tpk";
   std::string pkgid = "smoketpk45";
   std::string appid = "smoketpk45.InstallExtendedTpk";
-  ASSERT_EQ(InstallWithStorage(path, StorageType::EXTENDED),
+  ASSERT_EQ(backend.InstallWithStorage(path, StorageType::EXTENDED),
       ci::AppInstaller::Result::OK);
-  ASSERT_TRUE(ValidateExtendedPackage(pkgid, appid));
+  ASSERT_TRUE(ValidateExtendedPackage(pkgid, {appid}, params));
 }
 
-}  // namespace common_installer
+}  // namespace smoke_test
 
 int main(int argc,  char** argv) {
-  ci::RequestMode request_mode = ParseRequestMode(argc, argv);
+  ci::RequestMode request_mode = st::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::AddGlobalTestEnvironment(
-      new common_installer::SmokeEnvironment(request_mode));
+  ::env = testing::AddGlobalTestEnvironment(
+      new smoke_test::SmokeEnvironment(request_mode));
+  signal(SIGINT, ::signalHandler);
+  signal(SIGSEGV, ::signalHandler);
   return RUN_ALL_TESTS();
 }
index 185f8fa..4f4673a 100644 (file)
 // Use of this source code is governed by an apache-2.0 license that can be
 // found in the LICENSE file.
 
-#include <boost/filesystem/operations.hpp>
-#include <boost/range/iterator_range.hpp>
-#include <boost/system/error_code.hpp>
+#include <unit_tests/common/smoke_utils.h>
 
-#include <common/step/configuration/step_fail.h>
-#include <common/utils/subprocess.h>
-#include <common/utils/user_util.h>
-#include <common/request.h>
-#include <gum/gum-user.h>
-#include <gum/gum-user-service.h>
-#include <gum/common/gum-user-types.h>
-
-#include <gtest/gtest.h>
-#include <gtest/gtest-death-test.h>
-
-#include <pkgmgr-info.h>
-#include <signal.h>
-#include <unistd.h>
-#include <tzplatform_config.h>
-#include <vconf.h>
-#include <vconf-internal-keys.h>
-
-#include <array>
-#include <cstdio>
-#include <cstdlib>
-#include <functional>
-#include <regex>
-
-#include "tpk/tpk_app_query_interface.h"
+#include "tpk/tpk_installer.h"
 
 #include "unit_tests/smoke_utils.h"
 
+namespace ci = common_installer;
+namespace st = smoke_test;
 
-const uid_t kGlobalUserUid = tzplatform_getuid(TZ_SYS_GLOBALAPP_USER);
-const uid_t kGlobalUserGid = tzplatform_getgid(TZ_SYS_GLOBALAPP_USER);
-const uid_t kDefaultUserUid = tzplatform_getuid(TZ_SYS_DEFAULT_USER);
-uid_t kTestUserId = kGlobalUserUid;
-gid_t kTestGroupId = kGlobalUserGid;
-std::string kTestUserIdStr = std::to_string(kTestUserId);
-const char kNormalUserName[] = "smokeuser";
-const char kSystemShareGroupName[] = "system_share";
-const std::string& kDefaultUserIdStr = std::to_string(kDefaultUserUid);
-const char kLegacyExtImageDir[] = "legacy_extimage_dir";
-const char kMigrateTestDBName[] = "app2sd_migrate.db";
+namespace smoke_test {
 
 const bf::path kSmokePackagesDirectory =
     "/usr/share/tpk-backend-ut/test_samples/smoke/";
 
-// common entries
-const std::vector<std::string> kDBEntries = {
-  {".pkgmgr_parser.db"},
-  {".pkgmgr_parser.db-journal"},
-  {".pkgmgr_cert.db"},
-  {".pkgmgr_cert.db-journal"},
-  {".app2sd.db"},
-  {".app2sd.db-journal"},
-};
-// globaluser entries
-const char kGlobalManifestDir[] = "/opt/share/packages";
-const char kSkelDir[] = "/etc/skel/apps_rw";
-const char kPreloadApps[] = "/usr/apps";
-const char kPreloadManifestDir[] = "/usr/share/packages";
-const char kPreloadIcons[] = "/usr/share/icons";
-
-namespace {
-
-enum RWDirectory {
-  DATA,
-  CACHE,
-  SHARED_CACHE,
-  SHARED_DATA,
-  SHARED_TRUSTED
-};
-
-const char* rwDirectories[] = {
-  "data",
-  "cache",
-  "shared/cache",
-  "shared/data",
-  "shared/trusted"
-};
-
-bool AddUser(const char *user_name) {
-  GumUser* user = nullptr;
-  user = gum_user_create_sync(FALSE);
-  if (user == nullptr)
-    LOG(WARNING) << "Failed to create gum user! (user name: "
-                 << user_name << ")";
-  g_object_set(G_OBJECT(user), "username", user_name, "usertype",
-      GUM_USERTYPE_NORMAL, NULL);
-  gboolean rval = FALSE;
-  rval = gum_user_add_sync(user);
-  g_object_unref(user);
-  return rval;
-}
-
-bool DeleteUser(const char *user_name, bool rem_home_dir) {
-  bool rval = FALSE;
-  GumUser* guser = gum_user_get_by_name_sync(user_name, FALSE);
-  if (guser)
-    rval = gum_user_delete_sync(guser, rem_home_dir);
-  return rval;
-}
-
-}  // namespace
-
-bool TouchFile(const bf::path& path) {
-  FILE* f = fopen(path.c_str(), "w+");
-  if (!f)
-    return false;
-  fclose(f);
-  return true;
-}
-
-ci::RequestMode ParseRequestMode(int argc,  char** argv) {
-  bo::options_description desc("Available options");
-  desc.add_options()
-      ("request-mode", bo::value<std::string>(), "set request mode")
-      ("global-request,g", "set request mode to global")
-      ("user-request,u", "set request mode to user");
-
-  bo::variables_map vm;
-  bo::store(bo::command_line_parser(argc, argv).
-      options(desc).allow_unregistered().run(), vm);
-  bo::notify(vm);
-
-  if (vm.count("global-request")) {
-    std::cout << "Request mode was set to global." << std::endl;
-    return ci::RequestMode::GLOBAL;
-  }
-  if (vm.count("user-request")) {
-    std::cout << "Request mode was set to user." << std::endl;
-    return ci::RequestMode::USER;
-  }
-  try {
-    if (vm.count("request-mode")) {
-      if (vm["request-mode"].as<std::string>() == "global") {
-        std::cout << "Request mode was set to global." << std::endl;
-        return ci::RequestMode::GLOBAL;
-      }
-      if (vm["request-mode"].as<std::string>() == "user") {
-        std::cout << "Request mode was set to user." << std::endl;
-        return ci::RequestMode::USER;
-      }
-      std::cout << "Cannot set request mode to "
-                << vm["request-mode"].as<std::string>() << std::endl;
-    }
-  }
-  catch (const boost::bad_any_cast &exception) {
-    LOG(ERROR) << exception.what();
-  }
-  std::cout << "Request mode was set to global." << std::endl;
-  return ci::RequestMode::GLOBAL;
-}
-
-bool AddTestUser(const char *user_name) {
-  std::cout << "Adding test user: " << user_name << std::endl;
-  AddUser(user_name);
-  if (boost::optional<uid_t> uid = ci::GetUidByUserName(user_name)) {
-    kTestUserId = *uid;
-    kTestUserIdStr = std::to_string(kTestUserId);
-    std::cout << "User created properly: uid=" << *uid;
-    if (boost::optional<gid_t> gid = ci::GetGidByUid(*uid)) {
-      kTestGroupId = *gid;
-      std::cout << " gid=" << *gid;
-    }
-    std::cout << std::endl;
-    return true;
-  }
-  LOG(ERROR) << "Adding test user failed";
-  return false;
-}
-
-bool DeleteTestUser(const char *user_name) {
-  std::cout << "Deleting test user: " << user_name << std::endl;
-  uid_t test_uid;
-  if (boost::optional<uid_t> uid = ci::GetUidByUserName(user_name))
-    test_uid = *uid;
-  else
-    // User do not exist
-    return true;
-  DeleteUser(user_name, true);
-  if (boost::optional<uid_t> uid = ci::GetUidByUserName(user_name)) {
-    LOG(ERROR) << "Deleting test user failed";
-    return false;
-  } else {
-    std::cout << "User deleted properly: user_name=" << user_name
-              << " uid=" << test_uid << std::endl;
-    return true;
-  }
-}
-
-void RemoveAllRecoveryFiles() {
-  bf::path root_path = ci::GetRootAppPath(false,
-      kTestUserId);
-  if (!bf::exists(root_path))
-    return;
-  for (auto& dir_entry : boost::make_iterator_range(
-      bf::directory_iterator(root_path), bf::directory_iterator())) {
-    if (bf::is_regular_file(dir_entry)) {
-      if (dir_entry.path().string().find("/tpk-recovery")
-          != std::string::npos) {
-        bs::error_code error;
-        bf::remove(dir_entry.path(), error);
-      }
-    }
-  }
-}
-
-bf::path FindRecoveryFile() {
-  bf::path root_path = ci::GetRootAppPath(false,
-      kTestUserId);
-  for (auto& dir_entry : boost::make_iterator_range(
-      bf::directory_iterator(root_path), bf::directory_iterator())) {
-    if (bf::is_regular_file(dir_entry)) {
-      if (dir_entry.path().string().find("/tpk-recovery")
-          != std::string::npos) {
-        return dir_entry.path();
-      }
-    }
-  }
-  return {};
+TpkBackendInterface::AppQueryInterfacePtr
+TpkBackendInterface::CreateQueryInterface() const {
+  return AppQueryInterfacePtr(new tpk::TpkAppQueryInterface());
 }
 
-bool ValidateFileContentInPackage(const std::string& pkgid,
-                                  const std::string& relative,
-                                  const std::string& expected,
-                                  bool is_readonly) {
-  bf::path root_path = ci::GetRootAppPath(is_readonly, kTestUserId);
-  bf::path file_path = root_path / pkgid / relative;
-  if (!bf::exists(file_path)) {
-    LOG(ERROR) << file_path << " doesn't exist";
-    return false;
-  }
-  FILE* handle = fopen(file_path.c_str(), "r");
-  if (!handle) {
-    LOG(ERROR) << file_path << " cannot  be open";
-    return false;
-  }
-  std::string content;
-  std::array<char, 200> buffer;
-  while (fgets(buffer.data(), buffer.size(), handle)) {
-    content += buffer.data();
-  }
-  fclose(handle);
-  return content == expected;
+TpkBackendInterface::AppInstallerPtr
+TpkBackendInterface::CreateInstaller(
+    ci::PkgMgrPtr pkgmgr) const {
+  return AppInstallerPtr(new tpk::TpkInstaller(pkgmgr));
 }
 
-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];
-
-  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);
-  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);
-    EXTENDED_ASSERT_EQ(uid, stats.st_uid);
-    EXTENDED_ASSERT_EQ(*system_share, stats.st_gid);
-  }
-
-  stat(cache_path.c_str(), &stats);
-  EXTENDED_ASSERT_EQ(uid, stats.st_uid);
-  EXTENDED_ASSERT_EQ(*system_share, stats.st_gid);
-  return true;
-}
-
-bool ValidatePackageFS(const std::string& pkgid, const std::string&,
-    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";
-  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");
-  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);
-  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) {
-    if (bf::is_symlink(symlink_status(iter->path())))
-      continue;
-    bool is_rw_dir = false;
-    for (const auto rw_dir : rwDirectories) {
-      bf::path rw_dir_path = rw_dir;
-      bf::path relative_path = ci::MakeRelativePath(iter->path(), package_path);
-      is_rw_dir |= (relative_path == rw_dir_path);
-    }
-    if (iter->path().filename() == ".mmc" || is_rw_dir) {
-      iter.no_push();
-      continue;
-    }
-    struct stat stats;
-    stat(iter->path().c_str(), &stats);
-    EXTENDED_ASSERT_EQ(uid, stats.st_uid);
-    EXTENDED_ASSERT_EQ(gid, stats.st_gid);
-  }
-  return true;
-}
-
-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;
-  EXTENDED_ASSERT_FALSE(bf::exists(package_path));
-
-  bf::path manifest_path = bf::path(getUserManifestPath(
-      kTestUserId, is_readonly)) / (pkgid + ".xml");
-  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);
-  EXTENDED_ASSERT_FALSE(bf::exists(package_backup));
-  EXTENDED_ASSERT_FALSE(bf::exists(manifest_backup));
-  return true;
-}
-
-bool ValidatePackage(const std::string& pkgid, const std::string& appid,
-    bool is_readonly) {
-  ci::PkgQueryInterface pkg_query(pkgid, kTestUserId);
-  EXTENDED_ASSERT_TRUE(pkg_query.IsPackageInstalled(
-      ci::GetRequestMode(kTestUserId)));
-  EXTENDED_ASSERT_TRUE(ValidatePackageFS(pkgid, appid, kTestUserId,
-      kTestGroupId, is_readonly));
-  if (kTestUserId == kGlobalUserUid) {
-    ci::UserList list = ci::GetUserList();
-    for (auto& l : list)
-      EXTENDED_ASSERT_TRUE(ValidatePackageRWFS(pkgid, std::get<0>(l)));
-  } else {
-    EXTENDED_ASSERT_TRUE(ValidatePackageRWFS(pkgid, kTestUserId));
-  }
-  return true;
-}
-
-bool ValidateExternalPackage_FS(const std::string& pkgid,
-    const std::string& appid, uid_t uid) {
-  EXTENDED_ASSERT_EQ(app2ext_usr_enable_external_pkg(pkgid.c_str(), uid), 0);
-  bf::path root_path = ci::GetRootAppPath(false, uid);
-  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;
-}
-
-bool ValidateExternalPackage(const std::string& pkgid,
-    const std::string& appid) {
-  ci::PkgQueryInterface pkg_query(pkgid, kTestUserId);
-  std::string storage = pkg_query.StorageForPkgId();
-  bf::path ext_mount_path = ci::GetExternalCardPath();
-  if (bf::is_empty(ext_mount_path)) {
-    LOG(INFO) << "Sdcard not exists!";
-    EXTENDED_ASSERT_EQ(storage, "installed_internal");
-  } else {
-    EXTENDED_ASSERT_EQ(storage, "installed_external");
-  }
-  EXTENDED_ASSERT_TRUE(ValidateExternalPackage_FS(pkgid, appid, kTestUserId));
-  return true;
-}
-
-bool ValidateExtendedPackage(const std::string& pkgid,
-    const std::string& appid) {
-  ci::PkgQueryInterface pkg_query(pkgid, kTestUserId);
-  std::string storage = pkg_query.StorageForPkgId();
-  bf::path extended_path =
-      bf::path(ci::GetExtendedRootAppPath(kTestUserId)) / pkgid;
-  if (!bf::exists(extended_path)) {
-    LOG(INFO) << "Extended storage not exists!";
-    EXTENDED_ASSERT_EQ(storage, "installed_internal");
-  } else {
-    EXTENDED_ASSERT_EQ(storage, "installed_extended");
-  }
-  EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, appid));
-  return true;
-}
-
-bool CheckPackageNonExistance(const std::string& pkgid,
-                              const std::string& appid,
-                              bool is_readonly) {
-  ci::PkgQueryInterface pkg_query(pkgid, kTestUserId);
-  EXTENDED_ASSERT_FALSE(pkg_query.IsPackageInstalled(
-      ci::GetRequestMode(kTestUserId)));
-  EXTENDED_ASSERT_TRUE(PackageCheckCleanup(pkgid, appid, is_readonly));
-  if (kTestUserId == kGlobalUserUid) {
-    bf::path skel_path(kSkelDir);
-    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;
-      EXTENDED_ASSERT_FALSE(bf::exists(package_path));
-    }
-  }
-  return true;
-}
-
-std::unique_ptr<ci::AppQueryInterface> CreateQueryInterface() {
-  std::unique_ptr<ci::AppQueryInterface> query_interface(
-      new tpk::TpkAppQueryInterface());
-  return query_interface;
-}
-
-std::unique_ptr<ci::AppInstaller> CreateInstaller(ci::PkgMgrPtr pkgmgr) {
-  std::unique_ptr<ci::AppInstaller> installer(new tpk::TpkInstaller(pkgmgr));
-  return installer;
-}
-
-void TestRollbackAfterEachStep(
-  int argc, const char* argv[], std::function<bool()> validator) {
-  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);
-  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) {
-  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);
-    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<ci::AppInstaller> installer = CreateInstaller(pkgmgr);
-  switch (mode) {
-  case RequestResult::FAIL:
-    installer->AddStep<ci::configuration::StepFail>();
-    break;
-  default:
-    break;
-  }
-  return installer->Run();
-}
-ci::AppInstaller::Result CallBackend(int argc,
-                                     const char* argv[],
-                                     RequestResult mode) {
-  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 ci::AppInstaller::Result::UNKNOWN;
-  }
-  return RunInstallerWithPkgrmgr(pkgmgr, mode);
-}
-
-ci::AppInstaller::Result Install(const bf::path& path,
-                                 RequestResult mode) {
-  const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()};
-  return CallBackend(SIZEOFARRAY(argv), argv, mode);
-}
-
-ci::AppInstaller::Result InstallPreload(const bf::path& path,
-    RequestResult mode) {
-  const char* argv[] = {"", "-i", path.c_str(), "--preload"};
-  return CallBackend(SIZEOFARRAY(argv), argv, mode);
-}
-
-bool CheckAvailableExternalPath() {
-  bf::path ext_mount_path = ci::GetExternalCardPath();
-  LOG(DEBUG) << "ext_mount_path :" << ext_mount_path;
-  if (ext_mount_path.empty()) {
-    LOG(ERROR) << "Sdcard not exists!";
-    return false;
-  }
-  return true;
-}
-
-bool CheckAvailableExtendedStorage() {
-  bf::path extended_path = bf::path(tzplatform_getenv(TZ_SYS_EXTENDEDSD));
-  LOG(DEBUG) << "extended_path :" << extended_path;
-  // TODO(jeremy.jang): It should be checked by libstorage API.
-  if (!bf::exists(extended_path)) {
-    LOG(ERROR) << "Extended storage not exists!";
-    return false;
-  }
-  return true;
-}
-
-ci::AppInstaller::Result InstallWithStorage(const bf::path& path,
-                                            StorageType type,
-                                            RequestResult mode) {
-  int default_storage = 0;
-  int storage = 0;
-  switch (type) {
-    case StorageType::EXTERNAL:
-      storage = 1;
-      break;
-    case StorageType::EXTENDED:
-      storage = 2;
-      break;
-    default:
-      LOG(ERROR) << "Unknown storage type";
-      break;
-  }
-  vconf_get_int(VCONFKEY_SETAPPL_DEFAULT_MEM_INSTALL_APPLICATIONS_INT,
-      &default_storage);
-  vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_MEM_INSTALL_APPLICATIONS_INT, storage);
-
-  const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str()};
-  ci::AppInstaller::Result result = CallBackend(SIZEOFARRAY(argv), argv, mode);
-
-  vconf_set_int(VCONFKEY_SETAPPL_DEFAULT_MEM_INSTALL_APPLICATIONS_INT,
-      default_storage);
-  return result;
-}
-
-ci::AppInstaller::Result MigrateLegacyExternalImage(const std::string& pkgid,
-    const bf::path& path,
-    const bf::path& legacy_path,
-    RequestResult mode) {
-  if (InstallWithStorage(path, StorageType::EXTERNAL) !=
-      ci::AppInstaller::Result::OK) {
-    LOG(ERROR) << "Failed to install application. Cannot perform Migrate";
-    return ci::AppInstaller::Result::ERROR;
-  }
-
-  bf::path ext_mount_path = ci::GetExternalCardPath();
-  if (bf::is_empty(ext_mount_path)) {
-    LOG(ERROR) << "Sdcard not exists!";
-    return ci::AppInstaller::Result::ERROR;
-  }
-  bf::path app2sd_path = ext_mount_path / "app2sd";
-
-  char *image_name = app2ext_usr_getname_image(pkgid.c_str(),
-                     kGlobalUserUid);
-  if (!image_name) {
-    LOG(ERROR) << "Failed to get external image name";
-    return ci::AppInstaller::Result::ERROR;
-  }
-  bf::path org_image = app2sd_path / image_name;
-  free(image_name);
-
-  bs::error_code error;
-  bf::remove(org_image, error);
-  if (error) {
-    LOG(ERROR) << "Failed to remove org image";
-    return ci::AppInstaller::Result::ERROR;
-  }
-
-  bf::path db_path = tzplatform_getenv(TZ_SYS_DB);
-  bf::path app2sd_db = db_path / ".app2sd.db";
-  bf::path app2sd_db_journal = db_path / ".app2sd.db-journal";
-  bf::remove(app2sd_db, error);
-  if (error) {
-    LOG(ERROR) << "Failed to remove app2sd db";
-    return ci::AppInstaller::Result::ERROR;
-  }
-  bf::remove(app2sd_db_journal, error);
-  if (error) {
-    LOG(ERROR) << "Failed to remove app2sd journal db";
-    return ci::AppInstaller::Result::ERROR;
-  }
-
-  bf::path app2sd_migrate_db = legacy_path / kMigrateTestDBName;
-  if (!ci::CopyFile(app2sd_migrate_db, app2sd_db)) {
-    LOG(ERROR) << "Failed to copy test db";
-    return ci::AppInstaller::Result::ERROR;
-  }
-
-  bf::path legacy_src = legacy_path / pkgid;
-  bf::path legacy_dst = app2sd_path / pkgid;
-  if (!ci::CopyFile(legacy_src, legacy_dst)) {
-    LOG(ERROR) << "Failed to copy test image";
-    return ci::AppInstaller::Result::ERROR;
-  }
-  const char* argv[] = {"", "--migrate-extimg", pkgid.c_str(),
-                       "-u", kDefaultUserIdStr.c_str()};
-  return CallBackend(SIZEOFARRAY(argv), argv, mode);
-}
-
-ci::AppInstaller::Result InstallWithTEP(
-    const bf::path& path,
-    const bf::path& tep,
-    RequestResult mode) {
-  const char* argv[] = {"", "-i", path.c_str(), "-u", kTestUserIdStr.c_str(),
+TpkBackendInterface::CommandResult
+TpkBackendInterface::InstallWithTEP(
+    const bf::path& path, const bf::path& tep) const {
+  const char* argv[] = {"", "-i", path.c_str(), "-u", uid_str_.c_str(),
                         "-e", tep.c_str()};
-  return CallBackend(SIZEOFARRAY(argv), argv, mode);
-}
-
-ci::AppInstaller::Result Update(const bf::path& path_old,
-                                const bf::path& path_new,
-                                RequestResult mode) {
-  if (Install(path_old) != ci::AppInstaller::Result::OK) {
-    LOG(ERROR) << "Failed to install application. Cannot update";
-    return ci::AppInstaller::Result::UNKNOWN;
-  }
-  return Install(path_new, mode);
-}
-
-ci::AppInstaller::Result MountInstall(const bf::path& path,
-    RequestResult mode) {
-  const char* argv[] = {"", "-w", path.c_str(), "-u", kTestUserIdStr.c_str()};
-  return CallBackend(SIZEOFARRAY(argv), argv, mode);
+  return CallBackend(SIZEOFARRAY(argv), argv);
 }
 
-ci::AppInstaller::Result MountInstallWithTEP(
-    const bf::path& path,
-    const bf::path& tep,
-    RequestResult mode) {
-  const char* argv[] = {"", "-w", path.c_str(), "-u", kTestUserIdStr.c_str(),
-      "-e", tep.c_str()};
-  return CallBackend(SIZEOFARRAY(argv), argv, mode);
-}
-
-ci::AppInstaller::Result MountUpdate(const bf::path& path_old,
-                                     const bf::path& path_new,
-                                     RequestResult mode) {
-  if (MountInstall(path_old) != ci::AppInstaller::Result::OK) {
-    LOG(ERROR) << "Failed to mount-install application. Cannot mount-update";
-    return ci::AppInstaller::Result::UNKNOWN;
-  }
-  return MountInstall(path_new, mode);
-}
-
-ci::AppInstaller::Result Uninstall(const std::string& pkgid, bool is_readonly,
-                                   RequestResult mode) {
-  if (is_readonly) {
-    const char* argv[] = {"", "-d", pkgid.c_str(), "--preload",
-        "--force-remove"};
-    return CallBackend(SIZEOFARRAY(argv), argv, mode);
-  } else {
-    const char* argv[] = {"", "-d", pkgid.c_str(), "-u",
-        kTestUserIdStr.c_str()};
-    return CallBackend(SIZEOFARRAY(argv), argv, mode);
-  }
-}
-
-ci::AppInstaller::Result EnablePackage(const std::string& path,
-                                       RequestResult mode) {
-  const char* argv[] = {"", "-A", path.c_str(), "-u", kTestUserIdStr.c_str()};
-  return CallBackend(SIZEOFARRAY(argv), argv, mode);
-}
-
-ci::AppInstaller::Result DisablePackage(const std::string& path,
-                                        RequestResult mode) {
-  const char* argv[] = {"", "-D", path.c_str(), "-u", kTestUserIdStr.c_str()};
-  return CallBackend(SIZEOFARRAY(argv), argv, mode);
-}
-
-ci::AppInstaller::Result RDSUpdate(const bf::path& path,
-                                   const std::string& pkgid,
-                                   RequestResult mode) {
-  if (Install(path) != ci::AppInstaller::Result::OK) {
-    LOG(ERROR) << "Failed to install application. Cannot perform RDS";
-    return ci::AppInstaller::Result::UNKNOWN;
-  }
-  const char* argv[] = {"", "-r", pkgid.c_str(), "-u",
-      kTestUserIdStr.c_str()};
-  return CallBackend(SIZEOFARRAY(argv), argv, mode);
-}
-
-ci::AppInstaller::Result DeltaInstall(const bf::path& path,
-    const bf::path& delta_package) {
-  if (Install(path) != ci::AppInstaller::Result::OK) {
-    LOG(ERROR) << "Failed to install application. Cannot perform RDS";
-    return ci::AppInstaller::Result::UNKNOWN;
-  }
-  return Install(delta_package);
-}
-
-ci::AppInstaller::Result Recover(const bf::path& recovery_file,
-                                 RequestResult mode) {
-  const char* argv[] = {"", "-b", recovery_file.c_str(), "-u",
-      kTestUserIdStr.c_str()};
-  return CallBackend(SIZEOFARRAY(argv), argv, mode);
-}
-
-ci::AppInstaller::Result ManifestDirectInstall(const std::string& pkgid,
-                                               RequestResult mode) {
-  const char* argv[] = {"", "-y", pkgid.c_str(), "-u", kTestUserIdStr.c_str()};
-  return CallBackend(SIZEOFARRAY(argv), argv, mode);
-}
-
-void BackupPath(const bf::path& path) {
-  bf::path backup_path = path.string() + ".bck";
-  std::cout << "Backup path: " << path << " to " << backup_path << std::endl;
-  bs::error_code error;
-  bf::remove_all(backup_path, error);
-  if (error)
-    LOG(ERROR) << "Remove failed: " << backup_path
-    << " (" << error.message() << ")";
-  if (bf::exists(path)) {
-    bf::rename(path, backup_path, error);
-    if (error)
-      LOG(ERROR) << "Failed to setup test environment. Does some previous"
-      << " test crashed? Path: "
-      << backup_path << " should not exist.";
-    assert(!error);
-  }
-}
-
-void RestorePath(const bf::path& path) {
-  bf::path backup_path = path.string() + ".bck";
-  std::cout << "Restore path: " << path << " from " << backup_path << std::endl;
-  bs::error_code error;
-  bf::remove_all(path, error);
-  if (error)
-    LOG(ERROR) << "Remove failed: " << path
-    << " (" << error.message() << ")";
-  if (bf::exists(backup_path)) {
-    bf::rename(backup_path, path, error);
-    if (error)
-      LOG(ERROR) << "Failed to restore backup path: " << backup_path
-      << " (" << error.message() << ")";
-  }
-}
-
-std::vector<bf::path> SetupBackupDirectories() {
-  std::vector<bf::path> entries;
-  bf::path db_dir = bf::path(tzplatform_getenv(TZ_SYS_DB));
-  if (kTestUserId != kGlobalUserUid)
-    db_dir = db_dir / "user" / std::to_string(kTestUserId);
-  for (auto e : kDBEntries) {
-    bf::path path = db_dir / e;
-    entries.emplace_back(path);
-  }
-
-  if (getuid() == 0) {
-    entries.emplace_back(kPreloadApps);
-    entries.emplace_back(kPreloadManifestDir);
-    entries.emplace_back(kPreloadIcons);
-  }
-
-  if (kTestUserId == kGlobalUserUid) {
-    entries.emplace_back(kSkelDir);
-    entries.emplace_back(kGlobalManifestDir);
-    ci::UserList list = ci::GetUserList();
-    for (auto l : list) {
-      bf::path apps = std::get<2>(l) / "apps_rw";
-      entries.emplace_back(apps);
-    }
-  } else {
-    tzplatform_set_user(kTestUserId);
-    bf::path approot = tzplatform_getenv(TZ_USER_APPROOT);
-    tzplatform_reset_user();
-    entries.emplace_back(approot);
-  }
-
-  bf::path apps_rw = ci::GetRootAppPath(false, kTestUserId);
-  entries.emplace_back(apps_rw);
-
-  return entries;
-}
-
-void UninstallAllAppsInDirectory(bf::path dir, bool is_readonly) {
-  if (bf::exists(dir)) {
-    for (auto& dir_entry : boost::make_iterator_range(
-        bf::directory_iterator(dir), bf::directory_iterator())) {
-      if (dir_entry.path().string().find("smoke") != std::string::npos &&
-          bf::is_directory(dir_entry)) {
-        std::string package = dir_entry.path().filename().string();
-        std::regex pkg_regex("smoke[a-zA-Z]{3,}[0-9]{2,}");
-        if (std::regex_match(package, pkg_regex)) {
-          if (Uninstall(package, is_readonly, RequestResult::NORMAL) !=
-              ci::AppInstaller::Result::OK) {
-            LOG(ERROR) << "Cannot uninstall smoke test app: " << package;
-          }
-        }
-      }
-    }
-  }
+TpkBackendInterface::CommandResult
+TpkBackendInterface::MountInstallWithTEP(
+    const bf::path& path, const bf::path& tep) const {
+  const char* argv[] = {"", "-w", path.c_str(), "-u", uid_str_.c_str(),
+                        "-e", tep.c_str()};
+  return CallBackend(SIZEOFARRAY(argv), argv);
 }
 
-void UninstallAllSmokeApps(ci::RequestMode request_mode) {
-  if (getuid() == 0 && request_mode == ci::RequestMode::GLOBAL) {
-    bf::path root_path = kPreloadApps;
-    UninstallAllAppsInDirectory(root_path, true);
+TpkBackendInterface::CommandResult
+TpkBackendInterface::InstallSuccessWithTEP(
+    const bf::path& path, const bf::path& tep) const {
+  RequestResult tmp_mode = mode_;
+  RequestResult &original_mode = const_cast<RequestResult&>(mode_);
+  original_mode = RequestResult::NORMAL;
+  if (InstallWithTEP(path, tep) != BackendInterface::CommandResult::OK) {
+    LOG(ERROR) << "Failed to install application with tep. Cannot update";
+    return BackendInterface::CommandResult::UNKNOWN;
   }
-  bf::path apps_rw = ci::GetRootAppPath(false, kTestUserId);
-  UninstallAllAppsInDirectory(apps_rw, false);
+  original_mode = tmp_mode;
+  return BackendInterface::CommandResult::OK;
 }
 
-int GetAppInstalledTime(const char *appid, uid_t uid) {
-  int ret = 0;
-  int installed_time = 0;
-  pkgmgrinfo_appinfo_h handle = NULL;
-  ret = pkgmgrinfo_appinfo_get_usr_appinfo(appid, uid, &handle);
-  if (ret != PMINFO_R_OK)
-    return -1;
-  ret = pkgmgrinfo_appinfo_get_installed_time(handle, &installed_time);
-  if (ret != PMINFO_R_OK) {
-    pkgmgrinfo_appinfo_destroy_appinfo(handle);
-    return -1;
+TpkBackendInterface::CommandResult
+TpkBackendInterface::MountInstallSuccessWithTEP(
+    const bf::path& path, const bf::path& tep) const {
+  RequestResult tmp_mode = mode_;
+  RequestResult &original_mode = const_cast<RequestResult&>(mode_);
+  original_mode = RequestResult::NORMAL;
+  if (MountInstallWithTEP(path, tep) != BackendInterface::CommandResult::OK) {
+    LOG(ERROR) << "Failed to mount install application with tep. Cannot update";
+    return BackendInterface::CommandResult::UNKNOWN;
   }
-  pkgmgrinfo_appinfo_destroy_appinfo(handle);
-  return installed_time;
+  original_mode = tmp_mode;
+  return BackendInterface::CommandResult::OK;
 }
 
+}  // namespace smoke_test
index 20f472f..166a350 100644 (file)
 #ifndef UNIT_TESTS_SMOKE_UTILS_H_
 #define UNIT_TESTS_SMOKE_UTILS_H_
 
-#include <boost/filesystem/path.hpp>
-#include <boost/program_options.hpp>
-
 #include <common/pkgmgr_interface.h>
-#include <common/tzip_interface.h>
-#include <common/pkgmgr_query.h>
-#include <common/utils/file_util.h>
-#include <common/paths.h>
+#include <common/app_installer.h>
+#include <unit_tests/common/smoke_utils.h>
 
-#include <string>
-#include <vector>
 #include <memory>
 
-#include "tpk/tpk_installer.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);
+#include "tpk/tpk_app_query_interface.h"
 
-#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;
-namespace bo = boost::program_options;
-
-extern const uid_t kGlobalUserUid;
-extern const uid_t kGlobalUserGid;
-extern const uid_t kDefaultUserUid;
-// TODO(s89.jang): Test local case also
-extern uid_t kTestUserId;
-extern gid_t kTestGroupId;
-extern std::string kTestUserIdStr;
-extern const char kNormalUserName[];
-extern const char kSystemShareGroupName[];
-extern const std::string& kDefaultUserIdStr;
-extern const char kLegacyExtImageDir[];
-extern const char kMigrateTestDBName[];
+namespace smoke_test {
 
 extern const bf::path kSmokePackagesDirectory;
 
-// common entries
-extern const std::vector<std::string> kDBEntries;
-
-// globaluser entries
-extern const char kGlobalManifestDir[];
-extern const char kSkelDir[];
-extern const char kPreloadApps[];
-extern const char kPreloadManifestDir[];
-extern const char kPreloadIcons[];
-
-enum class RequestResult {
-  NORMAL,
-  FAIL
-};
-
-class ScopedTzipInterface {
+class TpkBackendInterface: public BackendInterface {
  public:
-  explicit ScopedTzipInterface(const std::string& pkgid)
-      : pkg_path_(bf::path(ci::GetRootAppPath(false,
-            kTestUserId)) / pkgid),
-        interface_(ci::GetMountLocation(pkg_path_)),
-        mounted_(true) {
-    interface_.MountZip(ci::GetZipPackageLocation(pkg_path_, pkgid));
-  }
-
-  void Release() {
-    if (mounted_) {
-      interface_.UnmountZip();
-      mounted_ = false;
-    }
-  }
-
-  ~ScopedTzipInterface() {
-    Release();
-  }
+  using BackendInterface::BackendInterface;
+  CommandResult InstallWithTEP(const bf::path& path,
+      const bf::path& tep) const;
+  CommandResult InstallSuccessWithTEP(const bf::path& path,
+      const bf::path& tep) const;
+  CommandResult MountInstallWithTEP(const bf::path& path,
+      const bf::path& tep) const;
+  CommandResult MountInstallSuccessWithTEP(const bf::path& path,
+      const bf::path& tep) const;
 
  private:
-  bf::path pkg_path_;
-  ci::TzipInterface interface_;
-  bool mounted_;
+  AppQueryInterfacePtr CreateQueryInterface() const override;
+  AppInstallerPtr CreateInstaller(
+      common_installer::PkgMgrPtr pkgmgr) const override;
 };
 
+}  // namespace smoke_test
 
-class TestPkgmgrInstaller : public ci::PkgmgrInstallerInterface {
- public:
-  bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
-                             ci::InstallationMode* mode) {
-    *installer = pkgmgr_installer_offline_new();
-    if (!*installer)
-      return false;
-    *mode = ci::InstallationMode::ONLINE;
-    return true;
-  }
-
-  bool ShouldCreateSignal() const {
-    return false;
-  }
-};
-
-enum class StorageType {
-  INTERNAL,
-  EXTERNAL,
-  EXTENDED
-};
-
-ci::RequestMode ParseRequestMode(int argc,  char** argv);
-
-bool AddTestUser(const char *user_name);
-
-bool DeleteTestUser(const char *user_name);
-
-bool TouchFile(const bf::path& path);
-
-void RemoveAllRecoveryFiles();
-
-bf::path FindRecoveryFile();
-
-bool ValidateFileContentInPackage(const std::string& pkgid,
-                                  const std::string& relative,
-                                  const std::string& expected,
-                                  bool is_readonly = false);
-
-bool ValidatePackageRWFS(const std::string& pkgid, uid_t uid);
-
-bool ValidatePackageFS(const std::string& pkgid, const std::string& appid,
-    uid_t uid, gid_t gid, bool is_readonly = false);
-
-bool PackageCheckCleanup(const std::string& pkgid, const std::string&,
-                         bool is_readonly = false);
-
-bool ValidatePackage(const std::string& pkgid, const std::string& appid,
-    bool is_readonly = false);
-
-bool ValidateExternalPackage_FS(const std::string& pkgid,
-    const std::string& appid, uid_t uid);
-
-bool ValidateExternalPackage(const std::string& pkgid,
-    const std::string& appid);
-
-bool ValidateExtendedPackage(const std::string& pkgid,
-    const std::string& appid);
-
-bool CheckPackageNonExistance(const std::string& pkgid,
-                              const std::string& appid,
-                              bool is_readonly = false);
-
-bool CheckAvailableExternalPath();
-
-bool CheckAvailableExtendedStorage();
-
-std::unique_ptr<ci::AppQueryInterface> CreateQueryInterface();
-
-std::unique_ptr<ci::AppInstaller> CreateInstaller(ci::PkgMgrPtr pkgmgr);
-
-void TestRollbackAfterEachStep(
-    int argc, const char* argv[], std::function<bool()> validator);
-
-void CrashAfterEachStep(std::vector<std::string> args,
-    std::function<bool(int iter)> validator);
-
-ci::AppInstaller::Result RunInstallerWithPkgrmgr(ci::PkgMgrPtr pkgmgr,
-                                                 RequestResult mode);
-ci::AppInstaller::Result CallBackend(int argc,
-                                     const char* argv[],
-                                     RequestResult mode);
-
-ci::AppInstaller::Result Install(const bf::path& path,
-                                 RequestResult mode = RequestResult::NORMAL);
-
-ci::AppInstaller::Result InstallPreload(const bf::path& path,
-    RequestResult mode = RequestResult::NORMAL);
-
-ci::AppInstaller::Result InstallWithStorage(const bf::path& path,
-    StorageType type = StorageType::INTERNAL,
-    RequestResult mode = RequestResult::NORMAL);
-
-ci::AppInstaller::Result MigrateLegacyExternalImage(const std::string& pkgid,
-    const bf::path& path,
-    const bf::path& legacy_path,
-    RequestResult mode = RequestResult::NORMAL);
-
-ci::AppInstaller::Result InstallWithTEP(
-    const bf::path& path,
-    const bf::path& tep,
-    RequestResult mode = RequestResult::NORMAL);
-
-ci::AppInstaller::Result Update(const bf::path& path_old,
-                                const bf::path& path_new,
-                                RequestResult mode = RequestResult::NORMAL);
-
-ci::AppInstaller::Result MountInstall(const bf::path& path,
-    RequestResult mode = RequestResult::NORMAL);
-
-ci::AppInstaller::Result MountInstallWithTEP(
-    const bf::path& path,
-    const bf::path& tep,
-    RequestResult mode = RequestResult::NORMAL);
-
-ci::AppInstaller::Result MountUpdate(const bf::path& path_old,
-    const bf::path& path_new,
-    RequestResult mode = RequestResult::NORMAL);
-
-ci::AppInstaller::Result Uninstall(const std::string& pkgid, bool is_readonly,
-                                   RequestResult mode = RequestResult::NORMAL);
-
-ci::AppInstaller::Result EnablePackage(const std::string& path,
-    RequestResult mode = RequestResult::NORMAL);
-
-ci::AppInstaller::Result DisablePackage(const std::string& path,
-    RequestResult mode = RequestResult::NORMAL);
-
-ci::AppInstaller::Result RDSUpdate(const bf::path& path,
-                                   const std::string& pkgid,
-                                   RequestResult mode = RequestResult::NORMAL);
-
-ci::AppInstaller::Result DeltaInstall(const bf::path& path,
-    const bf::path& delta_package);
-
-ci::AppInstaller::Result Recover(const bf::path& recovery_file,
-    RequestResult mode = RequestResult::NORMAL);
-
-ci::AppInstaller::Result ManifestDirectInstall(const std::string& pkgid,
-    RequestResult mode = RequestResult::NORMAL);
-
-void BackupPath(const bf::path& path);
-
-void RestorePath(const bf::path& path);
-
-std::vector<bf::path> SetupBackupDirectories();
-
-void UninstallAllAppsInDirectory(bf::path dir, bool is_readonly);
-
-void UninstallAllSmokeApps(ci::RequestMode request_mode);
-
-int GetAppInstalledTime(const char *appid, uid_t uid);
 
 #endif  // UNIT_TESTS_SMOKE_UTILS_H_