Skip to content

Commit

Permalink
Merge pull request #295 from DUNE-DAQ/plasorak/remove-name-session-cli
Browse files Browse the repository at this point in the history
Remove the `--name` and `--session` from the cli, and use env instead
  • Loading branch information
plasorak authored Oct 2, 2024
2 parents d99666b + b2d9b52 commit 746af78
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 86 deletions.
29 changes: 18 additions & 11 deletions apps/daq_application.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
#include <string>
#include <vector>




/**
* @brief Using namespace for convenience
*/
Expand Down Expand Up @@ -79,19 +76,29 @@ main(int argc, char* argv[])
exit(0);
}

// Set/Update the application and partition name in the environment. Used by logging/ers.
setenv("DUNEDAQ_APPLICATION_NAME", args.app_name.c_str(), 0);
setenv("DUNEDAQ_PARTITION", args.session_name.c_str(), 0);
// Get the application and session name from the environment.
std::string app_name = "";
std::string session_name = "";

char* app_name_c = getenv("DUNEDAQ_APPLICATION_NAME");
char* session_name_c = getenv("DUNEDAQ_SESSION");

bool missing_env_var =
!app_name_c || std::string(app_name_c) == "" || !session_name_c || std::string(session_name_c) == "";
if (missing_env_var) {
ers::error(appfwk::EnvironmentVariableNotFound(ERS_HERE, "DUNEDAQ_APPLICATION_NAME or DUNEDAQ_SESSION"));
exit(1);
}

app_name = app_name_c;
session_name = session_name_c;

// Create the Application
appfwk::Application app(args.app_name,
args.session_name,
args.command_facility_plugin_name,
args.conf_service_plugin_name);
appfwk::Application app(app_name, session_name, args.command_facility_plugin_name, args.conf_service_plugin_name);

app.init();
app.run(run_marker);

TLOG() << "Application " << args.app_name << " exiting.";
TLOG() << "Application " << app_name << " exiting.";
return 0;
}
5 changes: 5 additions & 0 deletions include/appfwk/Issues.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ ERS_DECLARE_ISSUE(appfwk,
ActionPlanValidationFailed,
"Error validating action plan " << cmd << ", module " << module << ": " << message,
((std::string)cmd)((std::string)module)((std::string)message))

ERS_DECLARE_ISSUE(appfwk,
EnvironmentVariableNotFound,
"Environment variable " << var << " wasn't found.",
((std::string)var))
// Re-enable coverage collection LCOV_EXCL_STOP
} // namespace dunedaq

Expand Down
8 changes: 2 additions & 6 deletions src/CommandLineInterpreter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ struct CommandLineInterpreter
<< " known arguments (additional arguments will be stored and "
"passed on)";
bpo::options_description desc(descstr.str());
desc.add_options()("name,n", bpo::value<std::string>()->required(), "Application name")(
"session,s", bpo::value<std::string>()->default_value("global"), "Session name")(
desc.add_options()(
"commandFacility,c", bpo::value<std::string>()->required(), "CommandFacility URI")(
"configurationService,d", bpo::value<std::string>()->required(), "Configuration Service URI")(
"help,h", "produce help message");
Expand All @@ -80,17 +79,14 @@ struct CommandLineInterpreter
throw CommandLineIssue(ERS_HERE, *argv, e.what());
}

output.app_name = vm["name"].as<std::string>();
output.session_name = vm["session"].as<std::string>();
output.command_facility_plugin_name = vm["commandFacility"].as<std::string>();
output.conf_service_plugin_name = vm["configurationService"].as<std::string>();

return output;
}

bool help_requested{ false }; ///< Did the user just ask for help?

std::string app_name{ "" };
std::string session_name{ "" };
std::string command_facility_plugin_name{ "" }; ///< Name of the CommandFacility plugin to load
std::string conf_service_plugin_name{ "" }; ///< Name of the ConfService plugin to load

Expand Down
6 changes: 6 additions & 0 deletions src/DAQModuleManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,12 @@ DAQModuleManager::execute(const std::string& cmd, const dataobj_t& cmd_data)
for (auto& step : action_plan->get_steps()) {
execute_action_plan_step(cmd, step, cmd_data, serial_execution);
}

}

// Shutdown IOManager at scrap
if (cmd == "scrap") {
get_iomanager()->shutdown();
}
}

Expand Down
77 changes: 8 additions & 69 deletions unittest/CommandLineInterpreter_test.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,10 @@ BOOST_AUTO_TEST_CASE(ParseNoOptions)

BOOST_AUTO_TEST_CASE(AskForHelp)
{

char** arg_list = new char* [2] { (char*)("CommandLineInterpreter_test"), (char*)("-h") }; // NOLINT
auto parsed = CommandLineInterpreter::parse(2, arg_list);

BOOST_REQUIRE_EQUAL(parsed.help_requested, true);
BOOST_REQUIRE_EQUAL(parsed.app_name, "");
BOOST_REQUIRE_EQUAL(parsed.session_name, "");
BOOST_REQUIRE_EQUAL(parsed.command_facility_plugin_name, "");
BOOST_REQUIRE_EQUAL(parsed.conf_service_plugin_name, "");
BOOST_REQUIRE_EQUAL(parsed.other_options.size(), 0);
Expand All @@ -59,96 +56,38 @@ BOOST_AUTO_TEST_CASE(ParseCommandFacility)
delete[] arg_list; // NOLINT
}

BOOST_AUTO_TEST_CASE(ParseName)
{

char** arg_list = new char* [5] {
(char*)("CommandLineInterpreter_test"), (char*)("-n"), (char*)("cli_test"), (char*)("-d"), (char*)("file://"),
}; // NOLINT
BOOST_REQUIRE_EXCEPTION(CommandLineInterpreter::parse(5, arg_list),
dunedaq::appfwk::CommandLineIssue,
[&](dunedaq::appfwk::CommandLineIssue) { return true; });

delete[] arg_list; // NOLINT
}

BOOST_AUTO_TEST_CASE(ParseNameAndCommandFacility)
{
char** arg_list = new char* [7] {
(char*)("CommandLineInterpreter_test"), // NOLINT
(char*)("-c"), (char*)("stdin://"), // NOLINT
(char*)("-d"), (char*)("file://"), // NOLINT
(char*)("-n"), (char*)("cli_test") // NOLINT
};
auto parsed = CommandLineInterpreter::parse(7, arg_list);

BOOST_REQUIRE_EQUAL(parsed.help_requested, false);
BOOST_REQUIRE_EQUAL(parsed.app_name, "cli_test");
BOOST_REQUIRE_EQUAL(parsed.session_name, "global");
BOOST_REQUIRE_EQUAL(parsed.command_facility_plugin_name, "stdin://");
BOOST_REQUIRE_EQUAL(parsed.conf_service_plugin_name, "file://");
BOOST_REQUIRE_EQUAL(parsed.other_options.size(), 0);

delete[] arg_list; // NOLINT
}

BOOST_AUTO_TEST_CASE(ParseSession)
{
char** arg_list = new char* [9] {
(char*)("CommandLineInterpreter_test"), // NOLINT
(char*)("-c"), (char*)("stdin://"), // NOLINT
(char*)("-d"), (char*)("file://"), // NOLINT
(char*)("-n"), (char*)("cli_test"), // NOLINT
(char*)("-s"), (char*)("test_session") // NOLINT
};
auto parsed = CommandLineInterpreter::parse(9, arg_list);

BOOST_REQUIRE_EQUAL(parsed.help_requested, false);
BOOST_REQUIRE_EQUAL(parsed.app_name, "cli_test");
BOOST_REQUIRE_EQUAL(parsed.session_name, "test_session");
BOOST_REQUIRE_EQUAL(parsed.command_facility_plugin_name, "stdin://");
BOOST_REQUIRE_EQUAL(parsed.conf_service_plugin_name, "file://");
BOOST_REQUIRE_EQUAL(parsed.other_options.size(), 0);

delete[] arg_list; // NOLINT
}
BOOST_AUTO_TEST_CASE(ParseOtherOption)
{
char** arg_list = new char* [8] {
char** arg_list = new char* [6] {
(char*)("CommandLineInterpreter_test"), // NOLINT
(char*)("-c"), (char*)("stdin://"), // NOLINT
(char*)("-d"), (char*)("file://"), // NOLINT
(char*)("-n"), (char*)("cli_test"), // NOLINT
(char*)("--some-other-option") // NOLINT
(char*)("-c"), (char*)("stdin://"), // NOLINT
(char*)("-d"), (char*)("file://"), // NOLINT
(char*)("--some-other-option") // NOLINT
};
auto parsed = CommandLineInterpreter::parse(8, arg_list);
auto parsed = CommandLineInterpreter::parse(6, arg_list);

BOOST_REQUIRE_EQUAL(parsed.help_requested, false);
BOOST_REQUIRE_EQUAL(parsed.app_name, "cli_test");
BOOST_REQUIRE_EQUAL(parsed.session_name, "global");
BOOST_REQUIRE_EQUAL(parsed.command_facility_plugin_name, "stdin://");
BOOST_REQUIRE_EQUAL(parsed.conf_service_plugin_name, "file://");
BOOST_REQUIRE_EQUAL(parsed.other_options.size(), 1);
BOOST_REQUIRE_EQUAL(parsed.other_options[0], "--some-other-option");

delete[] arg_list; // NOLINT
}

BOOST_AUTO_TEST_CASE(ParseMultipleOtherOptions)
{
char** arg_list = new char* [11] {
char** arg_list = new char* [9] {
(char*)("CommandLineInterpreter_test"), // NOLINT
(char*)("-c"), (char*)("stdin://"), // NOLINT
(char*)("-d"), (char*)("file://"), // NOLINT
(char*)("-n"), (char*)("cli_test"), // NOLINT
(char*)("--some-other-option"), // NOLINT
(char*)("--yet-another-option=4"), // NOLINT
(char*)("-u"), (char*)("me") // NOLINT
};
auto parsed = CommandLineInterpreter::parse(11, arg_list);
auto parsed = CommandLineInterpreter::parse(9, arg_list);

BOOST_REQUIRE_EQUAL(parsed.help_requested, false);
BOOST_REQUIRE_EQUAL(parsed.app_name, "cli_test");
BOOST_REQUIRE_EQUAL(parsed.session_name, "global");
BOOST_REQUIRE_EQUAL(parsed.command_facility_plugin_name, "stdin://");
BOOST_REQUIRE_EQUAL(parsed.conf_service_plugin_name, "file://");
BOOST_REQUIRE_EQUAL(parsed.other_options.size(), 4);
Expand Down

0 comments on commit 746af78

Please sign in to comment.