Rework smoke tests 03/59903/1
authorTomasz Iwanek <t.iwanek@samsung.com>
Wed, 17 Feb 2016 09:35:29 +0000 (10:35 +0100)
committerTomasz Iwanek <t.iwanek@samsung.com>
Fri, 19 Feb 2016 09:32:22 +0000 (10:32 +0100)
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/wgt-backend-ut/smoke-test

Change-Id: I76cb751ce13d88528de2da6e20ea3dd848e492a8

CMakeLists.txt
packaging/wgt-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 10b8412..d520638 100644 (file)
@@ -24,9 +24,11 @@ SET(CMAKE_CXX_FLAGS_CCOV       "-O0 -std=c++11 -g --coverage")
 # Targets
 SET(TARGET_LIBNAME_WGT "wgt-installer")
 SET(TARGET_WGT_BACKEND "wgt-backend")
 # Targets
 SET(TARGET_LIBNAME_WGT "wgt-installer")
 SET(TARGET_WGT_BACKEND "wgt-backend")
-SET(TARGET_SMOKE_TEST "smoke_test")
 SET(TARGET_LIBNAME_HYBRID "hybrid-installer")
 
 SET(TARGET_LIBNAME_HYBRID "hybrid-installer")
 
+SET(TARGET_SMOKE_TEST "smoke-test")
+SET(TARGET_SMOKE_TEST_HELPER "smoke-test-helper")
+
 ADD_DEFINITIONS("-Wall")
 ADD_DEFINITIONS("-Wextra")
 ADD_DEFINITIONS("-fPIE")
 ADD_DEFINITIONS("-Wall")
 ADD_DEFINITIONS("-Wextra")
 ADD_DEFINITIONS("-fPIE")
index 6c0eb4f..9e728be 100644 (file)
@@ -4,5 +4,6 @@
         </request>
         <assign>
                 <filesystem path="/usr/bin/wgt-backend-ut/smoke_test" exec_label="User" />
         </request>
         <assign>
                 <filesystem path="/usr/bin/wgt-backend-ut/smoke_test" exec_label="User" />
+                <filesystem path="/usr/bin/wgt-backend-ut/smoke-test-helper" exec_label="User" />
         </assign>
 </manifest>
         </assign>
 </manifest>
index f482f8f..e09827f 100644 (file)
@@ -1,15 +1,19 @@
 SET(DESTINATION_DIR wgt-backend-ut)
 
 SET(DESTINATION_DIR wgt-backend-ut)
 
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../)
-
 # Executables
 ADD_EXECUTABLE(${TARGET_SMOKE_TEST}
   smoke_test.cc
 )
 # Executables
 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)
 
 
 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
 )
   Boost
   GTEST
 )
@@ -17,6 +21,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.
 # 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_WGT} ${TARGET_LIBNAME_HYBRID} ${GTEST_MAIN_LIBRARIES})
+target_link_libraries(${TARGET_SMOKE_TEST} PRIVATE ${TARGET_LIBNAME_WGT} ${TARGET_LIBNAME_HYBRID} ${GTEST_MAIN_LIBRARIES})
+target_link_libraries(${TARGET_SMOKE_TEST_HELPER} PRIVATE ${TARGET_LIBNAME_WGT})
 
 
-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 5749361..551313c 100644 (file)
@@ -11,6 +11,7 @@
 #include <common/pkgmgr_registration.h>
 #include <common/request.h>
 #include <common/step/step_fail.h>
 #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>
 #include <pkgmgr-info.h>
 #include <gtest/gtest.h>
 #include <gtest/gtest-death-test.h>
 #include <pkgmgr-info.h>
@@ -46,15 +47,14 @@ const char KUserAppsDirBackup[] = "apps_rw.bck";
 
 enum class RequestResult {
   NORMAL,
 
 enum class RequestResult {
   NORMAL,
-  FAIL,
-  CRASH
+  FAIL
 };
 
 class TestPkgmgrInstaller : public ci::PkgmgrInstallerInterface {
  public:
   bool CreatePkgMgrInstaller(pkgmgr_installer** installer,
                              ci::InstallationMode* mode) {
 };
 
 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;
     if (!*installer)
       return false;
     *mode = ci::InstallationMode::ONLINE;
@@ -71,19 +71,6 @@ enum class PackageType {
   HYBRID
 };
 
   HYBRID
 };
 
-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))
 void RemoveAllRecoveryFiles() {
   bf::path root_path = ci::GetRootAppPath(false);
   if (!bf::exists(root_path))
@@ -240,8 +227,6 @@ ci::AppInstaller::Result RunInstallerWithPkgrmgr(ci::PkgMgrPtr pkgmgr,
   case RequestResult::FAIL:
     installer->AddStep<ci::configuration::StepFail>();
     break;
   case RequestResult::FAIL:
     installer->AddStep<ci::configuration::StepFail>();
     break;
-  case RequestResult::CRASH:
-    installer->AddStep<StepCrash>();
   default:
     break;
   }
   default:
     break;
   }
@@ -454,7 +439,9 @@ TEST_F(SmokeTest, DeltaMode) {
 
 TEST_F(SmokeTest, RecoveryMode_ForInstallation) {
   bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForInstallation.wgt";
 
 TEST_F(SmokeTest, RecoveryMode_ForInstallation) {
   bf::path path = kSmokePackagesDirectory / "RecoveryMode_ForInstallation.wgt";
-  ASSERT_DEATH(Install(path, PackageType::WGT, RequestResult::CRASH), ".*");
+  Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
+  backend_crash.Run("-i", path.string());
+  ASSERT_NE(backend_crash.Wait(), 0);
 
   std::string pkgid = "smokeapp09";
   std::string appid = "smokeapp09.RecoveryModeForInstallation";
 
   std::string pkgid = "smokeapp09";
   std::string appid = "smokeapp09.RecoveryModeForInstallation";
@@ -469,8 +456,12 @@ TEST_F(SmokeTest, RecoveryMode_ForUpdate) {
   bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForUpdate.wgt";
   bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForUpdate_2.wgt";
   RemoveAllRecoveryFiles();
   bf::path path_old = kSmokePackagesDirectory / "RecoveryMode_ForUpdate.wgt";
   bf::path path_new = kSmokePackagesDirectory / "RecoveryMode_ForUpdate_2.wgt";
   RemoveAllRecoveryFiles();
-  ASSERT_DEATH(Update(path_old, path_new, PackageType::WGT,
-                      RequestResult::CRASH), ".*");
+  Subprocess backend_test("/usr/bin/wgt-backend");
+  backend_test.Run("-i", path_old.string());
+  ASSERT_EQ(backend_test.Wait(), 0);
+  Subprocess backend_crash("/usr/bin/wgt-backend-ut/smoke-test-helper");
+  backend_crash.Run("-i", path_new.string());
+  ASSERT_NE(backend_crash.Wait(), 0);
 
   std::string pkgid = "smokeapp10";
   std::string appid = "smokeapp10.RecoveryModeForUpdate";
 
   std::string pkgid = "smokeapp10";
   std::string appid = "smokeapp10.RecoveryModeForUpdate";
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..c3988d6
--- /dev/null
@@ -0,0 +1,45 @@
+// 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 <cerrno>
+
+#include "wgt/wgt_app_query_interface.h"
+#include "wgt/wgt_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 main of test binay in done purely for recovery smoke test.
+int main(int argc, char** argv) {
+  ci::PkgmgrInstaller pkgmgr_installer;
+  wgt::WgtAppQueryInterface query_interface;
+  auto pkgmgr = ci::PkgMgrInterface::Create(argc, argv, &pkgmgr_installer,
+                                            &query_interface);
+  if (!pkgmgr) {
+    LOG(ERROR) << "Options of pkgmgr installer cannot be parsed";
+    return EINVAL;
+  }
+
+  wgt::WgtInstaller installer(pkgmgr);
+  installer.AddStep<StepCrash>();
+  return (installer.Run() == ci::AppInstaller::Result::OK) ? 0 : 1;
+}
+