Merge "Step Recover Per User Directories for Recovery Mode added" into tizen
authorjongmyeong ko <jongmyeong.ko@samsung.com>
Fri, 10 Feb 2017 08:38:03 +0000 (00:38 -0800)
committerGerrit Code Review <gerrit@review.vlan103.tizen.org>
Fri, 10 Feb 2017 08:38:03 +0000 (00:38 -0800)
1  2 
src/unit_tests/smoke_test.cc

@@@ -371,6 -371,14 +371,14 @@@ void CheckPackageNonExistance(const std
        pkgid, ci::GetRequestMode(kTestUserId),
        kTestUserId));
    PackageCheckCleanup(pkgid, appids);
+   if (kTestUserId == kGlobalUserUid) {
+       ci::UserList list = ci::GetUserList();
+       for (auto& l : list) {
+         bf::path root_path = ci::GetRootAppPath(false, std::get<0>(l));
+         bf::path package_path = root_path / pkgid;
+         ASSERT_FALSE(bf::exists(package_path));
+       }
+   }
  }
  
  void CheckPackageReadonlyNonExistance(const std::string& pkgid,
@@@ -543,17 -551,15 +551,17 @@@ ci::AppInstaller::Result MountInstall(c
  
  ci::AppInstaller::Result Uninstall(const std::string& pkgid,
                                     PackageType type,
 +                                   bool is_preload,
                                     RequestResult mode = RequestResult::NORMAL) {
 -  const char* argv[] = {"", "-d", pkgid.c_str(), "-u", kTestUserIdStr.c_str()};
 -  return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
 -}
 -
 -ci::AppInstaller::Result UninstallPreload(const std::string& pkgid,
 -    PackageType type, RequestResult mode = RequestResult::NORMAL) {
 -  const char* argv[] = {"", "-d", pkgid.c_str(), "--preload", "--force-remove"};
 -  return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
 +  if (is_preload) {
 +    const char* argv[] = {"", "-d", pkgid.c_str(), "--preload",
 +        "--force-remove"};
 +    return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
 +  } else {
 +    const char* argv[] = {"", "-d", pkgid.c_str(), "-u",
 +        kTestUserIdStr.c_str()};
 +    return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
 +  }
  }
  
  ci::AppInstaller::Result RDSUpdate(const bf::path& path,
@@@ -671,32 -677,6 +679,32 @@@ std::vector<bf::path> SetupBackupDirect
    return entries;
  }
  
 +void UninstallAllAppsInDirectory(bf::path dir, bool is_preload) {
 +  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)) {
 +        if(Uninstall(dir_entry.path().filename().string(), PackageType::WGT,
 +            is_preload, RequestResult::NORMAL) !=
 +            ci::AppInstaller::Result::OK) {
 +          LOG(ERROR) << "Cannot uninstall smoke test app: "
 +              << dir_entry.path().filename().string();
 +        }
 +      }
 +    }
 +  }
 +}
 +
 +void UninstallAllSmokeApps(uid_t uid) {
 +  if (getuid() == 0) {
 +    bf::path root_path = kPreloadApps;
 +    UninstallAllAppsInDirectory(root_path, true);
 +  }
 +  bf::path apps_rw = ci::GetRootAppPath(false, uid);
 +  UninstallAllAppsInDirectory(apps_rw, false);
 +}
 +
  }  // namespace
  
  namespace common_installer {
@@@ -711,7 -691,7 +719,7 @@@ class SmokeEnvironment : public testing
        BackupPath(path);
    }
    void TearDown() override {
 -    // TODO(s89.jang): Uninstall smoke packages to clear security context
 +    UninstallAllSmokeApps(uid_);
      for (auto& path : backups_)
        RestorePath(path);
    }
  class SmokeTest : public testing::Test {
  };
  
 +// TODO(b.kunikowski): New smoke app pkgid name convention.
 +//    Change all smokeapp pkgids to smokewgt, because now there
 +//    may be some smoke app pkgid identical as in tpk smoke tests, and this may
 +//    cause bad results of some smoke tests.
 +
  TEST_F(SmokeTest, InstallationMode) {
    bf::path path = kSmokePackagesDirectory / "InstallationMode.wgt";
    std::string pkgid = "smokeapp03";
@@@ -757,8 -732,7 +765,8 @@@ TEST_F(SmokeTest, DeinstallationMode) 
    std::string appid = "smokeapp05.DeinstallationMode";
    ASSERT_EQ(Install(path, PackageType::WGT),
              ci::AppInstaller::Result::OK);
 -  ASSERT_EQ(Uninstall(pkgid, PackageType::WGT), ci::AppInstaller::Result::OK);
 +  ASSERT_EQ(Uninstall(pkgid, PackageType::WGT, false),
 +            ci::AppInstaller::Result::OK);
    CheckPackageNonExistance(pkgid, {appid});
  }
  
@@@ -976,8 -950,8 +984,8 @@@ TEST_F(SmokeTest, UpdateMode_Rollback) 
  TEST_F(SmokeTest, DeltaMode_Rollback) {
    bf::path path = kSmokePackagesDirectory / "DeltaMode_Rollback.wgt";
    bf::path delta_package = kSmokePackagesDirectory / "DeltaMode_Rollback.delta";
 -  std::string pkgid = "smokeapp37";
 -  std::string appid = "smokeapp37.DeltaMode";
 +  std::string pkgid = "smokewgt01";
 +  std::string appid = "smokewgt01.DeltaMode";
    ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
    AddDataFiles(pkgid, kTestUserId);
    ASSERT_EQ(Install(delta_package, PackageType::WGT, RequestResult::FAIL),
@@@ -1025,7 -999,7 +1033,7 @@@ TEST_F(SmokeTest, DeinstallationMode_Hy
    std::string appid1 = "smokehyb03.Web";
    ASSERT_EQ(Install(path, PackageType::HYBRID),
              ci::AppInstaller::Result::OK);
 -  ASSERT_EQ(Uninstall(pkgid, PackageType::HYBRID),
 +  ASSERT_EQ(Uninstall(pkgid, PackageType::HYBRID, false),
              ci::AppInstaller::Result::OK);
    CheckPackageNonExistance(pkgid, {appid1});
  }
@@@ -1223,8 -1197,8 +1231,8 @@@ TEST_F(SmokeTest, MountUpdateMode_Rollb
  
  TEST_F(SmokeTest, UserDefinedPlugins) {
    bf::path path = kSmokePackagesDirectory / "SimpleEchoPrivilege.wgt";
 -  std::string pkgid = "0CSPVhKmRk";
 -  std::string appid = "0CSPVhKmRk.SimpleEcho";
 +  std::string pkgid = "smokewgt02";
 +  std::string appid = "smokewgt02.SimpleEcho";
    std::string call_privilege = "http://tizen.org/privilege/call";
    std::string location_privilege = "http://tizen.org/privilege/location";
    std::string power_privilege = "http://tizen.org/privilege/power";
@@@ -1296,7 -1270,7 +1304,7 @@@ TEST_F(SmokeTest, DeinstallationMode_Pr
    std::string appid = "smokeapp39.DeinstallationModePreload";
    ASSERT_EQ(InstallPreload(path, PackageType::WGT),
              ci::AppInstaller::Result::OK);
 -  ASSERT_EQ(UninstallPreload(pkgid, PackageType::WGT),
 +  ASSERT_EQ(Uninstall(pkgid, PackageType::WGT, true),
              ci::AppInstaller::Result::OK);
    CheckPackageReadonlyNonExistance(pkgid, {appid});
  }