Add no backup option for smoke tests 84/218084/12
authorIlho Kim <ilho159.kim@samsung.com>
Tue, 19 Nov 2019 06:18:33 +0000 (15:18 +0900)
committerilho kim <ilho159.kim@samsung.com>
Tue, 26 Nov 2019 07:54:54 +0000 (07:54 +0000)
Run smoke tests with argument "--no-backup", backup is skipped

Change-Id: I83d58214b63f5528a0cc3c110cfa8554c5a0e544
Signed-off-by: Ilho Kim <ilho159.kim@samsung.com>
src/unit_tests/extensive_smoke_test.cc
src/unit_tests/recovery_test.cc
src/unit_tests/smoke_test.cc

index 9e73532e721ac3e37251a282e63c0782b328c062..6522fdd37380ecbe75ffba77c1d33cefaf67708e 100644 (file)
@@ -2,6 +2,9 @@
 // Use of this source code is governed by an apache-2.0 license that can be
 // found in the LICENSE file.
 
+#include <boost/exception/diagnostic_information.hpp>
+#include <boost/program_options.hpp>
+
 #include <unit_tests/common/smoke_utils.h>
 
 #include <gtest/gtest.h>
 
 #include "unit_tests/smoke_utils.h"
 
+namespace bpo = boost::program_options;
 namespace ci = common_installer;
 
 namespace smoke_test {
 
 class SmokeEnvironment : public testing::Environment {
  public:
-  explicit SmokeEnvironment(ci::RequestMode mode) {
-    request_mode_ = mode;
+  explicit SmokeEnvironment(ci::RequestMode mode, bool no_backup) :
+      request_mode_(mode), no_backup_(no_backup) {
   }
   void SetUp() override {
     if (request_mode_ == ci::RequestMode::USER)
       ASSERT_TRUE(AddTestUser(&test_user));
+    if (no_backup_)
+      return;
     backups_ = SetupBackupDirectories(test_user.uid);
     for (auto& path : backups_)
       ASSERT_TRUE(BackupPath(path));
@@ -31,16 +37,19 @@ class SmokeEnvironment : public testing::Environment {
                 kGlobalUserUid != test_user.uid));
     TpkBackendInterface backend(std::to_string(test_user.uid));
     UninstallAllSmokeApps(request_mode_, test_user.uid, &backend);
-    for (auto& path : backups_)
-      ASSERT_TRUE(RestorePath(path));
     if (request_mode_ == ci::RequestMode::USER)
       ASSERT_TRUE(DeleteTestUser());
+    if (no_backup_)
+      return;
+    for (auto& path : backups_)
+      ASSERT_TRUE(RestorePath(path));
   }
   User test_user;
 
  private:
   ci::RequestMode request_mode_;
   std::vector<bf::path> backups_;
+  bool no_backup_;
 };
 
 }  // namespace smoke_test
@@ -413,15 +422,39 @@ TEST_F(SmokeTest, MountUpdateMode_Rollback) {
 
 int main(int argc,  char** argv) {
   try {
+    bool no_backup = false;
     ci::RequestMode request_mode = smoke_test::ParseRequestMode(argc, argv);
     if (getuid() != 0 || request_mode != ci::RequestMode::GLOBAL) {
       std::cout << "Skip tests for preload request" << std::endl;
       ::testing::GTEST_FLAG(filter) = "SmokeTest.*";
     }
     testing::InitGoogleTest(&argc, argv);
+
+    bpo::options_description options("Allowed options");
+    bpo::variables_map opt_map;
+    try {
+      options.add_options()
+          ("help", "display this help message")
+          ("no-backup", "Do test without backup");
+      bpo::store(bpo::parse_command_line(argc, argv, options), opt_map);
+      if (opt_map.count("help")) {
+        std::cerr << options << std::endl;
+        return -1;
+      }
+
+      if (opt_map.count("no-backup"))
+        no_backup = true;
+      bpo::notify(opt_map);
+    } catch (...) {
+      std::cerr << "Exception occurred: "
+                << boost::current_exception_diagnostic_information()
+                << std::endl;
+      return -1;
+    }
+
     ::env = static_cast<smoke_test::SmokeEnvironment*>(
         testing::AddGlobalTestEnvironment(
-            new smoke_test::SmokeEnvironment(request_mode)));
+            new smoke_test::SmokeEnvironment(request_mode, no_backup)));
     signal(SIGINT, ::signalHandler);
     signal(SIGSEGV, ::signalHandler);
     return RUN_ALL_TESTS();
index 9244606e3032cabc3aa2bbeb1c617981997068ec..4f053452d809d4f9f5bc2d2448484a64895fd0bf 100644 (file)
@@ -42,19 +42,23 @@ namespace smoke_test {
 
 class SmokeEnvironment : public testing::Environment {
  public:
-  explicit SmokeEnvironment(ci::RequestMode mode) : request_mode_(mode) {
+  explicit SmokeEnvironment(ci::RequestMode mode, bool no_backup) :
+      request_mode_(mode), no_backup_(no_backup) {
   }
 
   void SetUp() override {
     if (request_mode_ == ci::RequestMode::USER)
       ASSERT_TRUE(AddTestUser(&test_user));
 
+    if (no_backup_)
+      return;
     backups_ = SetupBackupDirectories(test_user.uid);
     for (auto& path : backups_)
       ASSERT_TRUE(BackupPath(path));
   }
 
   void TearDown() override {
+    test_count++;
     ASSERT_TRUE(request_mode_ == ci::RequestMode::GLOBAL ||
                 (request_mode_ == ci::RequestMode::USER &&
                 kGlobalUserUid != test_user.uid));
@@ -62,13 +66,12 @@ class SmokeEnvironment : public testing::Environment {
     TpkBackendInterface backend(std::to_string(test_user.uid));
     UninstallAllSmokeApps(request_mode_, test_user.uid, &backend);
 
-    for (auto& path : backups_)
-      ASSERT_TRUE(RestorePath(path));
-
     if (request_mode_ == ci::RequestMode::USER)
       ASSERT_TRUE(DeleteTestUser());
-
-    test_count++;
+    if (no_backup_)
+      return;
+    for (auto& path : backups_)
+      ASSERT_TRUE(RestorePath(path));
   }
 
   User test_user;
@@ -76,6 +79,7 @@ class SmokeEnvironment : public testing::Environment {
  private:
   ci::RequestMode request_mode_;
   std::vector<bf::path> backups_;
+  bool no_backup_;
 };
 
 }  // namespace smoke_test
@@ -265,7 +269,7 @@ TEST_F(SmokeTest, RecoveryMode_ForMountUpdate) {
 
 const int kBufSize = 1024;
 
-const char *short_options = "iudmn:l:t:r";
+const char *short_options = "iudmn:l:t:r:b";
 const struct option long_options[] = {
   {"install", 0, NULL, 'i'},
   {"update", 0, NULL, 'u'},
@@ -275,6 +279,7 @@ const struct option long_options[] = {
   {"delay", 1, NULL, 'l'},
   {"interval", 1, NULL, 't'},
   {"repeat", 1, NULL, 'r'},
+  {"no-backup", 0, NULL, 'b'},
   {0, 0, 0, 0}    /* sentinel */
 };
 
@@ -296,9 +301,12 @@ static void __print_usage() {
       "use with repeat option. as it repeat the interval is added to delay\n");
   printf("--repeat   <count>    "
       "option for performing tests repeatedly\n");
+  printf("--no-backup           "
+      "do a test without backup\n");
 }
 
 int main(int argc,  char** argv) {
+  bool no_backup = false;
   int c = -1;
   int opt_idx = 0;
   int repeat_count = 10;
@@ -351,6 +359,10 @@ int main(int argc,  char** argv) {
         repeat_count = atoi(optarg);
       break;
 
+    case 'b':  /* skip backup */
+        no_backup = true;
+      break;
+
     default:
       break;
     }
@@ -382,7 +394,8 @@ int main(int argc,  char** argv) {
     testing::InitGoogleTest(&gtest_argc, gtest_argv.data());
     ::env = static_cast<smoke_test::SmokeEnvironment*>(
         testing::AddGlobalTestEnvironment(
-            new smoke_test::SmokeEnvironment(ci::RequestMode::GLOBAL)));
+            new smoke_test::SmokeEnvironment(ci::RequestMode::GLOBAL,
+                no_backup)));
     signal(SIGINT, ::signalHandler);
     signal(SIGSEGV, ::signalHandler);
     return RUN_ALL_TESTS();
index afb77dedce370dccc895851d613d39e8b6e814e2..2d3bcf1d0020940e3d5d8ade9528080dacb60df5 100644 (file)
@@ -2,6 +2,9 @@
 // Use of this source code is governed by an apache-2.0 license that can be
 // found in the LICENSE file.
 
+#include <boost/exception/diagnostic_information.hpp>
+#include <boost/program_options.hpp>
+
 #include <common/utils/subprocess.h>
 #include <common/utils/file_util.h>
 #include <common/pkgmgr_query.h>
@@ -16,17 +19,20 @@ namespace st = smoke_test;
 namespace bf = boost::filesystem;
 namespace bs = boost::system;
 namespace ci = common_installer;
-namespace bo = boost::program_options;
+namespace bpo = boost::program_options;
 
 namespace smoke_test {
 
 class SmokeEnvironment : public testing::Environment {
  public:
-  explicit SmokeEnvironment(ci::RequestMode mode) : request_mode_(mode) {
+  explicit SmokeEnvironment(ci::RequestMode mode, bool no_backup) :
+      request_mode_(mode), no_backup_(no_backup) {
   }
   void SetUp() override {
     if (request_mode_ == ci::RequestMode::USER)
       ASSERT_TRUE(AddTestUser(&test_user));
+    if (no_backup_)
+      return;
     backups_ = SetupBackupDirectories(test_user.uid);
     for (auto& path : backups_)
       ASSERT_TRUE(BackupPath(path));
@@ -37,16 +43,19 @@ class SmokeEnvironment : public testing::Environment {
                 kGlobalUserUid != test_user.uid));
     TpkBackendInterface backend(std::to_string(test_user.uid));
     UninstallAllSmokeApps(request_mode_, test_user.uid, &backend);
-    for (auto& path : backups_)
-      ASSERT_TRUE(RestorePath(path));
     if (request_mode_ == ci::RequestMode::USER)
       ASSERT_TRUE(DeleteTestUser());
+    if (no_backup_)
+      return;
+    for (auto& path : backups_)
+      ASSERT_TRUE(RestorePath(path));
   }
   User test_user;
 
  private:
   ci::RequestMode request_mode_;
   std::vector<bf::path> backups_;
+  bool no_backup_;
 };
 
 }  // namespace smoke_test
@@ -745,15 +754,40 @@ TEST_F(SmokeTest, RecoveryMode_CrashAfterUnzip) {
 
 int main(int argc,  char** argv) {
   try {
+    bool no_backup = false;
     ci::RequestMode request_mode = st::ParseRequestMode(argc, argv);
     if (getuid() != 0 || request_mode != ci::RequestMode::GLOBAL) {
       std::cout << "Skip tests for preload request" << std::endl;
       ::testing::GTEST_FLAG(filter) = "SmokeTest.*";
     }
     testing::InitGoogleTest(&argc, argv);
+
+    bpo::options_description options("Allowed options");
+    bpo::variables_map opt_map;
+    try {
+      options.add_options()
+          ("help", "display this help message")
+          ("no-backup", "Do test without backup");
+      bpo::store(bpo::parse_command_line(argc, argv, options), opt_map);
+      if (opt_map.count("help")) {
+        std::cerr << options << std::endl;
+        return -1;
+      }
+
+      if (opt_map.count("no-backup"))
+        no_backup = true;
+      bpo::notify(opt_map);
+    } catch (...) {
+      std::cerr << "Exception occurred: "
+                << boost::current_exception_diagnostic_information()
+                << std::endl;
+      return -1;
+    }
+
     ::env = static_cast<smoke_test::SmokeEnvironment*>(
         testing::AddGlobalTestEnvironment(
-            new smoke_test::SmokeEnvironment(request_mode)));
+            new smoke_test::SmokeEnvironment(request_mode, no_backup)));
+
     signal(SIGINT, ::signalHandler);
     signal(SIGSEGV, ::signalHandler);
     return RUN_ALL_TESTS();