ChimeraTK-DeviceAccess  03.18.00
testMathPluginDataValidity.cpp
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 
4 #define BOOST_TEST_DYN_LINK
5 #define BOOST_TEST_MODULE LMapMathPluginTest
6 #include <boost/test/unit_test.hpp>
7 using namespace boost::unit_test_framework;
8 
9 #include "Device.h"
10 #include "ExceptionDummyBackend.h"
11 
12 using namespace ChimeraTK;
13 
14 BOOST_AUTO_TEST_SUITE(LMathPluginDataValidityTestSuite)
15 
16 /**********************************************************************************************************************/
17 
18 BOOST_AUTO_TEST_CASE(testReadSync) {
20  device.open("(logicalNameMap?map=mathPlugin.xlmap)");
21 
22  auto accTarget = device.getScalarRegisterAccessor<int>("SimpleScalar");
23  auto accMathRead = device.getScalarRegisterAccessor<double>("SimpleScalarRead");
24 
25  accTarget.read();
26  BOOST_CHECK(accTarget.dataValidity() == ChimeraTK::DataValidity::ok);
27  accMathRead.read();
28  BOOST_CHECK(accMathRead.dataValidity() == ChimeraTK::DataValidity::ok);
29 
30  accTarget.setDataValidity(ChimeraTK::DataValidity::faulty);
31  accTarget.write();
32  accMathRead.read();
33  BOOST_CHECK(accMathRead.dataValidity() == ChimeraTK::DataValidity::faulty);
34 
35  accTarget.setDataValidity(ChimeraTK::DataValidity::ok);
36  accTarget.write();
37  accMathRead.read();
38  BOOST_CHECK(accMathRead.dataValidity() == ChimeraTK::DataValidity::ok);
39 }
40 
41 /**********************************************************************************************************************/
42 
45  device.open("(logicalNameMap?map=mathPlugin.xlmap)");
46 
47  auto accTarget = device.getScalarRegisterAccessor<int>("SimpleScalar");
48  auto accMathWrite = device.getScalarRegisterAccessor<double>("SimpleScalarWrite");
49 
50  accTarget.read();
51  BOOST_CHECK(accTarget.dataValidity() == ChimeraTK::DataValidity::ok);
52 
53  accMathWrite.setDataValidity(ChimeraTK::DataValidity::faulty);
54  accMathWrite.write();
55  accTarget.read();
56  BOOST_CHECK(accTarget.dataValidity() == ChimeraTK::DataValidity::faulty);
57 
58  accMathWrite.setDataValidity(ChimeraTK::DataValidity::ok);
59  accMathWrite.write();
60  accTarget.read();
61  BOOST_CHECK(accTarget.dataValidity() == ChimeraTK::DataValidity::ok);
62 }
63 
64 /**********************************************************************************************************************/
65 
66 BOOST_AUTO_TEST_CASE(testReadSyncWithParameters) {
68  device.open("(logicalNameMap?map=mathPlugin.xlmap)");
69 
70  auto accTarget = device.getScalarRegisterAccessor<int>("SimpleScalar");
71  auto scalarPar = device.getScalarRegisterAccessor<int>("ScalarParameter");
72  auto accMathRead = device.getScalarRegisterAccessor<double>("ScalarWithParametersRead");
73  auto arrayPar = device.getOneDRegisterAccessor<int>("SimpleArray");
74 
75  accTarget.read();
76  BOOST_CHECK(accTarget.dataValidity() == ChimeraTK::DataValidity::ok);
77  scalarPar.read();
78  BOOST_CHECK(scalarPar.dataValidity() == ChimeraTK::DataValidity::ok);
79  accMathRead.read();
80  BOOST_CHECK(accMathRead.dataValidity() == ChimeraTK::DataValidity::ok);
81  arrayPar.read();
82  BOOST_CHECK(arrayPar.dataValidity() == ChimeraTK::DataValidity::ok);
83 
84  // set a parameter to faulty.
85  scalarPar.setDataValidity(ChimeraTK::DataValidity::faulty);
86  scalarPar.write();
87 
88  // should become faulty
89  accMathRead.read();
90  BOOST_CHECK(accMathRead.dataValidity() == ChimeraTK::DataValidity::faulty);
91 
92  // It's readonly so no change is expected in target.
93  accTarget.read();
94  BOOST_CHECK(accTarget.dataValidity() == ChimeraTK::DataValidity::ok);
95 
96  // other parameters should be ok.
97  arrayPar.read();
98  BOOST_CHECK(arrayPar.dataValidity() == ChimeraTK::DataValidity::ok);
99 
100  // set a parameter to ok.
101  scalarPar.setDataValidity(ChimeraTK::DataValidity::ok);
102  scalarPar.write();
103 
104  // should be ok now.
105  accMathRead.read();
106  BOOST_CHECK(accMathRead.dataValidity() == ChimeraTK::DataValidity::ok);
107 
108  // set target to faulty.
109  accTarget.setDataValidity(ChimeraTK::DataValidity::faulty);
110  accTarget.write();
111 
112  // parameter should be ok.
113  scalarPar.read();
114  scalarPar.setDataValidity(ChimeraTK::DataValidity::ok);
115  arrayPar.read();
116  BOOST_CHECK(arrayPar.dataValidity() == ChimeraTK::DataValidity::ok);
117 
118  // It should become faulty
119  accMathRead.read();
120  BOOST_CHECK(accMathRead.dataValidity() == ChimeraTK::DataValidity::faulty);
121 
122  // set target to ok.
123  accTarget.setDataValidity(ChimeraTK::DataValidity::ok);
124  accTarget.write();
125 
126  // All should be ok now.
127  accMathRead.read();
128  BOOST_CHECK(accMathRead.dataValidity() == ChimeraTK::DataValidity::ok);
129 }
130 
131 /**********************************************************************************************************************/
132 
133 BOOST_AUTO_TEST_CASE(testWriteWithParameters) {
135  device.open("(logicalNameMap?map=mathPlugin.xlmap)");
136 
137  auto accTarget = device.getScalarRegisterAccessor<int>("SimpleScalar");
138  auto scalarPar = device.getScalarRegisterAccessor<int>("ScalarParameter");
139  auto accMathWrite = device.getScalarRegisterAccessor<double>("ScalarWithParametersWrite");
140  auto arrayPar = device.getOneDRegisterAccessor<int>("SimpleArray");
141 
142  accTarget.read();
143  BOOST_CHECK(accTarget.dataValidity() == ChimeraTK::DataValidity::ok);
144  scalarPar.read();
145  BOOST_CHECK(scalarPar.dataValidity() == ChimeraTK::DataValidity::ok);
146  arrayPar.read();
147  BOOST_CHECK(arrayPar.dataValidity() == ChimeraTK::DataValidity::ok);
148 
149  accMathWrite.setDataValidity(ChimeraTK::DataValidity::faulty);
150  accMathWrite.write();
151 
152  // target should become faulty.
153  accTarget.read();
154  BOOST_CHECK(accTarget.dataValidity() == ChimeraTK::DataValidity::faulty);
155 
156  // parameters should be ok.
157  scalarPar.read();
158  BOOST_CHECK(scalarPar.dataValidity() == ChimeraTK::DataValidity::ok);
159  arrayPar.read();
160  BOOST_CHECK(arrayPar.dataValidity() == ChimeraTK::DataValidity::ok);
161 
162  // set it back to ok
163  accMathWrite.setDataValidity(ChimeraTK::DataValidity::ok);
164  accMathWrite.write();
165 
166  // should be ok.
167  accTarget.read();
168  BOOST_CHECK(accTarget.dataValidity() == ChimeraTK::DataValidity::ok);
169 
170  // set parameter to faulty
171  scalarPar.setDataValidity(ChimeraTK::DataValidity::faulty);
172  scalarPar.write();
173 
174  // other parameter should be ok
175  arrayPar.read();
176  BOOST_CHECK(arrayPar.dataValidity() == ChimeraTK::DataValidity::ok);
177 
178  // update
179  accMathWrite.write();
180 
181  // target should become faulty.
182  accTarget.read();
183  BOOST_CHECK(accTarget.dataValidity() == ChimeraTK::DataValidity::faulty);
184 
185  // set parameter to ok
186  scalarPar.setDataValidity(ChimeraTK::DataValidity::ok);
187  scalarPar.write();
188 
189  // update
190  accMathWrite.write();
191 
192  // target should be ok now.
193  accTarget.read();
194  BOOST_CHECK(accTarget.dataValidity() == ChimeraTK::DataValidity::ok);
195 }
196 
197 BOOST_AUTO_TEST_SUITE_END()
ExceptionDummyBackend.h
device
ctk::Device device
Definition: testExceptionDummyDevice.cc:18
ChimeraTK::DataValidity::faulty
@ faulty
The data is considered valid.
ChimeraTK::Device::getOneDRegisterAccessor
OneDRegisterAccessor< UserType > getOneDRegisterAccessor(const RegisterPath &registerPathName, size_t numberOfWords=0, size_t wordOffsetInRegister=0, const AccessModeFlags &flags=AccessModeFlags({})) const
Get a OneDRegisterAccessor object for the given register.
Definition: Device.h:273
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(testReadSync)
Definition: testMathPluginDataValidity.cpp:18
ChimeraTK::DataValidity::ok
@ ok
Device.h
ChimeraTK::Device
Class allows to read/write registers from device.
Definition: Device.h:39
ChimeraTK::Device::open
void open(std::string const &aliasName)
Open a device by the given alias name from the DMAP file.
Definition: Device.cc:58
ChimeraTK::Device::getScalarRegisterAccessor
ScalarRegisterAccessor< UserType > getScalarRegisterAccessor(const RegisterPath &registerPathName, size_t wordOffsetInRegister=0, const AccessModeFlags &flags=AccessModeFlags({})) const
Get a ScalarRegisterObject object for the given register.
Definition: Device.h:263
ChimeraTK
Definition: DummyBackend.h:16