Add Test for creating res-control directories 33/259433/2
authorIlho Kim <ilho159.kim@samsung.com>
Tue, 8 Jun 2021 00:21:14 +0000 (09:21 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Thu, 17 Jun 2021 05:58:22 +0000 (14:58 +0900)
smoke-test
 -SmokeTest.InstallationMode_ResControl
 -SmokeTest.UpdateMode_AddResControl
 -SmokeTest.UpdateMode_RemoveResControl
 -SmokeTest.RecoveryMode_AddResControl
 -SmokeTest.RecoveryMode_RemoveResControl

extensive-smoke-test
 -SmokeTest.RecoveryMode_AddResControl
 -SmokeTest.RecoveryMode_RemoveResControl

Change-Id: Ie4d64b84e5395446cbe3028294febc9534c5cd20
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
test/smoke_tests/extensive_smoke_test.cc
test/smoke_tests/smoke_test.cc
test/smoke_tests/test_samples/smoke/InstallationMode_ResControl.tpk [new file with mode: 0644]
test/smoke_tests/test_samples/smoke/RecoveryMode_AddResControl.tpk [new file with mode: 0644]
test/smoke_tests/test_samples/smoke/RecoveryMode_AddResControl_2.tpk [new file with mode: 0644]
test/smoke_tests/test_samples/smoke/RecoveryMode_RemoveResControl.tpk [new file with mode: 0644]
test/smoke_tests/test_samples/smoke/RecoveryMode_RemoveResControl_2.tpk [new file with mode: 0644]
test/smoke_tests/test_samples/smoke/UpdateMode_AddResControl.tpk [new file with mode: 0644]
test/smoke_tests/test_samples/smoke/UpdateMode_AddResControl_2.tpk [new file with mode: 0644]
test/smoke_tests/test_samples/smoke/UpdateMode_RemoveResControl.tpk [new file with mode: 0644]
test/smoke_tests/test_samples/smoke/UpdateMode_RemoveResControl_2.tpk [new file with mode: 0644]

index 4e3238a635d396104f39c2d208fa3de9e0306ef4..3266eff01c34e9333445880be656e9e07f0652ac 100644 (file)
@@ -43,6 +43,8 @@ class SmokeEnvironment : public testing::Environment {
       for (auto& path : backups_)
         ASSERT_TRUE(BackupPathCopyAndRemove(path));
     }
+
+    CreateDatabase();
   }
   void TearDown() override {
     ASSERT_TRUE(request_mode_ == ci::RequestMode::GLOBAL ||
@@ -539,6 +541,98 @@ TEST_F(PreloadSmokeTest, RecoveryMode_ForReadonlyUpdateInstall) {
   }, params.pkg_type);
 }
 
+TEST_F(SmokeTest, RecoveryMode_AddResControl) {
+  bf::path path_old = kSmokePackagesDirectory
+      / "RecoveryMode_AddResControl.tpk";
+  bf::path path_new = kSmokePackagesDirectory
+      / "RecoveryMode_AddResControl_2.tpk";
+  RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
+  ASSERT_EQ(backend.Install(path_old), ci::AppInstaller::Result::OK);
+
+  std::string pkgid = "smoketpk50";
+  std::string appid = "smoketpk50.RecoveryMode_AddResControl";
+  std::string exec = "native";
+  bf::path root_path = ci::GetRootAppPath(params.is_readonly,
+                                          params.test_user.uid);
+
+  std::string test_uid_str = std::to_string(params.test_user.uid);
+  std::vector<std::string> args =
+      {"", "-i", path_new.string(), "-u", test_uid_str.c_str()};
+  backend.CrashAfterEachStep(&args, [&](int step) -> bool {
+    if (step >= 2) {
+      bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
+          params.test_user.uid);
+      EXTENDED_ASSERT_FALSE(recovery_file.empty());
+      std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
+          GetRecoverFileInfo(recovery_file);
+      EXTENDED_ASSERT_EQ(backend.Recover(recovery_file),
+          ci::AppInstaller::Result::OK);
+      EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
+      bool dir_exists = recovery_info->cleanup();
+      EXTENDED_ASSERT_EQ(bf::exists(root_path / pkgid / "res/mount/allowed"),
+          dir_exists);
+      EXTENDED_ASSERT_EQ(bf::exists(root_path / pkgid / "res/mount/global"),
+          dir_exists);
+      EXTENDED_ASSERT_EQ(bf::exists(root_path / pkgid / "res/mount/work"),
+          dir_exists);
+
+      if (recovery_info->cleanup()) {
+        EXTENDED_ASSERT_EQ(backend.Uninstall(pkgid),
+            ci::AppInstaller::Result::OK);
+        EXTENDED_ASSERT_EQ(backend.Install(path_old),
+            ci::AppInstaller::Result::OK);
+      }
+    }
+    return true;
+  }, params.pkg_type);
+}
+
+TEST_F(SmokeTest, RecoveryMode_RemoveResControl) {
+  bf::path path_old = kSmokePackagesDirectory
+      / "RecoveryMode_RemoveResControl.tpk";
+  bf::path path_new = kSmokePackagesDirectory
+      / "RecoveryMode_RemoveResControl_2.tpk";
+  RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
+  ASSERT_EQ(backend.Install(path_old), ci::AppInstaller::Result::OK);
+
+  std::string pkgid = "smoketpk51";
+  std::string appid = "smoketpk51.RecoveryMode_RemoveResControl";
+  std::string exec = "native";
+  bf::path root_path = ci::GetRootAppPath(params.is_readonly,
+                                          params.test_user.uid);
+
+  std::string test_uid_str = std::to_string(params.test_user.uid);
+  std::vector<std::string> args =
+      {"", "-i", path_new.string(), "-u", test_uid_str.c_str()};
+  backend.CrashAfterEachStep(&args, [&](int step) -> bool {
+    if (step >= 2) {
+      bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
+          params.test_user.uid);
+      EXTENDED_ASSERT_FALSE(recovery_file.empty());
+      std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
+          GetRecoverFileInfo(recovery_file);
+      EXTENDED_ASSERT_EQ(backend.Recover(recovery_file),
+          ci::AppInstaller::Result::OK);
+      EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
+      bool dir_exists = !recovery_info->cleanup();
+      EXTENDED_ASSERT_EQ(bf::exists(root_path / pkgid / "res/mount/allowed"),
+          dir_exists);
+      EXTENDED_ASSERT_EQ(bf::exists(root_path / pkgid / "res/mount/global"),
+          dir_exists);
+      EXTENDED_ASSERT_EQ(bf::exists(root_path / pkgid / "res/mount/work"),
+          dir_exists);
+
+      if (recovery_info->cleanup()) {
+        EXTENDED_ASSERT_EQ(backend.Uninstall(pkgid),
+            ci::AppInstaller::Result::OK);
+        EXTENDED_ASSERT_EQ(backend.Install(path_old),
+            ci::AppInstaller::Result::OK);
+      }
+    }
+    return true;
+  }, params.pkg_type);
+}
+
 }  // namespace smoke_test
 
 int main(int argc,  char** argv) {
index ced8f24b8a481810091c2901eaae2605fdb6dd7e..71d2c40c0541f76705089ed14bef6d249312e9c9 100644 (file)
@@ -928,6 +928,143 @@ TEST_F(PreloadSmokeTest, RecoveryMode_ForReadonlyUpdateInstall) {
   ASSERT_TRUE(version_old == version_recovered);
 }
 
+TEST_F(SmokeTest, InstallationMode_ResControl) {
+  bf::path path = kSmokePackagesDirectory / "InstallationMode_ResControl.tpk";
+  std::string pkgid = "smoketpk47";
+  std::string appid = "smoketpk47.InstallationMode_ResControl";
+  std::string exec = "native";
+  bf::path root_path = ci::GetRootAppPath(params.is_readonly,
+                                          params.test_user.uid);
+
+  ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
+  ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/allowed"));
+  ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/global"));
+  ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/work"));
+}
+
+TEST_F(SmokeTest, UpdateMode_AddResControl) {
+  bf::path path_old = kSmokePackagesDirectory
+      / "UpdateMode_AddResControl.tpk";
+  bf::path path_new = kSmokePackagesDirectory
+      / "UpdateMode_AddResControl_2.tpk";
+  std::string pkgid = "smoketpk48";
+  std::string appid = "smoketpk48.UpdateMode_AddResControl";
+  std::string exec = "native";
+  bf::path root_path = ci::GetRootAppPath(params.is_readonly,
+                                          params.test_user.uid);
+
+  ASSERT_EQ(backend.Install(path_old), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
+  ASSERT_FALSE(bf::exists(root_path / pkgid / "res/mount/allowed"));
+  ASSERT_FALSE(bf::exists(root_path / pkgid / "res/mount/global"));
+  ASSERT_FALSE(bf::exists(root_path / pkgid / "res/mount/work"));
+
+  ASSERT_EQ(backend.Install(path_new), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
+  ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/allowed"));
+  ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/global"));
+  ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/work"));
+}
+
+TEST_F(SmokeTest, UpdateMode_RemoveResControl) {
+  bf::path path_old = kSmokePackagesDirectory
+      / "UpdateMode_RemoveResControl.tpk";
+  bf::path path_new = kSmokePackagesDirectory
+      / "UpdateMode_RemoveResControl_2.tpk";
+  std::string pkgid = "smoketpk49";
+  std::string appid = "smoketpk49.UpdateMode_RemoveResControl";
+  std::string exec = "native";
+  bf::path root_path = ci::GetRootAppPath(params.is_readonly,
+                                          params.test_user.uid);
+
+  ASSERT_EQ(backend.Install(path_old), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
+  ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/allowed"));
+  ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/global"));
+  ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/work"));
+
+  ASSERT_EQ(backend.Install(path_new), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
+  ASSERT_FALSE(bf::exists(root_path / pkgid / "res/mount/allowed"));
+  ASSERT_FALSE(bf::exists(root_path / pkgid / "res/mount/global"));
+  ASSERT_FALSE(bf::exists(root_path / pkgid / "res/mount/work"));
+}
+
+TEST_F(SmokeTest, RecoveryMode_AddResControl) {
+  bf::path path_old = kSmokePackagesDirectory
+      / "RecoveryMode_AddResControl.tpk";
+  bf::path path_new = kSmokePackagesDirectory
+      / "RecoveryMode_AddResControl_2.tpk";
+  RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
+
+  std::string pkgid = "smoketpk50";
+  std::string appid = "smoketpk50.RecoveryMode_AddResControl";
+  std::string exec = "native";
+  bf::path root_path = ci::GetRootAppPath(params.is_readonly,
+                                          params.test_user.uid);
+
+  ASSERT_EQ(backend.Install(path_old), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
+  ASSERT_FALSE(bf::exists(root_path / pkgid / "res/mount/allowed"));
+  ASSERT_FALSE(bf::exists(root_path / pkgid / "res/mount/global"));
+  ASSERT_FALSE(bf::exists(root_path / pkgid / "res/mount/work"));
+
+  ci::Subprocess backend_crash("/usr/bin/tpk-installer-ut/smoke-test-helper");
+  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);
+
+  bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
+      params.test_user.uid);
+  ASSERT_FALSE(recovery_file.empty());
+  std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
+      GetRecoverFileInfo(recovery_file);
+  ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
+
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
+  ASSERT_FALSE(bf::exists(root_path / pkgid / "res/mount/allowed"));
+  ASSERT_FALSE(bf::exists(root_path / pkgid / "res/mount/global"));
+  ASSERT_FALSE(bf::exists(root_path / pkgid / "res/mount/work"));
+}
+
+TEST_F(SmokeTest, RecoveryMode_RemoveResControl) {
+  bf::path path_old = kSmokePackagesDirectory
+      / "RecoveryMode_RemoveResControl.tpk";
+  bf::path path_new = kSmokePackagesDirectory
+      / "RecoveryMode_RemoveResControl_2.tpk";
+  RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
+
+  std::string pkgid = "smoketpk51";
+  std::string appid = "smoketpk51.RecoveryMode_RemoveResControl";
+  std::string exec = "native";
+  bf::path root_path = ci::GetRootAppPath(params.is_readonly,
+                                          params.test_user.uid);
+
+  ASSERT_EQ(backend.Install(path_old), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
+  ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/allowed"));
+  ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/global"));
+  ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/work"));
+
+  ci::Subprocess backend_crash("/usr/bin/tpk-installer-ut/smoke-test-helper");
+  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);
+
+  bf::path recovery_file = FindRecoveryFile("/tpk-recovery",
+      params.test_user.uid);
+  ASSERT_FALSE(recovery_file.empty());
+  std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
+      GetRecoverFileInfo(recovery_file);
+  ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
+
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
+  ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/allowed"));
+  ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/global"));
+  ASSERT_TRUE(bf::exists(root_path / pkgid / "res/mount/work"));
+}
+
 }  // namespace smoke_test
 
 int main(int argc,  char** argv) {
diff --git a/test/smoke_tests/test_samples/smoke/InstallationMode_ResControl.tpk b/test/smoke_tests/test_samples/smoke/InstallationMode_ResControl.tpk
new file mode 100644 (file)
index 0000000..471fc24
Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/InstallationMode_ResControl.tpk differ
diff --git a/test/smoke_tests/test_samples/smoke/RecoveryMode_AddResControl.tpk b/test/smoke_tests/test_samples/smoke/RecoveryMode_AddResControl.tpk
new file mode 100644 (file)
index 0000000..a181ef4
Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/RecoveryMode_AddResControl.tpk differ
diff --git a/test/smoke_tests/test_samples/smoke/RecoveryMode_AddResControl_2.tpk b/test/smoke_tests/test_samples/smoke/RecoveryMode_AddResControl_2.tpk
new file mode 100644 (file)
index 0000000..712cd67
Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/RecoveryMode_AddResControl_2.tpk differ
diff --git a/test/smoke_tests/test_samples/smoke/RecoveryMode_RemoveResControl.tpk b/test/smoke_tests/test_samples/smoke/RecoveryMode_RemoveResControl.tpk
new file mode 100644 (file)
index 0000000..8f39f9e
Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/RecoveryMode_RemoveResControl.tpk differ
diff --git a/test/smoke_tests/test_samples/smoke/RecoveryMode_RemoveResControl_2.tpk b/test/smoke_tests/test_samples/smoke/RecoveryMode_RemoveResControl_2.tpk
new file mode 100644 (file)
index 0000000..8c57e1e
Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/RecoveryMode_RemoveResControl_2.tpk differ
diff --git a/test/smoke_tests/test_samples/smoke/UpdateMode_AddResControl.tpk b/test/smoke_tests/test_samples/smoke/UpdateMode_AddResControl.tpk
new file mode 100644 (file)
index 0000000..231e03d
Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/UpdateMode_AddResControl.tpk differ
diff --git a/test/smoke_tests/test_samples/smoke/UpdateMode_AddResControl_2.tpk b/test/smoke_tests/test_samples/smoke/UpdateMode_AddResControl_2.tpk
new file mode 100644 (file)
index 0000000..c3840a5
Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/UpdateMode_AddResControl_2.tpk differ
diff --git a/test/smoke_tests/test_samples/smoke/UpdateMode_RemoveResControl.tpk b/test/smoke_tests/test_samples/smoke/UpdateMode_RemoveResControl.tpk
new file mode 100644 (file)
index 0000000..692c570
Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/UpdateMode_RemoveResControl.tpk differ
diff --git a/test/smoke_tests/test_samples/smoke/UpdateMode_RemoveResControl_2.tpk b/test/smoke_tests/test_samples/smoke/UpdateMode_RemoveResControl_2.tpk
new file mode 100644 (file)
index 0000000..9a6dcad
Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/UpdateMode_RemoveResControl_2.tpk differ