5#include <ChimeraTK/ExceptionDummyBackend.h>
6#include <ChimeraTK/SharedDummyBackend.h>
8#define BOOST_TEST_MODULE noInitialValueTest
16#include <ChimeraTK/BackendFactory.h>
17#include <ChimeraTK/Device.h>
19#include <boost/test/included/unit_test.hpp>
31 std::cout <<
"TestNoInitialValueTagChecks" << std::endl;
34 using ctk::ApplicationModule::ApplicationModule;
44 ~TagCheckApp()
override {
shutdown(); }
45 TestModule mod{
this,
"Module",
""};
48 auto accessorList = app.mod.getAccessorListRecursive();
50 for(
auto& var : accessorList) {
51 if(var.getName() ==
"pushNoIv" || var.getName() ==
"pollNoIv") {
54 if(var.getName() ==
"normalPush" || var.getName() ==
"normalPoll") {
63 std::cout <<
"TestNoInitialValueModuleEntersMainLoop" << std::endl;
66 using ctk::ApplicationModule::ApplicationModule;
73 std::atomic<bool> mainLoopEntered{
false};
76 mainLoopEntered =
true;
77 mainLoopEntered.notify_one();
83 ~NoInitApp()
override {
shutdown(); }
84 TestModule mod{
this,
"Module",
""};
98 BOOST_TEST(app.mod.pushNoIv.getVersionNumber() == ctk::VersionNumber{nullptr});
99 BOOST_TEST(app.mod.pollNoIv.getVersionNumber() == ctk::VersionNumber{nullptr});
100 BOOST_TEST(app.mod.normalPush.getVersionNumber() != ctk::VersionNumber{nullptr});
101 BOOST_TEST(app.mod.normalPoll.getVersionNumber() != ctk::VersionNumber{nullptr});
103 BOOST_TEST(app.mod.pushNoIv == 0);
104 BOOST_TEST(app.mod.pollNoIv == 0);
105 BOOST_TEST(app.mod.normalPush == 666);
106 BOOST_TEST(app.mod.normalPoll == 777);
108 app.mod.pushNoIv.read();
109 app.mod.pollNoIv.read();
111 BOOST_TEST(app.mod.pushNoIv == 42);
112 BOOST_TEST(app.mod.pollNoIv == 120);
119static constexpr const char* testMap =
"testNoInitVal.map";
120static constexpr const char* testDmap =
"testNoInitVal.dmap";
121static constexpr const char* backendCdd =
"(ExceptionDummy:1?map=testNoInitVal.map)";
123static void setupDeviceMap() {
124 std::ofstream dmapFile(testDmap);
125 dmapFile <<
"testDevice " << backendCdd << std::endl;
127 std::ofstream mapFile(testMap);
128 mapFile <<
"Module.noInit 0x00000001 0x00000000 0x00000004 1 32 0 1 RO" << std::endl;
129 mapFile <<
"Module.noReco 0x00000001 0x00000004 0x00000004 1 32 0 1 RW" << std::endl;
132static void cleanupDeviceMap() {
133 std::remove(testDmap);
134 std::remove(testMap);
140 std::cout <<
"TestNoInitialValueOnlyEntersWithBrokenDevice" << std::endl;
143 ctk::BackendFactory::getInstance().setDMapFilePath(testDmap);
147 boost::dynamic_pointer_cast<ctk::ExceptionDummy>(ctk::BackendFactory::getInstance().createBackend(
"testDevice"));
148 BOOST_REQUIRE(backend);
149 backend->throwExceptionOpen =
true;
151 using ctk::ApplicationModule::ApplicationModule;
160 std::atomic<bool> mainLoopEntered{
false};
169 mainLoopEntered =
true;
170 mainLoopEntered.notify_one();
176 ~OnlyNoInitApp()
override {
shutdown(); }
178 NoInitOnlyModule mod{
this,
"Module",
""};
196 std::cout <<
"TestWithOptimiseUnmappedVariables" << std::endl;
199 ctk::BackendFactory::getInstance().setDMapFilePath(testDmap);
203 boost::dynamic_pointer_cast<ctk::ExceptionDummy>(ctk::BackendFactory::getInstance().createBackend(
"testDevice"));
204 BOOST_REQUIRE(backend);
205 backend->throwExceptionOpen =
true;
207 using ctk::ApplicationModule::ApplicationModule;
216 std::atomic<bool> mainLoopEntered{
false};
226 mainLoopEntered =
true;
227 mainLoopEntered.notify_one();
233 ~OnlyNoInitApp()
override {
shutdown(); }
235 NoInitOnlyModule mod{
this,
"Module",
""};
242 app.optimiseUnmappedVariables({
"/Module/noInit",
"/Module/noReco"});
#define CHECK_EQUAL_TIMEOUT(left, right, maxMilliseconds)
void shutdown() override
This will remove the global pointer to the instance and allows creating another instance afterwards.
virtual void mainLoop()=0
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
bool write(ChimeraTK::VersionNumber versionNumber)=delete
Convenience class for output scalar accessors with return channel ("read back") (always UpdateMode::p...
Helper class to facilitate tests of applications based on ApplicationCore.
void runApplication() const
Start the application in testable mode.
void setScalarDefault(const ChimeraTK::RegisterPath &name, const T &value)
Set default value for scalar process variable.
InvalidityTracer application module.
constexpr char noInitialValueReadTag[]
System tag to mark an accessor which should be excluded from the initial value read during applicatio...
BOOST_AUTO_TEST_CASE(TestNoInitialValueTagChecks)