Skip to content
Snippets Groups Projects
Commit 7be10d77 authored by vargheseg's avatar vargheseg
Browse files

testcase: runtimeErrorHandling_testPolledRead

parent 468fe158
No related branches found
No related tags found
No related merge requests found
#include <ChimeraTK/ScalarRegisterAccessor.h>
#include <cstring> #include <cstring>
#include <future> #include <future>
...@@ -85,6 +86,8 @@ struct Fixture_noTestFacility { ...@@ -85,6 +86,8 @@ struct Fixture_noTestFacility {
deviceBackend->open(); deviceBackend->open();
testFacitiy.runApplication(); testFacitiy.runApplication();
hwRegister.replace(application.device.device.getScalarRegisterAccessor<int>("/REG1"));
status.replace( status.replace(
testFacitiy.getScalar<int>(ctk::RegisterPath("/Devices") / DummyApplication::ExceptionDummyCDD1 / "status")); testFacitiy.getScalar<int>(ctk::RegisterPath("/Devices") / DummyApplication::ExceptionDummyCDD1 / "status"));
message.replace(testFacitiy.getScalar<std::string>( message.replace(testFacitiy.getScalar<std::string>(
...@@ -120,6 +123,7 @@ struct Fixture_noTestFacility { ...@@ -120,6 +123,7 @@ struct Fixture_noTestFacility {
ctk::ScalarRegisterAccessor<int> status; ctk::ScalarRegisterAccessor<int> status;
ctk::ScalarRegisterAccessor<std::string> message; ctk::ScalarRegisterAccessor<std::string> message;
ctk::ScalarRegisterAccessor<int> hwRegister;
}; };
/* /*
...@@ -165,14 +169,83 @@ BOOST_FIXTURE_TEST_CASE(runtimeErrorHandling_testFaultReporting, Fixture_noTestF ...@@ -165,14 +169,83 @@ BOOST_FIXTURE_TEST_CASE(runtimeErrorHandling_testFaultReporting, Fixture_noTestF
BOOST_CHECK(static_cast<std::string>(message) == ""); BOOST_CHECK(static_cast<std::string>(message) == "");
} }
BOOST_AUTO_TEST_CASE(testBlockingRead) { // wait_for_new_data /*
// how does the api of the accessor look like * Test read operation on poll type variable when a device runtime exception occours; A poll type
//device1DummyBackend["m1"]("i3")[cs("trigger", typeid(int), 1)] >> cs("i3", typeid(int), 1); * variable does not have its AccessMode as wait_for_new_data.
// make one with wait_for_new_data *
* For such a variable:
* - read is skipped till device recovers.
* - first skipped instance of read changes datavalidity flag to faulty and generates a new version
* number which stays the same till the device recovers
*/
BOOST_FIXTURE_TEST_CASE(runtimeErrorHandling_testPolledRead, Fixture_noTestFacility) {
std::cout << "runtimeErrorHandling_testPolledRead" << std::endl;
// since the testFacility cannot access the poll type process variable directly, we make use of
// proxy variable o1 that is linked with this poll type variable.
auto proxyVariable = testFacitiy.getScalar<int>("/o1");
// initialize to known value in deviceBackend register
hwRegister = 100;
hwRegister.write();
// verify normal operation
/************************************************************************************************/
application.pollModule.triggerRead();
proxyVariable.read();
auto versionNumberBeforeRuntimeError = proxyVariable.getVersionNumber();
BOOST_CHECK_EQUAL(proxyVariable, 100);
BOOST_CHECK(proxyVariable.dataValidity() == ctk::DataValidity::ok);
/************************************************************************************************/
// Behavior on Runtime error on device:
/************************************************************************************************/
hwRegister = 10;
hwRegister.write();
// The framework decides the accessmode flags based on how the wiring looks like: deviceBackend->throwExceptionRead = true;
//
// we will have to make up wiring to get what we desire. application.pollModule.triggerRead();
proxyVariable.read();
auto versionNumberOnRuntimeError = proxyVariable.getVersionNumber();
BOOST_CHECK_EQUAL(proxyVariable, 100);
BOOST_CHECK(proxyVariable.dataValidity() == ctk::DataValidity::faulty);
BOOST_CHECK(versionNumberOnRuntimeError > versionNumberBeforeRuntimeError);
/************************************************************************************************/
// Behavior on persisting Runtime error:
/************************************************************************************************/
application.pollModule.triggerRead();
proxyVariable.read();
auto versionNumber = proxyVariable.getVersionNumber();
BOOST_CHECK_EQUAL(proxyVariable, 100);
BOOST_CHECK(proxyVariable.dataValidity() == ctk::DataValidity::faulty);
BOOST_CHECK(versionNumber == versionNumberOnRuntimeError);
/************************************************************************************************/
deviceBackend->throwExceptionRead = false;
// workaround: wait till device module recovey completes; assumption: status variable == 0 =>
// device recovered.
CHECK_TIMEOUT(
[&]() {
status.readLatest();
return static_cast<int>(status);
}() == 0,
10000);
// Behavior on device recovery
/************************************************************************************************/
application.pollModule.triggerRead();
proxyVariable.read();
auto versionNumberAfterRecovery = proxyVariable.getVersionNumber();
BOOST_CHECK_EQUAL((int)proxyVariable, 10);
BOOST_CHECK(proxyVariable.dataValidity() == ctk::DataValidity::ok);
BOOST_CHECK(versionNumberAfterRecovery > versionNumberOnRuntimeError);
/************************************************************************************************/
} }
BOOST_AUTO_TEST_CASE(testReadLatest) {} BOOST_AUTO_TEST_CASE(testReadLatest) {}
......
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