mirror of
https://github.com/FairRootGroup/FairMQ.git
synced 2025-10-15 09:31:45 +00:00
Simplify structure in DeviceRunner and plugin classes
This commit is contained in:
committed by
Dennis Klein
parent
ee8afd7d2b
commit
ef3eb5f83e
@@ -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;
|
||||
};
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user