mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-13 16:46:47 +00:00
Add additional test for running device with plugins without DeviceRunner
This commit is contained in:
parent
4281d7b27e
commit
5271d4236e
|
@ -24,27 +24,27 @@ DeviceRunner::DeviceRunner(int argc, char* const argv[], bool printLogo)
|
|||
, fEvents()
|
||||
{}
|
||||
|
||||
bool DeviceRunner::HandleGeneralOptions()
|
||||
bool DeviceRunner::HandleGeneralOptions(const fair::mq::ProgOptions& config, bool printLogo)
|
||||
{
|
||||
if (fConfig.Count("help")) {
|
||||
fConfig.PrintHelp();
|
||||
if (config.Count("help")) {
|
||||
config.PrintHelp();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fConfig.Count("print-options")) {
|
||||
fConfig.PrintOptionsRaw();
|
||||
if (config.Count("print-options")) {
|
||||
config.PrintOptionsRaw();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fConfig.Count("print-channels") || fConfig.Count("version")) {
|
||||
if (config.Count("print-channels") || config.Count("version")) {
|
||||
fair::Logger::SetConsoleSeverity("nolog");
|
||||
} else {
|
||||
string severity = fConfig.GetProperty<string>("severity");
|
||||
string logFile = fConfig.GetProperty<string>("log-to-file");
|
||||
string logFileSeverity = fConfig.GetProperty<string>("file-severity");
|
||||
bool color = fConfig.GetProperty<bool>("color");
|
||||
string severity = config.GetProperty<string>("severity");
|
||||
string logFile = config.GetProperty<string>("log-to-file");
|
||||
string logFileSeverity = config.GetProperty<string>("file-severity");
|
||||
bool color = config.GetProperty<bool>("color");
|
||||
|
||||
string verbosity = fConfig.GetProperty<string>("verbosity");
|
||||
string verbosity = config.GetProperty<string>("verbosity");
|
||||
fair::Logger::SetVerbosity(verbosity);
|
||||
|
||||
if (logFile != "") {
|
||||
|
@ -55,7 +55,7 @@ bool DeviceRunner::HandleGeneralOptions()
|
|||
fair::Logger::SetConsoleSeverity(severity);
|
||||
}
|
||||
|
||||
if (fPrintLogo) {
|
||||
if (printLogo) {
|
||||
LOG(info) << endl
|
||||
<< " ______ _ _______ _________ " << endl
|
||||
<< " / ____/___ _(_)_______ |/ /_ __ \\ version " << FAIRMQ_GIT_VERSION << endl
|
||||
|
@ -64,7 +64,7 @@ bool DeviceRunner::HandleGeneralOptions()
|
|||
<< " /_/ \\__,_/_/_/ /_/ /_/ \\___\\_\\ " << FAIRMQ_LICENSE << " © " << FAIRMQ_COPYRIGHT << endl;
|
||||
}
|
||||
|
||||
fConfig.PrintOptions();
|
||||
config.PrintOptions();
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -122,7 +122,7 @@ auto DeviceRunner::Run() -> int
|
|||
|
||||
fConfig.ParseAll(fRawCmdLineArgs, true);
|
||||
|
||||
if (!HandleGeneralOptions()) {
|
||||
if (!HandleGeneralOptions(fConfig)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ class DeviceRunner
|
|||
auto Run() -> int;
|
||||
auto RunWithExceptionHandlers() -> int;
|
||||
|
||||
bool HandleGeneralOptions();
|
||||
static bool HandleGeneralOptions(const fair::mq::ProgOptions& config, bool printLogo = true);
|
||||
|
||||
void SubscribeForConfigChange();
|
||||
void UnsubscribeFromConfigChange();
|
||||
|
|
|
@ -363,12 +363,12 @@ void ProgOptions::AddChannel(const string& name, const FairMQChannel& channel)
|
|||
SetVarMapValue<bool>(string(prefix + "autoBind"), channel.GetAutoBind());
|
||||
}
|
||||
|
||||
void ProgOptions::PrintHelp()
|
||||
void ProgOptions::PrintHelp() const
|
||||
{
|
||||
cout << fAllOptions << endl;
|
||||
}
|
||||
|
||||
void ProgOptions::PrintOptions()
|
||||
void ProgOptions::PrintOptions() const
|
||||
{
|
||||
map<string, ValInfo> mapinfo;
|
||||
|
||||
|
@ -412,7 +412,7 @@ void ProgOptions::PrintOptions()
|
|||
LOG(debug) << ss.str();
|
||||
}
|
||||
|
||||
void ProgOptions::PrintOptionsRaw()
|
||||
void ProgOptions::PrintOptionsRaw() const
|
||||
{
|
||||
const vector<boost::shared_ptr<po::option_description>>& options = fAllOptions.options();
|
||||
|
||||
|
|
|
@ -144,9 +144,9 @@ class ProgOptions
|
|||
fEvents.Unsubscribe<fair::mq::PropertyChangeAsString, std::string>(subscriber);
|
||||
}
|
||||
|
||||
void PrintHelp();
|
||||
void PrintOptions();
|
||||
void PrintOptionsRaw();
|
||||
void PrintHelp() const;
|
||||
void PrintOptions() const;
|
||||
void PrintOptionsRaw() const;
|
||||
|
||||
const boost::program_options::variables_map& GetVarMap() const { return fVarMap; }
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
********************************************************************************/
|
||||
|
||||
#include <FairMQDevice.h>
|
||||
#include <fairmq/DeviceRunner.h>
|
||||
#include <fairmq/ProgOptions.h>
|
||||
|
||||
#include <fairmq/Tools.h>
|
||||
|
@ -125,6 +126,46 @@ class Config : public ::testing::Test
|
|||
return device.GetTransportName();
|
||||
}
|
||||
|
||||
string TestDeviceSetConfigWithPlugins(const string& transport)
|
||||
{
|
||||
fair::mq::ProgOptions config;
|
||||
|
||||
vector<string> emptyArgs = {"dummy", "--id", "test", "--color", "false"};
|
||||
|
||||
config.SetProperty("transport", transport);
|
||||
|
||||
FairMQDevice device;
|
||||
fair::mq::PluginManager mgr;
|
||||
mgr.LoadPlugin("s:config");
|
||||
mgr.ForEachPluginProgOptions([&](boost::program_options::options_description options) {
|
||||
config.AddToCmdLineOptions(options);
|
||||
});
|
||||
mgr.EmplacePluginServices(config, device);
|
||||
mgr.InstantiatePlugins();
|
||||
|
||||
config.ParseAll(emptyArgs, true);
|
||||
fair::mq::DeviceRunner::HandleGeneralOptions(config);
|
||||
device.SetConfig(config);
|
||||
|
||||
FairMQChannel channel;
|
||||
channel.UpdateType("pub");
|
||||
channel.UpdateMethod("connect");
|
||||
channel.UpdateAddress("tcp://localhost:5558");
|
||||
device.AddChannel("data", std::move(channel));
|
||||
|
||||
thread t(control, ref(device));
|
||||
|
||||
device.RunStateMachine();
|
||||
|
||||
config.PrintOptions();
|
||||
|
||||
if (t.joinable()) {
|
||||
t.join();
|
||||
}
|
||||
|
||||
return device.GetTransportName();
|
||||
}
|
||||
|
||||
string TestDeviceControlInConstructor(const string& transport)
|
||||
{
|
||||
TestDevice device(transport);
|
||||
|
@ -163,6 +204,14 @@ TEST_F(Config, SetConfig)
|
|||
EXPECT_EQ(transport, returnedTransport);
|
||||
}
|
||||
|
||||
TEST_F(Config, SetConfigWithPlugins)
|
||||
{
|
||||
string transport = "zeromq";
|
||||
string returnedTransport = TestDeviceSetConfigWithPlugins(transport);
|
||||
|
||||
EXPECT_EQ(transport, returnedTransport);
|
||||
}
|
||||
|
||||
TEST_F(Config, SetTransport)
|
||||
{
|
||||
string transport = "zeromq";
|
||||
|
|
Loading…
Reference in New Issue
Block a user