5#define BOOST_TEST_DYN_LINK
6#define BOOST_TEST_MODULE UioBackendUnifiedTest
7#include <boost/test/unit_test.hpp>
8using namespace boost::unit_test_framework;
32 const std::string
lockfile{
"/var/run/lock/uiodummy.lock"};
34 int fd = open(
lockfile.c_str(), O_WRONLY | O_CREAT, 0777);
40 int res = flock(
fd, LOCK_EX);
57BOOST_AUTO_TEST_SUITE(UioBackendUnifiedTestSuite)
61static const std::string
cdd(
"(uio:ctkuiodummy?map=uioBackendTest.mapp)");
67 explicit RawUioAccess(
const std::string& filePath,
const std::string& mapFile);
73 T
read(
const std::string& name);
75 void write(
const std::string& name, T value);
78 int _uioFileDescriptor;
80 std::filesystem::path _deviceFilePath;
81 size_t _deviceMemSize = 0;
82 void* _memoryPointer{
nullptr};
85 static uint64_t readUint64HexFromFile(
const std::string& filePath);
91: _deviceFilePath(filePath.c_str()) {
92 if(std::filesystem::is_symlink(_deviceFilePath)) {
93 _deviceFilePath = std::filesystem::canonical(_deviceFilePath);
95 _uioFileDescriptor = open(filePath.c_str(), O_RDWR);
97 if(_uioFileDescriptor < 0) {
98 throw std::runtime_error(
"failed to open UIO device '" + filePath +
"'");
101 _uioProcFd = open(
"/proc/uio-dummy", O_RDWR);
103 throw std::runtime_error(
"failed to open UIO device '" + filePath +
"'");
107 std::string fileName = _deviceFilePath.filename().string();
108 _deviceMemSize = readUint64HexFromFile(
"/sys/class/uio/" + fileName +
"/maps/map0/size");
110 _memoryPointer = mmap(
nullptr, _deviceMemSize, PROT_READ | PROT_WRITE, MAP_SHARED, _uioFileDescriptor, 0);
112 if(_memoryPointer == MAP_FAILED) {
113 throw std::runtime_error(
"UioMmap construction failed");
116 auto [cat, metaCat] = p.
parse(mapFile);
117 _catalogue = std::move(cat);
125 munmap(_memoryPointer, _deviceMemSize);
126 close(_uioFileDescriptor);
133 static int enable{1};
134 std::ignore =
::write(_uioProcFd, &enable,
sizeof(enable));
140 return _deviceMemSize;
146 return _memoryPointer;
154 return *
reinterpret_cast<T*
>(
reinterpret_cast<std::byte*
>(
data()) + r.address);
162 *
reinterpret_cast<T*
>(
reinterpret_cast<std::byte*
>(
data()) + r.address) = value;
168uint64_t RawUioAccess::readUint64HexFromFile(
const std::string& filePath) {
170 std::ifstream inputFile(filePath.c_str());
172 if(inputFile.is_open()) {
173 inputFile >> std::hex >> value;
183template<
typename Derived>
185 Derived*
derived =
static_cast<Derived*
>(
this);
196 .disableSwitchReadOnly()
197 .disableSwitchWriteOnly()
198 .disableTestWriteNeverLosesData()
199 .disableAsyncReadInconsistency()
200 .enableTestRawTransfer();
205 template<
typename Type>
209 Type val00 = (
raw ? rawVal00 : rawToCooked<Type, rawUserType>(rawVal00));
215 template<
typename Type>
218 Type val00 = (
raw ? rawVal00 : rawToCooked<Type, rawUserType>(rawVal00));
224 auto x = generateValue<rawUserType>(
true)[0][0];
229 template<
typename UserType,
typename RawType>
231 return static_cast<RawType
>(val);
235 template<
typename UserType,
typename RawType>
237 return static_cast<UserType
>(val);
247 static std::string
path() {
return "TIMING.WORD_ID"; }
255 static std::string
path() {
return "MOTOR_CONTROL.MOTOR_POSITION"; }
271BOOST_AUTO_TEST_SUITE_END()
Set of AccessMode flags with additional functionality for an easier handling.
static std::pair< NumericAddressedRegisterCatalogue, MetadataCatalogue > parse(const std::string &fileName)
Performs parsing of specified MAP file, resulting in catalogue objects describing all registers and m...
NumericAddressedRegisterInfo getBackendRegister(const RegisterPath ®isterPathName) const override
Note: Override this function if backend has "hidden" registers which are not added to the map and hen...
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.
void write(const std::string &name, T value)
RawUioAccess(const std::string &filePath, const std::string &mapFile)
T read(const std::string &name)
size_t getMemorySize() const
void sendInterrupt() const
@ 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...
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
static std::string path()
static ChimeraTK::AccessModeFlags supportedFlags()
static bool isWriteable()
static bool isWriteable()
static std::string path()
size_t writeQueueLength()
size_t nElementsPerChannel()
std::vector< std::vector< Type > > getRemoteValue(bool raw=false)
UserType rawToCooked(RawType val)
size_t nRuntimeErrorCases()
void setForceRuntimeError(bool enable, size_t type)
minimumUserType rawUserType
std::vector< std::vector< Type > > generateValue(bool raw=false)
AccessModeFlags supportedFlags()
RawType cookedToRaw(UserType val)
static constexpr auto capabilities
std::shared_ptr< RawUioAccess > remote
const std::string lockfile
BOOST_AUTO_TEST_CASE(testUnified)