4 #define BOOST_TEST_DYN_LINK
6 #define BOOST_TEST_MODULE SharedDummyBackendUnified
8 #include <boost/test/unit_test.hpp>
9 using namespace boost::unit_test_framework;
23 BOOST_AUTO_TEST_SUITE(SharedDummyBackendUnifiedTestSuite)
28 static std::string instanceId{
"1"};
29 static std::string mapFileName{
"sharedDummyUnified.map"};
30 static std::string
cdd(std::string(
"(sharedMemoryDummy:") + instanceId +
"?map=" + mapFileName +
")");
31 static boost::shared_ptr<SharedDummyBackend> sharedDummy;
35 static TestLocker testLocker(
"sharedDummyUnified.dmap");
41 sharedDummy = boost::dynamic_pointer_cast<SharedDummyBackend>(BackendFactory::getInstance().createBackend(
cdd));
43 mirrorRequest.type = sharedDummy->getRegisterAccessor<uint32_t>(
"MIRRORREQUEST/TYPE", 1, 0,
AccessModeFlags{});
44 mirrorRequest.busy = sharedDummy->getRegisterAccessor<uint32_t>(
"MIRRORREQUEST/BUSY", 1, 0,
AccessModeFlags{});
48 mirrorRequest.updated = sharedDummy->getRegisterAccessor<uint32_t>(
49 "MIRRORREQUEST/UPDATED", 1, 0,
AccessModeFlags{AccessMode::wait_for_new_data});
50 mirrorRequest.triggerInterrupt =
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;
65 mirrorRequest.triggerInterrupt->write();
66 mirrorRequest.type->accessData(0) = (int)reqType;
67 mirrorRequest.type->write();
68 mirrorRequest.busy->accessData(0) = 1;
69 mirrorRequest.busy->write();
73 boost::this_thread::sleep_for(boost::chrono::milliseconds(50));
74 mirrorRequest.busy->readLatest();
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.");
100 mirrorRequest.type.reset();
101 mirrorRequest.busy.reset();
102 mirrorRequest.updated.reset();
103 mirrorRequest.triggerInterrupt.reset();
110 template<
typename Derived>
112 Derived* derived{
static_cast<Derived*
>(
this)};
123 .disableSwitchReadOnly()
124 .disableSwitchWriteOnly()
125 .disableTestWriteNeverLosesData()
126 .disableAsyncReadInconsistency()
127 .enableTestRawTransfer();
129 boost::shared_ptr<NDRegisterAccessor<minimumUserType>> acc{
131 boost::shared_ptr<NDRegisterAccessor<rawUserType>> accBackdoor{sharedDummy->getRegisterAccessor<
rawUserType>(
132 std::string(
"MIRRORED/") + derived->path(), 1, 0, {AccessMode::raw})};
141 template<
typename Type>
144 accBackdoor->readLatest();
147 Type val00 = (
raw ? rawVal00 : derived->template rawToCooked<Type, rawUserType>(rawVal00));
152 template<
typename Type>
156 accBackdoor->readLatest();
158 Type val00 = (
raw ? rawVal00 : derived->template rawToCooked<Type, rawUserType>(rawVal00));
165 auto x = generateValue<rawUserType>(
true)[0][0];
166 accBackdoor->accessData(0) = x;
167 accBackdoor->write();
172 template<
typename UserType,
typename RawType>
174 return static_cast<RawType
>(val);
178 template<
typename UserType,
typename RawType>
180 return static_cast<UserType
>(val);
188 std::string
path() {
return "INTC_RW"; }
193 std::string
path() {
return "INTA_RO"; }
198 std::string
path() {
return "INTB_WO"; }
203 std::string
path() {
return "INTA_RO/DUMMY_WRITEABLE"; }
210 std::string
path() {
return "INTD_ASYNC"; }
217 template<
typename UserType>
224 auto x = generateValue<minimumUserType>()[0][0];
225 accBackdoor->accessData(0) = x;
226 accBackdoor->write();
238 std::cout <<
"*** testRegisterAccessor *** " << std::endl;
241 .addRegister<Integers_signed32_RO>()
243 .addRegister<Integers_signed32_DummyWritable>()
262 boost::filesystem::path absPathToMapFile = boost::filesystem::absolute(mapFileName);
269 BOOST_AUTO_TEST_SUITE_END()