Smoke tests for preload installation, update and deinstallation 00/110900/7
authorDamian Pietruchowski <d.pietruchow@samsung.com>
Wed, 18 Jan 2017 12:31:29 +0000 (13:31 +0100)
committerjongmyeong ko <jongmyeong.ko@samsung.com>
Mon, 6 Feb 2017 12:15:40 +0000 (04:15 -0800)
Verification: Run new smoke tests as superuser (root)

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

index 7a2aabf..a5139cf 100644 (file)
@@ -71,6 +71,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,
@@ -170,8 +173,10 @@ bf::path GetPackageRoot(const std::string& pkgid, uid_t uid) {
 
 bool ValidateFileContentInPackage(const std::string& pkgid,
                                   const std::string& relative,
-                                  const std::string& expected) {
-  bf::path file_path = GetPackageRoot(pkgid, kTestUserId) / relative;
+                                  const std::string& expected,
+                                  bool is_readonly = false) {
+  bf::path file_path = ci::GetRootAppPath(is_readonly, kTestUserId);
+  file_path = file_path / pkgid / relative;
   if (!bf::exists(file_path)) {
     LOG(ERROR) << file_path << " doesn't exist";
     return false;
@@ -251,16 +256,16 @@ void ValidatePackageRWFS(const std::string& pkgid, uid_t uid) {
 
 void ValidatePackageFS(const std::string& pkgid,
                        const std::vector<std::string>& appids,
-                       uid_t uid, gid_t gid) {
-  bf::path root_path = ci::GetRootAppPath(false, uid);
-  bf::path package_path = GetPackageRoot(pkgid, uid);
+                       uid_t uid, gid_t gid, bool is_readonly) {
+  bf::path root_path = ci::GetRootAppPath(is_readonly, uid);
+  bf::path package_path = root_path / pkgid;
   bf::path shared_path = package_path / "shared";
   ASSERT_TRUE(bf::exists(root_path));
   ASSERT_TRUE(bf::exists(package_path));
   ASSERT_TRUE(bf::exists(shared_path));
 
   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));
 
   for (auto& appid : appids) {
@@ -297,13 +302,13 @@ void ValidatePackageFS(const std::string& pkgid,
 }
 
 void PackageCheckCleanup(const std::string& pkgid,
-                         const std::vector<std::string>&) {
-  bf::path package_path = GetPackageRoot(pkgid, kTestUserId);
+    const std::vector<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");
+  bf::path manifest_path = bf::path(getUserManifestPath(kTestUserId,
+      is_readonly)) / (pkgid + ".xml");
   ASSERT_FALSE(bf::exists(manifest_path));
 
   // backups should not exist
@@ -314,11 +319,10 @@ void PackageCheckCleanup(const std::string& pkgid,
 }
 
 void ValidatePackage(const std::string& pkgid,
-                     const std::vector<std::string>& appids) {
+    const std::vector<std::string>& appids, bool is_readonly = false) {
   ASSERT_TRUE(ci::QueryIsPackageInstalled(
-      pkgid, ci::GetRequestMode(kTestUserId),
-      kTestUserId));
-  ValidatePackageFS(pkgid, appids, kTestUserId, kTestGroupId);
+      pkgid, ci::GetRequestMode(kTestUserId), kTestUserId));
+  ValidatePackageFS(pkgid, appids, kTestUserId, kTestGroupId, is_readonly);
   if (kTestUserId == kGlobalUserUid) {
     ci::UserList list = ci::GetUserList();
     for (auto& l : list)
@@ -334,7 +338,7 @@ void ValidateExternalPackageFS(const std::string& pkgid,
   ASSERT_EQ(app2ext_usr_enable_external_pkg(pkgid.c_str(), uid), 0);
   bf::path root_path = ci::GetRootAppPath(false, uid);
   ASSERT_TRUE(bf::exists(root_path / pkgid / ".mmc" / "res"));
-  ValidatePackageFS(pkgid, appids, uid, gid);
+  ValidatePackageFS(pkgid, appids, uid, gid, false);
   ASSERT_EQ(app2ext_usr_disable_external_pkg(pkgid.c_str(), uid), 0);
 }
 
@@ -369,6 +373,13 @@ void CheckPackageNonExistance(const std::string& pkgid,
   PackageCheckCleanup(pkgid, appids);
 }
 
+void CheckPackageReadonlyNonExistance(const std::string& pkgid,
+                                      const std::vector<std::string>& appids) {
+  ASSERT_FALSE(ci::QueryIsPackageInstalled(
+      pkgid, ci::GetRequestMode(kTestUserId), kTestUserId));
+  PackageCheckCleanup(pkgid, appids, true);
+}
+
 std::unique_ptr<ci::AppQueryInterface> CreateQueryInterface() {
   std::unique_ptr<ci::AppQueryInterface> query_interface(
       new wgt::WgtAppQueryInterface());
@@ -427,6 +438,12 @@ ci::AppInstaller::Result Install(const bf::path& path,
   return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
 }
 
+ci::AppInstaller::Result InstallPreload(const bf::path& path, PackageType type,
+    RequestResult mode = RequestResult::NORMAL) {
+  const char* argv[] = {"", "-i", path.c_str(), "--preload"};
+  return CallBackend(SIZEOFARRAY(argv), argv, type, mode);
+}
+
 bool CheckAvailableExternalPath() {
   bf::path ext_mount_path = ci::GetExternalCardPath();
   LOG(DEBUG) << "ext_mount_path :" << ext_mount_path;
@@ -531,6 +548,12 @@ ci::AppInstaller::Result Uninstall(const std::string& pkgid,
   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);
+}
+
 ci::AppInstaller::Result RDSUpdate(const bf::path& path,
                                    const std::string& pkgid,
                                    PackageType type,
@@ -629,6 +652,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);
@@ -1208,6 +1237,46 @@ TEST_F(SmokeTest, MigrateLegacyExternalImageMode) {
   ValidateExternalPackage(pkgid, {appid});
 }
 
+TEST_F(SmokeTest, InstallationMode_Preload) {
+  ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
+  bf::path path = kSmokePackagesDirectory / "InstallationMode_Preload.wgt";
+  std::string pkgid = "smokeapp37";
+  std::string appid = "smokeapp37.InstallationModePreload";
+  ASSERT_EQ(InstallPreload(path, PackageType::WGT),
+            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.wgt";
+  bf::path path_new = kSmokePackagesDirectory / "UpdateMode_Preload2.wgt";
+  std::string pkgid = "smokeapp38";
+  std::string appid = "smokeapp38.UpdateModePreload";
+  ASSERT_EQ(InstallPreload(path_old, PackageType::WGT),
+            ci::AppInstaller::Result::OK);
+  AddDataFiles(pkgid, kTestUserId);
+  ASSERT_EQ(InstallPreload(path_new, PackageType::WGT),
+            ci::AppInstaller::Result::OK);
+  ValidatePackage(pkgid, {appid}, true);
+
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "2",
+                                           true));
+  ValidateDataFiles(pkgid, kTestUserId);
+}
+
+TEST_F(SmokeTest, DeinstallationMode_Preload) {
+  ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
+  bf::path path = kSmokePackagesDirectory / "DeinstallationMode_Preload.wgt";
+  std::string pkgid = "smokeapp39";
+  std::string appid = "smokeapp39.DeinstallationModePreload";
+  ASSERT_EQ(InstallPreload(path, PackageType::WGT),
+            ci::AppInstaller::Result::OK);
+  ASSERT_EQ(UninstallPreload(pkgid, PackageType::WGT),
+            ci::AppInstaller::Result::OK);
+  CheckPackageReadonlyNonExistance(pkgid, {appid});
+}
+
 }  // namespace common_installer
 
 int main(int argc,  char** argv) {
diff --git a/src/unit_tests/test_samples/smoke/DeinstallationMode_Preload.wgt b/src/unit_tests/test_samples/smoke/DeinstallationMode_Preload.wgt
new file mode 100644 (file)
index 0000000..32f3480
Binary files /dev/null and b/src/unit_tests/test_samples/smoke/DeinstallationMode_Preload.wgt differ
diff --git a/src/unit_tests/test_samples/smoke/InstallationMode_Preload.wgt b/src/unit_tests/test_samples/smoke/InstallationMode_Preload.wgt
new file mode 100644 (file)
index 0000000..2e98b4d
Binary files /dev/null and b/src/unit_tests/test_samples/smoke/InstallationMode_Preload.wgt differ
diff --git a/src/unit_tests/test_samples/smoke/UpdateMode_Preload.wgt b/src/unit_tests/test_samples/smoke/UpdateMode_Preload.wgt
new file mode 100644 (file)
index 0000000..9e55d64
Binary files /dev/null and b/src/unit_tests/test_samples/smoke/UpdateMode_Preload.wgt differ
diff --git a/src/unit_tests/test_samples/smoke/UpdateMode_Preload2.wgt b/src/unit_tests/test_samples/smoke/UpdateMode_Preload2.wgt
new file mode 100644 (file)
index 0000000..bdbf497
Binary files /dev/null and b/src/unit_tests/test_samples/smoke/UpdateMode_Preload2.wgt differ