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

            Line data    Source code
       1              : /**
       2              :  * @file opmon_facility_test.cxx Test application that tests and demonstrates
       3              :  * the conversion from a generic protobuf message to an opmon entry.
       4              :  *
       5              :  * This is part of the DUNE DAQ Application Framework, copyright 2020.
       6              :  * Licensing/copyright details are in the COPYING file that you should have
       7              :  * received with this code.
       8              :  */
       9              : 
      10              : #include "opmonlib/OpMonFacility.hpp"
      11              : #include "NullOpMonFacility.hpp"
      12              : #include "opmonlib/Utils.hpp"
      13              : #include "opmonlib/opmon/test.pb.h"
      14              : 
      15              : #define BOOST_TEST_MODULE opmon_facility_test // NOLINT
      16              : 
      17              : #include "boost/test/unit_test.hpp"
      18              : 
      19              : #include <future>
      20              : 
      21              : using namespace dunedaq::opmonlib;
      22              : using namespace dunedaq::opmon;
      23              : 
      24              : BOOST_AUTO_TEST_SUITE(Opmon_Facility_Test)
      25              : 
      26              : 
      27            2 : BOOST_AUTO_TEST_CASE(Invalid_Creation) {
      28              : 
      29            4 :   BOOST_CHECK_THROW( auto service = makeOpMonFacility("invalid://"),
      30              :                      OpMonFacilityCreationFailed );
      31              : 
      32            2 :   BOOST_CHECK_NO_THROW( auto service = makeOpMonFacility("") );
      33              :   
      34            1 : }
      35              : 
      36              : 
      37            2 : BOOST_AUTO_TEST_CASE(STD_Cout_facility) {
      38              :   
      39            1 :   auto service = makeOpMonFacility("cout"); 
      40              : 
      41            1 :   dunedaq::opmon::TestInfo ti;
      42            1 :   ti.set_int_example( 42 );
      43            1 :   ti.set_float_example( 12.34 );
      44            1 :   ti.set_string_example( "anohter_test" );
      45            1 :   ti.set_bool_example( true );
      46              : 
      47            1 :   dunedaq::opmon::ComplexInfo ci;
      48            1 :   ci.set_another_float(1.23);
      49            1 :   *ci.mutable_sub_message() = ti;
      50              : 
      51            1 :   BOOST_CHECK_NO_THROW ( service -> publish(  to_entry( ci, {} ) ) ) ;
      52              :   
      53            1 : }
      54              : 
      55              : 
      56            2 : BOOST_AUTO_TEST_CASE(null_facility) {
      57              : 
      58            1 :   auto service = std::make_shared<NullOpMonFacility>(); 
      59              : 
      60            1 :   dunedaq::opmon::TestInfo ti;
      61            1 :   ti.set_int_example( 42 );
      62            1 :   ti.set_float_example( 12.34 );
      63            1 :   ti.set_string_example( "null_test" );
      64            1 :   ti.set_bool_example( true );
      65              : 
      66            4 :   BOOST_CHECK_THROW ( service -> publish(  to_entry( ti, {} ) ),
      67              :                       dunedaq::opmonlib::OpMonPublishFailure ) ;
      68              :   
      69            1 : }
      70              : 
      71              : 
      72            2 : BOOST_AUTO_TEST_CASE(File_facility) {
      73              : 
      74            4 :   BOOST_CHECK_THROW( auto service = makeOpMonFacility("file:///impossible_file.txt"),
      75              :                      OpMonFacilityCreationFailed);
      76              : 
      77            1 :   auto service = makeOpMonFacility("file://./test_file", make_origin("test", "app") );
      78              : 
      79           51 :   auto pub_func = [&](int i){
      80           50 :     dunedaq::opmon::OpMonId id;
      81           50 :     id += "unit";
      82           50 :     id += "test";
      83           50 :     id += "thread_"+std::to_string(i);
      84         1550 :     for (auto j = 0; j < 30; ++j ) {
      85         1500 :       dunedaq::opmon::TestInfo ti;
      86         1500 :       ti.set_int_example( i*1000 + j );
      87         1500 :       ti.set_string_example( "test" );
      88         1500 :       auto e = to_entry( ti, {} );
      89         1500 :       *e.mutable_origin() = id; 
      90         1498 :       BOOST_CHECK_NO_THROW( service->publish( std::move(e) ) );
      91         1500 :     }
      92           51 :   };
      93              : 
      94            1 :   const int n = 50;
      95            1 :   std::vector<std::future<void>> threads(n);
      96              : 
      97           51 :   for( auto i = 0 ; i < n; ++i ) {
      98           50 :     threads[i] = async(std::launch::async, pub_func, i);
      99              :   }
     100              :   
     101           51 :   for ( auto & t : threads ) {
     102           50 :     BOOST_CHECK_NO_THROW( t.get() );
     103              :   }
     104              :   
     105            1 : }
     106              : 
     107              : 
     108              : BOOST_AUTO_TEST_SUITE_END()
     109              : 
        

Generated by: LCOV version 2.0-1