LCOV - code coverage report
Current view: top level - confmodel/unittest - ExcludedEntity_test.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 100.0 % 198 198
Test Date: 2026-10-11 15:05:20 Functions: 100.0 % 10 10

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

Generated by: LCOV version 2.0-1