4 #define BOOST_TEST_DYN_LINK
5 #define BOOST_TEST_MODULE testDummyBackend
13 #include <boost/bind/bind.hpp>
14 #include <boost/function.hpp>
15 #include <boost/lambda/lambda.hpp>
20 #define BOOST_NO_EXCEPTIONS
21 #include <boost/test/unit_test.hpp>
22 #undef BOOST_NO_EXCEPTIONS
24 using namespace boost::unit_test_framework;
30 #define TEST_MAPPING_FILE "mtcadummy_withoutModules.map"
31 #define FIRMWARE_REGISTER_STRING "WORD_FIRMWARE"
32 #define STATUS_REGISTER_STRING "WORD_STATUS"
33 #define USER_REGISTER_STRING "WORD_USER"
34 #define CLOCK_MUX_REGISTER_STRING "WORD_CLK_MUX"
35 #define CLOCK_RESET_REGISTER_STRING "WORD_CLK_RST"
36 #define READ_ONLY_REGISTER_STRING "WORD_READ_ONLY"
38 #define EXISTING_DEVICE "(TestableDummy?map=" TEST_MAPPING_FILE ")"
39 #define NON_EXISTING_DEVICE "DUMMY9"
41 static BackendFactory& FactoryInstance = BackendFactory::getInstance();
53 using DummyBackend::checkSizeIsMultipleOfWordSize;
54 using DummyBackend::_barContents;
55 using DummyBackend::setReadOnly;
57 using DummyBackend::setWriteCallbackFunction;
58 using DummyBackend::writeRegisterWithoutCallback;
59 using DummyBackend::isWriteRangeOverlap;
60 using DummyBackend::_readOnlyAddresses;
61 using DummyBackend::_writeCallbackFunctions;
63 static boost::shared_ptr<DeviceBackend>
createInstance(std::string, std::map<std::string, std::string> parameters) {
69 std::cout <<
"TestableDummyBackend::BackendRegisterer: registering backend type TestableDummy" << std::endl;
80 Fixture_t() : a(0), b(0), c(0), _backendInstance() {
82 std::list<std::string> parameters;
89 friend class DummyBackendTestSuite;
105 _backendInstance->open();
128 uint64_t offset = 0x40;
130 int32_t dataContent = -1;
132 BOOST_CHECK_NO_THROW(dummyBackend->
read(bar, offset, &dataContent, 4));
133 BOOST_CHECK(dataContent == 0);
135 BOOST_CHECK_NO_THROW(dummyBackend->
write(bar, offset, &dataContent, 4));
139 dummyBackend->
read(bar, offset, &dataContent, 4);
140 BOOST_CHECK(dataContent == 47);
145 bar,
static_cast<uint64_t
>(dummyBackend->
_barContents[bar].size() *
sizeof(int32_t)), &dataContent, 4),
149 bar,
static_cast<uint64_t
>(dummyBackend->
_barContents[bar].size() *
sizeof(int32_t)), &dataContent, 4),
159 uint64_t offset = 0x20;
161 size_t sizeInBytes = 0x10;
162 size_t sizeInWords = 0x4;
163 std::vector<int32_t> dataContent(sizeInWords, -1);
165 BOOST_CHECK_NO_THROW(dummyBackend->
read(bar, offset, &(dataContent[0]), sizeInBytes));
166 for(std::vector<int32_t>::iterator dataIter = dataContent.begin(); dataIter != dataContent.end(); ++dataIter) {
167 std::stringstream errorMessage;
168 errorMessage <<
"*dataIter = " << *dataIter;
169 BOOST_CHECK_MESSAGE(*dataIter == 0, errorMessage.str());
172 for(
unsigned int index = 0; index < dataContent.size(); ++index) {
173 dataContent[index] =
static_cast<int32_t
>((index + 1) * (index + 1));
175 BOOST_CHECK_NO_THROW(dummyBackend->
write(bar, offset, &(dataContent[0]), sizeInBytes));
177 std::for_each(dataContent.begin(), dataContent.end(), boost::lambda::_1 = -1);
180 dummyBackend->
read(bar, offset, &(dataContent[0]), sizeInBytes);
183 for(
unsigned int index = 0; index < dataContent.size(); ++index) {
184 BOOST_CHECK(dataContent[index] ==
static_cast<int32_t
>((index + 1) * (index + 1)));
190 dummyBackend->
read(bar,
static_cast<uint64_t
>(dummyBackend->
_barContents[bar].size() *
sizeof(int32_t)),
191 &(dataContent[0]), sizeInBytes),
194 dummyBackend->
write(bar,
static_cast<uint64_t
>(dummyBackend->
_barContents[bar].size() *
sizeof(int32_t)),
195 &(dataContent[0]), sizeInBytes),
199 dataContent.resize(dummyBackend->
_barContents[bar].size());
201 dummyBackend->
read(bar, offset, &(dataContent[0]), dummyBackend->
_barContents[bar].size() *
sizeof(int32_t)),
204 dummyBackend->
write(bar, offset, &(dataContent[0]), dummyBackend->
_barContents[bar].size() *
sizeof(int32_t)),
215 std::string deviceInfo;
216 auto dummyBackend = FactoryInstance.
createBackend(
"DUMMYD0");
217 deviceInfo = dummyBackend->readDeviceInfo();
218 std::cout << deviceInfo << std::endl;
222 std::string absolutePathToMapfile =
225 BOOST_CHECK(deviceInfo == (std::string(
"DummyBackend with mapping file ") + absolutePathToMapfile));
235 uint64_t offset = 0x20;
237 size_t sizeInBytes = 0x10;
238 size_t sizeInWords = 0x4;
239 std::stringstream errorMessage;
240 errorMessage <<
"This register should have 4 words. If you changed your "
241 "mapping you have to adapt the testReadOnly() test.";
242 BOOST_REQUIRE_MESSAGE(sizeInWords == 4, errorMessage.str());
244 std::vector<int32_t> dataContent(sizeInWords);
245 for(
unsigned int index = 0; index < dataContent.size(); ++index) {
246 dataContent[index] =
static_cast<int32_t
>((index + 1) * (index + 1));
248 dummyBackend->
write(bar, offset, &(dataContent[0]), sizeInBytes);
253 std::for_each(dataContent.begin(), dataContent.end(), boost::lambda::_1 = 42);
254 dummyBackend->
write(bar, offset, &(dataContent[0]), sizeInBytes);
255 std::for_each(dataContent.begin(), dataContent.end(), boost::lambda::_1 = -1);
256 dummyBackend->
read(bar, offset, &(dataContent[0]), sizeInBytes);
257 BOOST_CHECK(dataContent[0] == 1);
258 BOOST_CHECK(dataContent[1] == 42);
259 BOOST_CHECK(dataContent[2] == 42);
260 BOOST_CHECK(dataContent[3] == 42);
266 std::for_each(dataContent.begin(), dataContent.end(), boost::lambda::_1 = 29);
268 for(
size_t index = 0; index < sizeInWords; ++index) {
269 dummyBackend->
write(bar, offset + index *
sizeof(int32_t), &dataContent[index], 4);
272 std::for_each(dataContent.begin(), dataContent.end(), boost::lambda::_1 = -1);
273 dummyBackend->
read(bar, offset, &(dataContent[0]), sizeInBytes);
274 BOOST_CHECK(dataContent[0] == 1);
275 BOOST_CHECK(dataContent[1] == 29);
276 BOOST_CHECK(dataContent[2] == 42);
277 BOOST_CHECK(dataContent[3] == 42);
280 int32_t originalNextDataWord;
281 dummyBackend->
read(bar, offset + sizeInBytes, &originalNextDataWord, 4);
282 int32_t writeWord = originalNextDataWord + 1;
283 dummyBackend->
write(bar, offset + sizeInBytes, &writeWord, 4);
284 int32_t readbackWord;
285 dummyBackend->
read(bar, offset + sizeInBytes, &readbackWord, 4);
286 BOOST_CHECK(originalNextDataWord + 1 == readbackWord);
297 BOOST_REQUIRE(dummyBackend->
_barContents[0].size() >= 13);
306 int32_t dataWord(42);
307 dummyBackend->
write(
static_cast<uint64_t
>(0), 12, &dataWord, 4);
308 BOOST_CHECK(f.
a == 0);
309 BOOST_CHECK(f.
b == 0);
310 BOOST_CHECK(f.
c == 0);
312 dummyBackend->
write(
static_cast<uint64_t
>(0), 20, &dataWord, 4);
313 BOOST_CHECK(f.
a == 0);
314 BOOST_CHECK(f.
b == 0);
315 BOOST_CHECK(f.
c == 1);
316 dummyBackend->
write(
static_cast<uint64_t
>(0), 24, &dataWord, 4);
317 BOOST_CHECK(f.
a == 0);
318 BOOST_CHECK(f.
b == 0);
319 BOOST_CHECK(f.
c == 2);
320 dummyBackend->
write(
static_cast<uint64_t
>(0), 28, &dataWord, 4);
321 BOOST_CHECK(f.
a == 0);
322 BOOST_CHECK(f.
b == 1);
323 BOOST_CHECK(f.
c == 3);
324 dummyBackend->
write(
static_cast<uint64_t
>(0), 32, &dataWord, 4);
325 BOOST_CHECK(f.
a == 0);
326 BOOST_CHECK(f.
b == 1);
327 BOOST_CHECK(f.
c == 3);
328 dummyBackend->
write(
static_cast<uint64_t
>(0), 36, &dataWord, 4);
329 BOOST_CHECK(f.
a == 1);
330 BOOST_CHECK(f.
b == 2);
331 BOOST_CHECK(f.
c == 3);
332 dummyBackend->
write(
static_cast<uint64_t
>(0), 40, &dataWord, 4);
333 BOOST_CHECK(f.
a == 1);
334 BOOST_CHECK(f.
b == 2);
335 BOOST_CHECK(f.
c == 3);
336 dummyBackend->
write(
static_cast<uint64_t
>(0), 44, &dataWord, 4);
337 BOOST_CHECK(f.
a == 1);
338 BOOST_CHECK(f.
b == 2);
339 BOOST_CHECK(f.
c == 3);
340 dummyBackend->
write(
static_cast<uint64_t
>(0), 48, &dataWord, 4);
341 BOOST_CHECK(f.
a == 1);
342 BOOST_CHECK(f.
b == 3);
343 BOOST_CHECK(f.
c == 3);
345 std::vector<int32_t> dataContents(8, 42);
349 dummyBackend->
write(
static_cast<uint64_t
>(0), 20, &(dataContents[0]), 32);
350 BOOST_CHECK(f.
a == 1);
351 BOOST_CHECK(f.
b == 1);
352 BOOST_CHECK(f.
c == 1);
353 dummyBackend->
write(
static_cast<uint64_t
>(0), 20, &(dataContents[0]), 8);
354 BOOST_CHECK(f.
a == 1);
355 BOOST_CHECK(f.
b == 1);
356 BOOST_CHECK(f.
c == 2);
357 dummyBackend->
write(
static_cast<uint64_t
>(0), 20, &(dataContents[0]), 12);
358 BOOST_CHECK(f.
a == 1);
359 BOOST_CHECK(f.
b == 2);
360 BOOST_CHECK(f.
c == 3);
361 dummyBackend->
write(
static_cast<uint64_t
>(0), 28, &(dataContents[0]), 24);
362 BOOST_CHECK(f.
a == 2);
363 BOOST_CHECK(f.
b == 3);
364 BOOST_CHECK(f.
c == 4);
365 dummyBackend->
write(
static_cast<uint64_t
>(0), 32, &(dataContents[0]), 16);
366 BOOST_CHECK(f.
a == 3);
367 BOOST_CHECK(f.
b == 4);
368 BOOST_CHECK(f.
c == 4);
369 dummyBackend->
write(
static_cast<uint64_t
>(0), 40, &(dataContents[0]), 8);
370 BOOST_CHECK(f.
a == 3);
371 BOOST_CHECK(f.
b == 4);
372 BOOST_CHECK(f.
c == 4);
373 dummyBackend->
write(
static_cast<uint64_t
>(0), 4, &(dataContents[0]), 8);
374 BOOST_CHECK(f.
a == 3);
375 BOOST_CHECK(f.
b == 4);
376 BOOST_CHECK(f.
c == 4);
385 int32_t dataWord = 42;
388 BOOST_CHECK(f.
a == 0);
389 BOOST_CHECK(f.
b == 0);
390 BOOST_CHECK(f.
c == 0);
393 dummyBackend->
read(
static_cast<uint64_t
>(0), 40, &dataWord, 4);
395 int32_t readbackDataWord;
396 dummyBackend->
read(
static_cast<uint64_t
>(0), 40, &readbackDataWord, 4);
397 BOOST_CHECK(readbackDataWord == dataWord + 1);
404 dummyDevice.
open(
"DUMMYD0");
418 for(
auto& info : dummyCatalogue) {
424 BOOST_CHECK(found ==
false);
427 for(
auto& info : dummyCatalogue) {
433 BOOST_CHECK(found ==
true);
440 BOOST_CHECK(info.isWriteable());
444 BOOST_CHECK(ro_register.isReadOnly());
445 BOOST_CHECK(!ro_register.isWriteable());
446 BOOST_CHECK(!ro_register_dw.isReadOnly());
447 BOOST_CHECK(ro_register_dw.isWriteable());
452 ro_register_dw.write();
455 BOOST_CHECK_EQUAL(ro_register, ro_register_dw);
461 BOOST_CHECK_NE(ro_register, 84);
462 BOOST_CHECK_EQUAL(ro_register, ro_register_dw);
470 dummyDevice.
open(
"DUMMYD0");
475 const std::string DUMMY_INTERRUPT{
"/DUMMY_INTERRUPT_3"};
480 for(
auto& info : dummyCatalogue) {
481 if(info.getRegisterName() == DUMMY_INTERRUPT) {
486 BOOST_CHECK(found ==
false);
490 auto info = dummyCatalogue.getRegister(DUMMY_INTERRUPT);
491 BOOST_CHECK_EQUAL(info.getRegisterName(), DUMMY_INTERRUPT);
492 BOOST_CHECK(!info.isReadable());
493 BOOST_CHECK(info.isWriteable());
494 BOOST_TEST(info.getDataDescriptor().fundamentalType() == DataDescriptor::FundamentalType::nodata);
501 dummyDevice.
open(
"DUMMYD0");
504 const std::string DUMMY_INTERRUPT{
"/DUMMY_INTERRUPT_3"};
508 BOOST_CHECK(!dummyAsyncAccessor.isReadable());
509 BOOST_CHECK(!dummyAsyncAccessor.isReadOnly());
510 BOOST_CHECK(dummyAsyncAccessor.isWriteable());
513 const std::string INTERRUPT{
"/!3"};
515 asyncAccessor.
read();
517 BOOST_CHECK(!asyncAccessor.readNonBlocking());
518 dummyAsyncAccessor.write();
519 BOOST_CHECK(asyncAccessor.readNonBlocking());
520 BOOST_CHECK(!asyncAccessor.readNonBlocking());
521 dummyAsyncAccessor.write();
522 dummyAsyncAccessor.write();
523 BOOST_CHECK(asyncAccessor.readNonBlocking());
524 BOOST_CHECK(asyncAccessor.readNonBlocking());
525 BOOST_CHECK(!asyncAccessor.readNonBlocking());
535 BOOST_CHECK(range24_8_0.
offset == 24);
537 BOOST_CHECK(range24_8_0.
bar == 0);
546 BOOST_CHECK((range24_8_0 < range24_8_1));
547 BOOST_CHECK((range24_8_0 < range12_8_1));
548 BOOST_CHECK((range24_8_0 < range28_8_0));
549 BOOST_CHECK((range24_8_0 < range28_8_1));
550 BOOST_CHECK(!(range24_8_0 < range24_12_0));
553 BOOST_CHECK(!(range24_8_1 < range24_8_0));
554 BOOST_CHECK(!(range12_8_1 < range24_8_0));
555 BOOST_CHECK(!(range28_8_0 < range24_8_0));
556 BOOST_CHECK(!(range28_8_1 < range24_8_0));
557 BOOST_CHECK(!(range24_12_0 < range24_8_0));
568 BOOST_CHECK(overlap ==
false);
580 dummyBackend->
close();
591 std::map<uint64_t, std::vector<int32_t>>::const_iterator bar0Iter = dummyBackend->
_barContents.find(0);
592 BOOST_REQUIRE(bar0Iter != dummyBackend->
_barContents.end());
593 BOOST_CHECK(bar0Iter->second.size() == 0x53);
594 std::map<uint64_t, std::vector<int32_t>>::const_iterator bar2Iter = dummyBackend->
_barContents.find(2);
595 BOOST_REQUIRE(bar2Iter != dummyBackend->
_barContents.end());
596 BOOST_CHECK(bar2Iter->second.size() == 0x400);
601 BOOST_CHECK(dummyBackend->
isOpen());
603 dummyBackend->
open();
604 BOOST_CHECK(dummyBackend->
isOpen());
606 dummyBackend->
close();
607 BOOST_CHECK(dummyBackend->
isOpen() ==
false);
609 dummyBackend->
close();
610 BOOST_CHECK(dummyBackend->
isOpen() ==
false);
633 std::map<std::string, std::string> pararmeters;
639 BOOST_CHECK(backendInstance);
641 BOOST_CHECK(backendInstance->isOpen() ==
false);
644 auto instance2 = BackendFactory::getInstance().createBackend(cdd1);
646 auto instance3 = BackendFactory::getInstance().createBackend(cdd3);
647 auto instance4 = BackendFactory::getInstance().createBackend(cdd3);
649 auto instance5 = BackendFactory::getInstance().createBackend(cdd5);
652 BOOST_CHECK(backendInstance.get() == instance2.get());
654 BOOST_CHECK(instance3.get() == instance4.get());
657 BOOST_CHECK(backendInstance.get() != instance3.get());
658 BOOST_CHECK(backendInstance.get() != instance5.get());
659 BOOST_CHECK(instance3.get() != instance5.get());