From: Ilho Kim Date: Tue, 19 Nov 2019 06:18:33 +0000 (+0900) Subject: Add no backup option for smoke tests X-Git-Tag: submit/tizen/20191213.074937~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=720cedce706379eed0e8be1c195e1a189b1d7e28;p=platform%2Fcore%2Fappfw%2Ftpk-backend.git Add no backup option for smoke tests Run smoke tests with argument "--no-backup", backup is skipped Change-Id: I83d58214b63f5528a0cc3c110cfa8554c5a0e544 Signed-off-by: Ilho Kim --- diff --git a/src/unit_tests/extensive_smoke_test.cc b/src/unit_tests/extensive_smoke_test.cc index 9e73532..6522fdd 100644 --- a/src/unit_tests/extensive_smoke_test.cc +++ b/src/unit_tests/extensive_smoke_test.cc @@ -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 +#include + #include #include @@ -9,18 +12,21 @@ #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 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( 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(); diff --git a/src/unit_tests/recovery_test.cc b/src/unit_tests/recovery_test.cc index 9244606..4f05345 100644 --- a/src/unit_tests/recovery_test.cc +++ b/src/unit_tests/recovery_test.cc @@ -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 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 " "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(>est_argc, gtest_argv.data()); ::env = static_cast( 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(); diff --git a/src/unit_tests/smoke_test.cc b/src/unit_tests/smoke_test.cc index afb77de..2d3bcf1 100644 --- a/src/unit_tests/smoke_test.cc +++ b/src/unit_tests/smoke_test.cc @@ -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 +#include + #include #include #include @@ -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 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( 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();