Skip to content
Snippets Groups Projects
Commit 9f9deb22 authored by Martin Christoph Hierholzer's avatar Martin Christoph Hierholzer
Browse files

added convenience read and write functions for tests

parent ec366499
No related branches found
No related tags found
No related merge requests found
...@@ -110,6 +110,39 @@ namespace ChimeraTK { ...@@ -110,6 +110,39 @@ namespace ChimeraTK {
return boost::fusion::at_key<T>(arrayMap.table)[name]; return boost::fusion::at_key<T>(arrayMap.table)[name];
} }
/** Convenience function to write a scalar process variable in a single call */
template<typename TYPE>
void writeScalar( const std::string &name, const TYPE value ) {
auto acc = getScalar<TYPE>(name);
acc = value;
acc.write();
}
/** Convenience function to write an array process variable in a single call */
template<typename TYPE>
void writeArray( const std::string &name, const std::vector<TYPE> &value ) {
auto acc = getArray<TYPE>(name);
acc = value;
acc.write();
}
/** Convenience function to read the latest value of a scalar process variable in a single call */
template<typename TYPE>
TYPE readScalar( const std::string &name ) {
auto acc = getScalar<TYPE>(name);
acc.readLatest();
return acc;
}
/** Convenience function to read the latest value of an array process variable in a single call */
template<typename TYPE>
std::vector<TYPE> readArray( const std::string &name ) {
auto acc = getArray<TYPE>(name);
acc.readLatest();
return acc;
}
protected: protected:
boost::shared_ptr<ControlSystemPVManager> pvManager; boost::shared_ptr<ControlSystemPVManager> pvManager;
......
...@@ -810,3 +810,38 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( testWithTriggerFanOut, T, test_types ) { ...@@ -810,3 +810,38 @@ BOOST_AUTO_TEST_CASE_TEMPLATE( testWithTriggerFanOut, T, test_types ) {
BOOST_CHECK(index.readNonBlocking() == false); BOOST_CHECK(index.readNonBlocking() == false);
} }
/*********************************************************************************************************************/
/* test convenience read functions */
BOOST_AUTO_TEST_CASE_TEMPLATE( testConvenienceRead, T, test_types ) {
std::cout << "*********************************************************************************************************************" << std::endl;
std::cout << "==> testConvenienceRead<" << typeid(T).name() << ">" << std::endl;
TestApplication<T> app;
app.cs("input") >> app.blockingReadTestModule.someInput;
app.blockingReadTestModule.someOutput >> app.cs("output");
app.asyncReadTestModule.connectTo(app.cs["async"]); // avoid runtime warning
app.readAnyTestModule.connectTo(app.cs["readAny"]); // avoid runtime warning
ctk::TestFacility test;
auto pvOutput = test.getScalar<T>("output");
test.runApplication();
// test blocking read when taking control in the test thread (note: the blocking read is executed in the app module!)
for(int i=0; i<5; ++i) {
test.writeScalar<T>("input", 120+i);
test.stepApplication();
CHECK_TIMEOUT(test.readScalar<T>("output") == 120+i, 200);
}
// same with array function (still a scalar variable behind, but this does not matter)
for(int i=0; i<5; ++i) {
std::vector<T> myValue{120+i};
test.writeArray<T>("input", myValue);
test.stepApplication();
CHECK_TIMEOUT(test.readArray<T>("output") == std::vector<T>{120+i}, 200);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment