Simplify structure in DeviceRunner and plugin classes

This commit is contained in:
Alexey Rybalchenko
2018-07-27 18:19:57 +02:00
committed by Dennis Klein
parent ee8afd7d2b
commit ef3eb5f83e
9 changed files with 54 additions and 55 deletions

View File

@@ -23,39 +23,39 @@ namespace mq
namespace test
{
inline auto control(std::shared_ptr<FairMQDevice> device) -> void
inline auto control(FairMQDevice& device) -> void
{
for (const auto event : {
FairMQDevice::INIT_DEVICE,
FairMQDevice::RESET_DEVICE,
FairMQDevice::END,
}) {
device->ChangeState(event);
if (event != FairMQDevice::END) device->WaitForEndOfState(event);
device.ChangeState(event);
if (event != FairMQDevice::END) device.WaitForEndOfState(event);
}
}
struct PluginServices : ::testing::Test {
PluginServices()
: mConfig()
, mDevice{std::make_shared<FairMQDevice>()}
, mServices{&mConfig, mDevice}
, mDevice()
, mServices(mConfig, mDevice)
, fRunStateMachineThread()
{
fRunStateMachineThread = std::thread(&FairMQDevice::RunStateMachine, mDevice.get());
mDevice->SetTransport("zeromq");
fRunStateMachineThread = std::thread(&FairMQDevice::RunStateMachine, &mDevice);
mDevice.SetTransport("zeromq");
}
~PluginServices()
{
if (mDevice->GetCurrentState() == FairMQDevice::IDLE) control(mDevice);
if (mDevice.GetCurrentState() == FairMQDevice::IDLE) control(mDevice);
if (fRunStateMachineThread.joinable()) {
fRunStateMachineThread.join();
}
}
FairMQProgOptions mConfig;
std::shared_ptr<FairMQDevice> mDevice;
FairMQDevice mDevice;
fair::mq::PluginServices mServices;
std::thread fRunStateMachineThread;
};

View File

@@ -39,9 +39,9 @@ TEST_F(PluginServices, OnlySingleController)
EXPECT_EQ(mServices.GetDeviceController(), string{"foo"});
// park device
mDevice->WaitForEndOfState(FairMQDevice::DEVICE_READY);
mDevice.WaitForEndOfState(FairMQDevice::DEVICE_READY);
mServices.ChangeDeviceState("foo", DeviceStateTransition::ResetDevice);
mDevice->WaitForEndOfState(FairMQDevice::RESET_DEVICE);
mDevice.WaitForEndOfState(FairMQDevice::RESET_DEVICE);
mServices.ChangeDeviceState("foo", DeviceStateTransition::End);
}
@@ -72,7 +72,7 @@ TEST_F(PluginServices, Control)
ASSERT_EQ(mServices.GetCurrentDeviceState(), DeviceState::DeviceReady);
mServices.ChangeDeviceState("foo", DeviceStateTransition::ResetDevice);
mDevice->WaitForEndOfState(FairMQDevice::RESET_DEVICE);
mDevice.WaitForEndOfState(FairMQDevice::RESET_DEVICE);
mServices.ChangeDeviceState("foo", DeviceStateTransition::End);
}

View File

@@ -24,31 +24,31 @@ namespace
using namespace std;
using namespace fair::mq;
auto control(shared_ptr<FairMQDevice> device) -> void
auto control(FairMQDevice& device) -> void
{
device->SetTransport("zeromq");
device.SetTransport("zeromq");
for (const auto event : {
FairMQDevice::INIT_DEVICE,
FairMQDevice::RESET_DEVICE,
FairMQDevice::END,
}) {
device->ChangeState(event);
if (event != FairMQDevice::END) device->WaitForEndOfState(event);
device.ChangeState(event);
if (event != FairMQDevice::END) device.WaitForEndOfState(event);
}
}
TEST(Plugin, Operators)
{
FairMQProgOptions config;
auto device = make_shared<FairMQDevice>();
PluginServices services{&config, device};
FairMQDevice device;
PluginServices services{config, device};
Plugin p1{"dds", {1, 0, 0}, "Foo Bar <foo.bar@test.net>", "https://git.test.net/dds.git", &services};
Plugin p2{"dds", {1, 0, 0}, "Foo Bar <foo.bar@test.net>", "https://git.test.net/dds.git", &services};
Plugin p3{"file", {1, 0, 0}, "Foo Bar <foo.bar@test.net>", "https://git.test.net/file.git", &services};
EXPECT_EQ(p1, p2);
EXPECT_NE(p1, p3);
thread t(control, device);
device->RunStateMachine();
thread t(control, std::ref(device));
device.RunStateMachine();
if (t.joinable()) {
t.join();
}
@@ -57,14 +57,14 @@ TEST(Plugin, Operators)
TEST(Plugin, OstreamOperators)
{
FairMQProgOptions config;
auto device = make_shared<FairMQDevice>();
PluginServices services{&config, device};
FairMQDevice device;
PluginServices services{config, device};
Plugin p1{"dds", {1, 0, 0}, "Foo Bar <foo.bar@test.net>", "https://git.test.net/dds.git", &services};
stringstream ss;
ss << p1;
EXPECT_EQ(ss.str(), string{"'dds', version '1.0.0', maintainer 'Foo Bar <foo.bar@test.net>', homepage 'https://git.test.net/dds.git'"});
thread t(control, device);
device->RunStateMachine();
thread t(control, std::ref(device));
device.RunStateMachine();
if (t.joinable()) {
t.join();
}

View File

@@ -25,25 +25,25 @@ using namespace boost::filesystem;
using namespace boost::program_options;
using namespace std;
auto control(shared_ptr<FairMQDevice> device) -> void
auto control(FairMQDevice& device) -> void
{
device->SetTransport("zeromq");
device.SetTransport("zeromq");
for (const auto event : {
FairMQDevice::INIT_DEVICE,
FairMQDevice::RESET_DEVICE,
FairMQDevice::END,
}) {
device->ChangeState(event);
if (event != FairMQDevice::END) device->WaitForEndOfState(event);
device.ChangeState(event);
if (event != FairMQDevice::END) device.WaitForEndOfState(event);
}
}
TEST(PluginManager, LoadPluginDynamic)
{
FairMQProgOptions config;
FairMQDevice device;
PluginManager mgr;
auto device = make_shared<FairMQDevice>();
mgr.EmplacePluginServices(&config, device);
mgr.EmplacePluginServices(config, device);
mgr.PrependSearchPath("./test");
@@ -63,8 +63,8 @@ TEST(PluginManager, LoadPluginDynamic)
mgr.ForEachPluginProgOptions([&count](const options_description& /*d*/){ ++count; });
ASSERT_EQ(count, 1);
thread t(control, device);
device->RunStateMachine();
thread t(control, std::ref(device));
device.RunStateMachine();
if (t.joinable()) {
t.join();
}
@@ -72,16 +72,16 @@ TEST(PluginManager, LoadPluginDynamic)
TEST(PluginManager, LoadPluginStatic)
{
FairMQDevice device;
PluginManager mgr;
auto device = make_shared<FairMQDevice>();
device->SetTransport("zeromq");
device.SetTransport("zeromq");
ASSERT_NO_THROW(mgr.LoadPlugin("s:control"));
FairMQProgOptions config;
config.SetValue<string>("control", "static");
config.SetValue("catch-signals", 0);
mgr.EmplacePluginServices(&config, device);
mgr.EmplacePluginServices(config, device);
ASSERT_NO_THROW(mgr.InstantiatePlugins());
@@ -96,7 +96,7 @@ TEST(PluginManager, LoadPluginStatic)
mgr.ForEachPluginProgOptions([&count](const options_description&){ ++count; });
ASSERT_EQ(count, 1);
device->RunStateMachine();
device.RunStateMachine();
mgr.WaitForPluginsToReleaseDeviceControl();
}