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

wip #6588: split test into its own cc file, extend tests a bit

parent dc9a8e65
No related branches found
No related tags found
No related merge requests found
// Define a name for the test module.
#define BOOST_TEST_MODULE testErrorCodes
// Only after defining the name include the unit test header.
#include <boost/test/included/unit_test.hpp>
#include <ChimeraTK/ApplicationCore/TestFacility.h>
#include <ChimeraTK/BackendFactory.h>
#include "Server.h"
#include "TecDummy.h"
using namespace boost::unit_test_framework;
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"))};
};
/// TestSuite for the server, adapt name
BOOST_AUTO_TEST_SUITE(TecServerTestSuite)
/**********************************************************************************************************************/
/// Test write of an out-of-range value
BOOST_FIXTURE_TEST_CASE(testOutOfRange, Fixture_t) {
std::cout << "testOutOfRange" << std::endl;
auto fanControlEnable = testFacility.getScalar<int>("TecModule/ctrl_ch1_fanControlEnable_wr");
auto fanTargetTemp = testFacility.getScalar<float>("TecModule/ctrl_ch1_fanTargetTemp_wr");
auto writeCh1Group7 = testFacility.getScalar<int>("TecModule/writeCh1Group7_wr");
auto targetObjectTemp = testFacility.getScalar<float>("TecModule/ctrl_ch1_targetObjectTemp_wr");
auto writeCh1Group1 = testFacility.getScalar<int>("TecModule/writeCh1Group1_wr");
auto errorMessage = testFacility.getScalar<std::string>("TecModule/errorMessage");
auto errorStatus = testFacility.getScalar<int>("TecModule/errorStatus");
auto errorReset = testFacility.getScalar<int>("TecModule/errorReset");
testFacility.runApplication();
// initially everything should work as normal, no error message must be produced
fanControlEnable = 1;
fanControlEnable.write();
writeCh1Group7.write();
BOOST_CHECK_EQUAL(dummy->getInt(TecFrame::TecParameter::ExpFanControlEnable), 0);
testFacility.stepApplication();
BOOST_CHECK_EQUAL(dummy->getInt(TecFrame::TecParameter::ExpFanControlEnable), 1);
BOOST_CHECK(!errorMessage.readLatest());
BOOST_CHECK(!errorStatus.readLatest());
BOOST_CHECK(std::string(errorMessage) == "");
BOOST_CHECK(errorStatus == 0);
// inject error in dummy
dummy->errorFlags[TecFrame::TecParameter::ExpFanControlEnable] = TecErrorCode::EER_PAR_OUT_OF_RANGE;
fanControlEnable = 42;
fanControlEnable.write();
writeCh1Group7.write();
BOOST_CHECK_EQUAL(dummy->getInt(TecFrame::TecParameter::ExpFanControlEnable), 1);
testFacility.stepApplication();
BOOST_CHECK(errorMessage.readLatest());
BOOST_CHECK(errorStatus.readLatest());
BOOST_CHECK(std::string(errorMessage) != "");
BOOST_CHECK(std::string(errorMessage).find("ctrl_ch1_fanControlEnable") != std::string::npos);
BOOST_CHECK(errorStatus != 0);
BOOST_CHECK_EQUAL(dummy->getInt(TecFrame::TecParameter::ExpFanControlEnable), 1);
// error needs to be reset manually
errorReset.write();
BOOST_CHECK(errorMessage.readLatest());
BOOST_CHECK(errorStatus.readLatest());
BOOST_CHECK(std::string(errorMessage) == "");
BOOST_CHECK(errorStatus == 0);
// check other variable in different group: no error should be observed
targetObjectTemp = 3.1415;
targetObjectTemp.write();
writeCh1Group1.write();
BOOST_CHECK_CLOSE(dummy->getFloat(TecFrame::TecParameter::TemTargetObjectTemp), 0.0, 0.0001);
testFacility.stepApplication();
BOOST_CHECK_CLOSE(dummy->getFloat(TecFrame::TecParameter::TemTargetObjectTemp), 3.1415, 0.0001);
BOOST_CHECK(!errorMessage.readLatest());
BOOST_CHECK(!errorStatus.readLatest());
BOOST_CHECK(std::string(errorMessage) == "");
BOOST_CHECK(errorStatus == 0);
// verify that error is still there for the first variable
writeCh1Group7.write();
testFacility.stepApplication();
BOOST_CHECK(errorMessage.readLatest());
BOOST_CHECK(errorStatus.readLatest());
BOOST_CHECK(std::string(errorMessage) != "");
BOOST_CHECK(std::string(errorMessage).find("ctrl_ch1_fanControlEnable") != std::string::npos);
BOOST_CHECK(errorStatus != 0);
BOOST_CHECK_EQUAL(dummy->getInt(TecFrame::TecParameter::ExpFanControlEnable), 1);
// generate error for another variable in the same group
dummy->errorFlags[TecFrame::TecParameter::ExpFanTargetTemp] = TecErrorCode::EER_PAR_OUT_OF_RANGE;
fanTargetTemp = 1500.;
fanTargetTemp.write();
writeCh1Group7.write();
BOOST_CHECK_EQUAL(dummy->getInt(TecFrame::TecParameter::ExpFanControlEnable), 1);
testFacility.stepApplication();
BOOST_CHECK(errorMessage.readLatest());
BOOST_CHECK(errorStatus.readLatest());
BOOST_CHECK(std::string(errorMessage) != "");
BOOST_CHECK(std::string(errorMessage).find("ctrl_ch1_fanControlEnable") != std::string::npos);
BOOST_CHECK(errorStatus != 0);
BOOST_CHECK_EQUAL(dummy->getInt(TecFrame::TecParameter::ExpFanControlEnable), 1);
// remove error from dummy and check again
dummy->errorFlags[TecFrame::TecParameter::ExpFanControlEnable] = TecErrorCode::NO_ERROR;
fanControlEnable = -120;
fanControlEnable.write();
writeCh1Group7.write();
testFacility.stepApplication();
BOOST_CHECK_EQUAL(dummy->getInt(TecFrame::TecParameter::ExpFanControlEnable), -120);
// error needs to be reset manually
BOOST_CHECK(!errorMessage.readLatest());
BOOST_CHECK(!errorStatus.readLatest());
errorReset.write();
BOOST_CHECK(errorMessage.readLatest());
BOOST_CHECK(errorStatus.readLatest());
BOOST_CHECK(std::string(errorMessage) == "");
BOOST_CHECK(errorStatus == 0);
}
/**********************************************************************************************************************/
BOOST_AUTO_TEST_SUITE_END()
......@@ -128,45 +128,4 @@ BOOST_FIXTURE_TEST_CASE(testFlashWrite, Fixture_t) {
/**********************************************************************************************************************/
/// Test write of an out-of-range value
BOOST_FIXTURE_TEST_CASE(testOutOfRange, Fixture_t) {
std::cout << "testOutOfRange" << std::endl;
auto fanControlEnable = testFacility.getScalar<int>("TecModule/ctrl_ch1_fanControlEnable_wr");
auto writeCh1Group7 = testFacility.getScalar<int>("TecModule/writeCh1Group7_wr");
auto errorMessage = testFacility.getScalar<std::string>("TecModule/errorMessage");
auto errorStatus = testFacility.getScalar<int>("TecModule/errorStatus");
auto errorReset = testFacility.getScalar<int>("TecModule/errorReset");
testFacility.runApplication();
fanControlEnable = 1;
fanControlEnable.write();
writeCh1Group7.write();
BOOST_CHECK_EQUAL(dummy->getInt(TecFrame::TecParameter::ExpFanControlEnable), 0);
testFacility.stepApplication();
BOOST_CHECK_EQUAL(dummy->getInt(TecFrame::TecParameter::ExpFanControlEnable), 1);
dummy->errorFlags[TecFrame::TecParameter::ExpFanControlEnable] = TecErrorCode::EER_PAR_OUT_OF_RANGE;
fanControlEnable = 42;
fanControlEnable.write();
writeCh1Group7.write();
BOOST_CHECK_EQUAL(dummy->getInt(TecFrame::TecParameter::ExpFanControlEnable), 1);
testFacility.stepApplication();
BOOST_CHECK(errorMessage.readLatest());
BOOST_CHECK(errorStatus.readLatest());
BOOST_CHECK(std::string(errorMessage) != "");
BOOST_CHECK(errorStatus != 0);
BOOST_CHECK_EQUAL(dummy->getInt(TecFrame::TecParameter::ExpFanControlEnable), 1);
fanControlEnable = -120;
fanControlEnable.write();
writeCh1Group7.write();
BOOST_CHECK_EQUAL(dummy->getInt(TecFrame::TecParameter::ExpFanControlEnable), 42);
testFacility.stepApplication();
BOOST_CHECK_EQUAL(dummy->getInt(TecFrame::TecParameter::ExpFanControlEnable), -120);
}
/**********************************************************************************************************************/
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