4#define BOOST_TEST_DYN_LINK
6#define BOOST_TEST_MODULE NumericAddressedBackendUnified
8#include <boost/test/unit_test.hpp>
9using namespace boost::unit_test_framework;
30BOOST_AUTO_TEST_SUITE(NumericAddressedBackendUnifiedTestSuite)
34static std::string
cdd(
"(ExceptionDummy:1?map=test3.map)");
38static std::string cddMuxed(
"(ExceptionDummy:1?map=muxedDataAccessor.jmap)");
39static auto exceptionDummyMuxed =
42static std::string cddBitRange(
"(ExceptionDummy:1?map=unifiedTest.jmap)");
43static auto exceptionDummyBitRange =
49 std::string
path() {
return "/Integers/signed32"; }
62 .disableAsyncReadInconsistency()
63 .disableSwitchReadOnly()
64 .disableSwitchWriteOnly()
65 .disableTestWriteNeverLosesData()
66 .enableTestRawTransfer();
70 template<
typename Type>
75 template<
typename UserType>
90 std::string
path() {
return "/Integers/signed32_async"; }
105 .disableAsyncReadInconsistency()
106 .disableSwitchReadOnly()
107 .disableSwitchWriteOnly()
108 .disableTestWriteNeverLosesData()
109 .enableTestRawTransfer();
113 template<
typename Type>
118 template<
typename UserType>
124 acc = generateValue<minimumUserType>()[0][0];
139 std::string
path() {
return "/Integers/signed32_async/DUMMY_WRITEABLE"; }
154 .disableAsyncReadInconsistency()
155 .disableSwitchReadOnly()
156 .disableSwitchWriteOnly()
157 .disableTestWriteNeverLosesData()
158 .enableTestRawTransfer();
162 template<
typename Type>
167 template<
typename UserType>
173 acc = generateValue<minimumUserType>()[0][0];
189template<
typename Derived,
typename rawUserType>
191 Derived*
derived{
static_cast<Derived*
>(
this)};
213 .disableAsyncReadInconsistency()
214 .disableSwitchReadOnly()
215 .disableSwitchWriteOnly()
216 .disableTestWriteNeverLosesData()
217 .enableTestRawTransfer();
225 void set(rawUserType val) {
226 acc &= ~derived->bitmask;
233 template<
typename Type>
235 rawUserType newRawValue =
static_cast<rawUserType
>(
get() +
derived->rawIncrement);
236 Type v = ChimeraTK::numeric::convert<Type>(
raw ? newRawValue : (newRawValue *
derived->rawToCooked));
249 template<
typename Type>
254 std::cerr <<
"getRemoteValue(): Padding data has changed. Test will be failed by returing a false remote value "
255 <<
"(off by one)." << std::endl;
282 std::string
path() {
return "/ShortRaw/signed16"; }
298 std::string
path() {
return "/ShortRaw/unsigned16"; }
311 std::string
path() {
return "/ShortRaw/fixedPoint16_8u"; }
324 std::string
path() {
return "/ShortRaw/fixedPoint16_8s"; }
337 std::string
path() {
return "/ByteRaw/signed8"; }
350 std::string
path() {
return "/ByteRaw/unsigned8"; }
363 std::string
path() {
return "/ByteRaw/fixedPoint8_4u"; }
376 std::string
path() {
return "/ByteRaw/fixedPoint8_4s"; }
389 static std::string
path() {
return "/Text/someAsciiData"; }
402 .disableAsyncReadInconsistency()
403 .disableSwitchReadOnly()
404 .disableSwitchWriteOnly()
405 .disableTestWriteNeverLosesData()
406 .disableTestRawTransfer();
415 template<
typename UserType>
420 template<
typename UserType>
422 std::vector<std::vector<UserType>> v{{
""}};
425 size_t byteInWord = i % 4;
426 char ch = char((
acc[word] >> (byteInWord * 8U)) & 0xFF);
430 std::cout <<
"getRemoteValue: " << v[0][0] << std::endl;
435 auto v = generateValue<minimumUserType>();
439 for(
size_t i = 0; i < std::min(
asciiLength, v[0][0].length()); ++i) {
440 char ch = v[0][0][i];
442 size_t byteInWord = i % 4;
443 acc[word] =
acc[word] | uint32_t(ch) << (byteInWord * 8U);
445 std::cout <<
"setRemoteValue: " << v[0][0] << std::endl;
458 std::string
path() {
return "/TEST/NODMA"; }
472 .disableAsyncReadInconsistency()
473 .disableSwitchReadOnly()
474 .disableSwitchWriteOnly()
475 .disableTestWriteNeverLosesData()
476 .disableTestRawTransfer();
480 template<
typename UserType>
482 std::vector<std::vector<UserType>> v;
484 for(
size_t c = 0; c <
nChannels(); ++c) {
486 v[c].push_back(uint16_t(
acc[c][e] + 7 * c + 3 * e));
492 template<
typename UserType>
494 std::vector<std::vector<UserType>> v;
496 for(
size_t c = 0; c <
nChannels(); ++c) {
498 v[c].push_back(
acc[c][e]);
505 auto v = generateValue<minimumUserType>();
506 for(
size_t c = 0; c <
nChannels(); ++c) {
514 exceptionDummyMuxed->throwExceptionRead = enable;
515 exceptionDummyMuxed->throwExceptionWrite = enable;
516 exceptionDummyMuxed->throwExceptionOpen = enable;
525 std::string
path() {
return "/TEST/NODMA.0"; }
538 .disableAsyncReadInconsistency()
539 .disableSwitchReadOnly()
540 .disableSwitchWriteOnly()
541 .disableTestWriteNeverLosesData()
542 .enableTestRawTransfer();
548 template<
typename UserType>
550 std::vector<std::vector<UserType>> v(1);
557 template<
typename UserType>
559 std::vector<std::vector<UserType>> v(1);
561 v[0].push_back(
acc[e]);
567 auto v = generateValue<minimumUserType>();
574 exceptionDummyMuxed->throwExceptionRead = enable;
575 exceptionDummyMuxed->throwExceptionWrite = enable;
576 exceptionDummyMuxed->throwExceptionOpen = enable;
581 std::string
path() {
return "/TEST/NODMA.3"; }
594 .disableAsyncReadInconsistency()
595 .disableSwitchReadOnly()
596 .disableSwitchWriteOnly()
597 .disableTestWriteNeverLosesData()
598 .enableTestRawTransfer();
606 template<
typename UserType>
608 std::vector<std::vector<UserType>> v(1);
615 template<
typename UserType>
617 std::vector<std::vector<UserType>> v(1);
625 auto v = generateValue<minimumUserType>();
632 exceptionDummyMuxed->throwExceptionRead = enable;
633 exceptionDummyMuxed->throwExceptionWrite = enable;
634 exceptionDummyMuxed->throwExceptionOpen = enable;
639 std::string
path() {
return "/TEST/NODMAASYNC"; }
653 .disableAsyncReadInconsistency()
654 .disableSwitchReadOnly()
655 .disableSwitchWriteOnly()
656 .disableTestWriteNeverLosesData()
657 .disableTestRawTransfer();
661 template<
typename UserType>
663 std::vector<std::vector<UserType>> v;
665 for(
size_t c = 0; c <
nChannels(); ++c) {
667 v[c].push_back(uint16_t(
acc[c][e] + 7 * c + 3 * e));
673 template<
typename UserType>
675 std::vector<std::vector<UserType>> v;
677 for(
size_t c = 0; c <
nChannels(); ++c) {
679 v[c].push_back(
acc[c][e]);
686 auto v = generateValue<minimumUserType>();
687 for(
size_t c = 0; c <
nChannels(); ++c) {
692 if(exceptionDummyMuxed->isOpen()) exceptionDummyMuxed->triggerInterrupt(6);
696 exceptionDummyMuxed->throwExceptionRead = enable;
697 exceptionDummyMuxed->throwExceptionWrite = enable;
698 exceptionDummyMuxed->throwExceptionOpen = enable;
699 if(exceptionDummyMuxed->isOpen()) exceptionDummyMuxed->triggerInterrupt(6);
704 std::string
path() {
return "/TEST/NODMAASYNC.0"; }
720 .disableAsyncReadInconsistency()
721 .disableSwitchReadOnly()
722 .disableSwitchWriteOnly()
723 .disableTestWriteNeverLosesData()
724 .enableTestRawTransfer();
729 template<
typename UserType>
731 std::vector<std::vector<UserType>> v(1);
738 template<
typename UserType>
740 std::vector<std::vector<UserType>> v(1);
748 auto v = generateValue<minimumUserType>();
752 if(exceptionDummyMuxed->isOpen()) exceptionDummyMuxed->triggerInterrupt(6);
756 exceptionDummyMuxed->throwExceptionRead = enable;
757 exceptionDummyMuxed->throwExceptionWrite = enable;
758 exceptionDummyMuxed->throwExceptionOpen = enable;
759 if(exceptionDummyMuxed->isOpen()) exceptionDummyMuxed->triggerInterrupt(6);
766 std::string
path() {
return "/TEST/FLOAT"; }
779 .disableAsyncReadInconsistency()
780 .disableSwitchReadOnly()
781 .disableSwitchWriteOnly()
782 .disableTestWriteNeverLosesData()
783 .disableTestRawTransfer();
787 template<
typename UserType>
789 std::vector<std::vector<UserType>> v;
791 for(uint32_t c = 0; c <
nChannels(); ++c) {
793 v[c].push_back(
acc[c][e] + 0.7f * c + 3 * e);
799 template<
typename UserType>
801 std::vector<std::vector<UserType>> v;
803 for(uint32_t c = 0; c <
nChannels(); ++c) {
805 v[c].push_back(
acc[c][e]);
812 auto v = generateValue<minimumUserType>();
813 for(uint32_t c = 0; c <
nChannels(); ++c) {
821 exceptionDummyMuxed->throwExceptionRead = enable;
822 exceptionDummyMuxed->throwExceptionWrite = enable;
823 exceptionDummyMuxed->throwExceptionOpen = enable;
830template<
typename Derived>
832 Derived*
derived{
static_cast<Derived*
>(
this)};
836 .disableAsyncReadInconsistency()
837 .disableSwitchReadOnly()
838 .disableSwitchWriteOnly()
839 .disableTestWriteNeverLosesData()
840 .enableTestRawTransfer();
856 dummy.throwExceptionWrite = enable;
857 dummy.throwExceptionOpen = enable;
858 if(
derived->isPush() && enable) {
859 dummy.triggerInterrupt(6);
865template<
typename Derived>
874 template<
typename T,
typename Traw>
876 return static_cast<T
>(value);
879 template<
typename UserType>
883 template<
typename Type>
886 typedef typename Derived::rawUserType Traw;
887 typedef typename Derived::minimumUserType T;
888 auto cv =
derived->template getRemoteValue<Traw>(
true)[0];
889 for(
size_t i = 0; i <
derived->nElementsPerChannel(); ++i) {
890 Traw e = cv[i] +
derived->increment * (
static_cast<Traw
>(i) + 1);
892 v.push_back(
derived->template convertRawToCooked<T, Traw>(e));
895 v.push_back(
static_cast<T
>(e));
902 template<
typename UserType>
904 typedef typename Derived::rawUserType Traw;
906 std::vector<UserType> cookedValues(
derived->nElementsPerChannel());
907 std::vector<Traw> rawValues(
derived->nElementsPerChannel());
913 auto bufferLock =
derived->acc.getBufferLock();
915 for(
size_t i = 0; i <
derived->nElementsPerChannel(); ++i) {
920 for(
size_t i = 0; i <
derived->nElementsPerChannel(); ++i) {
922 cookedValues[i] =
derived->template convertRawToCooked<UserType, Traw>(rawValues[i]);
925 cookedValues[i] =
static_cast<UserType
>(rawValues[i]);
928 return {cookedValues};
932 auto v = generateValue<typename Derived::rawUserType>(
true)[0];
934 auto bufferLock =
derived->acc.getBufferLock();
935 for(
size_t i = 0; i <
derived->nElementsPerChannel(); ++i) {
946template<
typename Derived>
952template<
typename Derived>
965 template<
typename UserType>
966 std::vector<std::vector<UserType>>
generateValue([[maybe_unused]]
bool getRaw =
false) {
967 return derived->target.template generateValue<UserType>();
970 template<
typename UserType>
974 return derived->target.template getRemoteValue<UserType>(
true);
977 uint64_t v =
derived->target.template getRemoteValue<uint64_t>()[0][0];
979 UserType result = (v & mask) >>
derived->shift;
992 std::string
path() {
return "/WORD_FIRMWARE"; }
1002 std::string
path() {
return "/WORD_FIRMWARE/BitRangeLower"; }
1014 std::string
path() {
return "/WORD_FIRMWARE/BitRangeUpper"; }
1019 uint16_t
width = 16;
1020 uint16_t
shift = 16;
1026 std::string
path() {
return "/WORD_FIRMWARE/BitRangeMiddle"; }
1040template<
typename Derived>
1053 template<
typename UserType>
1054 std::vector<std::vector<UserType>>
generateValue([[maybe_unused]]
bool getRaw =
false) {
1055 return derived->target.template generateValue<UserType>();
1058 template<
typename UserType>
1062 return derived->target.template getRemoteValue<UserType>(
true);
1065 auto rawValues =
derived->target.template getRemoteValue<uint64_t>();
1066 std::vector<UserType> result;
1067 for(
size_t i = 0; i < rawValues[0].size(); ++i) {
1068 uint64_t v = rawValues[0][i];
1069 uint64_t mask = ((1ULL <<
derived->width) - 1) <<
derived->shift;
1070 result.push_back(
static_cast<UserType
>((v & mask) >>
derived->shift));
1081 std::string
path() {
return "/ARRAY_REG"; }
1095 std::string
path() {
return "/ARRAY_REG/ArrayBitRangeLow"; }
1107 std::string
path() {
return "/ARRAY_REG/ArrayBitRangeHigh"; }
1121 std::cout <<
"*** testRegisterAccessor *** " << std::endl;
1124 .addRegister<Integers_signed32_async>()
1128 .addRegister<ShortRaw_unsigned16>()
1130 .addRegister<ShortRaw_fixedPoint16_8s>()
1132 .addRegister<ByteRaw_unsigned8>()
1134 .addRegister<ByteRaw_fixedPoint8_4u>()
1142 std::cout <<
"*** testMultiplexedRegisterAccessor *** " << std::endl;
1145 .addRegister<MuxedNodmaAsync>()
1147 .runTests(cddMuxed);
1153 std::cout <<
"*** testNamedChannelSlices *** " << std::endl;
1161 std::cout <<
"*** testNamedChannelSliceAsync *** " << std::endl;
1168 std::cout <<
"*** testBitRanges *** " << std::endl;
1172 .addRegister<RegUpperHalfOfFirmware>()
1174 .addRegister<ArrayBitRangeLow>()
1176 .runTests(cddBitRange);
1181BOOST_AUTO_TEST_SUITE_END()
Set of AccessMode flags with additional functionality for an easier handling.
void add(AccessMode flag)
Add the given flag to the set.
static BackendFactory & getInstance()
Static function to get an instance of factory.
std::atomic< bool > throwExceptionRead
Register accessor for accessing multiplexed 2D array registers internally of a DummyBackend implement...
Register accessor for accessing single word or 1D array registers internally of a DummyBackend implem...
unsigned int getNumberOfElements()
return number of elements
Accessor for raw 32 bit integer access to the underlying memory space.
Class to test any backend for correct behaviour.
UnifiedBackendTest< typename boost::mpl::push_back< VECTOR_OF_REGISTERS_T, REG_T >::type > addRegister()
Add a register to be used by the test.
@ wait_for_new_data
Make any read blocking until new data has arrived since the last read.
@ raw
Raw access: disable any possible conversion from the original hardware data type into the given UserT...
std::string to_string(const std::string &v)
Base descriptor for array bit-range accessors.
void setForceRuntimeError(bool enable, size_t caseIndex)
std::vector< std::vector< UserType > > getRemoteValue(bool getRaw=false)
size_t nRuntimeErrorCases()
std::vector< std::vector< UserType > > generateValue(bool getRaw=false)
ChimeraTK::AccessModeFlags supportedFlags()
static constexpr auto capabilities
size_t nElementsPerChannel()
DummyRegisterAccessor< minimumUserType > acc
size_t nElementsPerChannel()
std::vector< std::vector< UserType > > generateValue()
std::vector< std::vector< UserType > > getRemoteValue()
static size_t writeQueueLength()
DummyRegisterAccessor< uint32_t > acc
static size_t nChannels()
static bool isWriteable()
std::string minimumUserType
static constexpr auto capabilities
static std::string path()
static size_t nRuntimeErrorCases()
static ChimeraTK::AccessModeFlags supportedFlags()
static size_t nElementsPerChannel()
static void setForceRuntimeError(bool enable, size_t)
DummyRegisterAccessor< minimumUserType > acc
Descriptor for the test capabilities for each register.
constexpr TestCapabilities< _syncRead, TestCapability::disabled, _asyncReadInconsistency, _switchReadOnly, _switchWriteOnly, _writeNeverLosesData, _testWriteOnly, _testReadOnly, _testRawTransfer, _testCatalogue, _setRemoteValueIncrementsVersion, _testPartialAccessor > disableForceDataLossWrite() const
std::vector< std::vector< Type > > generateValue(bool raw=false)
size_t writeQueueLength()
static constexpr auto capabilities
void forceAsyncReadInconsistency()
std::vector< std::vector< UserType > > getRemoteValue(bool raw=false)
minimumUserType rawUserType
size_t nRuntimeErrorCases()
DummyRegisterAccessor< int32_t > acc
size_t nElementsPerChannel()
ChimeraTK::AccessModeFlags supportedFlags()
void setForceRuntimeError(bool enable, size_t)
std::vector< std::vector< Type > > generateValue(bool raw=false)
minimumUserType rawUserType
ChimeraTK::AccessModeFlags supportedFlags()
std::vector< std::vector< UserType > > getRemoteValue(bool raw=false)
size_t nElementsPerChannel()
void forceAsyncReadInconsistency()
static constexpr auto capabilities
void setForceRuntimeError(bool enable, size_t)
DummyRegisterAccessor< int32_t > acc
size_t nRuntimeErrorCases()
size_t writeQueueLength()
size_t nRuntimeErrorCases()
std::vector< std::vector< Type > > generateValue(bool raw=false)
void setForceRuntimeError(bool enable, size_t)
size_t writeQueueLength()
DummyRegisterAccessor< int32_t > acc
ChimeraTK::AccessModeFlags supportedFlags()
minimumUserType rawUserType
size_t nElementsPerChannel()
std::vector< std::vector< UserType > > getRemoteValue(bool raw=false)
static constexpr auto capabilities
static constexpr auto capabilities
void setForceRuntimeError(bool enable, size_t)
size_t nRuntimeErrorCases()
size_t nElementsPerChannel()
std::vector< std::vector< UserType > > generateValue()
ChimeraTK::AccessModeFlags supportedFlags()
DummyMultiplexedRegisterAccessor< float > acc
std::vector< std::vector< UserType > > getRemoteValue()
size_t nRuntimeErrorCases()
static constexpr auto capabilities
std::vector< std::vector< UserType > > getRemoteValue()
DummyMultiplexedRegisterAccessor< uint16_t > acc
minimumUserType rawUserType
ChimeraTK::AccessModeFlags supportedFlags()
void setForceRuntimeError(bool enable, size_t)
size_t nElementsPerChannel()
size_t writeQueueLength()
std::vector< std::vector< UserType > > generateValue()
size_t writeQueueLength()
DummyMultiplexedRegisterAccessor< uint16_t > acc
void setForceRuntimeError(bool enable, size_t)
size_t nRuntimeErrorCases()
size_t nElementsPerChannel()
std::vector< std::vector< UserType > > getRemoteValue()
ChimeraTK::AccessModeFlags supportedFlags()
minimumUserType rawUserType
static constexpr auto capabilities
std::vector< std::vector< UserType > > generateValue()
size_t nRuntimeErrorCases()
static constexpr auto capabilities
std::vector< std::vector< UserType > > generateValue(bool raw=false)
DummyRegisterAccessor< uint16_t > acc
size_t nElementsPerChannel()
ChimeraTK::AccessModeFlags supportedFlags()
DummyMultiplexedRegisterAccessor< uint16_t > full
std::vector< std::vector< UserType > > getRemoteValue(bool raw=false)
void setForceRuntimeError(bool enable, size_t)
static const size_t channelIndex
size_t writeQueueLength()
size_t nRuntimeErrorCases()
static constexpr auto capabilities
size_t writeQueueLength()
std::vector< std::vector< UserType > > generateValue(bool raw=false)
static const size_t channelIndex
std::vector< std::vector< UserType > > getRemoteValue(bool raw=false)
void setForceRuntimeError(bool enable, size_t)
DummyMultiplexedRegisterAccessor< uint16_t > full
ChimeraTK::AccessModeFlags supportedFlags()
size_t nElementsPerChannel()
size_t writeQueueLength()
void setForceRuntimeError(bool enable, size_t)
DummyMultiplexedRegisterAccessor< uint16_t > full
static constexpr auto capabilities
size_t nRuntimeErrorCases()
std::vector< std::vector< UserType > > getRemoteValue(bool raw=false)
size_t nElementsPerChannel()
ChimeraTK::AccessModeFlags supportedFlags()
static const size_t channelIndex
std::vector< std::vector< UserType > > generateValue(bool raw=false)
Base descriptor for 1D accessors (and scalars)
std::vector< std::vector< UserType > > getRemoteValue(bool getRaw=false)
void generateValueHook(std::vector< UserType > &)
T convertRawToCooked(Traw value)
std::vector< std::vector< Type > > generateValue(bool getRaw=false)
void setForceRuntimeError(bool enable, size_t caseIndex)
size_t nRuntimeErrorCases()
static constexpr auto capabilities
uint64_t debugReadRawFullWord()
Read the raw full word value from _barContents directly via the DummyRegisterAccessor.
std::vector< std::vector< UserType > > getRemoteValue(bool getRaw=false)
size_t nElementsPerChannel()
ChimeraTK::AccessModeFlags supportedFlags()
std::vector< std::vector< UserType > > generateValue(bool getRaw=false)
BitRangeAccessorTarget target
BitRangeAccessorTarget target
BitRangeAccessorTarget target
Base descriptor with defaults, used for all registers.
ChimeraTK::AccessModeFlags supportedFlags()
size_t writeQueueLength()
void setForceRuntimeError(bool enable, size_t)
static constexpr auto capabilities
size_t nRuntimeErrorCases()
Base descriptor for scalars.
size_t nElementsPerChannel()
void setForceRuntimeError(bool enable, size_t)
ChimeraTK::AccessModeFlags supportedFlags()
DummyRegisterRawAccessor acc
size_t writeQueueLength()
std::vector< std::vector< Type > > generateValue(bool raw=false)
size_t nRuntimeErrorCases()
bool printPaddingChangedMessage
static constexpr auto capabilities
void set(rawUserType val)
std::vector< std::vector< Type > > getRemoteValue(bool raw=false)
size_t nElementsPerChannel()
minimumUserType rawUserType
BOOST_AUTO_TEST_CASE(testRegisterAccessor)