53auto main(
int argc,
char** argv) ->
int
55 auto cli_args = CLI::App{
"SRS integration test" };
57 auto is_continuous_output =
false;
58 const auto input_filename = std::string{
"test_data.bin" };
59 auto output_filenames = std::vector<std::string>{
"" };
63 auto n_output_split = 1;
65 auto spdlog_level = spdlog::level::info;
66 const auto home_dir = []() -> std::string
68 const auto* home_var = getenv(
"HOME");
69 if (home_var !=
nullptr)
71 return std::string{ home_var };
75 auto json_filepath = home_dir.empty() ?
"" : std::format(
"{}/.config/srs-control/config.json", getenv(
"HOME"));
76 argv = cli_args.ensure_utf8(argv);
80 .add_option(
"-l, --log-level",
82 fmt::format(
"Set log level\nAvailable options: [{}]", fmt::join(
SPDLOG_LOG_NAMES,
", ")))
83 ->transform(CLI::CheckedTransformer(
spdlog_map, CLI::ignore_case).description(
""))
85 cli_args.add_flag(
"--cont", is_continuous_output,
"Set the emulator continuous output");
86 cli_args.add_option(
"-o, --output-files", output_filenames,
"Set output file (or socket) names")
87 ->capture_default_str()
89 cli_args.add_option(
"-s, --split-output", n_output_split,
"Splitting the output data into different files.")
90 ->capture_default_str();
93 "-d, --delay-time", delay_time,
"Set the delay time (us) when sending the data from the server.")
94 ->capture_default_str();
95 cli_args.add_option(
"-r, --run-time", run_time,
"Set the run time when --cont is enabled.")
96 ->capture_default_str();
97 cli_args.add_option(
"-c, --config-file", json_filepath,
"Set the path of the JSON config file")
98 ->capture_default_str();
100 cli_args.parse(argc, argv);
102 spdlog::set_level(spdlog_level);
105 world.set_delay_time_us(delay_time);
107 auto& app = world.get_app();
110 app.set_options(std::move(app_config));
111 app.get_config_ref().remote_fec_ips = std::vector{ std::string{
"127.0.0.1" } };
113 app.set_output_filenames(output_filenames, n_output_split);
115 world.launch_server();
117 app.start_workflow();
121 auto switch_off_thread = std::jthread(
122 [&app, &world, is_continuous_output, &run_time]()
124 if (is_continuous_output)
126 std::this_thread::sleep_for(std::chrono::seconds{ run_time });
130 world.get_server()->wait_for_data_sender();
132 app.exit_and_switch_off();
135 app.wait_for_workflow();
137 catch (
const CLI::ParseError& e)
142 catch (
const exception& ex)
144 spdlog::critical(
"exception occurred: {}", ex.what());
146 auto wrong_file_size = not is_continuous_output and
147 not std::ranges::all_of(output_filenames,
148 [&input_filename](std::string_view name) ->
bool
153 if (file_type == no_output or file_type ==
udp)
157 if (name.ends_with(
".bin"))
159 return get_file_size(name) == get_file_size(input_filename);
161 return get_file_size(name) != 0;
165 spdlog::error(
"Output files don't have correct sizes!");
168 spdlog::info(
"All output files have correct sizes!");
constexpr auto SPDLOG_LOG_NAMES