ChimeraTK-ApplicationCore 04.08.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) {
52
53 BOOST_CHECK_THROW(
54 {
55 app.initialise();
56 app.run();
57 },
58 ctk::logic_error);
59 }
60
61 /********************************************************************************************************************/
62 /* test case for two feeders */
63
64 template<typename T>
66 TestApplication3() : Application("testSuite") {}
67 ~TestApplication3() override { shutdown(); }
68
69 struct : ctk::ApplicationModule {
70 using ApplicationModule::ApplicationModule;
71
72 ctk::ScalarOutput<T> consumingPush{this, "/MyModule/readBack", "", ""};
73
74 void mainLoop() override {}
75 } testModule{this, ".", ""};
76
77 struct : ctk::ApplicationModule {
78 using ApplicationModule::ApplicationModule;
79
80 ctk::ScalarOutput<T> consumingPush2{this, "/MyModule/readBack", "", ""};
81
82 void mainLoop() override {}
83 } testModule2{this, ".", ""};
84 };
85
88
89 BOOST_CHECK_THROW(ctk::TestFacility tf(app, false), ctk::logic_error);
90 }
91
92 /********************************************************************************************************************/
93 /* test case for too many polling consumers */
94
96 TestApplication4() : Application("testSuite") {}
97 ~TestApplication4() override { shutdown(); }
98
100
101 struct : ctk::ApplicationModule {
102 using ApplicationModule::ApplicationModule;
103
104 ctk::ScalarPollInput<int> consumingPush{this, "/MyModule/readBack", "", ""};
105
106 void mainLoop() override {}
107 } testModule{this, ".", ""};
108
109 struct : ctk::ApplicationModule {
110 using ApplicationModule::ApplicationModule;
111
112 ctk::ScalarPollInput<int> consumingPush2{this, "/MyModule/readBack", "", ""};
113
114 void mainLoop() override {}
115 } testModule2{this, ".", ""};
116
117 ctk::DeviceModule dev{this, "Dummy0"};
118 };
119
120 BOOST_AUTO_TEST_CASE(testTooManyPollingConsumers) {
122
123 BOOST_CHECK_THROW(
124 {
125 app.initialise();
126 app.run();
127 },
128 ctk::logic_error);
129 }
130
131 /********************************************************************************************************************/
132 /* test case for different number of elements */
133
134 template<typename T>
136 TestApplication5() : Application("testSuite") {}
137 ~TestApplication5() override { shutdown(); }
138
139 struct : ctk::ApplicationModule {
140 using ApplicationModule::ApplicationModule;
141
142 ctk::ArrayOutput<T> feed{this, "/MyModule/readBack", "", 10, ""};
143
144 void mainLoop() override {}
145 } testModule{this, ".", ""};
146
147 struct : ctk::ApplicationModule {
148 using ApplicationModule::ApplicationModule;
149
150 ctk::ArrayPollInput<T> consume{this, "/MyModule/readBack", "", 20, ""};
151
152 void mainLoop() override {}
153 } testModule2{this, ".", ""};
154 };
155
156 BOOST_AUTO_TEST_CASE_TEMPLATE(testDifferentNrElements, T, TestTypes) {
158 BOOST_CHECK_THROW(ctk::TestFacility tf(app, false), ctk::logic_error);
159 }
160
161 /********************************************************************************************************************/
162 /* test case for zero-length elements that are not void */
163
164 template<typename T>
166 TestApplication6() : Application("testSuite") {}
167 ~TestApplication6() override { shutdown(); }
168
169 struct : ctk::ApplicationModule {
170 using ApplicationModule::ApplicationModule;
171
172 ctk::ArrayOutput<T> feed{this, "/MyModule/readBack", "", 0, ""};
173
174 void mainLoop() override {}
175 } testModule{this, ".", ""};
176
177 struct : ctk::ApplicationModule {
178 using ApplicationModule::ApplicationModule;
179
180 ctk::ArrayPollInput<T> consume{this, "/MyModule/readBack", "", 0, ""};
181
182 void mainLoop() override {}
183 } testModule2{this, ".", ""};
184 };
185
186 BOOST_AUTO_TEST_CASE_TEMPLATE(testDifferentZeroElementsNonVoid, T, TestTypes) {
188 BOOST_CHECK_THROW(ctk::TestFacility tf(app, false), ctk::logic_error);
189 }
190
191 /********************************************************************************************************************/
192 /* test cases for modules connecting itself, either directly or via a deep C++ hierarchy */
193
195 // An application module that will have its output connect to itself
196 using ctk::ApplicationModule::ApplicationModule;
197
198 ctk::ScalarOutput<int> out{this, "/Some/out", "", "Some output"};
199 ctk::ScalarPushInput<int> in{this, "/Some/out", "", "Some input"};
200
201 void mainLoop() override {}
202 };
203
205 using ctk::ApplicationModule::ApplicationModule;
206
208 using ctk::VariableGroup::VariableGroup;
209
211 using ctk::VariableGroup::VariableGroup;
212
214 using ctk::VariableGroup::VariableGroup;
215
217 using ctk::VariableGroup::VariableGroup;
218
219 ctk::ScalarOutput<int> out{this, "/Some/out", "", "Some output"};
220 } x{this, "Group", "description"};
221 } y{this, "Group", "description"};
222 } z{this, "Group", "description"};
223 } variableGroup{this, "Group", "Description"};
224
225 ctk::ScalarPushInput<int> in{this, "/Some/out", "", "Some input"};
226
227 void mainLoop() override {}
228 };
229
231 using Application::Application;
232
234 CircularConnectionModule theModule{this, "CircularModule", "Description"};
235 };
236
238 using Application::Application;
239
241 CircularConnectionModuleWithIntermediateGroup theModule{this, "CircularModuleWithIntermediate", "Description"};
242 };
243
244 BOOST_AUTO_TEST_CASE(testCircularModule) {
245 auto app = CircularConnectionApp("CircularConnection");
246 BOOST_CHECK_THROW(ctk::TestFacility tf{app}, ctk::logic_error);
247 }
248
249 BOOST_AUTO_TEST_CASE(testCircularModule2) {
250 // Test that connecting in the same module with some internal hierarchy still is caught
251 auto app = CircularConnectionApp2("CircularConnection");
252 BOOST_CHECK_THROW(ctk::TestFacility tf{app}, ctk::logic_error);
253 }
254} // namespace Tests::testIllegalNetworks
void run() override
Execute the module.
void initialise() override
void shutdown() override
This will remove the global pointer to the instance and allows creating another instance afterwards.
Convenience class for output array accessors (always UpdateMode::push)
Convenience class for input array accessors with UpdateMode::poll.
friend class Application
Definition ModuleGroup.h:47
Convenience class for output scalar accessors (always UpdateMode::push)
Convenience class for input scalar accessors with UpdateMode::poll.
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
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