9#include <ChimeraTK/BackendFactory.h>
11#include <boost/mpl/list.hpp>
15#define BOOST_NO_EXCEPTIONS
16#define BOOST_TEST_MODULE testAppModuleConnections
17#include <boost/test/included/unit_test.hpp>
18#undef BOOST_NO_EXCEPTIONS
20using namespace boost::unit_test_framework;
26 using test_types = boost::mpl::list<int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, float, double>;
34 const std::unordered_set<std::string>& tags = {},
bool unregister =
false)
64 const std::unordered_set<std::string>& tags = {},
bool unregister =
false)
112 std::cout <<
"*** testTwoScalarPushAccessors<" <<
typeid(T).name() <<
">" << std::endl;
134 auto futRead = std::async(std::launch::async, [&app] { app.
testModuleConsume.consumingPush.read(); });
135 BOOST_CHECK(futRead.wait_for(std::chrono::milliseconds(200)) == std::future_status::timeout);
144 BOOST_CHECK(futRead.wait_for(std::chrono::milliseconds(2000)) == std::future_status::ready);
153 std::cout <<
"*** testFourScalarPushAccessors<" <<
typeid(T).name() <<
">" << std::endl;
193 auto futRead = std::async(std::launch::async, [&app] { app.
testModuleConsume.consumingPush.read(); });
194 auto futRead2 = std::async(std::launch::async, [&app] { app.
testModuleConsume.consumingPush2.read(); });
195 auto futRead3 = std::async(std::launch::async, [&app] { app.
testModuleConsume.consumingPush3.read(); });
196 BOOST_CHECK(futRead.wait_for(std::chrono::milliseconds(200)) == std::future_status::timeout);
197 BOOST_CHECK(futRead2.wait_for(std::chrono::milliseconds(1)) == std::future_status::timeout);
198 BOOST_CHECK(futRead3.wait_for(std::chrono::milliseconds(1)) == std::future_status::timeout);
209 BOOST_CHECK(futRead.wait_for(std::chrono::milliseconds(2000)) == std::future_status::ready);
210 BOOST_CHECK(futRead2.wait_for(std::chrono::milliseconds(2000)) == std::future_status::ready);
211 BOOST_CHECK(futRead3.wait_for(std::chrono::milliseconds(2000)) == std::future_status::ready);
222 std::cout <<
"*** testTwoScalarPushPollAccessors<" <<
typeid(T).name() <<
">" << std::endl;
262 std::cout <<
"*** testTwoArrayAccessors<" <<
typeid(T).name() <<
">" << std::endl;
275 BOOST_CHECK(app.
testModuleFeed.feedingArray.getNElements() == 10);
282 for(
unsigned int i = 0; i < 10; ++i) {
286 BOOST_CHECK(val == 0);
290 BOOST_CHECK(val == 0);
293 for(
unsigned int i = 0; i < 10; ++i) {
299 auto futRead = std::async(std::launch::async, [&app] { app.
testModuleConsume.consumingPushArray.read(); });
300 BOOST_CHECK(futRead.wait_for(std::chrono::milliseconds(200)) == std::future_status::timeout);
302 for(
unsigned int i = 0; i < 10; ++i) {
307 for(
unsigned int i = 0; i < 10; ++i) {
313 BOOST_CHECK(futRead.wait_for(std::chrono::milliseconds(2000)) == std::future_status::ready);
314 for(
unsigned int i = 0; i < 10; ++i) {
323 std::cout <<
"*** testPseudoArray<" <<
typeid(T).name() <<
">" << std::endl;
350 const std::unordered_set<std::string>& tags = {})
383 std::cout <<
"*** testConstants<" <<
typeid(T).name() <<
">" << std::endl;
391 BOOST_TEST(app.
testModule.consumingPush == 66);
392 BOOST_TEST(app.
testModule.consumingPoll == 77);
393 BOOST_TEST(boost::starts_with(std::string(app.
testModule.myStringConstant),
"66"));
395 BOOST_TEST(app.
testModule.consumingPush.readNonBlocking() ==
false);
399 BOOST_TEST(app.
testModule.consumingPoll == 77);
407 ctk::ModuleGroup* owner,
const std::string& name,
const std::string& description,
bool unregister =
false)
441 std::cout <<
"*** testSelfUnregisteringModule" << std::endl;
448 auto& pvm = *tf.getPvManager();
449 BOOST_TEST(pvm.hasProcessVariable(
"a/out"));
450 BOOST_TEST(pvm.hasProcessVariable(
"a/in"));
451 BOOST_TEST(!pvm.hasProcessVariable(
"b/out"));
452 BOOST_TEST(!pvm.hasProcessVariable(
"b/in"));
453 BOOST_TEST(pvm.hasProcessVariable(
"c/out"));
454 BOOST_TEST(pvm.hasProcessVariable(
"c/in"));
456 auto aout = tf.getScalar<
int>(
"a/out");
457 auto ain = tf.getScalar<
int>(
"a/in");
458 auto cout = tf.getScalar<
int>(
"c/out");
459 auto cin = tf.getScalar<
int>(
"c/in");
461 tf.setScalarDefault(
"a/in", 1000);
462 tf.setScalarDefault(
"c/in", 2000);
466 BOOST_TEST(aout == 1001);
467 BOOST_TEST(cout == 2001);
470 tf.stepApplication();
471 BOOST_TEST(aout.readNonBlocking());
472 BOOST_TEST(!cout.readNonBlocking());
473 BOOST_TEST(aout == 43);
475 cin.setAndWrite(120);
476 tf.stepApplication();
477 BOOST_TEST(!aout.readNonBlocking());
478 BOOST_TEST(cout.readNonBlocking());
479 BOOST_TEST(cout == 121);
void debugMakeConnections()
Enable debug output for the ConnectionMaker.
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.
std::string constant(T value)
Create a variable name which will be automatically connected with a constant value.
void unregisterModule(Module *module) override
Unregister another module as a sub-module.
void readAll(bool includeReturnChannels=false)
Read all readable variables in the group.
void disable()
Disable the module such that it is not part of the Application.
void writeAll(bool includeReturnChannels=false)
Just call write() on all writable variables in the group.
Helper class to facilitate tests of applications based on ApplicationCore.
InvalidityTracer application module.
boost::mpl::list< int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, float, double > test_types
BOOST_AUTO_TEST_CASE(testSelfUnregisteringModule)
BOOST_AUTO_TEST_CASE_TEMPLATE(testTwoScalarPushAccessors, T, test_types)
Convenience class for output array accessors (always UpdateMode::push)
Convenience class for output scalar accessors (always UpdateMode::push)
ConstantTestApplication()
~ConstantTestApplication() override
ConstantTestModule< T > testModule
void prepare() override
Prepare the execution of the module.
ctk::ScalarPollInput< T > consumingPoll
ctk::ScalarPollInput< std::string > myStringConstant
ConstantTestModule(ctk::ModuleGroup *owner, const std::string &name, const std::string &description, const std::unordered_set< std::string > &tags={})
ctk::ScalarPushInput< T > consumingPush
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
boost::barrier mainLoopStarted
ctk::ScalarPushInput< int > in
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 > out
SelfUnregisteringModule(ctk::ModuleGroup *owner, const std::string &name, const std::string &description, bool unregister=false)
TestAppSelfUnregisteringModule()
SelfUnregisteringModule c
~TestAppSelfUnregisteringModule() override
SelfUnregisteringModule b
SelfUnregisteringModule a
~TestApplication() override
TestModuleConsume< T > testModuleConsume
TestModuleFeed< T > testModuleFeed
void prepare() override
Prepare the execution of the module.
TestModuleConsume(ctk::ModuleGroup *owner, const std::string &name, const std::string &description, const std::unordered_set< std::string > &tags={}, bool unregister=false)
ctk::ArrayPushInput< T > consumingPushArray
ctk::ScalarPushInput< T > consumingPush2
ctk::ScalarPollInput< T > consumingPoll
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
ctk::ScalarPushInput< T > consumingPush3
boost::barrier mainLoopStarted
ctk::ScalarPushInput< T > consumingPush
ctk::ArrayOutput< T > feedingArray
ctk::ArrayOutput< T > feedingPseudoArray
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
ctk::ScalarOutput< T > feedingPush
TestModuleFeed(ctk::ModuleGroup *owner, const std::string &name, const std::string &description, const std::unordered_set< std::string > &tags={}, bool unregister=false)
boost::barrier mainLoopStarted
void prepare() override
Prepare the execution of the module.