5#define BOOST_TEST_MODULE testDeviceAccessors
13#include <ChimeraTK/BackendFactory.h>
14#include <ChimeraTK/Device.h>
15#include <ChimeraTK/NDRegisterAccessor.h>
17#include <boost/mpl/list.hpp>
18#include <boost/test/included/unit_test.hpp>
20using namespace boost::unit_test_framework;
27#define CHECK_TIMEOUT(condition, maxMilliseconds) \
29 std::chrono::steady_clock::time_point t0 = std::chrono::steady_clock::now(); \
30 while(!(condition)) { \
31 bool timeout_reached = (std::chrono::steady_clock::now() - t0) > std::chrono::milliseconds(maxMilliseconds); \
32 BOOST_CHECK(!timeout_reached); \
33 if(timeout_reached) break; \
42 const std::unordered_set<std::string>& tags = {})
79 std::cout <<
"testFeedToDevice" << std::endl;
81 ChimeraTK::BackendFactory::getInstance().setDMapFilePath(
"test.dmap");
88 test.runApplication();
91 auto regacc = dev.getScalarRegisterAccessor<
int>(
"/MyModule/actuator");
97 BOOST_CHECK(regacc == 42);
100 BOOST_CHECK(regacc == 42);
103 BOOST_CHECK(regacc == 120);
110 std::cout <<
"testFeedToDeviceFanOut" << std::endl;
112 ChimeraTK::BackendFactory::getInstance().setDMapFilePath(
"test.dmap");
117 app.
dev2 = {&app,
"Dummy0wo"};
122 test.runApplication();
127 auto regac = dev.getScalarRegisterAccessor<
int>(
"/MyModule/actuator");
128 auto regrb = dev2.getScalarRegisterAccessor<
int>(
"/MyModule/actuator");
135 BOOST_CHECK(regac == 42);
137 BOOST_CHECK(regrb == 42);
140 BOOST_CHECK(regac == 42);
142 BOOST_CHECK(regrb == 42);
145 BOOST_CHECK(regac == 120);
147 BOOST_CHECK(regrb == 120);
154 std::cout <<
"testConsumeFromDevice" << std::endl;
156 ChimeraTK::BackendFactory::getInstance().setDMapFilePath(
"test.dmap");
167 test.setScalarDefault<
int>(
"/MyModule/actuator", 1);
168 test.runApplication();
172 auto regacc = dev.getScalarRegisterAccessor<
int>(
"/MyModule/readBack.DUMMY_WRITEABLE");
202 std::cout <<
"testConsumingFanOut" << std::endl;
204 ChimeraTK::BackendFactory::getInstance().setDMapFilePath(
"test.dmap");
217 test.setScalarDefault<
int>(
"/MyModule/actuator", 1);
220 auto regacc = dev.getScalarRegisterAccessor<
int>(
"/MyModule/readBack.DUMMY_WRITEABLE");
221 test.runApplication();
296 using ctk::ApplicationModule::ApplicationModule;
305 using ctk::ApplicationModule::ApplicationModule;
320 using ctk::ModuleGroup::ModuleGroup;
325 using ctk::ApplicationModule::ApplicationModule;
352 std::cout <<
"testDeviceModuleExceptions" << std::endl;
354 ChimeraTK::BackendFactory::getInstance().setDMapFilePath(
"test.dmap");
371 std::cout <<
"testDeviceModule" << std::endl;
373 ChimeraTK::BackendFactory::getInstance().setDMapFilePath(
"test.dmap");
377 test.runApplication();
382 auto actuator = dev.getScalarRegisterAccessor<
int>(
"MyModule/actuator");
383 auto& readback = actuator;
384 auto tests = dev.getScalarRegisterAccessor<
int>(
"Deeper/hierarchies/need/tests/DUMMY_WRITEABLE");
385 auto also = dev.getScalarRegisterAccessor<
int>(
"Deeper/hierarchies/also");
390 BOOST_CHECK_EQUAL(actuator, 42);
395 BOOST_CHECK_EQUAL(actuator, 12);
420 BOOST_CHECK_EQUAL(also, 42);
425 BOOST_CHECK_EQUAL(also, 12);
430 auto readback2 = dev2.getScalarRegisterAccessor<
int>(
"/MyModule/readBack/DUMMY_WRITEABLE");
435 test.stepApplication();
436 BOOST_CHECK_EQUAL(test.readScalar<
int>(
"/Deeper/readBack"), 543);
452 std::vector<ctk::DeviceModule>
cdevs;
461 std::cout <<
"testDeviceModuleMove" << std::endl;
462 ChimeraTK::BackendFactory::getInstance().setDMapFilePath(
"test.dmap");
466 app.
cdevs.push_back(std::move(app.
dev));
472 test.runApplication();
474 auto readBack = dummy0.getScalarRegisterAccessor<
int>(
"MyModule/readBack/DUMMY_WRITEABLE");
Model::RootProxy getModel()
Return the root of the application model.
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.
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.
bool hasReachedTestableMode()
Check whether this module has declared that it reached the testable mode.
void writeGraphViz(const std::string &filename, Args... args) const
Implementations of RootProxy.
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.
VariableGroup()=default
Default constructor: Allows late initialisation of VariableGroups (e.g.
InvalidityTracer application module.
BOOST_AUTO_TEST_CASE(testFeedToDevice)
Convenience class for output scalar accessors (always UpdateMode::push)
ctk::ScalarPollInput< int > tests
ctk::ScalarOutput< int > also
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 > trigger
Tests::testDeviceAccessors::Deeper2::Hierarchies::Need need
Tests::testDeviceAccessors::Deeper2::Hierarchies hierarchies
ctk::ScalarPollInput< int > tests
Tests::testDeviceAccessors::Deeper::Hierarchies::Need need
ctk::ScalarOutput< int > also
Tests::testDeviceAccessors::Deeper::Hierarchies hierarchies
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
~TestApplication3() override
std::atomic< size_t > initHandlerCallCount
std::vector< ctk::DeviceModule > cdevs
~TestApplication4() override
~TestApplication() override
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 > actuator
ctk::ScalarPollInput< int > readback
ctk::ScalarPollInput< int > consumingPoll
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
TestModule(ctk::ModuleGroup *owner, const std::string &name, const std::string &description, const std::unordered_set< std::string > &tags={})
void prepare() override
Prepare the execution of the module.
ctk::ScalarPushInput< int > consumingPush
ctk::ScalarOutput< int > feedingToDevice
ctk::ScalarPushInput< int > consumingPush2