4#define BOOST_TEST_DYN_LINK
6#define BOOST_TEST_MODULE SharedDummyBackendUnified
8#include <boost/test/unit_test.hpp>
9using namespace boost::unit_test_framework;
20BOOST_AUTO_TEST_SUITE(SharedDummyBackendUnifiedTestSuite)
25static std::string instanceId{
"1"};
26static std::string mapFileName{
"sharedDummyUnified.map"};
30static std::string
cdd(std::string(
"(sharedMemoryDummy:") + instanceId +
"?map=" + mapFileName +
")");
31static boost::shared_ptr<SharedDummyBackend> sharedDummy;
35static TestLocker testLocker(
"sharedDummyUnified.dmap");
48 mirrorRequest.updated = sharedDummy->getRegisterAccessor<uint32_t>(
49 "MIRRORREQUEST/UPDATED", 1, 0,
AccessModeFlags{AccessMode::wait_for_new_data});
51 sharedDummy->getRegisterAccessor<uint32_t>(
"MIRRORREQUEST/DATA_INTERRUPT", 1, 0, {});
55 boost::shared_ptr<NDRegisterAccessor<uint32_t>>
type;
56 boost::shared_ptr<NDRegisterAccessor<uint32_t>>
busy;
57 boost::shared_ptr<NDRegisterAccessor<uint32_t>>
updated;
64 mirrorRequest.triggerInterrupt->accessData(0) = triggerDataInterrupt ? 1 : 0;
73 boost::this_thread::sleep_for(boost::chrono::milliseconds(50));
75 }
while(
mirrorRequest.busy->accessData(0) == 1 && (--timeoutCnt >= 0));
76 BOOST_CHECK(timeoutCnt >= 0);
81 BOOST_CHECK(!std::system(
"./testSharedDummyBackendUnifiedExt "
82 "--run_test=SharedDummyBackendUnifiedTestSuite/testRegisterAccessor > /dev/null"
83 " & echo $! > ./testSharedDummyBackendUnifiedExt.pid"));
85 boost::this_thread::sleep_for(boost::chrono::milliseconds(100));
86 BOOST_REQUIRE_MESSAGE(std::system(
"ps $(cat testSharedDummyBackendUnifiedExt.pid) > /dev/null") == 0,
87 "FATAL: background application \'testSharedDummyBackendUnifiedExt\' not running!");
92 auto ret = std::system(
"pidfile=./testSharedDummyBackendUnifiedExt.pid; if [ -f $pidfile ]; "
93 "then kill $(cat $pidfile); rm $pidfile; fi ");
95 throw std::runtime_error(
"Attempt to kill helper process failed.");
109 catch(std::exception& e) {
111 std::cerr <<
"Caught exception when killing helper process: " << e.what() << std::endl;
118template<
typename Derived>
120 Derived*
derived{
static_cast<Derived*
>(
this)};
131 .disableSwitchReadOnly()
132 .disableSwitchWriteOnly()
133 .disableTestWriteNeverLosesData()
134 .disableAsyncReadInconsistency()
135 .enableTestRawTransfer();
137 boost::shared_ptr<NDRegisterAccessor<minimumUserType>>
acc{
140 std::string(
"MIRRORED/") +
derived->path(
true), 1, 0, {AccessMode::raw})};
149 template<
typename Type>
155 Type val00 = (
raw ? rawVal00 :
derived->template rawToCooked<Type, rawUserType>(rawVal00));
160 template<
typename Type>
166 Type val00 = (
raw ? rawVal00 :
derived->template rawToCooked<Type, rawUserType>(rawVal00));
173 auto x = generateValue<rawUserType>(
true)[0][0];
180 template<
typename UserType,
typename RawType>
182 return static_cast<RawType
>(val);
186 template<
typename UserType,
typename RawType>
188 return static_cast<UserType
>(val);
196 static std::string
path([[maybe_unused]]
bool mirrored =
false) {
return "INTC_RW"; }
201 static std::string
path([[maybe_unused]]
bool mirrored =
false) {
return "INTA_RO"; }
206 static std::string
path([[maybe_unused]]
bool mirrored =
false) {
return "INTB_WO"; }
211 static std::string
path(
bool mirrored =
false) {
return !mirrored ?
"INTA_RO/DUMMY_WRITEABLE" :
"INTA_RO"; }
218 static std::string
path([[maybe_unused]]
bool mirrored =
false) {
return "INTD_ASYNC"; }
225 template<
typename UserType>
232 auto x = generateValue<minimumUserType>()[0][0];
244 SharedDummyBackendUnifiedTestSuite::HelperProcess::start();
246 std::cout <<
"*** testRegisterAccessor *** " << std::endl;
249 .addRegister<IntegersSigned32RO>()
251 .addRegister<IntegersSigned32DummyWritable>()
255 SharedDummyBackendUnifiedTestSuite::HelperProcess::kill();
262 SharedDummyBackendUnifiedTestSuite::HelperProcess::start();
271 bool shm_removed{
false};
272 for(
size_t n = 0; n < 30; ++n) {
279 BOOST_CHECK(shm_removed);
282BOOST_AUTO_TEST_SUITE_END()
std::string getUserName()
Set of AccessMode flags with additional functionality for an easier handling.
static BackendFactory & getInstance()
Static function to get an instance of factory.
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.
std::size_t shmDummyInstanceIdHash(const std::string &address, const std::map< std::string, std::string > ¶meters)
Generates shm dummy instanceId hash from address and parameter map, Intended for use with parseDevice...
std::string createShmName(std::size_t instanceIdHash, const std::string &mapFileName, const std::string &userName)
Generates shm dummy name from parameter hashes.
@ 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...
bool shm_exists(std::string shmName)
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
void requestMirroring(MirrorRequestType reqType, bool triggerDataInterrupt=false) const
boost::shared_ptr< NDRegisterAccessor< uint32_t > > updated
struct HelperProcess::@1 mirrorRequest
boost::shared_ptr< NDRegisterAccessor< uint32_t > > triggerInterrupt
boost::shared_ptr< NDRegisterAccessor< uint32_t > > type
boost::shared_ptr< NDRegisterAccessor< uint32_t > > busy
void stopGracefully() const
size_t nElementsPerChannel()
std::vector< std::vector< Type > > generateValue(bool raw=false)
boost::shared_ptr< NDRegisterAccessor< minimumUserType > > acc
ChimeraTK::AccessModeFlags supportedFlags()
size_t writeQueueLength()
static constexpr auto capabilities
boost::shared_ptr< NDRegisterAccessor< rawUserType > > accBackdoor
UserType rawToCooked(RawType val)
std::vector< std::vector< Type > > getRemoteValue(bool raw=false)
size_t nRuntimeErrorCases()
RawType cookedToRaw(UserType val)
void setForceRuntimeError(bool, size_t)
minimumUserType rawUserType
static bool isWriteable()
std::vector< std::vector< UserType > > generateValue(bool=false)
static std::string path(bool mirrored=false)
static ChimeraTK::AccessModeFlags supportedFlags()
static std::string path(bool mirrored=false)
static bool isWriteable()
static bool isWriteable()
static std::string path(bool mirrored=false)
static std::string path(bool mirrored=false)
static bool isWriteable()
static bool isWriteable()
static std::string path(bool mirrored=false)
const int timeOutForWaitOnHelperProcess_ms
struct HelperProcess gHelperProcess
BOOST_AUTO_TEST_CASE(TestRegisterAccessor)