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: 2026-10-11 15:05:20 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 "NullOpMonFacility.hpp"
      11              : #include "opmonlib/OpMonFacility.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            2 : BOOST_AUTO_TEST_CASE(Invalid_Creation)
      27              : {
      28              : 
      29            3 :   BOOST_CHECK_THROW(auto service = makeOpMonFacility("invalid://"), OpMonFacilityCreationFailed);
      30              : 
      31            1 :   BOOST_CHECK_NO_THROW(auto service = makeOpMonFacility(""));
      32            1 : }
      33              : 
      34            2 : BOOST_AUTO_TEST_CASE(STD_Cout_facility)
      35              : {
      36              : 
      37            1 :   auto service = makeOpMonFacility("cout");
      38              : 
      39            1 :   dunedaq::opmon::TestInfo ti;
      40            1 :   ti.set_int_example(42);
      41            1 :   ti.set_float_example(12.34);
      42            1 :   ti.set_string_example("anohter_test");
      43            1 :   ti.set_bool_example(true);
      44              : 
      45            1 :   dunedaq::opmon::ComplexInfo ci;
      46            1 :   ci.set_another_float(1.23);
      47            1 :   *ci.mutable_sub_message() = ti;
      48              : 
      49            1 :   BOOST_CHECK_NO_THROW(service->publish(to_entry(ci, {})));
      50            1 : }
      51              : 
      52            2 : BOOST_AUTO_TEST_CASE(null_facility)
      53              : {
      54              : 
      55            1 :   auto service = std::make_shared<NullOpMonFacility>();
      56              : 
      57            1 :   dunedaq::opmon::TestInfo ti;
      58            1 :   ti.set_int_example(42);
      59            1 :   ti.set_float_example(12.34);
      60            1 :   ti.set_string_example("null_test");
      61            1 :   ti.set_bool_example(true);
      62              : 
      63            3 :   BOOST_CHECK_THROW(service->publish(to_entry(ti, {})), dunedaq::opmonlib::OpMonPublishFailure);
      64            1 : }
      65              : 
      66            2 : BOOST_AUTO_TEST_CASE(File_facility)
      67              : {
      68              : 
      69            3 :   BOOST_CHECK_THROW(auto service = makeOpMonFacility("file:///impossible_file.txt"), OpMonFacilityCreationFailed);
      70              : 
      71            1 :   auto service = makeOpMonFacility("file://./test_file", make_origin("test", "app"));
      72              : 
      73           51 :   auto pub_func = [&](int i) {
      74           50 :     dunedaq::opmon::OpMonId id;
      75           50 :     id += "unit";
      76           50 :     id += "test";
      77           50 :     id += "thread_" + std::to_string(i);
      78         1550 :     for (auto j = 0; j < 30; ++j) {
      79         1500 :       dunedaq::opmon::TestInfo ti;
      80         1500 :       ti.set_int_example(i * 1000 + j);
      81         1500 :       ti.set_string_example("test");
      82         1499 :       auto e = to_entry(ti, {});
      83         1499 :       *e.mutable_origin() = id;
      84         1499 :       BOOST_CHECK_NO_THROW(service->publish(std::move(e)));
      85         1500 :     }
      86           51 :   };
      87              : 
      88            1 :   const int n = 50;
      89            1 :   std::vector<std::future<void>> threads(n);
      90              : 
      91           51 :   for (auto i = 0; i < n; ++i) {
      92           50 :     threads[i] = async(std::launch::async, pub_func, i);
      93              :   }
      94              : 
      95           51 :   for (auto& t : threads) {
      96           50 :     BOOST_CHECK_NO_THROW(t.get());
      97              :   }
      98            1 : }
      99              : 
     100              : BOOST_AUTO_TEST_SUITE_END()
        

Generated by: LCOV version 2.0-1