LCOV - code coverage report
Current view: top level - fddetdataformats/unittest - TDEEthFrame_test.cxx (source / functions) Coverage Total Hit
Test: code.result Lines: 100.0 % 69 69
Test Date: 2026-05-24 15:29:04 Functions: 100.0 % 8 8

            Line data    Source code
       1              : /**
       2              :  * @file TDEEthFrame_test.cxx TDEEthFrame class Unit Tests
       3              :  *
       4              :  * This is part of the DUNE DAQ Application Framework, copyright 2022.
       5              :  * Licensing/copyright details are in the COPYING file that you should have
       6              :  * received with this code.
       7              :  */
       8              : 
       9              : #include "fddetdataformats/TDEEthFrame.hpp"
      10              : 
      11              : #define BOOST_TEST_MODULE TDEEthFrame_test // NOLINT
      12              : 
      13              : #include "boost/test/unit_test.hpp"
      14              : 
      15              : #include <random>
      16              : #include <vector>
      17              : 
      18              : // NOLINTBEGIN(build/unsigned)
      19              : 
      20              : BOOST_AUTO_TEST_SUITE(TDEEthFrame_test)
      21              : 
      22            2 : BOOST_AUTO_TEST_CASE(TDEEthFrame_ADCDataMutators)
      23              : {
      24            1 :   using dunedaq::fddetdataformats::TDEEthFrame;
      25              : 
      26            1 :   std::random_device dev;
      27            1 :   std::mt19937 rng(dev());
      28            1 :   std::uniform_int_distribution<uint16_t> dist(1, (1 << TDEEthFrame::s_bits_per_adc) - 1);
      29              : 
      30            1 :   std::vector<std::vector<uint16_t>> adcs(TDEEthFrame::s_num_channels,
      31            1 :                                           std::vector<uint16_t>(TDEEthFrame::s_time_samples_per_frame));
      32              : 
      33           65 :   for (int channel = 0; channel < TDEEthFrame::s_num_channels; ++channel) {
      34         4160 :     for (int sample = 0; sample < TDEEthFrame::s_time_samples_per_frame; ++sample) {
      35         4096 :       adcs[channel][sample] = dist(rng);
      36              :     }
      37              :   }
      38              : 
      39            1 :   TDEEthFrame frame{};
      40              : 
      41           65 :   for (int channel = 0; channel < TDEEthFrame::s_num_channels; ++channel) {
      42         4160 :     for (int sample = 0; sample < TDEEthFrame::s_time_samples_per_frame; ++sample) {
      43         4096 :       frame.set_adc(channel, sample, adcs[channel][sample]);
      44              :     }
      45              :   }
      46              : 
      47           65 :   for (int channel = 0; channel < TDEEthFrame::s_num_channels; ++channel) {
      48         4160 :     for (int sample = 0; sample < TDEEthFrame::s_time_samples_per_frame; ++sample) {
      49         4096 :       BOOST_REQUIRE_EQUAL(frame.get_adc(channel, sample), adcs[channel][sample]);
      50              :     }
      51              :   }
      52              : 
      53            1 :   frame.set_adc(0, 0, adcs[0][0]);
      54              : 
      55           65 :   for (int channel = 0; channel < TDEEthFrame::s_num_channels; ++channel) {
      56         4160 :     for (int sample = 0; sample < TDEEthFrame::s_time_samples_per_frame; ++sample) {
      57         4096 :       BOOST_REQUIRE_EQUAL(frame.get_adc(channel, sample), adcs[channel][sample]);
      58              :     }
      59              :   }
      60            1 : }
      61              : 
      62            2 : BOOST_AUTO_TEST_CASE(TDEEthFrame_IndexAndValueBounds)
      63              : {
      64            1 :   using dunedaq::fddetdataformats::TDEEthFrame;
      65              : 
      66            1 :   TDEEthFrame frame{};
      67              : 
      68            1 :   BOOST_CHECK_THROW(frame.get_adc(-1, 0), std::out_of_range);
      69            1 :   BOOST_CHECK_THROW(frame.get_adc(TDEEthFrame::s_num_channels, 0), std::out_of_range);
      70            1 :   BOOST_CHECK_THROW(frame.get_adc(0, -1), std::out_of_range);
      71            1 :   BOOST_CHECK_THROW(frame.get_adc(0, TDEEthFrame::s_time_samples_per_frame), std::out_of_range);
      72              : 
      73            1 :   BOOST_CHECK_THROW(frame.set_adc(-1, 0, 123), std::out_of_range);
      74            1 :   BOOST_CHECK_THROW(frame.set_adc(TDEEthFrame::s_num_channels, 0, 123), std::out_of_range);
      75            1 :   BOOST_CHECK_THROW(frame.set_adc(0, -1, 123), std::out_of_range);
      76            1 :   BOOST_CHECK_THROW(frame.set_adc(0, TDEEthFrame::s_time_samples_per_frame, 123), std::out_of_range);
      77            1 :   BOOST_CHECK_THROW(frame.set_adc(0, 0, static_cast<uint16_t>(1 << TDEEthFrame::s_bits_per_adc)), std::out_of_range);
      78              : 
      79            1 :   BOOST_CHECK_NO_THROW(frame.set_adc(0, 0, static_cast<uint16_t>((1 << TDEEthFrame::s_bits_per_adc) - 1)));
      80            1 :   BOOST_CHECK_EQUAL(frame.get_adc(0, 0), static_cast<uint16_t>((1 << TDEEthFrame::s_bits_per_adc) - 1));
      81            1 : }
      82              : 
      83            2 : BOOST_AUTO_TEST_CASE(TDEEthFrame_BitPackingBoundaryIsolation)
      84              : {
      85            1 :   using dunedaq::fddetdataformats::TDEEthFrame;
      86              : 
      87            1 :   TDEEthFrame frame{};
      88            1 :   constexpr auto max_adc = static_cast<uint16_t>((1u << TDEEthFrame::s_bits_per_adc) - 1u);
      89            1 :   constexpr int sample = 5;
      90            1 :   constexpr int boundary_channel = 4;
      91              : 
      92            1 :   frame.set_adc(boundary_channel - 1, sample, 0x0000u);
      93            1 :   frame.set_adc(boundary_channel, sample, 0x0000u);
      94            1 :   frame.set_adc(boundary_channel + 1, sample, 0x0000u);
      95              : 
      96            1 :   frame.set_adc(boundary_channel, sample, 0x2AAAu);
      97            1 :   BOOST_CHECK_EQUAL(frame.get_adc(boundary_channel - 1, sample), 0x0000u);
      98            1 :   BOOST_CHECK_EQUAL(frame.get_adc(boundary_channel, sample), 0x2AAAu);
      99            1 :   BOOST_CHECK_EQUAL(frame.get_adc(boundary_channel + 1, sample), 0x0000u);
     100              : 
     101            1 :   frame.set_adc(boundary_channel - 1, sample, max_adc);
     102            1 :   BOOST_CHECK_EQUAL(frame.get_adc(boundary_channel - 1, sample), max_adc);
     103            1 :   BOOST_CHECK_EQUAL(frame.get_adc(boundary_channel, sample), 0x2AAAu);
     104            1 :   BOOST_CHECK_EQUAL(frame.get_adc(boundary_channel + 1, sample), 0x0000u);
     105              : 
     106            1 :   frame.set_adc(boundary_channel + 1, sample, 0x1555u);
     107            1 :   BOOST_CHECK_EQUAL(frame.get_adc(boundary_channel - 1, sample), max_adc);
     108            1 :   BOOST_CHECK_EQUAL(frame.get_adc(boundary_channel, sample), 0x2AAAu);
     109            1 :   BOOST_CHECK_EQUAL(frame.get_adc(boundary_channel + 1, sample), 0x1555u);
     110            1 : }
     111              : 
     112            2 : BOOST_AUTO_TEST_CASE(TDEEthFrame_MetadataMutators)
     113              : {
     114            1 :   using dunedaq::fddetdataformats::TDEEthFrame;
     115              : 
     116            1 :   TDEEthFrame frame{};
     117              : 
     118            1 :   frame.set_timestamp(0x0123456789ABCDEFuLL);
     119            1 :   BOOST_CHECK_EQUAL(frame.get_timestamp(), 0x0123456789ABCDEFuLL);
     120              : 
     121            1 :   frame.set_channel(0);
     122            1 :   BOOST_CHECK_EQUAL(frame.get_channel(), 0);
     123              : 
     124            1 :   frame.set_channel(255);
     125            1 :   BOOST_CHECK_EQUAL(frame.get_channel(), 255);
     126            1 : }
     127              : 
     128              : BOOST_AUTO_TEST_SUITE_END()
     129              : 
     130              : // NOLINTEND(build/unsigned)
        

Generated by: LCOV version 2.0-1