Skip to content
Snippets Groups Projects
Commit 6a01d8b0 authored by Jens Georg's avatar Jens Georg
Browse files

Add test for heartbeat functionality

parent 3383574f
No related branches found
No related tags found
No related merge requests found
// Define a name for the test module.
#define BOOST_TEST_MODULE testHeartbeat
// Only after defining the name include the unit test header.
#include <boost/test/included/unit_test.hpp>
#include <ChimeraTK/ApplicationCore/TestFacility.h>
#include "Server.h"
#include "TecDummy.h"
namespace ctk = ChimeraTK;
// Declare the server instance
struct Fixture_t {
Server theServer{"tec_dummy"};
ChimeraTK::TestFacility testFacility;
boost::shared_ptr<TecDummy> dummy{
boost::dynamic_pointer_cast<TecDummy>(ChimeraTK::BackendFactory::getInstance().createBackend("ActualDevice"))};
};
using namespace boost::unit_test_framework;
BOOST_AUTO_TEST_SUITE(TecHeartbeatTestSuite)
/**********************************************************************************************************************/
BOOST_FIXTURE_TEST_CASE(testHeartbeatEnableDisable, Fixture_t) {
std::cout << "testHearbeatEnableDisable" << std::endl;
auto heartbeatEnable = testFacility.getScalar<ctk::Boolean>("TecModule/enableHeartbeat");
auto deviceType = testFacility.getScalar<int>("TecModule/mon_deviceType_rd");
testFacility.runApplication();
// Set the device type, the module should not read that as neither heartbeat is on, nor explicit read request for
// the property and not added to periodic readout
int setDeviceType = 4711;
dummy->set(TecFrame::TecParameter::DeviceType, setDeviceType);
theServer.periodicRead.sendTrigger();
testFacility.stepApplication();
deviceType.readLatest();
BOOST_CHECK_EQUAL(deviceType, 0);
// enable heartbeat, whe should get the value set above
heartbeatEnable = true;
heartbeatEnable.write();
theServer.periodicRead.sendTrigger();
testFacility.stepApplication();
deviceType.readLatest();
BOOST_CHECK_EQUAL(setDeviceType, deviceType);
// change value, should be updated in the module
setDeviceType++;
dummy->set(TecFrame::TecParameter::DeviceType, setDeviceType);
theServer.periodicRead.sendTrigger();
testFacility.stepApplication();
deviceType.readLatest();
BOOST_CHECK_EQUAL(setDeviceType, deviceType);
// disable heartbeat, update value. Value in module should stay the same
heartbeatEnable = false;
heartbeatEnable.write();
setDeviceType++;
dummy->set(TecFrame::TecParameter::DeviceType, setDeviceType);
theServer.periodicRead.sendTrigger();
testFacility.stepApplication();
deviceType.readLatest();
BOOST_CHECK_EQUAL(setDeviceType - 1, deviceType);
}
/**********************************************************************************************************************/
BOOST_FIXTURE_TEST_CASE(testHearbeatOnPeriodicRead, Fixture_t) {
std::cout << "testHearbeatOnPeriodicRead" << std::endl;
auto heartbeatEnable = testFacility.getScalar<ctk::Boolean>("TecModule/enableHeartbeat");
auto deviceType = testFacility.getScalar<int>("TecModule/mon_deviceType_rd");
int setDeviceType = 4811;
dummy->set(TecFrame::TecParameter::DeviceType, setDeviceType);
// Enable heartbeat, check that information from the heartbeat register is read
testFacility.runApplication();
heartbeatEnable = true;
heartbeatEnable.write();
theServer.periodicRead.sendTrigger();
testFacility.stepApplication();
deviceType.readLatest();
BOOST_CHECK_EQUAL(setDeviceType, deviceType);
// Add a variable to the periodic read. The module should stop reading out the heartbeat register
testFacility.writeScalar<int>("TecModule/mon_serialNumber_enaPeriodicRead", 1);
int lastDeviceType = setDeviceType;
for(int i = 0; i < 10; i++) {
dummy->set(TecFrame::TecParameter::DeviceType, ++setDeviceType);
theServer.periodicRead.sendTrigger();
testFacility.stepApplication();
deviceType.readLatest();
BOOST_CHECK_EQUAL(lastDeviceType, deviceType);
}
// disable periodic variable. HB register should be updated again
testFacility.writeScalar<int>("TecModule/mon_serialNumber_enaPeriodicRead", 0);
theServer.periodicRead.sendTrigger();
testFacility.stepApplication();
deviceType.readLatest();
BOOST_CHECK_EQUAL(setDeviceType, deviceType);
}
/**********************************************************************************************************************/
BOOST_FIXTURE_TEST_CASE(testHearbeatFailCausesModuleError, Fixture_t) {
std::cout << "testHearbeatOnPeriodicRead" << std::endl;
auto heartbeatEnable = testFacility.getScalar<ctk::Boolean>("TecModule/enableHeartbeat");
auto deviceType = testFacility.getScalar<int>("TecModule/mon_deviceType_rd");
auto errorMessage = testFacility.getScalar<std::string>("TecModule/errorMessage");
auto errorStatus = testFacility.getScalar<int>("TecModule/errorStatus");
auto errorReset = testFacility.getScalar<int>("TecModule/errorReset");
int setDeviceType = 4811;
dummy->set(TecFrame::TecParameter::DeviceType, setDeviceType);
// Enable heartbeat, check that information from the heartbeat register is read
testFacility.runApplication();
heartbeatEnable = true;
heartbeatEnable.write();
theServer.periodicRead.sendTrigger();
testFacility.stepApplication();
deviceType.readLatest();
BOOST_CHECK_EQUAL(setDeviceType, deviceType);
dummy->simulateSerialTimeout = true;
theServer.periodicRead.sendTrigger();
testFacility.stepApplication();
deviceType.readLatest();
BOOST_CHECK(deviceType.dataValidity() == ctk::DataValidity::faulty);
BOOST_CHECK(errorMessage.readNonBlocking());
BOOST_CHECK(errorStatus.readNonBlocking());
BOOST_CHECK(std::string(errorMessage) != "");
BOOST_CHECK(std::string(errorMessage).find("mon_deviceType") != std::string::npos);
BOOST_CHECK(errorStatus != 0);
BOOST_CHECK_EQUAL(setDeviceType, deviceType);
}
/**********************************************************************************************************************/
BOOST_AUTO_TEST_SUITE_END()
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