Smoke tests for preload installation, update and deinstallation 09/111709/9
authorDamian Pietruchowski <d.pietruchow@samsung.com>
Mon, 23 Jan 2017 13:12:01 +0000 (14:12 +0100)
committerjongmyeong ko <jongmyeong.ko@samsung.com>
Fri, 10 Feb 2017 01:28:17 +0000 (17:28 -0800)
Verification: Run new smoke tests as superuser (root)

Change-Id: Ie5cc65e111fc7f4ff161305630c79b252c5b32cc
Signed-off-by: Damian Pietruchowski <d.pietruchow@samsung.com>
src/unit_tests/smoke_test.cc
src/unit_tests/test_samples/smoke/DeinstallationMode_Preload.tpk [new file with mode: 0644]
src/unit_tests/test_samples/smoke/InstallationMode_Preload.tpk [new file with mode: 0644]
src/unit_tests/test_samples/smoke/UpdateMode_Preload.tpk [new file with mode: 0644]
src/unit_tests/test_samples/smoke/UpdateMode_Preload2.tpk [new file with mode: 0644]

index bdb1d95..4962626 100644 (file)
@@ -69,6 +69,9 @@ const std::vector<std::string> kDBEntries = {
 // 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";
 
 enum class RequestResult {
   NORMAL,
@@ -157,8 +160,9 @@ bf::path FindRecoveryFile() {
 
 bool ValidateFileContentInPackage(const std::string& pkgid,
                                   const std::string& relative,
-                                  const std::string& expected) {
-  bf::path root_path = ci::GetRootAppPath(false,
+                                  const std::string& expected,
+                                  bool is_readonly = false) {
+  bf::path root_path = ci::GetRootAppPath(is_readonly,
       kTestUserId);
   bf::path file_path = root_path / pkgid / relative;
   if (!bf::exists(file_path)) {
@@ -208,9 +212,9 @@ void ValidatePackageRWFS(const std::string& pkgid, uid_t uid) {
   ASSERT_EQ(*system_share, stats.st_gid) << "Invalid gid: " << cache_path;
 }
 
-void ValidatePackageFS(const std::string& pkgid, const std::string&,
-    uid_t uid, gid_t gid) {
-  bf::path root_path = ci::GetRootAppPath(false, uid);
+void ValidatePackageFS(const std::string& pkgid, const std::string& appid,
+    uid_t uid, gid_t gid, bool is_readonly = false) {
+  bf::path root_path = ci::GetRootAppPath(is_readonly, uid);
   bf::path package_path = root_path / pkgid;
   bf::path shared_path = package_path / "shared";
   ASSERT_TRUE(bf::exists(root_path));
@@ -218,7 +222,7 @@ void ValidatePackageFS(const std::string& pkgid, const std::string&,
   ASSERT_TRUE(bf::exists(shared_path));
 
   bf::path manifest_path =
-      bf::path(getUserManifestPath(uid, false)) / (pkgid + ".xml");
+      bf::path(getUserManifestPath(uid, is_readonly)) / (pkgid + ".xml");
   ASSERT_TRUE(bf::exists(manifest_path));
 
   // backups should not exist
@@ -241,15 +245,16 @@ void ValidatePackageFS(const std::string& pkgid, const std::string&,
   }
 }
 
-void PackageCheckCleanup(const std::string& pkgid, const std::string&) {
-  bf::path root_path = ci::GetRootAppPath(false,
+void PackageCheckCleanup(const std::string& pkgid, const std::string&,
+                         bool is_readonly = false) {
+  bf::path root_path = ci::GetRootAppPath(is_readonly,
       kTestUserId);
   bf::path package_path = root_path / pkgid;
   ASSERT_FALSE(bf::exists(package_path));
 
   bf::path manifest_path =
       bf::path(getUserManifestPath(
-          kTestUserId, false)) / (pkgid + ".xml");
+          kTestUserId, is_readonly)) / (pkgid + ".xml");
   ASSERT_FALSE(bf::exists(manifest_path));
 
   // backups should not exist
@@ -259,11 +264,12 @@ void PackageCheckCleanup(const std::string& pkgid, const std::string&) {
   ASSERT_FALSE(bf::exists(manifest_backup));
 }
 
-void ValidatePackage(const std::string& pkgid, const std::string& appid) {
+void ValidatePackage(const std::string& pkgid, const std::string& appid,
+    bool is_readonly = false) {
   ASSERT_TRUE(ci::QueryIsPackageInstalled(
       pkgid, ci::GetRequestMode(kTestUserId),
       kTestUserId));
-  ValidatePackageFS(pkgid, appid, kTestUserId, kTestGroupId);
+  ValidatePackageFS(pkgid, appid, kTestUserId, kTestGroupId, is_readonly);
   if (kTestUserId == kGlobalUserUid) {
     ci::UserList list = ci::GetUserList();
     for (auto& l : list)
@@ -298,11 +304,12 @@ void ValidateExternalPackage(const std::string& pkgid,
 }
 
 void CheckPackageNonExistance(const std::string& pkgid,
-                              const std::string& appid) {
+                              const std::string& appid,
+                              bool is_readonly = false) {
   ASSERT_FALSE(ci::QueryIsPackageInstalled(
       pkgid, ci::GetRequestMode(kTestUserId),
       kTestUserId));
-  PackageCheckCleanup(pkgid, appid);
+  PackageCheckCleanup(pkgid, appid, is_readonly);
 }
 
 std::unique_ptr<ci::AppQueryInterface> CreateQueryInterface() {
@@ -351,6 +358,12 @@ ci::AppInstaller::Result Install(const bf::path& path,
   return CallBackend(SIZEOFARRAY(argv), argv, mode);
 }
 
+ci::AppInstaller::Result InstallPreload(const bf::path& path,
+    RequestResult mode = RequestResult::NORMAL) {
+  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;
@@ -489,6 +502,12 @@ ci::AppInstaller::Result Uninstall(const std::string& pkgid,
   return CallBackend(SIZEOFARRAY(argv), argv, mode);
 }
 
+ci::AppInstaller::Result UninstallPreload(const std::string& pkgid,
+    RequestResult mode = RequestResult::NORMAL) {
+  const char* argv[] = {"", "-d", pkgid.c_str(), "--preload", "--force-remove"};
+  return CallBackend(SIZEOFARRAY(argv), argv, mode);
+}
+
 ci::AppInstaller::Result EnablePackage(const std::string& path,
                                  RequestResult mode = RequestResult::NORMAL) {
   const char* argv[] = {"", "-A", path.c_str(), "-u", kTestUserIdStr.c_str()};
@@ -573,6 +592,12 @@ std::vector<bf::path> SetupBackupDirectories(uid_t uid) {
     entries.emplace_back(path);
   }
 
+  if (getuid() == 0) {
+    entries.emplace_back(kPreloadApps);
+    entries.emplace_back(kPreloadManifestDir);
+    entries.emplace_back(kPreloadIcons);
+  }
+
   if (uid == kGlobalUserUid) {
     entries.emplace_back(kSkelDir);
     entries.emplace_back(kGlobalManifestDir);
@@ -948,6 +973,38 @@ TEST_F(SmokeTest, TEP_Tpk_Mount_TepInstallNoTepUpdateRollback) {
   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "tep/tep1.tep", "tep1\n"));
 }
 
+TEST_F(SmokeTest, InstallationMode_Preload) {
+  ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
+  bf::path path = kSmokePackagesDirectory / "InstallationMode_Preload.tpk";
+  std::string pkgid = "smoketpk29";
+  std::string appid = "smoketpk29.InstallationModePreload";
+  ASSERT_EQ(InstallPreload(path), ci::AppInstaller::Result::OK);
+  ValidatePackage(pkgid, appid, true);
+}
+
+TEST_F(SmokeTest, UpdateMode_Preload) {
+  ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
+  bf::path path_old = kSmokePackagesDirectory / "UpdateMode_Preload.tpk";
+  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);
+  ValidatePackage(pkgid, appid, true);
+
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/VERSION", "2", true));
+}
+
+TEST_F(SmokeTest, DeinstallationMode_Preload) {
+  ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
+  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(UninstallPreload(pkgid), ci::AppInstaller::Result::OK);
+  CheckPackageNonExistance(pkgid, appid, true);
+}
+
 TEST_F(SmokeTest, InstallationMode_GoodSignature) {
   bf::path path =
       kSmokePackagesDirectory / "InstallationMode_GoodSignature.tpk";
diff --git a/src/unit_tests/test_samples/smoke/DeinstallationMode_Preload.tpk b/src/unit_tests/test_samples/smoke/DeinstallationMode_Preload.tpk
new file mode 100644 (file)
index 0000000..52974c4
Binary files /dev/null and b/src/unit_tests/test_samples/smoke/DeinstallationMode_Preload.tpk differ
diff --git a/src/unit_tests/test_samples/smoke/InstallationMode_Preload.tpk b/src/unit_tests/test_samples/smoke/InstallationMode_Preload.tpk
new file mode 100644 (file)
index 0000000..03168ce
Binary files /dev/null and b/src/unit_tests/test_samples/smoke/InstallationMode_Preload.tpk differ
diff --git a/src/unit_tests/test_samples/smoke/UpdateMode_Preload.tpk b/src/unit_tests/test_samples/smoke/UpdateMode_Preload.tpk
new file mode 100644 (file)
index 0000000..0de6572
Binary files /dev/null and b/src/unit_tests/test_samples/smoke/UpdateMode_Preload.tpk differ
diff --git a/src/unit_tests/test_samples/smoke/UpdateMode_Preload2.tpk b/src/unit_tests/test_samples/smoke/UpdateMode_Preload2.tpk
new file mode 100644 (file)
index 0000000..54df318
Binary files /dev/null and b/src/unit_tests/test_samples/smoke/UpdateMode_Preload2.tpk differ