// 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));
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
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();
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));
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;
private:
ci::RequestMode request_mode_;
std::vector<bf::path> backups_;
+ bool no_backup_;
};
} // namespace smoke_test
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'},
{"delay", 1, NULL, 'l'},
{"interval", 1, NULL, 't'},
{"repeat", 1, NULL, 'r'},
+ {"no-backup", 0, NULL, 'b'},
{0, 0, 0, 0} /* sentinel */
};
"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;
repeat_count = atoi(optarg);
break;
+ case 'b': /* skip backup */
+ no_backup = true;
+ break;
+
default:
break;
}
testing::InitGoogleTest(>est_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();
// 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>
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));
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
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();