From 5271d4236e142b32d500ef3ffa4740faa05719b7 Mon Sep 17 00:00:00 2001 From: Alexey Rybalchenko Date: Wed, 12 Jun 2019 12:53:11 +0200 Subject: [PATCH] Add additional test for running device with plugins without DeviceRunner --- fairmq/DeviceRunner.cxx | 28 +++++++++++------------ fairmq/DeviceRunner.h | 2 +- fairmq/ProgOptions.cxx | 6 ++--- fairmq/ProgOptions.h | 6 ++--- test/device/_config.cxx | 49 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 70 insertions(+), 21 deletions(-) diff --git a/fairmq/DeviceRunner.cxx b/fairmq/DeviceRunner.cxx index 465997bf..c605ec84 100644 --- a/fairmq/DeviceRunner.cxx +++ b/fairmq/DeviceRunner.cxx @@ -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("severity"); - string logFile = fConfig.GetProperty("log-to-file"); - string logFileSeverity = fConfig.GetProperty("file-severity"); - bool color = fConfig.GetProperty("color"); + string severity = config.GetProperty("severity"); + string logFile = config.GetProperty("log-to-file"); + string logFileSeverity = config.GetProperty("file-severity"); + bool color = config.GetProperty("color"); - string verbosity = fConfig.GetProperty("verbosity"); + string verbosity = config.GetProperty("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; } diff --git a/fairmq/DeviceRunner.h b/fairmq/DeviceRunner.h index 4e6a1267..1ff011e6 100644 --- a/fairmq/DeviceRunner.h +++ b/fairmq/DeviceRunner.h @@ -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(); diff --git a/fairmq/ProgOptions.cxx b/fairmq/ProgOptions.cxx index 67cb8319..be8daabc 100644 --- a/fairmq/ProgOptions.cxx +++ b/fairmq/ProgOptions.cxx @@ -363,12 +363,12 @@ void ProgOptions::AddChannel(const string& name, const FairMQChannel& channel) SetVarMapValue(string(prefix + "autoBind"), channel.GetAutoBind()); } -void ProgOptions::PrintHelp() +void ProgOptions::PrintHelp() const { cout << fAllOptions << endl; } -void ProgOptions::PrintOptions() +void ProgOptions::PrintOptions() const { map mapinfo; @@ -412,7 +412,7 @@ void ProgOptions::PrintOptions() LOG(debug) << ss.str(); } -void ProgOptions::PrintOptionsRaw() +void ProgOptions::PrintOptionsRaw() const { const vector>& options = fAllOptions.options(); diff --git a/fairmq/ProgOptions.h b/fairmq/ProgOptions.h index beba33bf..0a59b310 100644 --- a/fairmq/ProgOptions.h +++ b/fairmq/ProgOptions.h @@ -144,9 +144,9 @@ class ProgOptions fEvents.Unsubscribe(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; } diff --git a/test/device/_config.cxx b/test/device/_config.cxx index 4dc5c933..e6d75bfa 100644 --- a/test/device/_config.cxx +++ b/test/device/_config.cxx @@ -7,6 +7,7 @@ ********************************************************************************/ #include +#include #include #include @@ -125,6 +126,46 @@ class Config : public ::testing::Test return device.GetTransportName(); } + string TestDeviceSetConfigWithPlugins(const string& transport) + { + fair::mq::ProgOptions config; + + vector 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";