From a26af0bf4b5e56598dac51a9f6c1f4c07d22a680 Mon Sep 17 00:00:00 2001 From: vargheseg <19566373+vargheseg@users.noreply.github.com> Date: Wed, 26 Feb 2020 14:35:04 +0100 Subject: [PATCH] Moved ExceptionDevice to DeviceAccess. --- .../testDeviceExceptionFlagPropagation.cc | 2 +- .../testDeviceInitialisationHandler.cc | 2 +- .../testExceptionDummyDevice.cc | 56 ---------------- .../executables_src/testExceptionHandling.cc | 2 +- .../testProcessVariableRecovery.cc | 7 +- .../testPropagateDataFaultFlag.cc | 3 +- tests/include/ExceptionDevice.h | 64 ------------------- 7 files changed, 9 insertions(+), 127 deletions(-) delete mode 100644 tests/executables_src/testExceptionDummyDevice.cc delete mode 100644 tests/include/ExceptionDevice.h diff --git a/tests/executables_src/testDeviceExceptionFlagPropagation.cc b/tests/executables_src/testDeviceExceptionFlagPropagation.cc index 4fc90790..56dabcf6 100644 --- a/tests/executables_src/testDeviceExceptionFlagPropagation.cc +++ b/tests/executables_src/testDeviceExceptionFlagPropagation.cc @@ -4,12 +4,12 @@ using namespace boost::unit_test_framework; #include <ChimeraTK/DummyRegisterAccessor.h> +#include <ChimeraTK/ExceptionDevice.h> #include "Application.h" #include "ApplicationModule.h" #include "ControlSystemModule.h" #include "DeviceModule.h" -#include "ExceptionDevice.h" #include "PeriodicTrigger.h" #include "TestFacility.h" #include "VariableGroup.h" diff --git a/tests/executables_src/testDeviceInitialisationHandler.cc b/tests/executables_src/testDeviceInitialisationHandler.cc index 658bc66d..fbd4336c 100644 --- a/tests/executables_src/testDeviceInitialisationHandler.cc +++ b/tests/executables_src/testDeviceInitialisationHandler.cc @@ -10,9 +10,9 @@ #include "DeviceModule.h" //#include "ScalarAccessor.h" #include "TestFacility.h" -#include "ExceptionDevice.h" #include <ChimeraTK/Device.h> +#include <ChimeraTK/ExceptionDevice.h> #include <stdlib.h> #include "check_timeout.h" diff --git a/tests/executables_src/testExceptionDummyDevice.cc b/tests/executables_src/testExceptionDummyDevice.cc deleted file mode 100644 index fd4231e6..00000000 --- a/tests/executables_src/testExceptionDummyDevice.cc +++ /dev/null @@ -1,56 +0,0 @@ -#define BOOST_TEST_MODULE testExceptionsDummy - -#include "ExceptionDevice.h" -#include <ChimeraTK/BackendFactory.h> -#include <ChimeraTK/Device.h> -#include <boost/test/included/unit_test.hpp> - -using namespace boost::unit_test_framework; -namespace ctk = ChimeraTK; - -auto exceptionDummy = boost::dynamic_pointer_cast<ExceptionDummy>(ctk::BackendFactory::getInstance().createBackend("(ExceptionDummy:1?map=test3.map)")); -ctk::Device device; - -BOOST_AUTO_TEST_CASE(testExceptionsDummyDevice) { - - // test general function - BOOST_CHECK(!device.isFunctional()); - device.open("(ExceptionDummy:1?map=test3.map)"); - BOOST_CHECK(device.isFunctional()); - - - // test throwExceptionRead - exceptionDummy->throwExceptionRead = true; - BOOST_CHECK(!device.isFunctional()); - BOOST_CHECK_THROW(device.read<int32_t>("/Integers/signed32"),ChimeraTK::runtime_error); - BOOST_CHECK(!device.isFunctional()); - BOOST_CHECK_THROW(device.open("(ExceptionDummy:1?map=test3.map)"),ChimeraTK::runtime_error); - BOOST_CHECK(!device.isFunctional()); - exceptionDummy->throwExceptionRead = false; - BOOST_CHECK(!device.isFunctional()); - device.open("(ExceptionDummy:1?map=test3.map)"); - BOOST_CHECK(device.isFunctional()); - - // test throwExceptionWrite - exceptionDummy->throwExceptionWrite = true; - BOOST_CHECK(!device.isFunctional()); - BOOST_CHECK_THROW(device.write<int32_t>("/Integers/signed32",0),ChimeraTK::runtime_error); - BOOST_CHECK(!device.isFunctional()); - BOOST_CHECK_THROW(device.open("(ExceptionDummy:1?map=test3.map)"),ChimeraTK::runtime_error); - BOOST_CHECK(!device.isFunctional()); - exceptionDummy->throwExceptionWrite = false; - BOOST_CHECK(!device.isFunctional()); - device.open("(ExceptionDummy:1?map=test3.map)"); - BOOST_CHECK(device.isFunctional()); - - // test throwExceptionOpen - exceptionDummy->throwExceptionOpen = true; - BOOST_CHECK(!device.isFunctional()); - BOOST_CHECK_THROW(device.open("(ExceptionDummy:1?map=test3.map)"),ChimeraTK::runtime_error); - BOOST_CHECK(!device.isFunctional()); - exceptionDummy->throwExceptionOpen = false; - BOOST_CHECK(!device.isFunctional()); - device.open("(ExceptionDummy:1?map=test3.map)"); - BOOST_CHECK(device.isFunctional()); - -} diff --git a/tests/executables_src/testExceptionHandling.cc b/tests/executables_src/testExceptionHandling.cc index 051c8179..78157d16 100644 --- a/tests/executables_src/testExceptionHandling.cc +++ b/tests/executables_src/testExceptionHandling.cc @@ -9,12 +9,12 @@ #include <ChimeraTK/Device.h> #include <ChimeraTK/NDRegisterAccessor.h> #include <ChimeraTK/DummyRegisterAccessor.h> +#include <ChimeraTK/ExceptionDevice.h> #include "Application.h" #include "ApplicationModule.h" #include "ControlSystemModule.h" #include "DeviceModule.h" -#include "ExceptionDevice.h" #include "ScalarAccessor.h" #include "TestFacility.h" #include "check_timeout.h" diff --git a/tests/executables_src/testProcessVariableRecovery.cc b/tests/executables_src/testProcessVariableRecovery.cc index 2b5aef1a..42b91d70 100644 --- a/tests/executables_src/testProcessVariableRecovery.cc +++ b/tests/executables_src/testProcessVariableRecovery.cc @@ -5,16 +5,17 @@ #include "ControlSystemModule.h" #include "DeviceModule.h" #include "TestFacility.h" -#include "ExceptionDevice.h" -#include <ChimeraTK/Device.h> -#include <stdlib.h> #include "check_timeout.h" #include "ApplicationModule.h" #include "ArrayAccessor.h" #include "ConfigReader.h" +#include <ChimeraTK/ExceptionDevice.h> +#include <ChimeraTK/Device.h> +#include <stdlib.h> #include <regex> + using namespace boost::unit_test_framework; namespace ctk = ChimeraTK; diff --git a/tests/executables_src/testPropagateDataFaultFlag.cc b/tests/executables_src/testPropagateDataFaultFlag.cc index 13285b77..3a25a444 100644 --- a/tests/executables_src/testPropagateDataFaultFlag.cc +++ b/tests/executables_src/testPropagateDataFaultFlag.cc @@ -16,10 +16,11 @@ #include "ScalarAccessor.h" #include "ArrayAccessor.h" #include "TestFacility.h" -#include "ExceptionDevice.h" #include "ModuleGroup.h" #include "check_timeout.h" +#include <ChimeraTK/ExceptionDevice.h> + using namespace boost::unit_test_framework; namespace ctk = ChimeraTK; diff --git a/tests/include/ExceptionDevice.h b/tests/include/ExceptionDevice.h deleted file mode 100644 index 359a2e8f..00000000 --- a/tests/include/ExceptionDevice.h +++ /dev/null @@ -1,64 +0,0 @@ -#include <ChimeraTK/BackendFactory.h> -#include <ChimeraTK/DeviceAccessVersion.h> -#include <ChimeraTK/DummyBackend.h> - -class ExceptionDummy : public ChimeraTK::DummyBackend { - public: - ExceptionDummy(std::string mapFileName) : DummyBackend(mapFileName) {} - bool throwExceptionOpen{false}; - bool throwExceptionRead{false}; - bool throwExceptionWrite{false}; - bool thereHaveBeenExceptions{false}; - - static boost::shared_ptr<DeviceBackend> createInstance(std::string, std::map<std::string, std::string> parameters) { - return boost::shared_ptr<DeviceBackend>(new ExceptionDummy(parameters["map"])); - } - - void open() override { - if(throwExceptionOpen) { - thereHaveBeenExceptions = true; - throw(ChimeraTK::runtime_error("DummyException: This is a test")); - } - ChimeraTK::DummyBackend::open(); - if(throwExceptionRead || throwExceptionWrite) { - thereHaveBeenExceptions = true; - throw(ChimeraTK::runtime_error("DummyException: open throws because of device error when already open.")); - } - thereHaveBeenExceptions = false; - } - - void read(uint8_t bar, uint32_t address, int32_t* data, size_t sizeInBytes) override { - if(throwExceptionRead) { - thereHaveBeenExceptions = true; - throw(ChimeraTK::runtime_error("DummyException: read throws by request")); - } - ChimeraTK::DummyBackend::read(bar, address, data, sizeInBytes); - } - - void write(uint8_t bar, uint32_t address, int32_t const* data, size_t sizeInBytes) override { - if(throwExceptionWrite) { - thereHaveBeenExceptions = true; - throw(ChimeraTK::runtime_error("DummyException: write throws by request")); - } - ChimeraTK::DummyBackend::write(bar, address, data, sizeInBytes); - } - - bool isFunctional() const override { - return (_opened && !throwExceptionOpen && !throwExceptionRead && !throwExceptionWrite && !thereHaveBeenExceptions); - } - - class BackendRegisterer { - public: - BackendRegisterer(); - }; - static BackendRegisterer backendRegisterer; -}; - -ExceptionDummy::BackendRegisterer ExceptionDummy::backendRegisterer; - -ExceptionDummy::BackendRegisterer::BackendRegisterer() { - std::cout << "ExceptionDummy::BackendRegisterer: registering backend type " - "ExceptionDummy" - << std::endl; - ChimeraTK::BackendFactory::getInstance().registerBackendType("ExceptionDummy", &ExceptionDummy::createInstance); -} -- GitLab