3#define BOOST_TEST_MODULE testInitialValues
12#include <ChimeraTK/BackendFactory.h>
13#include <ChimeraTK/Device.h>
14#include <ChimeraTK/DummyRegisterAccessor.h>
15#include <ChimeraTK/ExceptionDummyBackend.h>
17#include <boost/mpl/list.hpp>
18#include <boost/test/included/unit_test.hpp>
47 using namespace boost::unit_test_framework;
52 template<
class INPUT_TYPE>
55 INPUT_TYPE
input{
this,
"/REG1",
"",
""};
83 template<
class APPLICATION_TYPE>
87 ChimeraTK::BackendFactory::getInstance().createBackend(APPLICATION_TYPE::ExceptionDummyCDD1))) {}
99 BOOST_AUTO_TEST_SUITE(testInitialValuesInputsOfApplicationCore_D_8)
107 std::cout <<
"=== testInitValueAtDevice8bi " <<
typeid(APPLICATION_TYPE).name() <<
" ===" << std::endl;
108 std::chrono::time_point<std::chrono::steady_clock> start, end;
111 start = std::chrono::steady_clock::now();
113 dummyToStopTimeUntilOpen.
application.inputModule.p.get_future().wait();
114 std::this_thread::sleep_for(std::chrono::milliseconds(10));
115 end = std::chrono::steady_clock::now();
124 auto elapsed_milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
125 BOOST_CHECK(d.
application.inputModule.enteredTheMainLoop ==
false);
126 std::this_thread::sleep_for(std::chrono::milliseconds(2 * elapsed_milliseconds));
127 BOOST_CHECK(d.
application.inputModule.enteredTheMainLoop ==
false);
128 BOOST_CHECK(d.
application.inputModule.input.getVersionNumber() == ctk::VersionNumber(std::nullptr_t()));
131 BOOST_CHECK(d.
application.inputModule.enteredTheMainLoop ==
true);
132 BOOST_CHECK(d.
application.inputModule.input.getVersionNumber() != ctk::VersionNumber(std::nullptr_t()));
141 std::promise<void>
p;
149 template<
class INPUT_TYPE>
166 std::cout <<
"=== testPollProcessArrayInitValueAtDevice8bii " <<
typeid(INPUT_TYPE).name()
167 <<
" === " << std::endl;
168 std::chrono::time_point<std::chrono::steady_clock> start, end;
172 start = std::chrono::steady_clock::now();
173 dummyToStopTimeForApplicationStart.
application.run();
174 dummyToStopTimeForApplicationStart.
application.scalarOutputModule.output.write();
175 dummyToStopTimeForApplicationStart.
application.inputModule.p.get_future().wait();
176 end = std::chrono::steady_clock::now();
181 BOOST_CHECK(d.
application.inputModule.enteredTheMainLoop ==
false);
182 std::this_thread::sleep_for(end - start);
183 BOOST_CHECK(d.
application.inputModule.enteredTheMainLoop ==
false);
184 BOOST_CHECK(d.
application.inputModule.input.getVersionNumber() == ctk::VersionNumber(std::nullptr_t()));
187 BOOST_CHECK(d.
application.inputModule.enteredTheMainLoop ==
true);
188 BOOST_CHECK(d.
application.inputModule.input.getVersionNumber() != ctk::VersionNumber(std::nullptr_t()));
194 template<
class INPUT_TYPE>
212 std::cout <<
"=== testConstantInitValueAtDevice8biii " <<
typeid(INPUT_TYPE).name() <<
" === " << std::endl;
216 d.
application.optimiseUnmappedVariables({
"/REG1"});
221 BOOST_CHECK(d.
application.inputModule.input.getVersionNumber() != ctk::VersionNumber(std::nullptr_t()));
222 if(d.
application.inputModule.input.getAccessModeFlags().has(ctk::AccessMode::wait_for_new_data)) {
223 BOOST_CHECK(d.
application.inputModule.input.readNonBlocking() ==
227 BOOST_CHECK(d.
application.inputModule.input.readNonBlocking() ==
true);
236 std::promise<void>
p;
246 std::promise<void>
p;
284 std::cout <<
"=== testPushInitValueAtDeviceD9 === " << std::endl;
285 std::chrono::time_point<std::chrono::steady_clock> start, end;
288 start = std::chrono::steady_clock::now();
292 std::this_thread::sleep_for(std::chrono::milliseconds(10));
293 end = std::chrono::steady_clock::now();
301 std::this_thread::sleep_for(2 * (end - start));
303 BOOST_CHECK(d.
pushVariable1.getVersionNumber() == ctk::VersionNumber(std::nullptr_t()));
307 BOOST_CHECK(d.
pushVariable1.getVersionNumber() != ctk::VersionNumber(std::nullptr_t()));
316 std::promise<void>
p;
325 constexpr static const char*
ExceptionDummyCDD1 =
"(ExceptionDummy:1?map=test-trigger-fanout-iv.map)";
339 boost::dynamic_pointer_cast<
ChimeraTK::ExceptionDummy>(
ChimeraTK::BackendFactory::getInstance().createBackend(
356 std::cout <<
"=== testTriggerFanOutInitValueAtDeviceD9 === " << std::endl;
357 std::chrono::time_point<std::chrono::steady_clock> start, end;
360 start = std::chrono::steady_clock::now();
365 std::this_thread::sleep_for(std::chrono::milliseconds(10));
366 end = std::chrono::steady_clock::now();
374 std::this_thread::sleep_for(2 * (end - start));
376 BOOST_CHECK(d.
pushVariable1.getVersionNumber() == ctk::VersionNumber(std::nullptr_t()));
381 BOOST_CHECK(d.
pushVariable1.getVersionNumber() != ctk::VersionNumber(std::nullptr_t()));
393 } reg1{
this,
".",
""};
395 std::promise<void>
p;
421 ChimeraTK::BackendFactory::getInstance().createBackend(
"(ExceptionDummy:1?map=test.map)"))) {}
434 std::cout <<
"=== testConstantD10InitialValue === " << std::endl;
440 dev.write<
int>(
"REG1", 1234);
452 ChimeraTK::DummyRegisterAccessor<int> reg1(
453 boost::dynamic_pointer_cast<ChimeraTK::DummyBackend>(dev.getBackend()).get(),
"",
"REG1");
455 auto lk = reg1.getBufferLock();
456 BOOST_CHECK(reg1 == 1234);
468 std::promise<void>
p;
504 std::cout <<
"=== testD1InitialValue === " << std::endl;
511 BOOST_CHECK(d.
pushVariable.dataValidity() == ctk::DataValidity::ok);
513 BOOST_CHECK(d.
outputVariable.dataValidity() == ctk::DataValidity::ok);
521 std::cout <<
"=== testD2InitialValue === " << std::endl;
528 BOOST_CHECK(d.
pushVariable.getVersionNumber() != ctk::VersionNumber(std::nullptr_t()));
529 BOOST_CHECK(d.
outputVariable.getVersionNumber() != ctk::VersionNumber(std::nullptr_t()));
537 std::cout <<
"=== testD3InitialValue === " << std::endl;
543 BOOST_CHECK(d.
pushVariable.dataValidity() == ctk::DataValidity::ok);
544 BOOST_CHECK(d.
outputVariable.dataValidity() == ctk::DataValidity::ok);
570 using NotifyingModule::NotifyingModule;
590 std::cout <<
"=== testD7_1_InitialValue === " << std::endl;
605 std::cout <<
"=== testD7_2_InitialValue === " << std::endl;
619 constexpr static const char*
CDD =
"(dummy:1?map=test.map)";
624 using NotifyingModule::NotifyingModule;
627 } readerModule{
this,
".",
""};
647 std::cout <<
"=== testD6_a1_InitialValue === " << std::endl;
650 BOOST_CHECK(d.
pushVariable.getVersionNumber() == ctk::VersionNumber(std::nullptr_t()));
658 BOOST_CHECK(d.
pushVariable.getVersionNumber() != ctk::VersionNumber(std::nullptr_t()));
663 constexpr static const char*
CDD1 =
"(dummy:1?map=one-register.map)";
664 constexpr static const char*
CDD2 =
"(dummy:2?map=test-ro.map)";
669 using NotifyingModule::NotifyingModule;
671 } readerModule{
this,
"ReaderModule",
""};
696 std::cout <<
"=== testD6_a2_InitialValue === " << std::endl;
702 dev2.write<
int>(
"REG1/DUMMY_WRITEABLE", 99);
706 BOOST_CHECK(d.
pushVariable.getVersionNumber() == ctk::VersionNumber(std::nullptr_t()));
709 BOOST_CHECK(dev.read<
int>(
"REG1") != 99);
720 constexpr static const char*
CDD1 =
"(dummy:1?map=one-register.map)";
721 constexpr static const char*
CDD2 =
"(dummy:2?map=test-async.map)";
726 using NotifyingModule::NotifyingModule;
728 } readerModule{
this,
"ReaderModule",
""};
748 std::cout <<
"=== testD6_a3_InitialValue === " << std::endl;
754 dev2.write<
int>(
"REG1/DUMMY_WRITEABLE", 99);
762 BOOST_CHECK(d.
pushVariable.getVersionNumber() != ctk::VersionNumber(std::nullptr_t()));
772 using NotifyingModule::NotifyingModule;
774 } readerModule{
this,
"ReaderModule",
""};
793 std::cout <<
"=== testD6_a4_InitialValue === " << std::endl;
799 BOOST_CHECK(d.
application.readerModule.enteredTheMainLoop ==
true);
801 BOOST_CHECK(d.
pushVariable.getVersionNumber() != ctk::VersionNumber(std::nullptr_t()));
807 using NotifyingModule::NotifyingModule;
813 constexpr static const char*
CDD =
"(dummy?map=test-ro.map)";
836 std::cout <<
"=== testD6_b_InitialValue === " << std::endl;
844 dev.write<
int>(
"REG1/DUMMY_WRITEABLE", 99);
848 BOOST_CHECK(d.
pollVariable.getVersionNumber() != ctk::VersionNumber(std::nullptr_t()));
859 using NotifyingModule::NotifyingModule;
861 } readerModule{
this,
"ReaderModule",
""};
880 std::cout <<
"=== testD6_c_InitialValue === " << std::endl;
888 dev.write<
int>(
"REG1/DUMMY_WRITEABLE", 99);
889 dev.getVoidRegisterAccessor(
"/DUMMY_INTERRUPT_3").write();
891 BOOST_CHECK(d.
application.readerModule.enteredTheMainLoop ==
true);
893 BOOST_CHECK(d.
pushVariable.getVersionNumber() != ctk::VersionNumber(std::nullptr_t()));
896 BOOST_AUTO_TEST_SUITE_END()
void run() override
Execute the module.
void optimiseUnmappedVariables(const std::set< std::string > &names) override
void shutdown() override
This will remove the global pointer to the instance and allows creating another instance afterwards.
ApplicationModule()=default
Default constructor: Allows late initialisation of modules (e.g.
bool write(ChimeraTK::VersionNumber versionNumber)=delete
Helper class to facilitate tests of applications based on ApplicationCore.
void writeScalar(const std::string &name, TYPE value)
Convenience function to write a scalar process variable in a single call.
VariableGroup()=default
Default constructor: Allows late initialisation of VariableGroups (e.g.
bool write(ChimeraTK::VersionNumber versionNumber)=delete
InvalidityTracer application module.
boost::mpl::list< PushDummyApplication, PollDummyApplication > DeviceTestApplicationTypes
Test Initial Values - Inputs of ApplicationModules InitialValuesInputsOfApplicationCore_D_8 "D....
BOOST_AUTO_TEST_CASE(testPushInitValueAtDeviceD9)
D 9 b for ThreadedFanOut initialValueThreadedFanOut_D_9_b.
boost::mpl::list< ctk::ScalarPollInput< int >, ctk::ScalarPushInput< int > > TestInputTypes
BOOST_AUTO_TEST_CASE_TEMPLATE(testInitValueAtDevice8bi, APPLICATION_TYPE, DeviceTestApplicationTypes)
For device variables the ExceptionHandlingDecorator freezes the variable until the device is availabl...
Convenience class for output scalar accessors (always UpdateMode::push)
Convenience class for output void (always UpdateMode::push)
~ConstantD10DummyApplication() override
ConstantD10DummyApplication()
static constexpr const char * ExceptionDummyCDD1
ConstantModule constantModule
ChimeraTK::DeviceModule device
ConstantD10DummyApplication application
ChimeraTK::TestFacility testFacitiy
ConstantD10InitialValueEceptionDummy()
boost::shared_ptr< ChimeraTK::ExceptionDummy > deviceBackend
~ConstantD10InitialValueEceptionDummy()
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
std::atomic_bool enteredTheMainLoop
ChimeraTK::ScalarPushInput< int > constant
void prepare() override
Prepare the execution of the module.
static constexpr const char * ExceptionDummyCDD1
ConstantTestApplication()
~ConstantTestApplication() override
InputModule< INPUT_TYPE > inputModule
PushD9DummyApplication application
~D9InitialValueEceptionDummy()
D9InitialValueEceptionDummy()
ChimeraTK::TestFacility testFacitiy
boost::shared_ptr< ChimeraTK::ExceptionDummy > deviceBackend
ChimeraTK::ScalarPushInput< int > & pushVariable1
ChimeraTK::ScalarRegisterAccessor< int > exceptionDummyRegister
ChimeraTK::ScalarPushInput< int > & pushVariable2
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
void prepare() override
Prepare the execution of the module.
std::atomic_bool enteredTheMainLoop
std::atomic_bool enteredThePrepareLoop
~PollDummyApplication() override
static constexpr const char * ExceptionDummyCDD1
InputModule< ctk::ScalarPollInput< int > > inputModule
ChimeraTK::DeviceModule device
ChimeraTK::ScalarPollInput< int > pollInput
~ProcessArryDummyApplication() override
static constexpr const char * ExceptionDummyCDD1
ProcessArryDummyApplication()
InputModule< INPUT_TYPE > inputModule
ScalarOutputModule scalarOutputModule
ChimeraTK::DeviceModule device
~PushD9DummyApplication() override
PushModuleD92 pushModuleD92
static constexpr const char * ExceptionDummyCDD1
PushModuleD91 pushModuleD91
static constexpr const char * ExceptionDummyCDD1
ChimeraTK::DeviceModule device
InputModule< ctk::ScalarPushInput< int > > inputModule
~PushDummyApplication() override
std::atomic_bool enteredTheMainLoop
ChimeraTK::ScalarPushInput< int > pushInput
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
std::atomic_bool enteredTheMainLoop
ChimeraTK::ScalarPushInput< int > pushInput
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
ChimeraTK::ScalarPushInput< int > reg1
ChimeraTK::ScalarPushInput< int > reg2
std::atomic_bool enteredTheMainLoop
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
ChimeraTK::ScalarOutput< int > output
ChimeraTK::ScalarPushInput< int > reg1
~Test6A1DummyApplication() override
ChimeraTK::DeviceModule device
Test6A1DummyApplication()
static constexpr const char * CDD
Test6A1InitialValueEceptionDummy()=default
ChimeraTK::TestFacility testFacitiy
ChimeraTK::ScalarPushInput< int > & pushVariable
~Test6A1InitialValueEceptionDummy()=default
Test6A1DummyApplication application
Test6A2DummyApplication()
static constexpr const char * CDD2
ChimeraTK::DeviceModule device
ChimeraTK::ScalarPushInput< int > reg1
static constexpr const char * CDD1
~Test6A2DummyApplication() override
ChimeraTK::DeviceModule device2
TriggerModule triggerModule
ChimeraTK::ScalarPushInput< int > & pushVariable
ChimeraTK::TestFacility testFacility
Test6A2InitialValueEceptionDummy()=default
Test6A2DummyApplication application
~Test6A2InitialValueEceptionDummy()=default
ChimeraTK::DeviceModule device
Test6A3DummyApplication()
~Test6A3DummyApplication() override
static constexpr const char * CDD1
static constexpr const char * CDD2
ChimeraTK::DeviceModule device2
ChimeraTK::ScalarPushInput< int > reg1
ChimeraTK::ScalarPushInput< int > & pushVariable
Test6A3DummyApplication application
Test6A3InitialValueEceptionDummy()=default
~Test6A3InitialValueEceptionDummy()=default
ChimeraTK::TestFacility testFacility
~Test6A4DummyApplication() override
ChimeraTK::ScalarPushInput< int > reg1
WriterModule writerModule
Test6A4DummyApplication()
~Test6A4InitialValueEceptionDummy()=default
Test6A4InitialValueEceptionDummy()=default
ChimeraTK::TestFacility testFacitiy
ChimeraTK::ScalarPushInput< int > & pushVariable
Test6A4DummyApplication application
ChimeraTK::DeviceModule device
static constexpr const char * CDD
~Test6BDummyApplication() override
Test6BInitialValueEceptionDummy()=default
~Test6BInitialValueEceptionDummy()=default
ChimeraTK::TestFacility testFacitiy
ChimeraTK::ScalarPollInput< int > & pollVariable
Test6BDummyApplication application
~Test6CDummyApplication() override
ChimeraTK::ScalarPushInput< int > reg1
ChimeraTK::DeviceModule device
static constexpr const char * ExceptionDummyCDD1
Test6CInitialValueEceptionDummy()=default
ChimeraTK::TestFacility testFacitiy
ChimeraTK::ScalarPushInput< int > & pushVariable
Test6CDummyApplication application
ChimeraTK::ScalarRegisterAccessor< int > exceptionDummyRegister
~Test6CInitialValueEceptionDummy()=default
ReaderModule readerModule
~Test7DummyApplication() override
WriterModule writerModule
ChimeraTK::DeviceModule device
static constexpr const char * ExceptionDummyCDD1
~TestDummyApplication() override
boost::shared_ptr< ChimeraTK::ExceptionDummy > deviceBackend
ChimeraTK::ScalarRegisterAccessor< int > exceptionDummyRegister
APPLICATION_TYPE application
~TestFixtureWithEceptionDummy()
TestFixtureWithEceptionDummy()
ChimeraTK::TestFacility testFacility
ChimeraTK::ScalarPushInput< int > & pushVariable
boost::shared_ptr< ChimeraTK::ExceptionDummy > deviceBackend
TestInitialValueExceptionDummy()
ChimeraTK::TestFacility testFacitiy
TestDummyApplication application
~TestInitialValueExceptionDummy()
ChimeraTK::ScalarOutput< int > & outputVariable
ChimeraTK::ScalarPushInput< int > pushInput
std::atomic_bool enteredTheMainLoop
ChimeraTK::ScalarOutput< int > output
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
~TriggerFanOutD9DummyApplication() override
TriggerFanOutD9DummyApplication()
PushModuleD91 pushModuleD91
ChimeraTK::DeviceModule device
TriggerModule triggerModule
PushModuleD92 pushModuleD92
static constexpr const char * ExceptionDummyCDD1
boost::shared_ptr< ChimeraTK::ExceptionDummy > deviceBackend
ChimeraTK::ScalarRegisterAccessor< int > exceptionDummyRegister
ChimeraTK::ScalarPushInput< int > & pushVariable2
ChimeraTK::ScalarPushInput< int > & pushVariable1
~TriggerFanOutInitialValueEceptionDummy()
TriggerFanOutD9DummyApplication application
ChimeraTK::TestFacility testFacitiy
TriggerFanOutInitialValueEceptionDummy()
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
ChimeraTK::VoidOutput trigger
std::atomic_bool enteredTheMainLoop
void prepare() override
Prepare the execution of the module.
ChimeraTK::ScalarOutput< int > output2
ChimeraTK::ScalarOutput< int > output1
std::atomic_bool enteredThePrepareLoop
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
std::atomic_bool enteredTheMainLoop
#define CHECK_TIMEOUT(condition, maxMilliseconds)