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

            Line data    Source code
       1              : /**
       2              :  * @file DAPHNEStreamFrame_test.cxx DAPHNEStreamFrame 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/DAPHNEStreamFrame.hpp"
      10              : 
      11              : #define BOOST_TEST_MODULE DAPHNEStreamFrame_test // NOLINT
      12              : 
      13              : #include "boost/test/unit_test.hpp"
      14              : 
      15              : #include <cstdint>
      16              : #include <random>
      17              : #include <vector>
      18              : 
      19              : // NOLINTBEGIN(build/unsigned)
      20              : 
      21              : BOOST_AUTO_TEST_SUITE(DAPHNEStreamFrame_test)
      22              : 
      23            2 : BOOST_AUTO_TEST_CASE(DAPHNEStreamFrame_ADCDataMutators)
      24              : {
      25            1 :   using dunedaq::fddetdataformats::DAPHNEStreamFrame;
      26              : 
      27            1 :   std::random_device dev;
      28            1 :   std::mt19937 rng(dev());
      29            1 :   std::uniform_int_distribution<uint16_t> dist(0, (1 << DAPHNEStreamFrame::s_bits_per_adc) - 1);
      30              : 
      31            1 :   std::vector<std::vector<uint16_t>> adcs(DAPHNEStreamFrame::s_adcs_per_channel,
      32            1 :                                           std::vector<uint16_t>(DAPHNEStreamFrame::s_channels_per_frame));
      33              : 
      34           65 :   for (uint32_t sample = 0; sample < DAPHNEStreamFrame::s_adcs_per_channel; ++sample) {
      35          320 :     for (uint32_t channel = 0; channel < DAPHNEStreamFrame::s_channels_per_frame; ++channel) {
      36          256 :       adcs[sample][channel] = dist(rng);
      37              :     }
      38              :   }
      39              : 
      40            1 :   DAPHNEStreamFrame frame{};
      41              : 
      42           65 :   for (uint32_t sample = 0; sample < DAPHNEStreamFrame::s_adcs_per_channel; ++sample) {
      43          320 :     for (uint32_t channel = 0; channel < DAPHNEStreamFrame::s_channels_per_frame; ++channel) {
      44          256 :       frame.set_adc(sample, channel, adcs[sample][channel]);
      45              :     }
      46              :   }
      47              : 
      48           65 :   for (uint32_t sample = 0; sample < DAPHNEStreamFrame::s_adcs_per_channel; ++sample) {
      49          320 :     for (uint32_t channel = 0; channel < DAPHNEStreamFrame::s_channels_per_frame; ++channel) {
      50          256 :       BOOST_REQUIRE_EQUAL(frame.get_adc(sample, channel), adcs[sample][channel]);
      51              :     }
      52              :   }
      53              : 
      54            1 :   frame.set_adc(0, 0, adcs[0][0]);
      55              : 
      56           65 :   for (uint32_t sample = 0; sample < DAPHNEStreamFrame::s_adcs_per_channel; ++sample) {
      57          320 :     for (uint32_t channel = 0; channel < DAPHNEStreamFrame::s_channels_per_frame; ++channel) {
      58          256 :       BOOST_REQUIRE_EQUAL(frame.get_adc(sample, channel), adcs[sample][channel]);
      59              :     }
      60              :   }
      61            1 : }
      62              : 
      63            2 : BOOST_AUTO_TEST_CASE(DAPHNEStreamFrame_IndexAndValueBounds)
      64              : {
      65            1 :   using dunedaq::fddetdataformats::DAPHNEStreamFrame;
      66              : 
      67            1 :   DAPHNEStreamFrame frame{};
      68              : 
      69            1 :   BOOST_CHECK_THROW(frame.get_adc(DAPHNEStreamFrame::s_adcs_per_channel, 0), std::out_of_range);
      70            1 :   BOOST_CHECK_THROW(frame.get_adc(0, DAPHNEStreamFrame::s_channels_per_frame), std::out_of_range);
      71            1 :   BOOST_CHECK_THROW(frame.get_adc(static_cast<uint32_t>(-1), 0), std::out_of_range);
      72            1 :   BOOST_CHECK_THROW(frame.get_adc(0, static_cast<uint32_t>(-1)), std::out_of_range);
      73              : 
      74            1 :   BOOST_CHECK_THROW(frame.set_adc(DAPHNEStreamFrame::s_adcs_per_channel, 0, 123), std::out_of_range);
      75            1 :   BOOST_CHECK_THROW(frame.set_adc(0, DAPHNEStreamFrame::s_channels_per_frame, 123), std::out_of_range);
      76            1 :   BOOST_CHECK_THROW(frame.set_adc(static_cast<uint32_t>(-1), 0, 123), std::out_of_range);
      77            1 :   BOOST_CHECK_THROW(frame.set_adc(0, static_cast<uint32_t>(-1), 123), std::out_of_range);
      78            1 :   BOOST_CHECK_THROW(frame.set_adc(0, 0, static_cast<uint16_t>(1 << DAPHNEStreamFrame::s_bits_per_adc)),
      79              :                     std::out_of_range);
      80              : 
      81            1 :   BOOST_CHECK_NO_THROW(frame.set_adc(0, 0, static_cast<uint16_t>((1 << DAPHNEStreamFrame::s_bits_per_adc) - 1)));
      82            1 :   BOOST_CHECK_EQUAL(frame.get_adc(0, 0), static_cast<uint16_t>((1 << DAPHNEStreamFrame::s_bits_per_adc) - 1));
      83            1 : }
      84              : 
      85            2 : BOOST_AUTO_TEST_CASE(DAPHNEStreamFrame_BitPackingBoundaryIsolation)
      86              : {
      87            1 :   using dunedaq::fddetdataformats::DAPHNEStreamFrame;
      88              : 
      89            1 :   DAPHNEStreamFrame frame{};
      90            1 :   constexpr auto max_adc = static_cast<uint16_t>((1u << DAPHNEStreamFrame::s_bits_per_adc) - 1u);
      91              : 
      92            1 :   constexpr uint32_t boundary_sample = 1;
      93            1 :   constexpr uint32_t boundary_channel = 0;
      94              : 
      95            1 :   frame.set_adc(0, 3, 0x0000u);
      96            1 :   frame.set_adc(boundary_sample, boundary_channel, 0x0000u);
      97            1 :   frame.set_adc(boundary_sample, 1, 0x0000u);
      98              : 
      99            1 :   frame.set_adc(boundary_sample, boundary_channel, 0x2AAAu);
     100            1 :   BOOST_CHECK_EQUAL(frame.get_adc(0, 3), 0x0000u);
     101            1 :   BOOST_CHECK_EQUAL(frame.get_adc(boundary_sample, boundary_channel), 0x2AAAu);
     102            1 :   BOOST_CHECK_EQUAL(frame.get_adc(boundary_sample, 1), 0x0000u);
     103              : 
     104            1 :   frame.set_adc(0, 3, max_adc);
     105            1 :   BOOST_CHECK_EQUAL(frame.get_adc(0, 3), max_adc);
     106            1 :   BOOST_CHECK_EQUAL(frame.get_adc(boundary_sample, boundary_channel), 0x2AAAu);
     107            1 :   BOOST_CHECK_EQUAL(frame.get_adc(boundary_sample, 1), 0x0000u);
     108              : 
     109            1 :   frame.set_adc(boundary_sample, 1, 0x1555u);
     110            1 :   BOOST_CHECK_EQUAL(frame.get_adc(0, 3), max_adc);
     111            1 :   BOOST_CHECK_EQUAL(frame.get_adc(boundary_sample, boundary_channel), 0x2AAAu);
     112            1 :   BOOST_CHECK_EQUAL(frame.get_adc(boundary_sample, 1), 0x1555u);
     113            1 : }
     114              : 
     115            2 : BOOST_AUTO_TEST_CASE(DAPHNEStreamFrame_MetadataMutators)
     116              : {
     117            1 :   using dunedaq::fddetdataformats::DAPHNEStreamFrame;
     118              : 
     119            1 :   DAPHNEStreamFrame frame{};
     120              : 
     121            1 :   frame.set_timestamp(0x0123456789ABCDEFuLL);
     122            1 :   BOOST_CHECK_EQUAL(frame.get_timestamp(), 0x0123456789ABCDEFuLL);
     123              : 
     124            1 :   frame.header.channel_0 = 10;
     125            1 :   frame.header.channel_1 = 20;
     126            1 :   frame.header.channel_2 = 30;
     127            1 :   frame.header.channel_3 = 40;
     128              : 
     129            1 :   BOOST_CHECK_EQUAL(frame.get_channel0(), 10);
     130            1 :   BOOST_CHECK_EQUAL(frame.get_channel1(), 20);
     131            1 :   BOOST_CHECK_EQUAL(frame.get_channel2(), 30);
     132            1 :   BOOST_CHECK_EQUAL(frame.get_channel3(), 40);
     133            1 : }
     134              : 
     135              : BOOST_AUTO_TEST_SUITE_END()
     136              : 
     137              : // NOLINTEND(build/unsigned)
        

Generated by: LCOV version 2.0-1