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

            Line data    Source code
       1              : /**
       2              :  * @file TriggerRecord_test.cxx TriggerRecord class Unit Tests
       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 "daqdataformats/TriggerRecord.hpp"
      10              : 
      11              : /**
      12              :  * @brief Name of this test module
      13              :  */
      14              : #define BOOST_TEST_MODULE TriggerRecord_test // NOLINT
      15              : 
      16              : #include "boost/test/unit_test.hpp"
      17              : 
      18              : #include <memory>
      19              : #include <string>
      20              : #include <utility>
      21              : #include <vector>
      22              : 
      23              : using namespace dunedaq::daqdataformats;
      24              : 
      25              : BOOST_AUTO_TEST_SUITE(TriggerRecord_test)
      26              : 
      27              : /**
      28              :  * @brief Check that TriggerRecords have appropriate Copy/Move semantics
      29              :  */
      30            2 : BOOST_AUTO_TEST_CASE(CopyAndMoveSemantics)
      31              : {
      32            1 :   BOOST_REQUIRE(!std::is_copy_constructible_v<TriggerRecord>);
      33            1 :   BOOST_REQUIRE(!std::is_copy_assignable_v<TriggerRecord>);
      34            1 :   BOOST_REQUIRE(std::is_move_constructible_v<TriggerRecord>);
      35            1 :   BOOST_REQUIRE(std::is_move_assignable_v<TriggerRecord>);
      36            1 : }
      37              : 
      38              : /**
      39              :  * @brief Test constructor that takes a vector of ComponentRequests
      40              :  */
      41            2 : BOOST_AUTO_TEST_CASE(ComponentsConstructor)
      42              : {
      43            1 :   std::vector<ComponentRequest> components;
      44            1 :   components.emplace_back();
      45            1 :   components.back().component = { SourceID::Subsystem::kDetectorReadout, 12 };
      46            1 :   components.back().window_begin = 3;
      47            1 :   components.back().window_end = 4;
      48            1 :   components.emplace_back();
      49            1 :   components.back().component = { SourceID::Subsystem::kDetectorReadout, 56 };
      50            1 :   components.back().window_begin = 7;
      51            1 :   components.back().window_end = 8;
      52              : 
      53            1 :   auto record = new TriggerRecord(components);
      54            1 :   BOOST_REQUIRE_EQUAL(record->get_header_data().num_requested_components, 2);
      55            1 :   delete record; // NOLINT(build/raw_ownership)
      56            1 : }
      57              : 
      58              : /**
      59              :  * @brief Test constructor that uses and existing TriggerRecordHeader
      60              :  */
      61            2 : BOOST_AUTO_TEST_CASE(HeaderConstructor)
      62              : {
      63            1 :   std::vector<ComponentRequest> components;
      64            1 :   components.emplace_back();
      65            1 :   components.back().component = { SourceID::Subsystem::kDetectorReadout, 12 };
      66            1 :   components.back().window_begin = 3;
      67            1 :   components.back().window_end = 4;
      68            1 :   components.emplace_back();
      69            1 :   components.back().component = { SourceID::Subsystem::kDetectorReadout, 56 };
      70            1 :   components.back().window_begin = 7;
      71            1 :   components.back().window_end = 8;
      72              : 
      73            1 :   auto header = new TriggerRecordHeader(components);
      74            1 :   auto record = new TriggerRecord(*header);
      75            1 :   BOOST_REQUIRE_EQUAL(record->get_header_data().num_requested_components, 2);
      76            1 :   delete record; // NOLINT(build/raw_ownership)
      77            1 :   delete header; // NOLINT(build/raw_ownership)
      78            1 : }
      79              : 
      80              : /**
      81              :  * @brief Test TR move constroctor
      82              :  */
      83            2 : BOOST_AUTO_TEST_CASE(MoveConstructor)
      84              : {
      85              : 
      86            1 :   std::vector<ComponentRequest> components;
      87            1 :   components.emplace_back();
      88            1 :   components.back().component = { SourceID::Subsystem::kDetectorReadout, 12 };
      89            1 :   components.back().window_begin = 3;
      90            1 :   components.back().window_end = 4;
      91            1 :   components.emplace_back();
      92            1 :   components.back().component = { SourceID::Subsystem::kDetectorReadout, 56 };
      93            1 :   components.back().window_begin = 7;
      94            1 :   components.back().window_end = 8;
      95              : 
      96            1 :   TriggerRecord record(components);
      97            1 :   std::vector<uint8_t> buf1(10);
      98            1 :   auto frag = std::make_unique<Fragment>(buf1.data(), buf1.size());
      99            1 :   record.add_fragment(std::move(frag));
     100              : 
     101            1 :   auto second_record = std::move(record);
     102            1 :   BOOST_REQUIRE_EQUAL(second_record.get_header_data().num_requested_components, 2);
     103            1 : }
     104              : 
     105              : /**
     106              :  *@brief Test TriggerRecordHeader manipulation methods
     107              :  */
     108            2 : BOOST_AUTO_TEST_CASE(HeaderManipulation)
     109              : {
     110              : 
     111            1 :   std::vector<ComponentRequest> components;
     112            1 :   components.emplace_back();
     113            1 :   components.back().component = { SourceID::Subsystem::kDetectorReadout, 12 };
     114            1 :   components.back().window_begin = 3;
     115            1 :   components.back().window_end = 4;
     116            1 :   components.emplace_back();
     117            1 :   components.back().component = { SourceID::Subsystem::kDetectorReadout, 56 };
     118            1 :   components.back().window_begin = 7;
     119            1 :   components.back().window_end = 8;
     120              : 
     121            1 :   TriggerRecord record(components);
     122              : 
     123            1 :   components.emplace_back();
     124            1 :   components.back().component = { SourceID::Subsystem::kDetectorReadout, 910 };
     125            1 :   components.back().window_begin = 11;
     126            1 :   components.back().window_end = 12;
     127              : 
     128            1 :   TriggerRecordHeader new_header(components);
     129            1 :   record.set_header(new_header);
     130            1 :   BOOST_REQUIRE_EQUAL(record.get_header_ref().get_num_requested_components(), 3);
     131              : 
     132            1 :   record.get_header_ref().set_trigger_timestamp(100);
     133            1 :   BOOST_REQUIRE_EQUAL(record.get_header_data().trigger_timestamp, 100);
     134            1 : }
     135              : 
     136              : /**
     137              :  * @brief Test Fragment vector manipulation methods
     138              :  */
     139            2 : BOOST_AUTO_TEST_CASE(FragmentManipulation)
     140              : {
     141              : 
     142            1 :   std::vector<ComponentRequest> components;
     143            1 :   components.emplace_back();
     144            1 :   components.back().component = { SourceID::Subsystem::kDetectorReadout, 12 };
     145            1 :   components.back().window_begin = 3;
     146            1 :   components.back().window_end = 4;
     147            1 :   components.emplace_back();
     148            1 :   components.back().component = { SourceID::Subsystem::kDetectorReadout, 56 };
     149            1 :   components.back().window_begin = 7;
     150            1 :   components.back().window_end = 8;
     151              : 
     152            1 :   TriggerRecord record(components);
     153              : 
     154            1 :   BOOST_REQUIRE_EQUAL(record.get_fragments_ref().size(), 0);
     155              : 
     156            1 :   std::vector<uint8_t> buf1(10);
     157            1 :   auto frag = std::make_unique<Fragment>(buf1.data(), buf1.size());
     158            1 :   record.add_fragment(std::move(frag));
     159            1 :   BOOST_REQUIRE_EQUAL(record.get_fragments_ref().size(), 1);
     160            1 :   BOOST_REQUIRE_EQUAL(record.get_fragments_ref()[0]->get_size(), sizeof(FragmentHeader) + 10);
     161              : 
     162            1 :   BOOST_REQUIRE_EQUAL(record.get_total_size_bytes(), sizeof(TriggerRecordHeaderData) +
     163              :                       2 * sizeof(ComponentRequest) + sizeof(FragmentHeader) + 10);
     164            1 :   BOOST_REQUIRE_EQUAL(record.get_sum_of_fragment_payload_sizes(), 10);
     165              : 
     166            1 :   std::vector<std::unique_ptr<Fragment>> new_vector;
     167            1 :   record.set_fragments(std::move(new_vector));
     168            1 :   BOOST_REQUIRE_EQUAL(record.get_fragments_ref().size(), 0);
     169            1 : }
     170              : 
     171              : BOOST_AUTO_TEST_SUITE_END()
        

Generated by: LCOV version 2.0-1