Add recover test for crash after unzip 37/212537/3
authorIlho Kim <ilho159.kim@samsung.com>
Thu, 22 Aug 2019 11:57:30 +0000 (20:57 +0900)
committerSangyoon Jang <jeremy.jang@samsung.com>
Wed, 28 Aug 2019 04:53:27 +0000 (04:53 +0000)
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.tpk [new file with mode: 0644]

index 1129003..afb77de 100644 (file)
@@ -720,6 +720,27 @@ TEST_F(SmokeTest, InstallExtended_Tpk) {
   ASSERT_TRUE(ValidateExtendedPackage(pkgid, {appid, exec}, params));
 }
 
+TEST_F(SmokeTest, RecoveryMode_CrashAfterUnzip) {
+  bf::path path = kSmokePackagesDirectory / "RecoveryMode_CrashAfterUnzip.tpk";
+  RemoveAllRecoveryFiles("/tpk-recovery", params.test_user.uid);
+  ci::Subprocess backend_crash("/usr/bin/tpk-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 = "smokeapp47";
+  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_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 d826c9d..22b6252 100644 (file)
@@ -35,14 +35,17 @@ class StepCrash : public ci::Step {
     tpk::TpkInstaller::STEPS();                                                \
     if (crash_at_ > -1)                                                        \
       AddStepAtIndex<StepCrash>(crash_at_);                                    \
+    else if (step_name_.size())                                                \
+      AddStepAfter<StepCrash>(step_name_);                                     \
     else                                                                       \
       AddStep<StepCrash>();                                                    \
   }                                                                            \
 
 class CrashTpkInstaller : public tpk::TpkInstaller {
  public:
-  explicit CrashTpkInstaller(ci::PkgMgrPtr pkgmgr, int crash_at)
-      : tpk::TpkInstaller(pkgmgr), crash_at_(crash_at) { }
+  explicit CrashTpkInstaller(ci::PkgMgrPtr pkgmgr, int crash_at,
+      std::string step_name) : tpk::TpkInstaller(pkgmgr), crash_at_(crash_at),
+          step_name_(step_name) { }
 
  private:
   OVERRIDE_STEPS_BLOCK(InstallSteps)
@@ -67,6 +70,7 @@ class CrashTpkInstaller : public tpk::TpkInstaller {
   OVERRIDE_STEPS_BLOCK(RecoverDBSteps)
 
   int crash_at_;
+  std::string step_name_;
 };
 
 }  // namespace
@@ -76,12 +80,19 @@ class CrashTpkInstaller : public tpk::TpkInstaller {
 int main(const 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;
   tpk::TpkAppQueryInterface interface;
   ci::PkgMgrPtr pkgmgr = ci::PkgMgrInterface::Create(backend_argc, argv,
@@ -92,7 +103,7 @@ int main(const int argc, char* argv[]) {
     return -1;
   }
 
-  ::CrashTpkInstaller t(pkgmgr, index);
+  ::CrashTpkInstaller t(pkgmgr, index, step_name);
 
   if (t.Run() != ci::AppInstaller::Result::OK) {
     LOG(ERROR) << "CrashTpkInstaller run failure";
diff --git a/src/unit_tests/test_samples/smoke/RecoveryMode_CrashAfterUnzip.tpk b/src/unit_tests/test_samples/smoke/RecoveryMode_CrashAfterUnzip.tpk
new file mode 100644 (file)
index 0000000..d46291e
Binary files /dev/null and b/src/unit_tests/test_samples/smoke/RecoveryMode_CrashAfterUnzip.tpk differ