LCOV - code coverage report
Current view: top level - confmodel/unittest - DisabledResource_test.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 100.0 % 198 198
Test Date: 2026-07-12 15:23:06 Functions: 100.0 % 10 10

            Line data    Source code
       1              : /**
       2              :  * @file DisabledResource_test.cxx  Unit Tests for Resource disabling logic
       3              :  *
       4              :  * This is part of the DUNE DAQ Application Framework, copyright 2025.
       5              :  * Licensing/copyright details are in the COPYING file that you should have
       6              :  * received with this code.
       7              :  */
       8              : 
       9              : #include "conffwk/Configuration.hpp"
      10              : #include "confmodel/DisabledResources.hpp"
      11              : #include "confmodel/DummyApplication.hpp"
      12              : #include "confmodel/DummyD2D.hpp"
      13              : #include "confmodel/DummyReceiver.hpp"
      14              : #include "confmodel/DummyResource.hpp"
      15              : #include "confmodel/DummyResourceSetAND.hpp"
      16              : #include "confmodel/DummyResourceSet.hpp"
      17              : #include "confmodel/DummySender.hpp"
      18              : #include "confmodel/DummySmartResource.hpp"
      19              : #include "confmodel/DummyStream.hpp"
      20              : #include "confmodel/Segment.hpp"
      21              : #include "confmodel/Session.hpp"
      22              : 
      23              : #include "logging/Logging.hpp"
      24              : 
      25              : #define BOOST_TEST_MODULE DisabledResource_test // NOLINT
      26              : 
      27              : #include "boost/test/unit_test.hpp"
      28              : 
      29              : #include <list>
      30              : #include <string>
      31              : 
      32              : 
      33              : BOOST_AUTO_TEST_SUITE(DisabledResource_test)
      34              : 
      35              : using namespace dunedaq;
      36              : using namespace dunedaq::confmodel;
      37              : 
      38              : 
      39            2 : BOOST_AUTO_TEST_CASE(simple_resource_set){
      40              : 
      41            1 :   conffwk::Configuration confdb("oksconflibs");
      42            1 :   const std::string oksfile{"/tmp/drtest.data.xml"};
      43            1 :   const std::list<std::string> includes{
      44              :     "schema/confmodel/dunedaq.schema.xml",
      45            4 :     "schema/confmodel/dummy_resource.schema.xml"};
      46            1 :   confdb.create(oksfile, includes);
      47              : 
      48            1 :   std::vector<const DummyResource*> dummy_resources;
      49            1 :   std::vector<const conffwk::ConfigObject*> resource_config_objects;
      50            4 :   for (std::string id : {"dummyRes-0", "dummyRes-1", "dummyRes-2"}) {
      51            3 :     conffwk::ConfigObject conf_obj;
      52            3 :     confdb.create(oksfile, "DummyResource", id, conf_obj);
      53            3 :     auto res_dal = confdb.get<DummyResource>(conf_obj);
      54            3 :     resource_config_objects.push_back(&res_dal->config_object());
      55            3 :     dummy_resources.push_back(res_dal);
      56            3 :   }
      57              : 
      58            1 :   conffwk::ConfigObject conf_obj;
      59            1 :   confdb.create(oksfile, "DummyResourceSet", "root", conf_obj);
      60            1 :   conf_obj.set_objs("items", resource_config_objects);
      61              : 
      62            1 :   auto root = confdb.get<DummyResourceSet>(conf_obj);
      63              : 
      64              :   // Nothing disabled
      65            1 :   DisabledResources dr(root,{});
      66            1 :   BOOST_CHECK( dr.is_enabled(root) );
      67            1 :   BOOST_CHECK( dr.is_enabled(dummy_resources[1]) );
      68              : 
      69              :   // Single resource disabled
      70            1 :   dr.update(root,{dummy_resources[1]});
      71            1 :   BOOST_CHECK( dr.is_enabled(root) );
      72            1 :   BOOST_CHECK( dr.is_enabled(dummy_resources[0]) );
      73            1 :   BOOST_CHECK( !dr.is_enabled(dummy_resources[1]) );
      74              : 
      75              :   // All simple resources disabled - no affect on ResourceSet
      76            1 :   dr.update(root, {dummy_resources[0], dummy_resources[1], dummy_resources[2]});
      77            1 :   BOOST_CHECK( dr.is_enabled(root) );
      78            1 :   BOOST_CHECK( !dr.is_enabled(dummy_resources[1]) );
      79              : 
      80              :   // ResourceSet disabled -- should affect contained simple Resources
      81            1 :   dr.update(root,{root});
      82            1 :   BOOST_CHECK( !dr.is_enabled(root) );
      83            1 :   BOOST_CHECK( !dr.is_enabled(dummy_resources[0]) );
      84            1 :   BOOST_CHECK( !dr.is_enabled(dummy_resources[1]) );
      85              : 
      86            2 : }
      87              : 
      88            2 : BOOST_AUTO_TEST_CASE(resource_set_and){
      89              : 
      90            1 :   conffwk::Configuration confdb("oksconflibs");
      91            1 :   const std::string oksfile{"/tmp/drtest.data.xml"};
      92            1 :   const std::list<std::string> includes{
      93              :     "schema/confmodel/dunedaq.schema.xml",
      94            4 :     "schema/confmodel/dummy_resource.schema.xml"};
      95            1 :   confdb.create(oksfile, includes);
      96              : 
      97            1 :   std::vector<const DummyResource*> dummy_resources;
      98            1 :   std::vector<const conffwk::ConfigObject*> resource_config_objects;
      99            4 :   for (std::string id : {"dummyRes-0", "dummyRes-1", "dummyRes-2"}) {
     100            3 :     conffwk::ConfigObject conf_obj;
     101            3 :     confdb.create(oksfile, "DummyResource", id, conf_obj);
     102            3 :     auto res_dal = confdb.get<DummyResource>(conf_obj);
     103            3 :     resource_config_objects.push_back(&res_dal->config_object());
     104            3 :     dummy_resources.push_back(res_dal);
     105            3 :   }
     106              : 
     107            1 :   conffwk::ConfigObject conf_obj;
     108            1 :   confdb.create(oksfile, "DummyResourceSetAND", "root", conf_obj);
     109            1 :   conf_obj.set_objs("items", resource_config_objects);
     110              : 
     111            1 :   auto root = confdb.get<DummyResourceSetAND>(conf_obj);
     112              : 
     113              :   // Nothing disabled
     114            1 :   DisabledResources dr(root,{});
     115            1 :   BOOST_CHECK( dr.is_enabled(root) );
     116            1 :   BOOST_CHECK( dr.is_enabled(dummy_resources[1]) );
     117              : 
     118              :   // Single resource disabled
     119            1 :   dr.update(root,{dummy_resources[1]});
     120            1 :   BOOST_CHECK( dr.is_enabled(root) );
     121            1 :   BOOST_CHECK( dr.is_enabled(dummy_resources[0]) );
     122            1 :   BOOST_CHECK( !dr.is_enabled(dummy_resources[1]) );
     123              : 
     124              :   // All simple resources disabled - also disables ResourceSetDisableAND
     125            1 :   dr.update(root, {dummy_resources[0], dummy_resources[1], dummy_resources[2]});
     126            1 :   BOOST_CHECK( !dr.is_enabled(root) );
     127            1 :   BOOST_CHECK( !dr.is_enabled(dummy_resources[1]) );
     128              : 
     129              :   // ResourceSet disabled -- should affect contained simple Resources
     130            1 :   dr.update(root,{root});
     131            1 :   BOOST_CHECK( !dr.is_enabled(root) );
     132            1 :   BOOST_CHECK( !dr.is_enabled(dummy_resources[0]) );
     133            1 :   BOOST_CHECK( !dr.is_enabled(dummy_resources[1]) );
     134              : 
     135            2 : }
     136              : 
     137              : 
     138            2 : BOOST_AUTO_TEST_CASE(segment){
     139            1 :   dunedaq::logging::Logging().setup("a","a");
     140            1 :   conffwk::Configuration confdb("oksconflibs");
     141            1 :   const std::string oksfile{"/tmp/drtest.data.xml"};
     142            1 :   const std::list<std::string> includes{
     143              :     "schema/confmodel/dunedaq.schema.xml",
     144            4 :     "schema/confmodel/dummy_resource.schema.xml"};
     145            1 :   confdb.create(oksfile, includes);
     146              : 
     147            1 :   std::vector<const DummyApplication*> dummy_apps;
     148            1 :   std::vector<const conffwk::ConfigObject*> app_config_objects;
     149            4 :   for (std::string id : {"dummyApp-0", "dummyApp-1", "dummyApp-2"}) {
     150            3 :     conffwk::ConfigObject conf_obj;
     151            3 :     confdb.create(oksfile, "DummyApplication", id, conf_obj);
     152            3 :     auto res_dal = confdb.get<DummyApplication>(conf_obj);
     153            3 :     app_config_objects.push_back(&res_dal->config_object());
     154            3 :     dummy_apps.push_back(res_dal);
     155            3 :   }
     156              : 
     157            1 :   conffwk::ConfigObject segment_conf_obj;
     158            1 :   confdb.create(oksfile, "Segment", "root", segment_conf_obj);
     159            1 :   segment_conf_obj.set_objs("applications", app_config_objects);
     160              : 
     161            1 :   auto root = confdb.get<Segment>(segment_conf_obj);
     162              : 
     163              :   // Nothing disabled
     164            1 :   DisabledResources dr(root,{});
     165            1 :   BOOST_CHECK( dr.is_enabled(root) );
     166            1 :   BOOST_CHECK( dr.is_enabled(dummy_apps[0]) );
     167              : 
     168              :   // Single resource disabled
     169            1 :   dr.update(root,{dummy_apps[0]});
     170            1 :   BOOST_CHECK( dr.is_enabled(root) );
     171            1 :   BOOST_CHECK( !dr.is_enabled(dummy_apps[0]) );
     172            1 :   BOOST_CHECK( dr.is_enabled(dummy_apps[1]) );
     173              : 
     174              :   // All simple resources disabled - also disables Segment (ResourceSetDisableAND)
     175            1 :   dr.update(root, {dummy_apps[0], dummy_apps[1], dummy_apps[2]});
     176            1 :   BOOST_CHECK( !dr.is_enabled(root) );
     177            1 :   BOOST_CHECK( !dr.is_enabled(dummy_apps[1]) );
     178            2 : }
     179              : 
     180              : 
     181            2 : BOOST_AUTO_TEST_CASE(detector_to_daq){
     182              : 
     183            1 :   conffwk::Configuration confdb("oksconflibs");
     184            1 :   const std::string oksfile{"/tmp/drtest.data.xml"};
     185            1 :   const std::list<std::string> includes{
     186              :     "schema/confmodel/dunedaq.schema.xml",
     187            4 :     "schema/confmodel/dummy_resource.schema.xml"};
     188            1 :   confdb.create(oksfile, includes);
     189              : 
     190            1 :   conffwk::ConfigObject conf_obj;
     191              : 
     192            1 :   std::vector<const Resource*> sender0_streams;
     193            1 :   std::vector<const conffwk::ConfigObject*> stream_config_objects;
     194            4 :   for (std::string id : {"dummyStream-0", "dummyStream-1", "dummyStream-2"}) {
     195            3 :     confdb.create(oksfile, "DummyStream", id, conf_obj);
     196            3 :     auto res_dal = confdb.get<DummyStream>(conf_obj);
     197            3 :     stream_config_objects.push_back(&res_dal->config_object());
     198            3 :     sender0_streams.push_back(res_dal);
     199            3 :   }
     200              : 
     201              : 
     202            1 :   std::vector<const conffwk::ConfigObject*> sender_conf_objs;
     203            1 :   confdb.create(oksfile, "DummySender", "sender-0", conf_obj);
     204            1 :   conf_obj.set_objs("streams", stream_config_objects);
     205            1 :   auto sender0_dal = confdb.get<DummySender>(conf_obj);
     206            1 :   sender_conf_objs.push_back(&sender0_dal->config_object());
     207              : 
     208              : 
     209            1 :   std::vector<const Resource*> sender1_streams;
     210            1 :   stream_config_objects.clear();
     211            4 :   for (std::string id : {"dummyStream-3", "dummyStream-4", "dummyStream-5"}) {
     212            3 :     confdb.create(oksfile, "DummyStream", id, conf_obj);
     213            3 :     auto res_dal = confdb.get<DummyStream>(conf_obj);
     214            3 :     stream_config_objects.push_back(&res_dal->config_object());
     215            3 :     sender1_streams.push_back(res_dal);
     216            3 :   }
     217              : 
     218            1 :   confdb.create(oksfile, "DummySender", "sender-1", conf_obj);
     219            1 :   conf_obj.set_objs("streams", stream_config_objects);
     220            1 :   auto sender1_dal = confdb.get<DummySender>(conf_obj);
     221            1 :   sender_conf_objs.push_back(&sender1_dal->config_object());
     222              : 
     223            1 :   confdb.create(oksfile, "DummyReceiver", "receiver-0", conf_obj);
     224            1 :   auto receiver = confdb.get<DummyReceiver>(conf_obj);
     225            1 :   auto receiver_dal = confdb.get<DummyReceiver>(conf_obj);
     226            1 :   auto receiver_conf_obj = receiver_dal->config_object();
     227              : 
     228            1 :   confdb.create(oksfile, "DummyD2D", "d2d-0", conf_obj);
     229            1 :   conf_obj.set_objs("dummy_senders", sender_conf_objs);
     230            1 :   conf_obj.set_obj("dummy_receiver", &receiver_conf_obj);
     231            1 :   auto d2d_dal = confdb.get<DummyD2D>(conf_obj);
     232            1 :   auto d2d_conf_obj = d2d_dal->config_object();
     233            1 :   confdb.create(oksfile, "DummyResourceSet", "root", conf_obj);
     234            1 :   conf_obj.set_objs("items", {&d2d_conf_obj});
     235              : 
     236            1 :   auto root = confdb.get<DummyResourceSet>(conf_obj);
     237              : 
     238              :   // Nothing disabled
     239            1 :   DisabledResources dr(root,{});
     240            1 :   BOOST_CHECK( dr.is_enabled(root) );
     241            1 :   BOOST_CHECK( dr.is_enabled(receiver_dal) );
     242            1 :   BOOST_CHECK( dr.is_enabled(d2d_dal) );
     243              : 
     244              :   // receiver disabled - disables d2d
     245            1 :   dr.update(root,{receiver});
     246            1 :   BOOST_CHECK( dr.is_enabled(root) );
     247            1 :   BOOST_CHECK( !dr.is_enabled(receiver_dal) );
     248            1 :   BOOST_CHECK( !dr.is_enabled(d2d_dal) );
     249              : 
     250              :   
     251            1 :   std::vector<const Resource*> disable = sender0_streams;
     252              :   // All streams of sender0 disabled - disables sender0
     253            1 :   dr.update(root, disable);
     254            1 :   BOOST_CHECK( dr.is_enabled(d2d_dal) );
     255            1 :   BOOST_CHECK( dr.is_enabled(sender1_dal) );
     256            1 :   BOOST_CHECK( !dr.is_enabled(sender0_dal) );
     257            1 :   BOOST_CHECK( dr.is_enabled(receiver_dal) );
     258              : 
     259              :   // All streams of both senders disabled - disables d2d and in turn receiver
     260            1 :   disable.insert(disable.end(), sender1_streams.begin(), sender1_streams.end());
     261            1 :   dr.update(root, disable);
     262            1 :   BOOST_CHECK( !dr.is_enabled(d2d_dal) );
     263            1 :   BOOST_CHECK( !dr.is_enabled(receiver_dal) );
     264              : 
     265              :   // Sender0 and all streams of sender1 disabled - also disables d2d
     266            1 :   disable.clear();
     267            1 :   disable.push_back(sender0_dal);
     268            1 :   disable.insert(disable.end(), sender1_streams.begin(), sender1_streams.end());
     269            1 :   dr.update(root, disable);
     270            1 :   BOOST_CHECK( !dr.is_enabled(d2d_dal) );
     271            1 :   BOOST_CHECK( !dr.is_enabled(receiver_dal) );
     272              : 
     273              :   // Both senders disabled - same as above
     274            1 :   disable.clear();
     275            1 :   disable.push_back(sender0_dal);
     276            1 :   disable.push_back(sender1_dal);
     277            1 :   dr.update(root, disable);
     278            1 :   BOOST_CHECK( !dr.is_enabled(d2d_dal) );
     279            1 :   BOOST_CHECK( !dr.is_enabled(receiver_dal) );
     280              : 
     281            2 : }
     282              : 
     283            2 : BOOST_AUTO_TEST_CASE(smart_resource){
     284              : 
     285            1 :   conffwk::Configuration confdb("oksconflibs");
     286            1 :   const std::string oksfile{"/tmp/drtest.data.xml"};
     287            1 :   const std::list<std::string> includes{
     288              :     "schema/confmodel/dunedaq.schema.xml",
     289            4 :     "schema/confmodel/dummy_resource.schema.xml"};
     290            1 :   confdb.create(oksfile, includes);
     291              : 
     292            1 :   std::vector<const DummySmartResource*> dummy_resources;
     293            1 :   std::vector<const conffwk::ConfigObject*> resource_config_objects;
     294            4 :   for (std::string id : {"deadun", "dummyRes-1", "dummyRes-2"}) {
     295            3 :     conffwk::ConfigObject conf_obj;
     296            3 :     confdb.create(oksfile, "DummySmartResource", id, conf_obj);
     297            3 :     auto res_dal = confdb.get<DummySmartResource>(conf_obj);
     298            3 :     resource_config_objects.push_back(&res_dal->config_object());
     299            3 :     dummy_resources.push_back(res_dal);
     300            3 :   }
     301              : 
     302            1 :   conffwk::ConfigObject conf_obj;
     303            1 :   confdb.create(oksfile, "DummyResourceSetAND", "root", conf_obj);
     304            1 :   conf_obj.set_objs("items", resource_config_objects);
     305              : 
     306            1 :   auto root = confdb.get<DummyResourceSetAND>(conf_obj);
     307              : 
     308              :   // Nothing explicitly disabled, one DummySmartResource disabled due to UID
     309            1 :   DisabledResources dr(root,{});
     310            1 :   BOOST_CHECK( dr.is_enabled(root));
     311            1 :   BOOST_CHECK( !dr.is_enabled(dummy_resources[0]) );
     312            1 :   BOOST_CHECK( dr.is_enabled(dummy_resources[1]) );
     313              : 
     314            2 : }
     315              : 
     316              : BOOST_AUTO_TEST_SUITE_END()
        

Generated by: LCOV version 2.0-1