4 #define BOOST_TEST_DYN_LINK
6 #define BOOST_TEST_MODULE NumericAddressedBackendUnified
8 #include <boost/test/unit_test.hpp>
9 using namespace boost::unit_test_framework;
30 BOOST_AUTO_TEST_SUITE(NumericAddressedBackendUnifiedTestSuite)
34 static std::string
cdd(
"(ExceptionDummy:1?map=test3.map)");
36 boost::dynamic_pointer_cast<ExceptionDummy>(BackendFactory::getInstance().createBackend(
cdd));
38 static std::string cddMuxed(
"(ExceptionDummy:1?map=muxedDataAcessor.map)");
39 static auto exceptionDummyMuxed =
40 boost::dynamic_pointer_cast<ExceptionDummy>(BackendFactory::getInstance().createBackend(cddMuxed));
45 std::string
path() {
return "/Integers/signed32"; }
58 .disableAsyncReadInconsistency()
59 .disableSwitchReadOnly()
60 .disableSwitchWriteOnly()
61 .disableTestWriteNeverLosesData()
62 .enableTestRawTransfer();
66 template<
typename Type>
67 std::vector<std::vector<Type>>
generateValue([[maybe_unused]]
bool raw =
false) {
71 template<
typename UserType>
72 std::vector<std::vector<UserType>>
getRemoteValue([[maybe_unused]]
bool raw =
false) {
86 std::string
path() {
return "/Integers/signed32_async"; }
101 .disableAsyncReadInconsistency()
102 .disableSwitchReadOnly()
103 .disableSwitchWriteOnly()
104 .disableTestWriteNeverLosesData()
105 .enableTestRawTransfer();
109 template<
typename Type>
110 std::vector<std::vector<Type>>
generateValue([[maybe_unused]]
bool raw =
false) {
114 template<
typename UserType>
115 std::vector<std::vector<UserType>>
getRemoteValue([[maybe_unused]]
bool raw =
false) {
120 acc = generateValue<minimumUserType>()[0][0];
135 std::string
path() {
return "/Integers/signed32_async/DUMMY_WRITEABLE"; }
150 .disableAsyncReadInconsistency()
151 .disableSwitchReadOnly()
152 .disableSwitchWriteOnly()
153 .disableTestWriteNeverLosesData()
154 .enableTestRawTransfer();
158 template<
typename Type>
159 std::vector<std::vector<Type>>
generateValue([[maybe_unused]]
bool raw =
false) {
163 template<
typename UserType>
164 std::vector<std::vector<UserType>>
getRemoteValue([[maybe_unused]]
bool raw =
false) {
169 acc = generateValue<minimumUserType>()[0][0];
185 template<
typename Derived,
typename rawUserType>
187 Derived* derived{
static_cast<Derived*
>(
this)};
204 int32_t lastPadding{0};
205 bool printPaddingChangedMessage{
true};
209 .disableAsyncReadInconsistency()
210 .disableSwitchReadOnly()
211 .disableSwitchWriteOnly()
212 .disableTestWriteNeverLosesData()
213 .enableTestRawTransfer();
219 rawUserType
get() {
return (acc & derived->bitmask) >> derived->bitshift; }
221 void set(rawUserType val) {
222 acc &= ~derived->bitmask;
224 printPaddingChangedMessage =
true;
225 acc |= (val << derived->bitshift) & derived->bitmask;
229 template<
typename Type>
231 rawUserType newRawValue =
static_cast<rawUserType
>(get() + derived->rawIncrement);
232 Type v = (
raw ? newRawValue : (newRawValue * derived->rawToCooked));
235 lastPadding = acc & ~derived->bitmask;
236 printPaddingChangedMessage =
true;
245 template<
typename Type>
247 Type v = get() * (
raw ? 1 : derived->rawToCooked);
248 if((acc & ~derived->bitmask) != lastPadding) {
249 if(printPaddingChangedMessage) {
250 std::cerr <<
"getRemoteValue(): Padding data has changed. Test will be failed by returing a false remote value "
251 <<
"(off by one)." << std::endl;
252 printPaddingChangedMessage =
false;
262 set(get() + derived->rawIncrement);
278 std::string
path() {
return "/ShortRaw/signed16"; }
282 int16_t rawToCooked = 1;
286 int16_t rawIncrement = 17117;
288 int32_t bitmask = 0x0000FFFF;
294 std::string
path() {
return "/ShortRaw/unsigned16"; }
298 int16_t rawToCooked = 1;
299 int16_t rawIncrement = 17119;
301 int32_t bitmask = 0xFFFF0000;
307 std::string
path() {
return "/ShortRaw/fixedPoint16_8u"; }
311 float rawToCooked = 1. / 256.;
312 int16_t rawIncrement = 17121;
314 int32_t bitmask = 0x0000FFFF;
320 std::string
path() {
return "/ShortRaw/fixedPoint16_8s"; }
324 float rawToCooked = 1. / 256.;
325 int16_t rawIncrement = 17123;
327 int32_t bitmask = 0xFFFF0000;
333 std::string
path() {
return "/ByteRaw/signed8"; }
337 int8_t rawToCooked = 1;
338 int8_t rawIncrement = 119;
340 int32_t bitmask = 0x000000FF;
346 std::string
path() {
return "/ByteRaw/unsigned8"; }
350 uint8_t rawToCooked = 1;
351 int8_t rawIncrement = 121;
353 int32_t bitmask = 0x0000FF00;
359 std::string
path() {
return "/ByteRaw/fixedPoint8_4u"; }
363 float rawToCooked = 1. / 16.;
364 int8_t rawIncrement = 123;
366 int32_t bitmask = 0x00FF0000;
372 std::string
path() {
return "/ByteRaw/fixedPoint8_4s"; }
376 float rawToCooked = 1. / 16.;
377 int8_t rawIncrement = 125;
379 int32_t bitmask = 0xFF000000;
385 static std::string
path() {
return "/Text/someAsciiData"; }
398 .disableAsyncReadInconsistency()
399 .disableSwitchReadOnly()
400 .disableSwitchWriteOnly()
401 .disableTestWriteNeverLosesData()
402 .disableTestRawTransfer();
407 std::string textBase{
"Some $%#@! characters "};
409 const size_t asciiLength{35};
411 template<
typename UserType>
416 template<
typename UserType>
418 std::vector<std::vector<UserType>> v{{
""}};
419 for(
size_t i = 0; i < asciiLength; ++i) {
421 size_t byteInWord = i % 4;
422 char ch = char((acc[word] >> (byteInWord * 8U)) & 0xFF);
426 std::cout <<
"getRemoteValue: " << v[0][0] << std::endl;
431 auto v = generateValue<minimumUserType>();
432 for(
size_t i = 0; i < acc.getNumberOfElements(); ++i) {
435 for(
size_t i = 0; i < std::min(asciiLength, v[0][0].length()); ++i) {
436 char ch = v[0][0][i];
438 size_t byteInWord = i % 4;
439 acc[word] = acc[word] | uint32_t(ch) << (byteInWord * 8U);
441 std::cout <<
"setRemoteValue: " << v[0][0] << std::endl;
454 std::string
path() {
return "/TEST/NODMA"; }
468 .disableAsyncReadInconsistency()
469 .disableSwitchReadOnly()
470 .disableSwitchWriteOnly()
471 .disableTestWriteNeverLosesData()
472 .disableTestRawTransfer();
476 template<
typename UserType>
478 std::vector<std::vector<UserType>> v;
479 v.resize(nChannels());
480 for(
size_t c = 0; c < nChannels(); ++c) {
481 for(
size_t e = 0; e < nElementsPerChannel(); ++e) {
482 v[c].push_back(uint16_t(acc[c][e] + 7 * c + 3 * e));
488 template<
typename UserType>
490 std::vector<std::vector<UserType>> v;
491 v.resize(nChannels());
492 for(
size_t c = 0; c < nChannels(); ++c) {
493 for(
size_t e = 0; e < nElementsPerChannel(); ++e) {
494 v[c].push_back(acc[c][e]);
501 auto v = generateValue<minimumUserType>();
502 for(
size_t c = 0; c < nChannels(); ++c) {
503 for(
size_t e = 0; e < nElementsPerChannel(); ++e) {
510 exceptionDummyMuxed->throwExceptionRead = enable;
511 exceptionDummyMuxed->throwExceptionWrite = enable;
512 exceptionDummyMuxed->throwExceptionOpen = enable;
517 std::string
path() {
return "/TEST/NODMAASYNC"; }
531 .disableAsyncReadInconsistency()
532 .disableSwitchReadOnly()
533 .disableSwitchWriteOnly()
534 .disableTestWriteNeverLosesData()
535 .disableTestRawTransfer();
539 template<
typename UserType>
541 std::vector<std::vector<UserType>> v;
542 v.resize(nChannels());
543 for(
size_t c = 0; c < nChannels(); ++c) {
544 for(
size_t e = 0; e < nElementsPerChannel(); ++e) {
545 v[c].push_back(uint16_t(acc[c][e] + 7 * c + 3 * e));
551 template<
typename UserType>
553 std::vector<std::vector<UserType>> v;
554 v.resize(nChannels());
555 for(
size_t c = 0; c < nChannels(); ++c) {
556 for(
size_t e = 0; e < nElementsPerChannel(); ++e) {
557 v[c].push_back(acc[c][e]);
564 auto v = generateValue<minimumUserType>();
565 for(
size_t c = 0; c < nChannels(); ++c) {
566 for(
size_t e = 0; e < nElementsPerChannel(); ++e) {
570 if(exceptionDummyMuxed->isOpen()) exceptionDummyMuxed->triggerInterrupt(6);
574 exceptionDummyMuxed->throwExceptionRead = enable;
575 exceptionDummyMuxed->throwExceptionWrite = enable;
576 exceptionDummyMuxed->throwExceptionOpen = enable;
577 if(exceptionDummyMuxed->isOpen()) exceptionDummyMuxed->triggerInterrupt(6);
584 std::string
path() {
return "/TEST/FLOAT"; }
597 .disableAsyncReadInconsistency()
598 .disableSwitchReadOnly()
599 .disableSwitchWriteOnly()
600 .disableTestWriteNeverLosesData()
601 .disableTestRawTransfer();
605 template<
typename UserType>
607 std::vector<std::vector<UserType>> v;
608 v.resize(nChannels());
609 for(uint32_t c = 0; c < nChannels(); ++c) {
610 for(uint32_t e = 0; e < nElementsPerChannel(); ++e) {
611 int32_t rawValue = rawAcc[c][e];
612 float* cookedValue =
reinterpret_cast<float*
>(&rawValue);
613 v[c].push_back(*cookedValue + 0.7f * c + 3 * e);
619 template<
typename UserType>
621 std::vector<std::vector<UserType>> v;
622 v.resize(nChannels());
623 for(uint32_t c = 0; c < nChannels(); ++c) {
624 for(uint32_t e = 0; e < nElementsPerChannel(); ++e) {
625 int32_t rawValue = rawAcc[c][e];
626 float* cookedValue =
reinterpret_cast<float*
>(&rawValue);
627 v[c].push_back(*cookedValue);
634 auto v = generateValue<minimumUserType>();
635 for(uint32_t c = 0; c < nChannels(); ++c) {
636 for(uint32_t e = 0; e < nElementsPerChannel(); ++e) {
638 float* cookedValue =
reinterpret_cast<float*
>(&rawValue);
639 *cookedValue = v[c][e];
640 std::cout <<
"raw value is " << rawValue <<
"; cookedValue is " << *cookedValue << std::endl;
641 rawAcc[c][e] = rawValue;
647 exceptionDummyMuxed->throwExceptionRead = enable;
648 exceptionDummyMuxed->throwExceptionWrite = enable;
649 exceptionDummyMuxed->throwExceptionOpen = enable;
656 std::cout <<
"*** testRegisterAccessor *** " << std::endl;
659 .addRegister<Integers_signed32_async>()
663 .addRegister<ShortRaw_unsigned16>()
665 .addRegister<ShortRaw_fixedPoint16_8s>()
667 .addRegister<ByteRaw_unsigned8>()
669 .addRegister<ByteRaw_fixedPoint8_4u>()
677 std::cout <<
"*** testMultiplexedRegisterAccessor *** " << std::endl;
680 .addRegister<MuxedNodmaAsync>()
687 BOOST_AUTO_TEST_SUITE_END()