LCOV - code coverage report
Current view: top level - opmonlib/unittest - monitorable_object_test.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 94.4 % 54 51
Test Date: 2025-12-21 13:07:08 Functions: 91.7 % 12 11

            Line data    Source code
       1              : /**
       2              :  * @file moniotorable_object_test.cxx Test application that tests MonitorableObject.
       3              :  *
       4              :  * This is part of the DUNE DAQ Application Framework, copyright 2020.
       5              :  * Licensing/copyright details are in the COPYING file that you should have
       6              :  * received with this code.
       7              :  */
       8              : 
       9              : #include "opmonlib/opmon/test.pb.h"
      10              : #include "opmonlib/MonitorableObject.hpp"
      11              : #include "opmonlib/TestOpMonManager.hpp"
      12              : 
      13              : #define BOOST_TEST_MODULE monitorable_object_test // NOLINT
      14              : 
      15              : #include "boost/test/unit_test.hpp"
      16              : 
      17              : #include <vector>
      18              : #include <type_traits>
      19              : 
      20              : using namespace dunedaq::opmonlib;
      21              : using namespace dunedaq::opmon;
      22              : 
      23              : BOOST_AUTO_TEST_SUITE(Monitorable_Object_Test)
      24              : 
      25              : struct my_fixture {
      26              :   
      27              :   class TestObject : public MonitorableObject {
      28              : 
      29              :   public:
      30              :     using MonitorableObject::register_node;
      31              :     using MonitorableObject::publish;
      32            6 :     TestObject() : MonitorableObject() {;}
      33              :   };
      34              : 
      35            4 :   my_fixture()
      36            4 :     : manager("test", "manager")
      37            4 :     , node_p(new TestObject) {;}  
      38              :   
      39              :   TestOpMonManager manager;
      40              :   std::shared_ptr<TestObject> node_p;
      41              :    
      42              : };
      43              : 
      44            1 : BOOST_AUTO_TEST_CASE(pointer_casting) {
      45              : 
      46            0 :   static_assert(std::is_convertible_v<std::shared_ptr<OpMonLink>, std::shared_ptr<MonitorableObject>>);
      47            0 :   static_assert(!std::is_convertible_v<std::shared_ptr<OpMonManager>, std::shared_ptr<MonitorableObject>>);
      48              : 
      49            0 : }
      50              : 
      51              : 
      52            2 : BOOST_FIXTURE_TEST_CASE(test_manager, my_fixture) {
      53              : 
      54            1 :   auto facility = manager.get_backend_facility();
      55            1 :   BOOST_CHECK_EQUAL( bool(facility), true );
      56              : 
      57            1 :   std::shared_ptr<TestObject> child(new TestObject);
      58            1 :   manager.register_node("grand_child", child);
      59              : 
      60            1 :   dunedaq::opmon::TestInfo ct;
      61            1 :   ct.set_string_example( "child_test" );
      62            1 :   ct.set_int_example( 10 );
      63              : 
      64            1 :   child->publish(std::move(ct));
      65              :   
      66            1 :   auto list = facility -> get_entries();
      67            1 :   BOOST_CHECK_EQUAL( list.size(), 1 );
      68              : 
      69            1 : }
      70              : 
      71              : 
      72              : 
      73            2 : BOOST_FIXTURE_TEST_CASE( opmon_ids, my_fixture ) {
      74              : 
      75            1 :   BOOST_CHECK_EQUAL( to_string(node_p->get_opmon_id()), "" );
      76            1 :   BOOST_CHECK_EQUAL( to_string(manager.get_opmon_id()), "test.manager" );
      77              : 
      78            1 :   manager.register_node("child", node_p);
      79            1 :   BOOST_CHECK_EQUAL( to_string(node_p->get_opmon_id()), "test.manager.child" );
      80            1 : }
      81              : 
      82              : 
      83            2 : BOOST_FIXTURE_TEST_CASE( opmon_level, my_fixture ) {
      84              : 
      85            1 :   manager.register_node("child", node_p);
      86            1 :   auto parent_level = manager.get_opmon_level();
      87            1 :   auto child_level  = node_p->get_opmon_level();
      88              : 
      89            1 :   BOOST_CHECK_EQUAL( child_level, parent_level );
      90            1 :   BOOST_CHECK_EQUAL( child_level, to_level(SystemOpMonLevel::kAll) );
      91              : 
      92              :   
      93            1 :   manager.set_opmon_level( to_level(SystemOpMonLevel::kDisabled) );
      94              : 
      95            1 :   parent_level = manager.get_opmon_level();
      96            1 :   child_level  = node_p->get_opmon_level();
      97            1 :   BOOST_CHECK_EQUAL( child_level, parent_level );
      98            1 :   BOOST_CHECK_EQUAL( child_level, to_level(SystemOpMonLevel::kDisabled) );
      99            1 : }
     100              : 
     101              : 
     102            2 : BOOST_FIXTURE_TEST_CASE( counters, my_fixture ) {
     103              : 
     104            1 :   manager.register_node("child", node_p);
     105              : 
     106            1 :   std::shared_ptr<TestObject> child(new TestObject);
     107            1 :   node_p->register_node("grand_child", child);
     108              :   
     109            1 :   dunedaq::opmon::TestInfo ct;
     110            1 :   ct.set_string_example( "child_test" );
     111            1 :   ct.set_int_example( 1000 );
     112              : 
     113            1 :   node_p->publish( dunedaq::opmon::TestInfo(ct) );
     114              : 
     115            1 :   ct.set_int_example( 2000 );
     116            1 :   manager.set_opmon_level(to_level(SystemOpMonLevel::kDisabled));
     117            1 :   BOOST_CHECK_NO_THROW( child->publish( dunedaq::opmon::TestInfo(ct) ) );
     118              :   
     119            1 :   auto data = manager.collect() ;
     120            1 :   BOOST_CHECK_EQUAL( data.n_published_measurements(), 1 );
     121            1 :   BOOST_CHECK_EQUAL( data.n_ignored_measurements(), 1 );
     122            1 :   BOOST_CHECK_EQUAL( data.n_errors(), 0 );
     123            1 : }
     124              : 
     125              : 
     126              : 
     127              : 
     128              : 
     129              : 
     130              : BOOST_AUTO_TEST_SUITE_END()
     131              : 
        

Generated by: LCOV version 2.0-1