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;
21BOOST_AUTO_TEST_SUITE(SharedDummyBackendUnifiedTestSuite)
26static std::string instanceId{
"1"};
27static std::string mapFileName{
"sharedDummyUnified.map"};
31static std::string
cdd(std::string(
"(sharedMemoryDummy:") + instanceId +
"?map=" + mapFileName +
")");
32static boost::shared_ptr<SharedDummyBackend> sharedDummy;
36static TestLocker testLocker(
"sharedDummyUnified.dmap");
49 mirrorRequest.updated = sharedDummy->getRegisterAccessor<uint32_t>(
50 "MIRRORREQUEST/UPDATED", 1, 0,
AccessModeFlags{AccessMode::wait_for_new_data});
52 sharedDummy->getRegisterAccessor<uint32_t>(
"MIRRORREQUEST/DATA_INTERRUPT", 1, 0, {});
56 boost::shared_ptr<NDRegisterAccessor<uint32_t>>
type;
57 boost::shared_ptr<NDRegisterAccessor<uint32_t>>
busy;
58 boost::shared_ptr<NDRegisterAccessor<uint32_t>>
updated;
65 mirrorRequest.triggerInterrupt->accessData(0) = triggerDataInterrupt ? 1 : 0;
74 boost::this_thread::sleep_for(boost::chrono::milliseconds(50));
76 }
while(
mirrorRequest.busy->accessData(0) == 1 && (--timeoutCnt >= 0));
77 BOOST_CHECK(timeoutCnt >= 0);
82 BOOST_CHECK(!std::system(
"./testSharedDummyBackendUnifiedExt "
83 "--run_test=SharedDummyBackendUnifiedTestSuite/testRegisterAccessor > /dev/null"
84 " & echo $! > ./testSharedDummyBackendUnifiedExt.pid"));
86 boost::this_thread::sleep_for(boost::chrono::milliseconds(100));
87 BOOST_REQUIRE_MESSAGE(std::system(
"ps $(cat testSharedDummyBackendUnifiedExt.pid) > /dev/null") == 0,
88 "FATAL: background application \'testSharedDummyBackendUnifiedExt\' not running!");
93 auto ret = std::system(
"pidfile=./testSharedDummyBackendUnifiedExt.pid; if [ -f $pidfile ]; "
94 "then kill $(cat $pidfile); rm $pidfile; fi ");
96 throw std::runtime_error(
"Attempt to kill helper process failed.");
110 catch(std::exception& e) {
112 std::cerr <<
"Caught exception when killing helper process: " << e.what() << std::endl;
119template<
typename Derived>
121 Derived*
derived{
static_cast<Derived*
>(
this)};
132 .disableSwitchReadOnly()
133 .disableSwitchWriteOnly()
134 .disableTestWriteNeverLosesData()
135 .disableAsyncReadInconsistency()
136 .enableTestRawTransfer();
138 boost::shared_ptr<NDRegisterAccessor<minimumUserType>>
acc{
141 std::string(
"MIRRORED/") +
derived->path(
true), 1, 0, {AccessMode::raw})};
150 template<
typename Type>
156 Type val00 = (
raw ? rawVal00 :
derived->template rawToCooked<Type, rawUserType>(rawVal00));
161 template<
typename Type>
167 Type val00 = (
raw ? rawVal00 :
derived->template rawToCooked<Type, rawUserType>(rawVal00));
174 auto x = generateValue<rawUserType>(
true)[0][0];
181 template<
typename UserType,
typename RawType>
183 return static_cast<RawType
>(val);
187 template<
typename UserType,
typename RawType>
189 return static_cast<UserType
>(val);
197 static std::string
path([[maybe_unused]]
bool mirrored =
false) {
return "INTC_RW"; }
202 static std::string
path([[maybe_unused]]
bool mirrored =
false) {
return "INTA_RO"; }
207 static std::string
path([[maybe_unused]]
bool mirrored =
false) {
return "INTB_WO"; }
212 static std::string
path(
bool mirrored =
false) {
return !mirrored ?
"INTA_RO/DUMMY_WRITEABLE" :
"INTA_RO"; }
219 static std::string
path([[maybe_unused]]
bool mirrored =
false) {
return "INTD_ASYNC"; }
226 template<
typename UserType>
233 auto x = generateValue<minimumUserType>()[0][0];
245 SharedDummyBackendUnifiedTestSuite::HelperProcess::start();
247 std::cout <<
"*** testRegisterAccessor *** " << std::endl;
250 .addRegister<IntegersSigned32RO>()
252 .addRegister<IntegersSigned32DummyWritable>()
256 SharedDummyBackendUnifiedTestSuite::HelperProcess::kill();
263 SharedDummyBackendUnifiedTestSuite::HelperProcess::start();
272 bool shm_removed{
false};
273 for(
size_t n = 0; n < 30; ++n) {
280 BOOST_CHECK(shm_removed);
283BOOST_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)