Add additional test for running device with plugins without DeviceRunner

This commit is contained in:
Alexey Rybalchenko 2019-06-12 12:53:11 +02:00 committed by Dennis Klein
parent 4281d7b27e
commit 5271d4236e
5 changed files with 70 additions and 21 deletions

View File

@ -24,27 +24,27 @@ DeviceRunner::DeviceRunner(int argc, char* const argv[], bool printLogo)
, fEvents() , fEvents()
{} {}
bool DeviceRunner::HandleGeneralOptions() bool DeviceRunner::HandleGeneralOptions(const fair::mq::ProgOptions& config, bool printLogo)
{ {
if (fConfig.Count("help")) { if (config.Count("help")) {
fConfig.PrintHelp(); config.PrintHelp();
return false; return false;
} }
if (fConfig.Count("print-options")) { if (config.Count("print-options")) {
fConfig.PrintOptionsRaw(); config.PrintOptionsRaw();
return false; return false;
} }
if (fConfig.Count("print-channels") || fConfig.Count("version")) { if (config.Count("print-channels") || config.Count("version")) {
fair::Logger::SetConsoleSeverity("nolog"); fair::Logger::SetConsoleSeverity("nolog");
} else { } else {
string severity = fConfig.GetProperty<string>("severity"); string severity = config.GetProperty<string>("severity");
string logFile = fConfig.GetProperty<string>("log-to-file"); string logFile = config.GetProperty<string>("log-to-file");
string logFileSeverity = fConfig.GetProperty<string>("file-severity"); string logFileSeverity = config.GetProperty<string>("file-severity");
bool color = fConfig.GetProperty<bool>("color"); bool color = config.GetProperty<bool>("color");
string verbosity = fConfig.GetProperty<string>("verbosity"); string verbosity = config.GetProperty<string>("verbosity");
fair::Logger::SetVerbosity(verbosity); fair::Logger::SetVerbosity(verbosity);
if (logFile != "") { if (logFile != "") {
@ -55,7 +55,7 @@ bool DeviceRunner::HandleGeneralOptions()
fair::Logger::SetConsoleSeverity(severity); fair::Logger::SetConsoleSeverity(severity);
} }
if (fPrintLogo) { if (printLogo) {
LOG(info) << endl LOG(info) << endl
<< " ______ _ _______ _________ " << endl << " ______ _ _______ _________ " << endl
<< " / ____/___ _(_)_______ |/ /_ __ \\ version " << FAIRMQ_GIT_VERSION << endl << " / ____/___ _(_)_______ |/ /_ __ \\ version " << FAIRMQ_GIT_VERSION << endl
@ -64,7 +64,7 @@ bool DeviceRunner::HandleGeneralOptions()
<< " /_/ \\__,_/_/_/ /_/ /_/ \\___\\_\\ " << FAIRMQ_LICENSE << " © " << FAIRMQ_COPYRIGHT << endl; << " /_/ \\__,_/_/_/ /_/ /_/ \\___\\_\\ " << FAIRMQ_LICENSE << " © " << FAIRMQ_COPYRIGHT << endl;
} }
fConfig.PrintOptions(); config.PrintOptions();
} }
return true; return true;
@ -122,7 +122,7 @@ auto DeviceRunner::Run() -> int
fConfig.ParseAll(fRawCmdLineArgs, true); fConfig.ParseAll(fRawCmdLineArgs, true);
if (!HandleGeneralOptions()) { if (!HandleGeneralOptions(fConfig)) {
return 0; return 0;
} }

View File

@ -56,7 +56,7 @@ class DeviceRunner
auto Run() -> int; auto Run() -> int;
auto RunWithExceptionHandlers() -> int; auto RunWithExceptionHandlers() -> int;
bool HandleGeneralOptions(); static bool HandleGeneralOptions(const fair::mq::ProgOptions& config, bool printLogo = true);
void SubscribeForConfigChange(); void SubscribeForConfigChange();
void UnsubscribeFromConfigChange(); void UnsubscribeFromConfigChange();

View File

@ -363,12 +363,12 @@ void ProgOptions::AddChannel(const string& name, const FairMQChannel& channel)
SetVarMapValue<bool>(string(prefix + "autoBind"), channel.GetAutoBind()); SetVarMapValue<bool>(string(prefix + "autoBind"), channel.GetAutoBind());
} }
void ProgOptions::PrintHelp() void ProgOptions::PrintHelp() const
{ {
cout << fAllOptions << endl; cout << fAllOptions << endl;
} }
void ProgOptions::PrintOptions() void ProgOptions::PrintOptions() const
{ {
map<string, ValInfo> mapinfo; map<string, ValInfo> mapinfo;
@ -412,7 +412,7 @@ void ProgOptions::PrintOptions()
LOG(debug) << ss.str(); LOG(debug) << ss.str();
} }
void ProgOptions::PrintOptionsRaw() void ProgOptions::PrintOptionsRaw() const
{ {
const vector<boost::shared_ptr<po::option_description>>& options = fAllOptions.options(); const vector<boost::shared_ptr<po::option_description>>& options = fAllOptions.options();

View File

@ -144,9 +144,9 @@ class ProgOptions
fEvents.Unsubscribe<fair::mq::PropertyChangeAsString, std::string>(subscriber); fEvents.Unsubscribe<fair::mq::PropertyChangeAsString, std::string>(subscriber);
} }
void PrintHelp(); void PrintHelp() const;
void PrintOptions(); void PrintOptions() const;
void PrintOptionsRaw(); void PrintOptionsRaw() const;
const boost::program_options::variables_map& GetVarMap() const { return fVarMap; } const boost::program_options::variables_map& GetVarMap() const { return fVarMap; }

View File

@ -7,6 +7,7 @@
********************************************************************************/ ********************************************************************************/
#include <FairMQDevice.h> #include <FairMQDevice.h>
#include <fairmq/DeviceRunner.h>
#include <fairmq/ProgOptions.h> #include <fairmq/ProgOptions.h>
#include <fairmq/Tools.h> #include <fairmq/Tools.h>
@ -125,6 +126,46 @@ class Config : public ::testing::Test
return device.GetTransportName(); 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) string TestDeviceControlInConstructor(const string& transport)
{ {
TestDevice device(transport); TestDevice device(transport);
@ -163,6 +204,14 @@ TEST_F(Config, SetConfig)
EXPECT_EQ(transport, returnedTransport); EXPECT_EQ(transport, returnedTransport);
} }
TEST_F(Config, SetConfigWithPlugins)
{
string transport = "zeromq";
string returnedTransport = TestDeviceSetConfigWithPlugins(transport);
EXPECT_EQ(transport, returnedTransport);
}
TEST_F(Config, SetTransport) TEST_F(Config, SetTransport)
{ {
string transport = "zeromq"; string transport = "zeromq";