ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
testFanoutConnections.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2// SPDX-License-Identifier: LGPL-3.0-or-later
3#define BOOST_TEST_MODULE testFanoutConnections
4
5#include "Application.h"
6#include "ApplicationModule.h"
7#include "DeviceModule.h"
8#include "ScalarAccessor.h"
9#include "TestFacility.h"
10
11#include <ChimeraTK/ExceptionDummyBackend.h>
12
13#include <boost/mpl/list.hpp>
14#include <boost/test/included/unit_test.hpp>
15
17
18 namespace ctk = ChimeraTK;
19
21 using ctk::ApplicationModule::ApplicationModule;
22 ctk::ScalarPushInput<int> moduleTrigger{this, "moduleTrigger", "", ""};
23
24 ctk::ScalarPollInput<int> i3{this, "i3", "", ""};
25
26 ctk::ScalarOutput<int> moduleOutput{this, "moduleOutput", "", ""};
27
28 void mainLoop() override {
29 while(true) {
30 moduleTrigger.read();
31
32 i3.readLatest();
33
34 moduleOutput = int(i3);
35
36 writeAll();
37 }
38 }
39 };
40
41 // FIXME: This test is probably already covered by one of the other test cases
42 // What it previously tested, a different connection order of device and application to CS, is
43 // no longer possible.
44 //
45 // the connection code has to create a consuming fan out because m1.i3 is a poll type consumer,
46 // and a trigger fan out because m1.i1 only has one push type consumer in the CS
48 TestApplication1() : Application("testApp") {}
49 ~TestApplication1() override { shutdown(); }
50
51 constexpr static char const* dummyCDD1 = "(dummy?map=testDataValidity1.map)";
52
53 TestModule1 m1{this, "m1", ""};
54 ctk::DeviceModule device{this, dummyCDD1, "/deviceTrigger"};
55 };
56
57 BOOST_AUTO_TEST_CASE(testConnectConsumingFanout) {
58 TestApplication1 theApp;
59 ctk::TestFacility testFacility{theApp};
61
62 // write initial values to the dummy before starting the application
63 dummy.open();
64 dummy.write("m1/i1/DUMMY_WRITEABLE", 12);
65 dummy.write("m1/i3/DUMMY_WRITEABLE", 32);
66
67 testFacility.runApplication();
68
69 BOOST_CHECK_EQUAL(testFacility.readScalar<int>("m1/i1"), 12);
70 BOOST_CHECK_EQUAL(testFacility.readScalar<int>("m1/i3"), 32);
71
72 // check that the trigger only affects i1
73 dummy.write("m1/i1/DUMMY_WRITEABLE", 13);
74 dummy.write("m1/i3/DUMMY_WRITEABLE", 33);
75
76 testFacility.getVoid("deviceTrigger").write();
77 testFacility.stepApplication();
78
79 BOOST_CHECK_EQUAL(testFacility.readScalar<int>("m1/i1"), 13);
80 BOOST_CHECK_EQUAL(testFacility.readScalar<int>("m1/i3"), 32);
81
82 // check that the module trigger updates i3
83 BOOST_CHECK_EQUAL(testFacility.readScalar<int>("m1/moduleOutput"), 0);
84
85 dummy.write("m1/i1/DUMMY_WRITEABLE", 14);
86 dummy.write("m1/i3/DUMMY_WRITEABLE", 34);
87
88 testFacility.writeScalar<int>("m1/moduleTrigger", 1);
89 testFacility.stepApplication();
90
91 BOOST_CHECK_EQUAL(testFacility.readScalar<int>("m1/i1"), 13);
92 BOOST_CHECK_EQUAL(testFacility.readScalar<int>("m1/i3"), 34);
93 BOOST_CHECK_EQUAL(testFacility.readScalar<int>("m1/moduleOutput"), 34);
94 }
95
96} // namespace Tests::testFanoutConnections
void shutdown() override
This will remove the global pointer to the instance and allows creating another instance afterwards.
friend class Application
Definition ModuleGroup.h:47
void writeAll(bool includeReturnChannels=false)
Just call write() on all writable variables in the group.
Definition Module.cc:157
Convenience class for input scalar accessors with UpdateMode::push.
Helper class to facilitate tests of applications based on ApplicationCore.
InvalidityTracer application module.
BOOST_AUTO_TEST_CASE(testConnectConsumingFanout)
Convenience class for output scalar accessors (always UpdateMode::push)
Convenience class for input scalar accessors with UpdateMode::poll.
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...