3#define BOOST_TEST_MODULE testVersionpropagation
9#include <ChimeraTK/ExceptionDummyBackend.h>
10#include <ChimeraTK/RegisterPath.h>
11#include <ChimeraTK/VersionNumber.h>
13#include <boost/test/included/unit_test.hpp>
22 BOOST_FIXTURE_TEST_SUITE(VersionPropagationPart1,
Fixture)
27 std::cout <<
"versionPropagation_testPolledRead" << std::endl;
28 auto moduleVersion = application.group1.pollModule.getCurrentVersionNumber();
29 [[maybe_unused]]
auto pollVariableVersion = pollVariable2.getVersionNumber();
31 application.group1.outputModule.setCurrentVersionNumber({});
32 outputVariable2.
write();
35 assert(pollVariable2.getVersionNumber() > pollVariableVersion);
36 BOOST_CHECK(moduleVersion == application.group1.pollModule.getCurrentVersionNumber());
42 std::cout <<
"versionPropagation_testPolledReadNonBlocking" << std::endl;
43 auto moduleVersion = application.group1.pollModule.getCurrentVersionNumber();
44 [[maybe_unused]]
auto pollVariableVersion = pollVariable2.getVersionNumber();
46 application.group1.outputModule.setCurrentVersionNumber({});
47 outputVariable2.write();
48 pollVariable2.readNonBlocking();
50 assert(pollVariable2.getVersionNumber() > pollVariableVersion);
51 BOOST_CHECK(moduleVersion == application.group1.pollModule.getCurrentVersionNumber());
57 std::cout <<
"versionPropagation_testPolledReadLatest" << std::endl;
58 auto moduleVersion = application.group1.pollModule.getCurrentVersionNumber();
59 [[maybe_unused]]
auto pollVariableVersion = pollVariable2.getVersionNumber();
61 application.group1.outputModule.setCurrentVersionNumber({});
62 outputVariable2.write();
63 pollVariable2.readLatest();
65 assert(pollVariable2.getVersionNumber() > pollVariableVersion);
66 BOOST_CHECK(moduleVersion == application.group1.pollModule.getCurrentVersionNumber());
72 std::cout <<
"versionPropagation_testPushTypeRead" << std::endl;
76 [[maybe_unused]] ctk::VersionNumber nextVersionNumber = {};
79 assert(pushVariable.getVersionNumber() > nextVersionNumber);
80 BOOST_CHECK(application.group1.pushModule.getCurrentVersionNumber() == pushVariable.getVersionNumber());
86 std::cout <<
"versionPropagation_testPushTypeReadNonBlocking" << std::endl;
89 auto pushInputVersionNumber = pushVariable.getVersionNumber();
92 BOOST_CHECK_EQUAL(pushVariable.readNonBlocking(),
false);
93 BOOST_CHECK(pushInputVersionNumber == pushVariable.getVersionNumber());
95 ctk::VersionNumber nextVersionNumber = {};
96 auto moduleVersion = application.group1.pushModule.getCurrentVersionNumber();
100 BOOST_CHECK(pushVariable.getVersionNumber() > nextVersionNumber);
103 BOOST_CHECK(application.group1.pushModule.getCurrentVersionNumber() == moduleVersion);
109 std::cout <<
"versionPropagation_testPushTypeReadLatest" << std::endl;
113 auto pushInputVersionNumber = pushVariable.getVersionNumber();
116 BOOST_CHECK_EQUAL(pushVariable.readLatest(),
false);
117 BOOST_CHECK(pushInputVersionNumber == pushVariable.getVersionNumber());
119 ctk::VersionNumber nextVersionNumber = {};
120 auto moduleVersion = application.group1.pushModule.getCurrentVersionNumber();
124 BOOST_CHECK(pushVariable.getVersionNumber() > nextVersionNumber);
127 BOOST_CHECK(application.group1.pushModule.getCurrentVersionNumber() == moduleVersion);
130 BOOST_AUTO_TEST_SUITE_END()
138 BOOST_FIXTURE_TEST_SUITE(VersionPropagationPart2,
EmptyFixture)
145 std::promise<void>
p;
156 std::promise<void>
p;
162 explicit TheTestApplication(
const std::string& name,
const std::unordered_set<std::string>& pmTags = {})
174 std::cout <<
"versionPropagation_testSetAndWrite" << std::endl;
178 app.
pm.
p.get_future().wait();
179 app.
om.
p.get_future().wait();
181 ChimeraTK::VersionNumber theVersion;
193 std::cout <<
"versionPropagation_testWriteIfDifferent" << std::endl;
197 app.
pm.
p.get_future().wait();
198 app.
om.
p.get_future().wait();
200 ChimeraTK::VersionNumber theVersion;
212 std::cout <<
"versionPropagation_testDisabledVersionProp" << std::endl;
215 test.runApplication();
216 app.pm.p.get_future().wait();
217 app.om.p.get_future().wait();
220 ctk::VersionNumber vnInputBeforeWrite = app.pm.pushInput.getVersionNumber();
221 ctk::VersionNumber vnModuleBeforeWrite = app.pm.getCurrentVersionNumber();
222 app.om.setCurrentVersionNumber({});
223 app.om.output.write();
224 app.pm.pushInput.read();
225 BOOST_CHECK(app.pm.pushInput.getVersionNumber() > vnInputBeforeWrite);
226 BOOST_CHECK(app.pm.getCurrentVersionNumber() == vnModuleBeforeWrite);
231 BOOST_AUTO_TEST_SUITE_END()
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 setCurrentVersionNumber(VersionNumber versionNumber) override
Set the current version number.
VersionNumber getCurrentVersionNumber() const override
Return the current version number which has been received with the last push-type read operation.
bool write(ChimeraTK::VersionNumber versionNumber)=delete
void writeIfDifferent(UserType newValue, VersionNumber versionNumber, DataValidity validity)=delete
void setAndWrite(UserType newValue, VersionNumber versionNumber)=delete
Helper class to facilitate tests of applications based on ApplicationCore.
void runApplication() const
Start the application in testable mode.
InvalidityTracer application module.
constexpr auto independentVersionTag
Special tag to designate that a push-input should not propagate VersionNumber updates to its owning m...
BOOST_AUTO_TEST_CASE(versionPropagation_testPolledRead)
Convenience class for output scalar accessors (always UpdateMode::push)
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.
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...
ChimeraTK::ScalarPushInput< int > pushInput
~TheTestApplication() override
TheTestApplication(const std::string &name, const std::unordered_set< std::string > &pmTags={})
#define CHECK_TIMEOUT(condition, maxMilliseconds)