4#define BOOST_TEST_DYN_LINK
5#define BOOST_TEST_MODULE SubdeviceBackendUnifiedTest
6#include <boost/test/unit_test.hpp>
7using namespace boost::unit_test_framework;
16BOOST_AUTO_TEST_SUITE(SubdeviceBackendUnifiedTestSuite)
20static std::string
cdd(
"(ExceptionDummy:1?map=SubdeviceTarget.map)");
25template<
typename Register>
39 template<
typename UserType>
41 std::vector<UserType> v;
42 for(
size_t i = 0; i < this->nElementsPerChannel(); ++i) {
43 assert(i + this->address() / 4 < 10);
44 typename Register::minimumUserType e =
acc[i + this->address() / 4] + this->increment * (i + 1);
45 auto limited = this->limitGenerated(e);
46 v.push_back(
raw ? this->toRaw(limited) : limited);
53 template<
typename Type>
56 for(
size_t i = 0; i < this->nElementsPerChannel(); ++i) {
57 assert(i + this->address() / 4 < 10);
58 auto rawVal =
acc[i + this->address() / 4];
59 v.push_back((
raw ? rawVal : this->fromRaw(rawVal)));
65 auto v = generateValue<typename Register::minimumUserType>()[0];
66 for(
size_t i = 0; i < this->nElementsPerChannel(); ++i) {
67 assert(i + this->address() / 4 < 10);
68 acc[i + this->address() / 4] = this->toRaw(v[i]);
73 target->throwExceptionRead = enable;
74 target->throwExceptionWrite = enable;
75 target->throwExceptionOpen = enable;
83 assert(target !=
nullptr);
103 std::cout <<
"Error: address (" <<
address <<
") >= lastAddress (" <<
lastAddress <<
")!" << std::endl;
111 for(
size_t i = 0; i <
areaSize; ++i) {
123template<
typename Register>
134 .disableAsyncReadInconsistency()
135 .enableTestRawTransfer()
136 .disableTestPartialAccessor();
138 template<
typename Type>
141 for(
size_t i = 0; i < this->nElementsPerChannel(); ++i) {
150 typename Register::minimumUserType e = this->fromRaw(cv) + this->increment * (i + 1);
151 auto limited = this->limitGenerated(e);
152 v.push_back(
raw ? this->toRaw(limited) : limited);
157 template<
typename Type>
160 for(
size_t i = 0; i < this->nElementsPerChannel(); ++i) {
168 v.push_back(
raw ? rawValue : this->fromRaw(rawValue));
174 auto v = generateValue<typename Register::minimumUserType>()[0];
175 for(
size_t i = 0; i < this->nElementsPerChannel(); ++i) {
177 core.
currentValue[i + this->address()] = this->toRaw(v[i]);
186 target->throwExceptionRead = enable;
187 target->throwExceptionWrite = enable;
188 target->throwExceptionOpen = enable;
195 std::string
path() {
return "/APP.0/MY_REGISTER1"; }
198 uint32_t
toRaw(uint32_t v) {
return v; }
209 std::string
path() {
return "/APP.0/MY_AREA1"; }
212 uint32_t
toRaw(
float v) {
return v * 65536.F; }
213 float fromRaw(uint32_t v) {
return v / 65536.F; }
215 while(e > 32768.F) e -= 65535.F;
216 while(e < -32767.F) e += 65535.F;
227 std::string
path() {
return "/APP.0/THE_AREA_1"; }
230 uint32_t
toRaw(uint32_t v) {
return v; }
241 std::string
path() {
return "/APP.0/THE_AREA_2"; }
244 uint32_t
toRaw(
float v) {
return v * 65536.F; }
245 float fromRaw(uint32_t v) {
return v / 65536.F; }
247 while(e > 32768.F) e -= 65535.F;
248 while(e < -32767.F) e += 65535.F;
261 "(subdevice?type=area&device=" +
cdd +
"&area=APP.0.THE_AREA&map=Subdevice.map)");
269 "(subdevice?type=3regs&device=" +
cdd +
270 "&address=APP.1.ADDRESS&data=APP.1.DATA&status=APP.1.STATUS&map=Subdevice.map)");
279 "(subdevice?type=2regs&device=" +
cdd +
"&address=APP.1.ADDRESS&data=APP.1.DATA&sleep=1000&map=Subdevice.map)");
290 "(subdevice?type=3regs&device=" +
cdd +
291 "&address=APP.1.ADDRESS&data=APP.0.THE_AREA&status=APP.1.STATUS&map=SubdeviceMuxedArea.map)");
296BOOST_AUTO_TEST_SUITE_END()
Set of AccessMode flags with additional functionality for an easier handling.
static BackendFactory & getInstance()
Static function to get an instance of factory.
Register accessor for accessing single word or 1D array registers internally of a DummyBackend implem...
unsigned int getNumberOfElements()
return number of elements
void setWriteCallback(const std::function< void()> &writeCallback)
Set callback function which is called when the register is written to (through the normal Device inte...
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.
@ raw
Raw access: disable any possible conversion from the original hardware data type into the given UserT...
size_t writeQueueLength()
size_t nRuntimeErrorCases()
static constexpr auto capabilities
void setForceRuntimeError(bool enable, size_t)
DummyRegisterAccessor< uint32_t > acc
ChimeraTK::AccessModeFlags supportedFlags()
std::vector< std::vector< UserType > > generateValue(bool raw=false)
std::vector< std::vector< Type > > getRemoteValue(bool raw=false)
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
uint32_t fromRaw(uint32_t v)
uint32_t toRaw(uint32_t v)
uint32_t limitGenerated(uint32_t e)
size_t nElementsPerChannel()
float limitGenerated(float e)
size_t nElementsPerChannel()
float fromRaw(uint32_t v)
size_t nElementsPerChannel()
float limitGenerated(float e)
float fromRaw(uint32_t v)
uint32_t limitGenerated(uint32_t e)
size_t nElementsPerChannel()
uint32_t toRaw(uint32_t v)
uint32_t fromRaw(uint32_t v)
void setForceRuntimeError(bool enable, size_t)
size_t writeQueueLength()
static constexpr auto capabilities
ChimeraTK::AccessModeFlags supportedFlags()
std::vector< std::vector< Type > > getRemoteValue(bool raw=false)
size_t nRuntimeErrorCases()
std::vector< std::vector< Type > > generateValue(bool raw=false)
DummyRegisterAccessor< uint32_t > address
std::vector< uint32_t > currentValue
DummyRegisterAccessor< uint32_t > area
std::vector< std::vector< uint32_t > > currentAreaValue
DummyRegisterAccessor< uint32_t > status
DummyRegisterAccessor< uint32_t > data
BOOST_AUTO_TEST_CASE(TestUnifiedSimple)