Skip to content
Snippets Groups Projects
Commit dd37387f authored by Martin Killenberg's avatar Martin Killenberg
Browse files

device is re-initialised after exception

parent e41b3f35
No related branches found
No related tags found
No related merge requests found
...@@ -298,6 +298,11 @@ namespace ChimeraTK { ...@@ -298,6 +298,11 @@ namespace ChimeraTK {
deviceError.setCurrentVersionNumber({}); deviceError.setCurrentVersionNumber({});
deviceError.writeAll(); deviceError.writeAll();
errorCondVar.notify_all(); errorCondVar.notify_all();
// re-initialise the device before continuing
for (auto& initHandler : initialisationHandlers) {
initHandler(this);
}
} }
} }
catch(...) { catch(...) {
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "DeviceModule.h" #include "DeviceModule.h"
//#include "ScalarAccessor.h" //#include "ScalarAccessor.h"
#include "TestFacility.h" #include "TestFacility.h"
//#include "StatusMonitor.h" #include "ExceptionDevice.h"
#include <ChimeraTK/Device.h> #include <ChimeraTK/Device.h>
...@@ -22,6 +22,16 @@ void initialiseReg1(ctk::DeviceModule * dev){ ...@@ -22,6 +22,16 @@ void initialiseReg1(ctk::DeviceModule * dev){
dev->device.write<int32_t>("/REG1",42); dev->device.write<int32_t>("/REG1",42);
} }
void initialiseReg2(ctk::DeviceModule * dev){
// the initialisation of reg 2 must happen after the initialisation of reg1
dev->device.write<int32_t>("/REG2", dev->device.read<int32_t>("/REG1")+5);
}
void initialiseReg3(ctk::DeviceModule * dev){
// the initialisation of reg 3 must happen after the initialisation of reg2
dev->device.write<int32_t>("/REG3", dev->device.read<int32_t>("/REG2")+5);
}
/* dummy application */ /* dummy application */
struct TestApplication : public ctk::Application { struct TestApplication : public ctk::Application {
TestApplication() : Application("testSuite") {} TestApplication() : Application("testSuite") {}
...@@ -29,7 +39,7 @@ struct TestApplication : public ctk::Application { ...@@ -29,7 +39,7 @@ struct TestApplication : public ctk::Application {
void defineConnections() {} // the setup is done in the tests void defineConnections() {} // the setup is done in the tests
ctk::ControlSystemModule cs; ctk::ControlSystemModule cs;
ctk::DeviceModule dev{this, "(dummy?map=test.map)",&initialiseReg1}; ctk::DeviceModule dev{this, "(ExceptionDummy?map=test.map)",&initialiseReg1};
}; };
/*********************************************************************************************************************/ /*********************************************************************************************************************/
...@@ -44,79 +54,48 @@ BOOST_AUTO_TEST_CASE(testBasicInitialisation) { ...@@ -44,79 +54,48 @@ BOOST_AUTO_TEST_CASE(testBasicInitialisation) {
//app.dumpConnections(); //app.dumpConnections();
ctk::Device dummy; ctk::Device dummy;
dummy.open("(dummy?map=test.map)"); dummy.open("(ExceptionDummy?map=test.map)");
BOOST_CHECK_EQUAL(dummy.read<int32_t>("REG1"),42); auto reg1 = dummy.getScalarRegisterAccessor<int32_t>("/REG1");
reg1.read();
// auto error = test.getScalar<double_t>(std::string("/MAX_MONITOR.ERROR.THRESHOLD"));
// error = 50.1; // ********************************************************
// error.write(); // REQUIRED TEST 1: After opening the device is initialised
// test.stepApplication(); // ********************************************************
BOOST_CHECK_EQUAL(reg1,42);
// auto watch = test.getScalar<double_t>(std::string("/WATCH"));
// watch = 40.1; reg1=0;
// watch.write(); reg1.write();
// test.stepApplication();
// check that accessing an exception triggers a reconnection with re-initialisation
// auto status = test.getScalar<uint16_t>(std::string("/STATUS")); auto dummyBackend = boost::dynamic_pointer_cast<ExceptionDummy>(ctk::BackendFactory::getInstance().createBackend("(ExceptionDummy?map=test.map)"));
// status.readLatest(); dummyBackend->throwExceptionWrite=true;
// //should be in OK state. // FIXME: Due to a bug it is /REG2/REG2 instead of just /REG2. This will fails once the bug has been solved.
// BOOST_CHECK_EQUAL(status,ChimeraTK::States::OK); auto reg2_cs = test.getScalar<int32_t>("/REG2/REG2");
reg2_cs=19;
// //set watch value exceeding warning level reg2_cs.write();
// watch = 46.1; test.stepApplication();
// watch.write();
// test.stepApplication(); auto reg2 = dummy.getScalarRegisterAccessor<int32_t>("/REG2");
// status.readLatest(); reg2.read();
// //should be in WARNING state.
// BOOST_CHECK_EQUAL(status,ChimeraTK::States::WARNING); BOOST_CHECK_EQUAL(reg2,0);
BOOST_CHECK_EQUAL(reg1,0);
// //set watch value exceeding error level dummyBackend->throwExceptionWrite=false; // now the device should work again and be re-initialised
// watch = 51.1;
// watch.write(); reg2_cs=20;
// test.stepApplication(); reg2_cs.write();
// status.readLatest(); test.stepApplication();
// //should be in ERROR state.
// BOOST_CHECK_EQUAL(status,ChimeraTK::States::ERROR); reg2.read();
BOOST_CHECK_EQUAL(reg2,20);
// //increase error value greater than watch
// error = 60.1; // ****************************************************************
// error.write(); // REQUIRED TEST 2: After an exception the device is re-initialised
// test.stepApplication(); // ****************************************************************
// status.readLatest(); reg1.read();
// //should be in WARNING state. BOOST_CHECK_EQUAL(reg1, 42);
// BOOST_CHECK_EQUAL(status,ChimeraTK::States::WARNING);
// //increase warning value greater than watch
// warning = 55.1;
// warning.write();
// test.stepApplication();
// status.readLatest();
// //should be in OK state.
// BOOST_CHECK_EQUAL(status,ChimeraTK::States::OK);
// //set watch value exceeding error level
// watch = 65.1;
// watch.write();
// test.stepApplication();
// status.readLatest();
// //should be in ERROR state.
// BOOST_CHECK_EQUAL(status,ChimeraTK::States::ERROR);
// //decrease watch value lower than error level but still greater than warning level
// watch = 58.1;
// watch.write();
// test.stepApplication();
// status.readLatest();
// //should be in WARNING state.
// BOOST_CHECK_EQUAL(status,ChimeraTK::States::WARNING);
// //decrease watch value lower than warning level
// watch = 54.1;
// watch.write();
// test.stepApplication();
// status.readLatest();
// //should be in OK state.
// BOOST_CHECK_EQUAL(status,ChimeraTK::States::OK);
} }
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