diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f383ac..dcaf085 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,6 +55,7 @@ daq_add_unit_test(Application_test LINK_LIBRARIES appfwk ) daq_add_unit_test(CommandLineInterpreter_test LINK_LIBRARIES appfwk ) daq_add_unit_test(DAQModule_test LINK_LIBRARIES appfwk ) daq_add_unit_test(DAQModuleManager_test LINK_LIBRARIES appfwk ) +daq_add_unit_test(ConfigurationManager_test LINK_LIBRARIES appfwk ) ############################################################################## diff --git a/include/appfwk/ConfigurationManager.hpp b/include/appfwk/ConfigurationManager.hpp index 9f0e56b..aa0a53c 100644 --- a/include/appfwk/ConfigurationManager.hpp +++ b/include/appfwk/ConfigurationManager.hpp @@ -33,7 +33,7 @@ namespace dunedaq { // Disable coverage collection LCOV_EXCL_START ERS_DECLARE_ISSUE(appfwk, NotADaqApplication, - "Application " << app << " is neither a DaqApplication nor a SmartDaqApplication ", + "Application " << app << " is not a DaqApplication", ((std::string)app)) ERS_DECLARE_ISSUE(appfwk, MissingComponent, "No such component: " << what, ((std::string)what)) @@ -42,6 +42,10 @@ ERS_DECLARE_ISSUE(appfwk, ActionPlanValidationFailed, "Action plan validation failed: " << cmd << ", module " << module << ": " << message, ((std::string)cmd)((std::string)module)((std::string)message)) + +ERS_DECLARE_ISSUE(appfwk, FailedInclude, "Failed to include deferred database file: " << filename, + ((std::string)filename)) + // Re-enable coverage collection LCOV_EXCL_STOP namespace appfwk { @@ -95,11 +99,14 @@ class ConfigurationManager std::string get_app_name() const { return m_app_name; } + void load_deferred_db(const std::string& dbname); + private: std::shared_ptr m_confdb; std::shared_ptr m_helper; std::string m_app_name; std::string m_session_name; + std::string m_config_spec; const confmodel::Session* m_session; const confmodel::DaqApplication* m_application; diff --git a/src/ConfigurationManager.cpp b/src/ConfigurationManager.cpp index 65d457b..aabc566 100644 --- a/src/ConfigurationManager.cpp +++ b/src/ConfigurationManager.cpp @@ -42,6 +42,7 @@ ConfigurationManager::ConfigurationManager(std::string const& config_spec, : m_confdb(new conffwk::Configuration(config_spec)) , m_app_name(app_name) , m_session_name(session_name) + , m_config_spec(config_spec) { TLOG() << "configSpec <" << config_spec << "> session name " << session_name << " application name " << app_name; @@ -138,3 +139,18 @@ ConfigurationManager::get_action_plan(std::string cmd) const } return nullptr; } + +void +ConfigurationManager::load_deferred_db(const std::string& include_name) +{ + auto pos = m_config_spec.find_last_of(":"); + pos = (pos == std::string::npos) ? 0 : pos + 1; + auto dbfile = m_config_spec.substr(pos); + + try { + m_confdb->add_include(dbfile, include_name); + } + catch (const dunedaq::conffwk::Generic& except) { + throw(FailedInclude(ERS_HERE, include_name, except)); + } +} diff --git a/test/config/dummyInclude.data.xml b/test/config/dummyInclude.data.xml new file mode 100644 index 0000000..81e0dc5 --- /dev/null +++ b/test/config/dummyInclude.data.xml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + diff --git a/test/config/duplicateDummyInclude.data.xml b/test/config/duplicateDummyInclude.data.xml new file mode 100644 index 0000000..81e0dc5 --- /dev/null +++ b/test/config/duplicateDummyInclude.data.xml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + +]> + + + + + + + + + + + + + + + + + diff --git a/unittest/ConfigurationManager_test.cxx b/unittest/ConfigurationManager_test.cxx new file mode 100644 index 0000000..c0abc8c --- /dev/null +++ b/unittest/ConfigurationManager_test.cxx @@ -0,0 +1,52 @@ +/** + * @file ConfigurationManager_test.cxx ConfigurationManager_test class + * Unit Tests + * + * This is part of the DUNE DAQ Application Framework, copyright 2020. + * Licensing/copyright details are in the COPYING file that you should have + * received with this code. + */ + +#include "appfwk/ConfigurationManager.hpp" +#include "confmodel/Variable.hpp" + +#define BOOST_TEST_MODULE ConfigurationManager_test // NOLINT + +#include "boost/test/unit_test.hpp" + +using namespace dunedaq::appfwk; + +BOOST_AUTO_TEST_SUITE(ConfigurationManager_test) + +const std::string config_spec{"oksconflibs:test/config/appSession.data.xml"}; +const std::string appname{"TestApp"}; +const std::string session{"test-session"}; + +BOOST_AUTO_TEST_CASE(Include) +{ + auto cm = std::make_shared(config_spec, appname, session); + cm->load_deferred_db("test/config/dummyInclude.data.xml"); + + auto variable = cm->get_dal("test-variable"); + BOOST_REQUIRE(variable != nullptr); + BOOST_REQUIRE_EQUAL(variable->get_name(), "test"); +} +BOOST_AUTO_TEST_CASE(IncludeTwice) +{ + auto cm = std::make_shared(config_spec, appname, session); + cm->load_deferred_db("test/config/dummyInclude.data.xml"); + cm->load_deferred_db("test/config/dummyInclude.data.xml"); + + auto variable = cm->get_dal("test-variable"); + BOOST_REQUIRE(variable != nullptr); + BOOST_REQUIRE_EQUAL(variable->get_name(), "test"); +} + + +BOOST_AUTO_TEST_CASE(IncludeDuplicate) +{ + auto cm = std::make_shared(config_spec, appname, session); + cm->load_deferred_db("test/config/dummyInclude.data.xml"); + BOOST_REQUIRE_THROW(cm->load_deferred_db("test/config/duplicateDummyInclude.data.xml"), FailedInclude); +} +}