Add recovery test for ReadonlyUpdateInstall 86/243386/2
authorIlho Kim <ilho159.kim@samsung.com>
Mon, 7 Sep 2020 01:51:57 +0000 (10:51 +0900)
committerilho kim <ilho159.kim@samsung.com>
Tue, 8 Sep 2020 07:06:16 +0000 (07:06 +0000)
Change-Id: Ic78a29b63a26ead900a8fc2c25350f05cd5e2cb2
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.wgt [new file with mode: 0644]
test/smoke_tests/test_samples/smoke/RecoveryMode_ForReadonlyUpdateInstall_2.wgt [new file with mode: 0644]

index 444fbd9..6bd46c9 100644 (file)
@@ -72,6 +72,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::WGT, true}  {
+    params.test_user.uid = env->test_user.uid;
+    params.test_user.gid = env->test_user.gid;
+  }
+ protected:
+  WgtBackendInterface backend;
+  TestParameters params;
+};
+
 class HybridSmokeTest : public testing::Test {
  public:
   HybridSmokeTest() : backend(std::to_string(env->test_user.uid)),
@@ -466,6 +478,48 @@ TEST_F(SmokeTest, MountUpdateMode_Rollback) {
   });
 }
 
+TEST_F(PreloadSmokeTest, RecoveryMode_ForReadonlyUpdateInstall) {
+  ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
+  bf::path path_old = kSmokePackagesDirectory /
+      "RecoveryMode_ForReadonlyUpdateInstall.wgt";
+  bf::path path_new = kSmokePackagesDirectory /
+      "RecoveryMode_ForReadonlyUpdateInstall_2.wgt";
+  RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
+  ASSERT_EQ(backend.InstallPreload(path_old), ci::AppInstaller::Result::OK);
+  std::string pkgid = "smokewgt51";
+  std::string appid = "smokewgt51.RecoveryModeForReadonlyUpdateInstall";
+  AddDataFiles(pkgid, 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("/wgt-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}, params));
+
+      std::string version = recovery_info->cleanup() ? "2\n" :"1\n";
+      EXTENDED_ASSERT_TRUE(ValidateFileContentInPackage(pkgid,
+          "res/wgt/VERSION", version, params));
+      EXTENDED_ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
+
+      if (recovery_info->cleanup()) {
+        EXTENDED_ASSERT_EQ(backend.Uninstall(pkgid),
+            ci::AppInstaller::Result::OK);
+        AddDataFiles(pkgid, params.test_user.uid);
+      }
+    }
+    return true;
+  }, params.pkg_type);
+}
+
 }  // namespace smoke_test
 
 int main(int argc,  char** argv) {
index 883f3a2..ec82d92 100644 (file)
@@ -928,6 +928,33 @@ TEST_F(SmokeTest, InstallationMode_UIAppWithoutUiAppId) {
   ASSERT_EQ(backend.Install(path), ci::AppInstaller::Result::ERROR);
 }
 
+TEST_F(PreloadSmokeTest, RecoveryMode_ForReadonlyUpdateInstall) {
+  ASSERT_EQ(getuid(), 0) << "Test cannot be run by normal user";
+  bf::path path_old = kSmokePackagesDirectory /
+      "RecoveryMode_ForReadonlyUpdateInstall.wgt";
+  bf::path path_new = kSmokePackagesDirectory /
+      "RecoveryMode_ForReadonlyUpdateInstall_2.wgt";
+  RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
+  ASSERT_EQ(backend.InstallPreload(path_old), ci::AppInstaller::Result::OK);
+  std::string pkgid = "smokewgt51";
+  std::string appid = "smokewgt51.RecoveryModeForReadonlyUpdateInstall";
+  AddDataFiles(pkgid, params.test_user.uid);
+  ci::Subprocess backend_crash("/usr/bin/wgt-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("/wgt-recovery",
+                                            params.test_user.uid);
+  ASSERT_FALSE(recovery_file.empty());
+  ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(ValidatePackage(pkgid, {appid}, params));
+
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n",
+      params));
+  ASSERT_TRUE(ValidateDataFiles(pkgid, params.test_user.uid));
+}
+
 }  // namespace smoke_test
 
 int main(int argc,  char** argv) {
diff --git a/test/smoke_tests/test_samples/smoke/RecoveryMode_ForReadonlyUpdateInstall.wgt b/test/smoke_tests/test_samples/smoke/RecoveryMode_ForReadonlyUpdateInstall.wgt
new file mode 100644 (file)
index 0000000..bd12001
Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/RecoveryMode_ForReadonlyUpdateInstall.wgt differ
diff --git a/test/smoke_tests/test_samples/smoke/RecoveryMode_ForReadonlyUpdateInstall_2.wgt b/test/smoke_tests/test_samples/smoke/RecoveryMode_ForReadonlyUpdateInstall_2.wgt
new file mode 100644 (file)
index 0000000..508667e
Binary files /dev/null and b/test/smoke_tests/test_samples/smoke/RecoveryMode_ForReadonlyUpdateInstall_2.wgt differ