Line data Source code
1 : /**
2 : * @file CRTBernFrame_test.cxx CRTBernFrame 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/CRTBernFrame.hpp"
10 :
11 : #define BOOST_TEST_MODULE CRTBernFrame_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(CRTBernFrame_test)
21 :
22 2 : BOOST_AUTO_TEST_CASE(CRTBernFrame_ADCDataMutators)
23 : {
24 1 : using dunedaq::fddetdataformats::CRTBernFrame;
25 :
26 1 : std::random_device dev;
27 1 : std::mt19937 rng(dev());
28 1 : std::uniform_int_distribution<uint16_t> dist(0, 65535);
29 :
30 1 : std::vector<uint16_t> adcs(CRTBernFrame::s_num_channels);
31 33 : for (auto& value : adcs) {
32 32 : value = dist(rng);
33 : }
34 :
35 1 : CRTBernFrame frame{};
36 :
37 33 : for (int channel = 0; channel < CRTBernFrame::s_num_channels; ++channel) {
38 32 : frame.set_adc(channel, adcs[channel]);
39 : }
40 :
41 33 : for (int channel = 0; channel < CRTBernFrame::s_num_channels; ++channel) {
42 32 : BOOST_REQUIRE_EQUAL(frame.get_adc(channel), adcs[channel]);
43 : }
44 :
45 1 : frame.set_adc(0, adcs[0]);
46 33 : for (int channel = 0; channel < CRTBernFrame::s_num_channels; ++channel) {
47 32 : BOOST_REQUIRE_EQUAL(frame.get_adc(channel), adcs[channel]);
48 : }
49 1 : }
50 :
51 2 : BOOST_AUTO_TEST_CASE(CRTBernFrame_IndexBounds)
52 : {
53 1 : using dunedaq::fddetdataformats::CRTBernFrame;
54 :
55 1 : CRTBernFrame frame{};
56 :
57 1 : BOOST_CHECK_THROW(frame.get_adc(-1), std::out_of_range);
58 1 : BOOST_CHECK_THROW(frame.get_adc(CRTBernFrame::s_num_channels), std::out_of_range);
59 :
60 1 : BOOST_CHECK_THROW(frame.set_adc(-1, 123), std::out_of_range);
61 1 : BOOST_CHECK_THROW(frame.set_adc(CRTBernFrame::s_num_channels, 123), std::out_of_range);
62 1 : }
63 :
64 2 : BOOST_AUTO_TEST_CASE(CRTBernFrame_TimestampMutators)
65 : {
66 1 : using dunedaq::fddetdataformats::CRTBernFrame;
67 :
68 1 : CRTBernFrame frame{};
69 :
70 1 : uint64_t timestamp = 0x0123456789ABCDEFuLL;
71 1 : frame.set_timestamp(timestamp);
72 1 : BOOST_CHECK_EQUAL(frame.get_timestamp(), timestamp);
73 :
74 : // Verify ts0 is also set consistently with timestamp
75 1 : uint32_t expected_ts0 = (timestamp % CRTBernFrame::s_DTS_ticks_per_second) * CRTBernFrame::s_ns_per_DTS_tick;
76 1 : BOOST_CHECK_EQUAL(frame.get_ts0(), expected_ts0);
77 1 : }
78 :
79 2 : BOOST_AUTO_TEST_CASE(CRTBernFrame_MAC5Mutators)
80 : {
81 1 : using dunedaq::fddetdataformats::CRTBernFrame;
82 :
83 1 : CRTBernFrame frame{};
84 :
85 1 : uint16_t mac5_value = 0xABCD;
86 1 : frame.set_mac5(mac5_value);
87 1 : BOOST_CHECK_EQUAL(frame.get_mac5(), mac5_value);
88 :
89 : // Test with different values
90 1 : mac5_value = 0x0000;
91 1 : frame.set_mac5(mac5_value);
92 1 : BOOST_CHECK_EQUAL(frame.get_mac5(), mac5_value);
93 :
94 1 : mac5_value = 0xFFFF;
95 1 : frame.set_mac5(mac5_value);
96 1 : BOOST_CHECK_EQUAL(frame.get_mac5(), mac5_value);
97 1 : }
98 :
99 2 : BOOST_AUTO_TEST_CASE(CRTBernFrame_FlagsAndCounters)
100 : {
101 1 : using dunedaq::fddetdataformats::CRTBernFrame;
102 :
103 1 : CRTBernFrame frame{};
104 :
105 1 : uint16_t flags = 0x00FF;
106 1 : frame.set_flags(flags);
107 1 : BOOST_CHECK_EQUAL(frame.get_flags(), flags);
108 :
109 1 : uint16_t lostcpu = 0x1234;
110 1 : frame.set_lostcpu(lostcpu);
111 1 : BOOST_CHECK_EQUAL(frame.get_lostcpu(), lostcpu);
112 :
113 1 : uint16_t lostfpga = 0x5678;
114 1 : frame.set_lostfpga(lostfpga);
115 1 : BOOST_CHECK_EQUAL(frame.get_lostfpga(), lostfpga);
116 :
117 : // Verify all values are independent
118 1 : BOOST_CHECK_EQUAL(frame.get_flags(), flags);
119 1 : BOOST_CHECK_EQUAL(frame.get_lostcpu(), lostcpu);
120 1 : BOOST_CHECK_EQUAL(frame.get_lostfpga(), lostfpga);
121 1 : }
122 :
123 2 : BOOST_AUTO_TEST_CASE(CRTBernFrame_TimestampFields)
124 : {
125 1 : using dunedaq::fddetdataformats::CRTBernFrame;
126 :
127 1 : CRTBernFrame frame{};
128 :
129 1 : uint32_t ts0 = 0x12345678;
130 1 : frame.set_ts0(ts0);
131 1 : BOOST_CHECK_EQUAL(frame.get_ts0(), ts0);
132 :
133 1 : uint32_t ts1 = 0x9ABCDEF0;
134 1 : frame.set_ts1(ts1);
135 1 : BOOST_CHECK_EQUAL(frame.get_ts1(), ts1);
136 :
137 1 : uint32_t coinc = 0xDEADBEEF;
138 1 : frame.set_coinc(coinc);
139 1 : BOOST_CHECK_EQUAL(frame.get_coinc(), coinc);
140 :
141 : // Verify all values are independent
142 1 : BOOST_CHECK_EQUAL(frame.get_ts0(), ts0);
143 1 : BOOST_CHECK_EQUAL(frame.get_ts1(), ts1);
144 1 : BOOST_CHECK_EQUAL(frame.get_coinc(), coinc);
145 1 : }
146 :
147 2 : BOOST_AUTO_TEST_CASE(CRTBernFrame_Constants)
148 : {
149 1 : using dunedaq::fddetdataformats::CRTBernFrame;
150 :
151 1 : BOOST_CHECK_EQUAL(CRTBernFrame::s_DTS_ticks_per_second, 62500000u);
152 1 : BOOST_CHECK_EQUAL(CRTBernFrame::s_ns_per_DTS_tick, 16u);
153 1 : BOOST_CHECK_EQUAL(CRTBernFrame::s_num_channels, 32);
154 1 : }
155 :
156 : BOOST_AUTO_TEST_SUITE_END()
157 :
158 : // NOLINTEND(build/unsigned)
|