ChimeraTK-DeviceAccess  03.18.00
testLMapBackend.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 LMapBackendTest
6 #include <boost/test/unit_test.hpp>
7 using namespace boost::unit_test_framework;
8 
9 #include "Device.h"
10 #include "DummyRegisterAccessor.h"
11 #include "ExceptionDummyBackend.h"
12 #include "TransferGroup.h"
13 #include "UnifiedBackendTest.h"
14 
15 using namespace ChimeraTK;
16 
17 BOOST_AUTO_TEST_SUITE(LMapBackendTestSuite)
18 
19 /**********************************************************************************************************************/
20 
21 BOOST_AUTO_TEST_CASE(testExceptions) {
22  BackendFactory::getInstance().setDMapFilePath("logicalnamemap.dmap");
24  BOOST_CHECK(device.isOpened() == false);
25  device.open("LMAP0");
26  BOOST_CHECK(device.isOpened() == true);
27  // you must always be able to re-open a backend. It should try to re-connect, if applicable.
28  device.open();
29  BOOST_CHECK(device.isOpened() == true);
30  device.open("LMAP0");
31  BOOST_CHECK(device.isOpened() == true);
32 
33  int data = 0;
34 
35  BOOST_CHECK_THROW(device.write("Channel3", data), ChimeraTK::logic_error);
36 
37  BOOST_CHECK_THROW(
38  std::ignore = device.getOneDRegisterAccessor<int>("ExceedsNumberOfChannels"), ChimeraTK::logic_error);
39  BOOST_CHECK_NO_THROW(std::ignore = device.getOneDRegisterAccessor<int>("LastChannelInRegister"));
40 
41  BOOST_CHECK(device.isOpened() == true);
42  device.close();
43  BOOST_CHECK(device.isOpened() == false);
44  device.close();
45  BOOST_CHECK(device.isOpened() == false);
46 }
47 
48 /**********************************************************************************************************************/
49 
50 BOOST_AUTO_TEST_CASE(testCatalogue) {
51  BackendFactory::getInstance().setDMapFilePath("logicalnamemap.dmap");
53 
54  device.open("LMAP0");
55 
56  const RegisterCatalogue& catalogue = device.getRegisterCatalogue();
57 
58  auto info = catalogue.getRegister("SingleWord");
59  BOOST_CHECK(info.getRegisterName() == "/SingleWord");
60  BOOST_CHECK(info.getNumberOfElements() == 1);
61  BOOST_CHECK(info.getNumberOfChannels() == 1);
62  BOOST_CHECK(info.getNumberOfDimensions() == 0);
63 
64  info = catalogue.getRegister("FullArea");
65  BOOST_CHECK(info.getRegisterName() == "/FullArea");
66  BOOST_CHECK(info.getNumberOfElements() == 0x400);
67  BOOST_CHECK(info.getNumberOfChannels() == 1);
68  BOOST_CHECK(info.getNumberOfDimensions() == 1);
69 
70  info = catalogue.getRegister("PartOfArea");
71  BOOST_CHECK(info.getRegisterName() == "/PartOfArea");
72  BOOST_CHECK(info.getNumberOfElements() == 20);
73  BOOST_CHECK(info.getNumberOfChannels() == 1);
74  BOOST_CHECK(info.getNumberOfDimensions() == 1);
75 
76  ChimeraTK::Device target1;
77  target1.open("PCIE3");
78  ChimeraTK::TwoDRegisterAccessor<int32_t> accTarget = target1.getTwoDRegisterAccessor<int32_t>("TEST/NODMA");
79  unsigned int nSamples = accTarget[3].size();
80 
81  info = catalogue.getRegister("Channel3");
82  BOOST_CHECK(info.getRegisterName() == "/Channel3");
83  BOOST_CHECK(info.getNumberOfElements() == nSamples);
84  BOOST_CHECK(info.getNumberOfChannels() == 1);
85  BOOST_CHECK(info.getNumberOfDimensions() == 1);
86 
87  info = catalogue.getRegister("Constant2");
88  BOOST_CHECK(info.getRegisterName() == "/Constant2");
89  BOOST_CHECK(info.getNumberOfElements() == 1);
90  BOOST_CHECK(info.getNumberOfChannels() == 1);
91  BOOST_CHECK(info.getNumberOfDimensions() == 0);
92 
93  info = catalogue.getRegister("/MyModule/SomeSubmodule/Variable");
94  BOOST_CHECK(info.getRegisterName() == "/MyModule/SomeSubmodule/Variable");
95  BOOST_CHECK(info.getNumberOfElements() == 1);
96  BOOST_CHECK(info.getNumberOfChannels() == 1);
97  BOOST_CHECK(info.getNumberOfDimensions() == 0);
98 
99  // std::unordered_set<std::string> targetDevices = lmap.getTargetDevices();
100  // BOOST_CHECK(targetDevices.size() == 2);
101  // BOOST_CHECK(targetDevices.count("PCIE2") == 1);
102  // BOOST_CHECK(targetDevices.count("PCIE3") == 1);
103 
104  device.close();
105 }
106 
107 /**********************************************************************************************************************/
108 
109 BOOST_AUTO_TEST_CASE(testReadWriteConstant) {
110  BackendFactory::getInstance().setDMapFilePath("logicalnamemap.dmap");
112 
113  device.open("LMAP0");
114  BOOST_CHECK(device.read<int>("Constant") == 42);
115 
116  BOOST_CHECK_THROW(device.write("Constant", 0), ChimeraTK::logic_error);
117 
118  BOOST_CHECK(device.read<int>("Constant") == 42);
119 
120  // test with buffering register accessor
121  auto acc = device.getOneDRegisterAccessor<int32_t>("Constant");
122  BOOST_CHECK(acc.getNElements() == 1);
123  BOOST_CHECK(acc[0] == 0); // values are only available after the first read, otherwise there is the value after
124  // construction (= int32_t() aka. 0)
125  acc.read();
126  BOOST_CHECK(acc[0] == 42);
127  BOOST_CHECK_THROW(acc.write(), ChimeraTK::logic_error);
128 
129  auto acc2 = device.getOneDRegisterAccessor<int32_t>("Constant");
130  auto acc3 = device.getOneDRegisterAccessor<int32_t>("Constant2");
131 
132  boost::shared_ptr<NDRegisterAccessor<int32_t>> impl, impl2, impl3;
133  impl = boost::dynamic_pointer_cast<NDRegisterAccessor<int32_t>>(acc.getHighLevelImplElement());
134  impl2 = boost::dynamic_pointer_cast<NDRegisterAccessor<int32_t>>(acc2.getHighLevelImplElement());
135  impl3 = boost::dynamic_pointer_cast<NDRegisterAccessor<int32_t>>(acc3.getHighLevelImplElement());
136 
137  // BOOST_CHECK( impl->mayReplaceOther(impl2) == true ); // this is
138  // currently always set to false, since it doesn't really make any
139  // difference...
140  BOOST_CHECK(impl->mayReplaceOther(impl3) == false);
141 
142  auto arrayConstant = device.getOneDRegisterAccessor<int>("/ArrayConstant");
143  BOOST_CHECK_EQUAL(arrayConstant.getNElements(), 5);
144  BOOST_CHECK_EQUAL(arrayConstant[0], 0);
145  BOOST_CHECK_EQUAL(arrayConstant[1], 0);
146  BOOST_CHECK_EQUAL(arrayConstant[2], 0);
147  BOOST_CHECK_EQUAL(arrayConstant[3], 0);
148  BOOST_CHECK_EQUAL(arrayConstant[4], 0);
149  arrayConstant.read();
150  BOOST_CHECK_EQUAL(arrayConstant[0], 1111);
151  BOOST_CHECK_EQUAL(arrayConstant[1], 2222);
152  BOOST_CHECK_EQUAL(arrayConstant[2], 3333);
153  BOOST_CHECK_EQUAL(arrayConstant[3], 4444);
154  BOOST_CHECK_EQUAL(arrayConstant[4], 5555);
155  BOOST_CHECK_THROW(arrayConstant.write(), ChimeraTK::logic_error);
156 
157  auto partOfArrayConstant = device.getOneDRegisterAccessor<int>("/ArrayConstant", 2, 1);
158  BOOST_CHECK_EQUAL(partOfArrayConstant.getNElements(), 2);
159  BOOST_CHECK_EQUAL(partOfArrayConstant[0], 0);
160  BOOST_CHECK_EQUAL(partOfArrayConstant[1], 0);
161  partOfArrayConstant.read();
162  BOOST_CHECK_EQUAL(partOfArrayConstant[0], 2222);
163  BOOST_CHECK_EQUAL(partOfArrayConstant[1], 3333);
164  BOOST_CHECK_THROW(partOfArrayConstant.write(), ChimeraTK::logic_error);
165 
166  device.close();
167 }
168 
169 /**********************************************************************************************************************/
170 
171 BOOST_AUTO_TEST_CASE(testReadWriteVariable) {
172  BackendFactory::getInstance().setDMapFilePath("logicalnamemap.dmap");
174 
175  device.open("LMAP0");
176 
177  // test with buffering register accessor
178  auto acc = device.getOneDRegisterAccessor<int32_t>("/MyModule/SomeSubmodule/Variable");
179  auto acc2 = device.getOneDRegisterAccessor<int32_t>("/MyModule/SomeSubmodule/Variable");
180  BOOST_CHECK(acc.getVersionNumber() == VersionNumber(nullptr));
181  BOOST_CHECK(acc2.getVersionNumber() == VersionNumber(nullptr));
182  BOOST_CHECK(acc.getNElements() == 1);
183  BOOST_CHECK(acc[0] == 0);
184  BOOST_CHECK(acc2[0] == 0);
185  acc.read();
186  BOOST_CHECK(acc[0] == 2);
187  acc[0] = 3;
188  BOOST_CHECK(acc[0] == 3);
189  BOOST_CHECK(acc2[0] == 0);
190  acc.write();
191  acc2.read();
192  BOOST_CHECK(acc[0] == 3);
193  BOOST_CHECK(acc2[0] == 3);
194 
195  // test array access
196  auto arrayVariable = device.getOneDRegisterAccessor<int>("/ArrayVariable");
197  BOOST_CHECK_EQUAL(arrayVariable.getNElements(), 6);
198  BOOST_CHECK_EQUAL(arrayVariable[0], 0);
199  BOOST_CHECK_EQUAL(arrayVariable[1], 0);
200  BOOST_CHECK_EQUAL(arrayVariable[2], 0);
201  BOOST_CHECK_EQUAL(arrayVariable[3], 0);
202  BOOST_CHECK_EQUAL(arrayVariable[4], 0);
203  BOOST_CHECK_EQUAL(arrayVariable[5], 0);
204  arrayVariable.read();
205  BOOST_CHECK_EQUAL(arrayVariable[0], 11);
206  BOOST_CHECK_EQUAL(arrayVariable[1], 22);
207  BOOST_CHECK_EQUAL(arrayVariable[2], 33);
208  BOOST_CHECK_EQUAL(arrayVariable[3], 44);
209  BOOST_CHECK_EQUAL(arrayVariable[4], 55);
210  BOOST_CHECK_EQUAL(arrayVariable[5], 66);
211  arrayVariable = std::vector<int>({6, 5, 4, 3, 2, 1});
212  arrayVariable.write();
213  BOOST_CHECK_EQUAL(arrayVariable[0], 6);
214  BOOST_CHECK_EQUAL(arrayVariable[1], 5);
215  BOOST_CHECK_EQUAL(arrayVariable[2], 4);
216  BOOST_CHECK_EQUAL(arrayVariable[3], 3);
217  BOOST_CHECK_EQUAL(arrayVariable[4], 2);
218  BOOST_CHECK_EQUAL(arrayVariable[5], 1);
219  arrayVariable = std::vector<int>({0, 0, 0, 0, 0, 0});
220  arrayVariable.read();
221  BOOST_CHECK_EQUAL(arrayVariable[0], 6);
222  BOOST_CHECK_EQUAL(arrayVariable[1], 5);
223  BOOST_CHECK_EQUAL(arrayVariable[2], 4);
224  BOOST_CHECK_EQUAL(arrayVariable[3], 3);
225  BOOST_CHECK_EQUAL(arrayVariable[4], 2);
226  BOOST_CHECK_EQUAL(arrayVariable[5], 1);
227 
228  auto partOfArrayVariable = device.getOneDRegisterAccessor<int>("/ArrayVariable", 3, 2);
229  BOOST_CHECK_EQUAL(partOfArrayVariable.getNElements(), 3);
230  BOOST_CHECK_EQUAL(partOfArrayVariable[0], 0);
231  BOOST_CHECK_EQUAL(partOfArrayVariable[1], 0);
232  BOOST_CHECK_EQUAL(partOfArrayVariable[2], 0);
233  partOfArrayVariable.read();
234  BOOST_CHECK_EQUAL(partOfArrayVariable[0], 4);
235  BOOST_CHECK_EQUAL(partOfArrayVariable[1], 3);
236  BOOST_CHECK_EQUAL(partOfArrayVariable[2], 2);
237  partOfArrayVariable = std::vector<int>({42, 120, 31415});
238  partOfArrayVariable.write();
239  BOOST_CHECK_EQUAL(partOfArrayVariable[0], 42);
240  BOOST_CHECK_EQUAL(partOfArrayVariable[1], 120);
241  BOOST_CHECK_EQUAL(partOfArrayVariable[2], 31415);
242  partOfArrayVariable = std::vector<int>({0, 0, 0});
243  partOfArrayVariable.read();
244  BOOST_CHECK_EQUAL(partOfArrayVariable[0], 42);
245  BOOST_CHECK_EQUAL(partOfArrayVariable[1], 120);
246  BOOST_CHECK_EQUAL(partOfArrayVariable[2], 31415);
247 
248  BOOST_CHECK_EQUAL(arrayVariable[0], 6);
249  BOOST_CHECK_EQUAL(arrayVariable[1], 5);
250  BOOST_CHECK_EQUAL(arrayVariable[2], 4);
251  BOOST_CHECK_EQUAL(arrayVariable[3], 3);
252  BOOST_CHECK_EQUAL(arrayVariable[4], 2);
253  BOOST_CHECK_EQUAL(arrayVariable[5], 1);
254  arrayVariable.read();
255  BOOST_CHECK_EQUAL(arrayVariable[0], 6);
256  BOOST_CHECK_EQUAL(arrayVariable[1], 5);
257  BOOST_CHECK_EQUAL(arrayVariable[2], 42);
258  BOOST_CHECK_EQUAL(arrayVariable[3], 120);
259  BOOST_CHECK_EQUAL(arrayVariable[4], 31415);
260  BOOST_CHECK_EQUAL(arrayVariable[5], 1);
261 
262  device.close();
263 }
264 
265 /**********************************************************************************************************************/
266 
267 BOOST_AUTO_TEST_CASE(testReadWriteRegister) {
268  std::vector<int> area(1024);
269 
270  BackendFactory::getInstance().setDMapFilePath("logicalnamemap.dmap");
271  ChimeraTK::Device device, target1;
272 
273  target1.open("PCIE2");
274  device.open("LMAP0");
275  // single word
276  target1.write("BOARD.WORD_USER", 120);
277  BOOST_CHECK(device.read<int>("SingleWord") == 120);
278 
279  target1.write("BOARD.WORD_USER", 66);
280  BOOST_CHECK(device.read<int>("SingleWord") == 66);
281 
282  device.write("SingleWord", 42);
283  BOOST_CHECK(target1.read<int>("BOARD.WORD_USER") == 42);
284 
285  device.write("SingleWord", 12);
286  BOOST_CHECK(target1.read<int>("BOARD.WORD_USER") == 12);
287 
288  // area
289  for(int i = 0; i < 1024; i++) area[i] = 12345 + 3 * i;
290  target1.write("ADC.AREA_DMAABLE", area);
291  area = device.read<int>("FullArea", 1024);
292  for(int i = 0; i < 1024; i++) BOOST_CHECK(area[i] == 12345 + 3 * i);
293 
294  for(int i = 0; i < 1024; i++) area[i] = -876543210 + 42 * i;
295  target1.write("ADC.AREA_DMAABLE", area);
296  area = device.read<int>("FullArea", 1024);
297  for(int i = 0; i < 1024; i++) BOOST_CHECK(area[i] == -876543210 + 42 * i);
298 
299  for(int i = 0; i < 1024; i++) area[i] = 12345 + 3 * i;
300  device.write("FullArea", area);
301  area = target1.read<int>("ADC.AREA_DMAABLE", 1024);
302  for(int i = 0; i < 1024; i++) BOOST_CHECK(area[i] == 12345 + 3 * i);
303 
304  for(int i = 0; i < 1024; i++) area[i] = -876543210 + 42 * i;
305  device.write("FullArea", area);
306  area = target1.read<int>("ADC.AREA_DMAABLE", 1024);
307  for(int i = 0; i < 1024; i++) BOOST_CHECK(area[i] == -876543210 + 42 * i);
308 
309  device.close();
310 }
311 
312 /**********************************************************************************************************************/
313 
314 BOOST_AUTO_TEST_CASE(testReadWriteRange) {
315  std::vector<int> area(1024);
316 
317  BackendFactory::getInstance().setDMapFilePath("logicalnamemap.dmap");
318  ChimeraTK::Device device, target1;
319 
320  device.open("LMAP0");
321  target1.open("PCIE2");
322 
323  for(int i = 0; i < 1024; i++) area[i] = 0;
324  for(int i = 0; i < 20; i++) area[i + 10] = 12345 + 3 * i;
325  target1.write("ADC.AREA_DMAABLE", area);
326  area = device.read<int>("PartOfArea", 20);
327  for(int i = 0; i < 20; i++) BOOST_CHECK(area[i] == 12345 + 3 * i);
328 
329  area.resize(1024);
330  for(int i = 0; i < 1024; i++) area[i] = 0;
331  for(int i = 0; i < 20; i++) area[i + 10] = -876543210 + 42 * i;
332  target1.write("ADC.AREA_DMAABLE", area);
333  for(int i = 0; i < 1024; i++) area[i] = 0;
334  area = device.read<int>("PartOfArea", 20);
335  for(int i = 0; i < 20; i++) BOOST_CHECK(area[i] == -876543210 + 42 * i);
336 
337  device.close();
338 }
339 
340 /**********************************************************************************************************************/
341 
342 BOOST_AUTO_TEST_CASE(testRegisterAccessorForRegister) {
343  std::vector<int> area(1024);
344  int index;
345 
346  BackendFactory::getInstance().setDMapFilePath("logicalnamemap.dmap");
347  ChimeraTK::Device device, target1;
348 
349  device.open("LMAP0");
350  target1.open("PCIE2");
351 
352  auto acc = device.getOneDRegisterAccessor<int32_t>("FullArea");
353  BOOST_CHECK(!acc.isReadOnly());
354  BOOST_CHECK(acc.isReadable());
355  BOOST_CHECK(acc.isWriteable());
356 
357  auto acc2 = device.getOneDRegisterAccessor<int32_t>("PartOfArea");
358 
359  boost::shared_ptr<NDRegisterAccessor<int32_t>> impl, impl2;
360  impl = boost::dynamic_pointer_cast<NDRegisterAccessor<int32_t>>(acc.getHighLevelImplElement());
361  impl2 = boost::dynamic_pointer_cast<NDRegisterAccessor<int32_t>>(acc2.getHighLevelImplElement());
362 
363  BOOST_CHECK(impl != impl2);
364  BOOST_CHECK(impl->mayReplaceOther(impl) == true);
365  BOOST_CHECK(impl2->mayReplaceOther(impl) == false);
366  BOOST_CHECK(impl->mayReplaceOther(impl2) == false);
367 
368  const ChimeraTK::OneDRegisterAccessor<int32_t> acc_const = acc;
369 
370  // reading via [] operator
371  for(int i = 0; i < 1024; i++) area[i] = 12345 + 3 * i;
372  target1.write("ADC.AREA_DMAABLE", area);
373  acc.read();
374  for(int i = 0; i < 1024; i++) BOOST_CHECK(acc[i] == 12345 + 3 * i);
375 
376  for(int i = 0; i < 1024; i++) area[i] = -876543210 + 42 * i;
377  target1.write("ADC.AREA_DMAABLE", area);
378  acc.read();
379  for(int i = 0; i < 1024; i++) BOOST_CHECK(acc[i] == -876543210 + 42 * i);
380 
381  // writing via [] operator
382  for(int i = 0; i < 1024; i++) acc[i] = 12345 + 3 * i;
383  acc.write();
384  area = target1.read<int>("ADC.AREA_DMAABLE", 1024);
385  for(int i = 0; i < 1024; i++) BOOST_CHECK(area[i] == 12345 + 3 * i);
386 
387  for(int i = 0; i < 1024; i++) acc[i] = -876543210 + 42 * i;
388  acc.write();
389  area = target1.read<int>("ADC.AREA_DMAABLE", 1024);
390  for(int i = 0; i < 1024; i++) BOOST_CHECK(area[i] == -876543210 + 42 * i);
391 
392  // reading via iterator
393  index = 0;
394  for(auto it = acc.begin(); it != acc.end(); ++it) {
395  BOOST_CHECK(*it == -876543210 + 42 * index);
396  ++index;
397  }
398  BOOST_CHECK(index == 1024);
399 
400  // reading via const_iterator
401  index = 0;
402  for(auto it = acc_const.begin(); it != acc_const.end(); ++it) {
403  BOOST_CHECK(*it == -876543210 + 42 * index);
404  ++index;
405  }
406  BOOST_CHECK(index == 1024);
407 
408  // reading via reverse_iterator
409  index = 1024;
410  for(auto it = acc.rbegin(); it != acc.rend(); ++it) {
411  --index;
412  BOOST_CHECK(*it == -876543210 + 42 * index);
413  }
414  BOOST_CHECK(index == 0);
415 
416  // reading via const_reverse_iterator
417  index = 1024;
418  for(auto it = acc_const.rbegin(); it != acc_const.rend(); ++it) {
419  --index;
420  BOOST_CHECK(*it == -876543210 + 42 * index);
421  }
422  BOOST_CHECK(index == 0);
423 
424  // swap with std::vector
425  std::vector<int32_t> vec(1024);
426  acc.swap(vec);
427  for(unsigned int i = 0; i < vec.size(); i++) {
428  BOOST_CHECK(vec[i] == -876543210 + 42 * static_cast<signed>(i));
429  }
430 
431  device.close();
432 }
433 
434 /**********************************************************************************************************************/
435 
436 BOOST_AUTO_TEST_CASE(testRegisterAccessorForRange) {
437  std::vector<int> area(1024);
438  int index;
439 
440  BackendFactory::getInstance().setDMapFilePath("logicalnamemap.dmap");
441  ChimeraTK::Device device, target1;
442 
443  device.open("LMAP0");
444  target1.open("PCIE2");
445 
446  auto acc = device.getOneDRegisterAccessor<int32_t>("PartOfArea");
447  BOOST_CHECK(acc.isReadOnly() == false);
448  BOOST_CHECK(acc.isReadable());
449  BOOST_CHECK(acc.isWriteable());
450 
451  const ChimeraTK::OneDRegisterAccessor<int32_t> acc_const = acc;
452 
453  for(int i = 0; i < 20; i++) area[i + 10] = 12345 + 3 * i;
454  target1.write("ADC.AREA_DMAABLE", area);
455  acc.read();
456  for(int i = 0; i < 20; i++) BOOST_CHECK(acc[i] == 12345 + 3 * i);
457 
458  for(int i = 0; i < 20; i++) area[i + 10] = -876543210 + 42 * i;
459  target1.write("ADC.AREA_DMAABLE", area);
460  acc.read();
461  for(int i = 0; i < 20; i++) BOOST_CHECK(acc[i] == -876543210 + 42 * i);
462 
463  // reading via iterator
464  index = 0;
465  for(auto it = acc.begin(); it != acc.end(); ++it) {
466  BOOST_CHECK(*it == -876543210 + 42 * index);
467  ++index;
468  }
469  BOOST_CHECK(index == 20);
470 
471  // reading via const_iterator
472  index = 0;
473  for(auto it = acc_const.begin(); it != acc_const.end(); ++it) {
474  BOOST_CHECK(*it == -876543210 + 42 * index);
475  ++index;
476  }
477  BOOST_CHECK(index == 20);
478 
479  // reading via reverse_iterator
480  index = 20;
481  for(auto it = acc.rbegin(); it != acc.rend(); ++it) {
482  --index;
483  BOOST_CHECK(*it == -876543210 + 42 * index);
484  }
485  BOOST_CHECK(index == 0);
486 
487  // reading via const_reverse_iterator
488  index = 20;
489  for(auto it = acc_const.rbegin(); it != acc_const.rend(); ++it) {
490  --index;
491  BOOST_CHECK(*it == -876543210 + 42 * index);
492  }
493  BOOST_CHECK(index == 0);
494 
495  // writing
496  for(int i = 0; i < 20; i++) acc[i] = 24507 + 33 * i;
497  acc.write();
498  area = target1.read<int>("ADC.AREA_DMAABLE", 1024);
499  for(int i = 0; i < 20; i++) BOOST_CHECK(area[i + 10] == 24507 + 33 * i);
500 
501  device.close();
502 }
503 
504 /**********************************************************************************************************************/
505 
506 BOOST_AUTO_TEST_CASE(testRegisterAccessorForChannel) {
507  std::vector<int> area(1024);
508 
509  BackendFactory::getInstance().setDMapFilePath("logicalnamemap.dmap");
510  ChimeraTK::Device device, target1;
511 
512  device.open("LMAP0");
513  target1.open("PCIE3");
514 
515  auto acc3 = device.getOneDRegisterAccessor<int32_t>("Channel3");
516  auto acc4 = device.getOneDRegisterAccessor<int32_t>("Channel4");
517 
518  auto acc3_2 = device.getOneDRegisterAccessor<int32_t>("Channel3");
519 
520  boost::shared_ptr<NDRegisterAccessor<int32_t>> impl3, impl4, impl3_2;
521  impl3 = boost::dynamic_pointer_cast<NDRegisterAccessor<int32_t>>(acc3.getHighLevelImplElement());
522  impl4 = boost::dynamic_pointer_cast<NDRegisterAccessor<int32_t>>(acc4.getHighLevelImplElement());
523  impl3_2 = boost::dynamic_pointer_cast<NDRegisterAccessor<int32_t>>(acc3_2.getHighLevelImplElement());
524  BOOST_CHECK(impl3->mayReplaceOther(impl3_2) == true);
525  BOOST_CHECK(impl3->mayReplaceOther(impl4) == false);
526 
527  auto accTarget = target1.getTwoDRegisterAccessor<int32_t>("TEST/NODMA");
528  unsigned int nSamples = accTarget[3].size();
529  BOOST_CHECK(accTarget[4].size() == nSamples);
530  BOOST_CHECK(acc3.getNElements() == nSamples);
531  BOOST_CHECK(acc4.getNElements() == nSamples);
532 
533  // fill target register
534  for(unsigned int i = 0; i < nSamples; i++) {
535  accTarget[3][i] = 3000 + i;
536  accTarget[4][i] = 4000 - i;
537  }
538  accTarget.write();
539 
540  // clear channel accessor buffers
541  for(unsigned int i = 0; i < nSamples; i++) {
542  acc3[i] = 0;
543  acc4[i] = 0;
544  }
545 
546  // read channel accessors
547  acc3.read();
548  for(unsigned int i = 0; i < nSamples; i++) {
549  BOOST_CHECK(acc3[i] == (signed)(3000 + i));
550  BOOST_CHECK(acc4[i] == 0);
551  }
552  acc4.read();
553  for(unsigned int i = 0; i < nSamples; i++) {
554  BOOST_CHECK(acc3[i] == (signed)(3000 + i));
555  BOOST_CHECK(acc4[i] == (signed)(4000 - i));
556  }
557 
558  // read via iterators
559  unsigned int idx = 0;
560  for(auto it = acc3.begin(); it != acc3.end(); ++it) {
561  BOOST_CHECK(*it == (signed)(3000 + idx));
562  ++idx;
563  }
564  BOOST_CHECK(idx == nSamples);
565 
566  // read via const iterators
567  const ChimeraTK::OneDRegisterAccessor<int32_t>& acc3_const = acc3;
568  idx = 0;
569  for(auto it = acc3_const.begin(); it != acc3_const.end(); ++it) {
570  BOOST_CHECK(*it == (signed)(3000 + idx));
571  ++idx;
572  }
573  BOOST_CHECK(idx == nSamples);
574 
575  // read via reverse iterators
576  idx = nSamples;
577  for(auto it = acc3.rbegin(); it != acc3.rend(); ++it) {
578  --idx;
579  BOOST_CHECK(*it == (signed)(3000 + idx));
580  }
581  BOOST_CHECK(idx == 0);
582 
583  // read via reverse const iterators
584  idx = nSamples;
585  for(auto it = acc3_const.rbegin(); it != acc3_const.rend(); ++it) {
586  --idx;
587  BOOST_CHECK(*it == (signed)(3000 + idx));
588  }
589  BOOST_CHECK(idx == 0);
590 
591  // swap into other vector
592  std::vector<int> someVector(nSamples);
593  acc3.swap(someVector);
594  for(unsigned int i = 0; i < nSamples; i++) {
595  BOOST_CHECK(someVector[i] == (signed)(3000 + i));
596  }
597 
598  // write channel registers fails
599  BOOST_CHECK(acc3.isReadOnly());
600  BOOST_CHECK(acc3.isReadable());
601  BOOST_CHECK(acc3.isWriteable() == false);
602 
603  BOOST_CHECK(acc4.isReadOnly());
604  BOOST_CHECK(acc4.isReadable());
605  BOOST_CHECK(acc4.isWriteable() == false);
606 
607  BOOST_CHECK_THROW(acc3.write(), ChimeraTK::logic_error);
608  BOOST_CHECK_THROW(acc4.write(), ChimeraTK::logic_error);
609 
610  device.close();
611 }
612 
613 /**********************************************************************************************************************/
614 
615 BOOST_AUTO_TEST_CASE(testRegisterAccessorForBit) {
616  BackendFactory::getInstance().setDMapFilePath("logicalnamemap.dmap");
618 
619  device.open("LMAP0");
620 
621  auto bitField = device.getScalarRegisterAccessor<int>("/MyModule/SomeSubmodule/Variable");
622  auto bit0 = device.getScalarRegisterAccessor<uint8_t>("/Bit0ofVar");
623  auto bit1 = device.getScalarRegisterAccessor<uint16_t>("/Bit1ofVar");
624  auto bit2 = device.getScalarRegisterAccessor<int32_t>("/Bit2ofVar");
625  auto bit3 = device.getScalarRegisterAccessor<std::string>("/Bit3ofVar");
626 
627  bitField = 0;
628  bitField.write();
629 
630  bit0.read();
631  BOOST_CHECK_EQUAL(static_cast<uint8_t>(bit0), 0);
632  bit1.read();
633  BOOST_CHECK_EQUAL(static_cast<uint16_t>(bit1), 0);
634  bit2.read();
635  BOOST_CHECK_EQUAL(static_cast<int32_t>(bit2), 0);
636  bit3.read();
637  BOOST_CHECK_EQUAL(static_cast<std::string>(bit3), "0");
638 
639  bitField = 1;
640  bitField.write();
641 
642  bit0.read();
643  BOOST_CHECK_EQUAL(static_cast<uint8_t>(bit0), 1);
644  bit1.read();
645  BOOST_CHECK_EQUAL(static_cast<uint16_t>(bit1), 0);
646  bit2.read();
647  BOOST_CHECK_EQUAL(static_cast<int32_t>(bit2), 0);
648  bit3.read();
649  BOOST_CHECK_EQUAL(static_cast<std::string>(bit3), "0");
650 
651  bitField = 2;
652  bitField.write();
653 
654  bit0.read();
655  BOOST_CHECK_EQUAL(static_cast<uint8_t>(bit0), 0);
656  bit1.read();
657  BOOST_CHECK_EQUAL(static_cast<uint16_t>(bit1), 1);
658  bit2.read();
659  BOOST_CHECK_EQUAL(static_cast<int32_t>(bit2), 0);
660  bit3.read();
661  BOOST_CHECK_EQUAL(static_cast<std::string>(bit3), "0");
662 
663  bitField = 3;
664  bitField.write();
665 
666  bit0.read();
667  BOOST_CHECK_EQUAL(static_cast<uint8_t>(bit0), 1);
668  bit1.read();
669  BOOST_CHECK_EQUAL(static_cast<uint16_t>(bit1), 1);
670  bit2.read();
671  BOOST_CHECK_EQUAL(static_cast<int32_t>(bit2), 0);
672  bit3.read();
673  BOOST_CHECK_EQUAL(static_cast<std::string>(bit3), "0");
674 
675  bitField = 4;
676  bitField.write();
677 
678  bit0.read();
679  BOOST_CHECK_EQUAL(static_cast<uint8_t>(bit0), 0);
680  bit1.read();
681  BOOST_CHECK_EQUAL(static_cast<uint16_t>(bit1), 0);
682  bit2.read();
683  BOOST_CHECK_EQUAL(static_cast<int32_t>(bit2), 1);
684  bit3.read();
685  BOOST_CHECK_EQUAL(static_cast<std::string>(bit3), "0");
686 
687  bitField = 8;
688  bitField.write();
689 
690  bit0.read();
691  BOOST_CHECK_EQUAL(static_cast<uint8_t>(bit0), 0);
692  bit1.read();
693  BOOST_CHECK_EQUAL(static_cast<uint16_t>(bit1), 0);
694  bit2.read();
695  BOOST_CHECK_EQUAL(static_cast<int32_t>(bit2), 0);
696  bit3.read();
697  BOOST_CHECK_EQUAL(static_cast<std::string>(bit3), "1");
698 
699  bitField = 15;
700  bitField.write();
701 
702  bit0.read();
703  BOOST_CHECK_EQUAL(static_cast<uint8_t>(bit0), 1);
704  bit1.read();
705  BOOST_CHECK_EQUAL(static_cast<uint16_t>(bit1), 1);
706  bit2.read();
707  BOOST_CHECK_EQUAL(static_cast<int32_t>(bit2), 1);
708  bit3.read();
709  BOOST_CHECK_EQUAL(static_cast<std::string>(bit3), "1");
710 
711  bitField = 16;
712  bitField.write();
713 
714  bit0.read();
715  BOOST_CHECK_EQUAL(static_cast<uint8_t>(bit0), 0);
716  bit1.read();
717  BOOST_CHECK_EQUAL(static_cast<uint16_t>(bit1), 0);
718  bit2.read();
719  BOOST_CHECK_EQUAL(static_cast<int32_t>(bit2), 0);
720  bit3.read();
721  BOOST_CHECK_EQUAL(static_cast<std::string>(bit3), "0");
722 
723  bitField = 17;
724  bitField.write();
725 
726  bit0.read();
727  BOOST_CHECK_EQUAL(static_cast<uint8_t>(bit0), 1);
728  bit1.read();
729  BOOST_CHECK_EQUAL(static_cast<uint16_t>(bit1), 0);
730  bit2.read();
731  BOOST_CHECK_EQUAL(static_cast<int32_t>(bit2), 0);
732  bit3.read();
733  BOOST_CHECK_EQUAL(static_cast<std::string>(bit3), "0");
734 
735  bitField = 1;
736  bitField.write();
737 
738  bit0.read();
739  BOOST_CHECK_EQUAL(static_cast<uint8_t>(bit0), 1);
740  bit1.read();
741  BOOST_CHECK_EQUAL(static_cast<uint16_t>(bit1), 0);
742  bit2.read();
743  BOOST_CHECK_EQUAL(static_cast<int32_t>(bit2), 0);
744  bit3.read();
745  BOOST_CHECK_EQUAL(static_cast<std::string>(bit3), "0");
746 
747  bit2 = 1;
748  bit2.write();
749  bitField.read();
750  BOOST_CHECK_EQUAL(static_cast<int>(bitField), 5);
751 
752  bit1 = 1;
753  bit1.write();
754  bitField.read();
755  BOOST_CHECK_EQUAL(static_cast<int>(bitField), 7);
756 
757  bit0 = 0;
758  bit0.write();
759  bitField.read();
760  BOOST_CHECK_EQUAL(static_cast<int>(bitField), 6);
761 
762  bit3 = "1";
763  bit3.write();
764  bitField.read();
765  BOOST_CHECK_EQUAL(static_cast<int>(bitField), 14);
766 
767  // Test with TransferGroup
768  TransferGroup group;
769  group.addAccessor(bit0);
770  group.addAccessor(bit1);
771  group.addAccessor(bit2);
772  group.addAccessor(bit3);
773 
774  bitField = 0;
775  bitField.write();
776 
777  group.read();
778  BOOST_CHECK_EQUAL(static_cast<uint8_t>(bit0), 0);
779  BOOST_CHECK_EQUAL(static_cast<uint16_t>(bit1), 0);
780  BOOST_CHECK_EQUAL(static_cast<int32_t>(bit2), 0);
781  BOOST_CHECK_EQUAL(static_cast<std::string>(bit3), "0");
782 
783  bitField = 1;
784  bitField.write();
785 
786  group.read();
787  BOOST_CHECK_EQUAL(static_cast<uint8_t>(bit0), 1);
788  BOOST_CHECK_EQUAL(static_cast<uint16_t>(bit1), 0);
789  BOOST_CHECK_EQUAL(static_cast<int32_t>(bit2), 0);
790  BOOST_CHECK_EQUAL(static_cast<std::string>(bit3), "0");
791 
792  bitField = 2;
793  bitField.write();
794 
795  group.read();
796  BOOST_CHECK_EQUAL(static_cast<uint8_t>(bit0), 0);
797  BOOST_CHECK_EQUAL(static_cast<uint16_t>(bit1), 1);
798  BOOST_CHECK_EQUAL(static_cast<int32_t>(bit2), 0);
799  BOOST_CHECK_EQUAL(static_cast<std::string>(bit3), "0");
800 
801  bitField = 3;
802  bitField.write();
803 
804  group.read();
805  BOOST_CHECK_EQUAL(static_cast<uint8_t>(bit0), 1);
806  BOOST_CHECK_EQUAL(static_cast<uint16_t>(bit1), 1);
807  BOOST_CHECK_EQUAL(static_cast<int32_t>(bit2), 0);
808  BOOST_CHECK_EQUAL(static_cast<std::string>(bit3), "0");
809 
810  bitField = 4;
811  bitField.write();
812 
813  group.read();
814  BOOST_CHECK_EQUAL(static_cast<uint8_t>(bit0), 0);
815  BOOST_CHECK_EQUAL(static_cast<uint16_t>(bit1), 0);
816  BOOST_CHECK_EQUAL(static_cast<int32_t>(bit2), 1);
817  BOOST_CHECK_EQUAL(static_cast<std::string>(bit3), "0");
818 
819  bitField = 8;
820  bitField.write();
821 
822  group.read();
823  BOOST_CHECK_EQUAL(static_cast<uint8_t>(bit0), 0);
824  BOOST_CHECK_EQUAL(static_cast<uint16_t>(bit1), 0);
825  BOOST_CHECK_EQUAL(static_cast<int32_t>(bit2), 0);
826  BOOST_CHECK_EQUAL(static_cast<std::string>(bit3), "1");
827 
828  bitField = 15;
829  bitField.write();
830 
831  group.read();
832  BOOST_CHECK_EQUAL(static_cast<uint8_t>(bit0), 1);
833  BOOST_CHECK_EQUAL(static_cast<uint16_t>(bit1), 1);
834  BOOST_CHECK_EQUAL(static_cast<int32_t>(bit2), 1);
835  BOOST_CHECK_EQUAL(static_cast<std::string>(bit3), "1");
836 
837  bitField = 16;
838  bitField.write();
839 
840  group.read();
841  BOOST_CHECK_EQUAL(static_cast<uint8_t>(bit0), 0);
842  BOOST_CHECK_EQUAL(static_cast<uint16_t>(bit1), 0);
843  BOOST_CHECK_EQUAL(static_cast<int32_t>(bit2), 0);
844  BOOST_CHECK_EQUAL(static_cast<std::string>(bit3), "0");
845 
846  bitField = 17;
847  bitField.write();
848 
849  group.read();
850  BOOST_CHECK_EQUAL(static_cast<uint8_t>(bit0), 1);
851  BOOST_CHECK_EQUAL(static_cast<uint16_t>(bit1), 0);
852  BOOST_CHECK_EQUAL(static_cast<int32_t>(bit2), 0);
853  BOOST_CHECK_EQUAL(static_cast<std::string>(bit3), "0");
854 
855  bitField = 1;
856  bitField.write();
857 
858  group.read();
859  BOOST_CHECK_EQUAL(static_cast<uint8_t>(bit0), 1);
860  BOOST_CHECK_EQUAL(static_cast<uint16_t>(bit1), 0);
861  BOOST_CHECK_EQUAL(static_cast<int32_t>(bit2), 0);
862  BOOST_CHECK_EQUAL(static_cast<std::string>(bit3), "0");
863 
864  bit2 = 1;
865  group.write();
866  bitField.read();
867  BOOST_CHECK_EQUAL(static_cast<int>(bitField), 5);
868 
869  bit1 = 1;
870  group.write();
871  bitField.read();
872  BOOST_CHECK_EQUAL(static_cast<int>(bitField), 7);
873 
874  bit0 = 0;
875  group.write();
876  bitField.read();
877  BOOST_CHECK_EQUAL(static_cast<int>(bitField), 6);
878 
879  bit3 = "1";
880  group.write();
881  bitField.read();
882  BOOST_CHECK_EQUAL(static_cast<int>(bitField), 14);
883 
884  device.close();
885 }
886 
887 /**********************************************************************************************************************/
888 
890  BackendFactory::getInstance().setDMapFilePath("logicalnamemap.dmap");
892  device.open("LMAP0");
893 
894  BOOST_CHECK(device.readDeviceInfo().find("Logical name mapping file:") == 0);
895  device.close();
896 }
897 
898 /**********************************************************************************************************************/
899 
900 BOOST_AUTO_TEST_CASE(testParameters) {
901  BackendFactory::getInstance().setDMapFilePath("logicalnamemap.dmap");
903 
904  device.open("PARAMS0");
905 
906  BOOST_CHECK_EQUAL(device.read<int>("SingleWordWithParams"), 42);
907 }
908 
909 /**********************************************************************************************************************/
910 
911 BOOST_AUTO_TEST_CASE(testAccessorPlugins) {
912  BackendFactory::getInstance().setDMapFilePath("logicalnamemap.dmap");
913  ChimeraTK::Device device, target;
914 
915  device.open("LMAP0");
916  target.open("PCIE2");
917 
918  // test scalar register with multiply plugin
919  auto wordUser = target.getScalarRegisterAccessor<int32_t>("BOARD.WORD_USER");
920  auto wordUserScaled = device.getScalarRegisterAccessor<double>("SingleWord_Scaled");
921 
922  wordUser = 2;
923  wordUser.write();
924  wordUserScaled.read();
925  BOOST_CHECK_CLOSE(double(wordUserScaled), 2 * 4.2, 0.001);
926 
927  wordUser = 3;
928  wordUser.write();
929  wordUserScaled.read();
930  BOOST_CHECK_CLOSE(double(wordUserScaled), 3 * 4.2, 0.001);
931 
932  wordUserScaled = 10 / 4.2;
933  wordUserScaled.write();
934  wordUser.read();
935  BOOST_CHECK_EQUAL(int(wordUser), 10);
936 
937  wordUserScaled = 5.4 / 4.2; // rounding down
938  wordUserScaled.write();
939  wordUser.read();
940  BOOST_CHECK_EQUAL(int(wordUser), 5);
941 
942  wordUserScaled = 3.6 / 4.2; // rounding up
943  wordUserScaled.write();
944  wordUser.read();
945  BOOST_CHECK_EQUAL(int(wordUser), 4);
946 
947  wordUserScaled = -5.4 / 4.2; // rounding down
948  wordUserScaled.write();
949  wordUser.read();
950  BOOST_CHECK_EQUAL(int(wordUser), -5);
951 
952  wordUserScaled = -3.6 / 4.2; // rounding up
953  wordUserScaled.write();
954  wordUser.read();
955  BOOST_CHECK_EQUAL(int(wordUser), -4);
956 
957  // test scalar register with two multiply plugins
958  auto wordUserScaledTwice = device.getScalarRegisterAccessor<double>("SingleWord_Scaled_Twice");
959 
960  wordUser = 2;
961  wordUser.write();
962  wordUserScaledTwice.read();
963  BOOST_CHECK_CLOSE(double(wordUserScaledTwice), 2 * 6, 0.001);
964 
965  wordUser = 3;
966  wordUser.write();
967  wordUserScaledTwice.read();
968  BOOST_CHECK_CLOSE(double(wordUserScaledTwice), 3 * 6, 0.001);
969 
970  wordUserScaledTwice = 10. / 6.;
971  wordUserScaledTwice.write();
972  wordUser.read();
973  BOOST_CHECK_EQUAL(int(wordUser), 10);
974 
975  // test array register with multiply plugin
976  auto area = target.getOneDRegisterAccessor<int32_t>("ADC.AREA_DMAABLE");
977  auto areaScaled = device.getOneDRegisterAccessor<double>("FullArea_Scaled");
978 
979  BOOST_CHECK_EQUAL(area.getNElements(), 1024);
980  BOOST_CHECK_EQUAL(areaScaled.getNElements(), 1024);
981 
982  for(int i = 0; i < 1024; ++i) area[i] = 100 + i;
983  area.write();
984  areaScaled.read();
985  for(int i = 0; i < 1024; ++i) BOOST_CHECK_CLOSE(areaScaled[i], (100 + i) * 0.5, 0.001);
986 
987  for(int i = 0; i < 1024; ++i) areaScaled[i] = (-100 + i) / 0.5;
988  areaScaled.write();
989  area.read();
990  for(int i = 0; i < 1024; ++i) BOOST_CHECK_EQUAL(area[i], -100 + i);
991 }
992 
993 /**********************************************************************************************************************/
994 BOOST_AUTO_TEST_CASE(testIsFunctional) {
995  BackendFactory::getInstance().setDMapFilePath("logicalnamemap.dmap");
996  auto exceptionDummyBackend = boost::dynamic_pointer_cast<ExceptionDummy>(
997  BackendFactory::getInstance().createBackend("(ExceptionDummy:1?map=test3.map)"));
998 
999  Device d{"LMAP1"};
1000  d.open();
1001  BOOST_CHECK(d.isFunctional() == true);
1002 
1003  d.setException("Test Exception");
1004  BOOST_CHECK(d.isFunctional() == false);
1005 
1006  d.open();
1007  BOOST_CHECK(d.isFunctional() == true);
1008 
1009  d.close();
1010  BOOST_CHECK(d.isFunctional() == false);
1011 }
1012 
1013 /**********************************************************************************************************************/
1014 
1015 BOOST_AUTO_TEST_CASE(testWithTransferGroup) {
1016  BackendFactory::getInstance().setDMapFilePath("logicalnamemap.dmap");
1017  ChimeraTK::Device device, target1, target2;
1018 
1019  device.open("LMAP0");
1021  a[0].replace(device.getOneDRegisterAccessor<int>("SingleWord"));
1022  a[1].replace(device.getOneDRegisterAccessor<int>("FullArea"));
1023  a[2].replace(device.getOneDRegisterAccessor<int>("PartOfArea"));
1024  a[3].replace(device.getOneDRegisterAccessor<int>("Channel3"));
1025  a[4].replace(device.getOneDRegisterAccessor<int>("Channel4"));
1026  a[5].replace(device.getOneDRegisterAccessor<int>("Constant"));
1027 
1028  // obtain the private pointers to the implementation of the accessor
1029  boost::shared_ptr<NDRegisterAccessor<int>> impl[6];
1030  for(int i = 0; i < 6; i++) {
1031  impl[i] = boost::dynamic_pointer_cast<NDRegisterAccessor<int>>(a[i].getHighLevelImplElement());
1032  }
1033 
1034  // somewhat redundant check: underlying hardware accessors are different for
1035  // all accessors
1036  for(int i = 0; i < 6; i++) {
1037  BOOST_CHECK(impl[i]->getHardwareAccessingElements().size() == 1);
1038  for(int k = i + 1; k < 6; k++) {
1039  BOOST_CHECK(impl[i]->getHardwareAccessingElements()[0] != impl[k]->getHardwareAccessingElements()[0]);
1040  }
1041  }
1042 
1043  // add accessors to the transfer group
1044  TransferGroup group;
1045  for(int i = 0; i < 6; i++) {
1046  group.addAccessor(a[i]);
1047  }
1048 
1049  // now some accessors share the same underlying accessor
1050  BOOST_CHECK(impl[3]->getHardwareAccessingElements()[0] == impl[4]->getHardwareAccessingElements()[0]);
1051  BOOST_CHECK(impl[1]->getHardwareAccessingElements()[0] == impl[2]->getHardwareAccessingElements()[0]);
1052 
1053  // the others are still different
1054  BOOST_CHECK(impl[0]->getHardwareAccessingElements()[0] != impl[1]->getHardwareAccessingElements()[0]);
1055  BOOST_CHECK(impl[0]->getHardwareAccessingElements()[0] != impl[3]->getHardwareAccessingElements()[0]);
1056  BOOST_CHECK(impl[0]->getHardwareAccessingElements()[0] != impl[5]->getHardwareAccessingElements()[0]);
1057  BOOST_CHECK(impl[1]->getHardwareAccessingElements()[0] != impl[3]->getHardwareAccessingElements()[0]);
1058  BOOST_CHECK(impl[1]->getHardwareAccessingElements()[0] != impl[5]->getHardwareAccessingElements()[0]);
1059  BOOST_CHECK(impl[3]->getHardwareAccessingElements()[0] != impl[5]->getHardwareAccessingElements()[0]);
1060 
1061  // write some stuff to the registers via the target device
1062  // Note: there is only one DMA area in the PCIE dummy which are shared by the
1063  // registers accessed by t2 and t3. We
1064  // therefore cannot test those register at the same time!
1065  target1.open("PCIE2");
1066  target2.open("PCIE3");
1067  auto t1 = target1.getOneDRegisterAccessor<int>("BOARD.WORD_USER");
1068  auto t2 = target1.getOneDRegisterAccessor<int>("ADC.AREA_DMAABLE");
1069  auto t3 = target2.getTwoDRegisterAccessor<int>("TEST/NODMA");
1070 
1071  t1[0] = 120;
1072  t1.write();
1073  for(unsigned int i = 0; i < t2.getNElements(); i++) {
1074  t2[i] = 67890 + 66 * signed(i);
1075  }
1076  t2.write();
1077 
1078  // read it back via the transfer group
1079  group.read();
1080 
1081  BOOST_CHECK(a[0][0] == 120);
1082 
1083  BOOST_CHECK(t2.getNElements() == a[1].getNElements());
1084  for(unsigned int i = 0; i < t2.getNElements(); i++) {
1085  BOOST_CHECK(a[1][i] == 67890 + 66 * signed(i));
1086  }
1087 
1088  BOOST_CHECK(a[2].getNElements() == 20);
1089  for(unsigned int i = 0; i < a[2].getNElements(); i++) {
1090  BOOST_CHECK(a[2][i] == 67890 + 66 * signed(i + 10));
1091  }
1092 
1093  BOOST_CHECK(a[5][0] == 42);
1094 
1095  // write something to the multiplexed 2d register
1096  for(unsigned int i = 0; i < t3.getNChannels(); i++) {
1097  for(unsigned int k = 0; k < t3[i].size(); k++) {
1098  t3[i][k] = signed(i * 10 + k);
1099  }
1100  }
1101  t3.write();
1102 
1103  // read it back via transfer group
1104  group.read();
1105 
1106  BOOST_CHECK(a[3].getNElements() == t3[3].size());
1107  for(unsigned int i = 0; i < a[3].getNElements(); i++) {
1108  BOOST_CHECK(a[3][i] == 3 * 10 + signed(i));
1109  }
1110 
1111  BOOST_CHECK(a[4].getNElements() == t3[4].size());
1112  for(unsigned int i = 0; i < a[4].getNElements(); i++) {
1113  BOOST_CHECK(a[4][i] == 4 * 10 + signed(i));
1114  }
1115 
1116  // check that writing to the group fails (has read-only elements)
1117  BOOST_CHECK_THROW(group.write(), ChimeraTK::logic_error);
1118 }
1119 
1120 /**********************************************************************************************************************/
1121 
1122 BOOST_AUTO_TEST_SUITE_END()
ExceptionDummyBackend.h
ChimeraTK::OneDRegisterAccessor::rend
reverse_iterator rend()
Definition: OneDRegisterAccessor.h:67
ChimeraTK::OneDRegisterAccessor::rbegin
reverse_iterator rbegin()
Definition: OneDRegisterAccessor.h:64
ChimeraTK::TwoDRegisterAccessor
Accessor class to read and write 2D registers.
Definition: ForwardDeclarations.h:20
TransferGroup.h
ChimeraTK::OneDRegisterAccessor::end
iterator end()
Definition: OneDRegisterAccessor.h:61
device
ctk::Device device
Definition: testExceptionDummyDevice.cc:18
ChimeraTK::TransferGroup::write
void write(VersionNumber versionNumber={})
Trigger write transfer for all accessors in the group.
Definition: TransferGroup.cc:123
ChimeraTK::Device::close
void close()
Close the device.
Definition: Device.cc:66
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
t2
int t2[(((64 *GB - 1) % 671088649)==268434537) &&(((TB -(64 *GB - 1)+255) % 1792151290)==305159546) ? 1 :-1]
Definition: CheckFileOffsetBits.c:7
ChimeraTK::Device::read
UserType read(const RegisterPath &registerPathName, const AccessModeFlags &flags=AccessModeFlags({})) const
Inefficient convenience function to read a single-word register without obtaining an accessor.
Definition: Device.h:293
ChimeraTK::TransferGroup::addAccessor
void addAccessor(TransferElementAbstractor &accessor)
Add a register accessor to the group.
Definition: TransferGroup.cc:305
ChimeraTK::OneDRegisterAccessor::getNElements
unsigned int getNElements()
Return number of elements/samples in the register.
Definition: OneDRegisterAccessor.h:51
ChimeraTK::Device::readDeviceInfo
std::string readDeviceInfo() const
Return a device information string.
Definition: Device.cc:36
ChimeraTK::TransferGroup
Group multiple data accessors to efficiently trigger data transfers on the whole group.
Definition: TransferGroup.h:26
ChimeraTK::RegisterCatalogue
Catalogue of register information.
Definition: RegisterCatalogue.h:20
ChimeraTK::TransferGroup::read
void read()
Trigger read transfer for all accessors in the group.
Definition: TransferGroup.cc:44
ChimeraTK::NDRegisterAccessorAbstractor::replace
void replace(const NDRegisterAccessorAbstractor< UserType > &newAccessor)
Assign a new accessor to this NDRegisterAccessorAbstractor.
Definition: NDRegisterAccessorAbstractor.h:67
ChimeraTK::OneDRegisterAccessor
Accessor class to read and write registers transparently by using the accessor object like a vector o...
Definition: OneDRegisterAccessor.h:20
ChimeraTK::RegisterCatalogue::getRegister
RegisterInfo getRegister(const RegisterPath &registerPathName) const
Get register information for a given full path name.
Definition: RegisterCatalogue.cc:43
Device.h
ChimeraTK::Device::getRegisterCatalogue
RegisterCatalogue getRegisterCatalogue() const
Return the register catalogue with detailed information on all registers.
Definition: Device.cc:22
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(testExceptions)
Definition: testLMapBackend.cpp:21
ChimeraTK::TransferElementAbstractor::getHighLevelImplElement
const boost::shared_ptr< TransferElement > & getHighLevelImplElement()
Obtain the highest level implementation TransferElement.
Definition: TransferElementAbstractor.h:145
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
DummyRegisterAccessor.h
ChimeraTK::Device::getTwoDRegisterAccessor
TwoDRegisterAccessor< UserType > getTwoDRegisterAccessor(const RegisterPath &registerPathName, size_t numberOfElements=0, size_t elementsOffset=0, const AccessModeFlags &flags=AccessModeFlags({})) const
Get a TwoDRegisterAccessor object for the given register.
Definition: Device.h:283
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::OneDRegisterAccessor::begin
iterator begin()
Definition: OneDRegisterAccessor.h:58
ChimeraTK::VersionNumber
Class for generating and holding version numbers without exposing a numeric representation.
Definition: VersionNumber.h:23
ChimeraTK::Device::isOpened
bool isOpened() const
Check if the device is currently opened.
Definition: Device.cc:73
ChimeraTK::Device::write
void write(const RegisterPath &registerPathName, UserType value, const AccessModeFlags &flags=AccessModeFlags({}))
Inefficient convenience function to write a single-word register without obtaining an accessor.
Definition: Device.h:314
ChimeraTK
Definition: DummyBackend.h:16
UnifiedBackendTest.h
ChimeraTK::logic_error
Exception thrown when a logic error has occured.
Definition: Exception.h:51