ChimeraTK-ApplicationCore 04.06.00
Loading...
Searching...
No Matches
testIllegalNetworks.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#include "TestFacility.h"
5#include <future>
6
7#define BOOST_TEST_MODULE testIllegalNetworks
8
9#include "Application.h"
10#include "ApplicationModule.h"
11#include "ArrayAccessor.h"
12#include "DeviceModule.h"
13#include "ScalarAccessor.h"
14
15#include <ChimeraTK/BackendFactory.h>
16
17#include <boost/mpl/list.hpp>
18#include <boost/test/included/unit_test.hpp>
19
21
22 using namespace boost::unit_test_framework;
23 namespace ctk = ChimeraTK;
24
25 // list of user types the accessors are tested with
26 using TestTypes =
27 boost::mpl::list<int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, float, double, ctk::Boolean>;
28
29 /********************************************************************************************************************/
30 /* test case for two scalar accessors, feeder in poll mode and consumer in push
31 * mode (without trigger) */
32
34 TestApplication1() : Application("testSuite") {}
35 ~TestApplication1() override { shutdown(); }
36
38
39 struct : ctk::ApplicationModule {
40 using ApplicationModule::ApplicationModule;
41
42 ctk::ScalarPushInput<int> consumingPush{this, "/MyModule/readBack", "", ""};
43
44 void mainLoop() override {}
45 } testModule{(this), ".", ""}; // extra parentheses are for doxygen...
46
47 ctk::DeviceModule dev{this, "Dummy0"};
48 };
49
50 BOOST_AUTO_TEST_CASE(testTwoScalarPollPushAccessors) {
53
54 BOOST_CHECK_THROW(
55 {
56 app.initialise();
57 app.run();
58 },
59 ctk::logic_error);
60 }
61
62 /********************************************************************************************************************/
63 /* test case for two feeders */
64
65 template<typename T>
68 ~TestApplication3() override { shutdown(); }
69
70 struct : ctk::ApplicationModule {
71 using ApplicationModule::ApplicationModule;
72
73 ctk::ScalarOutput<T> consumingPush{this, "/MyModule/readBack", "", ""};
74
75 void mainLoop() override {}
76 } testModule{this, ".", ""};
77
78 struct : ctk::ApplicationModule {
79 using ApplicationModule::ApplicationModule;
80
81 ctk::ScalarOutput<T> consumingPush2{this, "/MyModule/readBack", "", ""};
82
83 void mainLoop() override {}
84 } testModule2{this, ".", ""};
85 };
86
89
90 BOOST_CHECK_THROW(ctk::TestFacility tf(app, false), ctk::logic_error);
91 }
92
93 /********************************************************************************************************************/
94 /* test case for too many polling consumers */
95
98 ~TestApplication4() override { shutdown(); }
99
101
102 struct : ctk::ApplicationModule {
103 using ApplicationModule::ApplicationModule;
104
105 ctk::ScalarPollInput<int> consumingPush{this, "/MyModule/readBack", "", ""};
106
107 void mainLoop() override {}
108 } testModule{this, ".", ""};
109
110 struct : ctk::ApplicationModule {
111 using ApplicationModule::ApplicationModule;
112
113 ctk::ScalarPollInput<int> consumingPush2{this, "/MyModule/readBack", "", ""};
114
115 void mainLoop() override {}
116 } testModule2{this, ".", ""};
117
118 ctk::DeviceModule dev{this, "Dummy0"};
119 };
120
121 BOOST_AUTO_TEST_CASE(testTooManyPollingConsumers) {
123
124 BOOST_CHECK_THROW(
125 {
126 app.initialise();
127 app.run();
128 },
129 ctk::logic_error);
130 }
131
132 /********************************************************************************************************************/
133 /* test case for different number of elements */
134
135 template<typename T>
138 ~TestApplication5() override { shutdown(); }
139
140 struct : ctk::ApplicationModule {
141 using ApplicationModule::ApplicationModule;
142
143 ctk::ArrayOutput<T> feed{this, "/MyModule/readBack", "", 10, ""};
144
145 void mainLoop() override {}
146 } testModule{this, ".", ""};
147
148 struct : ctk::ApplicationModule {
149 using ApplicationModule::ApplicationModule;
150
151 ctk::ArrayPollInput<T> consume{this, "/MyModule/readBack", "", 20, ""};
152
153 void mainLoop() override {}
154 } testModule2{this, ".", ""};
155 };
156
157 BOOST_AUTO_TEST_CASE_TEMPLATE(testDifferentNrElements, T, TestTypes) {
159 BOOST_CHECK_THROW(ctk::TestFacility tf(app, false), ctk::logic_error);
160 }
161
162 /********************************************************************************************************************/
163 /* test case for zero-length elements that are not void */
164
165 template<typename T>
168 ~TestApplication6() override { shutdown(); }
169
170 struct : ctk::ApplicationModule {
171 using ApplicationModule::ApplicationModule;
172
173 ctk::ArrayOutput<T> feed{this, "/MyModule/readBack", "", 0, ""};
174
175 void mainLoop() override {}
176 } testModule{this, ".", ""};
177
178 struct : ctk::ApplicationModule {
179 using ApplicationModule::ApplicationModule;
180
181 ctk::ArrayPollInput<T> consume{this, "/MyModule/readBack", "", 0, ""};
182
183 void mainLoop() override {}
184 } testModule2{this, ".", ""};
185 };
186
187 BOOST_AUTO_TEST_CASE_TEMPLATE(testDifferentZeroElementsNonVoid, T, TestTypes) {
189 BOOST_CHECK_THROW(ctk::TestFacility tf(app, false), ctk::logic_error);
190 }
191
192 /********************************************************************************************************************/
193 /* test cases for modules connecting itself, either directly or via a deep C++ hierarchy */
194
196 // An application module that will have its output connect to itself
197 using ctk::ApplicationModule::ApplicationModule;
198
199 ctk::ScalarOutput<int> out{this, "/Some/out", "", "Some output"};
200 ctk::ScalarPushInput<int> in{this, "/Some/out", "", "Some input"};
201
202 void mainLoop() override {}
203 };
204
206 using ctk::ApplicationModule::ApplicationModule;
207
209 using ctk::VariableGroup::VariableGroup;
210
212 using ctk::VariableGroup::VariableGroup;
213
215 using ctk::VariableGroup::VariableGroup;
216
218 using ctk::VariableGroup::VariableGroup;
219
220 ctk::ScalarOutput<int> out{this, "/Some/out", "", "Some output"};
221 } x{this, "Group", "description"};
222 } y{this, "Group", "description"};
223 } z{this, "Group", "description"};
224 } variableGroup{this, "Group", "Description"};
225
226 ctk::ScalarPushInput<int> in{this, "/Some/out", "", "Some input"};
227
228 void mainLoop() override {}
229 };
230
232 using Application::Application;
233
235 CircularConnectionModule theModule{this, "CircularModule", "Description"};
236 };
237
239 using Application::Application;
240
242 CircularConnectionModuleWithIntermediateGroup theModule{this, "CircularModuleWithIntermediate", "Description"};
243 };
244
245 BOOST_AUTO_TEST_CASE(testCircularModule) {
246 auto app = CircularConnectionApp("CircularConnection");
247 BOOST_CHECK_THROW(ctk::TestFacility tf{app}, ctk::logic_error);
248 }
249
250 BOOST_AUTO_TEST_CASE(testCircularModule2) {
251 // Test that connecting in the same module with some internal hierarchy still is caught
252 auto app = CircularConnectionApp2("CircularConnection");
253 BOOST_CHECK_THROW(ctk::TestFacility tf{app}, ctk::logic_error);
254 }
255} // namespace Tests::testIllegalNetworks
void run() override
Execute the module.
void initialise() override
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.
friend class Application
Definition ModuleGroup.h:47
Convenience class for input scalar accessors with UpdateMode::push.
Helper class to set the DMAP file path.
Helper class to facilitate tests of applications based on ApplicationCore.
InvalidityTracer application module.
BOOST_AUTO_TEST_CASE(testTwoScalarPollPushAccessors)
BOOST_AUTO_TEST_CASE_TEMPLATE(testTwoFeeders, T, TestTypes)
boost::mpl::list< int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, float, double, ctk::Boolean > TestTypes
Convenience class for output array accessors (always UpdateMode::push)
Convenience class for input array accessors with UpdateMode::poll.
Convenience class for output scalar accessors (always UpdateMode::push)
Convenience class for input scalar accessors with UpdateMode::poll.
CircularConnectionModuleWithIntermediateGroup theModule
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
void mainLoop() override
To be implemented by the user: function called in a separate thread executing the main loop of the mo...
ctk::ApplicationModule testModule(this)
ctk::ApplicationModule ctk::DeviceModule dev
void mainLoop() override