ChimeraTK-DeviceAccess  03.18.00
testLMapFile.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 
10 #include "LogicalNameMapParser.h"
11 
12 using namespace ChimeraTK;
13 
14 BOOST_AUTO_TEST_SUITE(LMapFileTestSuite)
15 
16 /**********************************************************************************************************************/
17 
18 void testErrorInDmapFileSingle(std::string fileName) {
19  std::map<std::string, LNMVariable> variables;
20  LogicalNameMapParser lmap({}, variables);
21  BOOST_CHECK_THROW(lmap.parseFile(fileName), ChimeraTK::logic_error);
22 }
23 
24 /**********************************************************************************************************************/
25 
26 BOOST_AUTO_TEST_CASE(testFileNotFound) {
27  std::cout << "******************************************************" << std::endl;
28  std::cout << "*** Warnings ahead. Testing for not existing file. ***" << std::endl;
29  testErrorInDmapFileSingle("notExisting.xlmap");
30  std::cout << "*** End of not existing file test. *******************" << std::endl;
31  std::cout << "******************************************************" << std::endl;
32 }
33 
34 /**********************************************************************************************************************/
35 
36 BOOST_AUTO_TEST_CASE(testErrorInDmapFile) {
37  std::cout << "********************************************************" << std::endl;
38  std::cout << "*** Warnings ahead. Testing for invalid xlmap files. ***" << std::endl;
39  testErrorInDmapFileSingle("invalid1.xlmap");
40  testErrorInDmapFileSingle("invalid2.xlmap");
41  testErrorInDmapFileSingle("invalid3.xlmap");
42  testErrorInDmapFileSingle("invalid4.xlmap");
43  testErrorInDmapFileSingle("invalid5.xlmap");
44  testErrorInDmapFileSingle("invalid6.xlmap");
45  testErrorInDmapFileSingle("invalid7.xlmap");
46  testErrorInDmapFileSingle("invalid8.xlmap");
47  testErrorInDmapFileSingle("invalidStartIndex1.xlmap");
48  testErrorInDmapFileSingle("invalidStartIndex2.xlmap");
49  testErrorInDmapFileSingle("invalidDuplicateName.xlmap");
50  std::cout << "*** End of invalid xlmap file test. ********************" << std::endl;
51  std::cout << "********************************************************" << std::endl;
52 }
53 
54 /**********************************************************************************************************************/
55 
56 BOOST_AUTO_TEST_CASE(testParseFile) {
57  std::map<std::string, LNMVariable> variables;
58  LogicalNameMapParser lmap({}, variables);
59  auto catalogue = lmap.parseFile("valid.xlmap");
60 
61  auto info = catalogue.getBackendRegister("SingleWord");
62  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::REGISTER);
63  BOOST_CHECK(info.deviceName == "PCIE2");
64  BOOST_CHECK(info.registerName == "BOARD.WORD_USER");
65 
66  info = catalogue.getBackendRegister("PartOfArea");
67  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::REGISTER);
68  BOOST_CHECK(info.deviceName == "PCIE2");
69  BOOST_CHECK(info.registerName == "ADC.AREA_DMAABLE");
70  BOOST_CHECK(info.firstIndex == 10);
71  BOOST_CHECK(info.length == 20);
72 
73  info = catalogue.getBackendRegister("FullArea");
74  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::REGISTER);
75  BOOST_CHECK(info.deviceName == "PCIE2");
76  BOOST_CHECK(info.registerName == "ADC.AREA_DMAABLE");
77 
78  info = catalogue.getBackendRegister("usingHexStartIndex");
79  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::REGISTER);
80  BOOST_CHECK(info.registerName == "ADC.AREA_DMAABLE");
81  BOOST_CHECK(info.firstIndex == 0x10);
82 
83  info = catalogue.getBackendRegister("Channel3");
84  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::CHANNEL);
85  BOOST_CHECK(info.deviceName == "PCIE3");
86  BOOST_CHECK(info.registerName == "TEST.NODMA");
87  BOOST_CHECK(info.channel == 3);
88 
89  info = catalogue.getBackendRegister("Channel4");
90  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::CHANNEL);
91  BOOST_CHECK(info.deviceName == "PCIE3");
92  BOOST_CHECK(info.registerName == "TEST.NODMA");
93  BOOST_CHECK(info.channel == 4);
94 
95  info = catalogue.getBackendRegister("Constant");
96  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::CONSTANT);
97  BOOST_CHECK(info.valueType == ChimeraTK::DataType::int32);
98  BOOST_CHECK(boost::fusion::at_key<int32_t>(variables.at(info.name).valueTable.table).latestValue[0] == 42);
99 
100  info = catalogue.getBackendRegister("/MyModule/SomeSubmodule/Variable");
101  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
102  BOOST_CHECK(info.valueType == ChimeraTK::DataType::int32);
103  BOOST_CHECK(boost::fusion::at_key<int32_t>(variables.at(info.name).valueTable.table).latestValue[0] == 2);
104  info = catalogue.getBackendRegister("MyModule/ConfigurableChannel");
105  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::CHANNEL);
106  BOOST_CHECK(info.deviceName == "PCIE3");
107  BOOST_CHECK(info.registerName == "TEST.NODMA");
108  BOOST_CHECK(info.channel == 42);
109 
110  info = catalogue.getBackendRegister("ArrayConstant");
111  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::CONSTANT);
112  BOOST_CHECK(info.valueType == ChimeraTK::DataType::int32);
113  BOOST_CHECK(info.length == 5);
114  BOOST_CHECK(boost::fusion::at_key<int32_t>(variables.at(info.name).valueTable.table).latestValue.size() == 5);
115  BOOST_CHECK(boost::fusion::at_key<int32_t>(variables.at(info.name).valueTable.table).latestValue[0] == 1111);
116  BOOST_CHECK(boost::fusion::at_key<int32_t>(variables.at(info.name).valueTable.table).latestValue[1] == 2222);
117  BOOST_CHECK(boost::fusion::at_key<int32_t>(variables.at(info.name).valueTable.table).latestValue[2] == 3333);
118  BOOST_CHECK(boost::fusion::at_key<int32_t>(variables.at(info.name).valueTable.table).latestValue[3] == 4444);
119  BOOST_CHECK(boost::fusion::at_key<int32_t>(variables.at(info.name).valueTable.table).latestValue[4] == 5555);
120 
121  info = catalogue.getBackendRegister("Bit0ofVar");
122  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::BIT);
123  BOOST_CHECK(info.deviceName == "this");
124  BOOST_CHECK(info.registerName == "/MyModule/SomeSubmodule/Variable");
125  BOOST_CHECK(info.bit == 0);
126 
127  info = catalogue.getBackendRegister("Bit1ofVar");
128  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::BIT);
129  BOOST_CHECK(info.deviceName == "this");
130  BOOST_CHECK(info.registerName == "/MyModule/SomeSubmodule/Variable");
131  BOOST_CHECK(info.bit == 1);
132 
133  info = catalogue.getBackendRegister("Bit2ofVar");
134  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::BIT);
135  BOOST_CHECK(info.deviceName == "this");
136  BOOST_CHECK(info.registerName == "/MyModule/SomeSubmodule/Variable");
137  BOOST_CHECK(info.bit == 2);
138 
139  info = catalogue.getBackendRegister("Bit3ofVar");
140  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::BIT);
141  BOOST_CHECK(info.deviceName == "this");
142  BOOST_CHECK(info.registerName == "/MyModule/SomeSubmodule/Variable");
143  BOOST_CHECK(info.bit == 3);
144 
145  info = catalogue.getBackendRegister("/var_int8");
146  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
147  BOOST_CHECK(info.valueType == ChimeraTK::DataType::int8);
148  BOOST_CHECK(boost::fusion::at_key<int8_t>(variables.at(info.name).valueTable.table).latestValue[0] == -128);
149  info = catalogue.getBackendRegister("/var_uint8");
150  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
151  BOOST_CHECK(info.valueType == ChimeraTK::DataType::uint8);
152  BOOST_CHECK(boost::fusion::at_key<uint8_t>(variables.at(info.name).valueTable.table).latestValue[0] == 255);
153  info = catalogue.getBackendRegister("/var_int16");
154  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
155  BOOST_CHECK(info.valueType == ChimeraTK::DataType::int16);
156  BOOST_CHECK(boost::fusion::at_key<int16_t>(variables.at(info.name).valueTable.table).latestValue[0] == -32768);
157  info = catalogue.getBackendRegister("/var_uint16");
158  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
159  BOOST_CHECK(info.valueType == ChimeraTK::DataType::uint16);
160  BOOST_CHECK(boost::fusion::at_key<uint16_t>(variables.at(info.name).valueTable.table).latestValue[0] == 65535);
161  info = catalogue.getBackendRegister("/var_int32");
162  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
163  BOOST_CHECK(info.valueType == ChimeraTK::DataType::int32);
164  BOOST_CHECK(boost::fusion::at_key<int32_t>(variables.at(info.name).valueTable.table).latestValue[0] == -1);
165  info = catalogue.getBackendRegister("/var_uint32");
166  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
167  BOOST_CHECK(info.valueType == ChimeraTK::DataType::uint32);
168  BOOST_CHECK(boost::fusion::at_key<uint32_t>(variables.at(info.name).valueTable.table).latestValue[0] == 0xfffffffe);
169  info = catalogue.getBackendRegister("/var_int64");
170  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
171  BOOST_CHECK(info.valueType == ChimeraTK::DataType::int64);
172  BOOST_CHECK(boost::fusion::at_key<int64_t>(variables.at(info.name).valueTable.table).latestValue[0] == -1);
173  info = catalogue.getBackendRegister("/var_uint64");
174  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
175  BOOST_CHECK(info.valueType == ChimeraTK::DataType::uint64);
176  BOOST_CHECK(boost::fusion::at_key<uint64_t>(variables.at(info.name).valueTable.table).latestValue[0] == 0);
177  info = catalogue.getBackendRegister("/var_float32");
178  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
179  BOOST_CHECK(info.valueType == ChimeraTK::DataType::float32);
180  BOOST_CHECK_CLOSE(
181  boost::fusion::at_key<float>(variables.at(info.name).valueTable.table).latestValue[0], -1.2345e10, 1e-5);
182  info = catalogue.getBackendRegister("/var_float64");
183  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
184  BOOST_CHECK(info.valueType == ChimeraTK::DataType::float64);
185  BOOST_CHECK_CLOSE(
186  boost::fusion::at_key<double>(variables.at(info.name).valueTable.table).latestValue[0], -1.23456789e20, 1e-10);
187  info = catalogue.getBackendRegister("/var_string");
188  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::VARIABLE);
189  BOOST_CHECK(info.valueType == ChimeraTK::DataType::string);
190  BOOST_CHECK(
191  boost::fusion::at_key<std::string>(variables.at(info.name).valueTable.table).latestValue[0] == "stringValue");
192 }
193 
194 /**********************************************************************************************************************/
195 
196 BOOST_AUTO_TEST_CASE(testParameters) {
197  {
198  std::map<std::string, std::string> params;
199  params["ParamA"] = "ValueA";
200  params["ParamB"] = "ValueB";
201  std::map<std::string, LNMVariable> variables;
202 
203  LogicalNameMapParser lmap(params, variables);
204  auto catalogue = lmap.parseFile("withParams.xlmap");
205 
206  auto info = catalogue.getBackendRegister("SingleWordWithParams");
207  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::REGISTER);
208  BOOST_CHECK(info.deviceName == "ValueA");
209  BOOST_CHECK(info.registerName == "ValueB");
210  }
211 
212  {
213  std::map<std::string, std::string> params;
214  params["ParamA"] = "OtherValues";
215  params["ParamB"] = "ThisTime";
216  std::map<std::string, LNMVariable> variables;
217 
218  LogicalNameMapParser lmap(params, variables);
219  auto catalogue = lmap.parseFile("withParams.xlmap");
220 
221  auto info = catalogue.getBackendRegister("SingleWordWithParams");
222  BOOST_CHECK(info.targetType == LNMBackendRegisterInfo::TargetType::REGISTER);
223  BOOST_CHECK(info.deviceName == "OtherValues");
224  BOOST_CHECK(info.registerName == "ThisTime");
225  }
226 }
227 
228 BOOST_AUTO_TEST_SUITE_END()
ChimeraTK::DataType::uint8
@ uint8
Unsigned 8 bit integer.
Definition: SupportedUserTypes.h:608
ChimeraTK::DataType::float64
@ float64
Double precision float.
Definition: SupportedUserTypes.h:616
testErrorInDmapFileSingle
void testErrorInDmapFileSingle(std::string fileName)
Definition: testLMapFile.cpp:18
ChimeraTK::DataType::float32
@ float32
Single precision float.
Definition: SupportedUserTypes.h:615
ChimeraTK::DataType::int32
@ int32
Signed 32 bit integer.
Definition: SupportedUserTypes.h:611
ChimeraTK::LogicalNameMapParser
Logical name map: store information from xlmap file and provide it to the LogicalNameMappingBackend a...
Definition: LogicalNameMapParser.h:26
ChimeraTK::DataType::uint32
@ uint32
Unsigned 32 bit integer.
Definition: SupportedUserTypes.h:612
ChimeraTK::DataType::uint16
@ uint16
Unsigned 16 bit integer.
Definition: SupportedUserTypes.h:610
LogicalNameMapParser.h
lmap
std::string lmap
Definition: testDoubleBuffering.cpp:74
ChimeraTK::DataType::int64
@ int64
Signed 64 bit integer.
Definition: SupportedUserTypes.h:613
ChimeraTK::DataType::int8
@ int8
Signed 8 bit integer.
Definition: SupportedUserTypes.h:607
BOOST_AUTO_TEST_CASE
BOOST_AUTO_TEST_CASE(testFileNotFound)
Definition: testLMapFile.cpp:26
LNMBackendRegisterInfo.h
ChimeraTK::DataType::int16
@ int16
Signed 16 bit integer.
Definition: SupportedUserTypes.h:609
ChimeraTK
Definition: DummyBackend.h:16
ChimeraTK::DataType::string
@ string
std::string
Definition: SupportedUserTypes.h:617
ChimeraTK::DataType::uint64
@ uint64
Unsigned 64 bit integer.
Definition: SupportedUserTypes.h:614
ChimeraTK::logic_error
Exception thrown when a logic error has occured.
Definition: Exception.h:51