Rework smoke tests 99/59899/2
authorTomasz Iwanek <t.iwanek@samsung.com>
Wed, 17 Feb 2016 09:35:23 +0000 (10:35 +0100)
committerTomasz Iwanek <t.iwanek@samsung.com>
Mon, 22 Feb 2016 11:34:13 +0000 (03:34 -0800)
Reimplement smoke tests so that they don't use gtest's
EXPECT_DEATH. This will fix problems that are sourced
in forking test binary. "smoke-test-helper" binary is
introduced purely for recovery tests to provide crash
test scenario.

Verification:
 - /usr/bin/tpk-backend-ut/smoke-test

Change-Id: I1ba39f7fa84a7bd1cf2c9d7bca5dd21d20905fe6

CMakeLists.txt
packaging/tpk-backend-tests.manifest
src/unit_tests/CMakeLists.txt
src/unit_tests/smoke_test.cc
src/unit_tests/smoke_test_helper.cc [new file with mode: 0644]

index 13f749874bd5f9c6f2c6539ceee190d6962b4f1d..08b0642bafcbccb7fdd994bdcb8f2e3a8e22dc70 100644 (file)
@@ -25,6 +25,9 @@ SET(CMAKE_CXX_FLAGS_CCOV       "-O0 -std=c++11 -g --coverage")
 SET(TARGET_LIBNAME_TPK "tpk-installer")
 SET(TARGET_TPK_BACKEND "tpk-backend")
 
+SET(TARGET_SMOKE_TEST "smoke-test")
+SET(TARGET_SMOKE_TEST_HELPER "smoke-test-helper")
+
 ADD_DEFINITIONS("-Wall")
 ADD_DEFINITIONS("-Wextra")
 ADD_DEFINITIONS("-fPIE")
index ddd4d34725806fa5cee80f3106f80106a10acdaa..1f06ac4aa6654740c2cf12c7626634a92841988e 100644 (file)
@@ -3,6 +3,7 @@
                 <domain name="_" />
         </request>
         <assign>
-                <filesystem path="/usr/bin/tpk-backend-ut/smoke_test" exec_label="User" />
+                <filesystem path="/usr/bin/tpk-backend-ut/smoke-test" exec_label="User" />
+                <filesystem path="/usr/bin/tpk-backend-ut/smoke-test-helper" exec_label="User" />
         </assign>
 </manifest>
index a8155541f9e11d63b926c2396b6c7cbd191c52d0..4a8d7e8707153d512733cd96daaf5e7268f36c30 100644 (file)
@@ -1,15 +1,20 @@
 SET(DESTINATION_DIR tpk-backend-ut)
 
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../)
-
 # Executables
-ADD_EXECUTABLE(smoke_test
+ADD_EXECUTABLE(${TARGET_SMOKE_TEST}
   smoke_test.cc
 )
 
+ADD_EXECUTABLE(${TARGET_SMOKE_TEST_HELPER}
+  smoke_test_helper.cc
+)
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_SMOKE_TEST} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)
+TARGET_INCLUDE_DIRECTORIES(${TARGET_SMOKE_TEST_HELPER} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../)
+
 INSTALL(DIRECTORY test_samples/ DESTINATION ${SHAREDIR}/${DESTINATION_DIR}/test_samples)
 
-APPLY_PKG_CONFIG(smoke_test PUBLIC
+APPLY_PKG_CONFIG(${TARGET_SMOKE_TEST} PUBLIC
   Boost
   GTEST
 )
@@ -17,6 +22,8 @@ APPLY_PKG_CONFIG(smoke_test PUBLIC
 # FindGTest module do not sets all needed libraries in GTEST_LIBRARIES and
 # GTest main libraries is still missing, so additional linking of
 # GTEST_MAIN_LIBRARIES is needed.
-target_link_libraries(smoke_test PRIVATE ${TARGET_LIBNAME_TPK} ${GTEST_MAIN_LIBRARIES})
+target_link_libraries(${TARGET_SMOKE_TEST} PRIVATE ${TARGET_LIBNAME_TPK} ${GTEST_MAIN_LIBRARIES})
+target_link_libraries(${TARGET_SMOKE_TEST_HELPER} PRIVATE ${TARGET_LIBNAME_TPK})
 
-INSTALL(TARGETS smoke_test DESTINATION ${BINDIR}/${DESTINATION_DIR})
+INSTALL(TARGETS ${TARGET_SMOKE_TEST} DESTINATION ${BINDIR}/${DESTINATION_DIR})
+INSTALL(TARGETS ${TARGET_SMOKE_TEST_HELPER} DESTINATION ${BINDIR}/${DESTINATION_DIR})
index 9c58eff18e5dc559240515e5f53f620665e3e1b9..531a410b0bd34207b64211ea007a89a5aa0b1c47 100644 (file)
@@ -12,6 +12,7 @@
 #include <common/pkgmgr_registration.h>
 #include <common/request.h>
 #include <common/step/step_fail.h>
+#include <common/utils/subprocess.h>
 
 #include <gtest/gtest.h>
 #include <gtest/gtest-death-test.h>
@@ -46,15 +47,14 @@ const char KUserAppsDirBackup[] = "apps_rw.bck";
 
 enum class RequestResult {
   NORMAL,
-  FAIL,
-  CRASH
+  FAIL
 };
 
 class TestPkgmgrInstaller : public ci::PkgmgrInstallerInterface {
  public:
   bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
                              ci::InstallationMode* mode) {
-    *installer = pkgmgr_installer_new();
+    *installer = pkgmgr_installer_offline_new();
     if (!*installer)
       return false;
     *mode = ci::InstallationMode::ONLINE;
@@ -66,19 +66,6 @@ class TestPkgmgrInstaller : public ci::PkgmgrInstallerInterface {
   }
 };
 
-class StepCrash : public ci::Step {
- public:
-  using Step::Step;
-
-  ci::Step::Status process() override {
-    raise(SIGSEGV);
-    return Status::OK;
-  }
-  ci::Step::Status clean() override { return ci::Step::Status::OK; }
-  ci::Step::Status undo() override { return ci::Step::Status::OK; }
-  ci::Step::Status precheck() override { return ci::Step::Status::OK; }
-};
-
 void RemoveAllRecoveryFiles() {
   bf::path root_path = ci::GetRootAppPath(false);
   if (!bf::exists(root_path))
@@ -208,8 +195,6 @@ ci::AppInstaller::Result RunInstallerWithPkgrmgr(ci::PkgMgrPtr pkgmgr,
   case RequestResult::FAIL:
     installer->AddStep<ci::configuration::StepFail>();
     break;
-  case RequestResult::CRASH:
-    installer->AddStep<StepCrash>();
   default:
     break;
   }
@@ -399,7 +384,10 @@ TEST_F(SmokeTest, DeinstallationMode_Tpk) {
 
 TEST_F(SmokeTest, RecoveryMode_Tpk_Installation) {
   bf::path path = kSmokePackagesDirectory / "RecoveryMode_Tpk_Installation.tpk";
-  ASSERT_DEATH(Install(path, RequestResult::CRASH), ".*");
+  RemoveAllRecoveryFiles();
+  ci::Subprocess backend_crash("/usr/bin/tpk-backend-ut/smoke-test-helper");
+  backend_crash.Run("-i", path.string());
+  ASSERT_NE(backend_crash.Wait(), 0);
 
   std::string pkgid = "smokeapp15";
   std::string appid = "smokeapp15.RecoveryModeTpkInstallation";
@@ -413,7 +401,12 @@ TEST_F(SmokeTest, RecoveryMode_Tpk_Update) {
   bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_Tpk_Update.tpk";
   bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_Tpk_Update_2.tpk";
   RemoveAllRecoveryFiles();
-  ASSERT_DEATH(Update(path_old, path_new, RequestResult::CRASH), ".*");
+  ci::Subprocess backend("/usr/bin/tpk-backend");
+  backend.Run("-i", path_old.string());
+  ASSERT_EQ(backend.Wait(), 0);
+  ci::Subprocess backend_crash("/usr/bin/tpk-backend-ut/smoke-test-helper");
+  backend_crash.Run("-i", path_new.string());
+  ASSERT_NE(backend_crash.Wait(), 0);
 
   std::string pkgid = "smokeapp16";
   std::string appid = "smokeapp16.RecoveryModeTpkUpdate";
diff --git a/src/unit_tests/smoke_test_helper.cc b/src/unit_tests/smoke_test_helper.cc
new file mode 100644 (file)
index 0000000..f803ddd
--- /dev/null
@@ -0,0 +1,53 @@
+// Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
+// Use of this source code is governed by an apache-2.0 license that can be
+// found in the LICENSE file.
+
+#include <common/pkgmgr_interface.h>
+#include <common/step/step.h>
+#include <manifest_parser/utils/logging.h>
+
+#include <iostream>
+
+#include "tpk/tpk_app_query_interface.h"
+#include "tpk/tpk_installer.h"
+
+namespace ci = common_installer;
+
+namespace {
+
+class StepCrash : public ci::Step {
+ public:
+  using Step::Step;
+
+  ci::Step::Status process() override {
+    raise(SIGSEGV);
+    return Status::OK;
+  }
+  ci::Step::Status clean() override { return ci::Step::Status::OK; }
+  ci::Step::Status undo() override { return ci::Step::Status::OK; }
+  ci::Step::Status precheck() override { return ci::Step::Status::OK; }
+};
+
+}  // namespace
+
+// This version of backend will crash in the end
+// it is used for recovery testcase
+int main(const int argc, char* argv[]) {
+  ci::PkgmgrInstaller pkgmgr_installer;
+  tpk::TpkAppQueryInterface interface;
+  ci::PkgMgrPtr pkgmgr = ci::PkgMgrInterface::Create(argc, argv,
+                                                     &pkgmgr_installer,
+                                                     &interface);
+  if (!pkgmgr) {
+    LOG(ERROR) << "Failed to create pkgmgr interface";
+    return -1;
+  }
+
+  tpk::TpkInstaller t(pkgmgr);
+  t.AddStep<StepCrash>();
+  if (t.Run() != ci::AppInstaller::Result::OK) {
+    LOG(ERROR) << "TpkInstaller run failure";
+    return -1;
+  }
+  return 0;
+}