3#define BOOST_TEST_MODULE testDataValidityPropagation
11#include <ChimeraTK/Device.h>
12#include <ChimeraTK/DummyRegisterAccessor.h>
13#include <ChimeraTK/ExceptionDummyBackend.h>
14#include <ChimeraTK/NDRegisterAccessor.h>
16#include <boost/mpl/list.hpp>
22#define BOOST_NO_EXCEPTIONS
23#include <boost/test/included/unit_test.hpp>
24#undef BOOST_NO_EXCEPTIONS
26using namespace boost::unit_test_framework;
36 using ctk::ApplicationModule::ApplicationModule;
51 using ctk::ApplicationModule::ApplicationModule;
86 ctk::ApplicationModule::incrementDataFaultCounter();
91 ctk::ApplicationModule::decrementDataFaultCounter();
98 using ctk::ApplicationModule::ApplicationModule;
117 using ctk::ApplicationModule::ApplicationModule;
132 template<
typename ModuleT>
137 ModuleT
mod{
this,
"m1",
""};
139 const std::string
dummyCdd{
"(ExceptionDummy?map=testDataValidityPropagation.map)"};
147 throw ChimeraTK::runtime_error(
"device is not ready.");
155 constexpr static char const*
ExceptionDummyCDD =
"(ExceptionDummy?map=testDataValidityPropagation2.map)";
200 auto i1 = test.
getScalar<
int>(
"/dev/i1");
206 BOOST_CHECK(i1.dataValidity() == ctk::DataValidity::faulty);
261 auto input = test.getScalar<
int>(
"/m1/i1");
262 auto result = test.getScalar<
int>(
"/m2/o1");
263 test.runApplication();
267 test.stepApplication();
269 test.stepApplication();
275 BOOST_CHECK(result.dataValidity() == ctk::DataValidity::faulty);
299 auto o0 = test.
getScalar<
int>(
"/m1/oNothing");
303 BOOST_CHECK(o0.readNonBlocking() ==
false);
305 BOOST_CHECK(o0.dataValidity() == ctk::DataValidity::faulty);
318 auto i1 = test.getScalar<
int>(
"/m1/i1");
319 test.runApplication();
320 assert(app.
mod.getDataValidity() == ctk::DataValidity::ok);
326 test.stepApplication();
327 i1.setDataValidity(ctk::DataValidity::faulty);
329 test.stepApplication();
330 BOOST_CHECK(app.
mod.incCalled == 1);
331 BOOST_CHECK(app.
mod.decCalled == 0);
334 BOOST_CHECK(app.
mod.getDataValidity() == ctk::DataValidity::faulty);
357 auto i1 = test.getScalar<
int>(
"/m1/i1");
359 test.runApplication();
362 i1.setDataValidity(ctk::DataValidity::faulty);
365 test.stepApplication();
367 BOOST_CHECK(app.
mod.incCalled == 1);
369 i1.setDataValidity(ctk::DataValidity::ok);
372 test.stepApplication();
374 BOOST_CHECK(app.
mod.decCalled == 1);
423 auto i1 = test.getScalar<
int>(
"/m1/i1");
424 auto o1 = test.getScalar<
int>(
"/m1/o1");
425 auto oconst = test.getScalar<
int>(
"/m1/oconst");
426 test.runApplication();
431 i1.setDataValidity(ctk::DataValidity::faulty);
434 test.stepApplication();
439 BOOST_CHECK(o1.dataValidity() == ctk::DataValidity::faulty);
441 BOOST_CHECK(oconst.readLatest() ==
false);
456 auto i1 = test.getScalar<
int>(
"/m1/i1");
457 test.runApplication();
459 test.stepApplication();
461 BOOST_CHECK(app.
mod.dataValidity2 ==
false);
464 i1.setDataValidity(ctk::DataValidity::faulty);
466 test.stepApplication();
468 BOOST_CHECK(app.
mod.dataValidity1 ==
false);
484 auto result1 = test.getScalar<
int>(
"dev/i3");
486 test.runApplication();
489 app.
m2.
o1.setDataValidity(ctk::DataValidity::faulty);
492 test.stepApplication();
494 BOOST_CHECK(result1.dataValidity() == ctk::DataValidity::faulty);
518 auto result1 = test.getScalar<
int>(
"/dev/i1");
519 auto result2 = test.getScalar<
int>(
"/dev/i3");
523 test.runApplication();
524 auto exceptionDummy = boost::dynamic_pointer_cast<ctk::ExceptionDummy>(dev.getBackend());
525 assert(exceptionDummy);
526 exceptionDummy->setValidity(
"/dev/i1", ctk::DataValidity::faulty);
529 test.stepApplication();
531 BOOST_CHECK(result1.dataValidity() == ctk::DataValidity::faulty);
533 BOOST_CHECK(result2.dataValidity() == ctk::DataValidity::ok);
void shutdown() override
This will remove the global pointer to the instance and allows creating another instance afterwards.
DataValidity getDataValidity() const override
Return the data validity flag.
void decrementDataFaultCounter() override
Decrement the fault counter and set the data validity flag to ok if the counter has reached 0.
void incrementDataFaultCounter() override
Set the data validity flag to fault and increment the fault counter.
ChimeraTK::ReadAnyGroup readAnyGroup()
Create a ChimeraTK::ReadAnyGroup for all readable variables in this Module.
void writeAll(bool includeReturnChannels=false)
Just call write() on all writable variables in the group.
bool write(ChimeraTK::VersionNumber versionNumber)=delete
Helper class to facilitate tests of applications based on ApplicationCore.
ChimeraTK::ScalarRegisterAccessor< T > getScalar(const ChimeraTK::RegisterPath &name) const
Obtain a scalar process variable from the application, which is published to the control system.
void runApplication() const
Start the application in testable mode.
InvalidityTracer application module.
BOOST_AUTO_TEST_CASE(testDataValidity_1_3)
1.3 If a device is in error state, all variables which are read from it shall be marked as 'faulty'.
Convenience class for output scalar accessors (always UpdateMode::push)
app with two chained modules, for testDataValidity_1_6
~TestApplication16() override
static void initialiseDev(ChimeraTK::Device &)
const std::string dummyCdd
std::atomic_bool deviceError
~TestApplication1() override
static constexpr char const * ExceptionDummyCDD
~TestApplication3() override
ctk::DeviceModule device1
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
ctk::ScalarPushInput< int > i1
ctk::ScalarOutput< int > oNothing
void prepare() override
Prepare the execution of the module.
ctk::ScalarPushInput< int > i1
ctk::ScalarOutput< int > oconst
void incrementDataFaultCounter() override
Set the data validity flag to fault and increment the fault counter.
void decrementDataFaultCounter() override
Decrement the fault counter and set the data validity flag to ok if the counter has reached 0.
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
ctk::ScalarOutput< int > o1
ctk::DataValidity outputValidity
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
ctk::ScalarPushInput< int > i1
ctk::ScalarOutput< int > o1
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...