Recovery mode for mount install and mount update 41/86741/3
authorTomasz Iwanek <t.iwanek@samsung.com>
Thu, 1 Sep 2016 11:54:40 +0000 (13:54 +0200)
committerTomasz Iwanek <t.iwanek@samsung.com>
Wed, 7 Sep 2016 10:08:12 +0000 (03:08 -0700)
To verify, run new smoke tests.

Recovery mode requires mounting zip package.
Signature files  which needs to be read in next
step are within zip package.

Requires:
 - https://review.tizen.org/gerrit/86739

Change-Id: I857ecea3dae3836cf9a0af2c11766481a016847e

src/hybrid/hybrid_installer.cc
src/unit_tests/smoke_test.cc
src/unit_tests/test_samples/smoke/RecoveryMode_ForDelta.delta [changed mode: 0755->0644]
src/unit_tests/test_samples/smoke/RecoveryMode_ForInstallation.wgt
src/unit_tests/test_samples/smoke/RecoveryMode_ForMountInstall.wgt [new file with mode: 0644]
src/unit_tests/test_samples/smoke/RecoveryMode_ForMountUpdate.wgt [new file with mode: 0644]
src/unit_tests/test_samples/smoke/RecoveryMode_ForMountUpdate_2.wgt [new file with mode: 0644]
src/wgt/wgt_installer.cc

index ea2cc76..6760416 100644 (file)
@@ -43,6 +43,7 @@
 #include <common/step/filesystem/step_update_tep.h>
 #include <common/step/mount/step_mount_install.h>
 #include <common/step/mount/step_mount_unpacked.h>
+#include <common/step/mount/step_mount_recover.h>
 #include <common/step/mount/step_mount_update.h>
 #include <common/step/pkgmgr/step_check_removable.h>
 #include <common/step/pkgmgr/step_check_restriction.h>
@@ -273,6 +274,7 @@ HybridInstaller::HybridInstaller(common_installer::PkgMgrPtr pkgmgr)
       AddStep<ci::filesystem::StepRecoverExternalStorage>();
       AddStep<ci::filesystem::StepRecoverStorageDirectories>();
       AddStep<ci::filesystem::StepRecoverFiles>();
+      AddStep<ci::mount::StepMountRecover>();
       AddStep<tpk::security::StepTpkRecoverSignature>();
       AddStep<ci::pkgmgr::StepRecoverApplication>();
       AddStep<ci::security::StepRecoverSecurity>();
index 75c0fa3..49905e2 100644 (file)
@@ -61,17 +61,26 @@ class ScopedTzipInterface {
   explicit ScopedTzipInterface(const std::string& pkgid)
       : pkg_path_(bf::path(ci::GetRootAppPath(false,
             kTestUserId)) / pkgid),
-        interface_(ci::GetMountLocation(pkg_path_)) {
+        interface_(ci::GetMountLocation(pkg_path_)),
+        mounted_(true) {
     interface_.MountZip(ci::GetZipPackageLocation(pkg_path_, pkgid));
   }
 
+  void Release() {
+    if (mounted_) {
+      interface_.UnmountZip();
+      mounted_ = false;
+    }
+  }
+
   ~ScopedTzipInterface() {
-    interface_.UnmountZip();
+    Release();
   }
 
  private:
   bf::path pkg_path_;
   ci::TzipInterface interface_;
+  bool mounted_;
 };
 
 class TestPkgmgrInstaller : public ci::PkgmgrInstallerInterface {
@@ -618,6 +627,50 @@ TEST_F(SmokeTest, RecoveryMode_ForDelta) {
   ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
 }
 
+TEST_F(SmokeTest, RecoveryMode_ForMountInstall) {
+  bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForMountInstall.wgt";
+  RemoveAllRecoveryFiles();
+  Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
+  backend_crash.Run("-w", path.string(), "-u", kTestUserIdStr.c_str());
+  ASSERT_NE(backend_crash.Wait(), 0);
+
+  std::string pkgid = "smokeapp31";
+  std::string appid = "smokeapp31.RecoveryModeForMountInstall";
+  bf::path recovery_file = FindRecoveryFile();
+  ASSERT_FALSE(recovery_file.empty());
+  ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
+            ci::AppInstaller::Result::OK);
+  CheckPackageNonExistance(pkgid, {appid});
+}
+
+TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) {
+  bf::path path_old =
+      kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate.wgt";
+  bf::path path_new =
+      kSmokePackagesDirectory / "RecoveryMode_ForMountUpdate_2.wgt";
+  std::string pkgid = "smokeapp32";
+  std::string appid = "smokeapp32.RecoveryModeForMountUpdate";
+  RemoveAllRecoveryFiles();
+  ASSERT_EQ(MountInstall(path_old, PackageType::WGT),
+            ci::AppInstaller::Result::OK);
+  Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
+  backend_crash.Run("-w", path_new.string(), "-u", kTestUserIdStr.c_str());
+  ASSERT_NE(backend_crash.Wait(), 0);
+
+  // Filesystem may be mounted after crash
+  ScopedTzipInterface poweroff_unmount_interface(pkgid);
+  poweroff_unmount_interface.Release();
+
+  bf::path recovery_file = FindRecoveryFile();
+  ASSERT_FALSE(recovery_file.empty());
+  ASSERT_EQ(Recover(recovery_file, PackageType::WGT),
+            ci::AppInstaller::Result::OK);
+
+  ScopedTzipInterface interface(pkgid);
+  ValidatePackage(pkgid, {appid});
+  ASSERT_TRUE(ValidateFileContentInPackage(pkgid, "res/wgt/VERSION", "1\n"));
+}
+
 TEST_F(SmokeTest, InstallationMode_GoodSignature) {
   bf::path path = kSmokePackagesDirectory / "InstallationMode_GoodSignature.wgt";  // NOLINT
   ASSERT_EQ(Install(path, PackageType::WGT), ci::AppInstaller::Result::OK);
index 3990f80..7f9dc0e 100644 (file)
Binary files a/src/unit_tests/test_samples/smoke/RecoveryMode_ForInstallation.wgt and b/src/unit_tests/test_samples/smoke/RecoveryMode_ForInstallation.wgt differ
diff --git a/src/unit_tests/test_samples/smoke/RecoveryMode_ForMountInstall.wgt b/src/unit_tests/test_samples/smoke/RecoveryMode_ForMountInstall.wgt
new file mode 100644 (file)
index 0000000..201608e
Binary files /dev/null and b/src/unit_tests/test_samples/smoke/RecoveryMode_ForMountInstall.wgt differ
diff --git a/src/unit_tests/test_samples/smoke/RecoveryMode_ForMountUpdate.wgt b/src/unit_tests/test_samples/smoke/RecoveryMode_ForMountUpdate.wgt
new file mode 100644 (file)
index 0000000..17ab974
Binary files /dev/null and b/src/unit_tests/test_samples/smoke/RecoveryMode_ForMountUpdate.wgt differ
diff --git a/src/unit_tests/test_samples/smoke/RecoveryMode_ForMountUpdate_2.wgt b/src/unit_tests/test_samples/smoke/RecoveryMode_ForMountUpdate_2.wgt
new file mode 100644 (file)
index 0000000..374b66d
Binary files /dev/null and b/src/unit_tests/test_samples/smoke/RecoveryMode_ForMountUpdate_2.wgt differ
index 282b3c0..d137fab 100755 (executable)
@@ -45,6 +45,7 @@
 #include <common/step/filesystem/step_unzip.h>
 #include <common/step/filesystem/step_update_tep.h>
 #include <common/step/mount/step_mount_install.h>
+#include <common/step/mount/step_mount_recover.h>
 #include <common/step/mount/step_mount_unpacked.h>
 #include <common/step/mount/step_mount_update.h>
 #include <common/step/pkgmgr/step_check_removable.h>
@@ -289,6 +290,7 @@ WgtInstaller::WgtInstaller(ci::PkgMgrPtr pkgrmgr)
       AddStep<ci::filesystem::StepRecoverExternalStorage>();
       AddStep<ci::filesystem::StepRecoverStorageDirectories>();
       AddStep<ci::filesystem::StepRecoverFiles>();
+      AddStep<ci::mount::StepMountRecover>();
       AddStep<wgt::security::StepWgtRecoverSignature>();
       AddStep<ci::pkgmgr::StepRecoverApplication>();
       AddStep<ci::security::StepRecoverSecurity>();