Add recover test for crash after unzip 30/213030/1
authorIlho Kim <ilho159.kim@samsung.com>
Thu, 22 Aug 2019 11:57:30 +0000 (20:57 +0900)
committerIlho Kim <ilho159.kim@samsung.com>
Thu, 29 Aug 2019 10:00:09 +0000 (19:00 +0900)
requires:
 - https://review.tizen.org/gerrit/#/c/platform/core/appfw/app-installers/+/212535/

Change-Id: I842ef743a815a4ff040c554e1795d3bc5d443b93
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/unit_tests/smoke_test.cc
src/unit_tests/smoke_test_helper.cc
src/unit_tests/test_samples/smoke/RecoveryMode_CrashAfterUnzip.wgt [new file with mode: 0644]

index d61b444806a3eaef1591dcaefd78d7d240224e80..4ceba21adfb22d79719e5042af0ebe3fa9fe07b1 100644 (file)
@@ -864,6 +864,27 @@ TEST_F(SmokeTest, InstallExtendedMode) {
   ASSERT_TRUE(ValidateExtendedPackage(pkgid, {appid}, params));
 }
 
+TEST_F(SmokeTest, RecoveryMode_CrashAfterUnzip) {
+  bf::path path = kSmokePackagesDirectory / "RecoveryMode_CrashAfterUnzip.wgt";
+  RemoveAllRecoveryFiles("/wgt-recovery", params.test_user.uid);
+  ci::Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
+  std::string test_uid_str = std::to_string(params.test_user.uid);
+  backend_crash.Run("-i", path.string(), "-u", test_uid_str.c_str(),
+      "-step_name", "Unzip");
+  ASSERT_NE(backend_crash.Wait(), 0);
+
+  std::string pkgid = "smokewgt45";
+  bf::path recovery_file = FindRecoveryFile("/wgt-recovery",
+      params.test_user.uid);
+  ASSERT_FALSE(recovery_file.empty());
+  std::unique_ptr<ci::recovery::RecoveryFile> recovery_info =
+      GetRecoverFileInfo(recovery_file);
+  ASSERT_TRUE(recovery_info);
+  ASSERT_EQ(backend.Recover(recovery_file), ci::AppInstaller::Result::OK);
+  ASSERT_TRUE(CheckPackageNonExistance(pkgid, params));
+  ASSERT_FALSE(bf::exists(recovery_info->unpacked_dir()));
+}
+
 }  // namespace smoke_test
 
 int main(int argc,  char** argv) {
index 8ddf3df3c411aca7a270607b7caeef6e269418c5..3549d847e304c18d82b1286168035097ccd03b78 100644 (file)
@@ -32,14 +32,17 @@ class StepCrash : public ci::Step {
     wgt::WgtInstaller::STEPS();                                                \
     if (crash_at_ > -1)                                                        \
       AddStepAtIndex<StepCrash>(crash_at_);                                    \
+    else if (step_name_.size())                                                \
+      AddStepAfter<StepCrash>(step_name_);                                     \
     else                                                                       \
       AddStep<StepCrash>();                                                    \
   }                                                                            \
 
 class CrashWgtInstaller : public wgt::WgtInstaller {
  public:
-  explicit CrashWgtInstaller(ci::PkgMgrPtr pkgmgr, int crash_at)
-      : wgt::WgtInstaller(pkgmgr), crash_at_(crash_at) { }
+  explicit CrashWgtInstaller(ci::PkgMgrPtr pkgmgr, int crash_at,
+      std::string step_name) : wgt::WgtInstaller(pkgmgr), crash_at_(crash_at),
+          step_name_(step_name) { }
 
  private:
   OVERRIDE_STEPS_BLOCK(InstallSteps)
@@ -64,6 +67,7 @@ class CrashWgtInstaller : public wgt::WgtInstaller {
   OVERRIDE_STEPS_BLOCK(RecoverDBSteps)
 
   int crash_at_;
+  std::string step_name_;
 };
 
 }  // namespace
@@ -72,12 +76,19 @@ class CrashWgtInstaller : public wgt::WgtInstaller {
 int main(int argc, char** argv) {
   int index = -1;
   int backend_argc = argc;
+  std::string step_name;
   if (!strcmp(argv[argc-2], "-idx")) {
     index = atoi(argv[argc-1]);
     backend_argc = argc - 2;
     LOG(DEBUG) << "Step crash after " << index << " step.";
   }
 
+  if (!strcmp(argv[argc-2], "-step_name")) {
+    step_name = argv[argc-1];
+    backend_argc = argc-2;
+    LOG(DEBUG) << "Step crash after " << step_name << " step.";
+  }
+
   ci::PkgmgrInstaller pkgmgr_installer;
   wgt::WgtAppQueryInterface query_interface;
   auto pkgmgr = ci::PkgMgrInterface::Create(backend_argc, argv,
@@ -87,7 +98,7 @@ int main(int argc, char** argv) {
     return EINVAL;
   }
 
-  ::CrashWgtInstaller installer(pkgmgr, index);
+  ::CrashWgtInstaller installer(pkgmgr, index, step_name);
   return (installer.Run() == ci::AppInstaller::Result::OK) ? 0 : 1;
 }
 
diff --git a/src/unit_tests/test_samples/smoke/RecoveryMode_CrashAfterUnzip.wgt b/src/unit_tests/test_samples/smoke/RecoveryMode_CrashAfterUnzip.wgt
new file mode 100644 (file)
index 0000000..b9ecec4
Binary files /dev/null and b/src/unit_tests/test_samples/smoke/RecoveryMode_CrashAfterUnzip.wgt differ