LCOV - code coverage report
Current view: top level - confmodel/unittest - DisabledResource_test.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 100.0 % 174 174
Test Date: 2025-12-21 13:07:08 Functions: 100.0 % 8 8

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

Generated by: LCOV version 2.0-1