Add recovery test for ReadonlyUpdateInstall 84/243384/3
authorIlho Kim <ilho159.kim@samsung.com>
Mon, 7 Sep 2020 01:49:05 +0000 (10:49 +0900)
committerilho kim <ilho159.kim@samsung.com>
Fri, 11 Sep 2020 06:51:27 +0000 (06:51 +0000)
Change-Id: Ie204fa3c61024e8703a1065be9704bc451647f19
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/RecoveryMode_ForReadonlyUpdateInstall.tpk [new file with mode: 0644]
test/smoke_tests/test_samples/smoke/RecoveryMode_ForReadonlyUpdateInstall_2.tpk [new file with mode: 0644]

index 559aa92abb1ed057706ea27cd6128ea506793a22..4e3238a635d396104f39c2d208fa3de9e0306ef4 100644 (file)
@@ -98,6 +98,18 @@ class SmokeTest : public testing::Test {
   TestParameters params;
 };
 
+class PreloadSmokeTest : public testing::Test {
+ public:
+  PreloadSmokeTest() : backend(std::to_string(env->test_user.uid)),
+      params{PackageType::TPK, true}  {
+    params.test_user.uid = env->test_user.uid;
+    params.test_user.gid = 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 /
@@ -489,6 +501,44 @@ TEST_F(SmokeTest, MountUpdateMode_Rollback) {
   });
 }
 
+TEST_F(PreloadSmokeTest, RecoveryMode_ForReadonlyUpdateInstall) {
+  bf::path path_old = kSmokePackagesDirectory /
+      "RecoveryMode_ForReadonlyUpdateInstall.tpk";
+  bf::path path_new = kSmokePackagesDirectory /
+      "RecoveryMode_ForReadonlyUpdateInstall_2.tpk";
+  RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
+  ASSERT_EQ(backend.InstallPreload(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", test_uid_str.c_str()};
+  backend.CrashAfterEachStep(&args, [&](int step) -> bool {
+    if (step >= 2) {
+      std::string pkgid = "smoketpk46";
+      std::string appid = "smoketpk46.RecoveryMode_ForReadonlyUpdateInstall";
+      std::string exec = "smoketpk46";
+      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);
+      if (recovery_info->cleanup())
+        params.is_readonly = false;
+      EXTENDED_ASSERT_TRUE(ValidatePackage(pkgid, {appid, exec}, params));
+      std::string version = recovery_info->cleanup() ? "2" : "1";
+      EXTENDED_ASSERT_TRUE(
+          ValidateFileContentInPackage(pkgid, "res/VERSION", version, params));
+      if (recovery_info->cleanup()) {
+        EXTENDED_ASSERT_EQ(backend.Uninstall(pkgid),
+            ci::AppInstaller::Result::OK);
+      }
+    }
+    return true;
+  }, params.pkg_type);
+}
+
 }  // namespace smoke_test
 
 int main(int argc,  char** argv) {
index c026b892d0dcd62f8b0fd5b6543a8e4fd6fbd9e3..50bd8e039c2305d448ddd42dbb5b3f51e2342564 100644 (file)
@@ -891,6 +891,41 @@ TEST_F(SmokeTest, RecoveryMode_NonSharedDataUpdate) {
   ASSERT_FALSE(bf::exists(recovery_info->unpacked_dir()));
 }
 
+TEST_F(PreloadSmokeTest, RecoveryMode_ForReadonlyUpdateInstall) {
+  ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
+  bf::path path_old = kSmokePackagesDirectory /
+      "RecoveryMode_ForReadonlyUpdateInstall.tpk";
+  bf::path path_new = kSmokePackagesDirectory /
+      "RecoveryMode_ForReadonlyUpdateInstall_2.tpk";
+  RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
+  ASSERT_EQ(backend.InstallPreload(path_old), ci::AppInstaller::Result::OK);
+
+  std::string pkgid = "smoketpk46";
+  std::string appid = "smoketpk46.RecoveryMode_ForReadonlyUpdateInstall";
+  std::string exec = "smoketpk46";
+  ci::PkgQueryInterface pkg_query(pkgid, params.test_user.uid);
+  std::string version_old = pkg_query.Version();
+
+  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(ValidateFileContentInPackage(pkgid, "res/VERSION", "1", params));
+  ASSERT_FALSE(bf::exists(recovery_info->unpacked_dir()));
+  ci::PkgQueryInterface pkg_query2(pkgid, params.test_user.uid, true);
+  std::string version_recovered = pkg_query2.Version();
+  ASSERT_TRUE(version_old == version_recovered);
+}
+
 }  // namespace smoke_test
 
 int main(int argc,  char** argv) {
diff --git a/test/smoke_tests/test_samples/smoke/RecoveryMode_ForReadonlyUpdateInstall.tpk b/test/smoke_tests/test_samples/smoke/RecoveryMode_ForReadonlyUpdateInstall.tpk
new file mode 100644 (file)
index 0000000..da34119
Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/RecoveryMode_ForReadonlyUpdateInstall.tpk differ
diff --git a/test/smoke_tests/test_samples/smoke/RecoveryMode_ForReadonlyUpdateInstall_2.tpk b/test/smoke_tests/test_samples/smoke/RecoveryMode_ForReadonlyUpdateInstall_2.tpk
new file mode 100644 (file)
index 0000000..20de544
Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/RecoveryMode_ForReadonlyUpdateInstall_2.tpk differ