1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
#include "utils/test_server.h"
#include "utils/utils.h"
#include "utils/options.h"
#include <tango/tango.h>
#include <catch2/catch_session.hpp>
#include <string_view>
#include <iostream>
namespace TangoTest
{
Options g_options;
int test_main(int argc, const char *argv[])
{
using namespace Catch::Clara;
Catch::Session session;
auto cli = session.cli();
cli |= Opt(g_options.log_file_per_test_case)["--log-file-per-test-case"](
"create a log file for each test case, otherwise use a single log file for the whole run");
cli |= Opt([](int value) { g_options.only_idl_version = value; },
"idlversion")["--only-idl"]("only idl version of servers to run tests against");
session.cli(cli);
return session.run(argc, argv);
}
int server_main(int argc, const char *argv[])
{
try
{
auto *tg = Tango::Util::init(argc, (char **) argv);
tg->set_trace_level(5);
detail::setup_topic_log_appender(tg->get_ds_inst_name());
Tango::Logging::get_core_logger()->set_level(log4tango::Level::DEBUG);
tg->server_init();
std::cout << TestServer::k_ready_string << '\n' << std::flush;
tg->server_run();
tg->server_cleanup();
}
catch(std::exception &ex)
{
std::cerr << "Server initialisation failed: " << ex.what() << "\n" << std::flush;
return 2;
}
catch(Tango::DevFailed &ex)
{
Tango::Except::print_exception(ex);
return 2;
}
catch(CORBA::Exception &ex)
{
Tango::Except::print_exception(ex);
return 2;
}
return 0;
}
} // namespace TangoTest
namespace
{
// Returns true if `string` ends with `suffix`
bool ends_with(std::string_view string, std::string_view suffix)
{
size_t size = string.size();
size_t suffix_size = suffix.size();
if(size < suffix_size)
{
return false;
}
std::string_view ending = string.substr(size - suffix_size);
return ending == suffix;
}
} // namespace
int main(int argc, const char *argv[])
{
std::string name{argv[0]};
if(ends_with(name, TANGO_TEST_CATCH2_SERVER_BINARY_NAME))
{
return TangoTest::server_main(argc, argv);
}
else if(ends_with(name, TANGO_TEST_CATCH2_TEST_BINARY_NAME))
{
return TangoTest::test_main(argc, argv);
}
std::cerr << "Unexpected argv[0] " << name << "\n";
return 1;
}
|