LCOV - code coverage report
Current view: top level - artdaq-core-mu2e/test/Overlays - DTC_SubEvent_t.cc (source / functions) Coverage Total Hit
Test: mu2edaq.info.cleaned Lines: 98.0 % 50 49
Test Date: 2026-07-30 01:56:44 Functions: 90.9 % 11 10

            Line data    Source code
       1              : #define BOOST_TEST_MODULE DTC_SubEvent_t
       2              : #include <boost/test/unit_test.hpp>
       3              : 
       4              : #include "TRACE/tracemf.h"
       5              : #define TRACE_NAME "DTC_SubEvent_t"
       6              : 
       7              : #include <fstream>
       8              : 
       9              : #include "artdaq-core-mu2e/Overlays/DTC_Packets/DTC_SubEvent.h"
      10              : 
      11              : BOOST_AUTO_TEST_SUITE(DTC_SubEvent_t)
      12              : 
      13            2 : BOOST_AUTO_TEST_CASE(Constructor)
      14              : {
      15            1 :         size_t size_bytes = sizeof(DTCLib::DTC_SubEventHeader);  // 6 empty ROC headers;
      16              : 
      17            1 :         auto evt = std::make_unique<DTCLib::DTC_SubEvent>(size_bytes);
      18              : 
      19            1 :         DTCLib::DTC_SubEventHeader evtHdr;
      20            1 :         evtHdr.inclusive_subevent_byte_count = size_bytes;
      21            1 :         evtHdr.num_rocs = 0;
      22            1 :         evtHdr.event_tag_low = 1;
      23            1 :         evtHdr.event_tag_high = 0;
      24            1 :         memcpy(const_cast<uint8_t*>(reinterpret_cast<const uint8_t*>(evt->GetRawBufferPointer())), &evtHdr, sizeof(DTCLib::DTC_SubEventHeader));
      25              : 
      26            2 :         TLOG(TLVL_TRACE + 22) << "Calling SetupSubEvent";
      27            1 :         std::string accumulatedErrors = "";
      28            1 :         auto ok = evt->SetupSubEvent(accumulatedErrors);
      29            1 :         if (accumulatedErrors.size())
      30            0 :                 TLOG(TLVL_ERROR) << "Returned from SetupSubEvent, accumulatedErrors = " << accumulatedErrors;
      31            1 :         BOOST_REQUIRE(!accumulatedErrors.size());
      32            1 :         BOOST_REQUIRE(ok);
      33              : 
      34            1 :         BOOST_REQUIRE_EQUAL(evt->GetDataBlockCount(), 0);
      35            1 :         BOOST_REQUIRE_EQUAL(evt->GetEventWindowTag(), DTCLib::DTC_EventWindowTag(1));
      36            1 : }
      37              : 
      38            2 : BOOST_AUTO_TEST_CASE(GoodBinaryFile)
      39              : {
      40            1 :         std::ifstream input("subevent_test.bin", std::ios::binary);
      41            1 :         std::vector<unsigned char> buffer(std::istreambuf_iterator<char>(input), {});
      42              : 
      43            1 :         auto evt = std::make_unique<DTCLib::DTC_SubEvent>(buffer.data());
      44            1 :         auto ok = evt->SetupSubEvent();
      45            1 :         BOOST_REQUIRE(ok);
      46            1 :         BOOST_REQUIRE_EQUAL(evt->GetDataBlockCount(), 6);
      47            1 :         BOOST_REQUIRE_EQUAL(evt->GetEventWindowTag(), DTCLib::DTC_EventWindowTag(1));
      48            1 : }
      49              : 
      50            2 : BOOST_AUTO_TEST_CASE(BadBinaryFile_Short)
      51              : {
      52            1 :         std::ifstream input("subevent_test_short.bin", std::ios::binary);
      53            1 :         std::vector<unsigned char> buffer(std::istreambuf_iterator<char>(input), {});
      54              : 
      55            1 :         auto evt = std::make_unique<DTCLib::DTC_SubEvent>(buffer.data());
      56            1 :         std::string accumulatedErrors = "";
      57            1 :         auto ok = evt->SetupSubEvent(accumulatedErrors);
      58            1 :         if (accumulatedErrors.size())
      59            3 :                 TLOG(TLVL_ERROR) << "Returned from SetupSubEvent, accumulatedErrors = " << accumulatedErrors;
      60            1 :         BOOST_REQUIRE(accumulatedErrors.size());
      61            1 :         BOOST_REQUIRE(!ok);
      62            1 :         BOOST_REQUIRE_EQUAL(evt->GetDataBlockCount(), 6);
      63            1 :         BOOST_REQUIRE_EQUAL(evt->GetEventWindowTag(), DTCLib::DTC_EventWindowTag(1));
      64            1 : }
      65              : 
      66            2 : BOOST_AUTO_TEST_CASE(BadBinaryFile_Long)
      67              : {
      68            1 :         std::ifstream input("subevent_test_long.bin", std::ios::binary);
      69            1 :         std::vector<unsigned char> buffer(std::istreambuf_iterator<char>(input), {});
      70              : 
      71            1 :         auto evt = std::make_unique<DTCLib::DTC_SubEvent>(buffer.data());
      72            1 :         auto ok = evt->SetupSubEvent();
      73            1 :         BOOST_REQUIRE(!ok);
      74            1 :         BOOST_REQUIRE_EQUAL(evt->GetDataBlockCount(), 6);
      75            1 :         BOOST_REQUIRE_EQUAL(evt->GetEventWindowTag(), DTCLib::DTC_EventWindowTag(1));
      76            1 : }
      77              : 
      78              : BOOST_AUTO_TEST_SUITE_END()
        

Generated by: LCOV version 2.0-1